diff options
author | jsing <> | 2014-05-26 12:37:32 +0000 |
---|---|---|
committer | jsing <> | 2014-05-26 12:37:32 +0000 |
commit | 0a3c64a44b2d2d7ba5da3fafde6657ae6f2a6435 (patch) | |
tree | ab5672653bce63a239165b17c0951468b96ecbc1 /src/lib/libcrypto/x509v3/v3_sxnet.c | |
parent | 043e50e025a8f1c5baa37e18d206b24c27356069 (diff) | |
download | openbsd-0a3c64a44b2d2d7ba5da3fafde6657ae6f2a6435.tar.gz openbsd-0a3c64a44b2d2d7ba5da3fafde6657ae6f2a6435.tar.bz2 openbsd-0a3c64a44b2d2d7ba5da3fafde6657ae6f2a6435.zip |
KNF.
Diffstat (limited to 'src/lib/libcrypto/x509v3/v3_sxnet.c')
-rw-r--r-- | src/lib/libcrypto/x509v3/v3_sxnet.c | 150 |
1 files changed, 88 insertions, 62 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c index a2b0322e44..81ba50ca03 100644 --- a/src/lib/libcrypto/x509v3/v3_sxnet.c +++ b/src/lib/libcrypto/x509v3/v3_sxnet.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 |
@@ -67,24 +67,25 @@ | |||
67 | 67 | ||
68 | #define SXNET_TEST | 68 | #define SXNET_TEST |
69 | 69 | ||
70 | static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, int indent); | 70 | static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, |
71 | int indent); | ||
71 | #ifdef SXNET_TEST | 72 | #ifdef SXNET_TEST |
72 | static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, | 73 | static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, |
73 | STACK_OF(CONF_VALUE) *nval); | 74 | STACK_OF(CONF_VALUE) *nval); |
74 | #endif | 75 | #endif |
75 | const X509V3_EXT_METHOD v3_sxnet = { | 76 | const X509V3_EXT_METHOD v3_sxnet = { |
76 | NID_sxnet, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(SXNET), | 77 | NID_sxnet, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(SXNET), |
77 | 0,0,0,0, | 78 | 0, 0, 0, 0, |
78 | 0,0, | 79 | 0, 0, |
79 | 0, | 80 | 0, |
80 | #ifdef SXNET_TEST | 81 | #ifdef SXNET_TEST |
81 | (X509V3_EXT_V2I)sxnet_v2i, | 82 | (X509V3_EXT_V2I)sxnet_v2i, |
82 | #else | 83 | #else |
83 | 0, | 84 | 0, |
84 | #endif | 85 | #endif |
85 | (X509V3_EXT_I2R)sxnet_i2r, | 86 | (X509V3_EXT_I2R)sxnet_i2r, |
86 | 0, | 87 | 0, |
87 | NULL | 88 | NULL |
88 | }; | 89 | }; |
89 | 90 | ||
90 | ASN1_SEQUENCE(SXNETID) = { | 91 | ASN1_SEQUENCE(SXNETID) = { |
@@ -101,16 +102,17 @@ ASN1_SEQUENCE(SXNET) = { | |||
101 | 102 | ||
102 | IMPLEMENT_ASN1_FUNCTIONS(SXNET) | 103 | IMPLEMENT_ASN1_FUNCTIONS(SXNET) |
103 | 104 | ||
104 | static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, | 105 | static int |
105 | int indent) | 106 | sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, int indent) |
106 | { | 107 | { |
107 | long v; | 108 | long v; |
108 | char *tmp; | 109 | char *tmp; |
109 | SXNETID *id; | 110 | SXNETID *id; |
110 | int i; | 111 | int i; |
112 | |||
111 | v = ASN1_INTEGER_get(sx->version); | 113 | v = ASN1_INTEGER_get(sx->version); |
112 | BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", v + 1, v); | 114 | BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", v + 1, v); |
113 | for(i = 0; i < sk_SXNETID_num(sx->ids); i++) { | 115 | for (i = 0; i < sk_SXNETID_num(sx->ids); i++) { |
114 | id = sk_SXNETID_value(sx->ids, i); | 116 | id = sk_SXNETID_value(sx->ids, i); |
115 | tmp = i2s_ASN1_INTEGER(NULL, id->zone); | 117 | tmp = i2s_ASN1_INTEGER(NULL, id->zone); |
116 | BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp); | 118 | BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp); |
@@ -127,34 +129,36 @@ static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, | |||
127 | * they should really be separate values for each user. | 129 | * they should really be separate values for each user. |
128 | */ | 130 | */ |
129 | 131 | ||
130 | 132 | static SXNET * | |
131 | static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, | 133 | sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, |
132 | STACK_OF(CONF_VALUE) *nval) | 134 | STACK_OF(CONF_VALUE) *nval) |
133 | { | 135 | { |
134 | CONF_VALUE *cnf; | 136 | CONF_VALUE *cnf; |
135 | SXNET *sx = NULL; | 137 | SXNET *sx = NULL; |
136 | int i; | 138 | int i; |
137 | for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { | 139 | |
140 | for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { | ||
138 | cnf = sk_CONF_VALUE_value(nval, i); | 141 | cnf = sk_CONF_VALUE_value(nval, i); |
139 | if(!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1)) | 142 | if (!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1)) |
140 | return NULL; | 143 | return NULL; |
141 | } | 144 | } |
142 | return sx; | 145 | return sx; |
143 | } | 146 | } |
144 | 147 | ||
145 | |||
146 | #endif | 148 | #endif |
147 | 149 | ||
148 | /* Strong Extranet utility functions */ | 150 | /* Strong Extranet utility functions */ |
149 | 151 | ||
150 | /* Add an id given the zone as an ASCII number */ | 152 | /* Add an id given the zone as an ASCII number */ |
151 | 153 | ||
152 | int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, | 154 | int |
153 | int userlen) | 155 | SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen) |
154 | { | 156 | { |
155 | ASN1_INTEGER *izone = NULL; | 157 | ASN1_INTEGER *izone = NULL; |
156 | if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) { | 158 | |
157 | X509V3err(X509V3_F_SXNET_ADD_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE); | 159 | if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) { |
160 | X509V3err(X509V3_F_SXNET_ADD_ID_ASC, | ||
161 | X509V3_R_ERROR_CONVERTING_ZONE); | ||
158 | return 0; | 162 | return 0; |
159 | } | 163 | } |
160 | return SXNET_add_id_INTEGER(psx, izone, user, userlen); | 164 | return SXNET_add_id_INTEGER(psx, izone, user, userlen); |
@@ -162,17 +166,18 @@ int SXNET_add_id_asc(SXNET **psx, char *zone, char *user, | |||
162 | 166 | ||
163 | /* Add an id given the zone as an unsigned long */ | 167 | /* Add an id given the zone as an unsigned long */ |
164 | 168 | ||
165 | int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, | 169 | int |
166 | int userlen) | 170 | SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen) |
167 | { | 171 | { |
168 | ASN1_INTEGER *izone = NULL; | 172 | ASN1_INTEGER *izone = NULL; |
169 | if(!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) { | 173 | |
170 | X509V3err(X509V3_F_SXNET_ADD_ID_ULONG,ERR_R_MALLOC_FAILURE); | 174 | if (!(izone = M_ASN1_INTEGER_new()) || |
175 | !ASN1_INTEGER_set(izone, lzone)) { | ||
176 | X509V3err(X509V3_F_SXNET_ADD_ID_ULONG, ERR_R_MALLOC_FAILURE); | ||
171 | M_ASN1_INTEGER_free(izone); | 177 | M_ASN1_INTEGER_free(izone); |
172 | return 0; | 178 | return 0; |
173 | } | 179 | } |
174 | return SXNET_add_id_INTEGER(psx, izone, user, userlen); | 180 | return SXNET_add_id_INTEGER(psx, izone, user, userlen); |
175 | |||
176 | } | 181 | } |
177 | 182 | ||
178 | /* Add an id given the zone as an ASN1_INTEGER. | 183 | /* Add an id given the zone as an ASN1_INTEGER. |
@@ -180,52 +185,67 @@ int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, | |||
180 | * free it up afterwards. | 185 | * free it up afterwards. |
181 | */ | 186 | */ |
182 | 187 | ||
183 | int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user, | 188 | int |
184 | int userlen) | 189 | SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user, int userlen) |
185 | { | 190 | { |
186 | SXNET *sx = NULL; | 191 | SXNET *sx = NULL; |
187 | SXNETID *id = NULL; | 192 | SXNETID *id = NULL; |
188 | if(!psx || !zone || !user) { | 193 | |
189 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_INVALID_NULL_ARGUMENT); | 194 | if (!psx || !zone || !user) { |
195 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, | ||
196 | X509V3_R_INVALID_NULL_ARGUMENT); | ||
190 | return 0; | 197 | return 0; |
191 | } | 198 | } |
192 | if(userlen == -1) userlen = strlen(user); | 199 | if (userlen == -1) |
193 | if(userlen > 64) { | 200 | userlen = strlen(user); |
194 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_USER_TOO_LONG); | 201 | if (userlen > 64) { |
202 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, | ||
203 | X509V3_R_USER_TOO_LONG); | ||
195 | return 0; | 204 | return 0; |
196 | } | 205 | } |
197 | if(!*psx) { | 206 | if (!*psx) { |
198 | if(!(sx = SXNET_new())) goto err; | 207 | if (!(sx = SXNET_new())) |
199 | if(!ASN1_INTEGER_set(sx->version, 0)) goto err; | 208 | goto err; |
209 | if (!ASN1_INTEGER_set(sx->version, 0)) | ||
210 | goto err; | ||
200 | *psx = sx; | 211 | *psx = sx; |
201 | } else sx = *psx; | 212 | } else |
202 | if(SXNET_get_id_INTEGER(sx, zone)) { | 213 | sx = *psx; |
203 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,X509V3_R_DUPLICATE_ZONE_ID); | 214 | if (SXNET_get_id_INTEGER(sx, zone)) { |
215 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, | ||
216 | X509V3_R_DUPLICATE_ZONE_ID); | ||
204 | return 0; | 217 | return 0; |
205 | } | 218 | } |
206 | 219 | ||
207 | if(!(id = SXNETID_new())) goto err; | 220 | if (!(id = SXNETID_new())) |
208 | if(userlen == -1) userlen = strlen(user); | 221 | goto err; |
209 | 222 | if (userlen == -1) | |
210 | if(!M_ASN1_OCTET_STRING_set(id->user, user, userlen)) goto err; | 223 | userlen = strlen(user); |
211 | if(!sk_SXNETID_push(sx->ids, id)) goto err; | 224 | |
225 | if (!M_ASN1_OCTET_STRING_set(id->user, user, userlen)) | ||
226 | goto err; | ||
227 | if (!sk_SXNETID_push(sx->ids, id)) | ||
228 | goto err; | ||
212 | id->zone = zone; | 229 | id->zone = zone; |
213 | return 1; | 230 | return 1; |
214 | 231 | ||
215 | err: | 232 | err: |
216 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,ERR_R_MALLOC_FAILURE); | 233 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, ERR_R_MALLOC_FAILURE); |
217 | SXNETID_free(id); | 234 | SXNETID_free(id); |
218 | SXNET_free(sx); | 235 | SXNET_free(sx); |
219 | *psx = NULL; | 236 | *psx = NULL; |
220 | return 0; | 237 | return 0; |
221 | } | 238 | } |
222 | 239 | ||
223 | ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone) | 240 | ASN1_OCTET_STRING * |
241 | SXNET_get_id_asc(SXNET *sx, char *zone) | ||
224 | { | 242 | { |
225 | ASN1_INTEGER *izone = NULL; | 243 | ASN1_INTEGER *izone = NULL; |
226 | ASN1_OCTET_STRING *oct; | 244 | ASN1_OCTET_STRING *oct; |
227 | if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) { | 245 | |
228 | X509V3err(X509V3_F_SXNET_GET_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE); | 246 | if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) { |
247 | X509V3err(X509V3_F_SXNET_GET_ID_ASC, | ||
248 | X509V3_R_ERROR_CONVERTING_ZONE); | ||
229 | return NULL; | 249 | return NULL; |
230 | } | 250 | } |
231 | oct = SXNET_get_id_INTEGER(sx, izone); | 251 | oct = SXNET_get_id_INTEGER(sx, izone); |
@@ -233,12 +253,15 @@ ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, char *zone) | |||
233 | return oct; | 253 | return oct; |
234 | } | 254 | } |
235 | 255 | ||
236 | ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone) | 256 | ASN1_OCTET_STRING * |
257 | SXNET_get_id_ulong(SXNET *sx, unsigned long lzone) | ||
237 | { | 258 | { |
238 | ASN1_INTEGER *izone = NULL; | 259 | ASN1_INTEGER *izone = NULL; |
239 | ASN1_OCTET_STRING *oct; | 260 | ASN1_OCTET_STRING *oct; |
240 | if(!(izone = M_ASN1_INTEGER_new()) || !ASN1_INTEGER_set(izone, lzone)) { | 261 | |
241 | X509V3err(X509V3_F_SXNET_GET_ID_ULONG,ERR_R_MALLOC_FAILURE); | 262 | if (!(izone = M_ASN1_INTEGER_new()) || |
263 | !ASN1_INTEGER_set(izone, lzone)) { | ||
264 | X509V3err(X509V3_F_SXNET_GET_ID_ULONG, ERR_R_MALLOC_FAILURE); | ||
242 | M_ASN1_INTEGER_free(izone); | 265 | M_ASN1_INTEGER_free(izone); |
243 | return NULL; | 266 | return NULL; |
244 | } | 267 | } |
@@ -247,13 +270,16 @@ ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone) | |||
247 | return oct; | 270 | return oct; |
248 | } | 271 | } |
249 | 272 | ||
250 | ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone) | 273 | ASN1_OCTET_STRING * |
274 | SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone) | ||
251 | { | 275 | { |
252 | SXNETID *id; | 276 | SXNETID *id; |
253 | int i; | 277 | int i; |
254 | for(i = 0; i < sk_SXNETID_num(sx->ids); i++) { | 278 | |
279 | for (i = 0; i < sk_SXNETID_num(sx->ids); i++) { | ||
255 | id = sk_SXNETID_value(sx->ids, i); | 280 | id = sk_SXNETID_value(sx->ids, i); |
256 | if(!M_ASN1_INTEGER_cmp(id->zone, zone)) return id->user; | 281 | if (!M_ASN1_INTEGER_cmp(id->zone, zone)) |
282 | return id->user; | ||
257 | } | 283 | } |
258 | return NULL; | 284 | return NULL; |
259 | } | 285 | } |