diff options
Diffstat (limited to 'src/lib/libcrypto/x509v3/v3_sxnet.c')
| -rw-r--r-- | src/lib/libcrypto/x509v3/v3_sxnet.c | 335 |
1 files changed, 0 insertions, 335 deletions
diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c deleted file mode 100644 index 7029aad916..0000000000 --- a/src/lib/libcrypto/x509v3/v3_sxnet.c +++ /dev/null | |||
| @@ -1,335 +0,0 @@ | |||
| 1 | /* $OpenBSD: v3_sxnet.c,v 1.13 2015/02/10 08:33:10 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | |||
| 62 | #include <openssl/asn1.h> | ||
| 63 | #include <openssl/asn1t.h> | ||
| 64 | #include <openssl/conf.h> | ||
| 65 | #include <openssl/err.h> | ||
| 66 | #include <openssl/x509v3.h> | ||
| 67 | |||
| 68 | /* Support for Thawte strong extranet extension */ | ||
| 69 | |||
| 70 | #define SXNET_TEST | ||
| 71 | |||
| 72 | static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, | ||
| 73 | int indent); | ||
| 74 | #ifdef SXNET_TEST | ||
| 75 | static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, | ||
| 76 | STACK_OF(CONF_VALUE) *nval); | ||
| 77 | #endif | ||
| 78 | const X509V3_EXT_METHOD v3_sxnet = { | ||
| 79 | NID_sxnet, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(SXNET), | ||
| 80 | 0, 0, 0, 0, | ||
| 81 | 0, 0, | ||
| 82 | 0, | ||
| 83 | #ifdef SXNET_TEST | ||
| 84 | (X509V3_EXT_V2I)sxnet_v2i, | ||
| 85 | #else | ||
| 86 | 0, | ||
| 87 | #endif | ||
| 88 | (X509V3_EXT_I2R)sxnet_i2r, | ||
| 89 | 0, | ||
| 90 | NULL | ||
| 91 | }; | ||
| 92 | |||
| 93 | ASN1_SEQUENCE(SXNETID) = { | ||
| 94 | ASN1_SIMPLE(SXNETID, zone, ASN1_INTEGER), | ||
| 95 | ASN1_SIMPLE(SXNETID, user, ASN1_OCTET_STRING) | ||
| 96 | } ASN1_SEQUENCE_END(SXNETID) | ||
| 97 | |||
| 98 | |||
| 99 | SXNETID * | ||
| 100 | d2i_SXNETID(SXNETID **a, const unsigned char **in, long len) | ||
| 101 | { | ||
| 102 | return (SXNETID *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
| 103 | &SXNETID_it); | ||
| 104 | } | ||
| 105 | |||
| 106 | int | ||
| 107 | i2d_SXNETID(SXNETID *a, unsigned char **out) | ||
| 108 | { | ||
| 109 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &SXNETID_it); | ||
| 110 | } | ||
| 111 | |||
| 112 | SXNETID * | ||
| 113 | SXNETID_new(void) | ||
| 114 | { | ||
| 115 | return (SXNETID *)ASN1_item_new(&SXNETID_it); | ||
| 116 | } | ||
| 117 | |||
| 118 | void | ||
| 119 | SXNETID_free(SXNETID *a) | ||
| 120 | { | ||
| 121 | ASN1_item_free((ASN1_VALUE *)a, &SXNETID_it); | ||
| 122 | } | ||
| 123 | |||
| 124 | ASN1_SEQUENCE(SXNET) = { | ||
| 125 | ASN1_SIMPLE(SXNET, version, ASN1_INTEGER), | ||
| 126 | ASN1_SEQUENCE_OF(SXNET, ids, SXNETID) | ||
| 127 | } ASN1_SEQUENCE_END(SXNET) | ||
| 128 | |||
| 129 | |||
| 130 | SXNET * | ||
| 131 | d2i_SXNET(SXNET **a, const unsigned char **in, long len) | ||
| 132 | { | ||
| 133 | return (SXNET *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
| 134 | &SXNET_it); | ||
| 135 | } | ||
| 136 | |||
| 137 | int | ||
| 138 | i2d_SXNET(SXNET *a, unsigned char **out) | ||
| 139 | { | ||
| 140 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &SXNET_it); | ||
| 141 | } | ||
| 142 | |||
| 143 | SXNET * | ||
| 144 | SXNET_new(void) | ||
| 145 | { | ||
| 146 | return (SXNET *)ASN1_item_new(&SXNET_it); | ||
| 147 | } | ||
| 148 | |||
| 149 | void | ||
| 150 | SXNET_free(SXNET *a) | ||
| 151 | { | ||
| 152 | ASN1_item_free((ASN1_VALUE *)a, &SXNET_it); | ||
| 153 | } | ||
| 154 | |||
| 155 | static int | ||
| 156 | sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, int indent) | ||
| 157 | { | ||
| 158 | long v; | ||
| 159 | char *tmp; | ||
| 160 | SXNETID *id; | ||
| 161 | int i; | ||
| 162 | |||
| 163 | v = ASN1_INTEGER_get(sx->version); | ||
| 164 | BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", v + 1, v); | ||
| 165 | for (i = 0; i < sk_SXNETID_num(sx->ids); i++) { | ||
| 166 | id = sk_SXNETID_value(sx->ids, i); | ||
| 167 | tmp = i2s_ASN1_INTEGER(NULL, id->zone); | ||
| 168 | BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp); | ||
| 169 | free(tmp); | ||
| 170 | M_ASN1_OCTET_STRING_print(out, id->user); | ||
| 171 | } | ||
| 172 | return 1; | ||
| 173 | } | ||
| 174 | |||
| 175 | #ifdef SXNET_TEST | ||
| 176 | |||
| 177 | /* NBB: this is used for testing only. It should *not* be used for anything | ||
| 178 | * else because it will just take static IDs from the configuration file and | ||
| 179 | * they should really be separate values for each user. | ||
| 180 | */ | ||
| 181 | |||
| 182 | static SXNET * | ||
| 183 | sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, | ||
| 184 | STACK_OF(CONF_VALUE) *nval) | ||
| 185 | { | ||
| 186 | CONF_VALUE *cnf; | ||
| 187 | SXNET *sx = NULL; | ||
| 188 | int i; | ||
| 189 | |||
| 190 | for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { | ||
| 191 | cnf = sk_CONF_VALUE_value(nval, i); | ||
| 192 | if (!SXNET_add_id_asc(&sx, cnf->name, cnf->value, -1)) | ||
| 193 | return NULL; | ||
| 194 | } | ||
| 195 | return sx; | ||
| 196 | } | ||
| 197 | |||
| 198 | #endif | ||
| 199 | |||
| 200 | /* Strong Extranet utility functions */ | ||
| 201 | |||
| 202 | /* Add an id given the zone as an ASCII number */ | ||
| 203 | |||
| 204 | int | ||
| 205 | SXNET_add_id_asc(SXNET **psx, char *zone, char *user, int userlen) | ||
| 206 | { | ||
| 207 | ASN1_INTEGER *izone = NULL; | ||
| 208 | |||
| 209 | if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) { | ||
| 210 | X509V3err(X509V3_F_SXNET_ADD_ID_ASC, | ||
| 211 | X509V3_R_ERROR_CONVERTING_ZONE); | ||
| 212 | return 0; | ||
| 213 | } | ||
| 214 | return SXNET_add_id_INTEGER(psx, izone, user, userlen); | ||
| 215 | } | ||
| 216 | |||
| 217 | /* Add an id given the zone as an unsigned long */ | ||
| 218 | |||
| 219 | int | ||
| 220 | SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user, int userlen) | ||
| 221 | { | ||
| 222 | ASN1_INTEGER *izone = NULL; | ||
| 223 | |||
| 224 | if (!(izone = M_ASN1_INTEGER_new()) || | ||
| 225 | !ASN1_INTEGER_set(izone, lzone)) { | ||
| 226 | X509V3err(X509V3_F_SXNET_ADD_ID_ULONG, ERR_R_MALLOC_FAILURE); | ||
| 227 | M_ASN1_INTEGER_free(izone); | ||
| 228 | return 0; | ||
| 229 | } | ||
| 230 | return SXNET_add_id_INTEGER(psx, izone, user, userlen); | ||
| 231 | } | ||
| 232 | |||
| 233 | /* Add an id given the zone as an ASN1_INTEGER. | ||
| 234 | * Note this version uses the passed integer and doesn't make a copy so don't | ||
| 235 | * free it up afterwards. | ||
| 236 | */ | ||
| 237 | |||
| 238 | int | ||
| 239 | SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user, int userlen) | ||
| 240 | { | ||
| 241 | SXNET *sx = NULL; | ||
| 242 | SXNETID *id = NULL; | ||
| 243 | |||
| 244 | if (!psx || !zone || !user) { | ||
| 245 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, | ||
| 246 | X509V3_R_INVALID_NULL_ARGUMENT); | ||
| 247 | return 0; | ||
| 248 | } | ||
| 249 | if (userlen == -1) | ||
| 250 | userlen = strlen(user); | ||
| 251 | if (userlen > 64) { | ||
| 252 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, | ||
| 253 | X509V3_R_USER_TOO_LONG); | ||
| 254 | return 0; | ||
| 255 | } | ||
| 256 | if (!*psx) { | ||
| 257 | if (!(sx = SXNET_new())) | ||
| 258 | goto err; | ||
| 259 | if (!ASN1_INTEGER_set(sx->version, 0)) | ||
| 260 | goto err; | ||
| 261 | *psx = sx; | ||
| 262 | } else | ||
| 263 | sx = *psx; | ||
| 264 | if (SXNET_get_id_INTEGER(sx, zone)) { | ||
| 265 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, | ||
| 266 | X509V3_R_DUPLICATE_ZONE_ID); | ||
| 267 | return 0; | ||
| 268 | } | ||
| 269 | |||
| 270 | if (!(id = SXNETID_new())) | ||
| 271 | goto err; | ||
| 272 | if (userlen == -1) | ||
| 273 | userlen = strlen(user); | ||
| 274 | |||
| 275 | if (!M_ASN1_OCTET_STRING_set(id->user, user, userlen)) | ||
| 276 | goto err; | ||
| 277 | if (!sk_SXNETID_push(sx->ids, id)) | ||
| 278 | goto err; | ||
| 279 | id->zone = zone; | ||
| 280 | return 1; | ||
| 281 | |||
| 282 | err: | ||
| 283 | X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, ERR_R_MALLOC_FAILURE); | ||
| 284 | SXNETID_free(id); | ||
| 285 | SXNET_free(sx); | ||
| 286 | *psx = NULL; | ||
| 287 | return 0; | ||
| 288 | } | ||
| 289 | |||
| 290 | ASN1_OCTET_STRING * | ||
| 291 | SXNET_get_id_asc(SXNET *sx, char *zone) | ||
| 292 | { | ||
| 293 | ASN1_INTEGER *izone = NULL; | ||
| 294 | ASN1_OCTET_STRING *oct; | ||
| 295 | |||
| 296 | if (!(izone = s2i_ASN1_INTEGER(NULL, zone))) { | ||
| 297 | X509V3err(X509V3_F_SXNET_GET_ID_ASC, | ||
| 298 | X509V3_R_ERROR_CONVERTING_ZONE); | ||
| 299 | return NULL; | ||
| 300 | } | ||
| 301 | oct = SXNET_get_id_INTEGER(sx, izone); | ||
| 302 | M_ASN1_INTEGER_free(izone); | ||
| 303 | return oct; | ||
| 304 | } | ||
| 305 | |||
| 306 | ASN1_OCTET_STRING * | ||
| 307 | SXNET_get_id_ulong(SXNET *sx, unsigned long lzone) | ||
| 308 | { | ||
| 309 | ASN1_INTEGER *izone = NULL; | ||
| 310 | ASN1_OCTET_STRING *oct; | ||
| 311 | |||
| 312 | if (!(izone = M_ASN1_INTEGER_new()) || | ||
| 313 | !ASN1_INTEGER_set(izone, lzone)) { | ||
| 314 | X509V3err(X509V3_F_SXNET_GET_ID_ULONG, ERR_R_MALLOC_FAILURE); | ||
| 315 | M_ASN1_INTEGER_free(izone); | ||
| 316 | return NULL; | ||
| 317 | } | ||
| 318 | oct = SXNET_get_id_INTEGER(sx, izone); | ||
| 319 | M_ASN1_INTEGER_free(izone); | ||
| 320 | return oct; | ||
| 321 | } | ||
| 322 | |||
| 323 | ASN1_OCTET_STRING * | ||
| 324 | SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone) | ||
| 325 | { | ||
| 326 | SXNETID *id; | ||
| 327 | int i; | ||
| 328 | |||
| 329 | for (i = 0; i < sk_SXNETID_num(sx->ids); i++) { | ||
| 330 | id = sk_SXNETID_value(sx->ids, i); | ||
| 331 | if (!M_ASN1_INTEGER_cmp(id->zone, zone)) | ||
| 332 | return id->user; | ||
| 333 | } | ||
| 334 | return NULL; | ||
| 335 | } | ||
