v / thirdparty / vschannel
Raw file | 51 loc (32 sloc) | 1.4 KB | Latest commit hash 9e09b709e
1#include <stdint.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <windows.h>
5#include <winsock.h>
6#include <wincrypt.h>
7#include <wintrust.h>
8#include <schannel.h>
9
10#define SECURITY_WIN32
11#include <security.h>
12#include <sspi.h>
13
14#define vsc_init_resp_buff_size 44000
15
16#define IO_BUFFER_SIZE 0x10000
17
18#define TLS_MAX_BUFSIZ 32768
19
20// Define here to be sure
21#define SP_PROT_TLS1_2_CLIENT 0x00000800
22
23#if !defined(VSCHANNEL_REALLOC)
24#define VSCHANNEL_REALLOC realloc
25#endif
26
27typedef struct TlsContext TlsContext;
28
29TlsContext new_tls_context();
30
31static void vschannel_init(TlsContext *tls_ctx);
32
33static void vschannel_cleanup(TlsContext *tls_ctx);
34
35static INT request(TlsContext *tls_ctx, INT iport, LPWSTR host, CHAR *req, DWORD req_len, CHAR **out);
36
37static SECURITY_STATUS https_make_request(TlsContext *tls_ctx, CHAR *req, DWORD req_len, CHAR **out, int *length);
38
39static INT connect_to_server(TlsContext *tls_ctx, LPWSTR host, INT port_number);
40
41static LONG disconnect_from_server(TlsContext *tls_ctx);
42
43static SECURITY_STATUS perform_client_handshake(TlsContext *tls_ctx, LPWSTR host, SecBuffer *pExtraData);
44
45static SECURITY_STATUS client_handshake_loop(TlsContext *tls_ctx, BOOL fDoInitialRead, SecBuffer *pExtraData);
46
47static DWORD verify_server_certificate(PCCERT_CONTEXT pServerCert, LPWSTR host, DWORD dwCertFlags);
48
49static SECURITY_STATUS create_credentials(TlsContext *tls_ctx);
50
51static void get_new_client_credentials(TlsContext *tls_ctx);