-
Notifications
You must be signed in to change notification settings - Fork 0
/
ck_ssl.c
4438 lines (4033 loc) · 147 KB
/
ck_ssl.c
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
char *cksslv = "SSL/TLS support, 9.0.233, 24 Dec 2015";
/*
C K _ S S L . C -- OpenSSL Interface for C-Kermit
Copyright (C) 1985, 2017,
Trustees of Columbia University in the City of New York.
All rights reserved. See the C-Kermit COPYING.TXT file or the
copyright text in the ckcmai.c module for disclaimer and permissions.
Author: Jeffrey E Altman (jaltman@secure-endpoints.com)
Secure Endpoints Inc., New York City
Provides:
. Telnet Auth SSL option compatible with Tim Hudson's hack.
. Telnet START_TLS option
. Configuration of certificate and key files
. Certificate verification and revocation list checks
. Client certificate to user id routine
Note: This code is written to be compatible with OpenSSL 0.9.6[abcdefgh]
and 0.9.7 beta 5 and later, and (since July 2012) 1.0.x.
It will also compile with version 0.9.5 although that is discouraged
due to security weaknesses in that release.
Adapted for LibreSSL by Bernard Spil, December 2015 (search "Spil")
*/
#include "ckcsym.h"
#include "ckcdeb.h"
#ifdef CK_SSL
#include "ckcnet.h"
#include "ckuath.h"
#include <stdlib.h>
#include <string.h>
#ifdef UNIX
#include <netinet/in.h>
#ifndef FREEBSD4
#include <arpa/inet.h>
#endif /* FREEBSD4 */
#endif /* UNIX */
#ifdef DEC_TCPIP
#include <time.h>
#include <inet.h>
#endif /* DEC_TCPIP */
#ifdef OS2
extern char exedir[];
#ifdef NT
char * GetAppData(int);
#endif
#endif /* OS2 */
extern int quiet; /* fdc - Mon Nov 28 11:44:15 2005 */
static int ssl_installed = 1;
#endif /* CK_SSL */
int
ck_ssh_is_installed()
{
#ifdef SSHBUILTIN
#ifdef SSLDLL
#ifdef NT
extern HINSTANCE hCRYPTO;
#else /* NT */
extern HMODULE hCRYPTO;
#endif /* NT */
debug(F111,"ck_ssh_is_installed","hCRYPTO",hCRYPTO);
return(ssl_installed && (hCRYPTO != NULL));
#else /* SSLDLL */
return(ssl_installed);
#endif /* SSLDLL */
#else
return 0;
#endif
}
int
#ifdef CK_ANSIC
ck_ssleay_is_installed(void)
#else
ck_ssleay_is_installed()
#endif
{
#ifdef CK_SSL
#ifdef SSLDLL
#ifdef NT
extern HINSTANCE hSSL, hCRYPTO;
#else /* NT */
extern HMODULE hSSL, hCRYPTO;
#endif /* NT */
debug(F111,"ck_ssleay_is_installed","hSSL",hSSL);
debug(F111,"ck_ssleay_is_installed","hCRYPTO",hCRYPTO);
return(ssl_installed && (hSSL != NULL) && (hCRYPTO != NULL));
#else /* SSLDLL */
return(ssl_installed);
#endif /* SSLDLL */
#else /* CK_SSL */
return(0);
#endif /* CK_SSL */
}
#ifdef CK_SSL
#include "ckcker.h"
#include "ckucmd.h" /* For struct keytab */
#include "ckctel.h"
#include "ck_ssl.h"
#ifdef UNIX
#include <pwd.h> /* Password file for home directory */
#endif /* UNIX */
#ifdef OS2
#include <process.h>
#endif /* OS2 */
#ifdef OS2ONLY
#include "ckotcp.h"
#endif /* OS2ONLY */
#ifdef SSLDLL
int ssl_finished_messages = 0;
#else /* SSLDLL */
#ifdef OPENSSL_VERSION_NUMBER
int ssl_finished_messages = (OPENSSL_VERSION_NUMBER >= 0x0090581fL);
#else
!ERROR This module requires OpenSSL 0.9.5a or higher
#endif /* OPENSSL_VERSION_NUMBER */
#endif /* SSLDLL */
static int auth_ssl_valid = 0;
static char *auth_ssl_name = 0; /* this holds the oneline name */
char ssl_err[SSL_ERR_BFSZ]="";
BIO *bio_err=NULL;
X509_STORE *crl_store = NULL;
#ifndef NOFTP
#ifndef SYSFTP
SSL *ssl_ftp_con = NULL;
SSL_CTX *ssl_ftp_ctx = NULL;
SSL *ssl_ftp_data_con = NULL;
int ssl_ftp_active_flag = 0;
int ssl_ftp_data_active_flag = 0;
#endif /* SYSFTP */
#endif /* NOFTP */
#ifndef NOHTTP
SSL *tls_http_con = NULL;
SSL_CTX *tls_http_ctx = NULL;
int tls_http_active_flag = 0;
int ssl_http_initialized = 0;
#endif /* NOHTTP */
SSL_CTX *ssl_ctx = NULL;
SSL *ssl_con = NULL;
int ssl_debug_flag = 0;
int ssl_verbose_flag = 0;
int ssl_only_flag = 0;
int ssl_raw_flag = 0;
int ssl_active_flag = 0;
int ssl_verify_flag = SSL_VERIFY_PEER;
int ssl_certsok_flag = 0;
char *ssl_rsa_cert_file = NULL;
char *ssl_rsa_cert_chain_file = NULL;
char *ssl_rsa_key_file = NULL;
char *ssl_dsa_cert_file = NULL;
char *ssl_dsa_cert_chain_file = NULL;
char *ssl_dh_key_file = NULL;
char *ssl_crl_file = NULL;
char *ssl_crl_dir = NULL;
char *ssl_verify_file = NULL;
char *ssl_verify_dir = NULL;
char *ssl_dh_param_file = NULL;
char *ssl_cipher_list = NULL;
char *ssl_rnd_file = NULL;
SSL_CTX *tls_ctx = NULL;
SSL *tls_con = NULL;
int tls_only_flag = 0;
int tls_raw_flag = 0;
int tls_active_flag = 0;
int ssl_initialized = 0;
int ssl_verify_depth = -1; /* used to track depth in verify routines */
/* compile this set to 1 to negotiate SSL/TLS but not actually start it */
int ssl_dummy_flag=0;
extern int inserver;
extern int debses;
extern int accept_complete;
extern char szHostName[], szUserNameRequested[], szUserNameAuthenticated[];
_PROTOTYP(int X509_to_user,(X509 *, char *, int));
static int verbosity = 0; /* Message control */
static VOID
setverbosity() {
verbosity = ssl_verbose_flag;
if (quiet) verbosity = 0;
}
int
#ifdef CK_ANSIC
ssl_server_verify_callback(int ok, X509_STORE_CTX * ctx)
#else /* CK_ANSIC */
ssl_server_verify_callback(ok, ctx)
int ok;
X509_STORE_CTX *ctx;
#endif /* CK_ANSIC */
{
static char *saved_subject=NULL;
char *subject=NULL, *issuer=NULL;
int depth,error;
X509 *xs = NULL;
if ( ssl_certsok_flag )
return(1);
setverbosity();
error=X509_STORE_CTX_get_error(ctx);
depth=X509_STORE_CTX_get_error_depth(ctx);
xs=X509_STORE_CTX_get_current_cert(ctx);
if (depth==0) {
/* clear things */
if (saved_subject!=NULL) {
free(saved_subject);
saved_subject=NULL;
}
if (auth_ssl_name!=NULL) {
free(auth_ssl_name);
auth_ssl_name=NULL;
}
}
if (ssl_debug_flag && !inserver) {
printf("ssl:server_verify_callback:depth=%d ok=%d err=%d-%s\r\n",
depth,ok,error,X509_verify_cert_error_string(error));
}
/* first thing is to have a meaningful name for the current
* certificate that is being verified ... and if we cannot
* determine that then something is seriously wrong!
*/
makestr(&subject,
(char *)X509_NAME_oneline(X509_get_subject_name(xs),NULL,0));
makestr(&issuer,
(char *)X509_NAME_oneline(X509_get_issuer_name(xs),NULL,0));
if (!subject || !subject[0] || !issuer || !issuer[0]) {
ok = 0;
goto return_time;
}
if (verbosity && !inserver && depth != ssl_verify_depth) {
printf("[%d] Certificate Subject:\r\n%s\r\n",depth,subject);
printf("[%d] Certificate Issuer:\r\n%s\r\n",depth,issuer);
ssl_verify_depth = depth;
}
/* make sure that the certificate that has been presented */
/* has not been revoked (if we have been given a CRL. */
ok = ssl_verify_crl(ok, ctx);
/* if we have any form of error in secure mode we reject the connection */
if (error!=X509_V_OK) {
if (inserver) {
#ifdef CKSYSLOG
if (ckxsyslog >= SYSLG_LI && ckxlogging) {
cksyslog(SYSLG_LI, 0,
"X.509 Certificate verify failure",
(char *) subject,
(char *)X509_verify_cert_error_string(error)
);
}
#endif /* CKSYSLOG */
} else {
if ( ssl_verify_flag &
(SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
printf("Error: ");
else
printf("Warning: ");
switch (error) {
case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
printf("Certificate is self signed.\r\n");
break;
case X509_V_ERR_CERT_HAS_EXPIRED:
printf("Certificate has expired.\r\n");
break;
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
printf(
"Certificate issuer's certificate isn't available locally.\r\n");
break;
case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
printf("Unable to verify leaf signature.\r\n");
break;
case X509_V_ERR_CERT_REVOKED:
printf("Certificate revoked.\r\n");
break;
default:
printf("Error %d while verifying certificate.\r\n",
X509_STORE_CTX_get_error(ctx));
break;
}
}
ok = !(ssl_verify_flag & SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
} else {
/* if we got all the way to the top of the tree then
* we *can* use this certificate for a username to
* match ... in all other cases we must not!
*/
auth_ssl_name = saved_subject;
saved_subject = NULL;
}
return_time:
/* save the name if at least the first level is okay */
if (depth == 0 && ok)
makestr(&saved_subject,subject);
/* clean up things */
if (subject!=NULL)
free(subject);
if (issuer!=NULL)
free(issuer);
return ok;
}
int
#ifdef CK_ANSIC
ssl_client_verify_callback(int ok, X509_STORE_CTX * ctx)
#else
ssl_client_verify_callback(ok, ctx)
int ok;
X509_STORE_CTX *ctx;
#endif
{
char subject[256]="", issuer[256]="";
int depth, error, len;
X509 *xs;
setverbosity();
xs=X509_STORE_CTX_get_current_cert(ctx);
error=X509_STORE_CTX_get_error(ctx);
depth=X509_STORE_CTX_get_error_depth(ctx);
if ( ssl_debug_flag )
printf("ssl:client_verify_callback:depth=%d ok=%d err=%d-%s\r\n",
depth,ok,error,X509_verify_cert_error_string(error));
if ( ssl_certsok_flag ) {
ok = 1;
}
/* first thing is to have a meaningful name for the current
* certificate that is being verified ... and if we cannot
* determine that then something is seriously wrong!
*/
#ifdef XN_FLAG_SEP_MULTILINE
X509_NAME_print_ex(bio_err,X509_get_subject_name(xs),4,
XN_FLAG_SEP_MULTILINE);
len = BIO_read(bio_err,subject,256);
subject[len < 256 ? len : 255] = '\0';
if (!subject[0]) {
ERR_print_errors(bio_err);
len = BIO_read(bio_err,ssl_err,SSL_ERR_BFSZ);
ssl_err[len < SSL_ERR_BFSZ ? len : SSL_ERR_BFSZ] = '\0';
uq_ok("X.509 Subject Name unavailable", ssl_err, 1, NULL, 0);
ok=0;
goto return_time;
}
X509_NAME_print_ex(bio_err,X509_get_issuer_name(xs),4,
XN_FLAG_SEP_MULTILINE);
len = BIO_read(bio_err,issuer,256);
issuer[len < 256 ? len : 255] = '\0';
if (!issuer[0]) {
ERR_print_errors(bio_err);
len = BIO_read(bio_err,ssl_err,SSL_ERR_BFSZ);
ssl_err[len < SSL_ERR_BFSZ ? len : SSL_ERR_BFSZ] = '\0';
uq_ok("X.509 Issuer Name unavailable", ssl_err, 1, NULL, 0);
ok=0;
goto return_time;
}
#else /* XN_FLAG_SEP_MULTILINE */
X509_NAME_oneline(X509_get_subject_name(xs),subject,256);
if (!subject[0]) {
int len;
ERR_print_errors(bio_err);
len = BIO_read(bio_err,ssl_err,SSL_ERR_BFSZ);
ssl_err[len < SSL_ERR_BFSZ ? len : SSL_ERR_BFSZ] = '\0';
uq_ok("X.509 Subject Name unavailable", ssl_err, 1, NULL, 0);
ok=0;
goto return_time;
}
X509_NAME_oneline(X509_get_issuer_name(xs),issuer,256);
if (!issuer[0]) {
int len;
ERR_print_errors(bio_err);
len = BIO_read(bio_err,ssl_err,SSL_ERR_BFSZ);
ssl_err[len < SSL_ERR_BFSZ ? len : SSL_ERR_BFSZ] = '\0';
uq_ok("X.509 Issuer Name unavailable", ssl_err, 1, NULL, 0);
ok=0;
goto return_time;
}
#endif /* XN_FLAG_SEP_MULTILINE */
if (verbosity && depth != ssl_verify_depth) {
printf("[%d] Certificate Subject:\r\n%s\r\n",depth,subject);
printf("[%d] Certificate Issuer:\r\n%s\r\n",depth,issuer);
ssl_verify_depth = depth;
}
ok = ssl_verify_crl(ok, ctx);
if ( !ok ) {
char prefix[1024];
/* if the server is using a self signed certificate then
* we need to decide if that is good enough for us to
* accept ...
*/
switch ( error ) {
case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: {
if (ssl_verify_flag & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) {
/* make 100% sure that in secure more we drop the
* connection if the server does not have a
* real certificate!
*/
ckmakxmsg(prefix,1024,
"Error: Server has a self-signed certificate\n",
"[",ckitoa(depth),"] Certificate Subject=\n",subject,
"\n[",ckitoa(depth),"] Certificate Issuer=\n",issuer,
NULL,NULL,NULL);
uq_ok(prefix, "Rejecting Connection", 1, NULL, 0);
/* sometimes it is really handy to be able to debug things
* and still get a connection!
*/
if (ssl_debug_flag) {
printf("SSL: debug -> ignoring cert required!\r\n");
ok=1;
} else {
ok=0;
}
goto return_time;
} else if (ssl_verify_flag != SSL_VERIFY_NONE) {
ckmakxmsg(prefix,1024,
"Warning: Server has a self-signed certificate\n",
"[",ckitoa(depth),"] Certificate Subject=\n",subject,
"\n[",ckitoa(depth),"] Certificate Issuer=\n",issuer,
NULL,NULL,NULL);
ok = uq_ok(prefix,
"Continue? (Y/N) ",
3, NULL, 0);
if ( ok < 0 )
ok = 0;
goto return_time;
}
}
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
if (ssl_verify_flag & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) {
/* make 100% sure that in secure more we drop the
* connection if the server does not have a
* real certificate!
*/
ckmakxmsg(prefix,1024,
"Error: ",
(char *)X509_verify_cert_error_string(error),
"\nCertificate Issuer=\n",issuer,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
uq_ok(prefix, "Rejecting Connection", 1, NULL, 0);
/* sometimes it is really handy to be able to debug things
* and still get a connection!
*/
if (ssl_debug_flag) {
printf("SSL: debug -> ignoring cert required!\r\n");
ok=1;
} else {
ok=0;
}
goto return_time;
} else if (ssl_verify_flag != SSL_VERIFY_NONE) {
ckmakxmsg(prefix,1024,
"Warning: ",
(char *)X509_verify_cert_error_string(error),
"\nCertificate Issuer=\n",issuer,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
ok = uq_ok(prefix, "Continue (Y/N)", 3, NULL, 0);
goto return_time;
}
break;
case X509_V_ERR_CERT_NOT_YET_VALID:
case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
if (ssl_verify_flag & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) {
int len;
/* make 100% sure that in secure more we drop the
* connection if the server does not have a
* real certificate!
*/
ASN1_TIME_print(bio_err,X509_get_notBefore(xs));
len = BIO_read(bio_err,ssl_err,SSL_ERR_BFSZ);
ssl_err[len < SSL_ERR_BFSZ ? len : SSL_ERR_BFSZ] = '\0';
ckmakxmsg(prefix,1024,
"Error: ",
(char *)X509_verify_cert_error_string(error),
"\nCertificate Subject=\n",subject,
"\nnotBefore=",ssl_err,
NULL,NULL,NULL,NULL,NULL,NULL);
uq_ok(prefix, "Rejecting Connection", 1, NULL, 0);
/* sometimes it is really handy to be able to debug things
* and still get a connection!
*/
if (ssl_debug_flag) {
printf("SSL: debug -> ignoring cert required!\r\n");
ok=1;
} else {
ok=0;
}
goto return_time;
} else if (ssl_verify_flag != SSL_VERIFY_NONE) {
int len;
ASN1_TIME_print(bio_err,X509_get_notBefore(xs));
len = BIO_read(bio_err,ssl_err,SSL_ERR_BFSZ);
ssl_err[len < SSL_ERR_BFSZ ? len : SSL_ERR_BFSZ] = '\0';
ckmakxmsg(prefix,1024,
"Warning: ",
(char *)X509_verify_cert_error_string(error),
"\nCertificate Subject=\n",subject,
"\n notBefore=",ssl_err,
NULL,NULL,NULL,NULL,NULL,NULL);
ok = uq_ok(prefix, "Continue (Y/N)", 3, NULL, 0);
}
break;
case X509_V_ERR_CERT_HAS_EXPIRED:
case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
if (ssl_verify_flag & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) {
int len;
/* make 100% sure that in secure more we drop the
* connection if the server does not have a
* real certificate!
*/
ASN1_TIME_print(bio_err,X509_get_notAfter(xs));
len = BIO_read(bio_err,ssl_err,SSL_ERR_BFSZ);
ssl_err[len < SSL_ERR_BFSZ ? len : SSL_ERR_BFSZ] = '\0';
ckmakxmsg(prefix,1024,
"Error: ",
(char *)X509_verify_cert_error_string(error),
"\nCertificate Subject=\n",subject,
"\n notAfter=",ssl_err,
NULL,NULL,NULL,NULL,NULL,NULL);
uq_ok(prefix, "Rejecting Connection", 1, NULL, 0);
/* sometimes it is really handy to be able to debug things
* and still get a connection!
*/
if (ssl_debug_flag) {
printf("SSL: debug -> ignoring cert required!\r\n");
ok=1;
} else {
ok=0;
}
goto return_time;
} else if (ssl_verify_flag != SSL_VERIFY_NONE) {
int len;
ASN1_TIME_print(bio_err,X509_get_notAfter(xs));
len = BIO_read(bio_err,ssl_err,SSL_ERR_BFSZ);
ssl_err[len < SSL_ERR_BFSZ ? len : SSL_ERR_BFSZ] = '\0';
ckmakxmsg(prefix,1024,
"Warning: ",
(char *)X509_verify_cert_error_string(error),
"\nCertificate Subject=\n",subject,
"\n notAfter=",ssl_err,
NULL,NULL,NULL,NULL,NULL,NULL);
ok = uq_ok(prefix, "Continue (Y/N)", 3, NULL, 0);
}
break;
case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
/*
* When an SSL server sends its certificates to the client there
* are two" conventions": one is to send the complete certificate
* chain and the other is to send the whole chain apart from the
* root.
*
* You don't usually need the root because the root is normally
* stored and trusted locally.
*
* So if you get the whole chain it will complain about the self
* signed certificate whereas if the root is missing it says it
* can't find the issuer certificate.
*/
if (ssl_verify_flag & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) {
/* make 100% sure that in secure more we drop the
* connection if the server does not have a
* real certificate!
*/
ckmakxmsg(prefix,1024,
"Error: ",
(char *)X509_verify_cert_error_string(error),
"\nCertificate Issuer=\n",issuer,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
uq_ok(prefix, "Rejecting Connection", 1, NULL, 0);
/* sometimes it is really handy to be able to debug things
* and still get a connection!
*/
if (ssl_debug_flag) {
printf("SSL: debug -> ignoring cert required!\r\n");
ok=1;
} else {
ok=0;
}
goto return_time;
} else if (ssl_verify_flag != SSL_VERIFY_NONE) {
ckmakxmsg(prefix,1024,
"Warning: ",
(char *)X509_verify_cert_error_string(error),
"\nCertificate Issuer=\n",issuer,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
ok = uq_ok(prefix, "Continue (Y/N)", 3, NULL, 0);
#ifdef NT
if (ok) {
/* if the user decides to accept the certificate
* offer to store it for future connections in
* the user's private store
*/
ok = uq_ok(
"Do you wish to store the certificate to verify future connections?",
"Continue (Y/N)", 3, NULL, 0);
if (ok)
ck_X509_save_cert_to_user_store(xs);
}
#endif /* NT */
}
break;
case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
case X509_V_ERR_UNABLE_TO_GET_CRL:
case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
case X509_V_ERR_CERT_SIGNATURE_FAILURE:
case X509_V_ERR_CRL_SIGNATURE_FAILURE:
case X509_V_ERR_CRL_NOT_YET_VALID:
case X509_V_ERR_CRL_HAS_EXPIRED:
case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
case X509_V_ERR_OUT_OF_MEM:
case X509_V_ERR_CERT_CHAIN_TOO_LONG:
case X509_V_ERR_CERT_REVOKED:
case X509_V_ERR_APPLICATION_VERIFICATION:
default:
if (ssl_verify_flag & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) {
/* make 100% sure that in secure mode we drop the
* connection if the server does not have a
* real certificate!
*/
ckmakxmsg(prefix,1024,
"Error: ",
(char *)X509_verify_cert_error_string(error),
"\nCertificate Subject=\n",subject,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
uq_ok(prefix, "Rejecting Connection", 1, NULL, 0);
/* sometimes it is really handy to be able to debug things
* and still get a connection!
*/
if (ssl_debug_flag) {
printf("SSL: debug -> ignoring cert required!\r\n");
ok=1;
} else {
ok=0;
}
goto return_time;
} else if (ssl_verify_flag != SSL_VERIFY_NONE) {
ckmakxmsg(prefix,1024,
"Warning: ",
(char *)X509_verify_cert_error_string(error),
"\nCertificate Subject=\n",subject,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
ok = uq_ok(prefix, "Continue (Y/N)", 3, NULL, 0);
}
break;
}
}
return_time:
if ( ssl_debug_flag )
printf("ssl:client_verify_callback => ok: %d\r\n",ok);
return ok;
}
VOID
#ifdef CK_ANSIC
ssl_client_info_callback(const SSL *s, int where, int ret)
#else
ssl_client_info_callback(s,where,ret)
const SSL *s;
int where;
int ret;
#endif /* CK_ANSIC */
{
if (inserver || !ssl_debug_flag)
return;
setverbosity();
switch ( where ) {
case SSL_CB_CONNECT_LOOP:
printf("SSL_connect:%s %s\r\n",
SSL_state_string((SSL *)s),SSL_state_string_long((SSL *)s));
break;
case SSL_CB_CONNECT_EXIT:
if (ret == 0) {
printf("SSL_connect:failed in %s %s\r\n",
SSL_state_string((SSL *)s),SSL_state_string_long((SSL *)s));
} else if (ret < 0) {
printf("SSL_connect:error in %s %s\r\n",
SSL_state_string((SSL *)s),SSL_state_string_long((SSL *)s));
}
break;
case SSL_CB_ACCEPT_LOOP:
printf("SSL_accept:%s %s\r\n",
SSL_state_string((SSL *)s),SSL_state_string_long((SSL *)s));
break;
case SSL_CB_ACCEPT_EXIT:
if (ret == 0) {
printf("SSL_accept:failed in %s %s\r\n",
SSL_state_string((SSL *)s),SSL_state_string_long((SSL *)s));
} else if (ret < 0) {
printf("SSL_accept:error in %s %s\r\n",
SSL_state_string((SSL *)s),SSL_state_string_long((SSL *)s));
}
break;
case SSL_CB_READ_ALERT:
printf("SSL_read_alert\r\n");
break;
case SSL_CB_WRITE_ALERT:
printf("SSL_write_alert\r\n");
break;
case SSL_CB_HANDSHAKE_START:
printf("SSL_handshake:%s %s\r\n",
SSL_state_string((SSL *)s),SSL_state_string_long((SSL *)s));
break;
case SSL_CB_HANDSHAKE_DONE:
printf("SSL_handshake:%s %s\r\n",
SSL_state_string((SSL *)s),SSL_state_string_long((SSL *)s));
break;
}
}
#ifdef USE_CERT_CB
/* Return 1, client cert is available */
/* Return 0, no client cert is available */
/* Return -1, callback must be called again. SSL_want_x509_lookup() == 1 */
int
#ifdef CK_ANSIC
ssl_client_cert_callback(SSL * s, X509 ** x509, EVP_PKEY ** pkey)
#else /* CK_ANSIC */
ssl_client_cert_callback(s, x509, pkey)
SSL * s;
X509 ** x509;
EVP_PKEY ** pkey;
#endif /* CK_ANSIC */
{
setverbosity();
if ( ssl_debug_flag ) {
const char * cipher_list=SSL_get_cipher(s);
printf("ssl_client_cert_callback called (%s)\r\n",
cipher_list?cipher_list:"UNKNOWN");
}
#ifdef COMMENT
if ( s == tls_con ) {
if (tls_load_certs(tls_cts,tls_con,0)) {
*x509 = SSL_get_certificate(s);
*pkey = SSL_get_privatekey(s);
return(1);
}
} else if ( s == ssl_con ) {
if (tls_load_certs(ssl_ctx,ssl_con,0)) {
*x509 = SSL_get_certificate(s);
*pkey = SSL_get_privatekey(s);
return(1);
}
}
return(0);
#else /* COMMENT */
return(0);
#endif /* COMMENT */
}
#endif /* USE_CERT_CB */
#ifndef MS_CALLBACK
#define MS_CALLBACK
#endif /* MS_CALLBACK */
static RSA MS_CALLBACK *
#ifdef CK_ANSIC
tmp_rsa_cb(SSL * s, int export, int keylength)
#else /* CK_ANSIC */
tmp_rsa_cb(s,export,keylength)
SSL *s;
int export;
int keylength;
#endif /* CK_ANSIC */
{
static RSA *rsa_tmp=NULL;
#ifndef NO_RSA
if (rsa_tmp == NULL)
{
if (ssl_debug_flag)
printf("Generating temporary (%d bit) RSA key...\r\n",keylength);
rsa_tmp=RSA_generate_key(keylength,RSA_F4,NULL,NULL);
if (ssl_debug_flag)
printf("\r\n");
}
#else /* NO_RSA */
if (ssl_debug_flag)
printf("Unable to generate temporary RSA key...\r\n");
#endif
return(rsa_tmp);
}
#ifndef NO_DH
static unsigned char dh512_p[]={
0xE9,0x4E,0x3A,0x64,0xFA,0x65,0x5F,0xA6,0x44,0xC7,0xFC,0xF1,
0x16,0x8B,0x11,0x11,0x7A,0xF0,0xB2,0x49,0x80,0x56,0xA3,0xF8,
0x0F,0x7D,0x01,0x68,0x5D,0xF6,0x8A,0xEA,0x8C,0xDD,0x01,0xDC,
0x43,0x18,0xE0,0xC4,0x89,0x80,0xE6,0x2D,0x44,0x77,0x45,0xFD,
0xBA,0xFC,0x43,0x35,0x12,0xC0,0xED,0x32,0xD3,0x16,0xEF,0x51,
0x09,0x44,0xA2,0xDB,
};
static unsigned char dh512_g[]={
0x05,
};
static unsigned char dh768_p[]={
0x8B,0x2A,0x8C,0x6C,0x0F,0x87,0xC7,0x34,0xEE,0x2E,0xFB,0x60,
0x94,0xB3,0xBF,0x95,0xBA,0x84,0x74,0x86,0xEA,0xE0,0xA4,0x33,
0xE0,0x8F,0x7C,0x79,0x5C,0x62,0xE2,0x91,0xC5,0x6D,0x68,0xB9,
0x6C,0x5E,0x4E,0x94,0x0C,0x8E,0x56,0x8E,0xEB,0x98,0x7C,0x6E,
0x0E,0xF2,0xD5,0xAA,0x22,0x27,0x3F,0x0F,0xAF,0x10,0xB5,0x0B,
0x16,0xCC,0x05,0x27,0xBB,0x58,0x6D,0x61,0x4B,0x2B,0xAB,0xDC,
0x6A,0x15,0xBC,0x36,0x75,0x4D,0xEC,0xAB,0xFA,0xB6,0xE1,0xB1,
0x13,0x70,0xD8,0x77,0xCD,0x5E,0x51,0x77,0x81,0x0D,0x77,0x43,
};
static unsigned char dh768_g[]={
0x05,
};
static unsigned char dh1024_p[]={
0xA4,0x75,0xCF,0x35,0x00,0xAF,0x3C,0x17,0xCE,0xB0,0xD0,0x52,
0x43,0xA0,0x0E,0xFA,0xA2,0xC9,0xBE,0x0B,0x76,0x7A,0xD9,0x2E,
0xF4,0x97,0xAC,0x02,0x24,0x69,0xF6,0x36,0x4F,0xAB,0xCC,0x43,
0xC1,0x74,0xFF,0xA3,0xD4,0x04,0x0F,0x11,0x2B,0x6D,0x8C,0x47,
0xC9,0xCF,0x40,0x93,0x9B,0x7D,0x1E,0x52,0x85,0xB2,0x17,0x55,
0x9C,0xF2,0x41,0x02,0x2A,0x9D,0x5F,0x24,0x22,0xC6,0x04,0xC4,
0xAB,0x92,0x6D,0xC7,0xC8,0xF3,0x41,0x58,0x6C,0x86,0xFD,0xB8,
0x0F,0x2D,0xDD,0xBF,0xA8,0x40,0x0C,0x58,0xC8,0xF2,0x3F,0x18,
0xEF,0xF1,0x93,0x3E,0xBA,0x16,0x41,0xBE,0x32,0x6C,0xC5,0x63,
0xFF,0x8A,0x02,0x3D,0xAC,0xD5,0x5A,0x49,0x64,0x34,0x14,0x2E,
0xFB,0x2E,0xE7,0x39,0x1A,0x0F,0x3C,0x33,
};
static unsigned char dh1024_g[]={
0x05,
};
static unsigned char dh1536_p[]={
0xA3,0x2B,0x75,0x0E,0x7B,0x31,0x82,0xCA,0xF2,0xFC,0xF3,0x3D,
0xCE,0x5F,0xCD,0x5B,0x95,0xF6,0x2F,0xA4,0x5D,0x08,0x26,0xD2,
0x5F,0xC0,0x3F,0xC5,0xD8,0xA2,0xFE,0x83,0x26,0xBC,0xEB,0x7D,
0xF0,0x4E,0xD2,0xA6,0xBB,0x3C,0x88,0x63,0xCE,0x98,0xDE,0x08,
0xE2,0xE1,0xAF,0xE2,0x38,0xA8,0xFA,0x68,0x76,0x8D,0xBF,0xDF,
0xBB,0x30,0x15,0xFE,0xBD,0x22,0xCC,0x03,0x4E,0x5E,0x33,0xA3,
0x6D,0xD6,0x68,0x12,0x97,0x17,0x4B,0xB5,0x84,0x5F,0x5F,0xA3,
0x5C,0x2F,0xA4,0x10,0xC1,0xAD,0xBF,0xAC,0x30,0xCA,0x47,0x64,
0x63,0xFE,0xEE,0xEE,0xA1,0x64,0x73,0x70,0xAA,0xF9,0xFE,0xC6,
0xAD,0x5E,0xF6,0xF3,0x9C,0xDF,0x34,0x53,0x34,0x72,0xA6,0xA4,
0xBB,0x81,0x5A,0x43,0x41,0xFD,0x41,0x05,0x5B,0x77,0x7B,0x84,
0x03,0xFA,0x8A,0xFA,0xF7,0x8E,0x0F,0xCB,0x51,0xA2,0xB8,0x45,
0xFF,0x59,0x42,0xEF,0xCF,0xF6,0x25,0x37,0xE2,0x6D,0xFF,0x69,
0x11,0xF5,0x77,0x59,0x79,0x1C,0x5F,0x05,0xFC,0x7A,0x65,0x81,
0x03,0x4A,0x78,0xC6,0xE9,0x48,0x73,0xF6,0x10,0xBC,0x99,0x1C,
0xEE,0x44,0x2F,0x8B,0x70,0xCA,0xA8,0xB6,0x02,0x83,0x3E,0x0B,
};
static unsigned char dh1536_g[]={
0x05,
};
static unsigned char dh2048_p[]={
0xFA,0x4E,0xE4,0x3B,0xFA,0xC1,0x87,0xDD,0xE7,0xC6,0x8B,0xE6,
0x13,0x85,0xBC,0x9B,0x2B,0x8B,0x5B,0x46,0xBB,0x8B,0x86,0x6D,
0xD7,0xB6,0xD5,0x49,0xC5,0x54,0xF2,0x3E,0xD2,0x39,0x64,0x9B,
0x0E,0x33,0x39,0x8F,0xFA,0xFA,0xD9,0x78,0xED,0x34,0x82,0x29,
0x37,0x58,0x4D,0x5D,0x40,0xCB,0x69,0xE3,0x8A,0x9F,0x17,0x0C,
0x01,0x23,0x6B,0x05,0x01,0xAF,0x33,0xDE,0xDF,0x1A,0xBB,0x7B,
0x6A,0x9F,0xD8,0xED,0x8D,0x5E,0x44,0x19,0x5B,0xE0,0xB6,0x23,
0xF9,0x7A,0x96,0x6E,0x94,0x33,0x31,0x49,0xBA,0x84,0xD5,0x12,
0xD7,0x6D,0xDC,0x35,0x54,0x64,0xA3,0xD8,0x04,0x26,0xC5,0xAF,
0x7F,0xE3,0xFE,0x6F,0xBE,0xD5,0x17,0x72,0x4B,0xA6,0xD0,0xA7,
0x5F,0x18,0xF5,0xF0,0x2D,0x11,0x9A,0xF6,0xD5,0x3B,0x6C,0x61,
0x3C,0x6F,0x8E,0x09,0x4F,0x2C,0xE1,0x26,0x06,0x51,0xB3,0x19,
0x85,0x85,0x13,0xF9,0xC2,0x6E,0x80,0x28,0x9E,0x8A,0xA0,0x01,
0x46,0xD1,0x85,0x44,0x8C,0xE6,0xEE,0x7E,0x1E,0x17,0x3D,0xBA,
0x54,0xFF,0xE8,0x0E,0xDD,0x51,0xF3,0x74,0x7F,0x0D,0x0B,0xAB,
0xCA,0x84,0x8D,0x24,0x5D,0x56,0xD4,0x47,0x02,0xFC,0x93,0x9F,
0xAE,0x9B,0x5C,0xDB,0x63,0xEB,0x65,0x01,0x38,0xC2,0x7B,0x30,
0x1E,0x17,0x1C,0x75,0xF5,0x16,0x3B,0x4F,0x5F,0x41,0x32,0xB5,
0xFF,0x9E,0x61,0xFD,0xD2,0x62,0x6E,0xFD,0x8A,0x28,0x93,0x59,
0x2D,0x70,0x14,0x4D,0xE1,0x86,0xD5,0x90,0xB4,0xDF,0x72,0x71,
0xE0,0xB4,0xD0,0xD6,0x82,0x3A,0x4A,0x04,0x58,0x32,0x0B,0xD3,
0x51,0x13,0x32,0x63,
};
static unsigned char dh2048_g[]={
0x02,
};
static DH *
get_dh512()
{
DH *dh=NULL;
BIGNUM *p, *g;
if ((dh=DH_new()) == NULL)
return(NULL);
p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL);
g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL);
if ((p == NULL) || (g == NULL))
return(NULL);
DH_set0_pqg(dh, p, NULL, g);
return(dh);
}
static DH *
get_dh768()
{
DH *dh=NULL;
BIGNUM *p, *g;
if ((dh=DH_new()) == NULL)
return(NULL);
p=BN_bin2bn(dh768_p,sizeof(dh768_p),NULL);
g=BN_bin2bn(dh768_g,sizeof(dh768_g),NULL);
if ((p == NULL) || (g == NULL))
return(NULL);
DH_set0_pqg(dh, p, NULL, g);
return(dh);
}
static DH *
get_dh1024()
{
DH *dh=NULL;
BIGNUM *p, *g;
if ((dh=DH_new()) == NULL)
return(NULL);
p=BN_bin2bn(dh1024_p,sizeof(dh1024_p),NULL);
g=BN_bin2bn(dh1024_g,sizeof(dh1024_g),NULL);
if ((p == NULL) || (g == NULL))
return(NULL);
DH_set0_pqg(dh, p, NULL, g);
return(dh);
}
static DH *
get_dh1536()
{
DH *dh=NULL;
BIGNUM *p, *g;
if ((dh=DH_new()) == NULL)
return(NULL);
p=BN_bin2bn(dh1536_p,sizeof(dh1536_p),NULL);
g=BN_bin2bn(dh1536_g,sizeof(dh1536_g),NULL);
if ((p == NULL) || (g == NULL))
return(NULL);
DH_set0_pqg(dh, p, NULL, g);
return(dh);
}
static DH *
get_dh2048()
{