forked from ultibohub/AraratSynapse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssl_openssl_lib.pas
2214 lines (1971 loc) · 80.6 KB
/
ssl_openssl_lib.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{==============================================================================|
| Project : Ararat Synapse | 003.008.000 |
|==============================================================================|
| Content: SSL support by OpenSSL |
|==============================================================================|
| Copyright (c)1999-2017, Lukas Gebauer |
| All rights reserved. |
| |
| Redistribution and use in source and binary forms, with or without |
| modification, are permitted provided that the following conditions are met: |
| |
| Redistributions of source code must retain the above copyright notice, this |
| list of conditions and the following disclaimer. |
| |
| Redistributions in binary form must reproduce the above copyright notice, |
| this list of conditions and the following disclaimer in the documentation |
| and/or other materials provided with the distribution. |
| |
| Neither the name of Lukas Gebauer nor the names of its contributors may |
| be used to endorse or promote products derived from this software without |
| specific prior written permission. |
| |
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR |
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| DAMAGE. |
|==============================================================================|
| The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
| Portions created by Lukas Gebauer are Copyright (c)2002-2017. |
| Portions created by Petr Fejfar are Copyright (c)2011-2012. |
| All Rights Reserved. |
|==============================================================================|
| Contributor(s): |
| Tomas Hajny (OS2 support) |
|==============================================================================|
| History: see HISTORY.HTM from distribution package |
| (Found at URL: http://www.ararat.cz/synapse/) |
|==============================================================================}
{
Special thanks to Gregor Ibic <[email protected]>
(Intelicom d.o.o., http://www.intelicom.si)
for good inspiration about begin with SSL programming.
}
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$H+}
{$IFDEF VER125}
{$DEFINE BCB}
{$ENDIF}
{$IFDEF BCB}
{$ObjExportAll On}
(*$HPPEMIT 'namespace ssl_openssl_lib { using System::Shortint; }' *)
{$ENDIF}
//old Delphi does not have MSWINDOWS define.
{$IFDEF WIN32}
{$IFNDEF MSWINDOWS}
{$DEFINE MSWINDOWS}
{$ENDIF}
{$ENDIF}
{:@abstract(OpenSSL support)
This unit is Pascal interface to OpenSSL library (used by @link(ssl_openssl) unit).
OpenSSL is loaded dynamicly on-demand. If this library is not found in system,
requested OpenSSL function just return errorcode.
}
unit ssl_openssl_lib;
interface
uses
{$IFDEF CIL}
System.Runtime.InteropServices,
System.Text,
{$ENDIF}
Classes,
synafpc,
{$IFNDEF MSWINDOWS}
{$IFDEF FPC}
{$IFDEF UNIX}
BaseUnix,
{$ENDIF UNIX}
{$ELSE}
Libc,
{$ENDIF}
SysUtils;
{$ELSE}
Windows;
{$ENDIF}
{$IFDEF CIL}
const
{$IFDEF LINUX}
DLLSSLName = 'libssl.so';
DLLUtilName = 'libcrypto.so';
{$ELSE}
DLLSSLName = 'ssleay32.dll';
DLLUtilName = 'libeay32.dll';
{$ENDIF}
{$ELSE}
var
{$IFNDEF MSWINDOWS}
{$IFDEF DARWIN}
DLLSSLName: string = 'libssl.dylib';
DLLUtilName: string = 'libcrypto.dylib';
{$ELSE}
{$IFDEF OS2}
{$IFDEF OS2GCC}
DLLSSLName: string = 'kssl.dll';
DLLUtilName: string = 'kcrypto.dll';
{$ELSE OS2GCC}
DLLSSLName: string = 'ssl.dll';
DLLUtilName: string = 'crypto.dll';
{$ENDIF OS2GCC}
{$ELSE OS2}
DLLSSLName: string = 'libssl.so';
DLLUtilName: string = 'libcrypto.so';
{$ENDIF OS2}
{$ENDIF}
{$ELSE}
DLLSSLName: string = 'ssleay32.dll';
DLLSSLName2: string = 'libssl32.dll';
DLLUtilName: string = 'libeay32.dll';
{$ENDIF}
{$ENDIF}
type
{$IFDEF CIL}
SslPtr = IntPtr;
{$ELSE}
SslPtr = Pointer;
{$ENDIF}
PSslPtr = ^SslPtr;
PSSL_CTX = SslPtr;
PSSL = SslPtr;
PSSL_METHOD = SslPtr;
PX509 = SslPtr;
PX509_NAME = SslPtr;
PEVP_MD = SslPtr;
PInteger = ^Integer;
PBIO_METHOD = SslPtr;
PBIO = SslPtr;
EVP_PKEY = SslPtr;
PRSA = SslPtr;
PASN1_UTCTIME = SslPtr;
PASN1_INTEGER = SslPtr;
PPasswdCb = SslPtr;
PFunction = procedure;
PSTACK = SslPtr; {pf}
TSkPopFreeFunc = procedure(p:SslPtr); cdecl; {pf}
TX509Free = procedure(x: PX509); cdecl; {pf}
DES_cblock = array[0..7] of Byte;
PDES_cblock = ^DES_cblock;
des_ks_struct = packed record
ks: DES_cblock;
weak_key: Integer;
end;
des_key_schedule = array[1..16] of des_ks_struct;
const
EVP_MAX_MD_SIZE = 16 + 20;
SSL_ERROR_NONE = 0;
SSL_ERROR_SSL = 1;
SSL_ERROR_WANT_READ = 2;
SSL_ERROR_WANT_WRITE = 3;
SSL_ERROR_WANT_X509_LOOKUP = 4;
SSL_ERROR_SYSCALL = 5; //look at error stack/return value/errno
SSL_ERROR_ZERO_RETURN = 6;
SSL_ERROR_WANT_CONNECT = 7;
SSL_ERROR_WANT_ACCEPT = 8;
SSL_OP_NO_SSLv2 = $01000000;
SSL_OP_NO_SSLv3 = $02000000;
SSL_OP_NO_TLSv1 = $04000000;
SSL_OP_ALL = $000FFFFF;
SSL_VERIFY_NONE = $00;
SSL_VERIFY_PEER = $01;
OPENSSL_DES_DECRYPT = 0;
OPENSSL_DES_ENCRYPT = 1;
X509_V_OK = 0;
X509_V_ILLEGAL = 1;
X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT = 2;
X509_V_ERR_UNABLE_TO_GET_CRL = 3;
X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE = 4;
X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE = 5;
X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY = 6;
X509_V_ERR_CERT_SIGNATURE_FAILURE = 7;
X509_V_ERR_CRL_SIGNATURE_FAILURE = 8;
X509_V_ERR_CERT_NOT_YET_VALID = 9;
X509_V_ERR_CERT_HAS_EXPIRED = 10;
X509_V_ERR_CRL_NOT_YET_VALID = 11;
X509_V_ERR_CRL_HAS_EXPIRED = 12;
X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD = 13;
X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD = 14;
X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD = 15;
X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD = 16;
X509_V_ERR_OUT_OF_MEM = 17;
X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT = 18;
X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN = 19;
X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY = 20;
X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE = 21;
X509_V_ERR_CERT_CHAIN_TOO_LONG = 22;
X509_V_ERR_CERT_REVOKED = 23;
X509_V_ERR_INVALID_CA = 24;
X509_V_ERR_PATH_LENGTH_EXCEEDED = 25;
X509_V_ERR_INVALID_PURPOSE = 26;
X509_V_ERR_CERT_UNTRUSTED = 27;
X509_V_ERR_CERT_REJECTED = 28;
//These are 'informational' when looking for issuer cert
X509_V_ERR_SUBJECT_ISSUER_MISMATCH = 29;
X509_V_ERR_AKID_SKID_MISMATCH = 30;
X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH = 31;
X509_V_ERR_KEYUSAGE_NO_CERTSIGN = 32;
X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER = 33;
X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION = 34;
//The application is not happy
X509_V_ERR_APPLICATION_VERIFICATION = 50;
SSL_FILETYPE_ASN1 = 2;
SSL_FILETYPE_PEM = 1;
EVP_PKEY_RSA = 6;
SSL_CTRL_SET_TLSEXT_HOSTNAME = 55;
TLSEXT_NAMETYPE_host_name = 0;
var
SSLLibHandle: TLibHandle = 0;
SSLUtilHandle: TLibHandle = 0;
SSLLibFile: string = '';
SSLUtilFile: string = '';
{$IFDEF CIL}
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_get_error')]
function SslGetError(s: PSSL; ret_code: Integer): Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_library_init')]
function SslLibraryInit: Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_load_error_strings')]
procedure SslLoadErrorStrings; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_set_cipher_list')]
function SslCtxSetCipherList(arg0: PSSL_CTX; var str: String): Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_new')]
function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_free')]
procedure SslCtxFree (arg0: PSSL_CTX); external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_set_fd')]
function SslSetFd(s: PSSL; fd: Integer):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSLv2_method')]
function SslMethodV2 : PSSL_METHOD; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSLv3_method')]
function SslMethodV3 : PSSL_METHOD; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'TLSv1_method')]
function SslMethodTLSV1:PSSL_METHOD; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'TLSv1_1_method')]
function SslMethodTLSV11:PSSL_METHOD; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'TLSv1_2_method')]
function SslMethodTLSV12:PSSL_METHOD; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSLv23_method')]
function SslMethodV23 : PSSL_METHOD; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'TLS_method')]
function SslMethodTLS : PSSL_METHOD; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_use_PrivateKey')]
function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_use_PrivateKey_ASN1')]
function SslCtxUsePrivateKeyASN1(pk: integer; ctx: PSSL_CTX; d: String; len: integer):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_use_RSAPrivateKey_file')]
function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_use_certificate')]
function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_use_certificate_ASN1')]
function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: integer; d: String):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_use_certificate_file')]
function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: String; _type: Integer):Integer;external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_use_certificate_chain_file')]
function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: String):Integer;external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_check_private_key')]
function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_set_default_passwd_cb')]
procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb); external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_set_default_passwd_cb_userdata')]
procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: IntPtr); external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_load_verify_locations')]
function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; CAfile: string; CApath: String):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_ctrl')]
function SslCtxCtrl(ctx: PSSL_CTX; cmd: integer; larg: integer; parg: IntPtr): integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_new')]
function SslNew(ctx: PSSL_CTX):PSSL; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_free')]
procedure SslFree(ssl: PSSL); external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_accept')]
function SslAccept(ssl: PSSL):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_connect')]
function SslConnect(ssl: PSSL):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_shutdown')]
function SslShutdown(s: PSSL):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_read')]
function SslRead(ssl: PSSL; buf: StringBuilder; num: Integer):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_peek')]
function SslPeek(ssl: PSSL; buf: StringBuilder; num: Integer):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_write')]
function SslWrite(ssl: PSSL; buf: String; num: Integer):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_pending')]
function SslPending(ssl: PSSL):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_get_version')]
function SslGetVersion(ssl: PSSL):String; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_get_peer_certificate')]
function SslGetPeerCertificate(s: PSSL):PX509; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CTX_set_verify')]
procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: PFunction); external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_get_current_cipher')]
function SSLGetCurrentCipher(s: PSSL): SslPtr; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CIPHER_get_name')]
function SSLCipherGetName(c: SslPtr):String; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_CIPHER_get_bits')]
function SSLCipherGetBits(c: SslPtr; var alg_bits: Integer):Integer; external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_get_verify_result')]
function SSLGetVerifyResult(ssl: PSSL):Integer;external;
[DllImport(DLLSSLName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSL_ctrl')]
function SslCtrl(ssl: PSSL; cmd: integer; larg: integer; parg: IntPtr): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_new')]
function X509New: PX509; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_free')]
procedure X509Free(x: PX509); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_NAME_oneline')]
function X509NameOneline(a: PX509_NAME; buf: StringBuilder; size: Integer): String; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_get_subject_name')]
function X509GetSubjectName(a: PX509):PX509_NAME; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_get_issuer_name')]
function X509GetIssuerName(a: PX509):PX509_NAME; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_NAME_hash')]
function X509NameHash(x: PX509_NAME):Cardinal; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_digest')]
function X509Digest (data: PX509; _type: PEVP_MD; md: StringBuilder; var len: Integer):Integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_set_version')]
function X509SetVersion(x: PX509; version: integer): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_set_pubkey')]
function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_set_issuer_name')]
function X509SetIssuerName(x: PX509; name: PX509_NAME): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_NAME_add_entry_by_txt')]
function X509NameAddEntryByTxt(name: PX509_NAME; field: string; _type: integer;
bytes: string; len, loc, _set: integer): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_sign')]
function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_print')]
function X509print(b: PBIO; a: PX509): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_gmtime_adj')]
function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_set_notBefore')]
function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_set_notAfter')]
function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'X509_get_serialNumber')]
function X509GetSerialNumber(x: PX509): PASN1_INTEGER; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'EVP_PKEY_new')]
function EvpPkeyNew: EVP_PKEY; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'EVP_PKEY_free')]
procedure EvpPkeyFree(pk: EVP_PKEY); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'EVP_PKEY_assign')]
function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'EVP_get_digestbyname')]
function EvpGetDigestByName(Name: String): PEVP_MD; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'EVP_cleanup')]
procedure EVPcleanup; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'SSLeay_version')]
function SSLeayversion(t: integer): String; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ERR_error_string_n')]
procedure ErrErrorString(e: integer; buf: StringBuilder; len: integer); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ERR_get_error')]
function ErrGetError: integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ERR_clear_error')]
procedure ErrClearError; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ERR_free_strings')]
procedure ErrFreeStrings; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ERR_remove_state')]
procedure ErrRemoveState(pid: integer); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'OPENSSL_add_all_algorithms_noconf')]
procedure OPENSSLaddallalgorithms; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'CRYPTO_cleanup_all_ex_data')]
procedure CRYPTOcleanupAllExData; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'RAND_screen')]
procedure RandScreen; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_new')]
function BioNew(b: PBIO_METHOD): PBIO; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_free_all')]
procedure BioFreeAll(b: PBIO); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_s_mem')]
function BioSMem: PBIO_METHOD; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_ctrl_pending')]
function BioCtrlPending(b: PBIO): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_read')]
function BioRead(b: PBIO; Buf: StringBuilder; Len: integer): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'BIO_write')]
function BioWrite(b: PBIO; var Buf: String; Len: integer): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'd2i_PKCS12_bio')]
function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'PKCS12_parse')]
function PKCS12parse(p12: SslPtr; pass: string; var pkey, cert, ca: SslPtr): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'PKCS12_free')]
procedure PKCS12free(p12: SslPtr); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'RSA_generate_key')]
function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ASN1_UTCTIME_new')]
function Asn1UtctimeNew: PASN1_UTCTIME; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ASN1_UTCTIME_free')]
procedure Asn1UtctimeFree(a: PASN1_UTCTIME); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'ASN1_INTEGER_set')]
function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'i2d_X509_bio')]
function i2dX509bio(b: PBIO; x: PX509): integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'i2d_PrivateKey_bio')]
function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): integer; external;
// 3DES functions
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'DES_set_odd_parity')]
procedure DESsetoddparity(Key: des_cblock); external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'DES_set_key_checked')]
function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer; external;
[DllImport(DLLUtilName, CharSet = CharSet.Ansi,
SetLastError = False, CallingConvention= CallingConvention.cdecl,
EntryPoint = 'DES_ecb_encrypt')]
procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer); external;
{$ELSE}
// libssl.dll
function SslGetError(s: PSSL; ret_code: Integer):Integer;
function SslLibraryInit:Integer;
procedure SslLoadErrorStrings;
// function SslCtxSetCipherList(arg0: PSSL_CTX; str: PChar):Integer;
function SslCtxSetCipherList(arg0: PSSL_CTX; var str: AnsiString):Integer;
function SslCtxNew(meth: PSSL_METHOD):PSSL_CTX;
procedure SslCtxFree(arg0: PSSL_CTX);
function SslSetFd(s: PSSL; fd: Integer):Integer;
function SslMethodV2:PSSL_METHOD;
function SslMethodV3:PSSL_METHOD;
function SslMethodTLSV1:PSSL_METHOD;
function SslMethodTLSV11:PSSL_METHOD;
function SslMethodTLSV12:PSSL_METHOD;
function SslMethodV23:PSSL_METHOD;
function SslMethodTLS:PSSL_METHOD;
function SslCtxUsePrivateKey(ctx: PSSL_CTX; pkey: SslPtr):Integer;
function SslCtxUsePrivateKeyASN1(pk: integer; ctx: PSSL_CTX; d: AnsiString; len: integer):Integer;
// function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: PChar; _type: Integer):Integer;
function SslCtxUsePrivateKeyFile(ctx: PSSL_CTX; const _file: AnsiString; _type: Integer):Integer;
function SslCtxUseCertificate(ctx: PSSL_CTX; x: SslPtr):Integer;
function SslCtxUseCertificateASN1(ctx: PSSL_CTX; len: integer; d: AnsiString):Integer;
function SslCtxUseCertificateFile(ctx: PSSL_CTX; const _file: AnsiString; _type: Integer):Integer;
// function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: PChar):Integer;
function SslCtxUseCertificateChainFile(ctx: PSSL_CTX; const _file: AnsiString):Integer;
function SslCtxCheckPrivateKeyFile(ctx: PSSL_CTX):Integer;
procedure SslCtxSetDefaultPasswdCb(ctx: PSSL_CTX; cb: PPasswdCb);
procedure SslCtxSetDefaultPasswdCbUserdata(ctx: PSSL_CTX; u: SslPtr);
// function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: PChar; const CApath: PChar):Integer;
function SslCtxLoadVerifyLocations(ctx: PSSL_CTX; const CAfile: AnsiString; const CApath: AnsiString):Integer;
function SslCtxCtrl(ctx: PSSL_CTX; cmd: integer; larg: integer; parg: SslPtr): integer;
function SslNew(ctx: PSSL_CTX):PSSL;
procedure SslFree(ssl: PSSL);
function SslAccept(ssl: PSSL):Integer;
function SslConnect(ssl: PSSL):Integer;
function SslShutdown(ssl: PSSL):Integer;
function SslRead(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
function SslPeek(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
function SslWrite(ssl: PSSL; buf: SslPtr; num: Integer):Integer;
function SslPending(ssl: PSSL):Integer;
function SslGetVersion(ssl: PSSL):AnsiString;
function SslGetPeerCertificate(ssl: PSSL):PX509;
procedure SslCtxSetVerify(ctx: PSSL_CTX; mode: Integer; arg2: PFunction);
function SSLGetCurrentCipher(s: PSSL):SslPtr;
function SSLCipherGetName(c: SslPtr): AnsiString;
function SSLCipherGetBits(c: SslPtr; var alg_bits: Integer):Integer;
function SSLGetVerifyResult(ssl: PSSL):Integer;
function SSLCtrl(ssl: PSSL; cmd: integer; larg: integer; parg: SslPtr):Integer;
// libeay.dll
function X509New: PX509;
procedure X509Free(x: PX509);
function X509NameOneline(a: PX509_NAME; var buf: AnsiString; size: Integer):AnsiString;
function X509GetSubjectName(a: PX509):PX509_NAME;
function X509GetIssuerName(a: PX509):PX509_NAME;
function X509NameHash(x: PX509_NAME):Cardinal;
// function SslX509Digest(data: PX509; _type: PEVP_MD; md: PChar; len: PInteger):Integer;
function X509Digest(data: PX509; _type: PEVP_MD; md: AnsiString; var len: Integer):Integer;
function X509print(b: PBIO; a: PX509): integer;
function X509SetVersion(x: PX509; version: integer): integer;
function X509SetPubkey(x: PX509; pkey: EVP_PKEY): integer;
function X509SetIssuerName(x: PX509; name: PX509_NAME): integer;
function X509NameAddEntryByTxt(name: PX509_NAME; field: Ansistring; _type: integer;
bytes: Ansistring; len, loc, _set: integer): integer;
function X509Sign(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer;
function X509GmtimeAdj(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME;
function X509SetNotBefore(x: PX509; tm: PASN1_UTCTIME): integer;
function X509SetNotAfter(x: PX509; tm: PASN1_UTCTIME): integer;
function X509GetSerialNumber(x: PX509): PASN1_INTEGER;
function EvpPkeyNew: EVP_PKEY;
procedure EvpPkeyFree(pk: EVP_PKEY);
function EvpPkeyAssign(pkey: EVP_PKEY; _type: integer; key: Prsa): integer;
function EvpGetDigestByName(Name: AnsiString): PEVP_MD;
procedure EVPcleanup;
// function ErrErrorString(e: integer; buf: PChar): PChar;
function SSLeayversion(t: integer): Ansistring;
procedure ErrErrorString(e: integer; var buf: Ansistring; len: integer);
function ErrGetError: integer;
procedure ErrClearError;
procedure ErrFreeStrings;
procedure ErrRemoveState(pid: integer);
procedure OPENSSLaddallalgorithms;
procedure CRYPTOcleanupAllExData;
procedure RandScreen;
function BioNew(b: PBIO_METHOD): PBIO;
procedure BioFreeAll(b: PBIO);
function BioSMem: PBIO_METHOD;
function BioCtrlPending(b: PBIO): integer;
function BioRead(b: PBIO; var Buf: AnsiString; Len: integer): integer;
function BioWrite(b: PBIO; Buf: AnsiString; Len: integer): integer;
function d2iPKCS12bio(b:PBIO; Pkcs12: SslPtr): SslPtr;
function PKCS12parse(p12: SslPtr; pass: Ansistring; var pkey, cert, ca: SslPtr): integer;
procedure PKCS12free(p12: SslPtr);
function RsaGenerateKey(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA;
function Asn1UtctimeNew: PASN1_UTCTIME;
procedure Asn1UtctimeFree(a: PASN1_UTCTIME);
function Asn1IntegerSet(a: PASN1_INTEGER; v: integer): integer;
function Asn1IntegerGet(a: PASN1_INTEGER): integer; {pf}
function i2dX509bio(b: PBIO; x: PX509): integer;
function d2iX509bio(b:PBIO; x:PX509): PX509; {pf}
function PEMReadBioX509(b:PBIO; {var x:PX509;}x:PSslPtr; callback:PFunction; cb_arg: SslPtr): PX509; {pf}
procedure SkX509PopFree(st: PSTACK; func: TSkPopFreeFunc); {pf}
function i2dPrivateKeyBio(b: PBIO; pkey: EVP_PKEY): integer;
// 3DES functions
procedure DESsetoddparity(Key: des_cblock);
function DESsetkeychecked(key: des_cblock; schedule: des_key_schedule): Integer;
procedure DESecbencrypt(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer);
{$ENDIF}
function IsSSLloaded: Boolean;
function InitSSLInterface: Boolean;
function DestroySSLInterface: Boolean;
var
_X509Free: TX509Free = nil; {pf}
implementation
uses
{$IFDEF OS2}
Sockets,
{$ENDIF OS2}
SyncObjs;
{$IFNDEF CIL}
type
// libssl.dll
TSslGetError = function(s: PSSL; ret_code: Integer):Integer; cdecl;
TSslLibraryInit = function:Integer; cdecl;
TSslLoadErrorStrings = procedure; cdecl;
TSslCtxSetCipherList = function(arg0: PSSL_CTX; str: PAnsiChar):Integer; cdecl;
TSslCtxNew = function(meth: PSSL_METHOD):PSSL_CTX; cdecl;
TSslCtxFree = procedure(arg0: PSSL_CTX); cdecl;
TSslSetFd = function(s: PSSL; fd: Integer):Integer; cdecl;
TSslMethodV2 = function:PSSL_METHOD; cdecl;
TSslMethodV3 = function:PSSL_METHOD; cdecl;
TSslMethodTLSV1 = function:PSSL_METHOD; cdecl;
TSslMethodTLSV11 = function:PSSL_METHOD; cdecl;
TSslMethodTLSV12 = function:PSSL_METHOD; cdecl;
TSslMethodV23 = function:PSSL_METHOD; cdecl;
TSslMethodTLS = function:PSSL_METHOD; cdecl;
TSslCtxUsePrivateKey = function(ctx: PSSL_CTX; pkey: sslptr):Integer; cdecl;
TSslCtxUsePrivateKeyASN1 = function(pk: integer; ctx: PSSL_CTX; d: sslptr; len: integer):Integer; cdecl;
TSslCtxUsePrivateKeyFile = function(ctx: PSSL_CTX; const _file: PAnsiChar; _type: Integer):Integer; cdecl;
TSslCtxUseCertificate = function(ctx: PSSL_CTX; x: SslPtr):Integer; cdecl;
TSslCtxUseCertificateASN1 = function(ctx: PSSL_CTX; len: Integer; d: SslPtr):Integer; cdecl;
TSslCtxUseCertificateFile = function(ctx: PSSL_CTX; const _file: PAnsiChar; _type: Integer):Integer; cdecl;
TSslCtxUseCertificateChainFile = function(ctx: PSSL_CTX; const _file: PAnsiChar):Integer; cdecl;
TSslCtxCheckPrivateKeyFile = function(ctx: PSSL_CTX):Integer; cdecl;
TSslCtxSetDefaultPasswdCb = procedure(ctx: PSSL_CTX; cb: SslPtr); cdecl;
TSslCtxSetDefaultPasswdCbUserdata = procedure(ctx: PSSL_CTX; u: SslPtr); cdecl;
TSslCtxLoadVerifyLocations = function(ctx: PSSL_CTX; const CAfile: PAnsiChar; const CApath: PAnsiChar):Integer; cdecl;
TSslCtxCtrl = function(ctx: PSSL_CTX; cmd: integer; larg: integer; parg: SslPtr): integer; cdecl;
TSslNew = function(ctx: PSSL_CTX):PSSL; cdecl;
TSslFree = procedure(ssl: PSSL); cdecl;
TSslAccept = function(ssl: PSSL):Integer; cdecl;
TSslConnect = function(ssl: PSSL):Integer; cdecl;
TSslShutdown = function(ssl: PSSL):Integer; cdecl;
TSslRead = function(ssl: PSSL; buf: PAnsiChar; num: Integer):Integer; cdecl;
TSslPeek = function(ssl: PSSL; buf: PAnsiChar; num: Integer):Integer; cdecl;
TSslWrite = function(ssl: PSSL; const buf: PAnsiChar; num: Integer):Integer; cdecl;
TSslPending = function(ssl: PSSL):Integer; cdecl;
TSslGetVersion = function(ssl: PSSL):PAnsiChar; cdecl;
TSslGetPeerCertificate = function(ssl: PSSL):PX509; cdecl;
TSslCtxSetVerify = procedure(ctx: PSSL_CTX; mode: Integer; arg2: SslPtr); cdecl;
TSSLGetCurrentCipher = function(s: PSSL):SslPtr; cdecl;
TSSLCipherGetName = function(c: Sslptr):PAnsiChar; cdecl;
TSSLCipherGetBits = function(c: SslPtr; alg_bits: PInteger):Integer; cdecl;
TSSLGetVerifyResult = function(ssl: PSSL):Integer; cdecl;
TSSLCtrl = function(ssl: PSSL; cmd: integer; larg: integer; parg: SslPtr):Integer; cdecl;
TSSLSetTlsextHostName = function(ssl: PSSL; buf: PAnsiChar):Integer; cdecl;
// libeay.dll
TX509New = function: PX509; cdecl;
TX509NameOneline = function(a: PX509_NAME; buf: PAnsiChar; size: Integer):PAnsiChar; cdecl;
TX509GetSubjectName = function(a: PX509):PX509_NAME; cdecl;
TX509GetIssuerName = function(a: PX509):PX509_NAME; cdecl;
TX509NameHash = function(x: PX509_NAME):Cardinal; cdecl;
TX509Digest = function(data: PX509; _type: PEVP_MD; md: PAnsiChar; len: PInteger):Integer; cdecl;
TX509print = function(b: PBIO; a: PX509): integer; cdecl;
TX509SetVersion = function(x: PX509; version: integer): integer; cdecl;
TX509SetPubkey = function(x: PX509; pkey: EVP_PKEY): integer; cdecl;
TX509SetIssuerName = function(x: PX509; name: PX509_NAME): integer; cdecl;
TX509NameAddEntryByTxt = function(name: PX509_NAME; field: PAnsiChar; _type: integer;
bytes: PAnsiChar; len, loc, _set: integer): integer; cdecl;
TX509Sign = function(x: PX509; pkey: EVP_PKEY; const md: PEVP_MD): integer; cdecl;
TX509GmtimeAdj = function(s: PASN1_UTCTIME; adj: integer): PASN1_UTCTIME; cdecl;
TX509SetNotBefore = function(x: PX509; tm: PASN1_UTCTIME): integer; cdecl;
TX509SetNotAfter = function(x: PX509; tm: PASN1_UTCTIME): integer; cdecl;
TX509GetSerialNumber = function(x: PX509): PASN1_INTEGER; cdecl;
TEvpPkeyNew = function: EVP_PKEY; cdecl;
TEvpPkeyFree = procedure(pk: EVP_PKEY); cdecl;
TEvpPkeyAssign = function(pkey: EVP_PKEY; _type: integer; key: Prsa): integer; cdecl;
TEvpGetDigestByName = function(Name: PAnsiChar): PEVP_MD; cdecl;
TEVPcleanup = procedure; cdecl;
TSSLeayversion = function(t: integer): PAnsiChar; cdecl;
TErrErrorString = procedure(e: integer; buf: PAnsiChar; len: integer); cdecl;
TErrGetError = function: integer; cdecl;
TErrClearError = procedure; cdecl;
TErrFreeStrings = procedure; cdecl;
TErrRemoveState = procedure(pid: integer); cdecl;
TOPENSSLaddallalgorithms = procedure; cdecl;
TCRYPTOcleanupAllExData = procedure; cdecl;
TRandScreen = procedure; cdecl;
TBioNew = function(b: PBIO_METHOD): PBIO; cdecl;
TBioFreeAll = procedure(b: PBIO); cdecl;
TBioSMem = function: PBIO_METHOD; cdecl;
TBioCtrlPending = function(b: PBIO): integer; cdecl;
TBioRead = function(b: PBIO; Buf: PAnsiChar; Len: integer): integer; cdecl;
TBioWrite = function(b: PBIO; Buf: PAnsiChar; Len: integer): integer; cdecl;
Td2iPKCS12bio = function(b:PBIO; Pkcs12: SslPtr): SslPtr; cdecl;
TPKCS12parse = function(p12: SslPtr; pass: PAnsiChar; var pkey, cert, ca: SslPtr): integer; cdecl;
TPKCS12free = procedure(p12: SslPtr); cdecl;
TRsaGenerateKey = function(bits, e: integer; callback: PFunction; cb_arg: SslPtr): PRSA; cdecl;
TAsn1UtctimeNew = function: PASN1_UTCTIME; cdecl;
TAsn1UtctimeFree = procedure(a: PASN1_UTCTIME); cdecl;
TAsn1IntegerSet = function(a: PASN1_INTEGER; v: integer): integer; cdecl;
TAsn1IntegerGet = function(a: PASN1_INTEGER): integer; cdecl; {pf}
Ti2dX509bio = function(b: PBIO; x: PX509): integer; cdecl;
Td2iX509bio = function(b:PBIO; x:PX509): PX509; cdecl; {pf}
TPEMReadBioX509 = function(b:PBIO; {var x:PX509;}x:PSslPtr; callback:PFunction; cb_arg:SslPtr): PX509; cdecl; {pf}
TSkX509PopFree = procedure(st: PSTACK; func: TSkPopFreeFunc); cdecl; {pf}
Ti2dPrivateKeyBio= function(b: PBIO; pkey: EVP_PKEY): integer; cdecl;
// 3DES functions
TDESsetoddparity = procedure(Key: des_cblock); cdecl;
TDESsetkeychecked = function(key: des_cblock; schedule: des_key_schedule): Integer; cdecl;
TDESecbencrypt = procedure(Input: des_cblock; output: des_cblock; ks: des_key_schedule; enc: Integer); cdecl;
//thread lock functions
TCRYPTOnumlocks = function: integer; cdecl;
TCRYPTOSetLockingCallback = procedure(cb: Sslptr); cdecl;
var
// libssl.dll
_SslGetError: TSslGetError = nil;
_SslLibraryInit: TSslLibraryInit = nil;
_SslLoadErrorStrings: TSslLoadErrorStrings = nil;
_SslCtxSetCipherList: TSslCtxSetCipherList = nil;
_SslCtxNew: TSslCtxNew = nil;
_SslCtxFree: TSslCtxFree = nil;
_SslSetFd: TSslSetFd = nil;
_SslMethodV2: TSslMethodV2 = nil;
_SslMethodV3: TSslMethodV3 = nil;
_SslMethodTLSV1: TSslMethodTLSV1 = nil;
_SslMethodTLSV11: TSslMethodTLSV11 = nil;
_SslMethodTLSV12: TSslMethodTLSV12 = nil;
_SslMethodV23: TSslMethodV23 = nil;
_SslMethodTLS: TSslMethodTLS = nil;
_SslCtxUsePrivateKey: TSslCtxUsePrivateKey = nil;
_SslCtxUsePrivateKeyASN1: TSslCtxUsePrivateKeyASN1 = nil;
_SslCtxUsePrivateKeyFile: TSslCtxUsePrivateKeyFile = nil;
_SslCtxUseCertificate: TSslCtxUseCertificate = nil;
_SslCtxUseCertificateASN1: TSslCtxUseCertificateASN1 = nil;
_SslCtxUseCertificateFile: TSslCtxUseCertificateFile = nil;
_SslCtxUseCertificateChainFile: TSslCtxUseCertificateChainFile = nil;
_SslCtxCheckPrivateKeyFile: TSslCtxCheckPrivateKeyFile = nil;
_SslCtxSetDefaultPasswdCb: TSslCtxSetDefaultPasswdCb = nil;
_SslCtxSetDefaultPasswdCbUserdata: TSslCtxSetDefaultPasswdCbUserdata = nil;
_SslCtxLoadVerifyLocations: TSslCtxLoadVerifyLocations = nil;
_SslCtxCtrl: TSslCtxCtrl = nil;
_SslNew: TSslNew = nil;
_SslFree: TSslFree = nil;
_SslAccept: TSslAccept = nil;
_SslConnect: TSslConnect = nil;
_SslShutdown: TSslShutdown = nil;
_SslRead: TSslRead = nil;
_SslPeek: TSslPeek = nil;
_SslWrite: TSslWrite = nil;
_SslPending: TSslPending = nil;
_SslGetVersion: TSslGetVersion = nil;
_SslGetPeerCertificate: TSslGetPeerCertificate = nil;
_SslCtxSetVerify: TSslCtxSetVerify = nil;
_SSLGetCurrentCipher: TSSLGetCurrentCipher = nil;
_SSLCipherGetName: TSSLCipherGetName = nil;
_SSLCipherGetBits: TSSLCipherGetBits = nil;
_SSLGetVerifyResult: TSSLGetVerifyResult = nil;
_SSLCtrl: TSSLCtrl = nil;
// libeay.dll
_X509New: TX509New = nil;
_X509NameOneline: TX509NameOneline = nil;
_X509GetSubjectName: TX509GetSubjectName = nil;
_X509GetIssuerName: TX509GetIssuerName = nil;
_X509NameHash: TX509NameHash = nil;