line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "EXTERN.h" |
2
|
|
|
|
|
|
|
#include "perl.h" |
3
|
|
|
|
|
|
|
#include "XSUB.h" |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#include |
6
|
|
|
|
|
|
|
#include |
7
|
|
|
|
|
|
|
#include |
8
|
|
|
|
|
|
|
#include |
9
|
|
|
|
|
|
|
#include |
10
|
|
|
|
|
|
|
#include |
11
|
|
|
|
|
|
|
#include |
12
|
|
|
|
|
|
|
#include |
13
|
|
|
|
|
|
|
#include |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
typedef X509_STORE* Crypt__OpenSSL__VerifyX509; |
16
|
|
|
|
|
|
|
typedef X509* Crypt__OpenSSL__X509; |
17
|
|
|
|
|
|
|
|
18
|
4
|
|
|
|
|
|
static int verify_cb(int ok, X509_STORE_CTX *ctx) { |
19
|
4
|
100
|
|
|
|
|
if (!ok) |
20
|
1
|
50
|
|
|
|
|
switch (X509_STORE_CTX_get_error (ctx)) { |
21
|
|
|
|
|
|
|
case X509_V_ERR_CERT_HAS_EXPIRED: |
22
|
|
|
|
|
|
|
/* case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: */ |
23
|
|
|
|
|
|
|
case X509_V_ERR_INVALID_CA: |
24
|
|
|
|
|
|
|
case X509_V_ERR_PATH_LENGTH_EXCEEDED: |
25
|
|
|
|
|
|
|
case X509_V_ERR_INVALID_PURPOSE: |
26
|
|
|
|
|
|
|
case X509_V_ERR_CRL_HAS_EXPIRED: |
27
|
|
|
|
|
|
|
case X509_V_ERR_CRL_NOT_YET_VALID: |
28
|
|
|
|
|
|
|
case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION: |
29
|
0
|
|
|
|
|
|
ok = 1; |
30
|
0
|
|
|
|
|
|
break; |
31
|
|
|
|
|
|
|
} |
32
|
4
|
|
|
|
|
|
return(ok); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
|
static const char *ssl_error(void) { |
36
|
1
|
|
|
|
|
|
return ERR_error_string(ERR_get_error(), NULL); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
|
static const char *ctx_error(X509_STORE_CTX *ctx) { |
40
|
1
|
|
|
|
|
|
return X509_verify_cert_error_string(X509_STORE_CTX_get_error (ctx)); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
MODULE = Crypt::OpenSSL::VerifyX509 PACKAGE = Crypt::OpenSSL::VerifyX509 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
PROTOTYPES: DISABLE |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#if OPENSSL_API_COMPAT >= 0x10100000L |
48
|
|
|
|
|
|
|
#undef ERR_load_crypto_strings |
49
|
|
|
|
|
|
|
#define ERR_load_crypto_strings() /* nothing */ |
50
|
|
|
|
|
|
|
#undef OpenSSL_add_all_algorithms |
51
|
|
|
|
|
|
|
# define OpenSSL_add_all_algorithms() /* nothing */ |
52
|
|
|
|
|
|
|
#endif |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
BOOT: |
55
|
6
|
|
|
|
|
|
ERR_load_crypto_strings(); |
56
|
6
|
|
|
|
|
|
ERR_load_ERR_strings(); |
57
|
6
|
|
|
|
|
|
OpenSSL_add_all_algorithms(); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Crypt::OpenSSL::VerifyX509 |
60
|
|
|
|
|
|
|
new(class, cafile_str) |
61
|
|
|
|
|
|
|
SV *class |
62
|
|
|
|
|
|
|
SV *cafile_str |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
PREINIT: |
65
|
|
|
|
|
|
|
|
66
|
5
|
|
|
|
|
|
int i = 1; |
67
|
5
|
|
|
|
|
|
X509_LOOKUP *lookup = NULL; |
68
|
|
|
|
|
|
|
STRLEN len; |
69
|
|
|
|
|
|
|
char *cafile; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
CODE: |
72
|
|
|
|
|
|
|
|
73
|
5
|
50
|
|
|
|
|
(void) SvPV_nolen(class); |
74
|
|
|
|
|
|
|
|
75
|
5
|
|
|
|
|
|
RETVAL = X509_STORE_new(); |
76
|
5
|
50
|
|
|
|
|
if (RETVAL == NULL) |
77
|
0
|
|
|
|
|
|
croak("failure to allocate x509 store: %s", ssl_error()); |
78
|
|
|
|
|
|
|
|
79
|
5
|
|
|
|
|
|
X509_STORE_set_verify_cb_func(RETVAL,verify_cb); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
/* load CA file given */ |
82
|
5
|
|
|
|
|
|
lookup = X509_STORE_add_lookup(RETVAL, X509_LOOKUP_file()); |
83
|
5
|
50
|
|
|
|
|
if (lookup == NULL) |
84
|
0
|
|
|
|
|
|
croak("failure to add file lookup to store: %s", ssl_error()); |
85
|
|
|
|
|
|
|
|
86
|
5
|
50
|
|
|
|
|
cafile = SvPV(cafile_str, len); |
87
|
5
|
|
|
|
|
|
i = X509_LOOKUP_load_file(lookup, cafile, X509_FILETYPE_PEM); |
88
|
|
|
|
|
|
|
|
89
|
5
|
100
|
|
|
|
|
if (!i) |
90
|
1
|
|
|
|
|
|
croak("load CA cert: %s", ssl_error()); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
/* default hash_dir lookup */ |
93
|
4
|
|
|
|
|
|
lookup = X509_STORE_add_lookup(RETVAL,X509_LOOKUP_hash_dir()); |
94
|
4
|
50
|
|
|
|
|
if (lookup == NULL) |
95
|
0
|
|
|
|
|
|
croak("failure to add hash_dir lookup to store: %s", ssl_error()); |
96
|
|
|
|
|
|
|
|
97
|
4
|
|
|
|
|
|
X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT); |
98
|
|
|
|
|
|
|
|
99
|
4
|
|
|
|
|
|
ERR_clear_error(); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
OUTPUT: |
102
|
|
|
|
|
|
|
RETVAL |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
int |
105
|
|
|
|
|
|
|
verify(store, x509) |
106
|
|
|
|
|
|
|
Crypt::OpenSSL::VerifyX509 store; |
107
|
|
|
|
|
|
|
Crypt::OpenSSL::X509 x509; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
PREINIT: |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
X509_STORE_CTX *csc; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
CODE: |
114
|
|
|
|
|
|
|
|
115
|
2
|
50
|
|
|
|
|
if (x509 == NULL) |
116
|
0
|
|
|
|
|
|
croak("no cert to verify"); |
117
|
|
|
|
|
|
|
|
118
|
2
|
|
|
|
|
|
csc = X509_STORE_CTX_new(); |
119
|
2
|
50
|
|
|
|
|
if (csc == NULL) |
120
|
0
|
|
|
|
|
|
croak("csc new: %s", ssl_error()); |
121
|
|
|
|
|
|
|
|
122
|
2
|
|
|
|
|
|
X509_STORE_set_flags(store, 0); |
123
|
|
|
|
|
|
|
|
124
|
2
|
50
|
|
|
|
|
if (!X509_STORE_CTX_init(csc,store,x509,NULL)) |
125
|
0
|
|
|
|
|
|
croak("store ctx init: %s", ssl_error()); |
126
|
|
|
|
|
|
|
|
127
|
2
|
|
|
|
|
|
RETVAL = X509_verify_cert(csc); |
128
|
|
|
|
|
|
|
|
129
|
2
|
100
|
|
|
|
|
if (!RETVAL) |
130
|
1
|
|
|
|
|
|
croak("verify: %s", ctx_error(csc)); |
131
|
|
|
|
|
|
|
|
132
|
1
|
|
|
|
|
|
X509_STORE_CTX_free(csc); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
OUTPUT: |
135
|
|
|
|
|
|
|
RETVAL |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
void |
138
|
|
|
|
|
|
|
DESTROY(store) |
139
|
|
|
|
|
|
|
Crypt::OpenSSL::VerifyX509 store; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
PPCODE: |
142
|
|
|
|
|
|
|
|
143
|
4
|
50
|
|
|
|
|
if (store) X509_STORE_free(store); store = 0; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
#if OPENSSL_API_COMPAT >= 0x10100000L |
147
|
|
|
|
|
|
|
void |
148
|
|
|
|
|
|
|
__X509_cleanup(void) |
149
|
|
|
|
|
|
|
PPCODE: |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
/* deinitialisation is done automatically */ |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
#else |
154
|
|
|
|
|
|
|
void |
155
|
|
|
|
|
|
|
__X509_cleanup(void) |
156
|
|
|
|
|
|
|
PPCODE: |
157
|
|
|
|
|
|
|
|
158
|
6
|
|
|
|
|
|
CRYPTO_cleanup_all_ex_data(); |
159
|
6
|
|
|
|
|
|
ERR_free_strings(); |
160
|
6
|
|
|
|
|
|
ERR_remove_state(0); |
161
|
6
|
|
|
|
|
|
EVP_cleanup(); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
#endif |
164
|
|
|
|
|
|
|
|