22 #ifndef __KOPENSSLPROXY_H
23 #define __KOPENSSLPROXY_H
25 #define KOSSL KOpenSSLProxy
26 class KOpenSSLProxyPrivate;
30 #include <ksslconfig.h>
33 #define crypt _openssl_crypt
34 #include <openssl/ssl.h>
35 #include <openssl/x509.h>
36 #include <openssl/x509v3.h>
37 #include <openssl/pem.h>
38 #include <openssl/bio.h>
39 #include <openssl/rand.h>
40 #include <openssl/asn1.h>
41 #include <openssl/pkcs7.h>
42 #include <openssl/pkcs12.h>
43 #include <openssl/evp.h>
44 #include <openssl/stack.h>
45 #include <openssl/bn.h>
47 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
49 #define OSSL_SKVALUE_RTYPE void
50 #define OSSL_MORECONST const
52 #define OSSL_SKVALUE_RTYPE char
53 #define OSSL_MORECONST
96 int SSL_connect(SSL *ssl);
101 int SSL_accept(SSL *ssl);
106 int SSL_get_error(SSL *ssl,
int rc);
111 int SSL_read(SSL *ssl,
void *buf,
int num);
116 int SSL_write(SSL *ssl,
const void *buf,
int num);
121 SSL *SSL_new(SSL_CTX *ctx);
126 void SSL_free(SSL *ssl);
131 int SSL_shutdown(SSL *ssl);
136 SSL_CTX *SSL_CTX_new(SSL_METHOD *method);
141 void SSL_CTX_free(SSL_CTX *ctx);
146 int SSL_set_fd(SSL *ssl,
int fd);
151 int SSL_pending(SSL *ssl);
156 int SSL_peek(SSL *ssl,
void *buf,
int num);
161 int SSL_CTX_set_cipher_list(SSL_CTX *ctx,
const char *str);
166 void SSL_CTX_set_verify(SSL_CTX *ctx,
int mode,
167 int (*verify_callback)(
int, X509_STORE_CTX *));
172 int SSL_use_certificate(SSL *ssl, X509 *x);
177 SSL_CIPHER *SSL_get_current_cipher(SSL *ssl);
189 long SSL_ctrl(SSL *ssl,
int cmd,
long larg,
char *parg);
194 int RAND_egd(
const char *path);
200 const char *RAND_file_name(
char *buf,
size_t num);
206 int RAND_load_file(
const char *filename,
long max_bytes);
212 int RAND_write_file(
const char *filename);
218 SSL_METHOD *TLSv1_client_method();
224 SSL_METHOD *SSLv23_client_method();
230 X509 *SSL_get_peer_certificate(SSL *s);
236 STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s);
241 int SSL_CIPHER_get_bits(SSL_CIPHER *c,
int *alg_bits);
247 char *SSL_CIPHER_get_version(SSL_CIPHER *c);
253 const char *SSL_CIPHER_get_name(SSL_CIPHER *c);
259 char *SSL_CIPHER_description(SSL_CIPHER *,
char *buf,
int size);
266 int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
272 int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
278 X509 * d2i_X509(X509 **a,
unsigned char **pp,
long length);
284 int i2d_X509(X509 *a,
unsigned char **pp);
290 int X509_cmp(X509 *a, X509 *b);
296 X509 *X509_dup(X509 *x509);
302 ASN1_TIME *X509_getm_notBefore(
const X509 *x);
308 ASN1_TIME *X509_getm_notAfter(
const X509 *x);
314 X509_STORE_CTX *X509_STORE_CTX_new(
void);
320 void X509_STORE_CTX_free(X509_STORE_CTX *v);
326 void X509_STORE_CTX_set_chain(X509_STORE_CTX *v,
STACK_OF(X509)* x);
332 void X509_STORE_CTX_set_purpose(X509_STORE_CTX *v,
int purpose);
338 X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *v);
344 void X509_STORE_CTX_set_error(X509_STORE_CTX *v,
int error);
350 int X509_STORE_CTX_get_error(X509_STORE_CTX *v);
356 int X509_verify_cert(X509_STORE_CTX *v);
362 X509_STORE *X509_STORE_new(
void);
368 void X509_STORE_free(X509_STORE *v);
374 void X509_STORE_set_verify_cb(X509_STORE *v,
int (*verify_cb)(
int, X509_STORE_CTX *));
380 void X509_free(X509 *v);
386 char *X509_NAME_oneline(X509_NAME *a,
char *buf,
int size);
392 X509_NAME *X509_get_subject_name(X509 *a);
398 X509_NAME *X509_get_issuer_name(X509 *a);
404 void X509_get0_signature(
const ASN1_BIT_STRING **psig,
const X509_ALGOR **palg,
const X509 *x);
410 X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m);
416 X509_LOOKUP_METHOD *X509_LOOKUP_file(
void);
422 void X509_LOOKUP_free(X509_LOOKUP *x);
428 int X509_LOOKUP_ctrl(X509_LOOKUP *ctx,
int cmd,
const char *argc,
long argl,
char **ret);
434 void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
STACK_OF(X509) *chain);
440 #if OPENSSL_VERSION_NUMBER < 0x10100000L
441 void CRYPTO_free(
void *x);
443 void CRYPTO_free(
void *x,
const char *file,
int line);
449 BIO *BIO_new(BIO_METHOD *type);
454 BIO_METHOD *BIO_s_mem(
void);
459 BIO *BIO_new_fp(FILE *stream,
int close_flag);
464 BIO *BIO_new_mem_buf(
void *buf,
int len);
469 int BIO_free(BIO *a);
474 long BIO_ctrl(BIO *bp,
int cmd,
long larg,
void *parg);
479 int BIO_write(BIO *b,
const void *data,
int len);
484 int PEM_write_bio_X509(BIO *bp, X509 *x);
489 int ASN1_item_i2d_fp(FILE *out,
unsigned char *x);
495 X509 *X509_d2i_fp(FILE *out, X509** buf);
501 int X509_print(FILE *
fp, X509 *x);
507 PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
513 int PKCS12_newpass(PKCS12 *p12,
char *oldpass,
char *newpass);
519 int i2d_PKCS12(PKCS12 *p12,
unsigned char **p);
525 int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);
531 PKCS12 *PKCS12_new(
void);
537 void PKCS12_free(PKCS12 *a);
543 int PKCS12_parse(PKCS12 *p12,
const char *pass, EVP_PKEY **pkey,
550 void EVP_PKEY_free(EVP_PKEY *x);
556 char *OPENSSL_sk_pop(STACK *s);
562 void OPENSSL_sk_free(STACK *s);
564 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
565 void OPENSSL_sk_free(
void *s) {
return OPENSSL_sk_free(reinterpret_cast<STACK*>(s)); }
571 int OPENSSL_sk_num(STACK *s);
577 char *OPENSSL_sk_value(STACK *s,
int n);
579 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
580 char *OPENSSL_sk_value(
void *s,
int n) {
return OPENSSL_sk_value(reinterpret_cast<STACK*>(s), n); }
586 STACK *OPENSSL_sk_new(
int (*cmp)());
592 int OPENSSL_sk_push(STACK *s,
char *d);
594 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
595 int OPENSSL_sk_push(
void *s,
void *d) {
return OPENSSL_sk_push(reinterpret_cast<STACK*>(s), reinterpret_cast<char*>(d)); }
602 STACK *OPENSSL_sk_dup(STACK *s);
608 char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
614 ASN1_INTEGER *X509_get_serialNumber(X509 *x);
620 EVP_PKEY *X509_get_pubkey(X509 *x);
626 int i2d_PublicKey(EVP_PKEY *a,
unsigned char **pp);
632 int X509_check_private_key(X509 *x, EVP_PKEY *p);
638 char *BN_bn2hex(
const BIGNUM *a);
644 int X509_digest(
const X509 *x,
const EVP_MD *t,
unsigned char *md,
unsigned int *len);
656 void ASN1_INTEGER_free(ASN1_INTEGER *x);
662 unsigned char *ASN1_STRING_data(ASN1_STRING *x);
667 int ASN1_STRING_length(ASN1_STRING *x);
672 int OBJ_obj2nid(ASN1_OBJECT *o);
677 const char * OBJ_nid2ln(
int n);
682 int X509_get_ext_count(X509 *x);
687 int X509_get_ext_by_NID(X509 *x,
int nid,
int lastpos);
692 int X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,
int lastpos);
697 X509_EXTENSION *X509_get_ext(X509 *x,
int loc);
702 X509_EXTENSION *X509_delete_ext(X509 *x,
int loc);
707 int X509_add_ext(X509 *x, X509_EXTENSION *ex,
int loc);
712 void *X509_get_ext_d2i(X509 *x,
int nid,
int *crit,
int *idx);
717 char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5);
722 int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a,
int n);
727 PKCS7 *PKCS7_new(
void);
732 void PKCS7_free(PKCS7 *a);
737 void PKCS7_content_free(PKCS7 *a);
742 int i2d_PKCS7(PKCS7 *a,
unsigned char **pp);
747 PKCS7 *d2i_PKCS7(PKCS7 **a,
unsigned char **pp,
long length);
752 int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);
757 PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7);
762 int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);
767 PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7);
772 PKCS7 *PKCS7_dup(PKCS7 *p7);
777 PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey,
STACK_OF(X509) *certs,
778 BIO *data,
int flags);
783 int PKCS7_verify(PKCS7 *p7,
STACK_OF(X509) *certs, X509_STORE *store,
784 BIO *indata, BIO *out,
int flags);
789 STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7,
STACK_OF(X509) *certs,
int flags);
794 PKCS7 *PKCS7_encrypt(
STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher,
800 int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data,
int flags);
806 STACK_OF(X509_NAME) *SSL_load_client_CA_file(
const char *file);
812 pem_password_cb *cb,
void *u);
817 int X509_PURPOSE_get_count();
823 int X509_PURPOSE_get_id(X509_PURPOSE *);
829 int X509_check_purpose(X509 *x,
int id,
int ca);
835 X509_PURPOSE * X509_PURPOSE_get0(
int idx);
841 EVP_PKEY* EVP_PKEY_new();
847 int EVP_PKEY_assign(EVP_PKEY *pkey,
int type,
char *key);
853 int EVP_PKEY_base_id(EVP_PKEY *pkey);
855 RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);
856 void RSA_get0_key(RSA *rsa,
const BIGNUM **n,
const BIGNUM **e,
const BIGNUM **d);
857 DSA *EVP_PKEY_get0_DSA(EVP_PKEY *pkey);
858 void DSA_get0_pqg(DSA *dsa,
const BIGNUM **p,
const BIGNUM **q,
const BIGNUM **g);
859 void DSA_get0_key(DSA *dsa,
const BIGNUM **pub_key,
const BIGNUM **priv_key);
865 RSA *RSA_generate_key(
int bits,
unsigned long e,
void
866 (*callback)(
int,
int,
void *),
void *cb_arg);
872 X509_REQ *X509_REQ_new();
873 void X509_REQ_free(X509_REQ *a);
879 int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
882 int i2d_X509_REQ_fp(FILE *fp, X509_REQ *x);
885 STACK *X509_get1_email(X509 *x);
886 void X509_email_free(STACK *sk);
889 EVP_CIPHER *EVP_des_ede3_cbc();
890 EVP_CIPHER *EVP_des_cbc();
891 EVP_CIPHER *EVP_rc2_cbc();
892 EVP_CIPHER *EVP_rc2_64_cbc();
893 EVP_CIPHER *EVP_rc2_40_cbc();
896 void ERR_clear_error();
899 unsigned long ERR_get_error();
902 void ERR_print_errors_fp(FILE *fp);
905 SSL_SESSION *SSL_get1_session(SSL *ssl);
908 void SSL_SESSION_free(SSL_SESSION *session);
911 int SSL_set_session(SSL *ssl, SSL_SESSION *session);
914 SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,
unsigned char **pp,
long length);
916 int i2d_SSL_SESSION(SSL_SESSION *in,
unsigned char **pp);
919 int i2d_PrivateKey_fp(FILE*, EVP_PKEY*);
922 int i2d_PKCS8PrivateKey_fp(FILE*, EVP_PKEY*,
const EVP_CIPHER*,
char*,
int, pem_password_cb*,
void*);
928 EVP_CIPHER *EVP_bf_cbc();
931 int X509_REQ_sign(X509_REQ*, EVP_PKEY*,
const EVP_MD*);
934 int X509_NAME_add_entry_by_txt(X509_NAME*,
char*,
int,
unsigned char*,
int,
int,
int);
937 X509_NAME *X509_NAME_new();
940 int X509_REQ_set_subject_name(X509_REQ*,X509_NAME*);
943 STACK_OF(SSL_CIPHER) *SSL_get_ciphers(
const SSL* ssl);
bool hasLibCrypto() const
Return true of libcrypto was found and loaded.
Dynamically load and wrap OpenSSL.
friend class KOpenSSLProxyPrivate
bool hasLibSSL() const
Return true of libssl was found and loaded.
void destroy()
Destroy the class and start over - don't use this unless you know what you are doing.