Commit | Line | Data |
---|---|---|
9d1c15ef JH |
1 | /************************************************* |
2 | * Exim - an Internet mail transport agent * | |
3 | *************************************************/ | |
4 | ||
f9ba5e22 | 5 | /* Copyright (c) Jeremy Harris 2014 - 2018 */ |
9d1c15ef JH |
6 | |
7 | /* This module provides TLS (aka SSL) support for Exim using the OpenSSL | |
8 | library. It is #included into the tls.c file when that library is used. | |
9 | */ | |
10 | ||
11 | ||
12 | /* Heading stuff */ | |
13 | ||
14 | #include <openssl/lhash.h> | |
15 | #include <openssl/ssl.h> | |
16 | #include <openssl/err.h> | |
17 | #include <openssl/rand.h> | |
51424d08 | 18 | #include <openssl/x509v3.h> |
9d1c15ef | 19 | |
c8dfb21d JH |
20 | #if OPENSSL_VERSION_NUMBER >= 0x10100000L |
21 | # define EXIM_HAVE_ASN1_MACROS | |
22 | #endif | |
23 | ||
3ae79556 JH |
24 | #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) |
25 | # define ASN1_STRING_get0_data ASN1_STRING_data | |
26 | #endif | |
9d1c15ef JH |
27 | |
28 | /***************************************************** | |
29 | * Export/import a certificate, binary/printable | |
30 | *****************************************************/ | |
31 | int | |
32 | tls_export_cert(uschar * buf, size_t buflen, void * cert) | |
33 | { | |
34 | BIO * bp = BIO_new(BIO_s_mem()); | |
35 | int fail; | |
36 | ||
37 | if ((fail = PEM_write_bio_X509(bp, (X509 *)cert) ? 0 : 1)) | |
38 | log_write(0, LOG_MAIN, "TLS error in certificate export: %s", | |
39 | ERR_error_string(ERR_get_error(), NULL)); | |
40 | else | |
41 | { | |
42 | char * cp = CS buf; | |
43 | int n; | |
44 | buflen -= 2; | |
45 | for(;;) | |
46 | { | |
47 | if ((n = BIO_gets(bp, cp, (int)buflen)) <= 0) break; | |
48 | cp += n+1; | |
49 | buflen -= n+1; | |
50 | cp[-2] = '\\'; cp[-1] = 'n'; /* newline->"\n" */ | |
51 | } /* compat with string_printing() */ | |
52 | *cp = '\0'; | |
53 | } | |
54 | ||
55 | BIO_free(bp); | |
56 | return fail; | |
57 | } | |
58 | ||
59 | int | |
60 | tls_import_cert(const uschar * buf, void ** cert) | |
61 | { | |
62 | void * reset_point = store_get(0); | |
63 | const uschar * cp = string_unprinting(US buf); | |
64 | BIO * bp; | |
152e7604 | 65 | X509 * x = *(X509 **)cert; |
c03fae8a | 66 | int fail = 0; |
9d1c15ef | 67 | |
152e7604 JH |
68 | if (x) X509_free(x); |
69 | ||
9d1c15ef | 70 | bp = BIO_new_mem_buf(US cp, -1); |
c03fae8a JH |
71 | if (!(x = PEM_read_bio_X509(bp, NULL, 0, NULL))) |
72 | { | |
73 | log_write(0, LOG_MAIN, "TLS error in certificate import: %s", | |
74 | ERR_error_string(ERR_get_error(), NULL)); | |
9d1c15ef | 75 | fail = 1; |
c03fae8a | 76 | } |
9d1c15ef JH |
77 | else |
78 | *cert = (void *)x; | |
79 | BIO_free(bp); | |
80 | store_reset(reset_point); | |
81 | return fail; | |
82 | } | |
83 | ||
84 | void | |
790fbb71 | 85 | tls_free_cert(void ** cert) |
9d1c15ef | 86 | { |
790fbb71 JH |
87 | X509 * x = *(X509 **)cert; |
88 | if (x) | |
89 | { | |
90 | X509_free(x); | |
91 | *cert = NULL; | |
92 | } | |
9d1c15ef JH |
93 | } |
94 | ||
c03fae8a | 95 | |
9d1c15ef JH |
96 | /***************************************************** |
97 | * Certificate field extraction routines | |
98 | *****************************************************/ | |
c03fae8a JH |
99 | |
100 | /* First, some internal service functions */ | |
101 | ||
102 | static uschar * | |
103 | badalloc(void) | |
104 | { | |
105 | expand_string_message = US"allocation failure"; | |
106 | return NULL; | |
107 | } | |
108 | ||
9d1c15ef JH |
109 | static uschar * |
110 | bio_string_copy(BIO * bp, int len) | |
111 | { | |
e3dd1d67 | 112 | uschar * cp = US""; |
9d1c15ef JH |
113 | len = len > 0 ? (int) BIO_get_mem_data(bp, &cp) : 0; |
114 | cp = string_copyn(cp, len); | |
115 | BIO_free(bp); | |
116 | return cp; | |
117 | } | |
118 | ||
119 | static uschar * | |
e9477a08 | 120 | asn1_time_copy(const ASN1_TIME * asntime, uschar * mod) |
9d1c15ef | 121 | { |
e9477a08 | 122 | uschar * s = NULL; |
9d1c15ef | 123 | BIO * bp = BIO_new(BIO_s_mem()); |
c03fae8a JH |
124 | int len; |
125 | ||
e9477a08 JH |
126 | if (!bp) |
127 | return badalloc(); | |
128 | len = ASN1_TIME_print(bp, asntime); | |
d4ff61d1 | 129 | len = len > 0 ? (int) BIO_get_mem_data(bp, CSS &s) : 0; |
c03fae8a | 130 | |
e9477a08 JH |
131 | if (mod && Ustrcmp(mod, "raw") == 0) /* native ASN */ |
132 | s = string_copyn(s, len); | |
133 | else | |
134 | { | |
135 | struct tm tm; | |
136 | struct tm * tm_p = &tm; | |
755762fd | 137 | BOOL mod_tz = TRUE; |
45500060 | 138 | uschar * tz = to_tz(US"GMT0"); /* need to call strptime with baseline TZ */ |
e9477a08 JH |
139 | |
140 | /* Parse OpenSSL ASN1_TIME_print output. A shame there seems to | |
141 | be no other interface for the times. | |
142 | */ | |
143 | ||
144 | /*XXX %Z might be glibc-specific? Solaris has it, at least*/ | |
145 | /*XXX should we switch to POSIX locale for this? */ | |
146 | tm.tm_isdst = 0; | |
d4ff61d1 | 147 | if (!len || !strptime(CCS s, "%b %e %T %Y %Z", &tm)) |
e9477a08 JH |
148 | expand_string_message = US"failed time conversion"; |
149 | ||
150 | else | |
151 | { | |
152 | time_t t = mktime(&tm); /* make the tm self-consistent */ | |
153 | ||
154 | if (mod && Ustrcmp(mod, "int") == 0) /* seconds since epoch */ | |
bb07bcd3 | 155 | s = string_sprintf(TIME_T_FMT, t); |
e9477a08 JH |
156 | |
157 | else | |
158 | { | |
8768d548 | 159 | if (!f.timestamps_utc) /* decoded string in local TZ */ |
e9477a08 JH |
160 | { /* shift to local TZ */ |
161 | restore_tz(tz); | |
162 | mod_tz = FALSE; | |
163 | tm_p = localtime(&t); | |
164 | } | |
165 | /* "utc" is default, and rfc5280 says cert times should be Zulu */ | |
166 | ||
167 | /* convert to string in our format */ | |
168 | len = 32; | |
169 | s = store_get(len); | |
170 | strftime(CS s, (size_t)len, "%b %e %T %Y %z", tm_p); | |
171 | } | |
172 | } | |
173 | ||
755762fd | 174 | if (mod_tz) |
e9477a08 JH |
175 | restore_tz(tz); |
176 | } | |
177 | BIO_free(bp); | |
178 | return s; | |
9d1c15ef JH |
179 | } |
180 | ||
181 | static uschar * | |
182 | x509_name_copy(X509_NAME * name) | |
183 | { | |
184 | BIO * bp = BIO_new(BIO_s_mem()); | |
c03fae8a JH |
185 | int len_good; |
186 | ||
187 | if (!bp) return badalloc(); | |
188 | ||
189 | len_good = | |
9d1c15ef JH |
190 | X509_NAME_print_ex(bp, name, 0, XN_FLAG_RFC2253) >= 0 |
191 | ? 1 : 0; | |
192 | return bio_string_copy(bp, len_good); | |
193 | } | |
194 | ||
195 | /**/ | |
c03fae8a JH |
196 | /* Now the extractors, called from expand.c |
197 | Arguments: | |
198 | cert The certificate | |
199 | mod Optional modifiers for the operator | |
200 | ||
201 | Return: | |
202 | Allocated string with extracted value | |
203 | */ | |
9d1c15ef JH |
204 | |
205 | uschar * | |
9e4dddbd | 206 | tls_cert_issuer(void * cert, uschar * mod) |
9d1c15ef | 207 | { |
812a6045 JH |
208 | uschar * cp = x509_name_copy(X509_get_issuer_name((X509 *)cert)); |
209 | return mod ? tls_field_from_dn(cp, mod) : cp; | |
9d1c15ef JH |
210 | } |
211 | ||
212 | uschar * | |
9e4dddbd | 213 | tls_cert_not_before(void * cert, uschar * mod) |
9d1c15ef | 214 | { |
25ba2544 | 215 | return asn1_time_copy(X509_get_notBefore((X509 *)cert), mod); |
9d1c15ef JH |
216 | } |
217 | ||
218 | uschar * | |
9e4dddbd | 219 | tls_cert_not_after(void * cert, uschar * mod) |
9d1c15ef | 220 | { |
25ba2544 | 221 | return asn1_time_copy(X509_get_notAfter((X509 *)cert), mod); |
9d1c15ef JH |
222 | } |
223 | ||
224 | uschar * | |
9e4dddbd | 225 | tls_cert_serial_number(void * cert, uschar * mod) |
9d1c15ef JH |
226 | { |
227 | uschar txt[256]; | |
228 | BIO * bp = BIO_new(BIO_s_mem()); | |
c03fae8a | 229 | int len; |
9d1c15ef | 230 | |
c03fae8a JH |
231 | if (!bp) return badalloc(); |
232 | ||
233 | len = i2a_ASN1_INTEGER(bp, X509_get_serialNumber((X509 *)cert)); | |
9d1c15ef JH |
234 | if (len < sizeof(txt)) |
235 | BIO_read(bp, txt, len); | |
236 | else | |
237 | len = 0; | |
238 | BIO_free(bp); | |
239 | return string_copynlc(txt, len); /* lowercase */ | |
240 | } | |
241 | ||
242 | uschar * | |
9e4dddbd | 243 | tls_cert_signature(void * cert, uschar * mod) |
9d1c15ef | 244 | { |
9d1c15ef | 245 | uschar * cp = NULL; |
c03fae8a JH |
246 | BIO * bp = BIO_new(BIO_s_mem()); |
247 | ||
248 | if (!bp) return badalloc(); | |
9d1c15ef JH |
249 | |
250 | if (X509_print_ex(bp, (X509 *)cert, 0, | |
94431adb HSHR |
251 | X509_FLAG_NO_HEADER | X509_FLAG_NO_VERSION | X509_FLAG_NO_SERIAL | |
252 | X509_FLAG_NO_SIGNAME | X509_FLAG_NO_ISSUER | X509_FLAG_NO_VALIDITY | | |
253 | X509_FLAG_NO_SUBJECT | X509_FLAG_NO_PUBKEY | X509_FLAG_NO_EXTENSIONS | | |
9d1c15ef JH |
254 | /* X509_FLAG_NO_SIGDUMP is the missing one */ |
255 | X509_FLAG_NO_AUX) == 1) | |
256 | { | |
257 | long len = BIO_get_mem_data(bp, &cp); | |
315e209a JH |
258 | |
259 | /* Strip leading "Signature Algorithm" line */ | |
260 | while (*cp && *cp != '\n') { cp++; len--; } | |
261 | ||
262 | cp = string_copyn(cp+1, len-1); | |
9d1c15ef JH |
263 | } |
264 | BIO_free(bp); | |
265 | return cp; | |
266 | } | |
267 | ||
268 | uschar * | |
9e4dddbd | 269 | tls_cert_signature_algorithm(void * cert, uschar * mod) |
9d1c15ef | 270 | { |
315e209a JH |
271 | uschar * cp = NULL; |
272 | BIO * bp = BIO_new(BIO_s_mem()); | |
273 | ||
274 | if (!bp) return badalloc(); | |
275 | ||
276 | if (X509_print_ex(bp, (X509 *)cert, 0, | |
94431adb | 277 | X509_FLAG_NO_HEADER | X509_FLAG_NO_VERSION | X509_FLAG_NO_SERIAL | |
315e209a | 278 | /* X509_FLAG_NO_SIGNAME is the missing one */ |
94431adb HSHR |
279 | X509_FLAG_NO_ISSUER | X509_FLAG_NO_VALIDITY | |
280 | X509_FLAG_NO_SUBJECT | X509_FLAG_NO_PUBKEY | X509_FLAG_NO_EXTENSIONS | | |
315e209a JH |
281 | X509_FLAG_NO_SIGDUMP | X509_FLAG_NO_AUX) == 1) |
282 | { | |
283 | long len = BIO_get_mem_data(bp, &cp); | |
284 | ||
285 | /* Strip leading " Signature Algorithm: " and trailing newline */ | |
286 | while (*cp && *cp != ':') { cp++; len--; } | |
287 | do { cp++; len--; } while (*cp && *cp == ' '); | |
288 | if (cp[len-1] == '\n') len--; | |
289 | ||
290 | cp = string_copyn(cp, len); | |
291 | } | |
292 | BIO_free(bp); | |
293 | return cp; | |
9d1c15ef JH |
294 | } |
295 | ||
296 | uschar * | |
9e4dddbd | 297 | tls_cert_subject(void * cert, uschar * mod) |
9d1c15ef | 298 | { |
812a6045 JH |
299 | uschar * cp = x509_name_copy(X509_get_subject_name((X509 *)cert)); |
300 | return mod ? tls_field_from_dn(cp, mod) : cp; | |
9d1c15ef JH |
301 | } |
302 | ||
303 | uschar * | |
9e4dddbd | 304 | tls_cert_version(void * cert, uschar * mod) |
9d1c15ef | 305 | { |
bb07bcd3 | 306 | return string_sprintf("%ld", X509_get_version((X509 *)cert)); |
9d1c15ef JH |
307 | } |
308 | ||
309 | uschar * | |
310 | tls_cert_ext_by_oid(void * cert, uschar * oid, int idx) | |
311 | { | |
e3dd1d67 | 312 | int nid = OBJ_create(CS oid, "", ""); |
9d1c15ef JH |
313 | int nidx = X509_get_ext_by_NID((X509 *)cert, nid, idx); |
314 | X509_EXTENSION * ex = X509_get_ext((X509 *)cert, nidx); | |
315 | ASN1_OCTET_STRING * adata = X509_EXTENSION_get_data(ex); | |
316 | BIO * bp = BIO_new(BIO_s_mem()); | |
317 | long len; | |
318 | uschar * cp1; | |
319 | uschar * cp2; | |
320 | uschar * cp3; | |
321 | ||
c03fae8a JH |
322 | if (!bp) return badalloc(); |
323 | ||
c8dfb21d JH |
324 | #ifdef EXIM_HAVE_ASN1_MACROS |
325 | ASN1_STRING_print(bp, adata); | |
326 | #else | |
9d1c15ef | 327 | M_ASN1_OCTET_STRING_print(bp, adata); |
c8dfb21d | 328 | #endif |
9d1c15ef | 329 | |
c8dfb21d | 330 | /* binary data, DER encoded */ |
9d1c15ef JH |
331 | /* just dump for now */ |
332 | len = BIO_get_mem_data(bp, &cp1); | |
333 | cp3 = cp2 = store_get(len*3+1); | |
334 | ||
335 | while(len) | |
336 | { | |
5976eb99 | 337 | cp2 += sprintf(CS cp2, "%.2x ", *cp1++); |
9d1c15ef JH |
338 | len--; |
339 | } | |
340 | cp2[-1] = '\0'; | |
341 | ||
342 | return cp3; | |
343 | } | |
344 | ||
345 | uschar * | |
9e4dddbd | 346 | tls_cert_subject_altname(void * cert, uschar * mod) |
9d1c15ef | 347 | { |
acec9514 | 348 | gstring * list = NULL; |
9d1c15ef JH |
349 | STACK_OF(GENERAL_NAME) * san = (STACK_OF(GENERAL_NAME) *) |
350 | X509_get_ext_d2i((X509 *)cert, NID_subject_alt_name, NULL, NULL); | |
b3ef41c9 | 351 | uschar osep = '\n'; |
9e4dddbd JH |
352 | uschar * tag = US""; |
353 | uschar * ele; | |
354 | int match = -1; | |
e51c7be2 | 355 | int len; |
9d1c15ef JH |
356 | |
357 | if (!san) return NULL; | |
358 | ||
b3ef41c9 | 359 | while (mod && *mod) |
9e4dddbd | 360 | { |
b3ef41c9 JH |
361 | if (*mod == '>' && *++mod) osep = *mod++; |
362 | else if (Ustrncmp(mod,"dns",3)==0) { match = GEN_DNS; mod += 3; } | |
363 | else if (Ustrncmp(mod,"uri",3)==0) { match = GEN_URI; mod += 3; } | |
364 | else if (Ustrncmp(mod,"mail",4)==0) { match = GEN_EMAIL; mod += 4; } | |
365 | else mod++; | |
9e4dddbd | 366 | |
b3ef41c9 | 367 | if (*mod == ',') mod++; |
9e4dddbd JH |
368 | } |
369 | ||
9d1c15ef JH |
370 | while (sk_GENERAL_NAME_num(san) > 0) |
371 | { | |
372 | GENERAL_NAME * namePart = sk_GENERAL_NAME_pop(san); | |
9e4dddbd JH |
373 | if (match != -1 && match != namePart->type) |
374 | continue; | |
9d1c15ef JH |
375 | switch (namePart->type) |
376 | { | |
9e4dddbd JH |
377 | case GEN_DNS: |
378 | tag = US"DNS"; | |
3ae79556 | 379 | ele = US ASN1_STRING_get0_data(namePart->d.dNSName); |
e51c7be2 | 380 | len = ASN1_STRING_length(namePart->d.dNSName); |
9e4dddbd | 381 | break; |
9d1c15ef | 382 | case GEN_URI: |
9e4dddbd | 383 | tag = US"URI"; |
3ae79556 | 384 | ele = US ASN1_STRING_get0_data(namePart->d.uniformResourceIdentifier); |
e51c7be2 | 385 | len = ASN1_STRING_length(namePart->d.uniformResourceIdentifier); |
9e4dddbd | 386 | break; |
9d1c15ef | 387 | case GEN_EMAIL: |
9e4dddbd | 388 | tag = US"MAIL"; |
3ae79556 | 389 | ele = US ASN1_STRING_get0_data(namePart->d.rfc822Name); |
e51c7be2 | 390 | len = ASN1_STRING_length(namePart->d.rfc822Name); |
9e4dddbd | 391 | break; |
9d1c15ef | 392 | default: |
9e4dddbd | 393 | continue; /* ignore unrecognised types */ |
9d1c15ef | 394 | } |
e51c7be2 JH |
395 | if (ele[len]) /* not nul-terminated */ |
396 | ele = string_copyn(ele, len); | |
397 | ||
9acf6b94 | 398 | if (Ustrlen(ele) == len) /* ignore any with embedded nul */ |
acec9514 | 399 | list = string_append_listele(list, osep, |
9e4dddbd | 400 | match == -1 ? string_sprintf("%s=%s", tag, ele) : ele); |
9d1c15ef JH |
401 | } |
402 | ||
9e4dddbd | 403 | sk_GENERAL_NAME_free(san); |
acec9514 | 404 | return string_from_gstring(list); |
9d1c15ef JH |
405 | } |
406 | ||
407 | uschar * | |
9e4dddbd | 408 | tls_cert_ocsp_uri(void * cert, uschar * mod) |
9d1c15ef JH |
409 | { |
410 | STACK_OF(ACCESS_DESCRIPTION) * ads = (STACK_OF(ACCESS_DESCRIPTION) *) | |
411 | X509_get_ext_d2i((X509 *)cert, NID_info_access, NULL, NULL); | |
412 | int adsnum = sk_ACCESS_DESCRIPTION_num(ads); | |
9e4dddbd | 413 | uschar sep = '\n'; |
acec9514 | 414 | gstring * list = NULL; |
9e4dddbd JH |
415 | |
416 | if (mod) | |
417 | if (*mod == '>' && *++mod) sep = *mod++; | |
9d1c15ef | 418 | |
d7978c0f | 419 | for (int i = 0; i < adsnum; i++) |
9d1c15ef JH |
420 | { |
421 | ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(ads, i); | |
422 | ||
423 | if (ad && OBJ_obj2nid(ad->method) == NID_ad_OCSP) | |
acec9514 | 424 | list = string_append_listele_n(list, sep, |
3ae79556 | 425 | US ASN1_STRING_get0_data(ad->location->d.ia5), |
4226691b | 426 | ASN1_STRING_length(ad->location->d.ia5)); |
9d1c15ef | 427 | } |
00ba27c5 | 428 | sk_ACCESS_DESCRIPTION_free(ads); |
acec9514 | 429 | return string_from_gstring(list); |
9d1c15ef JH |
430 | } |
431 | ||
432 | uschar * | |
9e4dddbd | 433 | tls_cert_crl_uri(void * cert, uschar * mod) |
9d1c15ef JH |
434 | { |
435 | STACK_OF(DIST_POINT) * dps = (STACK_OF(DIST_POINT) *) | |
436 | X509_get_ext_d2i((X509 *)cert, NID_crl_distribution_points, | |
437 | NULL, NULL); | |
438 | DIST_POINT * dp; | |
9e4dddbd | 439 | uschar sep = '\n'; |
acec9514 | 440 | gstring * list = NULL; |
9e4dddbd JH |
441 | |
442 | if (mod) | |
443 | if (*mod == '>' && *++mod) sep = *mod++; | |
9d1c15ef | 444 | |
d7978c0f | 445 | if (dps) for (int i = 0, dpsnum = sk_DIST_POINT_num(dps); i < dpsnum; i++) |
9d1c15ef JH |
446 | if ((dp = sk_DIST_POINT_value(dps, i))) |
447 | { | |
448 | STACK_OF(GENERAL_NAME) * names = dp->distpoint->name.fullname; | |
449 | GENERAL_NAME * np; | |
9d1c15ef | 450 | |
d7978c0f | 451 | for (int j = 0, nnum = sk_GENERAL_NAME_num(names); j < nnum; j++) |
9d1c15ef JH |
452 | if ( (np = sk_GENERAL_NAME_value(names, j)) |
453 | && np->type == GEN_URI | |
454 | ) | |
acec9514 | 455 | list = string_append_listele_n(list, sep, |
3ae79556 | 456 | US ASN1_STRING_get0_data(np->d.uniformResourceIdentifier), |
4226691b | 457 | ASN1_STRING_length(np->d.uniformResourceIdentifier)); |
9d1c15ef | 458 | } |
00ba27c5 | 459 | sk_DIST_POINT_free(dps); |
acec9514 | 460 | return string_from_gstring(list); |
9d1c15ef JH |
461 | } |
462 | ||
6a8a60e0 JH |
463 | |
464 | ||
465 | /***************************************************** | |
466 | * Certificate operator routines | |
467 | *****************************************************/ | |
59b87190 JH |
468 | uschar * |
469 | tls_cert_der_b64(void * cert) | |
470 | { | |
471 | BIO * bp = BIO_new(BIO_s_mem()); | |
472 | uschar * cp = NULL; | |
473 | ||
474 | if (!i2d_X509_bio(bp, (X509 *)cert)) | |
475 | log_write(0, LOG_MAIN, "TLS error in certificate export: %s", | |
476 | ERR_error_string(ERR_get_error(), NULL)); | |
477 | else | |
478 | { | |
479 | long len = BIO_get_mem_data(bp, &cp); | |
1f20760b | 480 | cp = b64encode(CUS cp, (int)len); |
59b87190 JH |
481 | } |
482 | ||
483 | BIO_free(bp); | |
484 | return cp; | |
485 | } | |
486 | ||
487 | ||
6a8a60e0 JH |
488 | static uschar * |
489 | fingerprint(X509 * cert, const EVP_MD * fdig) | |
490 | { | |
6a8a60e0 JH |
491 | unsigned int n; |
492 | uschar md[EVP_MAX_MD_SIZE]; | |
493 | uschar * cp; | |
494 | ||
495 | if (!X509_digest(cert,fdig,md,&n)) | |
496 | { | |
497 | expand_string_message = US"tls_cert_fprt: out of mem\n"; | |
498 | return NULL; | |
499 | } | |
500 | cp = store_get(n*2+1); | |
d7978c0f | 501 | for (int j = 0; j < (int)n; j++) sprintf(CS cp+2*j, "%02X", md[j]); |
6a8a60e0 JH |
502 | return(cp); |
503 | } | |
504 | ||
94431adb | 505 | uschar * |
6a8a60e0 JH |
506 | tls_cert_fprt_md5(void * cert) |
507 | { | |
508 | return fingerprint((X509 *)cert, EVP_md5()); | |
509 | } | |
510 | ||
94431adb | 511 | uschar * |
6a8a60e0 JH |
512 | tls_cert_fprt_sha1(void * cert) |
513 | { | |
514 | return fingerprint((X509 *)cert, EVP_sha1()); | |
515 | } | |
516 | ||
94431adb | 517 | uschar * |
9ef9101c JH |
518 | tls_cert_fprt_sha256(void * cert) |
519 | { | |
520 | return fingerprint((X509 *)cert, EVP_sha256()); | |
521 | } | |
522 | ||
6a8a60e0 | 523 | |
9d1c15ef JH |
524 | /* vi: aw ai sw=2 |
525 | */ | |
526 | /* End of tlscert-openssl.c */ |