v2 / thirdparty / vschannel / vschannel.h
51 lines · 31 sloc · 1.54 KB · 6ea10df6ec054049f4ad8e3ab77b3eab33290f09
Raw
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
23typedef void* (*vschannel_allocator)(void*, INT64);
24
25typedef struct TlsContext TlsContext;
26
27TlsContext new_tls_context();
28
29static void vschannel_init(TlsContext *tls_ctx, BOOL validate_server_certificate);
30
31static void vschannel_cleanup(TlsContext *tls_ctx);
32
33static INT vschannel_last_error(TlsContext *tls_ctx);
34
35static INT request(TlsContext *tls_ctx, INT iport, LPWSTR host, CHAR *req, DWORD req_len, CHAR **out, vschannel_allocator afn);
36
37static SECURITY_STATUS https_make_request(TlsContext *tls_ctx, CHAR *req, DWORD req_len, CHAR **out, int *length, vschannel_allocator afn);
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);
52