OpenVPN
Data Structures | Macros | Typedefs | Functions | Variables
cryptoapi.c File Reference
#include "syshead.h"
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <windows.h>
#include <wincrypt.h>
#include <stdio.h>
#include <ctype.h>
#include <assert.h>
#include "buffer.h"
Include dependency graph for cryptoapi.c:

Go to the source code of this file.

Data Structures

struct  _CAPI_DATA
 

Macros

#define CERT_SYSTEM_STORE_LOCATION_SHIFT   16
 
#define CERT_SYSTEM_STORE_CURRENT_USER_ID   1
 
#define CERT_SYSTEM_STORE_CURRENT_USER   (CERT_SYSTEM_STORE_CURRENT_USER_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)
 
#define CERT_STORE_READONLY_FLAG   0x00008000
 
#define CERT_STORE_OPEN_EXISTING_FLAG   0x00004000
 
#define SSL_SIG_LENGTH   36
 
#define ERR_LIB_CRYPTOAPI   (ERR_LIB_USER + 69) /* 69 is just a number... */
 
#define CRYPTOAPIerr(f)   err_put_ms_error(GetLastError(), (f), __FILE__, __LINE__)
 
#define CRYPTOAPI_F_CERT_OPEN_SYSTEM_STORE   100
 
#define CRYPTOAPI_F_CERT_FIND_CERTIFICATE_IN_STORE   101
 
#define CRYPTOAPI_F_CRYPT_ACQUIRE_CERTIFICATE_PRIVATE_KEY   102
 
#define CRYPTOAPI_F_CRYPT_CREATE_HASH   103
 
#define CRYPTOAPI_F_CRYPT_GET_HASH_PARAM   104
 
#define CRYPTOAPI_F_CRYPT_SET_HASH_PARAM   105
 
#define CRYPTOAPI_F_CRYPT_SIGN_HASH   106
 
#define CRYPTOAPI_F_LOAD_LIBRARY   107
 
#define CRYPTOAPI_F_GET_PROC_ADDRESS   108
 
#define ERR_MAP_SZ   16
 

Typedefs

typedef struct _CAPI_DATA CAPI_DATA
 

Functions

static char * ms_error_text (DWORD ms_err)
 
static void err_put_ms_error (DWORD ms_err, int func, const char *file, int line)
 
