diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/x509v3/v3_akey.c | 122 |
1 files changed, 59 insertions, 63 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_akey.c b/src/lib/libcrypto/x509v3/v3_akey.c index 04e1fb9544..6d5c576e23 100644 --- a/src/lib/libcrypto/x509v3/v3_akey.c +++ b/src/lib/libcrypto/x509v3/v3_akey.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * are met: | 10 | * are met: |
11 | * | 11 | * |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * | 14 | * |
15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
@@ -64,36 +64,37 @@ | |||
64 | #include <openssl/x509v3.h> | 64 | #include <openssl/x509v3.h> |
65 | 65 | ||
66 | static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, | 66 | static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, |
67 | AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist); | 67 | AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist); |
68 | static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, | 68 | static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, |
69 | X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values); | 69 | X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values); |
70 | 70 | ||
71 | const X509V3_EXT_METHOD v3_akey_id = | 71 | const X509V3_EXT_METHOD v3_akey_id = { |
72 | { | ||
73 | NID_authority_key_identifier, | 72 | NID_authority_key_identifier, |
74 | X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_KEYID), | 73 | X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_KEYID), |
75 | 0,0,0,0, | 74 | 0, 0,0, 0, |
76 | 0,0, | 75 | 0, 0, |
77 | (X509V3_EXT_I2V)i2v_AUTHORITY_KEYID, | 76 | (X509V3_EXT_I2V)i2v_AUTHORITY_KEYID, |
78 | (X509V3_EXT_V2I)v2i_AUTHORITY_KEYID, | 77 | (X509V3_EXT_V2I)v2i_AUTHORITY_KEYID, |
79 | 0,0, | 78 | 0, 0, |
80 | NULL | 79 | NULL |
81 | }; | 80 | }; |
82 | 81 | ||
83 | static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, | 82 | static |
84 | AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist) | 83 | STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, |
84 | AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist) | ||
85 | { | 85 | { |
86 | char *tmp; | 86 | char *tmp; |
87 | if(akeyid->keyid) { | 87 | |
88 | if (akeyid->keyid) { | ||
88 | tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length); | 89 | tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length); |
89 | X509V3_add_value("keyid", tmp, &extlist); | 90 | X509V3_add_value("keyid", tmp, &extlist); |
90 | free(tmp); | 91 | free(tmp); |
91 | } | 92 | } |
92 | if(akeyid->issuer) | 93 | if (akeyid->issuer) |
93 | extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist); | 94 | extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist); |
94 | if(akeyid->serial) { | 95 | if (akeyid->serial) { |
95 | tmp = hex_to_string(akeyid->serial->data, | 96 | tmp = hex_to_string(akeyid->serial->data, |
96 | akeyid->serial->length); | 97 | akeyid->serial->length); |
97 | X509V3_add_value("serial", tmp, &extlist); | 98 | X509V3_add_value("serial", tmp, &extlist); |
98 | free(tmp); | 99 | free(tmp); |
99 | } | 100 | } |
@@ -108,10 +109,11 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, | |||
108 | * this is always included. | 109 | * this is always included. |
109 | */ | 110 | */ |
110 | 111 | ||
111 | static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, | 112 | static AUTHORITY_KEYID * |
112 | X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values) | 113 | v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, |
113 | { | 114 | STACK_OF(CONF_VALUE) *values) |
114 | char keyid=0, issuer=0; | 115 | { |
116 | char keyid = 0, issuer = 0; | ||
115 | int i; | 117 | int i; |
116 | CONF_VALUE *cnf; | 118 | CONF_VALUE *cnf; |
117 | ASN1_OCTET_STRING *ikeyid = NULL; | 119 | ASN1_OCTET_STRING *ikeyid = NULL; |
@@ -123,76 +125,70 @@ static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, | |||
123 | X509 *cert; | 125 | X509 *cert; |
124 | AUTHORITY_KEYID *akeyid; | 126 | AUTHORITY_KEYID *akeyid; |
125 | 127 | ||
126 | for(i = 0; i < sk_CONF_VALUE_num(values); i++) | 128 | for (i = 0; i < sk_CONF_VALUE_num(values); i++) { |
127 | { | ||
128 | cnf = sk_CONF_VALUE_value(values, i); | 129 | cnf = sk_CONF_VALUE_value(values, i); |
129 | if(!strcmp(cnf->name, "keyid")) | 130 | if (!strcmp(cnf->name, "keyid")) { |
130 | { | ||
131 | keyid = 1; | 131 | keyid = 1; |
132 | if(cnf->value && !strcmp(cnf->value, "always")) | 132 | if (cnf->value && !strcmp(cnf->value, "always")) |
133 | keyid = 2; | 133 | keyid = 2; |
134 | } | 134 | } |
135 | else if(!strcmp(cnf->name, "issuer")) | 135 | else if (!strcmp(cnf->name, "issuer")) { |
136 | { | ||
137 | issuer = 1; | 136 | issuer = 1; |
138 | if(cnf->value && !strcmp(cnf->value, "always")) | 137 | if (cnf->value && !strcmp(cnf->value, "always")) |
139 | issuer = 2; | 138 | issuer = 2; |
140 | } | 139 | } else { |
141 | else | 140 | X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, |
142 | { | 141 | X509V3_R_UNKNOWN_OPTION); |
143 | X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNKNOWN_OPTION); | ||
144 | ERR_add_error_data(2, "name=", cnf->name); | 142 | ERR_add_error_data(2, "name=", cnf->name); |
145 | return NULL; | 143 | return NULL; |
146 | } | ||
147 | } | 144 | } |
145 | } | ||
148 | 146 | ||
149 | if(!ctx || !ctx->issuer_cert) | 147 | if (!ctx || !ctx->issuer_cert) { |
150 | { | 148 | if (ctx && (ctx->flags == CTX_TEST)) |
151 | if(ctx && (ctx->flags==CTX_TEST)) | ||
152 | return AUTHORITY_KEYID_new(); | 149 | return AUTHORITY_KEYID_new(); |
153 | X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_NO_ISSUER_CERTIFICATE); | 150 | X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, |
151 | X509V3_R_NO_ISSUER_CERTIFICATE); | ||
154 | return NULL; | 152 | return NULL; |
155 | } | 153 | } |
156 | 154 | ||
157 | cert = ctx->issuer_cert; | 155 | cert = ctx->issuer_cert; |
158 | 156 | ||
159 | if(keyid) | 157 | if (keyid) { |
160 | { | ||
161 | i = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1); | 158 | i = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1); |
162 | if((i >= 0) && (ext = X509_get_ext(cert, i))) | 159 | if ((i >= 0) && (ext = X509_get_ext(cert, i))) |
163 | ikeyid = X509V3_EXT_d2i(ext); | 160 | ikeyid = X509V3_EXT_d2i(ext); |
164 | if(keyid==2 && !ikeyid) | 161 | if (keyid == 2 && !ikeyid) { |
165 | { | 162 | X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, |
166 | X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_KEYID); | 163 | X509V3_R_UNABLE_TO_GET_ISSUER_KEYID); |
167 | return NULL; | 164 | return NULL; |
168 | } | ||
169 | } | 165 | } |
166 | } | ||
170 | 167 | ||
171 | if((issuer && !ikeyid) || (issuer == 2)) | 168 | if ((issuer && !ikeyid) || (issuer == 2)) { |
172 | { | ||
173 | isname = X509_NAME_dup(X509_get_issuer_name(cert)); | 169 | isname = X509_NAME_dup(X509_get_issuer_name(cert)); |
174 | serial = M_ASN1_INTEGER_dup(X509_get_serialNumber(cert)); | 170 | serial = M_ASN1_INTEGER_dup(X509_get_serialNumber(cert)); |
175 | if(!isname || !serial) | 171 | if (!isname || !serial) { |
176 | { | 172 | X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, |
177 | X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS); | 173 | X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS); |
178 | goto err; | 174 | goto err; |
179 | } | ||
180 | } | 175 | } |
176 | } | ||
181 | 177 | ||
182 | if(!(akeyid = AUTHORITY_KEYID_new())) goto err; | 178 | if (!(akeyid = AUTHORITY_KEYID_new())) |
179 | goto err; | ||
183 | 180 | ||
184 | if(isname) | 181 | if (isname) { |
185 | { | 182 | if (!(gens = sk_GENERAL_NAME_new_null()) || |
186 | if(!(gens = sk_GENERAL_NAME_new_null()) | 183 | !(gen = GENERAL_NAME_new()) || |
187 | || !(gen = GENERAL_NAME_new()) | 184 | !sk_GENERAL_NAME_push(gens, gen)) { |
188 | || !sk_GENERAL_NAME_push(gens, gen)) | 185 | X509V3err(X509V3_F_V2I_AUTHORITY_KEYID, |
189 | { | 186 | ERR_R_MALLOC_FAILURE); |
190 | X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,ERR_R_MALLOC_FAILURE); | ||
191 | goto err; | 187 | goto err; |
192 | } | 188 | } |
193 | gen->type = GEN_DIRNAME; | 189 | gen->type = GEN_DIRNAME; |
194 | gen->d.dirn = isname; | 190 | gen->d.dirn = isname; |
195 | } | 191 | } |
196 | 192 | ||
197 | akeyid->issuer = gens; | 193 | akeyid->issuer = gens; |
198 | akeyid->serial = serial; | 194 | akeyid->serial = serial; |
@@ -200,9 +196,9 @@ static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, | |||
200 | 196 | ||
201 | return akeyid; | 197 | return akeyid; |
202 | 198 | ||
203 | err: | 199 | err: |
204 | X509_NAME_free(isname); | 200 | X509_NAME_free(isname); |
205 | M_ASN1_INTEGER_free(serial); | 201 | M_ASN1_INTEGER_free(serial); |
206 | M_ASN1_OCTET_STRING_free(ikeyid); | 202 | M_ASN1_OCTET_STRING_free(ikeyid); |
207 | return NULL; | 203 | return NULL; |
208 | } | 204 | } |