X509.xs

filter: Statementstmt 53.7% 256 / 476 Branchbran 46.2% 123 / 266 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 51.0% 379 / 742 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Crypt/OpenSSL/X509.pm ↑ Summary
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 #include <openssl/asn1.h>
6 #include <openssl/objects.h>
7 #include <openssl/bio.h>
8 #include <openssl/crypto.h>
9 #include <openssl/err.h>
10 #include <openssl/evp.h>
11 #include <openssl/pem.h>
12 #include <openssl/x509.h>
13 #include <openssl/x509v3.h>
14 #include <openssl/opensslconf.h>
15 #if OPENSSL_VERSION_NUMBER >= 0x10100000
16 #include <openssl/rsa.h>
17 #include <openssl/dsa.h>
18 #include <openssl/bn.h>
19 #endif
20 #ifndef OPENSSL_NO_EC
21 # include <openssl/ec.h>
22 #endif
23  
24 /* from openssl/apps/apps.h */
25 #define FORMAT_UNDEF 0
26 #define FORMAT_ASN1 1
27 #define FORMAT_TEXT 2
28 #define FORMAT_PEM 3
29 #define FORMAT_PKCS12 5
30 #define FORMAT_SMIME 6
31 #define FORMAT_ENGINE 7
32 #define FORMAT_IISSGC 8
33  
34 /* fake our package name */
35 typedef X509* Crypt__OpenSSL__X509;
36 typedef X509_EXTENSION* Crypt__OpenSSL__X509__Extension;
37 typedef ASN1_OBJECT* Crypt__OpenSSL__X509__ObjectID;
38 typedef X509_NAME* Crypt__OpenSSL__X509__Name;
39 typedef X509_NAME_ENTRY* Crypt__OpenSSL__X509__Name_Entry;
40 typedef X509_CRL* Crypt__OpenSSL__X509__CRL;
41  
42 /* 1.0 backwards compat */
43 #if OPENSSL_VERSION_NUMBER < 0x10100000
44 #define const_ossl11
45  
46 #ifndef sk_OPENSSL_STRING_num
47 #define sk_OPENSSL_STRING_num sk_num
48 #endif
49  
50 #ifndef sk_OPENSSL_STRING_value
51 #define sk_OPENSSL_STRING_value sk_value
52 #endif
53  
54 static ASN1_INTEGER *X509_get0_serialNumber(const X509 *a)
55 {
56 return a->cert_info->serialNumber;
57 }
58  
59 static void RSA_get0_key(const RSA *r,
60 const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
61 {
62 if (n != NULL)
63 *n = r->n;
64 if (e != NULL)
65 *e = r->e;
66 if (d != NULL)
67 *d = r->d;
68 }
69  
70 static RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
71 {
72 if (pkey->type != EVP_PKEY_RSA)
73 return NULL;
74 return pkey->pkey.rsa;
75 }
76  
77 static void X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig,
78 X509_ALGOR **palg)
79 {
80 if (psig != NULL)
81 *psig = crl->signature;
82 if (palg != NULL)
83 *palg = crl->sig_alg;
84 }
85  
86 #if OPENSSL_VERSION_NUMBER < 0x10002000
87 static void X509_get0_signature(const_ossl11 ASN1_BIT_STRING **psig, const_ossl11 X509_ALGOR **palg,
88 const X509 *x)
89 {
90 if (psig != NULL)
91 *psig = x->signature;
92 if (palg != NULL)
93 *palg = x->sig_alg;
94 }
95 #endif
96  
97 static void DSA_get0_pqg(const DSA *d,
98 const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
99 {
100 if (p != NULL)
101 *p = d->p;
102 if (q != NULL)
103 *q = d->q;
104 if (g != NULL)
105 *g = d->g;
106 }
107  
108 static void DSA_get0_key(const DSA *d,
109 const BIGNUM **pub_key, const BIGNUM **priv_key)
110 {
111 if (pub_key != NULL)
112 *pub_key = d->pub_key;
113 if (priv_key != NULL)
114 *priv_key = d->priv_key;
115 }
116  
117 static DSA *EVP_PKEY_get0_DSA(EVP_PKEY *pkey)
118 {
119 if (pkey->type != EVP_PKEY_DSA)
120 return NULL;
121 return pkey->pkey.dsa;
122 }
123  
124 static EC_KEY *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
125 {
126 if (pkey->type != EVP_PKEY_EC)
127 return NULL;
128 return pkey->pkey.ec;
129 }
130  
131 #else
132 #define const_ossl11 const
133 #endif
134  
135 /* Unicode 0xfffd */
136 static U8 utf8_substitute_char[3] = { 0xef, 0xbf, 0xbd };
137  
138 /* stolen from OpenSSL.xs */
139 2442 long bio_write_cb(struct bio_st *bm, int m, const char *ptr, int l, long x, long y) {
140  
141 2442 ▶ if (m == BIO_CB_WRITE) {
Branch: 1 branch
BranchTrueFalseTotal
if (m == BIO_CB_WRITE) { 1178 1264 2442
142 1178 SV *sv = (SV *) BIO_get_callback_arg(bm);
143 1178 sv_catpvn(sv, ptr, l);
144 }
145  
146 2442 ▶ if (m == BIO_CB_PUTS) {
Branch: 1 branch
BranchTrueFalseTotal
if (m == BIO_CB_PUTS) { 0 2442 2442
147 0 SV *sv = (SV *) BIO_get_callback_arg(bm);
148 0 l = strlen(ptr);
149 0 sv_catpvn(sv, ptr, l);
150 }
151  
152 2442 return l;
153 }
154  
155 43 static BIO* sv_bio_create(void) {
156  
157 43 SV *sv = newSVpvn("", 0);
158  
159 /* create an in-memory BIO abstraction and callbacks */
160 43 BIO *bio = BIO_new(BIO_s_mem());
161  
162 43 BIO_set_callback(bio, bio_write_cb);
163 43 BIO_set_callback_arg(bio, (void *)sv);
164  
165 43 return bio;
166 }
167  
168 43 static SV* sv_bio_final(BIO *bio) {
169  
170 SV* sv;
171  
172 43 (void)BIO_flush(bio);
173 43 sv = (SV *)BIO_get_callback_arg(bio);
174 43 BIO_set_callback_arg(bio, (void *)NULL);
175 43 BIO_set_callback(bio, (void *)NULL);
176 43 BIO_free_all(bio);
177  
178 43 ▶ if (!sv) sv = &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
if (!sv) sv = &PL_sv_undef; 0 43 43
179  
180 43 return sv;
181 }
182  
183 /* call this just before sv_bio_final if the BIO got an UTF8 encoded text and you want native perl utf-8 strings. */
184 8 static SV* sv_bio_utf8_on(BIO *bio) {
185  
186 8 SV* sv = (SV *)BIO_get_callback_arg(bio);
187  
188 /* Illegal utf-8 in the string */
189 8 ▶ if (!sv_utf8_decode(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_utf8_decode(sv)) { 0 8 8
190 STRLEN len;
191 0 SV *nsv = newSVpvn("", 0);
192  
193 0 const U8* start = (U8 *) SvPV(sv, len);
194 0 const U8* end = start + len;
195 const U8* cur;
196  
197 0 ▶ while ((start < end) && !is_utf8_string_loclen(start, len, &cur, 0)) {
Branch: 2 branches
BranchTrueFalseTotal
while ((start < end) && !is_utf8_string_loclen(start, len, &cur, 0)) { 0 0 0
while ((start < end) && !is_utf8_string_loclen(start, len, &cur, 0)) { 0 0 0
198 0 sv_catpvn(nsv, (const char*)start, (cur - start) + 1); /* text that was ok */
199 0 sv_catpvn(nsv, (const char*)utf8_substitute_char, 3); /* insert \x{fffd} */
200 0 start = cur + 1;
201 0 len = end - cur;
202 }
203  
204 0 ▶ if (start < end) {
Branch: 1 branch
BranchTrueFalseTotal
if (start < end) { 0 0 0
205 0 sv_catpvn(nsv, (const char*)start, (cur - start) - 1); /* rest of the string */
206 }
207  
208 0 sv_copypv(sv, nsv);
209 0 SvREFCNT_dec(nsv);
210 0 sv_utf8_decode(sv); /* should be ok now */
211 }
212  
213 8 return sv;
214 }
215  
216 /*
217 static void sv_bio_error(BIO *bio) {
218  
219 SV* sv = (SV *)BIO_get_callback_arg(bio);
220 if (sv) sv_free(sv);
221  
222 BIO_free_all (bio);
223 }
224 */
225  
226 0 static const char *ssl_error(void) {
227 BIO *bio;
228 SV *sv;
229 STRLEN l;
230  
231 0 bio = sv_bio_create();
232 0 ERR_print_errors(bio);
233 0 sv = sv_bio_final(bio);
234 0 ERR_clear_error();
235 0 return SvPV(sv, l);
236 }
237  
238 /* Make a scalar ref to a class object */
239 43 static SV* sv_make_ref(const char* class, void* object) {
240 SV* rv;
241  
242 43 rv = newSV(0);
243 43 sv_setref_pv(rv, class, (void*) object);
244  
245 43 ▶ if (! sv_isa(rv, class) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (! sv_isa(rv, class) ) { 0 43 43
246 0 croak("Error creating reference to %s", class);
247 }
248  
249 43 return rv;
250 }
251  
252 /*
253 * hash of extensions from x509.
254 * no_name can be
255 * 0: index by long name,
256 * 1: index by oid string,
257 * 2: index by short name
258 */
259 12 static HV* hv_exts(X509* x509, int no_name) {
260 X509_EXTENSION *ext;
261 int i, c, r;
262 12 char* key = NULL;
263 12 const char* ckey = NULL;
264 SV* rv;
265  
266 12 HV* RETVAL = newHV();
267 12 sv_2mortal((SV*)RETVAL);
268 12 c = X509_get_ext_count(x509);
269  
270 12 ▶ if ( !(c > 0) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !(c > 0) ) { 1 11 12
271 1 croak("No extensions found\n");
272 }
273  
274 47 ▶ for (i = 0; i < c; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < c; i++) { 36 11 47
275 36 r = 0;
276 36 ckey = NULL;
277  
278 36 ext = (X509_EXTENSION *)X509_get_ext(x509, i);
279  
280 36 ▶ if (ext == NULL) croak("Extension %d unavailable\n", i);
Branch: 1 branch
BranchTrueFalseTotal
if (ext == NULL) croak("Extension %d unavailable\n", i); 0 36 36
281  
282 36 rv = sv_make_ref("Crypt::OpenSSL::X509::Extension", (void*)ext);
283  
284 36 ▶ if (no_name == 0 || no_name == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (no_name == 0 || no_name == 1) { 36 0 36
if (no_name == 0 || no_name == 1) { 33 3 36
285  
286 /* OBJ_obj2txt() returns the FULL textual length the OID needs, not
287 the number of bytes written into the buffer. The original code
288 passed a fixed 128-byte buffer and handed that return value to
289 hv_store() as the key length, so an OID longer than 128 bytes made
290 hv_store() read past the allocation (heap OOB read). Size the
291 buffer to the required length first, then format, and store the
292 number of bytes actually written (strlen) -- never the return
293 value -- so no over-read is possible on any code path or any
294 OBJ_obj2txt() version. */
295 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
296 33 r = OBJ_obj2txt(NULL, 0, X509_EXTENSION_get_object(ext), no_name);
297 #else
298 {
299 char tmp[1];
300 r = OBJ_obj2txt(tmp, sizeof(tmp), X509_EXTENSION_get_object(ext), no_name);
301 }
302 #endif
303 33 ▶ if (r <= 0) { SvREFCNT_dec(rv); croak("OBJ_obj2txt length query failed for extension %d\n", i); }
Branch: 1 branch
BranchTrueFalseTotal
if (r <= 0) { SvREFCNT_dec(rv); croak("OBJ_obj2txt length query failed for extension %d\n", i); } 0 33 33
304 33 key = malloc(sizeof(char) * ((size_t)r + 1));
305 33 ▶ if (key == NULL) { SvREFCNT_dec(rv); croak("malloc failed for extension key\n"); }
Branch: 1 branch
BranchTrueFalseTotal
if (key == NULL) { SvREFCNT_dec(rv); croak("malloc failed for extension key\n"); } 0 33 33
306 33 ▶ if (OBJ_obj2txt(key, r + 1, X509_EXTENSION_get_object(ext), no_name) < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (OBJ_obj2txt(key, r + 1, X509_EXTENSION_get_object(ext), no_name) < 0) { 0 33 33
307 0 free(key); key = NULL; SvREFCNT_dec(rv);
308 0 croak("OBJ_obj2txt format failed for extension %d\n", i);
309 }
310 33 ckey = key;
311 33 r = (int)strlen(key);
312  
313 3 ▶ } else if (no_name == 2) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (no_name == 2) { 3 0 3
314  
315 3 ckey = OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(ext)));
316 3 ▶ if (ckey == NULL) { SvREFCNT_dec(rv); croak("OBJ_nid2sn failed for extension %d\n", i); }
Branch: 1 branch
BranchTrueFalseTotal
if (ckey == NULL) { SvREFCNT_dec(rv); croak("OBJ_nid2sn failed for extension %d\n", i); } 0 3 3
317 3 r = strlen(ckey);
318 }
319  
320 /* hv_store() copies the key bytes, so the per-iteration key buffer can be
321 freed immediately. Free it BEFORE the failure croak so it is not leaked
322 on longjmp; on hv_store() failure the hash did not adopt rv, so drop
323 our reference too. */
324 {
325 36 SV** stored = hv_store(RETVAL, ckey, r, rv, 0);
326 36 ▶ if (key != NULL) { free(key); key = NULL; }
Branch: 1 branch
BranchTrueFalseTotal
if (key != NULL) { free(key); key = NULL; } 33 3 36
327 36 ▶ if (stored == NULL) { SvREFCNT_dec(rv); croak("Error storing extension in hash\n"); }
Branch: 1 branch
BranchTrueFalseTotal
if (stored == NULL) { SvREFCNT_dec(rv); croak("Error storing extension in hash\n"); } 0 36 36
328 }
329 }
330  
331 11 return RETVAL;
332 }
333  
334 MODULE = Crypt::OpenSSL::X509 PACKAGE = Crypt::OpenSSL::X509
335  
336 PROTOTYPES: DISABLE
337  
338 BOOT:
339 {
340 4 HV *stash = gv_stashpvn("Crypt::OpenSSL::X509", 20, TRUE);
341  
342 4 struct { const char *n; I32 v; } Crypt__OpenSSL__X509__const[] = {
343  
344 {"OPENSSL_VERSION_NUMBER", OPENSSL_VERSION_NUMBER},
345 {"FORMAT_UNDEF", FORMAT_UNDEF},
346 {"FORMAT_ASN1", FORMAT_ASN1},
347 {"FORMAT_TEXT", FORMAT_TEXT},
348 {"FORMAT_PEM", FORMAT_PEM},
349 {"FORMAT_PKCS12", FORMAT_PKCS12},
350 {"FORMAT_SMIME", FORMAT_SMIME},
351 {"FORMAT_ENGINE", FORMAT_ENGINE},
352 {"FORMAT_IISSGC", FORMAT_IISSGC},
353 {"V_ASN1_PRINTABLESTRING", V_ASN1_PRINTABLESTRING},
354 {"V_ASN1_UTF8STRING", V_ASN1_UTF8STRING},
355 {"V_ASN1_IA5STRING", V_ASN1_IA5STRING},
356 {Nullch,0}};
357  
358 const char *name;
359 int i;
360  
361 52 ▶ for (i = 0; (name = Crypt__OpenSSL__X509__const[i].n); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; (name = Crypt__OpenSSL__X509__const[i].n); i++) { 48 4 52
362 48 newCONSTSUB(stash, name, newSViv(Crypt__OpenSSL__X509__const[i].v));
363 }
364 #if OPENSSL_VERSION_NUMBER < 0x10100000
365 ERR_load_crypto_strings();
366 OPENSSL_add_all_algorithms_conf();
367 #endif
368 }
369  
370 Crypt::OpenSSL::X509
371 new(class)
372 SV *class
373  
374 CODE:
375  
376 0 ▶ if ((RETVAL = X509_new()) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ((RETVAL = X509_new()) == NULL) { 0 0 0
377 0 croak("X509_new");
378 }
379  
380 0 ▶ if (!X509_set_version(RETVAL, 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!X509_set_version(RETVAL, 2)) { 0 0 0
381 0 X509_free(RETVAL);
382 0 croak ("%s - can't X509_set_version()", SvPV_nolen(class));
383 }
384  
385 0 ASN1_INTEGER_set(X509_get_serialNumber(RETVAL), 0L);
386  
387 OUTPUT:
388 RETVAL
389  
390 Crypt::OpenSSL::X509
391 new_from_string(class, string, format = FORMAT_PEM)
392 SV *class
393 SV *string
394 int format
395  
396 ALIAS:
397 new_from_file = 1
398  
399 PREINIT:
400 BIO *bio;
401 STRLEN len;
402 char *cert;
403  
404 CODE:
405  
406 17 cert = SvPV(string, len);
407  
408 17 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 16 1 17
409 16 bio = BIO_new_file(cert, "r");
410 } else {
411 1 bio = BIO_new_mem_buf(cert, len);
412 }
413  
414 17 ▶ if (!bio) croak("%s: Failed to create BIO", SvPV_nolen(class));
Branch: 1 branch
BranchTrueFalseTotal
if (!bio) croak("%s: Failed to create BIO", SvPV_nolen(class)); 0 17 17
415  
416 /* this can come in any number of ways */
417 17 ▶ if (format == FORMAT_ASN1) {
Branch: 1 branch
BranchTrueFalseTotal
if (format == FORMAT_ASN1) { 1 16 17
418  
419 1 RETVAL = (X509*)d2i_X509_bio(bio, NULL);
420  
421 } else {
422  
423 16 RETVAL = (X509*)PEM_read_bio_X509(bio, NULL, NULL, NULL);
424 }
425  
426 17 BIO_free_all(bio);
427  
428 17 ▶ if (!RETVAL) croak("%s: failed to read X509 certificate.", SvPV_nolen(class));
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("%s: failed to read X509 certificate.", SvPV_nolen(class)); 0 17 17
429  
430 OUTPUT:
431 RETVAL
432  
433 void
434 DESTROY(x509)
435 Crypt::OpenSSL::X509 x509;
436  
437 PPCODE:
438  
439 17 ▶ if (x509) X509_free(x509); x509 = 0;
Branch: 1 branch
BranchTrueFalseTotal
if (x509) X509_free(x509); x509 = 0; 17 0 17
440  
441 # This is called via an END block in the Perl module to clean up initialization that happened in BOOT.
442 void
443 __X509_cleanup(void)
444 PPCODE:
445 #if OPENSSL_VERSION_NUMBER < 0x10100000
446 CRYPTO_cleanup_all_ex_data();
447 ERR_free_strings();
448 ERR_remove_state(0);
449 EVP_cleanup();
450 #endif
451  
452 SV*
453 accessor(x509)
454 Crypt::OpenSSL::X509 x509;
455  
456 ALIAS:
457 subject = 1
458 issuer = 2
459 serial = 3
460 hash = 4
461 subject_hash = 4
462 notBefore = 5
463 notAfter = 6
464 email = 7
465 version = 8
466 sig_alg_name = 9
467 key_alg_name = 10
468 issuer_hash = 11
469  
470 PREINIT:
471 BIO *bio;
472 X509_NAME *name;
473  
474 CODE:
475  
476 19 bio = sv_bio_create();
477  
478 /* this includes both subject and issuer since they are so much alike */
479 19 ▶ if (ix == 1 || ix == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (ix == 1 || ix == 2) { 15 4 19
if (ix == 1 || ix == 2) { 2 13 15
480  
481 6 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 4 2 6
482 4 name = (X509_NAME *)X509_get_subject_name(x509);
483 } else {
484 2 name = (X509_NAME *)X509_get_issuer_name(x509);
485 }
486  
487 /* this is prefered over X509_NAME_oneline() */
488 6 X509_NAME_print_ex(bio, name, 0, (XN_FLAG_SEP_CPLUS_SPC | ASN1_STRFLGS_UTF8_CONVERT) & ~ASN1_STRFLGS_ESC_MSB);
489  
490 /* this need not be pure ascii, try to get a native perl character string with * utf8 */
491 6 sv_bio_utf8_on(bio);
492  
493 13 ▶ } else if (ix == 3) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == 3) { 3 10 13
494  
495 3 i2a_ASN1_INTEGER(bio, X509_get0_serialNumber(x509));
496  
497 10 ▶ } else if (ix == 4) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == 4) { 2 8 10
498  
499 2 BIO_printf(bio, "%08lx", X509_subject_name_hash(x509));
500  
501 8 ▶ } else if (ix == 5) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == 5) { 0 8 8
502 #if OPENSSL_VERSION_NUMBER < 0x10100000
503 ASN1_TIME_print(bio, X509_get_notBefore(x509));
504 #else
505 0 ASN1_TIME_print(bio, X509_get0_notBefore(x509));
506 #endif
507  
508 8 ▶ } else if (ix == 6) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == 6) { 0 8 8
509 #if OPENSSL_VERSION_NUMBER < 0x10100000
510 ASN1_TIME_print(bio, X509_get_notAfter(x509));
511 #else
512 0 ASN1_TIME_print(bio, X509_get0_notAfter(x509));
513 #endif
514 8 ▶ } else if (ix == 7) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == 7) { 2 6 8
515  
516 int j;
517 2 STACK_OF(OPENSSL_STRING) *emlst = X509_get1_email(x509);
518  
519 6 ▶ for (j = 0; j < sk_OPENSSL_STRING_num(emlst); j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < sk_OPENSSL_STRING_num(emlst); j++) { 4 2 6
520 4 ▶ BIO_printf(bio, "%s%s", (j ? " " : ""), sk_OPENSSL_STRING_value(emlst, j));
Branch: 1 branch
BranchTrueFalseTotal
BIO_printf(bio, "%s%s", (j ? " " : ""), sk_OPENSSL_STRING_value(emlst, j)); 2 2 4
521 }
522  
523 2 X509_email_free(emlst);
524  
525 6 ▶ } else if (ix == 8) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == 8) { 1 5 6
526  
527 1 BIO_printf(bio, "%02ld", X509_get_version(x509));
528  
529 5 ▶ } else if (ix == 9) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == 9) { 2 3 5
530 const_ossl11 X509_ALGOR *palg;
531 const_ossl11 ASN1_OBJECT *paobj;
532  
533 2 X509_get0_signature(NULL, &palg, x509);
534 2 X509_ALGOR_get0(&paobj, NULL, NULL, palg);
535  
536 2 i2a_ASN1_OBJECT(bio, paobj);
537 3 ▶ } else if ( ix == 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( ix == 10 ) { 2 1 3
538 X509_PUBKEY *pkey;
539 ASN1_OBJECT *ppkalg;
540  
541 2 pkey = (X509_PUBKEY *)X509_get_X509_PUBKEY(x509);
542 2 X509_PUBKEY_get0_param(&ppkalg, NULL, NULL, NULL, pkey);
543  
544 2 i2a_ASN1_OBJECT(bio, ppkalg);
545 1 ▶ } else if ( ix == 11 ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( ix == 11 ) { 1 0 1
546 1 BIO_printf(bio, "%08lx", X509_issuer_name_hash(x509));
547 }
548  
549 19 RETVAL = sv_bio_final(bio);
550  
551 OUTPUT:
552 RETVAL
553  
554 Crypt::OpenSSL::X509::Name
555 subject_name(x509)
556 Crypt::OpenSSL::X509 x509;
557  
558 ALIAS:
559 subject_name = 1
560 issuer_name = 2
561  
562 CODE:
563 14 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 12 2 14
564 12 RETVAL = (X509_NAME *)X509_get_subject_name(x509);
565 } else {
566 2 RETVAL = (X509_NAME *)X509_get_issuer_name(x509);
567 }
568  
569 OUTPUT:
570 RETVAL
571  
572 SV*
573 sig_print(x509)
574 Crypt::OpenSSL::X509 x509;
575  
576 PREINIT:
577 BIO *bio;
578 unsigned char *s;
579 const_ossl11 ASN1_BIT_STRING *psig;
580 int n,i;
581  
582 CODE:
583  
584 0 X509_get0_signature(&psig, NULL, x509);
585 #if OPENSSL_VERSION_NUMBER >= 0x40000000L
586 n = ASN1_STRING_length((ASN1_STRING *)psig);
587 s = (unsigned char *)ASN1_STRING_get0_data((ASN1_STRING *)psig);
588 #else
589 0 n = psig->length;
590 0 s = psig->data;
591 #endif
592 0 bio = sv_bio_create();
593  
594 0 ▶ for (i=0; i<n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<n; i++) { 0 0 0
595 0 BIO_printf(bio, "%02x", s[i]);
596 }
597  
598 0 RETVAL = sv_bio_final(bio);
599 OUTPUT:
600 RETVAL
601  
602 SV*
603 as_string(x509, format = FORMAT_PEM)
604 Crypt::OpenSSL::X509 x509;
605 int format;
606  
607 PREINIT:
608 BIO *bio;
609  
610 CODE:
611  
612 1 bio = sv_bio_create();
613  
614 /* get the certificate back out in a specified format. */
615  
616 1 ▶ if (format == FORMAT_PEM) {
Branch: 1 branch
BranchTrueFalseTotal
if (format == FORMAT_PEM) { 0 1 1
617  
618 0 PEM_write_bio_X509(bio, x509);
619  
620 1 ▶ } else if (format == FORMAT_ASN1) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (format == FORMAT_ASN1) { 1 0 1
621  
622 1 i2d_X509_bio(bio, x509);
623  
624 }
625  
626 1 RETVAL = sv_bio_final(bio);
627  
628 OUTPUT:
629 RETVAL
630  
631 SV*
632 bit_length(x509)
633 Crypt::OpenSSL::X509 x509;
634  
635 PREINIT:
636 EVP_PKEY *pkey;
637 const DSA *dsa_pkey;
638 const RSA *rsa_pkey;
639 const EC_KEY *ec_pkey;
640 const BIGNUM *p;
641 const BIGNUM *n;
642 int length;
643  
644 CODE:
645 2 pkey = X509_extract_key(x509);
646 2 ▶ if (pkey == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (pkey == NULL) { 0 2 2
647 0 EVP_PKEY_free(pkey);
648 0 croak("Public key is unavailable\n");
649 }
650  
651 2 switch(EVP_PKEY_base_id(pkey)) {
652 1 case EVP_PKEY_RSA:
653 1 rsa_pkey = EVP_PKEY_get0_RSA(pkey);
654 1 RSA_get0_key(rsa_pkey, &n, NULL, NULL);
655 1 length = BN_num_bits(n);
656 1 break;
657 0 case EVP_PKEY_DSA:
658 0 dsa_pkey = EVP_PKEY_get0_DSA(pkey);
659 0 DSA_get0_pqg(dsa_pkey, &p, NULL, NULL);
660 0 length = BN_num_bits(p);
661 0 break;
662 #ifndef OPENSSL_NO_EC
663 1 case EVP_PKEY_EC:
664 {
665 const EC_GROUP *group;
666 BIGNUM* ec_order;
667 1 ec_order = BN_new();
668 1 ▶ if ( !ec_order ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !ec_order ) { 0 1 1
669 0 EVP_PKEY_free(pkey);
670 0 croak("Could not malloc bignum");
671 }
672 1 ec_pkey = EVP_PKEY_get0_EC_KEY(pkey);
673 1 ▶ if ( (group = EC_KEY_get0_group(ec_pkey)) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ( (group = EC_KEY_get0_group(ec_pkey)) == NULL) { 0 1 1
674 0 EVP_PKEY_free(pkey);
675 0 croak("No EC group");
676 }
677 /* */
678 1 ▶ if (!EC_GROUP_get_order(group, ec_order, NULL)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!EC_GROUP_get_order(group, ec_order, NULL)) { 0 1 1
679 0 EVP_PKEY_free(pkey);
680 0 croak("Could not get ec-group order");
681 }
682 1 length = BN_num_bits(ec_order);
683 /* */
684 1 BN_free(ec_order);
685 1 break;
686 }
687 #endif
688 0 default:
689 0 EVP_PKEY_free(pkey);
690 0 croak("Unknown public key type");
691 }
692  
693 2 RETVAL = newSVuv(length);
694  
695 OUTPUT:
696 RETVAL
697  
698 const char*
699 curve(x509)
700 Crypt::OpenSSL::X509 x509;
701  
702 PREINIT:
703 #ifndef OPENSSL_NO_EC
704 EVP_PKEY *pkey;
705 #endif
706  
707 CODE:
708 #ifdef OPENSSL_NO_EC
709 if ( x509 ) {} /* fix unused variable warning. */
710 croak("OpenSSL without EC-support");
711 #else
712 1 pkey = X509_extract_key(x509);
713 1 ▶ if (pkey == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (pkey == NULL) { 0 1 1
714 0 EVP_PKEY_free(pkey);
715 0 croak("Public key is unavailable\n");
716 }
717 1 ▶ if ( EVP_PKEY_base_id(pkey) == EVP_PKEY_EC ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( EVP_PKEY_base_id(pkey) == EVP_PKEY_EC ) { 1 0 1
718 const EC_GROUP *group;
719 const EC_KEY *ec_pkey;
720 int nid;
721 1 ec_pkey = EVP_PKEY_get0_EC_KEY(pkey);
722 1 ▶ if ( (group = EC_KEY_get0_group(ec_pkey)) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ( (group = EC_KEY_get0_group(ec_pkey)) == NULL) { 0 1 1
723 0 EVP_PKEY_free(pkey);
724 0 croak("No EC group");
725 }
726 1 nid = EC_GROUP_get_curve_name(group);
727 1 ▶ if ( nid == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( nid == 0 ) { 0 1 1
728 0 EVP_PKEY_free(pkey);
729 0 croak("invalid nid");
730 }
731 1 RETVAL = OBJ_nid2sn(nid);
732 } else {
733 0 EVP_PKEY_free(pkey);
734 0 croak("Wrong Algorithm type\n");
735 }
736 1 EVP_PKEY_free(pkey);
737 #endif
738  
739 OUTPUT:
740 RETVAL
741  
742  
743 SV*
744 modulus(x509)
745 Crypt::OpenSSL::X509 x509;
746  
747 PREINIT:
748 EVP_PKEY *pkey;
749 BIO *bio;
750 int pkey_id;
751  
752 CODE:
753  
754 0 pkey = X509_extract_key(x509);
755 0 bio = sv_bio_create();
756  
757 0 ▶ if (pkey == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (pkey == NULL) { 0 0 0
758  
759 0 BIO_free_all(bio);
760 0 EVP_PKEY_free(pkey);
761 0 croak("Modulus is unavailable\n");
762 }
763  
764 0 pkey_id = EVP_PKEY_base_id(pkey);
765 0 ▶ if (pkey_id == EVP_PKEY_RSA) {
Branch: 1 branch
BranchTrueFalseTotal
if (pkey_id == EVP_PKEY_RSA) { 0 0 0
766 const RSA *rsa_pkey;
767 const BIGNUM *n;
768  
769 0 rsa_pkey = EVP_PKEY_get0_RSA(pkey);
770 0 RSA_get0_key(rsa_pkey, &n, NULL, NULL);
771  
772 0 BN_print(bio, n);
773  
774 0 ▶ } else if (pkey_id == EVP_PKEY_DSA) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (pkey_id == EVP_PKEY_DSA) { 0 0 0
775 const DSA *dsa_pkey;
776 const BIGNUM *pub_key;
777  
778 0 dsa_pkey = EVP_PKEY_get0_DSA(pkey);
779 0 DSA_get0_key(dsa_pkey, &pub_key, NULL);
780 0 BN_print(bio, pub_key);
781 #ifndef OPENSSL_NO_EC
782 0 ▶ } else if ( pkey_id == EVP_PKEY_EC ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( pkey_id == EVP_PKEY_EC ) { 0 0 0
783 const EC_POINT *public_key;
784 const EC_GROUP *group;
785 const EC_KEY *ec_pkey;
786 0 BIGNUM *pub_key=NULL;
787  
788 0 ec_pkey = EVP_PKEY_get0_EC_KEY(pkey);
789 0 ▶ if ( (group = EC_KEY_get0_group(ec_pkey)) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ( (group = EC_KEY_get0_group(ec_pkey)) == NULL) { 0 0 0
790 0 BIO_free_all(bio);
791 0 EVP_PKEY_free(pkey);
792 0 croak("No EC group");
793 }
794 0 public_key = EC_KEY_get0_public_key(ec_pkey);
795 0 ▶ if ((pub_key = EC_POINT_point2bn(group, public_key, EC_KEY_get_conv_form(ec_pkey), NULL, NULL)) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ((pub_key = EC_POINT_point2bn(group, public_key, EC_KEY_get_conv_form(ec_pkey), NULL, NULL)) == NULL) { 0 0 0
796 0 BIO_free_all(bio);
797 0 EVP_PKEY_free(pkey);
798 0 croak("EC library error");
799 }
800 0 BN_print(bio, pub_key);
801 #endif
802 } else {
803  
804 0 BIO_free_all(bio);
805 0 EVP_PKEY_free(pkey);
806 0 croak("Wrong Algorithm type\n");
807 }
808  
809 0 RETVAL = sv_bio_final(bio);
810  
811 0 EVP_PKEY_free(pkey);
812  
813 OUTPUT:
814 RETVAL
815  
816 SV*
817 exponent(x509)
818 Crypt::OpenSSL::X509 x509;
819  
820 PREINIT:
821 EVP_PKEY *pkey;
822 BIO *bio;
823  
824 ALIAS:
825 pub_exponent = 1
826  
827 CODE:
828 2 pkey = X509_get_pubkey(x509);
829 2 bio = sv_bio_create();
830  
831 /* Silence warning */
832 2 ▶ if (ix)
Branch: 1 branch
BranchTrueFalseTotal
if (ix) 1 1 2
833  
834 1 ▶ if (pkey == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (pkey == NULL) { 0 1 1
835 0 BIO_free_all(bio);
836 0 EVP_PKEY_free(pkey);
837 0 croak("Exponent is unavailable\n");
838 }
839  
840 2 ▶ if (EVP_PKEY_base_id(pkey) == EVP_PKEY_RSA) {
Branch: 1 branch
BranchTrueFalseTotal
if (EVP_PKEY_base_id(pkey) == EVP_PKEY_RSA) { 2 0 2
841 const RSA *rsa_pkey;
842 const BIGNUM *e;
843  
844 2 rsa_pkey = EVP_PKEY_get0_RSA(pkey);
845 2 RSA_get0_key(rsa_pkey, NULL, &e, NULL);
846  
847 2 BN_print(bio, e);
848 } else {
849 0 BIO_free_all(bio);
850 0 EVP_PKEY_free(pkey);
851 0 croak("Wrong Algorithm type -- exponent only available with RSA\n");
852 }
853  
854 2 RETVAL = sv_bio_final(bio);
855  
856 2 EVP_PKEY_free(pkey);
857  
858 OUTPUT:
859 RETVAL
860  
861 SV*
862 fingerprint_md5(x509)
863 Crypt::OpenSSL::X509 x509;
864  
865 ALIAS:
866 fingerprint_sha1 = 1
867 fingerprint_sha224 = 2
868 fingerprint_sha256 = 3
869 fingerprint_sha384 = 4
870 fingerprint_sha512 = 5
871  
872 PREINIT:
873  
874 7 ▶ const EVP_MD *mds[] = { EVP_md5(), EVP_sha1(), EVP_sha224(), EVP_sha256(), EVP_sha384(), EVP_sha512() };
Branch: 1 branch
BranchTrueFalseTotal
const EVP_MD *mds[] = { EVP_md5(), EVP_sha1(), EVP_sha224(), EVP_sha256(), EVP_sha384(), EVP_sha512() }; 7 0 7
875 unsigned char md[EVP_MAX_MD_SIZE];
876 int i;
877 unsigned int n;
878 BIO *bio;
879  
880 CODE:
881  
882 7 bio = sv_bio_create();
883  
884 7 ▶ if (!X509_digest(x509, mds[ix], md, &n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!X509_digest(x509, mds[ix], md, &n)) { 0 7 7
885  
886 0 BIO_free_all(bio);
887 0 croak("Digest error: %s", ssl_error());
888 }
889  
890 7 BIO_printf(bio, "%02X", md[0]);
891 224 ▶ for (i = 1; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < n; i++) { 217 7 224
892 217 BIO_printf(bio, ":%02X", md[i]);
893 }
894  
895 7 RETVAL = sv_bio_final(bio);
896  
897 OUTPUT:
898 RETVAL
899  
900 SV*
901 checkend(x509, checkoffset)
902 Crypt::OpenSSL::X509 x509;
903 IV checkoffset;
904  
905 PREINIT:
906 time_t now;
907  
908 CODE:
909  
910 0 now = time(NULL);
911  
912 /* given an offset in seconds, will the certificate be expired? */
913 #if OPENSSL_VERSION_NUMBER < 0x10100000
914 if (ASN1_UTCTIME_cmp_time_t(X509_get_notAfter(x509), now + (int)checkoffset) == -1) {
915 #else
916 0 ▶ if (ASN1_UTCTIME_cmp_time_t(X509_get0_notAfter(x509), now + (int)checkoffset) == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ASN1_UTCTIME_cmp_time_t(X509_get0_notAfter(x509), now + (int)checkoffset) == -1) { 0 0 0
917 #endif
918 0 RETVAL = &PL_sv_yes;
919 } else {
920 0 RETVAL = &PL_sv_no;
921 }
922  
923 OUTPUT:
924 RETVAL
925  
926 SV*
927 pubkey(x509)
928 Crypt::OpenSSL::X509 x509;
929  
930 PREINIT:
931 EVP_PKEY *pkey;
932 BIO *bio;
933 int pkey_id;
934  
935 CODE:
936  
937 0 pkey = X509_get_pubkey(x509);
938 0 bio = sv_bio_create();
939  
940 0 ▶ if (pkey == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (pkey == NULL) { 0 0 0
941  
942 0 BIO_free_all(bio);
943 0 EVP_PKEY_free(pkey);
944 0 croak("Public Key is unavailable\n");
945 }
946  
947 0 pkey_id = EVP_PKEY_base_id(pkey);
948 0 ▶ if (pkey_id == EVP_PKEY_RSA) {
Branch: 1 branch
BranchTrueFalseTotal
if (pkey_id == EVP_PKEY_RSA) { 0 0 0
949 const RSA *rsa_pkey;
950  
951 0 rsa_pkey = EVP_PKEY_get0_RSA(pkey);
952 0 PEM_write_bio_RSAPublicKey(bio, rsa_pkey);
953  
954 0 ▶ } else if (pkey_id == EVP_PKEY_DSA) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (pkey_id == EVP_PKEY_DSA) { 0 0 0
955 const DSA *dsa_pkey;
956  
957 0 dsa_pkey = EVP_PKEY_get0_DSA(pkey);
958 /* In openssl v3, EVP_PKEY_get0_DSA came to return "const DSA*" type.
959 * However PEM_write_bio_DSA_PUBKEY still needs non-const DSA*.
960 * So we should force to cast dsa_pkey to "DSA*" here.
961 */
962 0 PEM_write_bio_DSA_PUBKEY(bio, (DSA*)dsa_pkey);
963 #ifndef OPENSSL_NO_EC
964 0 ▶ } else if (pkey_id == EVP_PKEY_EC ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (pkey_id == EVP_PKEY_EC ) { 0 0 0
965 const EC_KEY *ec_pkey;
966  
967 0 ec_pkey = EVP_PKEY_get0_EC_KEY(pkey);
968 /* In openssl v3, EVP_PKEY_get0_EC_KEY came to return "const EC_KEY*" type.
969 * However PEM_write_bio_EC_PUBKEY still needs non-const EC_KEY*.
970 * So we should force to cast ec_pkey to "EC_KEY*" here.
971 */
972 0 PEM_write_bio_EC_PUBKEY(bio, (EC_KEY*)ec_pkey);
973 #endif
974 } else {
975  
976 0 BIO_free_all(bio);
977 0 EVP_PKEY_free(pkey);
978 0 croak("Wrong Algorithm type\n");
979 }
980  
981 0 EVP_PKEY_free(pkey);
982  
983 0 RETVAL = sv_bio_final(bio);
984  
985 OUTPUT:
986 RETVAL
987  
988 const char*
989 pubkey_type(x509)
990 Crypt::OpenSSL::X509 x509;
991 PREINIT:
992 EVP_PKEY *pkey;
993 int pkey_id;
994 CODE:
995 1 RETVAL=NULL;
996 1 pkey = X509_get_pubkey(x509);
997  
998 1 ▶ if(!pkey)
Branch: 1 branch
BranchTrueFalseTotal
if(!pkey) 0 1 1
999 0 XSRETURN_UNDEF;
1000  
1001 1 pkey_id = EVP_PKEY_base_id(pkey);
1002 1 ▶ if (pkey_id == EVP_PKEY_DSA) {
Branch: 1 branch
BranchTrueFalseTotal
if (pkey_id == EVP_PKEY_DSA) { 0 1 1
1003 0 RETVAL="dsa";
1004  
1005 1 ▶ } else if (pkey_id == EVP_PKEY_RSA) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (pkey_id == EVP_PKEY_RSA) { 0 1 1
1006 0 RETVAL="rsa";
1007 #ifndef OPENSSL_NO_EC
1008 1 ▶ } else if (pkey_id == EVP_PKEY_EC ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (pkey_id == EVP_PKEY_EC ) { 1 0 1
1009 1 RETVAL="ec";
1010 #endif
1011 }
1012  
1013 OUTPUT:
1014 RETVAL
1015  
1016 int
1017 num_extensions(x509)
1018 Crypt::OpenSSL::X509 x509;
1019  
1020 CODE:
1021 1 RETVAL = X509_get_ext_count(x509);
1022  
1023 OUTPUT:
1024 RETVAL
1025  
1026 Crypt::OpenSSL::X509::Extension
1027 extension(x509, i)
1028 Crypt::OpenSSL::X509 x509;
1029 int i;
1030  
1031 PREINIT:
1032 X509_EXTENSION *ext;
1033 int c;
1034  
1035 CODE:
1036 0 ext = NULL;
1037  
1038 0 c = X509_get_ext_count(x509);
1039  
1040 0 ▶ if (!(c > 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(c > 0)) { 0 0 0
1041 0 croak("No extensions found\n");
1042 0 ▶ } else if (i >= c || i < 0) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (i >= c || i < 0) { 0 0 0
} else if (i >= c || i < 0) { 0 0 0
1043 0 croak("Requested extension index out of range\n");
1044 } else {
1045 0 ext = (X509_EXTENSION *)X509_get_ext(x509, i);
1046 }
1047  
1048 0 ▶ if (ext == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext == NULL) { 0 0 0
1049 /* X509_EXTENSION_free(ext); // not needed? */
1050 0 croak("Extension unavailable\n");
1051 }
1052  
1053 0 RETVAL = ext;
1054  
1055 OUTPUT:
1056 RETVAL
1057  
1058 HV*
1059 extensions(x509)
1060 Crypt::OpenSSL::X509 x509
1061  
1062 ALIAS:
1063 extensions_by_long_name = 0
1064 extensions_by_oid = 1
1065 extensions_by_name = 2
1066  
1067 CODE:
1068 12 RETVAL = hv_exts(x509, ix);
1069  
1070 OUTPUT:
1071 RETVAL
1072  
1073 MODULE = Crypt::OpenSSL::X509 PACKAGE = Crypt::OpenSSL::X509::Extension
1074  
1075 int
1076 critical(ext)
1077 Crypt::OpenSSL::X509::Extension ext;
1078  
1079 CODE:
1080  
1081 3 ▶ if (ext == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext == NULL) { 0 3 3
1082 0 croak("No extension supplied\n");
1083 }
1084  
1085 3 RETVAL = X509_EXTENSION_get_critical(ext);
1086  
1087 OUTPUT:
1088 RETVAL
1089  
1090 Crypt::OpenSSL::X509::ObjectID
1091 object(ext)
1092 Crypt::OpenSSL::X509::Extension ext;
1093  
1094 CODE:
1095  
1096 1 ▶ if (ext == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext == NULL) { 0 1 1
1097 0 croak("No extension supplied\n");
1098 }
1099  
1100 1 RETVAL = (ASN1_OBJECT *)X509_EXTENSION_get_object(ext);
1101  
1102 OUTPUT:
1103 RETVAL
1104  
1105 SV*
1106 value(ext)
1107 Crypt::OpenSSL::X509::Extension ext;
1108  
1109 PREINIT:
1110 BIO* bio;
1111  
1112 CODE:
1113 3 bio = sv_bio_create();
1114  
1115 3 ▶ if (ext == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext == NULL) { 0 3 3
1116 0 BIO_free_all(bio);
1117 0 croak("No extension supplied\n");
1118 }
1119  
1120 3 ASN1_STRING_print_ex(bio, X509_EXTENSION_get_data(ext), ASN1_STRFLGS_DUMP_ALL);
1121  
1122 3 RETVAL = sv_bio_final(bio);
1123  
1124 OUTPUT:
1125 RETVAL
1126  
1127 SV*
1128 to_string(ext)
1129 Crypt::OpenSSL::X509::Extension ext;
1130 ALIAS:
1131 as_string = 1
1132  
1133 PREINIT:
1134 BIO* bio;
1135
1136 CODE:
1137 (void)ix;
1138 2 bio = sv_bio_create();
1139  
1140 2 ▶ if (ext == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (ext == NULL) { 0 2 2
1141 0 BIO_free_all(bio);
1142 0 croak("No extension supplied\n");
1143 }
1144  
1145 2 X509V3_EXT_print(bio, ext, 0, 0);
1146  
1147 2 RETVAL = sv_bio_final(bio);
1148  
1149 OUTPUT:
1150 RETVAL
1151  
1152 int
1153 basicC(ext, value)
1154 Crypt::OpenSSL::X509::Extension ext;
1155 char *value;
1156  
1157 PREINIT:
1158 BASIC_CONSTRAINTS *bs;
1159 1 ▶ int ret = 0;
Branch: 1 branch
BranchTrueFalseTotal
int ret = 0; 1 0 1
1160  
1161 CODE:
1162  
1163 /* retrieve the value of CA or pathlen in basicConstraints */
1164 1 bs = X509V3_EXT_d2i(ext);
1165  
1166 /* X509V3_EXT_d2i() returns NULL when the extension's DER fails to parse.
1167 basicC() feeds a security decision (callers test CA / pathLenConstraint),
1168 so a malformed extension must be rejected rather than silently treated
1169 as ca=0 / pathlen=0. Croak instead of dereferencing NULL. */
1170 1 ▶ if (bs == NULL) croak("Error parsing basicConstraints extension\n");
Branch: 1 branch
BranchTrueFalseTotal
if (bs == NULL) croak("Error parsing basicConstraints extension\n"); 0 1 1
1171  
1172 1 ▶ if (strcmp(value, "ca") == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (strcmp(value, "ca") == 0) { 1 0 1
1173 1 ret = bs->ca ? 1 : 0;
1174  
1175 0 ▶ } else if (strcmp(value, "pathlen") == 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (strcmp(value, "pathlen") == 0) { 0 0 0
1176 0 ret = bs->pathlen ? 1 : 0;
1177 }
1178  
1179 1 BASIC_CONSTRAINTS_free(bs);
1180  
1181 1 ▶ RETVAL = ret;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ret; 0 1 1
1182  
1183 OUTPUT:
1184 RETVAL
1185  
1186 SV*
1187 ia5string(ext)
1188 Crypt::OpenSSL::X509::Extension ext;
1189  
1190 PREINIT:
1191 ASN1_IA5STRING *str;
1192 BIO *bio;
1193  
1194 CODE:
1195  
1196 /* retrieving the value of an ia5string object */
1197 0 bio = sv_bio_create();
1198 0 str = X509V3_EXT_d2i(ext);
1199 /* X509V3_EXT_d2i() returns NULL on a malformed extension; guard the
1200 dereference and return an empty string rather than crashing. */
1201 0 ▶ if (str != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (str != NULL) { 0 0 0
1202 #if OPENSSL_VERSION_NUMBER >= 0x40000000L
1203 BIO_write(bio, ASN1_STRING_get0_data((ASN1_STRING *)str),
1204 ASN1_STRING_length((ASN1_STRING *)str));
1205 #else
1206 0 BIO_write(bio, str->data, str->length);
1207 #endif
1208 0 ASN1_IA5STRING_free(str);
1209 }
1210  
1211 0 RETVAL = sv_bio_final(bio);
1212  
1213 OUTPUT:
1214 RETVAL
1215  
1216 SV*
1217 bit_string(ext)
1218 Crypt::OpenSSL::X509::Extension ext;
1219  
1220 PREINIT:
1221 int i, nid;
1222 ASN1_OBJECT *object;
1223 ASN1_BIT_STRING *bit_str;
1224 int string[10];
1225 BIO *bio;
1226  
1227 CODE:
1228 1 bio = sv_bio_create();
1229  
1230 1 object = (ASN1_OBJECT *)X509_EXTENSION_get_object(ext);
1231 1 nid = OBJ_obj2nid(object);
1232 1 bit_str = X509V3_EXT_d2i(ext);
1233  
1234 /* ASN1_BIT_STRING_get_bit() is NULL-tolerant (returns 0 for NULL), so
1235 this guard is defence-in-depth rather than a crash fix. */
1236 1 ▶ if (bit_str != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (bit_str != NULL) { 1 0 1
1237 1 ▶ if (nid == NID_key_usage) {
Branch: 1 branch
BranchTrueFalseTotal
if (nid == NID_key_usage) { 1 0 1
1238  
1239 10 ▶ for (i = 0; i < 9; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 9; i++) { 9 1 10
1240 9 string[i] = (int)ASN1_BIT_STRING_get_bit(bit_str, i);
1241 9 BIO_printf(bio, "%d", string[i]);
1242 }
1243  
1244 0 ▶ } else if (nid == NID_netscape_cert_type) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (nid == NID_netscape_cert_type) { 0 0 0
1245  
1246 0 ▶ for (i = 0; i < 8; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 8; i++) { 0 0 0
1247 0 string[i] = (int)ASN1_BIT_STRING_get_bit(bit_str, i);
1248 0 BIO_printf(bio, "%d", string[i]);
1249 }
1250 }
1251 1 ASN1_BIT_STRING_free(bit_str);
1252 }
1253  
1254 1 RETVAL = sv_bio_final(bio);
1255  
1256 OUTPUT:
1257 RETVAL
1258  
1259 SV*
1260 extendedKeyUsage(ext)
1261 Crypt::OpenSSL::X509::Extension ext;
1262  
1263 PREINIT:
1264 BIO *bio;
1265 STACK_OF(ASN1_OBJECT) *extku;
1266 int nid;
1267 const char *value;
1268  
1269 CODE:
1270  
1271 0 bio = sv_bio_create();
1272 0 extku = (STACK_OF(ASN1_OBJECT)*) X509V3_EXT_d2i(ext);
1273  
1274 /* OPENSSL_sk_num(NULL) returns -1 so the loop body never runs on NULL
1275 extku -- this guard is defence-in-depth. The real fix here is freeing
1276 both the popped ASN1_OBJECTs and the stack container, which the
1277 original code leaked on every call. */
1278 0 ▶ if (extku != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (extku != NULL) { 0 0 0
1279 ASN1_OBJECT *obj;
1280 0 ▶ while((obj = sk_ASN1_OBJECT_pop(extku)) != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
while((obj = sk_ASN1_OBJECT_pop(extku)) != NULL) { 0 0 0
1281 0 nid = OBJ_obj2nid(obj);
1282 0 ASN1_OBJECT_free(obj);
1283 0 value = OBJ_nid2sn(nid);
1284 0 ▶ if (value != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (value != NULL) { 0 0 0
1285 0 BIO_printf(bio, "%s ", value);
1286 }
1287 }
1288 0 sk_ASN1_OBJECT_free(extku);
1289 }
1290  
1291 0 RETVAL = sv_bio_final(bio);
1292  
1293 OUTPUT:
1294 RETVAL
1295  
1296 int
1297 auth_att(ext)
1298 Crypt::OpenSSL::X509::Extension ext;
1299  
1300 PREINIT:
1301 AUTHORITY_KEYID *akid;
1302  
1303 CODE:
1304  
1305 0 akid = X509V3_EXT_d2i(ext);
1306 /* akid is NULL on a malformed extension, and a well-formed AUTHORITY_KEYID
1307 may legitimately have a NULL optional keyid field -- both must not be
1308 dereferenced. Also free akid, which the original code leaked. */
1309 0 ▶ RETVAL = (akid != NULL && akid->keyid != NULL) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = (akid != NULL && akid->keyid != NULL) ? 1 : 0; 0 0 0
RETVAL = (akid != NULL && akid->keyid != NULL) ? 1 : 0; 0 0 0
1310 0 ▶ if (akid != NULL) AUTHORITY_KEYID_free(akid);
Branch: 1 branch
BranchTrueFalseTotal
if (akid != NULL) AUTHORITY_KEYID_free(akid); 0 0 0
1311  
1312 OUTPUT:
1313 RETVAL
1314  
1315 SV*
1316 keyid_data(ext)
1317 Crypt::OpenSSL::X509::Extension ext;
1318  
1319 PREINIT:
1320 AUTHORITY_KEYID *akid;
1321 ASN1_OCTET_STRING *skid;
1322 int nid, len;
1323 const unsigned char *p;
1324 ASN1_OBJECT *object;
1325 BIO *bio;
1326  
1327 CODE:
1328  
1329 1 bio = sv_bio_create();
1330 1 object = (ASN1_OBJECT *)X509_EXTENSION_get_object(ext);
1331 1 nid = OBJ_obj2nid(object);
1332  
1333 1 ▶ if (nid == NID_authority_key_identifier) {
Branch: 1 branch
BranchTrueFalseTotal
if (nid == NID_authority_key_identifier) { 0 1 1
1334  
1335 0 akid = X509V3_EXT_d2i(ext);
1336 /* akid is NULL on a malformed AKI; akid->keyid is an optional field that
1337 is legitimately NULL (e.g. an AKI carrying only issuer/serial). Guard
1338 both before dereferencing -- otherwise either is a NULL-deref crash. */
1339 0 ▶ if (akid != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (akid != NULL) { 0 0 0
1340 0 ▶ if (akid->keyid != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (akid->keyid != NULL) { 0 0 0
1341 #if OPENSSL_VERSION_NUMBER >= 0x40000000L
1342 p = ASN1_STRING_get0_data((ASN1_STRING *)akid->keyid);
1343 len = ASN1_STRING_length((ASN1_STRING *)akid->keyid);
1344 #else
1345 0 p = akid->keyid->data;
1346 0 len = akid->keyid->length;
1347 #endif
1348 0 BIO_write(bio, p, len);
1349 }
1350 0 AUTHORITY_KEYID_free(akid);
1351 }
1352  
1353 1 ▶ } else if (nid == NID_subject_key_identifier) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (nid == NID_subject_key_identifier) { 1 0 1
1354  
1355 1 skid = X509V3_EXT_d2i(ext);
1356 /* skid is NULL on a malformed subjectKeyIdentifier; guard the deref. */
1357 1 ▶ if (skid != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (skid != NULL) { 1 0 1
1358 #if OPENSSL_VERSION_NUMBER >= 0x40000000L
1359 p = ASN1_STRING_get0_data((ASN1_STRING *)skid);
1360 len = ASN1_STRING_length((ASN1_STRING *)skid);
1361 #else
1362 1 p = skid->data;
1363 1 len = skid->length;
1364 #endif
1365 1 BIO_write(bio, p, len);
1366 1 ASN1_OCTET_STRING_free(skid);
1367 }
1368 }
1369  
1370 1 RETVAL = sv_bio_final(bio);
1371  
1372 OUTPUT:
1373 RETVAL
1374  
1375 MODULE = Crypt::OpenSSL::X509 PACKAGE = Crypt::OpenSSL::X509::ObjectID
1376 char*
1377 name(obj)
1378 Crypt::OpenSSL::X509::ObjectID obj;
1379  
1380 PREINIT:
1381 char buf[128];
1382  
1383 CODE:
1384  
1385 1 ▶ if (obj == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (obj == NULL) { 0 1 1
1386 0 croak("No ObjectID supplied\n");
1387 }
1388  
1389 1 (void)OBJ_obj2txt(buf, 128, obj, 0);
1390  
1391 1 RETVAL = buf;
1392  
1393 OUTPUT:
1394 RETVAL
1395  
1396 char*
1397 oid(obj)
1398 Crypt::OpenSSL::X509::ObjectID obj;
1399  
1400 PREINIT:
1401 char buf[128];
1402  
1403 CODE:
1404  
1405 0 ▶ if (obj == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (obj == NULL) { 0 0 0
1406 0 croak("No ObjectID supplied\n");
1407 }
1408  
1409 0 (void)OBJ_obj2txt(buf, 128, obj, 1);
1410  
1411 0 RETVAL = buf;
1412  
1413 OUTPUT:
1414 RETVAL
1415  
1416 MODULE = Crypt::OpenSSL::X509 PACKAGE = Crypt::OpenSSL::X509::Name
1417  
1418 SV*
1419 as_string(name)
1420 Crypt::OpenSSL::X509::Name name;
1421  
1422 PREINIT:
1423 BIO *bio;
1424  
1425 CODE:
1426  
1427 2 bio = sv_bio_create();
1428 /* this is prefered over X509_NAME_oneline() */
1429 2 X509_NAME_print_ex(bio, name, 0, XN_FLAG_SEP_CPLUS_SPC);
1430  
1431 2 RETVAL = sv_bio_final(bio);
1432  
1433 OUTPUT:
1434 RETVAL
1435  
1436 AV*
1437 entries(name)
1438 Crypt::OpenSSL::X509::Name name;
1439  
1440 PREINIT:
1441 int i, c;
1442 SV* rv;
1443  
1444 CODE:
1445  
1446 1 RETVAL = newAV();
1447 1 sv_2mortal((SV*)RETVAL);
1448  
1449 1 c = X509_NAME_entry_count(name);
1450  
1451 8 ▶ for (i = 0; i < c; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < c; i++) { 7 1 8
1452 7 rv = sv_make_ref("Crypt::OpenSSL::X509::Name_Entry", (void*)(X509_NAME_ENTRY *)X509_NAME_get_entry(name, i));
1453 7 av_push(RETVAL, rv);
1454 }
1455  
1456 OUTPUT:
1457 RETVAL
1458  
1459 int
1460 get_index_by_type(name, type, lastpos = -1)
1461 Crypt::OpenSSL::X509::Name name;
1462 const char* type;
1463 int lastpos;
1464  
1465 ALIAS:
1466 get_index_by_long_type = 1
1467 has_entry = 2
1468 has_long_entry = 3
1469 has_oid_entry = 4
1470 get_index_by_oid_type = 5
1471  
1472 PREINIT:
1473 int nid, i;
1474  
1475 CODE:
1476  
1477 6 ▶ if (ix == 1 || ix == 3) {
Branch: 2 branches
BranchTrueFalseTotal
if (ix == 1 || ix == 3) { 5 1 6
if (ix == 1 || ix == 3) { 1 4 5
1478 2 nid = OBJ_ln2nid(type);
1479 4 ▶ } else if (ix == 4 || ix == 5) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (ix == 4 || ix == 5) { 2 2 4
} else if (ix == 4 || ix == 5) { 0 2 2
1480 2 nid = OBJ_obj2nid(OBJ_txt2obj(type, /*oid*/ 1));
1481 } else {
1482 2 nid = OBJ_sn2nid(type);
1483 }
1484  
1485 6 ▶ if (!nid) {
Branch: 1 branch
BranchTrueFalseTotal
if (!nid) { 0 6 6
1486 0 croak("Unknown type");
1487 }
1488  
1489 6 i = X509_NAME_get_index_by_NID(name, nid, lastpos);
1490  
1491 6 ▶ if (ix == 2 || ix == 3 || ix == 4) { /* has_entry */
Branch: 3 branches
BranchTrueFalseTotal
if (ix == 2 || ix == 3 || ix == 4) { /* has_entry */ 5 1 6
if (ix == 2 || ix == 3 || ix == 4) { /* has_entry */ 4 1 5
if (ix == 2 || ix == 3 || ix == 4) { /* has_entry */ 2 2 4
1492 4 RETVAL = (i > lastpos)?1:0;
1493 } else { /* get_index */
1494 2 RETVAL = i;
1495 }
1496  
1497 OUTPUT:
1498 RETVAL
1499  
1500 Crypt::OpenSSL::X509::Name_Entry
1501 get_entry_by_type(name, type, lastpos = -1)
1502 Crypt::OpenSSL::X509::Name name;
1503 const char* type;
1504 int lastpos;
1505  
1506 ALIAS:
1507 get_entry_by_long_type = 1
1508  
1509 PREINIT:
1510 int nid, i;
1511  
1512 CODE:
1513  
1514 3 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 3 3
1515 0 nid = OBJ_ln2nid(type);
1516 } else {
1517 3 nid = OBJ_sn2nid(type);
1518 }
1519  
1520 3 ▶ if (!nid) {
Branch: 1 branch
BranchTrueFalseTotal
if (!nid) { 0 3 3
1521 0 croak("Unknown type");
1522 }
1523  
1524 3 i = X509_NAME_get_index_by_NID(name, nid, lastpos);
1525 3 RETVAL = (X509_NAME_ENTRY *)X509_NAME_get_entry(name, i);
1526  
1527 OUTPUT:
1528 RETVAL
1529  
1530  
1531 MODULE = Crypt::OpenSSL::X509 PACKAGE = Crypt::OpenSSL::X509::Name_Entry
1532  
1533 SV*
1534 as_string(name_entry, ln = 0)
1535 Crypt::OpenSSL::X509::Name_Entry name_entry;
1536 int ln;
1537  
1538 ALIAS:
1539 as_long_string = 1
1540  
1541 PREINIT:
1542 BIO *bio;
1543 const char *n;
1544 int nid;
1545  
1546 CODE:
1547 2 bio = sv_bio_create();
1548 2 nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(name_entry));
1549  
1550 2 ▶ if (ix == 1 || ln) {
Branch: 2 branches
BranchTrueFalseTotal
if (ix == 1 || ln) { 1 1 2
if (ix == 1 || ln) { 0 1 1
1551 1 n = OBJ_nid2ln(nid);
1552 } else {
1553 1 n = OBJ_nid2sn(nid);
1554 }
1555  
1556 2 BIO_printf(bio, "%s=", n);
1557  
1558 2 ASN1_STRING_print_ex(bio, X509_NAME_ENTRY_get_data(name_entry), ASN1_STRFLGS_UTF8_CONVERT & ~ASN1_STRFLGS_ESC_MSB);
1559  
1560 2 sv_bio_utf8_on(bio);
1561  
1562 2 RETVAL = sv_bio_final(bio);
1563  
1564 OUTPUT:
1565 RETVAL
1566  
1567 SV*
1568 type(name_entry, ln = 0)
1569 Crypt::OpenSSL::X509::Name_Entry name_entry;
1570 int ln;
1571  
1572 ALIAS:
1573 long_type = 1
1574  
1575 PREINIT:
1576 BIO *bio;
1577 const char *n;
1578 int nid;
1579  
1580 CODE:
1581 2 bio = sv_bio_create();
1582 2 nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(name_entry));
1583  
1584 2 ▶ if (ix == 1 || ln) {
Branch: 2 branches
BranchTrueFalseTotal
if (ix == 1 || ln) { 1 1 2
if (ix == 1 || ln) { 0 1 1
1585 1 n = OBJ_nid2ln(nid);
1586 } else {
1587 1 n = OBJ_nid2sn(nid);
1588 }
1589  
1590 2 BIO_printf(bio, "%s", n);
1591 2 RETVAL = sv_bio_final(bio);
1592  
1593 OUTPUT:
1594 RETVAL
1595  
1596 SV*
1597 value(name_entry)
1598 Crypt::OpenSSL::X509::Name_Entry name_entry;
1599  
1600 PREINIT:
1601 BIO *bio;
1602  
1603 CODE:
1604 1 bio = sv_bio_create();
1605 1 ASN1_STRING_print(bio, X509_NAME_ENTRY_get_data(name_entry));
1606 1 RETVAL = sv_bio_final(bio);
1607  
1608 OUTPUT:
1609 RETVAL
1610  
1611 int
1612 is_printableString(name_entry, asn1_type = V_ASN1_PRINTABLESTRING)
1613 Crypt::OpenSSL::X509::Name_Entry name_entry;
1614 int asn1_type;
1615  
1616 ALIAS:
1617 is_asn1_type = 1
1618 is_printableString = V_ASN1_PRINTABLESTRING
1619 is_ia5string = V_ASN1_IA5STRING
1620 is_utf8string = V_ASN1_UTF8STRING
1621  
1622 CODE:
1623 #if OPENSSL_VERSION_NUMBER >= 0x40000000L
1624 RETVAL = (ASN1_STRING_type(X509_NAME_ENTRY_get_data(name_entry)) == (ix == 1 ? asn1_type : ix));
1625 #else
1626 2 ▶ RETVAL = (X509_NAME_ENTRY_get_data(name_entry)->type == (ix == 1 ? asn1_type : ix));
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = (X509_NAME_ENTRY_get_data(name_entry)->type == (ix == 1 ? asn1_type : ix)); 1 1 2
RETVAL = (X509_NAME_ENTRY_get_data(name_entry)->type == (ix == 1 ? asn1_type : ix)); 0 2 2
1627 #endif
1628  
1629 OUTPUT:
1630 RETVAL
1631  
1632 const char*
1633 encoding(name_entry)
1634 Crypt::OpenSSL::X509::Name_Entry name_entry;
1635  
1636 CODE:
1637 #if OPENSSL_VERSION_NUMBER >= 0x40000000L
1638 {
1639 int asn1_str_type = ASN1_STRING_type(X509_NAME_ENTRY_get_data(name_entry));
1640 if (asn1_str_type == V_ASN1_PRINTABLESTRING) {
1641 RETVAL = "printableString";
1642 } else if (asn1_str_type == V_ASN1_IA5STRING) {
1643 RETVAL = "ia5String";
1644 } else if (asn1_str_type == V_ASN1_UTF8STRING) {
1645 RETVAL = "utf8String";
1646 } else {
1647 RETVAL = NULL;
1648 }
1649 }
1650 #else
1651 0 RETVAL = NULL;
1652  
1653 0 ▶ if (X509_NAME_ENTRY_get_data(name_entry)->type == V_ASN1_PRINTABLESTRING) {
Branch: 1 branch
BranchTrueFalseTotal
if (X509_NAME_ENTRY_get_data(name_entry)->type == V_ASN1_PRINTABLESTRING) { 0 0 0
1654 0 RETVAL = "printableString";
1655  
1656 0 ▶ } else if(X509_NAME_ENTRY_get_data(name_entry)->type == V_ASN1_IA5STRING) {
Branch: 1 branch
BranchTrueFalseTotal
} else if(X509_NAME_ENTRY_get_data(name_entry)->type == V_ASN1_IA5STRING) { 0 0 0
1657 0 RETVAL = "ia5String";
1658  
1659 0 ▶ } else if(X509_NAME_ENTRY_get_data(name_entry)->type == V_ASN1_UTF8STRING) {
Branch: 1 branch
BranchTrueFalseTotal
} else if(X509_NAME_ENTRY_get_data(name_entry)->type == V_ASN1_UTF8STRING) { 0 0 0
1660 0 RETVAL = "utf8String";
1661 }
1662 #endif
1663  
1664 OUTPUT:
1665 RETVAL
1666  
1667 MODULE = Crypt::OpenSSL::X509 PACKAGE = Crypt::OpenSSL::X509_CRL
1668  
1669 Crypt::OpenSSL::X509::CRL
1670 new_from_crl_string(class, string, format = FORMAT_PEM)
1671 SV *class;
1672 SV *string;
1673 int format;
1674  
1675 ALIAS:
1676 new_from_crl_file = 1
1677  
1678 PREINIT:
1679 BIO *bio;
1680 STRLEN len;
1681 char *crl;
1682  
1683 CODE:
1684  
1685 0 crl = SvPV(string, len);
1686  
1687 0 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 0 0
1688 0 bio = BIO_new_file(crl, "r");
1689 } else {
1690 0 bio = BIO_new_mem_buf(crl, len);
1691 }
1692  
1693 0 ▶ if (!bio) {
Branch: 1 branch
BranchTrueFalseTotal
if (!bio) { 0 0 0
1694 0 croak("%s: Failed to create BIO", SvPV_nolen(class));
1695 }
1696  
1697 0 ▶ if (format == FORMAT_ASN1) {
Branch: 1 branch
BranchTrueFalseTotal
if (format == FORMAT_ASN1) { 0 0 0
1698 0 RETVAL = (X509_CRL*)d2i_X509_CRL_bio(bio, NULL);
1699 } else {
1700 0 RETVAL = (X509_CRL*)PEM_read_bio_X509_CRL(bio, NULL, NULL, NULL);
1701 }
1702  
1703 0 ▶ if (!RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) { 0 0 0
1704 0 croak("%s: failed to read X509 certificate.", SvPV_nolen(class));
1705 }
1706  
1707 0 BIO_free(bio);
1708  
1709 OUTPUT:
1710 RETVAL
1711  
1712 SV*
1713 CRL_accessor(crl)
1714 Crypt::OpenSSL::X509::CRL crl;
1715  
1716 ALIAS:
1717 CRL_issuer = 1
1718 CRL_sig_alg_name = 2
1719  
1720 PREINIT:
1721 BIO *bio;
1722 X509_NAME *name;
1723  
1724 CODE:
1725 0 bio = sv_bio_create();
1726  
1727 0 ▶ if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 1) { 0 0 0
1728 0 name = (X509_NAME *)X509_CRL_get_issuer(crl);
1729 0 sv_bio_utf8_on(bio);
1730 0 X509_NAME_print_ex(bio, name, 0, (XN_FLAG_SEP_CPLUS_SPC | ASN1_STRFLGS_UTF8_CONVERT) & ~ASN1_STRFLGS_ESC_MSB);
1731  
1732 0 ▶ } else if (ix == 2) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ix == 2) { 0 0 0
1733 const_ossl11 X509_ALGOR *palg;
1734 const_ossl11 ASN1_OBJECT *paobj;
1735  
1736 0 X509_CRL_get0_signature(crl, NULL, &palg);
1737 0 X509_ALGOR_get0(&paobj, NULL, NULL, palg);
1738  
1739 0 i2a_ASN1_OBJECT(bio, paobj);
1740 }
1741  
1742 0 RETVAL = sv_bio_final(bio);
1743  
1744 OUTPUT:
1745 RETVAL
« blib/lib/Crypt/OpenSSL/X509.pm ↑ Summary