1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
/*
* Copyright (C) 1997-2000 Sensus Consulting Ltd.
* Matt Newman <[email protected]>
*/
#include <tcl.h>
#include <stdio.h>
#include <openssl/bio.h>
#include <openssl/sha.h>
#include <openssl/x509.h>
#include <openssl/asn1.h>
#include "tlsInt.h"
/*
* Ensure these are not macros - known to be defined on Win32
*/
#ifdef min
#undef min
#endif
#ifdef max
#undef max
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
/*
* Copyright (C) 1997-2000 Sensus Consulting Ltd.
* Matt Newman <[email protected]>
*/
#include <tcl.h>
#include <stdio.h>
#include <openssl/bio.h>
#include <openssl/sha.h>
#include <openssl/x509.h>
#include <openssl/asn1.h>
#include "tlsInt.h"
/*
* Ensure these are not macros - known to be defined on Win32
*/
#ifdef min
#undef min
#endif
#ifdef max
#undef max
|
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
|
static char *
ASN1_UTCTIME_tostr(ASN1_UTCTIME *tm)
{
static char bp[128];
char *v;
int gmt=0;
static char *mon[12]={
"Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec"};
int i;
int y=0,M=0,d=0,h=0,m=0,s=0;
i=tm->length;
v=(char *)tm->data;
if (i < 10) goto err;
if (v[i-1] == 'Z') gmt=1;
for (i=0; i<10; i++)
if ((v[i] > '9') || (v[i] < '0')) goto err;
y= (v[0]-'0')*10+(v[1]-'0');
if (y < 70) y+=100;
M= (v[2]-'0')*10+(v[3]-'0');
if ((M > 12) || (M < 1)) goto err;
d= (v[4]-'0')*10+(v[5]-'0');
h= (v[6]-'0')*10+(v[7]-'0');
m= (v[8]-'0')*10+(v[9]-'0');
if ( (v[10] >= '0') && (v[10] <= '9') &&
(v[11] >= '0') && (v[11] <= '9'))
s= (v[10]-'0')*10+(v[11]-'0');
sprintf(bp,"%s %2d %02d:%02d:%02d %d%s",
mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"");
return bp;
err:
return "Bad time value";
}
/*
*------------------------------------------------------*
|
|
<
|
|
<
|
|
|
<
|
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
|
static char *
ASN1_UTCTIME_tostr(ASN1_UTCTIME *tm)
{
static char bp[128];
char *v;
int gmt=0;
static char *mon[12]={
"Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec"};
int i;
int y=0,M=0,d=0,h=0,m=0,s=0;
i=tm->length;
v=(char *)tm->data;
if (i < 10) goto err;
if (v[i-1] == 'Z') gmt=1;
for (i=0; i<10; i++)
if ((v[i] > '9') || (v[i] < '0')) goto err;
y= (v[0]-'0')*10+(v[1]-'0');
if (y < 70) y+=100;
M= (v[2]-'0')*10+(v[3]-'0');
if ((M > 12) || (M < 1)) goto err;
d= (v[4]-'0')*10+(v[5]-'0');
h= (v[6]-'0')*10+(v[7]-'0');
m= (v[8]-'0')*10+(v[9]-'0');
if ((v[10] >= '0') && (v[10] <= '9') && (v[11] >= '0') && (v[11] <= '9'))
s= (v[10]-'0')*10+(v[11]-'0');
sprintf(bp,"%s %2d %02d:%02d:%02d %d%s", mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"");
return bp;
err:
return "Bad time value";
}
/*
*------------------------------------------------------*
|
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
*
*------------------------------------------------------*
*/
#define CERT_STR_SIZE 16384
Tcl_Obj*
Tls_NewX509Obj( Tcl_Interp *interp, X509 *cert) {
Tcl_Obj *certPtr = Tcl_NewListObj( 0, NULL);
BIO *bio;
int n;
unsigned long flags;
char subject[BUFSIZ];
char issuer[BUFSIZ];
char serial[BUFSIZ];
char notBefore[BUFSIZ];
|
|
|
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
*
*------------------------------------------------------*
*/
#define CERT_STR_SIZE 16384
Tcl_Obj*
Tls_NewX509Obj(Tcl_Interp *interp, X509 *cert) {
Tcl_Obj *certPtr = Tcl_NewListObj(0, NULL);
BIO *bio;
int n;
unsigned long flags;
char subject[BUFSIZ];
char issuer[BUFSIZ];
char serial[BUFSIZ];
char notBefore[BUFSIZ];
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
subject[0] = 0;
issuer[0] = 0;
serial[0] = 0;
} else {
flags = XN_FLAG_RFC2253 | ASN1_STRFLGS_UTF8_CONVERT;
flags &= ~ASN1_STRFLGS_ESC_MSB;
X509_NAME_print_ex(bio, X509_get_subject_name(cert), 0, flags);
n = BIO_read(bio, subject, min(BIO_pending(bio), BUFSIZ - 1));
n = max(n, 0);
subject[n] = 0;
(void)BIO_flush(bio);
X509_NAME_print_ex(bio, X509_get_issuer_name(cert), 0, flags);
n = BIO_read(bio, issuer, min(BIO_pending(bio), BUFSIZ - 1));
|
|
|
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
subject[0] = 0;
issuer[0] = 0;
serial[0] = 0;
} else {
flags = XN_FLAG_RFC2253 | ASN1_STRFLGS_UTF8_CONVERT;
flags &= ~ASN1_STRFLGS_ESC_MSB;
X509_NAME_print_ex(bio, X509_get_subject_name(cert), 0, flags);
n = BIO_read(bio, subject, min(BIO_pending(bio), BUFSIZ - 1));
n = max(n, 0);
subject[n] = 0;
(void)BIO_flush(bio);
X509_NAME_print_ex(bio, X509_get_issuer_name(cert), 0, flags);
n = BIO_read(bio, issuer, min(BIO_pending(bio), BUFSIZ - 1));
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
(void)BIO_flush(bio);
}
BIO_free(bio);
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
strcpy( notBefore, ASN1_UTCTIME_tostr( X509_get_notBefore(cert) ));
strcpy( notAfter, ASN1_UTCTIME_tostr( X509_get_notAfter(cert) ));
#else
strcpy( notBefore, ASN1_UTCTIME_tostr( X509_getm_notBefore(cert) ));
strcpy( notAfter, ASN1_UTCTIME_tostr( X509_getm_notAfter(cert) ));
#endif
#ifndef NO_SSL_SHA
/* SHA1 */
X509_digest(cert, EVP_sha1(), sha1_hash_binary, NULL);
for (int n = 0; n < SHA_DIGEST_LENGTH; n++) {
sha1_hash_ascii[n*2] = shachars[(sha1_hash_binary[n] & 0xF0) >> 4];
|
|
|
|
|
|
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
(void)BIO_flush(bio);
}
BIO_free(bio);
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
strcpy(notBefore, ASN1_UTCTIME_tostr(X509_get_notBefore(cert)));
strcpy(notAfter, ASN1_UTCTIME_tostr(X509_get_notAfter(cert)));
#else
strcpy(notBefore, ASN1_UTCTIME_tostr(X509_getm_notBefore(cert)));
strcpy(notAfter, ASN1_UTCTIME_tostr(X509_getm_notAfter(cert)));
#endif
#ifndef NO_SSL_SHA
/* SHA1 */
X509_digest(cert, EVP_sha1(), sha1_hash_binary, NULL);
for (int n = 0; n < SHA_DIGEST_LENGTH; n++) {
sha1_hash_ascii[n*2] = shachars[(sha1_hash_binary[n] & 0xF0) >> 4];
|