2019-08-09 12:52:14 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2019-11-16 00:30:50 +01:00
|
|
|
#include <windows.h>
|
2019-08-09 12:52:14 +02:00
|
|
|
#include <winsock.h>
|
|
|
|
#include <wincrypt.h>
|
|
|
|
#include <wintrust.h>
|
|
|
|
#include <schannel.h>
|
|
|
|
|
|
|
|
#define SECURITY_WIN32
|
|
|
|
#include <security.h>
|
|
|
|
#include <sspi.h>
|
|
|
|
|
2019-08-25 20:27:12 +02:00
|
|
|
#define vsc_init_resp_buff_size 44000
|
|
|
|
|
2019-08-09 12:52:14 +02:00
|
|
|
#define IO_BUFFER_SIZE 0x10000
|
|
|
|
|
|
|
|
#define TLS_MAX_BUFSIZ 32768
|
|
|
|
|
|
|
|
// Define here to be sure
|
|
|
|
#define SP_PROT_TLS1_2_CLIENT 0x00000800
|
|
|
|
|
2019-08-29 11:33:20 +02:00
|
|
|
typedef struct TlsContext TlsContext;
|
2019-08-09 12:52:14 +02:00
|
|
|
|
2019-08-29 11:33:20 +02:00
|
|
|
TlsContext new_tls_context();
|
2019-08-10 10:05:59 +02:00
|
|
|
|
2019-08-29 11:33:20 +02:00
|
|
|
static void vschannel_init(TlsContext *tls_ctx);
|
2019-08-10 10:05:59 +02:00
|
|
|
|
2019-08-29 11:33:20 +02:00
|
|
|
static void vschannel_cleanup(TlsContext *tls_ctx);
|
2019-08-10 10:05:59 +02:00
|
|
|
|
2019-09-26 21:54:15 +02:00
|
|
|
static INT request(TlsContext *tls_ctx, INT iport, LPWSTR host, CHAR *req, CHAR **out);
|
2019-08-09 12:52:14 +02:00
|
|
|
|
2019-08-29 11:33:20 +02:00
|
|
|
static SECURITY_STATUS https_make_request(TlsContext *tls_ctx, CHAR *req, CHAR **out, int *length);
|
2019-08-11 13:13:33 +02:00
|
|
|
|
2019-09-26 21:54:15 +02:00
|
|
|
static INT connect_to_server(TlsContext *tls_ctx, LPWSTR host, INT port_number);
|
2019-08-09 12:52:14 +02:00
|
|
|
|
2019-08-29 11:33:20 +02:00
|
|
|
static LONG disconnect_from_server(TlsContext *tls_ctx);
|
2019-08-09 12:52:14 +02:00
|
|
|
|
2019-09-26 21:54:15 +02:00
|
|
|
static SECURITY_STATUS perform_client_handshake(TlsContext *tls_ctx, LPWSTR host, SecBuffer *pExtraData);
|
2019-08-09 12:52:14 +02:00
|
|
|
|
2019-08-29 11:33:20 +02:00
|
|
|
static SECURITY_STATUS client_handshake_loop(TlsContext *tls_ctx, BOOL fDoInitialRead, SecBuffer *pExtraData);
|
2019-08-09 12:52:14 +02:00
|
|
|
|
2019-09-26 21:54:15 +02:00
|
|
|
static DWORD verify_server_certificate(PCCERT_CONTEXT pServerCert, LPWSTR host, DWORD dwCertFlags);
|
2019-08-09 12:52:14 +02:00
|
|
|
|
2019-08-29 11:33:20 +02:00
|
|
|
static SECURITY_STATUS create_credentials(TlsContext *tls_ctx);
|
2019-08-09 12:52:14 +02:00
|
|
|
|
2019-11-16 00:30:50 +01:00
|
|
|
static void get_new_client_credentials(TlsContext *tls_ctx);
|