Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/x509/v3_ocsp.c

raw
1 // Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 #include <string.h>
5
6 #include <openssl/x509.h>
7
8 #include <openssl/asn1.h>
9 #include <openssl/bio.h>
10 #include <openssl/nid.h>
11 #include "../internal.h"
12
13 // OCSP extensions and a couple of CRL entry extensions
14
15 static int i2r_ocsp_acutoff(const X509V3_EXT_METHOD *method, void *cutoff,
16 BIO *bp, int indent);
17
18 static void *ocsp_nonce_new(void);
19 static int i2d_ocsp_nonce(void *a, unsigned char **pp);
20 static void *d2i_ocsp_nonce(void *a, const unsigned char **pp, long length);
21 static void ocsp_nonce_free(void *a);
22 static int i2r_ocsp_nonce(const X509V3_EXT_METHOD *method, void *nonce,
23 BIO *out, int indent);
24
25 static int i2r_ocsp_nocheck(const X509V3_EXT_METHOD *method, void *nocheck,
26 BIO *out, int indent);
27 static void *s2i_ocsp_nocheck(const X509V3_EXT_METHOD *method,
28 const X509V3_CTX *ctx, const char *str);
29
30 const X509V3_EXT_METHOD v3_crl_invdate = {
31 NID_invalidity_date,
32 0,
33 ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),
34 0,
35 0,
36 0,
37 0,
38 0,
39 0,
40 0,
41 0,
42 i2r_ocsp_acutoff,
43 0,
44 NULL,
45 };
46
47 const X509V3_EXT_METHOD v3_ocsp_nonce = {
48 NID_id_pkix_OCSP_Nonce,
49 0,
50 NULL,
51 ocsp_nonce_new,
52 ocsp_nonce_free,
53 d2i_ocsp_nonce,
54 i2d_ocsp_nonce,
55 0,
56 0,
57 0,
58 0,
59 i2r_ocsp_nonce,
60 0,
61 NULL
62 };
63
64 const X509V3_EXT_METHOD v3_ocsp_nocheck = {
65 NID_id_pkix_OCSP_noCheck,
66 0,
67 ASN1_ITEM_ref(ASN1_NULL),
68 0,
69 0,
70 0,
71 0,
72 0,
73 s2i_ocsp_nocheck,
74 0,
75 0,
76 i2r_ocsp_nocheck,
77 0,
78 NULL,
79 };
80
81 static int i2r_ocsp_acutoff(const X509V3_EXT_METHOD *method, void *cutoff,
82 BIO *bp, int ind) {
83 if (BIO_printf(bp, "%*s", ind, "") <= 0) {
84 return 0;
85 }
86 if (!ASN1_GENERALIZEDTIME_print(bp, cutoff)) {
87 return 0;
88 }
89 return 1;
90 }
91
92 // OCSP nonce. This is needs special treatment because it doesn't have an
93 // ASN1 encoding at all: it just contains arbitrary data.
94
95 static void *ocsp_nonce_new(void) { return ASN1_OCTET_STRING_new(); }
96
97 static int i2d_ocsp_nonce(void *a, unsigned char **pp) {
98 ASN1_OCTET_STRING *os = a;
99 if (pp != NULL) {
100 OPENSSL_memcpy(*pp, os->data, os->length);
101 *pp += os->length;
102 }
103 return os->length;
104 }
105
106 static void *d2i_ocsp_nonce(void *a, const unsigned char **pp, long length) {
107 ASN1_OCTET_STRING *os, **pos;
108 pos = a;
109 if (pos == NULL || *pos == NULL) {
110 os = ASN1_OCTET_STRING_new();
111 if (os == NULL) {
112 goto err;
113 }
114 } else {
115 os = *pos;
116 }
117 if (!ASN1_OCTET_STRING_set(os, *pp, (int)length)) {
118 goto err;
119 }
120
121 *pp += length;
122
123 if (pos != NULL) {
124 *pos = os;
125 }
126 return os;
127
128 err:
129 if ((pos == NULL) || (*pos != os)) {
130 ASN1_OCTET_STRING_free(os);
131 }
132 OPENSSL_PUT_ERROR(OCSP, ERR_R_MALLOC_FAILURE);
133 return NULL;
134 }
135
136 static void ocsp_nonce_free(void *a) { ASN1_OCTET_STRING_free(a); }
137
138 static int i2r_ocsp_nonce(const X509V3_EXT_METHOD *method, void *nonce,
139 BIO *out, int indent) {
140 if (BIO_printf(out, "%*s", indent, "") <= 0) {
141 return 0;
142 }
143 if (i2a_ASN1_STRING(out, nonce, V_ASN1_OCTET_STRING) <= 0) {
144 return 0;
145 }
146 return 1;
147 }
148
149 // Nocheck is just a single NULL. Don't print anything and always set it
150
151 static int i2r_ocsp_nocheck(const X509V3_EXT_METHOD *method, void *nocheck,
152 BIO *out, int indent) {
153 return 1;
154 }
155
156 static void *s2i_ocsp_nocheck(const X509V3_EXT_METHOD *method,
157 const X509V3_CTX *ctx, const char *str) {
158 return ASN1_NULL_new();
159 }