static int rsa_pub_enc (int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
 
static int rsa_pub_dec (int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
 
static int rsa_priv_enc (int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
 
static int rsa_priv_dec (int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
 
static int init (RSA *rsa)
 
static int finish (RSA *rsa)
 
static const CERT_CONTEXT * find_certificate_in_store (const char *cert_prop, HCERTSTORE cert_store)
 
int SSL_CTX_use_CryptoAPI_certificate (SSL_CTX *ssl_ctx, const char *cert_prop)
 

Variables

static ERR_STRING_DATA CRYPTOAPI_str_functs []
 

Macro Definition Documentation

◆ CERT_STORE_OPEN_EXISTING_FLAG

#define CERT_STORE_OPEN_EXISTING_FLAG   0x00004000

Definition at line 67 of file cryptoapi.c.

Referenced by SSL_CTX_use_CryptoAPI_certificate().

◆ CERT_STORE_READONLY_FLAG

#define CERT_STORE_READONLY_FLAG   0x00008000

Definition at line 64 of file cryptoapi.c.

Referenced by SSL_CTX_use_CryptoAPI_certificate().

◆ CERT_SYSTEM_STORE_CURRENT_USER

#define CERT_SYSTEM_STORE_CURRENT_USER   (CERT_SYSTEM_STORE_CURRENT_USER_ID << CERT_SYSTEM_STORE_LOCATION_SHIFT)

Definition at line 61 of file cryptoapi.c.

Referenced by SSL_CTX_use_CryptoAPI_certificate().

◆ CERT_SYSTEM_STORE_CURRENT_USER_ID

#define CERT_SYSTEM_STORE_CURRENT_USER_ID   1

Definition at line 58 of file cryptoapi.c.

◆ CERT_SYSTEM_STORE_LOCATION_SHIFT

#define CERT_SYSTEM_STORE_LOCATION_SHIFT   16

Definition at line 55 of file cryptoapi.c.

◆ CRYPTOAPI_F_CERT_FIND_CERTIFICATE_IN_STORE

#define CRYPTOAPI_F_CERT_FIND_CERTIFICATE_IN_STORE   101

Definition at line 77 of file cryptoapi.c.

Referenced by SSL_CTX_use_CryptoAPI_certificate().

◆ CRYPTOAPI_F_CERT_OPEN_SYSTEM_STORE

#define CRYPTOAPI_F_CERT_OPEN_SYSTEM_STORE   100

Definition at line 76 of file cryptoapi.c.

Referenced by SSL_CTX_use_CryptoAPI_certificate().

◆ CRYPTOAPI_F_CRYPT_ACQUIRE_CERTIFICATE_PRIVATE_KEY

#define CRYPTOAPI_F_CRYPT_ACQUIRE_CERTIFICATE_PRIVATE_KEY   102

Definition at line 78 of file cryptoapi.c.

Referenced by SSL_CTX_use_CryptoAPI_certificate().

◆ CRYPTOAPI_F_CRYPT_CREATE_HASH

#define CRYPTOAPI_F_CRYPT_CREATE_HASH   103

Definition at line 79 of file cryptoapi.c.

Referenced by rsa_priv_enc().

◆ CRYPTOAPI_F_CRYPT_GET_HASH_PARAM

#define CRYPTOAPI_F_CRYPT_GET_HASH_PARAM   104

Definition at line 80 of file cryptoapi.c.

Referenced by rsa_priv_enc().

◆ CRYPTOAPI_F_CRYPT_SET_HASH_PARAM

#define CRYPTOAPI_F_CRYPT_SET_HASH_PARAM   105

Definition at line 81 of file cryptoapi.c.

Referenced by rsa_priv_enc().

◆ CRYPTOAPI_F_CRYPT_SIGN_HASH

#define CRYPTOAPI_F_CRYPT_SIGN_HASH   106

Definition at line 82 of file cryptoapi.c.

Referenced by rsa_priv_enc().

◆ CRYPTOAPI_F_GET_PROC_ADDRESS

#define CRYPTOAPI_F_GET_PROC_ADDRESS   108

Definition at line 84 of file cryptoapi.c.

◆ CRYPTOAPI_F_LOAD_LIBRARY

#define CRYPTOAPI_F_LOAD_LIBRARY   107

Definition at line 83 of file cryptoapi.c.

◆ CRYPTOAPIerr

#define CRYPTOAPIerr (   f)    err_put_ms_error(GetLastError(), (f), __FILE__, __LINE__)

Definition at line 75 of file cryptoapi.c.

Referenced by rsa_priv_enc(), and SSL_CTX_use_CryptoAPI_certificate().

◆ ERR_LIB_CRYPTOAPI

#define ERR_LIB_CRYPTOAPI   (ERR_LIB_USER + 69) /* 69 is just a number... */

Definition at line 74 of file cryptoapi.c.

Referenced by err_put_ms_error().

◆ ERR_MAP_SZ

#define ERR_MAP_SZ   16

Referenced by err_put_ms_error().

◆ SSL_SIG_LENGTH

#define SSL_SIG_LENGTH   36

Definition at line 71 of file cryptoapi.c.

Referenced by rsa_priv_enc().

Typedef Documentation

◆ CAPI_DATA

typedef struct _CAPI_DATA CAPI_DATA

Function Documentation

◆ err_put_ms_error()

static void err_put_ms_error ( DWORD  ms_err,
int  func,
const char *  file,
int  line 
)
static

◆ find_certificate_in_store()

static const CERT_CONTEXT* find_certificate_in_store ( const char *  cert_prop,
HCERTSTORE  cert_store 
)
static

Definition at line 336 of file cryptoapi.c.

Referenced by SSL_CTX_use_CryptoAPI_certificate().

◆ finish()

static int finish ( RSA *  rsa)
static

◆ init()

static int init ( RSA *  rsa)
static

Definition at line 305 of file cryptoapi.c.

Referenced by err_put_ms_error(), and RSA_meth_set_init().

◆ ms_error_text()

static char* ms_error_text ( DWORD  ms_err)
static

Definition at line 108 of file cryptoapi.c.

References string_alloc().

Referenced by err_put_ms_error().

◆ rsa_priv_dec()

static int rsa_priv_dec ( int  flen,
const unsigned char *  from,
unsigned char *  to,
RSA *  rsa,
int  padding 
)
static

Definition at line 295 of file cryptoapi.c.

Referenced by SSL_CTX_use_CryptoAPI_certificate().

◆ rsa_priv_enc()

static int rsa_priv_enc ( int  flen,
const unsigned char *  from,
unsigned char *  to,
RSA *  rsa,
int  padding 
)
static

◆ rsa_pub_dec()

static int rsa_pub_dec ( int  flen,
const unsigned char *  from,
unsigned char *  to,
RSA *  rsa,
int  padding 
)
static

Definition at line 204 of file cryptoapi.c.

Referenced by SSL_CTX_use_CryptoAPI_certificate().

◆ rsa_pub_enc()

static int rsa_pub_enc ( int  flen,
const unsigned char *  from,
unsigned char *  to,
RSA *  rsa,
int  padding 
)
static

Definition at line 194 of file cryptoapi.c.

Referenced by SSL_CTX_use_CryptoAPI_certificate().

◆ SSL_CTX_use_CryptoAPI_certificate()

int SSL_CTX_use_CryptoAPI_certificate ( SSL_CTX *  ssl_ctx,
const char *  cert_prop 
)

Variable Documentation

◆ CRYPTOAPI_str_functs

ERR_STRING_DATA CRYPTOAPI_str_functs[]
static
Initial value:
= {
{ ERR_PACK(ERR_LIB_CRYPTOAPI, 0, 0), "microsoft cryptoapi"},
{ ERR_PACK(0, CRYPTOAPI_F_CERT_OPEN_SYSTEM_STORE, 0), "CertOpenSystemStore" },
{ ERR_PACK(0, CRYPTOAPI_F_CERT_FIND_CERTIFICATE_IN_STORE, 0), "CertFindCertificateInStore" },
{ ERR_PACK(0, CRYPTOAPI_F_CRYPT_ACQUIRE_CERTIFICATE_PRIVATE_KEY, 0), "CryptAcquireCertificatePrivateKey" },
{ ERR_PACK(0, CRYPTOAPI_F_CRYPT_CREATE_HASH, 0), "CryptCreateHash" },
{ ERR_PACK(0, CRYPTOAPI_F_CRYPT_GET_HASH_PARAM, 0), "CryptGetHashParam" },
{ ERR_PACK(0, CRYPTOAPI_F_CRYPT_SET_HASH_PARAM, 0), "CryptSetHashParam" },
{ ERR_PACK(0, CRYPTOAPI_F_CRYPT_SIGN_HASH, 0), "CryptSignHash" },
{ ERR_PACK(0, CRYPTOAPI_F_LOAD_LIBRARY, 0), "LoadLibrary" },
{ ERR_PACK(0, CRYPTOAPI_F_GET_PROC_ADDRESS, 0), "GetProcAddress" },
{ 0, NULL }
}
#define CRYPTOAPI_F_CRYPT_ACQUIRE_CERTIFICATE_PRIVATE_KEY
Definition: cryptoapi.c:78
#define CRYPTOAPI_F_CRYPT_SET_HASH_PARAM
Definition: cryptoapi.c:81
#define CRYPTOAPI_F_CERT_FIND_CERTIFICATE_IN_STORE
Definition: cryptoapi.c:77
#define CRYPTOAPI_F_CRYPT_SIGN_HASH
Definition: cryptoapi.c:82
#define CRYPTOAPI_F_CRYPT_GET_HASH_PARAM
Definition: cryptoapi.c:80
#define ERR_LIB_CRYPTOAPI
Definition: cryptoapi.c:74
#define CRYPTOAPI_F_GET_PROC_ADDRESS
Definition: cryptoapi.c:84
#define CRYPTOAPI_F_LOAD_LIBRARY
Definition: cryptoapi.c:83
#define CRYPTOAPI_F_CRYPT_CREATE_HASH
Definition: cryptoapi.c:79
#define CRYPTOAPI_F_CERT_OPEN_SYSTEM_STORE
Definition: cryptoapi.c:76

Definition at line 86 of file cryptoapi.c.

Referenced by err_put_ms_error().