1 /* $OpenBSD: crl.c,v 1.10 2021/01/29 10:13:16 claudio Exp $ */ 2 /* 3 * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <sys/socket.h> 19 20 #include <arpa/inet.h> 21 #include <assert.h> 22 #include <err.h> 23 #include <inttypes.h> 24 #include <stdarg.h> 25 #include <stdlib.h> 26 #include <string.h> 27 #include <unistd.h> 28 29 #include "extern.h" 30 31 X509_CRL * 32 crl_parse(const char *fn) 33 { 34 int rc = 0; 35 X509_CRL *x = NULL; 36 BIO *bio = NULL; 37 FILE *f; 38 39 if ((f = fopen(fn, "rb")) == NULL) { 40 warn("%s", fn); 41 return NULL; 42 } 43 44 if ((bio = BIO_new_fp(f, BIO_CLOSE)) == NULL) { 45 if (verbose > 0) 46 cryptowarnx("%s: BIO_new_file", fn); 47 return NULL; 48 } 49 50 if ((x = d2i_X509_CRL_bio(bio, NULL)) == NULL) { 51 cryptowarnx("%s: d2i_X509_CRL_bio", fn); 52 goto out; 53 } 54 55 rc = 1; 56 out: 57 BIO_free_all(bio); 58 if (rc == 0) { 59 X509_CRL_free(x); 60 x = NULL; 61 } 62 return x; 63 } 64 65 static inline int 66 crlcmp(struct crl *a, struct crl *b) 67 { 68 return strcmp(a->aki, b->aki); 69 } 70 71 RB_GENERATE(crl_tree, crl, entry, crlcmp); 72 73 void 74 free_crl(struct crl *crl) 75 { 76 free(crl->aki); 77 X509_CRL_free(crl->x509_crl); 78 free(crl); 79 } 80