-
Notifications
You must be signed in to change notification settings - Fork 4
/
ocsp-stapling.c
62 lines (51 loc) · 1.33 KB
/
ocsp-stapling.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/ocsp.h>
int get_ocsp(char *filename, unsigned char **ocsp) {
BIO *bio;
OCSP_RESPONSE *response;
int len = -1;
unsigned char *p, *buf;
if (filename == NULL) {
*ocsp = NULL;
return 0;
}
if ((bio = BIO_new_file(filename, "r")) == NULL) {
perror("get_ocsp: BIO_new_file failed");
ERR_print_errors_fp(stderr);
return -1;
}
if ((response = d2i_OCSP_RESPONSE_bio(bio, NULL)) == NULL) {
perror("get_ocsp: d2i_OCSP_RESPONSE_bio failed");
ERR_print_errors_fp(stderr);
BIO_free(bio);
return -2;
}
if ((len = i2d_OCSP_RESPONSE(response, NULL)) <= 0) {
perror("get_ocsp: i2d_OCSP_RESPONSE #1 failed");
ERR_print_errors_fp(stderr);
OCSP_RESPONSE_free(response);
BIO_free(bio);
return -3;
}
if ((buf = malloc((size_t) len)) == NULL) {
perror("get_ocsp: malloc failed");
OCSP_RESPONSE_free(response);
BIO_free(bio);
return -4;
}
p = buf;
if ((len = i2d_OCSP_RESPONSE(response, &p)) <= 0) {
perror("get_ocsp: i2d_OCSP_RESPONSE #2 failed");
ERR_print_errors_fp(stderr);
free(buf);
OCSP_RESPONSE_free(response);
BIO_free(bio);
return -5;
}
OCSP_RESPONSE_free(response);
BIO_free(bio);
fprintf(stdout, "get_ocsp: %i octets\n", len);
*ocsp = buf;
return len;
}