00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __KOPENSSLPROXY_H
00023 #define __KOPENSSLPROXY_H
00024
00025 #define KOSSL KOpenSSLProxy
00026 class KOpenSSLProxyPrivate;
00027
00028 #include <klibloader.h>
00029
00030 #ifdef Q_WS_WIN
00031 #include "ksslconfig_win.h"
00032 #else
00033 #include "ksslconfig.h"
00034 #endif
00035
00036 #ifdef KSSL_HAVE_SSL
00037 #define crypt _openssl_crypt
00038 #include <openssl/ssl.h>
00039 #include <openssl/x509.h>
00040 #include <openssl/x509v3.h>
00041 #include <openssl/pem.h>
00042 #include <openssl/bio.h>
00043 #include <openssl/rand.h>
00044 #include <openssl/asn1.h>
00045 #include <openssl/pkcs7.h>
00046 #include <openssl/pkcs12.h>
00047 #include <openssl/evp.h>
00048 #include <openssl/stack.h>
00049 #include <openssl/bn.h>
00050 #undef crypt
00051 #endif
00052
00053 #include <kstaticdeleter.h>
00054
00063 class KIO_EXPORT KOpenSSLProxy {
00064 friend class KStaticDeleter<KOpenSSLProxy>;
00065 public:
00066
00071 static KOpenSSLProxy *self();
00072
00076 bool hasLibCrypto() const;
00077
00081 bool hasLibSSL() const;
00082
00087 void destroy();
00088
00089
00090 #ifdef KSSL_HAVE_SSL
00091
00092
00093
00094
00095 int SSL_connect(SSL *ssl);
00096
00097
00098
00099
00100 int SSL_accept(SSL *ssl);
00101
00102
00103
00104
00105 int SSL_get_error(SSL *ssl, int rc);
00106
00107
00108
00109
00110 int SSL_read(SSL *ssl, void *buf, int num);
00111
00112
00113
00114
00115 int SSL_write(SSL *ssl, const void *buf, int num);
00116
00117
00118
00119
00120 SSL *SSL_new(SSL_CTX *ctx);
00121
00122
00123
00124
00125 void SSL_free(SSL *ssl);
00126
00127
00128
00129
00130 int SSL_shutdown(SSL *ssl);
00131
00132
00133
00134
00135 SSL_CTX *SSL_CTX_new(SSL_METHOD *method);
00136
00137
00138
00139
00140 void SSL_CTX_free(SSL_CTX *ctx);
00141
00142
00143
00144
00145 int SSL_set_fd(SSL *ssl, int fd);
00146
00147
00148
00149
00150 int SSL_pending(SSL *ssl);
00151
00152
00153
00154
00155 int SSL_peek(SSL *ssl, void *buf, int num);
00156
00157
00158
00159
00160 int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str);
00161
00162
00163
00164
00165 void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
00166 int (*verify_callback)(int, X509_STORE_CTX *));
00167
00168
00169
00170
00171 int SSL_use_certificate(SSL *ssl, X509 *x);
00172
00173
00174
00175
00176 SSL_CIPHER *SSL_get_current_cipher(SSL *ssl);
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 long SSL_ctrl(SSL *ssl,int cmd, long larg, char *parg);
00189
00190
00191
00192
00193 int RAND_egd(const char *path);
00194
00195
00196
00197
00198
00199 const char *RAND_file_name(char *buf, size_t num);
00200
00201
00202
00203
00204
00205 int RAND_load_file(const char *filename, long max_bytes);
00206
00207
00208
00209
00210
00211 int RAND_write_file(const char *filename);
00212
00213
00214
00215
00216
00217 SSL_METHOD *TLSv1_client_method();
00218
00219
00220
00221
00222
00223 SSL_METHOD *SSLv2_client_method();
00224
00225
00226
00227
00228
00229 SSL_METHOD *SSLv3_client_method();
00230
00231
00232
00233
00234
00235 SSL_METHOD *SSLv23_client_method();
00236
00237
00238
00239
00240
00241 X509 *SSL_get_peer_certificate(SSL *s);
00242
00243
00244
00245
00246
00247 STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s);
00248
00249
00250
00251
00252 int SSL_CIPHER_get_bits(SSL_CIPHER *c,int *alg_bits);
00253
00254
00255
00256
00257
00258 char *SSL_CIPHER_get_version(SSL_CIPHER *c);
00259
00260
00261
00262
00263
00264 const char *SSL_CIPHER_get_name(SSL_CIPHER *c);
00265
00266
00267
00268
00269
00270 char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size);
00271
00272
00273
00274
00275
00276
00277 int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
00278
00279
00280
00281
00282
00283 int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
00284
00285
00286
00287
00288
00289 X509 * d2i_X509(X509 **a,unsigned char **pp,long length);
00290
00291
00292
00293
00294
00295 int i2d_X509(X509 *a,unsigned char **pp);
00296
00297
00298
00299
00300
00301 int X509_cmp(X509 *a, X509 *b);
00302
00303
00304
00305
00306
00307 X509 *X509_dup(X509 *x509);
00308
00309
00310
00311
00312
00313 X509_STORE_CTX *X509_STORE_CTX_new(void);
00314
00315
00316
00317
00318
00319 void X509_STORE_CTX_free(X509_STORE_CTX *v);
00320
00321
00322
00323
00324
00325 void X509_STORE_CTX_set_chain(X509_STORE_CTX *v, STACK_OF(X509)* x);
00326
00327
00328
00329
00330 void X509_STORE_CTX_set_purpose(X509_STORE_CTX *v, int purpose);
00331
00332
00333
00334
00335 int X509_verify_cert(X509_STORE_CTX *v);
00336
00337
00338
00339
00340
00341 X509_STORE *X509_STORE_new(void);
00342
00343
00344
00345
00346
00347 void X509_STORE_free(X509_STORE *v);
00348
00349
00350
00351
00352
00353 void X509_free(X509 *v);
00354
00355
00356
00357
00358
00359 char *X509_NAME_oneline(X509_NAME *a, char *buf, int size);
00360
00361
00362
00363
00364
00365 X509_NAME *X509_get_subject_name(X509 *a);
00366
00367
00368
00369
00370
00371 X509_NAME *X509_get_issuer_name(X509 *a);
00372
00373
00374
00375
00376
00377 X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m);
00378
00379
00380
00381
00382
00383 X509_LOOKUP_METHOD *X509_LOOKUP_file(void);
00384
00385
00386
00387
00388
00389 void X509_LOOKUP_free(X509_LOOKUP *x);
00390
00391
00392
00393
00394
00395 int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl, char **ret);
00396
00397
00398
00399
00400
00401 void X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509, STACK_OF(X509) *chain);
00402
00403
00404
00405
00406
00407 void CRYPTO_free(void *x);
00408
00409
00410
00411
00412 BIO *BIO_new(BIO_METHOD *type);
00413
00414
00415
00416
00417 BIO_METHOD *BIO_s_mem(void);
00418
00419
00420
00421
00422 BIO *BIO_new_fp(FILE *stream, int close_flag);
00423
00424
00425
00426
00427 BIO *BIO_new_mem_buf(void *buf, int len);
00428
00429
00430
00431
00432 int BIO_free(BIO *a);
00433
00434
00435
00436
00437 long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
00438
00439
00440
00441
00442 int BIO_write(BIO *b, const void *data, int len);
00443
00444
00445
00446
00447 int PEM_write_bio_X509(BIO *bp, X509 *x);
00448
00449
00450
00451
00452
00453 ASN1_METHOD *X509_asn1_meth();
00454
00455
00456
00457
00458
00459 int ASN1_i2d_fp(FILE *out, unsigned char *x);
00460
00461
00462
00463
00464
00465 X509 *X509_d2i_fp(FILE *out, X509** buf);
00466
00467
00468
00469
00470
00471 int X509_print(FILE *fp, X509 *x);
00472
00473
00474
00475
00476
00477 PKCS12 *d2i_PKCS12_fp(FILE *fp, PKCS12 **p12);
00478
00479
00480
00481
00482
00483 int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
00484
00485
00486
00487
00488
00489 int i2d_PKCS12(PKCS12 *p12, unsigned char **p);
00490
00491
00492
00493
00494
00495 int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);
00496
00497
00498
00499
00500
00501 PKCS12 *PKCS12_new(void);
00502
00503
00504
00505
00506
00507 void PKCS12_free(PKCS12 *a);
00508
00509
00510
00511
00512
00513 int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey,
00514 X509 **cert, STACK_OF(X509) **ca);
00515
00516
00517
00518
00519
00520 void EVP_PKEY_free(EVP_PKEY *x);
00521
00522
00523
00524
00525
00526 char *sk_pop(STACK *s);
00527
00528
00529
00530
00531
00532 void sk_free(STACK *s);
00533
00534
00535
00536
00537
00538 int sk_num(STACK *s);
00539
00540
00541
00542
00543
00544 char *sk_value(STACK *s, int n);
00545
00546
00547
00548
00549
00550 STACK *sk_new(int (*cmp)());
00551
00552
00553
00554
00555
00556 int sk_push(STACK *s, char *d);
00557
00558
00559
00560
00561
00562 STACK *sk_dup(STACK *s);
00563
00564
00565
00566
00567
00568 char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
00569
00570
00571
00572
00573
00574 ASN1_INTEGER *X509_get_serialNumber(X509 *x);
00575
00576
00577
00578
00579
00580 EVP_PKEY *X509_get_pubkey(X509 *x);
00581
00582
00583
00584
00585
00586 int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
00587
00588
00589
00590
00591
00592 int X509_check_private_key(X509 *x, EVP_PKEY *p);
00593
00594
00595
00596
00597
00598 char *BN_bn2hex(const BIGNUM *a);
00599
00600
00601
00602
00603
00604 int X509_digest(const X509 *x,const EVP_MD *t, unsigned char *md, unsigned int *len);
00605
00606
00607
00608
00609
00610 EVP_MD *EVP_md5();
00611
00612
00613
00614
00615
00616 void ASN1_INTEGER_free(ASN1_INTEGER *x);
00617
00618
00619
00620
00621
00622 unsigned char *ASN1_STRING_data(ASN1_STRING *x);
00623
00624
00625
00626
00627 int OBJ_obj2nid(ASN1_OBJECT *o);
00628
00629
00630
00631
00632 const char * OBJ_nid2ln(int n);
00633
00634
00635
00636
00637 int X509_get_ext_count(X509 *x);
00638
00639
00640
00641
00642 int X509_get_ext_by_NID(X509 *x, int nid, int lastpos);
00643
00644
00645
00646
00647 int X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos);
00648
00649
00650
00651
00652 X509_EXTENSION *X509_get_ext(X509 *x, int loc);
00653
00654
00655
00656
00657 X509_EXTENSION *X509_delete_ext(X509 *x, int loc);
00658
00659
00660
00661
00662 int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc);
00663
00664
00665
00666
00667 void *X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
00668
00669
00670
00671
00672 char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *ia5);
00673
00674
00675
00676
00677 int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
00678
00679
00680
00681
00682 PKCS7 *PKCS7_new(void);
00683
00684
00685
00686
00687 void PKCS7_free(PKCS7 *a);
00688
00689
00690
00691
00692 void PKCS7_content_free(PKCS7 *a);
00693
00694
00695
00696
00697 int i2d_PKCS7(PKCS7 *a, unsigned char **pp);
00698
00699
00700
00701
00702 PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp,long length);
00703
00704
00705
00706
00707 int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);
00708
00709
00710
00711
00712 PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7);
00713
00714
00715
00716
00717 int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);
00718
00719
00720
00721
00722 PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7);
00723
00724
00725
00726
00727 PKCS7 *PKCS7_dup(PKCS7 *p7);
00728
00729
00730
00731
00732 PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
00733 BIO *data, int flags);
00734
00735
00736
00737
00738 int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
00739 BIO *indata, BIO *out, int flags);
00740
00741
00742
00743
00744 STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
00745
00746
00747
00748
00749 PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher,
00750 int flags);
00751
00752
00753
00754
00755 int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags);
00756
00757
00758
00759
00760
00761 STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
00762
00763
00764
00765
00766 STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
00767 pem_password_cb *cb, void *u);
00768
00769
00770
00771
00772 int X509_PURPOSE_get_count();
00773
00774
00775
00776
00777
00778 int X509_PURPOSE_get_id(X509_PURPOSE *);
00779
00780
00781
00782
00783
00784 int X509_check_purpose(X509 *x, int id, int ca);
00785
00786
00787
00788
00789
00790 X509_PURPOSE * X509_PURPOSE_get0(int idx);
00791
00792
00793
00794
00795
00796 EVP_PKEY* EVP_PKEY_new();
00797
00798
00799
00800
00801
00802 int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key);
00803
00804
00805
00806
00807
00808 RSA *RSA_generate_key(int bits, unsigned long e, void
00809 (*callback)(int,int,void *), void *cb_arg);
00810
00811
00812
00813
00814
00815 X509_REQ *X509_REQ_new();
00816 void X509_REQ_free(X509_REQ *a);
00817
00818
00819
00820
00821
00822 int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey);
00823
00824
00825 int i2d_X509_REQ_fp(FILE *fp, X509_REQ *x);
00826
00827
00828 STACK *X509_get1_email(X509 *x);
00829 void X509_email_free(STACK *sk);
00830
00831
00832 EVP_CIPHER *EVP_des_ede3_cbc();
00833 EVP_CIPHER *EVP_des_cbc();
00834 EVP_CIPHER *EVP_rc2_cbc();
00835 EVP_CIPHER *EVP_rc2_64_cbc();
00836 EVP_CIPHER *EVP_rc2_40_cbc();
00837
00838
00839 void ERR_clear_error();
00840
00841
00842 unsigned long ERR_get_error();
00843
00844
00845 void ERR_print_errors_fp(FILE *fp);
00846
00847
00848 SSL_SESSION *SSL_get1_session(SSL *ssl);
00849
00850
00851 void SSL_SESSION_free(SSL_SESSION *session);
00852
00853
00854 int SSL_set_session(SSL *ssl, SSL_SESSION *session);
00855
00856
00857 SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, unsigned char **pp, long length);
00858
00859 int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp);
00860
00861
00862 int i2d_PrivateKey_fp(FILE*, EVP_PKEY*);
00863
00864
00865 int i2d_PKCS8PrivateKey_fp(FILE*, EVP_PKEY*, const EVP_CIPHER*, char*, int, pem_password_cb*, void*);
00866
00867
00868 void RSA_free(RSA*);
00869
00870
00871 EVP_CIPHER *EVP_bf_cbc();
00872
00873
00874 int X509_REQ_sign(X509_REQ*, EVP_PKEY*, const EVP_MD*);
00875
00876
00877 int X509_NAME_add_entry_by_txt(X509_NAME*, char*, int, unsigned char*, int, int, int);
00878
00879
00880 X509_NAME *X509_NAME_new();
00881
00882
00883 int X509_REQ_set_subject_name(X509_REQ*,X509_NAME*);
00884
00885
00886 STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL* ssl);
00887
00888 #endif
00889
00890 private:
00891 KOpenSSLProxy();
00892 ~KOpenSSLProxy();
00893 KOpenSSLProxyPrivate *d;
00894
00895 KLibrary *_sslLib;
00896 KLibrary *_cryptoLib;
00897 static KOpenSSLProxy *_me;
00898
00899 bool _ok;
00900 };
00901
00902 #endif
00903