diff options
| author | cvs2svn <admin@example.com> | 2015-08-02 21:54:22 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 2015-08-02 21:54:22 +0000 |
| commit | 92262c9818409ff436c41f1e51c2cea5b227f152 (patch) | |
| tree | 5609c82060f75c53af0a7641d9b33a88574876cd /src/lib/libcrypto/x509 | |
| parent | ed40f444ba01bcae1d8540f9c26d79537ab5baf2 (diff) | |
| download | openbsd-OPENBSD_5_8_BASE.tar.gz openbsd-OPENBSD_5_8_BASE.tar.bz2 openbsd-OPENBSD_5_8_BASE.zip | |
This commit was manufactured by cvs2git to create tag 'OPENBSD_5_8_BASE'.OPENBSD_5_8_BASE
Diffstat (limited to 'src/lib/libcrypto/x509')
28 files changed, 0 insertions, 10673 deletions
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c deleted file mode 100644 index 7b7d14a950..0000000000 --- a/src/lib/libcrypto/x509/by_dir.c +++ /dev/null | |||
| @@ -1,422 +0,0 @@ | |||
| 1 | /* $OpenBSD: by_dir.c,v 1.37 2015/04/11 16:03:21 deraadt Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <sys/types.h> | ||
| 60 | |||
| 61 | #include <errno.h> | ||
| 62 | #include <stdio.h> | ||
| 63 | #include <string.h> | ||
| 64 | #include <time.h> | ||
| 65 | #include <unistd.h> | ||
| 66 | |||
| 67 | #include <openssl/opensslconf.h> | ||
| 68 | |||
| 69 | #include <openssl/err.h> | ||
| 70 | #include <openssl/lhash.h> | ||
| 71 | #include <openssl/x509.h> | ||
| 72 | |||
| 73 | # include <sys/stat.h> | ||
| 74 | |||
| 75 | typedef struct lookup_dir_hashes_st { | ||
| 76 | unsigned long hash; | ||
| 77 | int suffix; | ||
| 78 | } BY_DIR_HASH; | ||
| 79 | |||
| 80 | typedef struct lookup_dir_entry_st { | ||
| 81 | char *dir; | ||
| 82 | int dir_type; | ||
| 83 | STACK_OF(BY_DIR_HASH) *hashes; | ||
| 84 | } BY_DIR_ENTRY; | ||
| 85 | |||
| 86 | typedef struct lookup_dir_st { | ||
| 87 | BUF_MEM *buffer; | ||
| 88 | STACK_OF(BY_DIR_ENTRY) *dirs; | ||
| 89 | } BY_DIR; | ||
| 90 | |||
| 91 | DECLARE_STACK_OF(BY_DIR_HASH) | ||
| 92 | DECLARE_STACK_OF(BY_DIR_ENTRY) | ||
| 93 | |||
| 94 | static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, | ||
| 95 | char **ret); | ||
| 96 | static int new_dir(X509_LOOKUP *lu); | ||
| 97 | static void free_dir(X509_LOOKUP *lu); | ||
| 98 | static int add_cert_dir(BY_DIR *ctx, const char *dir, int type); | ||
| 99 | static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, | ||
| 100 | X509_OBJECT *ret); | ||
| 101 | |||
| 102 | static X509_LOOKUP_METHOD x509_dir_lookup = { | ||
| 103 | .name = "Load certs from files in a directory", | ||
| 104 | .new_item = new_dir, | ||
| 105 | .free = free_dir, | ||
| 106 | .init = NULL, | ||
| 107 | .shutdown = NULL, | ||
| 108 | .ctrl = dir_ctrl, | ||
| 109 | .get_by_subject = get_cert_by_subject, | ||
| 110 | .get_by_issuer_serial = NULL, | ||
| 111 | .get_by_fingerprint = NULL, | ||
| 112 | .get_by_alias = NULL, | ||
| 113 | }; | ||
| 114 | |||
| 115 | X509_LOOKUP_METHOD * | ||
| 116 | X509_LOOKUP_hash_dir(void) | ||
| 117 | { | ||
| 118 | return (&x509_dir_lookup); | ||
| 119 | } | ||
| 120 | |||
| 121 | static int | ||
| 122 | dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, | ||
| 123 | char **retp) | ||
| 124 | { | ||
| 125 | int ret = 0; | ||
| 126 | BY_DIR *ld; | ||
| 127 | |||
| 128 | ld = (BY_DIR *)ctx->method_data; | ||
| 129 | |||
| 130 | switch (cmd) { | ||
| 131 | case X509_L_ADD_DIR: | ||
| 132 | if (argl == X509_FILETYPE_DEFAULT) { | ||
| 133 | ret = add_cert_dir(ld, X509_get_default_cert_dir(), | ||
| 134 | X509_FILETYPE_PEM); | ||
| 135 | if (!ret) { | ||
| 136 | X509err(X509_F_DIR_CTRL, X509_R_LOADING_CERT_DIR); | ||
| 137 | } | ||
| 138 | } else | ||
| 139 | ret = add_cert_dir(ld, argp, (int)argl); | ||
| 140 | break; | ||
| 141 | } | ||
| 142 | return (ret); | ||
| 143 | } | ||
| 144 | |||
| 145 | static int | ||
| 146 | new_dir(X509_LOOKUP *lu) | ||
| 147 | { | ||
| 148 | BY_DIR *a; | ||
| 149 | |||
| 150 | if ((a = malloc(sizeof(BY_DIR))) == NULL) | ||
| 151 | return (0); | ||
| 152 | if ((a->buffer = BUF_MEM_new()) == NULL) { | ||
| 153 | free(a); | ||
| 154 | return (0); | ||
| 155 | } | ||
| 156 | a->dirs = NULL; | ||
| 157 | lu->method_data = (char *)a; | ||
| 158 | return (1); | ||
| 159 | } | ||
| 160 | |||
| 161 | static void | ||
| 162 | by_dir_hash_free(BY_DIR_HASH *hash) | ||
| 163 | { | ||
| 164 | free(hash); | ||
| 165 | } | ||
| 166 | |||
| 167 | static int | ||
| 168 | by_dir_hash_cmp(const BY_DIR_HASH * const *a, | ||
| 169 | const BY_DIR_HASH * const *b) | ||
| 170 | { | ||
| 171 | if ((*a)->hash > (*b)->hash) | ||
| 172 | return 1; | ||
| 173 | if ((*a)->hash < (*b)->hash) | ||
| 174 | return -1; | ||
| 175 | return 0; | ||
| 176 | } | ||
| 177 | |||
| 178 | static void | ||
| 179 | by_dir_entry_free(BY_DIR_ENTRY *ent) | ||
| 180 | { | ||
| 181 | free(ent->dir); | ||
| 182 | if (ent->hashes) | ||
| 183 | sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free); | ||
| 184 | free(ent); | ||
| 185 | } | ||
| 186 | |||
| 187 | static void | ||
| 188 | free_dir(X509_LOOKUP *lu) | ||
| 189 | { | ||
| 190 | BY_DIR *a; | ||
| 191 | |||
| 192 | a = (BY_DIR *)lu->method_data; | ||
| 193 | if (a->dirs != NULL) | ||
| 194 | sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free); | ||
| 195 | if (a->buffer != NULL) | ||
| 196 | BUF_MEM_free(a->buffer); | ||
| 197 | free(a); | ||
| 198 | } | ||
| 199 | |||
| 200 | static int | ||
| 201 | add_cert_dir(BY_DIR *ctx, const char *dir, int type) | ||
| 202 | { | ||
| 203 | int j; | ||
| 204 | const char *s, *ss, *p; | ||
| 205 | ptrdiff_t len; | ||
| 206 | |||
| 207 | if (dir == NULL || !*dir) { | ||
| 208 | X509err(X509_F_ADD_CERT_DIR, X509_R_INVALID_DIRECTORY); | ||
| 209 | return 0; | ||
| 210 | } | ||
| 211 | |||
| 212 | s = dir; | ||
| 213 | p = s; | ||
| 214 | do { | ||
| 215 | if ((*p == ':') || (*p == '\0')) { | ||
| 216 | BY_DIR_ENTRY *ent; | ||
| 217 | ss = s; | ||
| 218 | s = p + 1; | ||
| 219 | len = p - ss; | ||
| 220 | if (len == 0) | ||
| 221 | continue; | ||
| 222 | for (j = 0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) { | ||
| 223 | ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j); | ||
| 224 | if (strlen(ent->dir) == (size_t)len && | ||
| 225 | strncmp(ent->dir, ss, (size_t)len) == 0) | ||
| 226 | break; | ||
| 227 | } | ||
| 228 | if (j < sk_BY_DIR_ENTRY_num(ctx->dirs)) | ||
| 229 | continue; | ||
| 230 | if (ctx->dirs == NULL) { | ||
| 231 | ctx->dirs = sk_BY_DIR_ENTRY_new_null(); | ||
| 232 | if (!ctx->dirs) { | ||
| 233 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); | ||
| 234 | return 0; | ||
| 235 | } | ||
| 236 | } | ||
| 237 | ent = malloc(sizeof(BY_DIR_ENTRY)); | ||
| 238 | if (!ent) { | ||
| 239 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); | ||
| 240 | return 0; | ||
| 241 | } | ||
| 242 | ent->dir_type = type; | ||
| 243 | ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); | ||
| 244 | ent->dir = strndup(ss, (size_t)len); | ||
| 245 | if (!ent->dir || !ent->hashes) { | ||
| 246 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); | ||
| 247 | by_dir_entry_free(ent); | ||
| 248 | return 0; | ||
| 249 | } | ||
| 250 | if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) { | ||
| 251 | X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE); | ||
| 252 | by_dir_entry_free(ent); | ||
| 253 | return 0; | ||
| 254 | } | ||
| 255 | } | ||
| 256 | } while (*p++ != '\0'); | ||
| 257 | return 1; | ||
| 258 | } | ||
| 259 | |||
| 260 | static int | ||
| 261 | get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, | ||
| 262 | X509_OBJECT *ret) | ||
| 263 | { | ||
| 264 | BY_DIR *ctx; | ||
| 265 | union { | ||
| 266 | struct { | ||
| 267 | X509 st_x509; | ||
| 268 | X509_CINF st_x509_cinf; | ||
| 269 | } x509; | ||
| 270 | struct { | ||
| 271 | X509_CRL st_crl; | ||
| 272 | X509_CRL_INFO st_crl_info; | ||
| 273 | } crl; | ||
| 274 | } data; | ||
| 275 | int ok = 0; | ||
| 276 | int i, j, k; | ||
| 277 | unsigned long h; | ||
| 278 | BUF_MEM *b = NULL; | ||
| 279 | X509_OBJECT stmp, *tmp; | ||
| 280 | const char *postfix=""; | ||
| 281 | |||
| 282 | if (name == NULL) | ||
| 283 | return (0); | ||
| 284 | |||
| 285 | stmp.type = type; | ||
| 286 | if (type == X509_LU_X509) { | ||
| 287 | data.x509.st_x509.cert_info = &data.x509.st_x509_cinf; | ||
| 288 | data.x509.st_x509_cinf.subject = name; | ||
| 289 | stmp.data.x509 = &data.x509.st_x509; | ||
| 290 | postfix=""; | ||
| 291 | } else if (type == X509_LU_CRL) { | ||
| 292 | data.crl.st_crl.crl = &data.crl.st_crl_info; | ||
| 293 | data.crl.st_crl_info.issuer = name; | ||
| 294 | stmp.data.crl = &data.crl.st_crl; | ||
| 295 | postfix="r"; | ||
| 296 | } else { | ||
| 297 | X509err(X509_F_GET_CERT_BY_SUBJECT, X509_R_WRONG_LOOKUP_TYPE); | ||
| 298 | goto finish; | ||
| 299 | } | ||
| 300 | |||
| 301 | if ((b = BUF_MEM_new()) == NULL) { | ||
| 302 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_BUF_LIB); | ||
| 303 | goto finish; | ||
| 304 | } | ||
| 305 | |||
| 306 | ctx = (BY_DIR *)xl->method_data; | ||
| 307 | |||
| 308 | h = X509_NAME_hash(name); | ||
| 309 | for (i = 0; i < sk_BY_DIR_ENTRY_num(ctx->dirs); i++) { | ||
| 310 | BY_DIR_ENTRY *ent; | ||
| 311 | int idx; | ||
| 312 | BY_DIR_HASH htmp, *hent; | ||
| 313 | ent = sk_BY_DIR_ENTRY_value(ctx->dirs, i); | ||
| 314 | j = strlen(ent->dir) + 1 + 8 + 6 + 1 + 1; | ||
| 315 | if (!BUF_MEM_grow(b, j)) { | ||
| 316 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); | ||
| 317 | goto finish; | ||
| 318 | } | ||
| 319 | if (type == X509_LU_CRL && ent->hashes) { | ||
| 320 | htmp.hash = h; | ||
| 321 | CRYPTO_r_lock(CRYPTO_LOCK_X509_STORE); | ||
| 322 | idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp); | ||
| 323 | if (idx >= 0) { | ||
| 324 | hent = sk_BY_DIR_HASH_value(ent->hashes, idx); | ||
| 325 | k = hent->suffix; | ||
| 326 | } else { | ||
| 327 | hent = NULL; | ||
| 328 | k = 0; | ||
| 329 | } | ||
| 330 | CRYPTO_r_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 331 | } else { | ||
| 332 | k = 0; | ||
| 333 | hent = NULL; | ||
| 334 | } | ||
| 335 | for (;;) { | ||
| 336 | (void) snprintf(b->data, b->max, "%s/%08lx.%s%d", | ||
| 337 | ent->dir, h, postfix, k); | ||
| 338 | |||
| 339 | { | ||
| 340 | struct stat st; | ||
| 341 | if (stat(b->data, &st) < 0) | ||
| 342 | break; | ||
| 343 | } | ||
| 344 | /* found one. */ | ||
| 345 | if (type == X509_LU_X509) { | ||
| 346 | if ((X509_load_cert_file(xl, b->data, | ||
| 347 | ent->dir_type)) == 0) | ||
| 348 | break; | ||
| 349 | } else if (type == X509_LU_CRL) { | ||
| 350 | if ((X509_load_crl_file(xl, b->data, | ||
| 351 | ent->dir_type)) == 0) | ||
| 352 | break; | ||
| 353 | } | ||
| 354 | /* else case will caught higher up */ | ||
| 355 | k++; | ||
| 356 | } | ||
| 357 | |||
| 358 | /* we have added it to the cache so now pull it out again */ | ||
| 359 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 360 | j = sk_X509_OBJECT_find(xl->store_ctx->objs, &stmp); | ||
| 361 | if (j != -1) | ||
| 362 | tmp = sk_X509_OBJECT_value(xl->store_ctx->objs, j); | ||
| 363 | else | ||
| 364 | tmp = NULL; | ||
| 365 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 366 | |||
| 367 | /* If a CRL, update the last file suffix added for this */ | ||
| 368 | if (type == X509_LU_CRL) { | ||
| 369 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 370 | /* | ||
| 371 | * Look for entry again in case another thread added | ||
| 372 | * an entry first. | ||
| 373 | */ | ||
| 374 | if (!hent) { | ||
| 375 | htmp.hash = h; | ||
| 376 | idx = sk_BY_DIR_HASH_find(ent->hashes, &htmp); | ||
| 377 | if (idx >= 0) | ||
| 378 | hent = sk_BY_DIR_HASH_value( | ||
| 379 | ent->hashes, idx); | ||
| 380 | } | ||
| 381 | if (!hent) { | ||
| 382 | hent = malloc(sizeof(BY_DIR_HASH)); | ||
| 383 | if (!hent) { | ||
| 384 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); | ||
| 385 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 386 | ok = 0; | ||
| 387 | goto finish; | ||
| 388 | } | ||
| 389 | hent->hash = h; | ||
| 390 | hent->suffix = k; | ||
| 391 | if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) { | ||
| 392 | X509err(X509_F_GET_CERT_BY_SUBJECT, ERR_R_MALLOC_FAILURE); | ||
| 393 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 394 | free(hent); | ||
| 395 | ok = 0; | ||
| 396 | goto finish; | ||
| 397 | } | ||
| 398 | } else if (hent->suffix < k) | ||
| 399 | hent->suffix = k; | ||
| 400 | |||
| 401 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 402 | |||
| 403 | } | ||
| 404 | |||
| 405 | if (tmp != NULL) { | ||
| 406 | ok = 1; | ||
| 407 | ret->type = tmp->type; | ||
| 408 | memcpy(&ret->data, &tmp->data, sizeof(ret->data)); | ||
| 409 | /* | ||
| 410 | * If we were going to up the reference count, | ||
| 411 | * we would need to do it on a perl 'type' basis | ||
| 412 | */ | ||
| 413 | /* CRYPTO_add(&tmp->data.x509->references,1, | ||
| 414 | CRYPTO_LOCK_X509);*/ | ||
| 415 | goto finish; | ||
| 416 | } | ||
| 417 | } | ||
| 418 | finish: | ||
| 419 | if (b != NULL) | ||
| 420 | BUF_MEM_free(b); | ||
| 421 | return (ok); | ||
| 422 | } | ||
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c deleted file mode 100644 index 68920271fc..0000000000 --- a/src/lib/libcrypto/x509/by_file.c +++ /dev/null | |||
| @@ -1,275 +0,0 @@ | |||
| 1 | /* $OpenBSD: by_file.c,v 1.19 2015/04/11 16:03:21 deraadt Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | #include <time.h> | ||
| 62 | #include <unistd.h> | ||
| 63 | |||
| 64 | #include <openssl/buffer.h> | ||
| 65 | #include <openssl/err.h> | ||
| 66 | #include <openssl/pem.h> | ||
| 67 | #include <openssl/lhash.h> | ||
| 68 | #include <openssl/x509.h> | ||
| 69 | |||
| 70 | static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, | ||
| 71 | long argl, char **ret); | ||
| 72 | |||
| 73 | static X509_LOOKUP_METHOD x509_file_lookup = { | ||
| 74 | .name = "Load file into cache", | ||
| 75 | .new_item = NULL, | ||
| 76 | .free = NULL, | ||
| 77 | .init = NULL, | ||
| 78 | .shutdown = NULL, | ||
| 79 | .ctrl = by_file_ctrl, | ||
| 80 | .get_by_subject = NULL, | ||
| 81 | .get_by_issuer_serial = NULL, | ||
| 82 | .get_by_fingerprint = NULL, | ||
| 83 | .get_by_alias = NULL, | ||
| 84 | }; | ||
| 85 | |||
| 86 | X509_LOOKUP_METHOD * | ||
| 87 | X509_LOOKUP_file(void) | ||
| 88 | { | ||
| 89 | return (&x509_file_lookup); | ||
| 90 | } | ||
| 91 | |||
| 92 | static int | ||
| 93 | by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, | ||
| 94 | char **ret) | ||
| 95 | { | ||
| 96 | int ok = 0; | ||
| 97 | |||
| 98 | switch (cmd) { | ||
| 99 | case X509_L_FILE_LOAD: | ||
| 100 | if (argl == X509_FILETYPE_DEFAULT) { | ||
| 101 | ok = (X509_load_cert_crl_file(ctx, | ||
| 102 | X509_get_default_cert_file(), | ||
| 103 | X509_FILETYPE_PEM) != 0); | ||
| 104 | if (!ok) { | ||
| 105 | X509err(X509_F_BY_FILE_CTRL, | ||
| 106 | X509_R_LOADING_DEFAULTS); | ||
| 107 | } | ||
| 108 | } else { | ||
| 109 | if (argl == X509_FILETYPE_PEM) | ||
| 110 | ok = (X509_load_cert_crl_file(ctx, argp, | ||
| 111 | X509_FILETYPE_PEM) != 0); | ||
| 112 | else | ||
| 113 | ok = (X509_load_cert_file(ctx, | ||
| 114 | argp, (int)argl) != 0); | ||
| 115 | } | ||
| 116 | break; | ||
| 117 | } | ||
| 118 | return (ok); | ||
| 119 | } | ||
| 120 | |||
| 121 | int | ||
| 122 | X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type) | ||
| 123 | { | ||
| 124 | int ret = 0; | ||
| 125 | BIO *in = NULL; | ||
| 126 | int i, count = 0; | ||
| 127 | X509 *x = NULL; | ||
| 128 | |||
| 129 | if (file == NULL) | ||
| 130 | return (1); | ||
| 131 | in = BIO_new(BIO_s_file_internal()); | ||
| 132 | |||
| 133 | if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) { | ||
| 134 | X509err(X509_F_X509_LOAD_CERT_FILE, ERR_R_SYS_LIB); | ||
| 135 | goto err; | ||
| 136 | } | ||
| 137 | |||
| 138 | if (type == X509_FILETYPE_PEM) { | ||
| 139 | for (;;) { | ||
| 140 | x = PEM_read_bio_X509_AUX(in, NULL, NULL, NULL); | ||
| 141 | if (x == NULL) { | ||
| 142 | if ((ERR_GET_REASON(ERR_peek_last_error()) == | ||
| 143 | PEM_R_NO_START_LINE) && (count > 0)) { | ||
| 144 | ERR_clear_error(); | ||
| 145 | break; | ||
| 146 | } else { | ||
| 147 | X509err(X509_F_X509_LOAD_CERT_FILE, | ||
| 148 | ERR_R_PEM_LIB); | ||
| 149 | goto err; | ||
| 150 | } | ||
| 151 | } | ||
| 152 | i = X509_STORE_add_cert(ctx->store_ctx, x); | ||
| 153 | if (!i) | ||
| 154 | goto err; | ||
| 155 | count++; | ||
| 156 | X509_free(x); | ||
| 157 | x = NULL; | ||
| 158 | } | ||
| 159 | ret = count; | ||
| 160 | } else if (type == X509_FILETYPE_ASN1) { | ||
| 161 | x = d2i_X509_bio(in, NULL); | ||
| 162 | if (x == NULL) { | ||
| 163 | X509err(X509_F_X509_LOAD_CERT_FILE, ERR_R_ASN1_LIB); | ||
| 164 | goto err; | ||
| 165 | } | ||
| 166 | i = X509_STORE_add_cert(ctx->store_ctx, x); | ||
| 167 | if (!i) | ||
| 168 | goto err; | ||
| 169 | ret = i; | ||
| 170 | } else { | ||
| 171 | X509err(X509_F_X509_LOAD_CERT_FILE, X509_R_BAD_X509_FILETYPE); | ||
| 172 | goto err; | ||
| 173 | } | ||
| 174 | err: | ||
| 175 | if (x != NULL) | ||
| 176 | X509_free(x); | ||
| 177 | BIO_free(in); | ||
| 178 | return (ret); | ||
| 179 | } | ||
| 180 | |||
| 181 | int | ||
| 182 | X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type) | ||
| 183 | { | ||
| 184 | int ret = 0; | ||
| 185 | BIO *in = NULL; | ||
| 186 | int i, count = 0; | ||
| 187 | X509_CRL *x = NULL; | ||
| 188 | |||
| 189 | if (file == NULL) | ||
| 190 | return (1); | ||
| 191 | in = BIO_new(BIO_s_file_internal()); | ||
| 192 | |||
| 193 | if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) { | ||
| 194 | X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_SYS_LIB); | ||
| 195 | goto err; | ||
| 196 | } | ||
| 197 | |||
| 198 | if (type == X509_FILETYPE_PEM) { | ||
| 199 | for (;;) { | ||
| 200 | x = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL); | ||
| 201 | if (x == NULL) { | ||
| 202 | if ((ERR_GET_REASON(ERR_peek_last_error()) == | ||
| 203 | PEM_R_NO_START_LINE) && (count > 0)) { | ||
| 204 | ERR_clear_error(); | ||
| 205 | break; | ||
| 206 | } else { | ||
| 207 | X509err(X509_F_X509_LOAD_CRL_FILE, | ||
| 208 | ERR_R_PEM_LIB); | ||
| 209 | goto err; | ||
| 210 | } | ||
| 211 | } | ||
| 212 | i = X509_STORE_add_crl(ctx->store_ctx, x); | ||
| 213 | if (!i) | ||
| 214 | goto err; | ||
| 215 | count++; | ||
| 216 | X509_CRL_free(x); | ||
| 217 | x = NULL; | ||
| 218 | } | ||
| 219 | ret = count; | ||
| 220 | } else if (type == X509_FILETYPE_ASN1) { | ||
| 221 | x = d2i_X509_CRL_bio(in, NULL); | ||
| 222 | if (x == NULL) { | ||
| 223 | X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_ASN1_LIB); | ||
| 224 | goto err; | ||
| 225 | } | ||
| 226 | i = X509_STORE_add_crl(ctx->store_ctx, x); | ||
| 227 | if (!i) | ||
| 228 | goto err; | ||
| 229 | ret = i; | ||
| 230 | } else { | ||
| 231 | X509err(X509_F_X509_LOAD_CRL_FILE, X509_R_BAD_X509_FILETYPE); | ||
| 232 | goto err; | ||
| 233 | } | ||
| 234 | err: | ||
| 235 | if (x != NULL) | ||
| 236 | X509_CRL_free(x); | ||
| 237 | BIO_free(in); | ||
| 238 | return (ret); | ||
| 239 | } | ||
| 240 | |||
| 241 | int | ||
| 242 | X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type) | ||
| 243 | { | ||
| 244 | STACK_OF(X509_INFO) *inf; | ||
| 245 | X509_INFO *itmp; | ||
| 246 | BIO *in; | ||
| 247 | int i, count = 0; | ||
| 248 | if (type != X509_FILETYPE_PEM) | ||
| 249 | return X509_load_cert_file(ctx, file, type); | ||
| 250 | in = BIO_new_file(file, "r"); | ||
| 251 | if (!in) { | ||
| 252 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_SYS_LIB); | ||
| 253 | return 0; | ||
| 254 | } | ||
| 255 | inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL); | ||
| 256 | BIO_free(in); | ||
| 257 | if (!inf) { | ||
| 258 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_PEM_LIB); | ||
| 259 | return 0; | ||
| 260 | } | ||
| 261 | for (i = 0; i < sk_X509_INFO_num(inf); i++) { | ||
| 262 | itmp = sk_X509_INFO_value(inf, i); | ||
| 263 | if (itmp->x509) { | ||
| 264 | X509_STORE_add_cert(ctx->store_ctx, itmp->x509); | ||
| 265 | count++; | ||
| 266 | } | ||
| 267 | if (itmp->crl) { | ||
| 268 | X509_STORE_add_crl(ctx->store_ctx, itmp->crl); | ||
| 269 | count++; | ||
| 270 | } | ||
| 271 | } | ||
| 272 | sk_X509_INFO_pop_free(inf, X509_INFO_free); | ||
| 273 | return count; | ||
| 274 | } | ||
| 275 | |||
diff --git a/src/lib/libcrypto/x509/by_mem.c b/src/lib/libcrypto/x509/by_mem.c deleted file mode 100644 index ecab813406..0000000000 --- a/src/lib/libcrypto/x509/by_mem.c +++ /dev/null | |||
| @@ -1,138 +0,0 @@ | |||
| 1 | /* $OpenBSD: by_mem.c,v 1.3 2015/02/05 01:33:22 reyk Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <sys/uio.h> | ||
| 60 | #include <errno.h> | ||
| 61 | #include <stdio.h> | ||
| 62 | #include <time.h> | ||
| 63 | #include <unistd.h> | ||
| 64 | |||
| 65 | #include <openssl/buffer.h> | ||
| 66 | #include <openssl/err.h> | ||
| 67 | #include <openssl/pem.h> | ||
| 68 | #include <openssl/lhash.h> | ||
| 69 | #include <openssl/x509.h> | ||
| 70 | |||
| 71 | static int by_mem_ctrl(X509_LOOKUP *, int, const char *, long, char **); | ||
| 72 | |||
| 73 | static X509_LOOKUP_METHOD x509_mem_lookup = { | ||
| 74 | .name = "Load cert from memory", | ||
| 75 | .new_item = NULL, | ||
| 76 | .free = NULL, | ||
| 77 | .init = NULL, | ||
| 78 | .shutdown = NULL, | ||
| 79 | .ctrl = by_mem_ctrl, | ||
| 80 | .get_by_subject = NULL, | ||
| 81 | .get_by_issuer_serial = NULL, | ||
| 82 | .get_by_fingerprint = NULL, | ||
| 83 | .get_by_alias = NULL, | ||
| 84 | }; | ||
| 85 | |||
| 86 | X509_LOOKUP_METHOD * | ||
| 87 | X509_LOOKUP_mem(void) | ||
| 88 | { | ||
| 89 | return (&x509_mem_lookup); | ||
| 90 | } | ||
| 91 | |||
| 92 | static int | ||
| 93 | by_mem_ctrl(X509_LOOKUP *lu, int cmd, const char *buf, | ||
| 94 | long type, char **ret) | ||
| 95 | { | ||
| 96 | STACK_OF(X509_INFO) *inf = NULL; | ||
| 97 | const struct iovec *iov; | ||
| 98 | X509_INFO *itmp; | ||
| 99 | BIO *in = NULL; | ||
| 100 | int i, count = 0, ok = 0; | ||
| 101 | |||
| 102 | iov = (const struct iovec *)buf; | ||
| 103 | |||
| 104 | if (!(cmd == X509_L_MEM && type == X509_FILETYPE_PEM)) | ||
| 105 | goto done; | ||
| 106 | |||
| 107 | if ((in = BIO_new_mem_buf(iov->iov_base, iov->iov_len)) == NULL) | ||
| 108 | goto done; | ||
| 109 | |||
| 110 | if ((inf = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL)) == NULL) | ||
| 111 | goto done; | ||
| 112 | |||
| 113 | for (i = 0; i < sk_X509_INFO_num(inf); i++) { | ||
| 114 | itmp = sk_X509_INFO_value(inf, i); | ||
| 115 | if (itmp->x509) { | ||
| 116 | ok = X509_STORE_add_cert(lu->store_ctx, itmp->x509); | ||
| 117 | if (!ok) | ||
| 118 | goto done; | ||
| 119 | count++; | ||
| 120 | } | ||
| 121 | if (itmp->crl) { | ||
| 122 | ok = X509_STORE_add_crl(lu->store_ctx, itmp->crl); | ||
| 123 | if (!ok) | ||
| 124 | goto done; | ||
| 125 | count++; | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | ok = count != 0; | ||
| 130 | done: | ||
| 131 | if (count == 0) | ||
| 132 | X509err(X509_F_X509_LOAD_CERT_CRL_FILE,ERR_R_PEM_LIB); | ||
| 133 | if (inf != NULL) | ||
| 134 | sk_X509_INFO_pop_free(inf, X509_INFO_free); | ||
| 135 | if (in != NULL) | ||
| 136 | BIO_free(in); | ||
| 137 | return (ok); | ||
| 138 | } | ||
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h deleted file mode 100644 index cf00ea5ebe..0000000000 --- a/src/lib/libcrypto/x509/x509.h +++ /dev/null | |||
| @@ -1,1270 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509.h,v 1.23 2015/04/12 15:15:51 doug Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | /* ==================================================================== | ||
| 59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
| 60 | * ECDH support in OpenSSL originally developed by | ||
| 61 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
| 62 | */ | ||
| 63 | |||
| 64 | #ifndef HEADER_X509_H | ||
| 65 | #define HEADER_X509_H | ||
| 66 | |||
| 67 | #include <openssl/opensslconf.h> | ||
| 68 | |||
| 69 | #ifndef OPENSSL_NO_BUFFER | ||
| 70 | #include <openssl/buffer.h> | ||
| 71 | #endif | ||
| 72 | #ifndef OPENSSL_NO_EVP | ||
| 73 | #include <openssl/evp.h> | ||
| 74 | #endif | ||
| 75 | #ifndef OPENSSL_NO_BIO | ||
| 76 | #include <openssl/bio.h> | ||
| 77 | #endif | ||
| 78 | #include <openssl/stack.h> | ||
| 79 | #include <openssl/asn1.h> | ||
| 80 | #include <openssl/safestack.h> | ||
| 81 | |||
| 82 | #ifndef OPENSSL_NO_EC | ||
| 83 | #include <openssl/ec.h> | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #ifndef OPENSSL_NO_ECDSA | ||
| 87 | #include <openssl/ecdsa.h> | ||
| 88 | #endif | ||
| 89 | |||
| 90 | #ifndef OPENSSL_NO_ECDH | ||
| 91 | #include <openssl/ecdh.h> | ||
| 92 | #endif | ||
| 93 | |||
| 94 | #ifndef OPENSSL_NO_DEPRECATED | ||
| 95 | #ifndef OPENSSL_NO_RSA | ||
| 96 | #include <openssl/rsa.h> | ||
| 97 | #endif | ||
| 98 | #ifndef OPENSSL_NO_DSA | ||
| 99 | #include <openssl/dsa.h> | ||
| 100 | #endif | ||
| 101 | #ifndef OPENSSL_NO_DH | ||
| 102 | #include <openssl/dh.h> | ||
| 103 | #endif | ||
| 104 | #endif | ||
| 105 | |||
| 106 | #ifndef OPENSSL_NO_SHA | ||
| 107 | #include <openssl/sha.h> | ||
| 108 | #endif | ||
| 109 | #include <openssl/ossl_typ.h> | ||
| 110 | |||
| 111 | #ifdef __cplusplus | ||
| 112 | extern "C" { | ||
| 113 | #endif | ||
| 114 | |||
| 115 | #define X509_FILETYPE_PEM 1 | ||
| 116 | #define X509_FILETYPE_ASN1 2 | ||
| 117 | #define X509_FILETYPE_DEFAULT 3 | ||
| 118 | |||
| 119 | #define X509v3_KU_DIGITAL_SIGNATURE 0x0080 | ||
| 120 | #define X509v3_KU_NON_REPUDIATION 0x0040 | ||
| 121 | #define X509v3_KU_KEY_ENCIPHERMENT 0x0020 | ||
| 122 | #define X509v3_KU_DATA_ENCIPHERMENT 0x0010 | ||
| 123 | #define X509v3_KU_KEY_AGREEMENT 0x0008 | ||
| 124 | #define X509v3_KU_KEY_CERT_SIGN 0x0004 | ||
| 125 | #define X509v3_KU_CRL_SIGN 0x0002 | ||
| 126 | #define X509v3_KU_ENCIPHER_ONLY 0x0001 | ||
| 127 | #define X509v3_KU_DECIPHER_ONLY 0x8000 | ||
| 128 | #define X509v3_KU_UNDEF 0xffff | ||
| 129 | |||
| 130 | typedef struct X509_objects_st | ||
| 131 | { | ||
| 132 | int nid; | ||
| 133 | int (*a2i)(void); | ||
| 134 | int (*i2a)(void); | ||
| 135 | } X509_OBJECTS; | ||
| 136 | |||
| 137 | struct X509_algor_st | ||
| 138 | { | ||
| 139 | ASN1_OBJECT *algorithm; | ||
| 140 | ASN1_TYPE *parameter; | ||
| 141 | } /* X509_ALGOR */; | ||
| 142 | |||
| 143 | DECLARE_ASN1_SET_OF(X509_ALGOR) | ||
| 144 | |||
| 145 | typedef STACK_OF(X509_ALGOR) X509_ALGORS; | ||
| 146 | |||
| 147 | typedef struct X509_val_st | ||
| 148 | { | ||
| 149 | ASN1_TIME *notBefore; | ||
| 150 | ASN1_TIME *notAfter; | ||
| 151 | } X509_VAL; | ||
| 152 | |||
| 153 | struct X509_pubkey_st | ||
| 154 | { | ||
| 155 | X509_ALGOR *algor; | ||
| 156 | ASN1_BIT_STRING *public_key; | ||
| 157 | EVP_PKEY *pkey; | ||
| 158 | }; | ||
| 159 | |||
| 160 | typedef struct X509_sig_st | ||
| 161 | { | ||
| 162 | X509_ALGOR *algor; | ||
| 163 | ASN1_OCTET_STRING *digest; | ||
| 164 | } X509_SIG; | ||
| 165 | |||
| 166 | typedef struct X509_name_entry_st | ||
| 167 | { | ||
| 168 | ASN1_OBJECT *object; | ||
| 169 | ASN1_STRING *value; | ||
| 170 | int set; | ||
| 171 | int size; /* temp variable */ | ||
| 172 | } X509_NAME_ENTRY; | ||
| 173 | |||
| 174 | DECLARE_STACK_OF(X509_NAME_ENTRY) | ||
| 175 | DECLARE_ASN1_SET_OF(X509_NAME_ENTRY) | ||
| 176 | |||
| 177 | /* we always keep X509_NAMEs in 2 forms. */ | ||
| 178 | struct X509_name_st | ||
| 179 | { | ||
| 180 | STACK_OF(X509_NAME_ENTRY) *entries; | ||
| 181 | int modified; /* true if 'bytes' needs to be built */ | ||
| 182 | #ifndef OPENSSL_NO_BUFFER | ||
| 183 | BUF_MEM *bytes; | ||
| 184 | #else | ||
| 185 | char *bytes; | ||
| 186 | #endif | ||
| 187 | /* unsigned long hash; Keep the hash around for lookups */ | ||
| 188 | unsigned char *canon_enc; | ||
| 189 | int canon_enclen; | ||
| 190 | } /* X509_NAME */; | ||
| 191 | |||
| 192 | DECLARE_STACK_OF(X509_NAME) | ||
| 193 | |||
| 194 | #define X509_EX_V_NETSCAPE_HACK 0x8000 | ||
| 195 | #define X509_EX_V_INIT 0x0001 | ||
| 196 | typedef struct X509_extension_st | ||
| 197 | { | ||
| 198 | ASN1_OBJECT *object; | ||
| 199 | ASN1_BOOLEAN critical; | ||
| 200 | ASN1_OCTET_STRING *value; | ||
| 201 | } X509_EXTENSION; | ||
| 202 | |||
| 203 | typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS; | ||
| 204 | |||
| 205 | DECLARE_STACK_OF(X509_EXTENSION) | ||
| 206 | DECLARE_ASN1_SET_OF(X509_EXTENSION) | ||
| 207 | |||
| 208 | /* a sequence of these are used */ | ||
| 209 | typedef struct x509_attributes_st | ||
| 210 | { | ||
| 211 | ASN1_OBJECT *object; | ||
| 212 | int single; /* 0 for a set, 1 for a single item (which is wrong) */ | ||
| 213 | union { | ||
| 214 | char *ptr; | ||
| 215 | /* 0 */ STACK_OF(ASN1_TYPE) *set; | ||
| 216 | /* 1 */ ASN1_TYPE *single; | ||
| 217 | } value; | ||
| 218 | } X509_ATTRIBUTE; | ||
| 219 | |||
| 220 | DECLARE_STACK_OF(X509_ATTRIBUTE) | ||
| 221 | DECLARE_ASN1_SET_OF(X509_ATTRIBUTE) | ||
| 222 | |||
| 223 | |||
| 224 | typedef struct X509_req_info_st | ||
| 225 | { | ||
| 226 | ASN1_ENCODING enc; | ||
| 227 | ASN1_INTEGER *version; | ||
| 228 | X509_NAME *subject; | ||
| 229 | X509_PUBKEY *pubkey; | ||
| 230 | /* d=2 hl=2 l= 0 cons: cont: 00 */ | ||
| 231 | STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ | ||
| 232 | } X509_REQ_INFO; | ||
| 233 | |||
| 234 | typedef struct X509_req_st | ||
| 235 | { | ||
| 236 | X509_REQ_INFO *req_info; | ||
| 237 | X509_ALGOR *sig_alg; | ||
| 238 | ASN1_BIT_STRING *signature; | ||
| 239 | int references; | ||
| 240 | } X509_REQ; | ||
| 241 | |||
| 242 | typedef struct x509_cinf_st | ||
| 243 | { | ||
| 244 | ASN1_INTEGER *version; /* [ 0 ] default of v1 */ | ||
| 245 | ASN1_INTEGER *serialNumber; | ||
| 246 | X509_ALGOR *signature; | ||
| 247 | X509_NAME *issuer; | ||
| 248 | X509_VAL *validity; | ||
| 249 | X509_NAME *subject; | ||
| 250 | X509_PUBKEY *key; | ||
| 251 | ASN1_BIT_STRING *issuerUID; /* [ 1 ] optional in v2 */ | ||
| 252 | ASN1_BIT_STRING *subjectUID; /* [ 2 ] optional in v2 */ | ||
| 253 | STACK_OF(X509_EXTENSION) *extensions; /* [ 3 ] optional in v3 */ | ||
| 254 | ASN1_ENCODING enc; | ||
| 255 | } X509_CINF; | ||
| 256 | |||
| 257 | /* This stuff is certificate "auxiliary info" | ||
| 258 | * it contains details which are useful in certificate | ||
| 259 | * stores and databases. When used this is tagged onto | ||
| 260 | * the end of the certificate itself | ||
| 261 | */ | ||
| 262 | |||
| 263 | typedef struct x509_cert_aux_st | ||
| 264 | { | ||
| 265 | STACK_OF(ASN1_OBJECT) *trust; /* trusted uses */ | ||
| 266 | STACK_OF(ASN1_OBJECT) *reject; /* rejected uses */ | ||
| 267 | ASN1_UTF8STRING *alias; /* "friendly name" */ | ||
| 268 | ASN1_OCTET_STRING *keyid; /* key id of private key */ | ||
| 269 | STACK_OF(X509_ALGOR) *other; /* other unspecified info */ | ||
| 270 | } X509_CERT_AUX; | ||
| 271 | |||
| 272 | struct x509_st | ||
| 273 | { | ||
| 274 | X509_CINF *cert_info; | ||
| 275 | X509_ALGOR *sig_alg; | ||
| 276 | ASN1_BIT_STRING *signature; | ||
| 277 | int valid; | ||
| 278 | int references; | ||
| 279 | char *name; | ||
| 280 | CRYPTO_EX_DATA ex_data; | ||
| 281 | /* These contain copies of various extension values */ | ||
| 282 | long ex_pathlen; | ||
| 283 | long ex_pcpathlen; | ||
| 284 | unsigned long ex_flags; | ||
| 285 | unsigned long ex_kusage; | ||
| 286 | unsigned long ex_xkusage; | ||
| 287 | unsigned long ex_nscert; | ||
| 288 | ASN1_OCTET_STRING *skid; | ||
| 289 | AUTHORITY_KEYID *akid; | ||
| 290 | X509_POLICY_CACHE *policy_cache; | ||
| 291 | STACK_OF(DIST_POINT) *crldp; | ||
| 292 | STACK_OF(GENERAL_NAME) *altname; | ||
| 293 | NAME_CONSTRAINTS *nc; | ||
| 294 | #ifndef OPENSSL_NO_SHA | ||
| 295 | unsigned char sha1_hash[SHA_DIGEST_LENGTH]; | ||
| 296 | #endif | ||
| 297 | X509_CERT_AUX *aux; | ||
| 298 | } /* X509 */; | ||
| 299 | |||
| 300 | DECLARE_STACK_OF(X509) | ||
| 301 | DECLARE_ASN1_SET_OF(X509) | ||
| 302 | |||
| 303 | /* This is used for a table of trust checking functions */ | ||
| 304 | |||
| 305 | typedef struct x509_trust_st { | ||
| 306 | int trust; | ||
| 307 | int flags; | ||
| 308 | int (*check_trust)(struct x509_trust_st *, X509 *, int); | ||
| 309 | char *name; | ||
| 310 | int arg1; | ||
| 311 | void *arg2; | ||
| 312 | } X509_TRUST; | ||
| 313 | |||
| 314 | DECLARE_STACK_OF(X509_TRUST) | ||
| 315 | |||
| 316 | typedef struct x509_cert_pair_st { | ||
| 317 | X509 *forward; | ||
| 318 | X509 *reverse; | ||
| 319 | } X509_CERT_PAIR; | ||
| 320 | |||
| 321 | /* standard trust ids */ | ||
| 322 | |||
| 323 | #define X509_TRUST_DEFAULT -1 /* Only valid in purpose settings */ | ||
| 324 | |||
| 325 | #define X509_TRUST_COMPAT 1 | ||
| 326 | #define X509_TRUST_SSL_CLIENT 2 | ||
| 327 | #define X509_TRUST_SSL_SERVER 3 | ||
| 328 | #define X509_TRUST_EMAIL 4 | ||
| 329 | #define X509_TRUST_OBJECT_SIGN 5 | ||
| 330 | #define X509_TRUST_OCSP_SIGN 6 | ||
| 331 | #define X509_TRUST_OCSP_REQUEST 7 | ||
| 332 | #define X509_TRUST_TSA 8 | ||
| 333 | |||
| 334 | /* Keep these up to date! */ | ||
| 335 | #define X509_TRUST_MIN 1 | ||
| 336 | #define X509_TRUST_MAX 8 | ||
| 337 | |||
| 338 | |||
| 339 | /* trust_flags values */ | ||
| 340 | #define X509_TRUST_DYNAMIC 1 | ||
| 341 | #define X509_TRUST_DYNAMIC_NAME 2 | ||
| 342 | |||
| 343 | /* check_trust return codes */ | ||
| 344 | |||
| 345 | #define X509_TRUST_TRUSTED 1 | ||
| 346 | #define X509_TRUST_REJECTED 2 | ||
| 347 | #define X509_TRUST_UNTRUSTED 3 | ||
| 348 | |||
| 349 | /* Flags for X509_print_ex() */ | ||
| 350 | |||
| 351 | #define X509_FLAG_COMPAT 0 | ||
| 352 | #define X509_FLAG_NO_HEADER 1L | ||
| 353 | #define X509_FLAG_NO_VERSION (1L << 1) | ||
| 354 | #define X509_FLAG_NO_SERIAL (1L << 2) | ||
| 355 | #define X509_FLAG_NO_SIGNAME (1L << 3) | ||
| 356 | #define X509_FLAG_NO_ISSUER (1L << 4) | ||
| 357 | #define X509_FLAG_NO_VALIDITY (1L << 5) | ||
| 358 | #define X509_FLAG_NO_SUBJECT (1L << 6) | ||
| 359 | #define X509_FLAG_NO_PUBKEY (1L << 7) | ||
| 360 | #define X509_FLAG_NO_EXTENSIONS (1L << 8) | ||
| 361 | #define X509_FLAG_NO_SIGDUMP (1L << 9) | ||
| 362 | #define X509_FLAG_NO_AUX (1L << 10) | ||
| 363 | #define X509_FLAG_NO_ATTRIBUTES (1L << 11) | ||
| 364 | |||
| 365 | /* Flags specific to X509_NAME_print_ex() */ | ||
| 366 | |||
| 367 | /* The field separator information */ | ||
| 368 | |||
| 369 | #define XN_FLAG_SEP_MASK (0xf << 16) | ||
| 370 | |||
| 371 | #define XN_FLAG_COMPAT 0 /* Traditional SSLeay: use old X509_NAME_print */ | ||
| 372 | #define XN_FLAG_SEP_COMMA_PLUS (1 << 16) /* RFC2253 ,+ */ | ||
| 373 | #define XN_FLAG_SEP_CPLUS_SPC (2 << 16) /* ,+ spaced: more readable */ | ||
| 374 | #define XN_FLAG_SEP_SPLUS_SPC (3 << 16) /* ;+ spaced */ | ||
| 375 | #define XN_FLAG_SEP_MULTILINE (4 << 16) /* One line per field */ | ||
| 376 | |||
| 377 | #define XN_FLAG_DN_REV (1 << 20) /* Reverse DN order */ | ||
| 378 | |||
| 379 | /* How the field name is shown */ | ||
| 380 | |||
| 381 | #define XN_FLAG_FN_MASK (0x3 << 21) | ||
| 382 | |||
| 383 | #define XN_FLAG_FN_SN 0 /* Object short name */ | ||
| 384 | #define XN_FLAG_FN_LN (1 << 21) /* Object long name */ | ||
| 385 | #define XN_FLAG_FN_OID (2 << 21) /* Always use OIDs */ | ||
| 386 | #define XN_FLAG_FN_NONE (3 << 21) /* No field names */ | ||
| 387 | |||
| 388 | #define XN_FLAG_SPC_EQ (1 << 23) /* Put spaces round '=' */ | ||
| 389 | |||
| 390 | /* This determines if we dump fields we don't recognise: | ||
| 391 | * RFC2253 requires this. | ||
| 392 | */ | ||
| 393 | |||
| 394 | #define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24) | ||
| 395 | |||
| 396 | #define XN_FLAG_FN_ALIGN (1 << 25) /* Align field names to 20 characters */ | ||
| 397 | |||
| 398 | /* Complete set of RFC2253 flags */ | ||
| 399 | |||
| 400 | #define XN_FLAG_RFC2253 (ASN1_STRFLGS_RFC2253 | \ | ||
| 401 | XN_FLAG_SEP_COMMA_PLUS | \ | ||
| 402 | XN_FLAG_DN_REV | \ | ||
| 403 | XN_FLAG_FN_SN | \ | ||
| 404 | XN_FLAG_DUMP_UNKNOWN_FIELDS) | ||
| 405 | |||
| 406 | /* readable oneline form */ | ||
| 407 | |||
| 408 | #define XN_FLAG_ONELINE (ASN1_STRFLGS_RFC2253 | \ | ||
| 409 | ASN1_STRFLGS_ESC_QUOTE | \ | ||
| 410 | XN_FLAG_SEP_CPLUS_SPC | \ | ||
| 411 | XN_FLAG_SPC_EQ | \ | ||
| 412 | XN_FLAG_FN_SN) | ||
| 413 | |||
| 414 | /* readable multiline form */ | ||
| 415 | |||
| 416 | #define XN_FLAG_MULTILINE (ASN1_STRFLGS_ESC_CTRL | \ | ||
| 417 | ASN1_STRFLGS_ESC_MSB | \ | ||
| 418 | XN_FLAG_SEP_MULTILINE | \ | ||
| 419 | XN_FLAG_SPC_EQ | \ | ||
| 420 | XN_FLAG_FN_LN | \ | ||
| 421 | XN_FLAG_FN_ALIGN) | ||
| 422 | |||
| 423 | struct x509_revoked_st | ||
| 424 | { | ||
| 425 | ASN1_INTEGER *serialNumber; | ||
| 426 | ASN1_TIME *revocationDate; | ||
| 427 | STACK_OF(X509_EXTENSION) /* optional */ *extensions; | ||
| 428 | /* Set up if indirect CRL */ | ||
| 429 | STACK_OF(GENERAL_NAME) *issuer; | ||
| 430 | /* Revocation reason */ | ||
| 431 | int reason; | ||
| 432 | int sequence; /* load sequence */ | ||
| 433 | }; | ||
| 434 | |||
| 435 | DECLARE_STACK_OF(X509_REVOKED) | ||
| 436 | DECLARE_ASN1_SET_OF(X509_REVOKED) | ||
| 437 | |||
| 438 | typedef struct X509_crl_info_st | ||
| 439 | { | ||
| 440 | ASN1_INTEGER *version; | ||
| 441 | X509_ALGOR *sig_alg; | ||
| 442 | X509_NAME *issuer; | ||
| 443 | ASN1_TIME *lastUpdate; | ||
| 444 | ASN1_TIME *nextUpdate; | ||
| 445 | STACK_OF(X509_REVOKED) *revoked; | ||
| 446 | STACK_OF(X509_EXTENSION) /* [0] */ *extensions; | ||
| 447 | ASN1_ENCODING enc; | ||
| 448 | } X509_CRL_INFO; | ||
| 449 | |||
| 450 | struct X509_crl_st | ||
| 451 | { | ||
| 452 | /* actual signature */ | ||
| 453 | X509_CRL_INFO *crl; | ||
| 454 | X509_ALGOR *sig_alg; | ||
| 455 | ASN1_BIT_STRING *signature; | ||
| 456 | int references; | ||
| 457 | int flags; | ||
| 458 | /* Copies of various extensions */ | ||
| 459 | AUTHORITY_KEYID *akid; | ||
| 460 | ISSUING_DIST_POINT *idp; | ||
| 461 | /* Convenient breakdown of IDP */ | ||
| 462 | int idp_flags; | ||
| 463 | int idp_reasons; | ||
| 464 | /* CRL and base CRL numbers for delta processing */ | ||
| 465 | ASN1_INTEGER *crl_number; | ||
| 466 | ASN1_INTEGER *base_crl_number; | ||
| 467 | #ifndef OPENSSL_NO_SHA | ||
| 468 | unsigned char sha1_hash[SHA_DIGEST_LENGTH]; | ||
| 469 | #endif | ||
| 470 | STACK_OF(GENERAL_NAMES) *issuers; | ||
| 471 | const X509_CRL_METHOD *meth; | ||
| 472 | void *meth_data; | ||
| 473 | } /* X509_CRL */; | ||
| 474 | |||
| 475 | DECLARE_STACK_OF(X509_CRL) | ||
| 476 | DECLARE_ASN1_SET_OF(X509_CRL) | ||
| 477 | |||
| 478 | typedef struct private_key_st | ||
| 479 | { | ||
| 480 | int version; | ||
| 481 | /* The PKCS#8 data types */ | ||
| 482 | X509_ALGOR *enc_algor; | ||
| 483 | ASN1_OCTET_STRING *enc_pkey; /* encrypted pub key */ | ||
| 484 | |||
| 485 | /* When decrypted, the following will not be NULL */ | ||
| 486 | EVP_PKEY *dec_pkey; | ||
| 487 | |||
| 488 | /* used to encrypt and decrypt */ | ||
| 489 | int key_length; | ||
| 490 | char *key_data; | ||
| 491 | int key_free; /* true if we should auto free key_data */ | ||
| 492 | |||
| 493 | /* expanded version of 'enc_algor' */ | ||
| 494 | EVP_CIPHER_INFO cipher; | ||
| 495 | |||
| 496 | int references; | ||
| 497 | } X509_PKEY; | ||
| 498 | |||
| 499 | #ifndef OPENSSL_NO_EVP | ||
| 500 | typedef struct X509_info_st | ||
| 501 | { | ||
| 502 | X509 *x509; | ||
| 503 | X509_CRL *crl; | ||
| 504 | X509_PKEY *x_pkey; | ||
| 505 | |||
| 506 | EVP_CIPHER_INFO enc_cipher; | ||
| 507 | int enc_len; | ||
| 508 | char *enc_data; | ||
| 509 | |||
| 510 | int references; | ||
| 511 | } X509_INFO; | ||
| 512 | |||
| 513 | DECLARE_STACK_OF(X509_INFO) | ||
| 514 | #endif | ||
| 515 | |||
| 516 | /* The next 2 structures and their 8 routines were sent to me by | ||
| 517 | * Pat Richard <patr@x509.com> and are used to manipulate | ||
| 518 | * Netscapes spki structures - useful if you are writing a CA web page | ||
| 519 | */ | ||
| 520 | typedef struct Netscape_spkac_st | ||
| 521 | { | ||
| 522 | X509_PUBKEY *pubkey; | ||
| 523 | ASN1_IA5STRING *challenge; /* challenge sent in atlas >= PR2 */ | ||
| 524 | } NETSCAPE_SPKAC; | ||
| 525 | |||
| 526 | typedef struct Netscape_spki_st | ||
| 527 | { | ||
| 528 | NETSCAPE_SPKAC *spkac; /* signed public key and challenge */ | ||
| 529 | X509_ALGOR *sig_algor; | ||
| 530 | ASN1_BIT_STRING *signature; | ||
| 531 | } NETSCAPE_SPKI; | ||
| 532 | |||
| 533 | /* Netscape certificate sequence structure */ | ||
| 534 | typedef struct Netscape_certificate_sequence | ||
| 535 | { | ||
| 536 | ASN1_OBJECT *type; | ||
| 537 | STACK_OF(X509) *certs; | ||
| 538 | } NETSCAPE_CERT_SEQUENCE; | ||
| 539 | |||
| 540 | /* Unused (and iv length is wrong) | ||
| 541 | typedef struct CBCParameter_st | ||
| 542 | { | ||
| 543 | unsigned char iv[8]; | ||
| 544 | } CBC_PARAM; | ||
| 545 | */ | ||
| 546 | |||
| 547 | /* Password based encryption structure */ | ||
| 548 | |||
| 549 | typedef struct PBEPARAM_st { | ||
| 550 | ASN1_OCTET_STRING *salt; | ||
| 551 | ASN1_INTEGER *iter; | ||
| 552 | } PBEPARAM; | ||
| 553 | |||
| 554 | /* Password based encryption V2 structures */ | ||
| 555 | |||
| 556 | typedef struct PBE2PARAM_st { | ||
| 557 | X509_ALGOR *keyfunc; | ||
| 558 | X509_ALGOR *encryption; | ||
| 559 | } PBE2PARAM; | ||
| 560 | |||
| 561 | typedef struct PBKDF2PARAM_st { | ||
| 562 | ASN1_TYPE *salt; /* Usually OCTET STRING but could be anything */ | ||
| 563 | ASN1_INTEGER *iter; | ||
| 564 | ASN1_INTEGER *keylength; | ||
| 565 | X509_ALGOR *prf; | ||
| 566 | } PBKDF2PARAM; | ||
| 567 | |||
| 568 | |||
| 569 | /* PKCS#8 private key info structure */ | ||
| 570 | |||
| 571 | struct pkcs8_priv_key_info_st | ||
| 572 | { | ||
| 573 | int broken; /* Flag for various broken formats */ | ||
| 574 | #define PKCS8_OK 0 | ||
| 575 | #define PKCS8_NO_OCTET 1 | ||
| 576 | #define PKCS8_EMBEDDED_PARAM 2 | ||
| 577 | #define PKCS8_NS_DB 3 | ||
| 578 | #define PKCS8_NEG_PRIVKEY 4 | ||
| 579 | ASN1_INTEGER *version; | ||
| 580 | X509_ALGOR *pkeyalg; | ||
| 581 | ASN1_TYPE *pkey; /* Should be OCTET STRING but some are broken */ | ||
| 582 | STACK_OF(X509_ATTRIBUTE) *attributes; | ||
| 583 | }; | ||
| 584 | |||
| 585 | #ifdef __cplusplus | ||
| 586 | } | ||
| 587 | #endif | ||
| 588 | |||
| 589 | #include <openssl/x509_vfy.h> | ||
| 590 | #include <openssl/pkcs7.h> | ||
| 591 | |||
| 592 | #ifdef __cplusplus | ||
| 593 | extern "C" { | ||
| 594 | #endif | ||
| 595 | |||
| 596 | #define X509_EXT_PACK_UNKNOWN 1 | ||
| 597 | #define X509_EXT_PACK_STRING 2 | ||
| 598 | |||
| 599 | #define X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version) | ||
| 600 | /* #define X509_get_serialNumber(x) ((x)->cert_info->serialNumber) */ | ||
| 601 | #define X509_get_notBefore(x) ((x)->cert_info->validity->notBefore) | ||
| 602 | #define X509_get_notAfter(x) ((x)->cert_info->validity->notAfter) | ||
| 603 | #define X509_extract_key(x) X509_get_pubkey(x) /*****/ | ||
| 604 | #define X509_REQ_get_version(x) ASN1_INTEGER_get((x)->req_info->version) | ||
| 605 | #define X509_REQ_get_subject_name(x) ((x)->req_info->subject) | ||
| 606 | #define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a) | ||
| 607 | #define X509_name_cmp(a,b) X509_NAME_cmp((a),(b)) | ||
| 608 | #define X509_get_signature_type(x) EVP_PKEY_type(OBJ_obj2nid((x)->sig_alg->algorithm)) | ||
| 609 | |||
| 610 | #define X509_CRL_get_version(x) ASN1_INTEGER_get((x)->crl->version) | ||
| 611 | #define X509_CRL_get_lastUpdate(x) ((x)->crl->lastUpdate) | ||
| 612 | #define X509_CRL_get_nextUpdate(x) ((x)->crl->nextUpdate) | ||
| 613 | #define X509_CRL_get_issuer(x) ((x)->crl->issuer) | ||
| 614 | #define X509_CRL_get_REVOKED(x) ((x)->crl->revoked) | ||
| 615 | |||
| 616 | void X509_CRL_set_default_method(const X509_CRL_METHOD *meth); | ||
| 617 | X509_CRL_METHOD *X509_CRL_METHOD_new( | ||
| 618 | int (*crl_init)(X509_CRL *crl), | ||
| 619 | int (*crl_free)(X509_CRL *crl), | ||
| 620 | int (*crl_lookup)(X509_CRL *crl, X509_REVOKED **ret, | ||
| 621 | ASN1_INTEGER *ser, X509_NAME *issuer), | ||
| 622 | int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk)); | ||
| 623 | void X509_CRL_METHOD_free(X509_CRL_METHOD *m); | ||
| 624 | |||
| 625 | void X509_CRL_set_meth_data(X509_CRL *crl, void *dat); | ||
| 626 | void *X509_CRL_get_meth_data(X509_CRL *crl); | ||
| 627 | |||
| 628 | /* This one is only used so that a binary form can output, as in | ||
| 629 | * i2d_X509_NAME(X509_get_X509_PUBKEY(x),&buf) */ | ||
| 630 | #define X509_get_X509_PUBKEY(x) ((x)->cert_info->key) | ||
| 631 | |||
| 632 | |||
| 633 | const char *X509_verify_cert_error_string(long n); | ||
| 634 | |||
| 635 | #ifndef OPENSSL_NO_EVP | ||
| 636 | int X509_verify(X509 *a, EVP_PKEY *r); | ||
| 637 | |||
| 638 | int X509_REQ_verify(X509_REQ *a, EVP_PKEY *r); | ||
| 639 | int X509_CRL_verify(X509_CRL *a, EVP_PKEY *r); | ||
| 640 | int NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r); | ||
| 641 | |||
| 642 | NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len); | ||
| 643 | char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *x); | ||
| 644 | EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x); | ||
| 645 | int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey); | ||
| 646 | |||
| 647 | int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki); | ||
| 648 | |||
| 649 | int X509_signature_dump(BIO *bp,const ASN1_STRING *sig, int indent); | ||
| 650 | int X509_signature_print(BIO *bp,X509_ALGOR *alg, ASN1_STRING *sig); | ||
| 651 | |||
| 652 | int X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); | ||
| 653 | int X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx); | ||
| 654 | int X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md); | ||
| 655 | int X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx); | ||
| 656 | int X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md); | ||
| 657 | int X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx); | ||
| 658 | int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md); | ||
| 659 | |||
| 660 | int X509_pubkey_digest(const X509 *data,const EVP_MD *type, | ||
| 661 | unsigned char *md, unsigned int *len); | ||
| 662 | int X509_digest(const X509 *data,const EVP_MD *type, | ||
| 663 | unsigned char *md, unsigned int *len); | ||
| 664 | int X509_CRL_digest(const X509_CRL *data,const EVP_MD *type, | ||
| 665 | unsigned char *md, unsigned int *len); | ||
| 666 | int X509_REQ_digest(const X509_REQ *data,const EVP_MD *type, | ||
| 667 | unsigned char *md, unsigned int *len); | ||
| 668 | int X509_NAME_digest(const X509_NAME *data,const EVP_MD *type, | ||
| 669 | unsigned char *md, unsigned int *len); | ||
| 670 | #endif | ||
| 671 | |||
| 672 | X509 *d2i_X509_fp(FILE *fp, X509 **x509); | ||
| 673 | int i2d_X509_fp(FILE *fp,X509 *x509); | ||
| 674 | X509_CRL *d2i_X509_CRL_fp(FILE *fp,X509_CRL **crl); | ||
| 675 | int i2d_X509_CRL_fp(FILE *fp,X509_CRL *crl); | ||
| 676 | X509_REQ *d2i_X509_REQ_fp(FILE *fp,X509_REQ **req); | ||
| 677 | int i2d_X509_REQ_fp(FILE *fp,X509_REQ *req); | ||
| 678 | #ifndef OPENSSL_NO_RSA | ||
| 679 | RSA *d2i_RSAPrivateKey_fp(FILE *fp,RSA **rsa); | ||
| 680 | int i2d_RSAPrivateKey_fp(FILE *fp,RSA *rsa); | ||
| 681 | RSA *d2i_RSAPublicKey_fp(FILE *fp,RSA **rsa); | ||
| 682 | int i2d_RSAPublicKey_fp(FILE *fp,RSA *rsa); | ||
| 683 | RSA *d2i_RSA_PUBKEY_fp(FILE *fp,RSA **rsa); | ||
| 684 | int i2d_RSA_PUBKEY_fp(FILE *fp,RSA *rsa); | ||
| 685 | #endif | ||
| 686 | #ifndef OPENSSL_NO_DSA | ||
| 687 | DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa); | ||
| 688 | int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa); | ||
| 689 | int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); | ||
| 690 | #endif | ||
| 691 | #ifndef OPENSSL_NO_EC | ||
| 692 | EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey); | ||
| 693 | int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey); | ||
| 694 | EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey); | ||
| 695 | int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey); | ||
| 696 | #endif | ||
| 697 | X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8); | ||
| 698 | int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8); | ||
| 699 | PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, | ||
| 700 | PKCS8_PRIV_KEY_INFO **p8inf); | ||
| 701 | int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf); | ||
| 702 | int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key); | ||
| 703 | int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey); | ||
| 704 | EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a); | ||
| 705 | int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey); | ||
| 706 | EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); | ||
| 707 | |||
| 708 | #ifndef OPENSSL_NO_BIO | ||
| 709 | X509 *d2i_X509_bio(BIO *bp,X509 **x509); | ||
| 710 | int i2d_X509_bio(BIO *bp,X509 *x509); | ||
| 711 | X509_CRL *d2i_X509_CRL_bio(BIO *bp,X509_CRL **crl); | ||
| 712 | int i2d_X509_CRL_bio(BIO *bp,X509_CRL *crl); | ||
| 713 | X509_REQ *d2i_X509_REQ_bio(BIO *bp,X509_REQ **req); | ||
| 714 | int i2d_X509_REQ_bio(BIO *bp,X509_REQ *req); | ||
| 715 | #ifndef OPENSSL_NO_RSA | ||
| 716 | RSA *d2i_RSAPrivateKey_bio(BIO *bp,RSA **rsa); | ||
| 717 | int i2d_RSAPrivateKey_bio(BIO *bp,RSA *rsa); | ||
| 718 | RSA *d2i_RSAPublicKey_bio(BIO *bp,RSA **rsa); | ||
| 719 | int i2d_RSAPublicKey_bio(BIO *bp,RSA *rsa); | ||
| 720 | RSA *d2i_RSA_PUBKEY_bio(BIO *bp,RSA **rsa); | ||
| 721 | int i2d_RSA_PUBKEY_bio(BIO *bp,RSA *rsa); | ||
| 722 | #endif | ||
| 723 | #ifndef OPENSSL_NO_DSA | ||
| 724 | DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa); | ||
| 725 | int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa); | ||
| 726 | DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); | ||
| 727 | int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); | ||
| 728 | #endif | ||
| 729 | #ifndef OPENSSL_NO_EC | ||
| 730 | EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey); | ||
| 731 | int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey); | ||
| 732 | EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey); | ||
| 733 | int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey); | ||
| 734 | #endif | ||
| 735 | X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8); | ||
| 736 | int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8); | ||
| 737 | PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, | ||
| 738 | PKCS8_PRIV_KEY_INFO **p8inf); | ||
| 739 | int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf); | ||
| 740 | int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key); | ||
| 741 | int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey); | ||
| 742 | EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a); | ||
| 743 | int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey); | ||
| 744 | EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); | ||
| 745 | #endif | ||
| 746 | |||
| 747 | X509 *X509_dup(X509 *x509); | ||
| 748 | X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa); | ||
| 749 | X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex); | ||
| 750 | X509_CRL *X509_CRL_dup(X509_CRL *crl); | ||
| 751 | X509_REQ *X509_REQ_dup(X509_REQ *req); | ||
| 752 | X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn); | ||
| 753 | int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval); | ||
| 754 | void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval, | ||
| 755 | X509_ALGOR *algor); | ||
| 756 | void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md); | ||
| 757 | int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b); | ||
| 758 | |||
| 759 | X509_NAME *X509_NAME_dup(X509_NAME *xn); | ||
| 760 | X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne); | ||
| 761 | |||
| 762 | int X509_cmp_time(const ASN1_TIME *s, time_t *t); | ||
| 763 | int X509_cmp_current_time(const ASN1_TIME *s); | ||
| 764 | ASN1_TIME * X509_time_adj(ASN1_TIME *s, long adj, time_t *t); | ||
| 765 | ASN1_TIME * X509_time_adj_ex(ASN1_TIME *s, | ||
| 766 | int offset_day, long offset_sec, time_t *t); | ||
| 767 | ASN1_TIME * X509_gmtime_adj(ASN1_TIME *s, long adj); | ||
| 768 | |||
| 769 | const char * X509_get_default_cert_area(void ); | ||
| 770 | const char * X509_get_default_cert_dir(void ); | ||
| 771 | const char * X509_get_default_cert_file(void ); | ||
| 772 | const char * X509_get_default_cert_dir_env(void ); | ||
| 773 | const char * X509_get_default_cert_file_env(void ); | ||
| 774 | const char * X509_get_default_private_dir(void ); | ||
| 775 | |||
| 776 | X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); | ||
| 777 | X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey); | ||
| 778 | |||
| 779 | DECLARE_ASN1_FUNCTIONS(X509_ALGOR) | ||
| 780 | DECLARE_ASN1_ENCODE_FUNCTIONS(X509_ALGORS, X509_ALGORS, X509_ALGORS) | ||
| 781 | DECLARE_ASN1_FUNCTIONS(X509_VAL) | ||
| 782 | |||
| 783 | DECLARE_ASN1_FUNCTIONS(X509_PUBKEY) | ||
| 784 | |||
| 785 | int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); | ||
| 786 | EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key); | ||
| 787 | int X509_get_pubkey_parameters(EVP_PKEY *pkey, | ||
| 788 | STACK_OF(X509) *chain); | ||
| 789 | int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp); | ||
| 790 | EVP_PKEY * d2i_PUBKEY(EVP_PKEY **a,const unsigned char **pp, | ||
| 791 | long length); | ||
| 792 | #ifndef OPENSSL_NO_RSA | ||
| 793 | int i2d_RSA_PUBKEY(RSA *a,unsigned char **pp); | ||
| 794 | RSA * d2i_RSA_PUBKEY(RSA **a,const unsigned char **pp, | ||
| 795 | long length); | ||
| 796 | #endif | ||
| 797 | #ifndef OPENSSL_NO_DSA | ||
| 798 | int i2d_DSA_PUBKEY(DSA *a,unsigned char **pp); | ||
| 799 | DSA * d2i_DSA_PUBKEY(DSA **a,const unsigned char **pp, | ||
| 800 | long length); | ||
| 801 | #endif | ||
| 802 | #ifndef OPENSSL_NO_EC | ||
| 803 | int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp); | ||
| 804 | EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, | ||
| 805 | long length); | ||
| 806 | #endif | ||
| 807 | |||
| 808 | DECLARE_ASN1_FUNCTIONS(X509_SIG) | ||
| 809 | DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO) | ||
| 810 | DECLARE_ASN1_FUNCTIONS(X509_REQ) | ||
| 811 | |||
| 812 | DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE) | ||
| 813 | X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value); | ||
| 814 | |||
| 815 | DECLARE_ASN1_FUNCTIONS(X509_EXTENSION) | ||
| 816 | DECLARE_ASN1_ENCODE_FUNCTIONS(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS) | ||
| 817 | |||
| 818 | DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY) | ||
| 819 | |||
| 820 | DECLARE_ASN1_FUNCTIONS(X509_NAME) | ||
| 821 | |||
| 822 | int X509_NAME_set(X509_NAME **xn, X509_NAME *name); | ||
| 823 | |||
| 824 | DECLARE_ASN1_FUNCTIONS(X509_CINF) | ||
| 825 | |||
| 826 | DECLARE_ASN1_FUNCTIONS(X509) | ||
| 827 | DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX) | ||
| 828 | |||
| 829 | DECLARE_ASN1_FUNCTIONS(X509_CERT_PAIR) | ||
| 830 | |||
| 831 | int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 832 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
| 833 | int X509_set_ex_data(X509 *r, int idx, void *arg); | ||
| 834 | void *X509_get_ex_data(X509 *r, int idx); | ||
| 835 | int i2d_X509_AUX(X509 *a,unsigned char **pp); | ||
| 836 | X509 * d2i_X509_AUX(X509 **a,const unsigned char **pp,long length); | ||
| 837 | |||
| 838 | int X509_alias_set1(X509 *x, unsigned char *name, int len); | ||
| 839 | int X509_keyid_set1(X509 *x, unsigned char *id, int len); | ||
| 840 | unsigned char * X509_alias_get0(X509 *x, int *len); | ||
| 841 | unsigned char * X509_keyid_get0(X509 *x, int *len); | ||
| 842 | int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int); | ||
| 843 | int X509_TRUST_set(int *t, int trust); | ||
| 844 | int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj); | ||
| 845 | int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj); | ||
| 846 | void X509_trust_clear(X509 *x); | ||
| 847 | void X509_reject_clear(X509 *x); | ||
| 848 | |||
| 849 | DECLARE_ASN1_FUNCTIONS(X509_REVOKED) | ||
| 850 | DECLARE_ASN1_FUNCTIONS(X509_CRL_INFO) | ||
| 851 | DECLARE_ASN1_FUNCTIONS(X509_CRL) | ||
| 852 | |||
| 853 | int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev); | ||
| 854 | int X509_CRL_get0_by_serial(X509_CRL *crl, | ||
| 855 | X509_REVOKED **ret, ASN1_INTEGER *serial); | ||
| 856 | int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, X509 *x); | ||
| 857 | |||
| 858 | X509_PKEY * X509_PKEY_new(void ); | ||
| 859 | void X509_PKEY_free(X509_PKEY *a); | ||
| 860 | |||
| 861 | DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI) | ||
| 862 | DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC) | ||
| 863 | DECLARE_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE) | ||
| 864 | |||
| 865 | #ifndef OPENSSL_NO_EVP | ||
| 866 | X509_INFO * X509_INFO_new(void); | ||
| 867 | void X509_INFO_free(X509_INFO *a); | ||
| 868 | char * X509_NAME_oneline(X509_NAME *a,char *buf,int size); | ||
| 869 | |||
| 870 | int ASN1_item_digest(const ASN1_ITEM *it,const EVP_MD *type,void *data, | ||
| 871 | unsigned char *md,unsigned int *len); | ||
| 872 | |||
| 873 | int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *algor1, | ||
| 874 | ASN1_BIT_STRING *signature,void *data,EVP_PKEY *pkey); | ||
| 875 | |||
| 876 | int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | ||
| 877 | ASN1_BIT_STRING *signature, | ||
| 878 | void *data, EVP_PKEY *pkey, const EVP_MD *type); | ||
| 879 | int ASN1_item_sign_ctx(const ASN1_ITEM *it, | ||
| 880 | X509_ALGOR *algor1, X509_ALGOR *algor2, | ||
| 881 | ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx); | ||
| 882 | #endif | ||
| 883 | |||
| 884 | int X509_set_version(X509 *x,long version); | ||
| 885 | int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial); | ||
| 886 | ASN1_INTEGER * X509_get_serialNumber(X509 *x); | ||
| 887 | int X509_set_issuer_name(X509 *x, X509_NAME *name); | ||
| 888 | X509_NAME * X509_get_issuer_name(X509 *a); | ||
| 889 | int X509_set_subject_name(X509 *x, X509_NAME *name); | ||
| 890 | X509_NAME * X509_get_subject_name(X509 *a); | ||
| 891 | int X509_set_notBefore(X509 *x, const ASN1_TIME *tm); | ||
| 892 | int X509_set_notAfter(X509 *x, const ASN1_TIME *tm); | ||
| 893 | int X509_set_pubkey(X509 *x, EVP_PKEY *pkey); | ||
| 894 | EVP_PKEY * X509_get_pubkey(X509 *x); | ||
| 895 | ASN1_BIT_STRING * X509_get0_pubkey_bitstr(const X509 *x); | ||
| 896 | int X509_certificate_type(X509 *x,EVP_PKEY *pubkey /* optional */); | ||
| 897 | |||
| 898 | int X509_REQ_set_version(X509_REQ *x,long version); | ||
| 899 | int X509_REQ_set_subject_name(X509_REQ *req,X509_NAME *name); | ||
| 900 | int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey); | ||
| 901 | EVP_PKEY * X509_REQ_get_pubkey(X509_REQ *req); | ||
| 902 | int X509_REQ_extension_nid(int nid); | ||
| 903 | int * X509_REQ_get_extension_nids(void); | ||
| 904 | void X509_REQ_set_extension_nids(int *nids); | ||
| 905 | STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req); | ||
| 906 | int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts, | ||
| 907 | int nid); | ||
| 908 | int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts); | ||
| 909 | int X509_REQ_get_attr_count(const X509_REQ *req); | ||
| 910 | int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid, | ||
| 911 | int lastpos); | ||
| 912 | int X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj, | ||
| 913 | int lastpos); | ||
| 914 | X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc); | ||
| 915 | X509_ATTRIBUTE *X509_REQ_delete_attr(X509_REQ *req, int loc); | ||
| 916 | int X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr); | ||
| 917 | int X509_REQ_add1_attr_by_OBJ(X509_REQ *req, | ||
| 918 | const ASN1_OBJECT *obj, int type, | ||
| 919 | const unsigned char *bytes, int len); | ||
| 920 | int X509_REQ_add1_attr_by_NID(X509_REQ *req, | ||
| 921 | int nid, int type, | ||
| 922 | const unsigned char *bytes, int len); | ||
| 923 | int X509_REQ_add1_attr_by_txt(X509_REQ *req, | ||
| 924 | const char *attrname, int type, | ||
| 925 | const unsigned char *bytes, int len); | ||
| 926 | |||
| 927 | int X509_CRL_set_version(X509_CRL *x, long version); | ||
| 928 | int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name); | ||
| 929 | int X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm); | ||
| 930 | int X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm); | ||
| 931 | int X509_CRL_sort(X509_CRL *crl); | ||
| 932 | |||
| 933 | int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial); | ||
| 934 | int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm); | ||
| 935 | |||
| 936 | int X509_REQ_check_private_key(X509_REQ *x509,EVP_PKEY *pkey); | ||
| 937 | |||
| 938 | int X509_check_private_key(X509 *x509,EVP_PKEY *pkey); | ||
| 939 | |||
| 940 | int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b); | ||
| 941 | unsigned long X509_issuer_and_serial_hash(X509 *a); | ||
| 942 | |||
| 943 | int X509_issuer_name_cmp(const X509 *a, const X509 *b); | ||
| 944 | unsigned long X509_issuer_name_hash(X509 *a); | ||
| 945 | |||
| 946 | int X509_subject_name_cmp(const X509 *a, const X509 *b); | ||
| 947 | unsigned long X509_subject_name_hash(X509 *x); | ||
| 948 | |||
| 949 | #ifndef OPENSSL_NO_MD5 | ||
| 950 | unsigned long X509_issuer_name_hash_old(X509 *a); | ||
| 951 | unsigned long X509_subject_name_hash_old(X509 *x); | ||
| 952 | #endif | ||
| 953 | |||
| 954 | int X509_cmp(const X509 *a, const X509 *b); | ||
| 955 | int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b); | ||
| 956 | unsigned long X509_NAME_hash(X509_NAME *x); | ||
| 957 | unsigned long X509_NAME_hash_old(X509_NAME *x); | ||
| 958 | |||
| 959 | int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b); | ||
| 960 | int X509_CRL_match(const X509_CRL *a, const X509_CRL *b); | ||
| 961 | int X509_print_ex_fp(FILE *bp,X509 *x, unsigned long nmflag, unsigned long cflag); | ||
| 962 | int X509_print_fp(FILE *bp,X509 *x); | ||
| 963 | int X509_CRL_print_fp(FILE *bp,X509_CRL *x); | ||
| 964 | int X509_REQ_print_fp(FILE *bp,X509_REQ *req); | ||
| 965 | int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags); | ||
| 966 | |||
| 967 | #ifndef OPENSSL_NO_BIO | ||
| 968 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase); | ||
| 969 | int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags); | ||
| 970 | int X509_print_ex(BIO *bp,X509 *x, unsigned long nmflag, unsigned long cflag); | ||
| 971 | int X509_print(BIO *bp,X509 *x); | ||
| 972 | int X509_ocspid_print(BIO *bp,X509 *x); | ||
| 973 | int X509_CERT_AUX_print(BIO *bp,X509_CERT_AUX *x, int indent); | ||
| 974 | int X509_CRL_print(BIO *bp,X509_CRL *x); | ||
| 975 | int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, unsigned long cflag); | ||
| 976 | int X509_REQ_print(BIO *bp,X509_REQ *req); | ||
| 977 | #endif | ||
| 978 | |||
| 979 | int X509_NAME_entry_count(X509_NAME *name); | ||
| 980 | int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, | ||
| 981 | char *buf,int len); | ||
| 982 | int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, | ||
| 983 | char *buf,int len); | ||
| 984 | |||
| 985 | /* NOTE: you should be passsing -1, not 0 as lastpos. The functions that use | ||
| 986 | * lastpos, search after that position on. */ | ||
| 987 | int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos); | ||
| 988 | int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj, | ||
| 989 | int lastpos); | ||
| 990 | X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc); | ||
| 991 | X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc); | ||
| 992 | int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, | ||
| 993 | int loc, int set); | ||
| 994 | int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, | ||
| 995 | unsigned char *bytes, int len, int loc, int set); | ||
| 996 | int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, | ||
| 997 | unsigned char *bytes, int len, int loc, int set); | ||
| 998 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, | ||
| 999 | const char *field, int type, const unsigned char *bytes, int len); | ||
| 1000 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, | ||
| 1001 | int type,unsigned char *bytes, int len); | ||
| 1002 | int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, | ||
| 1003 | const unsigned char *bytes, int len, int loc, int set); | ||
| 1004 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, | ||
| 1005 | ASN1_OBJECT *obj, int type,const unsigned char *bytes, | ||
| 1006 | int len); | ||
| 1007 | int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, | ||
| 1008 | ASN1_OBJECT *obj); | ||
| 1009 | int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, | ||
| 1010 | const unsigned char *bytes, int len); | ||
| 1011 | ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne); | ||
| 1012 | ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne); | ||
| 1013 | |||
| 1014 | int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x); | ||
| 1015 | int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, | ||
| 1016 | int nid, int lastpos); | ||
| 1017 | int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x, | ||
| 1018 | ASN1_OBJECT *obj,int lastpos); | ||
| 1019 | int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x, | ||
| 1020 | int crit, int lastpos); | ||
| 1021 | X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc); | ||
| 1022 | X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc); | ||
| 1023 | STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, | ||
| 1024 | X509_EXTENSION *ex, int loc); | ||
| 1025 | |||
| 1026 | int X509_get_ext_count(X509 *x); | ||
| 1027 | int X509_get_ext_by_NID(X509 *x, int nid, int lastpos); | ||
| 1028 | int X509_get_ext_by_OBJ(X509 *x,ASN1_OBJECT *obj,int lastpos); | ||
| 1029 | int X509_get_ext_by_critical(X509 *x, int crit, int lastpos); | ||
| 1030 | X509_EXTENSION *X509_get_ext(X509 *x, int loc); | ||
| 1031 | X509_EXTENSION *X509_delete_ext(X509 *x, int loc); | ||
| 1032 | int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc); | ||
| 1033 | void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx); | ||
| 1034 | int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit, | ||
| 1035 | unsigned long flags); | ||
| 1036 | |||
| 1037 | int X509_CRL_get_ext_count(X509_CRL *x); | ||
| 1038 | int X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos); | ||
| 1039 | int X509_CRL_get_ext_by_OBJ(X509_CRL *x,ASN1_OBJECT *obj,int lastpos); | ||
| 1040 | int X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos); | ||
| 1041 | X509_EXTENSION *X509_CRL_get_ext(X509_CRL *x, int loc); | ||
| 1042 | X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc); | ||
| 1043 | int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc); | ||
| 1044 | void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx); | ||
| 1045 | int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit, | ||
| 1046 | unsigned long flags); | ||
| 1047 | |||
| 1048 | int X509_REVOKED_get_ext_count(X509_REVOKED *x); | ||
| 1049 | int X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos); | ||
| 1050 | int X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x,ASN1_OBJECT *obj,int lastpos); | ||
| 1051 | int X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos); | ||
| 1052 | X509_EXTENSION *X509_REVOKED_get_ext(X509_REVOKED *x, int loc); | ||
| 1053 | X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc); | ||
| 1054 | int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc); | ||
| 1055 | void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx); | ||
| 1056 | int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit, | ||
| 1057 | unsigned long flags); | ||
| 1058 | |||
| 1059 | X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, | ||
| 1060 | int nid, int crit, ASN1_OCTET_STRING *data); | ||
| 1061 | X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, | ||
| 1062 | ASN1_OBJECT *obj,int crit,ASN1_OCTET_STRING *data); | ||
| 1063 | int X509_EXTENSION_set_object(X509_EXTENSION *ex,ASN1_OBJECT *obj); | ||
| 1064 | int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit); | ||
| 1065 | int X509_EXTENSION_set_data(X509_EXTENSION *ex, | ||
| 1066 | ASN1_OCTET_STRING *data); | ||
| 1067 | ASN1_OBJECT * X509_EXTENSION_get_object(X509_EXTENSION *ex); | ||
| 1068 | ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne); | ||
| 1069 | int X509_EXTENSION_get_critical(X509_EXTENSION *ex); | ||
| 1070 | |||
| 1071 | int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x); | ||
| 1072 | int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid, | ||
| 1073 | int lastpos); | ||
| 1074 | int X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj, | ||
| 1075 | int lastpos); | ||
| 1076 | X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc); | ||
| 1077 | X509_ATTRIBUTE *X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc); | ||
| 1078 | STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x, | ||
| 1079 | X509_ATTRIBUTE *attr); | ||
| 1080 | STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x, | ||
| 1081 | const ASN1_OBJECT *obj, int type, | ||
| 1082 | const unsigned char *bytes, int len); | ||
| 1083 | STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x, | ||
| 1084 | int nid, int type, | ||
| 1085 | const unsigned char *bytes, int len); | ||
| 1086 | STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x, | ||
| 1087 | const char *attrname, int type, | ||
| 1088 | const unsigned char *bytes, int len); | ||
| 1089 | void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x, | ||
| 1090 | ASN1_OBJECT *obj, int lastpos, int type); | ||
| 1091 | X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, | ||
| 1092 | int atrtype, const void *data, int len); | ||
| 1093 | X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr, | ||
| 1094 | const ASN1_OBJECT *obj, int atrtype, const void *data, int len); | ||
| 1095 | X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr, | ||
| 1096 | const char *atrname, int type, const unsigned char *bytes, int len); | ||
| 1097 | int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj); | ||
| 1098 | int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len); | ||
| 1099 | void *X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx, | ||
| 1100 | int atrtype, void *data); | ||
| 1101 | int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr); | ||
| 1102 | ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr); | ||
| 1103 | ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx); | ||
| 1104 | |||
| 1105 | int EVP_PKEY_get_attr_count(const EVP_PKEY *key); | ||
| 1106 | int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid, | ||
| 1107 | int lastpos); | ||
| 1108 | int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, ASN1_OBJECT *obj, | ||
| 1109 | int lastpos); | ||
| 1110 | X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc); | ||
| 1111 | X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc); | ||
| 1112 | int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr); | ||
| 1113 | int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key, | ||
| 1114 | const ASN1_OBJECT *obj, int type, | ||
| 1115 | const unsigned char *bytes, int len); | ||
| 1116 | int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key, | ||
| 1117 | int nid, int type, | ||
| 1118 | const unsigned char *bytes, int len); | ||
| 1119 | int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key, | ||
| 1120 | const char *attrname, int type, | ||
| 1121 | const unsigned char *bytes, int len); | ||
| 1122 | |||
| 1123 | int X509_verify_cert(X509_STORE_CTX *ctx); | ||
| 1124 | |||
| 1125 | /* lookup a cert from a X509 STACK */ | ||
| 1126 | X509 *X509_find_by_issuer_and_serial(STACK_OF(X509) *sk,X509_NAME *name, | ||
| 1127 | ASN1_INTEGER *serial); | ||
| 1128 | X509 *X509_find_by_subject(STACK_OF(X509) *sk,X509_NAME *name); | ||
| 1129 | |||
| 1130 | DECLARE_ASN1_FUNCTIONS(PBEPARAM) | ||
| 1131 | DECLARE_ASN1_FUNCTIONS(PBE2PARAM) | ||
| 1132 | DECLARE_ASN1_FUNCTIONS(PBKDF2PARAM) | ||
| 1133 | |||
| 1134 | int PKCS5_pbe_set0_algor(X509_ALGOR *algor, int alg, int iter, | ||
| 1135 | const unsigned char *salt, int saltlen); | ||
| 1136 | |||
| 1137 | X509_ALGOR *PKCS5_pbe_set(int alg, int iter, | ||
| 1138 | const unsigned char *salt, int saltlen); | ||
| 1139 | X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, | ||
| 1140 | unsigned char *salt, int saltlen); | ||
| 1141 | X509_ALGOR *PKCS5_pbe2_set_iv(const EVP_CIPHER *cipher, int iter, | ||
| 1142 | unsigned char *salt, int saltlen, | ||
| 1143 | unsigned char *aiv, int prf_nid); | ||
| 1144 | |||
| 1145 | X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen, | ||
| 1146 | int prf_nid, int keylen); | ||
| 1147 | |||
| 1148 | /* PKCS#8 utilities */ | ||
| 1149 | |||
| 1150 | DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO) | ||
| 1151 | |||
| 1152 | EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8); | ||
| 1153 | PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey); | ||
| 1154 | PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken); | ||
| 1155 | PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken); | ||
| 1156 | |||
| 1157 | int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, | ||
| 1158 | int version, int ptype, void *pval, | ||
| 1159 | unsigned char *penc, int penclen); | ||
| 1160 | int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, | ||
| 1161 | const unsigned char **pk, int *ppklen, | ||
| 1162 | X509_ALGOR **pa, | ||
| 1163 | PKCS8_PRIV_KEY_INFO *p8); | ||
| 1164 | |||
| 1165 | int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj, | ||
| 1166 | int ptype, void *pval, | ||
| 1167 | unsigned char *penc, int penclen); | ||
| 1168 | int X509_PUBKEY_get0_param(ASN1_OBJECT **ppkalg, | ||
| 1169 | const unsigned char **pk, int *ppklen, | ||
| 1170 | X509_ALGOR **pa, | ||
| 1171 | X509_PUBKEY *pub); | ||
| 1172 | |||
| 1173 | int X509_check_trust(X509 *x, int id, int flags); | ||
| 1174 | int X509_TRUST_get_count(void); | ||
| 1175 | X509_TRUST * X509_TRUST_get0(int idx); | ||
| 1176 | int X509_TRUST_get_by_id(int id); | ||
| 1177 | int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int), | ||
| 1178 | char *name, int arg1, void *arg2); | ||
| 1179 | void X509_TRUST_cleanup(void); | ||
| 1180 | int X509_TRUST_get_flags(X509_TRUST *xp); | ||
| 1181 | char *X509_TRUST_get0_name(X509_TRUST *xp); | ||
| 1182 | int X509_TRUST_get_trust(X509_TRUST *xp); | ||
| 1183 | |||
| 1184 | /* BEGIN ERROR CODES */ | ||
| 1185 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 1186 | * made after this point may be overwritten when the script is next run. | ||
| 1187 | */ | ||
| 1188 | void ERR_load_X509_strings(void); | ||
| 1189 | |||
| 1190 | /* Error codes for the X509 functions. */ | ||
| 1191 | |||
| 1192 | /* Function codes. */ | ||
| 1193 | #define X509_F_ADD_CERT_DIR 100 | ||
| 1194 | #define X509_F_BY_FILE_CTRL 101 | ||
| 1195 | #define X509_F_CHECK_POLICY 145 | ||
| 1196 | #define X509_F_DIR_CTRL 102 | ||
| 1197 | #define X509_F_GET_CERT_BY_SUBJECT 103 | ||
| 1198 | #define X509_F_NETSCAPE_SPKI_B64_DECODE 129 | ||
| 1199 | #define X509_F_NETSCAPE_SPKI_B64_ENCODE 130 | ||
| 1200 | #define X509_F_X509AT_ADD1_ATTR 135 | ||
| 1201 | #define X509_F_X509V3_ADD_EXT 104 | ||
| 1202 | #define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136 | ||
| 1203 | #define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137 | ||
| 1204 | #define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140 | ||
| 1205 | #define X509_F_X509_ATTRIBUTE_GET0_DATA 139 | ||
| 1206 | #define X509_F_X509_ATTRIBUTE_SET1_DATA 138 | ||
| 1207 | #define X509_F_X509_CHECK_PRIVATE_KEY 128 | ||
| 1208 | #define X509_F_X509_CRL_PRINT_FP 147 | ||
| 1209 | #define X509_F_X509_EXTENSION_CREATE_BY_NID 108 | ||
| 1210 | #define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 | ||
| 1211 | #define X509_F_X509_GET_PUBKEY_PARAMETERS 110 | ||
| 1212 | #define X509_F_X509_LOAD_CERT_CRL_FILE 132 | ||
| 1213 | #define X509_F_X509_LOAD_CERT_FILE 111 | ||
| 1214 | #define X509_F_X509_LOAD_CRL_FILE 112 | ||
| 1215 | #define X509_F_X509_NAME_ADD_ENTRY 113 | ||
| 1216 | #define X509_F_X509_NAME_ENTRY_CREATE_BY_NID 114 | ||
| 1217 | #define X509_F_X509_NAME_ENTRY_CREATE_BY_TXT 131 | ||
| 1218 | #define X509_F_X509_NAME_ENTRY_SET_OBJECT 115 | ||
| 1219 | #define X509_F_X509_NAME_ONELINE 116 | ||
| 1220 | #define X509_F_X509_NAME_PRINT 117 | ||
| 1221 | #define X509_F_X509_PRINT_EX_FP 118 | ||
| 1222 | #define X509_F_X509_PUBKEY_GET 119 | ||
| 1223 | #define X509_F_X509_PUBKEY_SET 120 | ||
| 1224 | #define X509_F_X509_REQ_CHECK_PRIVATE_KEY 144 | ||
| 1225 | #define X509_F_X509_REQ_PRINT_EX 121 | ||
| 1226 | #define X509_F_X509_REQ_PRINT_FP 122 | ||
| 1227 | #define X509_F_X509_REQ_TO_X509 123 | ||
| 1228 | #define X509_F_X509_STORE_ADD_CERT 124 | ||
| 1229 | #define X509_F_X509_STORE_ADD_CRL 125 | ||
| 1230 | #define X509_F_X509_STORE_CTX_GET1_ISSUER 146 | ||
| 1231 | #define X509_F_X509_STORE_CTX_INIT 143 | ||
| 1232 | #define X509_F_X509_STORE_CTX_NEW 142 | ||
| 1233 | #define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134 | ||
| 1234 | #define X509_F_X509_TO_X509_REQ 126 | ||
| 1235 | #define X509_F_X509_TRUST_ADD 133 | ||
| 1236 | #define X509_F_X509_TRUST_SET 141 | ||
| 1237 | #define X509_F_X509_VERIFY_CERT 127 | ||
| 1238 | |||
| 1239 | /* Reason codes. */ | ||
| 1240 | #define X509_R_BAD_X509_FILETYPE 100 | ||
| 1241 | #define X509_R_BASE64_DECODE_ERROR 118 | ||
| 1242 | #define X509_R_CANT_CHECK_DH_KEY 114 | ||
| 1243 | #define X509_R_CERT_ALREADY_IN_HASH_TABLE 101 | ||
| 1244 | #define X509_R_ERR_ASN1_LIB 102 | ||
| 1245 | #define X509_R_INVALID_DIRECTORY 113 | ||
| 1246 | #define X509_R_INVALID_FIELD_NAME 119 | ||
| 1247 | #define X509_R_INVALID_TRUST 123 | ||
| 1248 | #define X509_R_KEY_TYPE_MISMATCH 115 | ||
| 1249 | #define X509_R_KEY_VALUES_MISMATCH 116 | ||
| 1250 | #define X509_R_LOADING_CERT_DIR 103 | ||
| 1251 | #define X509_R_LOADING_DEFAULTS 104 | ||
| 1252 | #define X509_R_METHOD_NOT_SUPPORTED 124 | ||
| 1253 | #define X509_R_NO_CERT_SET_FOR_US_TO_VERIFY 105 | ||
| 1254 | #define X509_R_PUBLIC_KEY_DECODE_ERROR 125 | ||
| 1255 | #define X509_R_PUBLIC_KEY_ENCODE_ERROR 126 | ||
| 1256 | #define X509_R_SHOULD_RETRY 106 | ||
| 1257 | #define X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN 107 | ||
| 1258 | #define X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY 108 | ||
| 1259 | #define X509_R_UNKNOWN_KEY_TYPE 117 | ||
| 1260 | #define X509_R_UNKNOWN_NID 109 | ||
| 1261 | #define X509_R_UNKNOWN_PURPOSE_ID 121 | ||
| 1262 | #define X509_R_UNKNOWN_TRUST_ID 120 | ||
| 1263 | #define X509_R_UNSUPPORTED_ALGORITHM 111 | ||
| 1264 | #define X509_R_WRONG_LOOKUP_TYPE 112 | ||
| 1265 | #define X509_R_WRONG_TYPE 122 | ||
| 1266 | |||
| 1267 | #ifdef __cplusplus | ||
| 1268 | } | ||
| 1269 | #endif | ||
| 1270 | #endif | ||
diff --git a/src/lib/libcrypto/x509/x509_att.c b/src/lib/libcrypto/x509/x509_att.c deleted file mode 100644 index 5e5cf4e384..0000000000 --- a/src/lib/libcrypto/x509/x509_att.c +++ /dev/null | |||
| @@ -1,403 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_att.c,v 1.13 2014/09/29 16:20:40 miod Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/objects.h> | ||
| 65 | #include <openssl/stack.h> | ||
| 66 | #include <openssl/x509.h> | ||
| 67 | #include <openssl/x509v3.h> | ||
| 68 | |||
| 69 | int | ||
| 70 | X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x) | ||
| 71 | { | ||
| 72 | return sk_X509_ATTRIBUTE_num(x); | ||
| 73 | } | ||
| 74 | |||
| 75 | int | ||
| 76 | X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid, int lastpos) | ||
| 77 | { | ||
| 78 | ASN1_OBJECT *obj; | ||
| 79 | |||
| 80 | obj = OBJ_nid2obj(nid); | ||
| 81 | if (obj == NULL) | ||
| 82 | return (-2); | ||
| 83 | return (X509at_get_attr_by_OBJ(x, obj, lastpos)); | ||
| 84 | } | ||
| 85 | |||
| 86 | int | ||
| 87 | X509at_get_attr_by_OBJ(const STACK_OF(X509_ATTRIBUTE) *sk, ASN1_OBJECT *obj, | ||
| 88 | int lastpos) | ||
| 89 | { | ||
| 90 | int n; | ||
| 91 | X509_ATTRIBUTE *ex; | ||
| 92 | |||
| 93 | if (sk == NULL) | ||
| 94 | return (-1); | ||
| 95 | lastpos++; | ||
| 96 | if (lastpos < 0) | ||
| 97 | lastpos = 0; | ||
| 98 | n = sk_X509_ATTRIBUTE_num(sk); | ||
| 99 | for (; lastpos < n; lastpos++) { | ||
| 100 | ex = sk_X509_ATTRIBUTE_value(sk, lastpos); | ||
| 101 | if (OBJ_cmp(ex->object, obj) == 0) | ||
| 102 | return (lastpos); | ||
| 103 | } | ||
| 104 | return (-1); | ||
| 105 | } | ||
| 106 | |||
| 107 | X509_ATTRIBUTE * | ||
| 108 | X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc) | ||
| 109 | { | ||
| 110 | if (x == NULL || sk_X509_ATTRIBUTE_num(x) <= loc || loc < 0) | ||
| 111 | return NULL; | ||
| 112 | else | ||
| 113 | return sk_X509_ATTRIBUTE_value(x, loc); | ||
| 114 | } | ||
| 115 | |||
| 116 | X509_ATTRIBUTE * | ||
| 117 | X509at_delete_attr(STACK_OF(X509_ATTRIBUTE) *x, int loc) | ||
| 118 | { | ||
| 119 | X509_ATTRIBUTE *ret; | ||
| 120 | |||
| 121 | if (x == NULL || sk_X509_ATTRIBUTE_num(x) <= loc || loc < 0) | ||
| 122 | return (NULL); | ||
| 123 | ret = sk_X509_ATTRIBUTE_delete(x, loc); | ||
| 124 | return (ret); | ||
| 125 | } | ||
| 126 | |||
| 127 | STACK_OF(X509_ATTRIBUTE) * | ||
| 128 | X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x, X509_ATTRIBUTE *attr) | ||
| 129 | { | ||
| 130 | X509_ATTRIBUTE *new_attr = NULL; | ||
| 131 | STACK_OF(X509_ATTRIBUTE) *sk = NULL; | ||
| 132 | |||
| 133 | if (x == NULL) { | ||
| 134 | X509err(X509_F_X509AT_ADD1_ATTR, ERR_R_PASSED_NULL_PARAMETER); | ||
| 135 | return (NULL); | ||
| 136 | } | ||
| 137 | |||
| 138 | if (*x == NULL) { | ||
| 139 | if ((sk = sk_X509_ATTRIBUTE_new_null()) == NULL) | ||
| 140 | goto err; | ||
| 141 | } else | ||
| 142 | sk = *x; | ||
| 143 | |||
| 144 | if ((new_attr = X509_ATTRIBUTE_dup(attr)) == NULL) | ||
| 145 | goto err2; | ||
| 146 | if (!sk_X509_ATTRIBUTE_push(sk, new_attr)) | ||
| 147 | goto err; | ||
| 148 | if (*x == NULL) | ||
| 149 | *x = sk; | ||
| 150 | return (sk); | ||
| 151 | |||
| 152 | err: | ||
| 153 | X509err(X509_F_X509AT_ADD1_ATTR, ERR_R_MALLOC_FAILURE); | ||
| 154 | err2: | ||
| 155 | if (new_attr != NULL) | ||
| 156 | X509_ATTRIBUTE_free(new_attr); | ||
| 157 | if (sk != NULL && sk != *x) | ||
| 158 | sk_X509_ATTRIBUTE_free(sk); | ||
| 159 | return (NULL); | ||
| 160 | } | ||
| 161 | |||
| 162 | STACK_OF(X509_ATTRIBUTE) * | ||
| 163 | X509at_add1_attr_by_OBJ(STACK_OF(X509_ATTRIBUTE) **x, const ASN1_OBJECT *obj, | ||
| 164 | int type, const unsigned char *bytes, int len) | ||
| 165 | { | ||
| 166 | X509_ATTRIBUTE *attr; | ||
| 167 | STACK_OF(X509_ATTRIBUTE) *ret; | ||
| 168 | |||
| 169 | attr = X509_ATTRIBUTE_create_by_OBJ(NULL, obj, type, bytes, len); | ||
| 170 | if (!attr) | ||
| 171 | return 0; | ||
| 172 | ret = X509at_add1_attr(x, attr); | ||
| 173 | X509_ATTRIBUTE_free(attr); | ||
| 174 | return ret; | ||
| 175 | } | ||
| 176 | |||
| 177 | STACK_OF(X509_ATTRIBUTE) * | ||
| 178 | X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x, int nid, int type, | ||
| 179 | const unsigned char *bytes, int len) | ||
| 180 | { | ||
| 181 | X509_ATTRIBUTE *attr; | ||
| 182 | STACK_OF(X509_ATTRIBUTE) *ret; | ||
| 183 | |||
| 184 | attr = X509_ATTRIBUTE_create_by_NID(NULL, nid, type, bytes, len); | ||
| 185 | if (!attr) | ||
| 186 | return 0; | ||
| 187 | ret = X509at_add1_attr(x, attr); | ||
| 188 | X509_ATTRIBUTE_free(attr); | ||
| 189 | return ret; | ||
| 190 | } | ||
| 191 | |||
| 192 | STACK_OF(X509_ATTRIBUTE) * | ||
| 193 | X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x, const char *attrname, | ||
| 194 | int type, const unsigned char *bytes, int len) | ||
| 195 | { | ||
| 196 | X509_ATTRIBUTE *attr; | ||
| 197 | STACK_OF(X509_ATTRIBUTE) *ret; | ||
| 198 | |||
| 199 | attr = X509_ATTRIBUTE_create_by_txt(NULL, attrname, type, bytes, len); | ||
| 200 | if (!attr) | ||
| 201 | return 0; | ||
| 202 | ret = X509at_add1_attr(x, attr); | ||
| 203 | X509_ATTRIBUTE_free(attr); | ||
| 204 | return ret; | ||
| 205 | } | ||
| 206 | |||
| 207 | void * | ||
| 208 | X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x, ASN1_OBJECT *obj, | ||
| 209 | int lastpos, int type) | ||
| 210 | { | ||
| 211 | int i; | ||
| 212 | X509_ATTRIBUTE *at; | ||
| 213 | |||
| 214 | i = X509at_get_attr_by_OBJ(x, obj, lastpos); | ||
| 215 | if (i == -1) | ||
| 216 | return NULL; | ||
| 217 | if ((lastpos <= -2) && (X509at_get_attr_by_OBJ(x, obj, i) != -1)) | ||
| 218 | return NULL; | ||
| 219 | at = X509at_get_attr(x, i); | ||
| 220 | if (lastpos <= -3 && (X509_ATTRIBUTE_count(at) != 1)) | ||
| 221 | return NULL; | ||
| 222 | return X509_ATTRIBUTE_get0_data(at, 0, type, NULL); | ||
| 223 | } | ||
| 224 | |||
| 225 | X509_ATTRIBUTE * | ||
| 226 | X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, int atrtype, | ||
| 227 | const void *data, int len) | ||
| 228 | { | ||
| 229 | ASN1_OBJECT *obj; | ||
| 230 | X509_ATTRIBUTE *ret; | ||
| 231 | |||
| 232 | obj = OBJ_nid2obj(nid); | ||
| 233 | if (obj == NULL) { | ||
| 234 | X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_NID, | ||
| 235 | X509_R_UNKNOWN_NID); | ||
| 236 | return (NULL); | ||
| 237 | } | ||
| 238 | ret = X509_ATTRIBUTE_create_by_OBJ(attr, obj, atrtype, data, len); | ||
| 239 | if (ret == NULL) | ||
| 240 | ASN1_OBJECT_free(obj); | ||
| 241 | return (ret); | ||
| 242 | } | ||
| 243 | |||
| 244 | X509_ATTRIBUTE * | ||
| 245 | X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr, const ASN1_OBJECT *obj, | ||
| 246 | int atrtype, const void *data, int len) | ||
| 247 | { | ||
| 248 | X509_ATTRIBUTE *ret; | ||
| 249 | |||
| 250 | if ((attr == NULL) || (*attr == NULL)) { | ||
| 251 | if ((ret = X509_ATTRIBUTE_new()) == NULL) { | ||
| 252 | X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ, | ||
| 253 | ERR_R_MALLOC_FAILURE); | ||
| 254 | return (NULL); | ||
| 255 | } | ||
| 256 | } else | ||
| 257 | ret= *attr; | ||
| 258 | |||
| 259 | if (!X509_ATTRIBUTE_set1_object(ret, obj)) | ||
| 260 | goto err; | ||
| 261 | if (!X509_ATTRIBUTE_set1_data(ret, atrtype, data, len)) | ||
| 262 | goto err; | ||
| 263 | |||
| 264 | if ((attr != NULL) && (*attr == NULL)) | ||
| 265 | *attr = ret; | ||
| 266 | return (ret); | ||
| 267 | |||
| 268 | err: | ||
| 269 | if ((attr == NULL) || (ret != *attr)) | ||
| 270 | X509_ATTRIBUTE_free(ret); | ||
| 271 | return (NULL); | ||
| 272 | } | ||
| 273 | |||
| 274 | X509_ATTRIBUTE * | ||
| 275 | X509_ATTRIBUTE_create_by_txt(X509_ATTRIBUTE **attr, const char *atrname, | ||
| 276 | int type, const unsigned char *bytes, int len) | ||
| 277 | { | ||
| 278 | ASN1_OBJECT *obj; | ||
| 279 | X509_ATTRIBUTE *nattr; | ||
| 280 | |||
| 281 | obj = OBJ_txt2obj(atrname, 0); | ||
| 282 | if (obj == NULL) { | ||
| 283 | X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_TXT, | ||
| 284 | X509_R_INVALID_FIELD_NAME); | ||
| 285 | ERR_asprintf_error_data("name=%s", atrname); | ||
| 286 | return (NULL); | ||
| 287 | } | ||
| 288 | nattr = X509_ATTRIBUTE_create_by_OBJ(attr, obj, type, bytes, len); | ||
| 289 | ASN1_OBJECT_free(obj); | ||
| 290 | return nattr; | ||
| 291 | } | ||
| 292 | |||
| 293 | int | ||
| 294 | X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj) | ||
| 295 | { | ||
| 296 | if ((attr == NULL) || (obj == NULL)) | ||
| 297 | return (0); | ||
| 298 | ASN1_OBJECT_free(attr->object); | ||
| 299 | attr->object = OBJ_dup(obj); | ||
| 300 | return (1); | ||
| 301 | } | ||
| 302 | |||
| 303 | int | ||
| 304 | X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, | ||
| 305 | int len) | ||
| 306 | { | ||
| 307 | ASN1_TYPE *ttmp = NULL; | ||
| 308 | ASN1_STRING *stmp = NULL; | ||
| 309 | int atype = 0; | ||
| 310 | |||
| 311 | if (!attr) | ||
| 312 | return 0; | ||
| 313 | if (attrtype & MBSTRING_FLAG) { | ||
| 314 | stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype, | ||
| 315 | OBJ_obj2nid(attr->object)); | ||
| 316 | if (!stmp) { | ||
| 317 | X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, | ||
| 318 | ERR_R_ASN1_LIB); | ||
| 319 | return 0; | ||
| 320 | } | ||
| 321 | atype = stmp->type; | ||
| 322 | } else if (len != -1){ | ||
| 323 | if (!(stmp = ASN1_STRING_type_new(attrtype))) | ||
| 324 | goto err; | ||
| 325 | if (!ASN1_STRING_set(stmp, data, len)) | ||
| 326 | goto err; | ||
| 327 | atype = attrtype; | ||
| 328 | } | ||
| 329 | if (!(attr->value.set = sk_ASN1_TYPE_new_null())) | ||
| 330 | goto err; | ||
| 331 | attr->single = 0; | ||
| 332 | /* This is a bit naughty because the attribute should really have | ||
| 333 | * at least one value but some types use and zero length SET and | ||
| 334 | * require this. | ||
| 335 | */ | ||
| 336 | if (attrtype == 0) { | ||
| 337 | ASN1_STRING_free(stmp); | ||
| 338 | return 1; | ||
| 339 | } | ||
| 340 | |||
| 341 | if (!(ttmp = ASN1_TYPE_new())) | ||
| 342 | goto err; | ||
| 343 | if ((len == -1) && !(attrtype & MBSTRING_FLAG)) { | ||
| 344 | if (!ASN1_TYPE_set1(ttmp, attrtype, data)) | ||
| 345 | goto err; | ||
| 346 | } else | ||
| 347 | ASN1_TYPE_set(ttmp, atype, stmp); | ||
| 348 | if (!sk_ASN1_TYPE_push(attr->value.set, ttmp)) | ||
| 349 | goto err; | ||
| 350 | return 1; | ||
| 351 | |||
| 352 | err: | ||
| 353 | ASN1_TYPE_free(ttmp); | ||
| 354 | ASN1_STRING_free(stmp); | ||
| 355 | X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE); | ||
| 356 | return 0; | ||
| 357 | } | ||
| 358 | |||
| 359 | int | ||
| 360 | X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr) | ||
| 361 | { | ||
| 362 | if (!attr->single) | ||
| 363 | return sk_ASN1_TYPE_num(attr->value.set); | ||
| 364 | if (attr->value.single) | ||
| 365 | return 1; | ||
| 366 | return 0; | ||
| 367 | } | ||
| 368 | |||
| 369 | ASN1_OBJECT * | ||
| 370 | X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr) | ||
| 371 | { | ||
| 372 | if (attr == NULL) | ||
| 373 | return (NULL); | ||
| 374 | return (attr->object); | ||
| 375 | } | ||
| 376 | |||
| 377 | void * | ||
| 378 | X509_ATTRIBUTE_get0_data(X509_ATTRIBUTE *attr, int idx, int atrtype, void *data) | ||
| 379 | { | ||
| 380 | ASN1_TYPE *ttmp; | ||
| 381 | |||
| 382 | ttmp = X509_ATTRIBUTE_get0_type(attr, idx); | ||
| 383 | if (!ttmp) | ||
| 384 | return NULL; | ||
| 385 | if (atrtype != ASN1_TYPE_get(ttmp)){ | ||
| 386 | X509err(X509_F_X509_ATTRIBUTE_GET0_DATA, X509_R_WRONG_TYPE); | ||
| 387 | return NULL; | ||
| 388 | } | ||
| 389 | return ttmp->value.ptr; | ||
| 390 | } | ||
| 391 | |||
| 392 | ASN1_TYPE * | ||
| 393 | X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx) | ||
| 394 | { | ||
| 395 | if (attr == NULL) | ||
| 396 | return (NULL); | ||
| 397 | if (idx >= X509_ATTRIBUTE_count(attr)) | ||
| 398 | return NULL; | ||
| 399 | if (!attr->single) | ||
| 400 | return sk_ASN1_TYPE_value(attr->value.set, idx); | ||
| 401 | else | ||
| 402 | return attr->value.single; | ||
| 403 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c deleted file mode 100644 index 407e1e07ad..0000000000 --- a/src/lib/libcrypto/x509/x509_cmp.c +++ /dev/null | |||
| @@ -1,369 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_cmp.c,v 1.26 2015/07/29 14:58:34 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <ctype.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | #include <string.h> | ||
| 62 | |||
| 63 | #include <openssl/opensslconf.h> | ||
| 64 | |||
| 65 | #include <openssl/asn1.h> | ||
| 66 | #include <openssl/err.h> | ||
| 67 | #include <openssl/objects.h> | ||
| 68 | #include <openssl/x509.h> | ||
| 69 | #include <openssl/x509v3.h> | ||
| 70 | |||
| 71 | int | ||
| 72 | X509_issuer_and_serial_cmp(const X509 *a, const X509 *b) | ||
| 73 | { | ||
| 74 | int i; | ||
| 75 | X509_CINF *ai, *bi; | ||
| 76 | |||
| 77 | ai = a->cert_info; | ||
| 78 | bi = b->cert_info; | ||
| 79 | i = ASN1_STRING_cmp(ai->serialNumber, bi->serialNumber); | ||
| 80 | if (i) | ||
| 81 | return (i); | ||
| 82 | return (X509_NAME_cmp(ai->issuer, bi->issuer)); | ||
| 83 | } | ||
| 84 | |||
| 85 | #ifndef OPENSSL_NO_MD5 | ||
| 86 | unsigned long | ||
| 87 | X509_issuer_and_serial_hash(X509 *a) | ||
| 88 | { | ||
| 89 | unsigned long ret = 0; | ||
| 90 | EVP_MD_CTX ctx; | ||
| 91 | unsigned char md[16]; | ||
| 92 | char *f; | ||
| 93 | |||
| 94 | EVP_MD_CTX_init(&ctx); | ||
| 95 | f = X509_NAME_oneline(a->cert_info->issuer, NULL, 0); | ||
| 96 | if (f == NULL) | ||
| 97 | goto err; | ||
| 98 | if (!EVP_DigestInit_ex(&ctx, EVP_md5(), NULL)) | ||
| 99 | goto err; | ||
| 100 | if (!EVP_DigestUpdate(&ctx, (unsigned char *)f, strlen(f))) | ||
| 101 | goto err; | ||
| 102 | free(f); | ||
| 103 | f = NULL; | ||
| 104 | if (!EVP_DigestUpdate(&ctx, | ||
| 105 | (unsigned char *)a->cert_info->serialNumber->data, | ||
| 106 | (unsigned long)a->cert_info->serialNumber->length)) | ||
| 107 | goto err; | ||
| 108 | if (!EVP_DigestFinal_ex(&ctx, &(md[0]), NULL)) | ||
| 109 | goto err; | ||
| 110 | ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) | | ||
| 111 | ((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)) & | ||
| 112 | 0xffffffffL; | ||
| 113 | |||
| 114 | err: | ||
| 115 | EVP_MD_CTX_cleanup(&ctx); | ||
| 116 | free(f); | ||
| 117 | return (ret); | ||
| 118 | } | ||
| 119 | #endif | ||
| 120 | |||
| 121 | int | ||
| 122 | X509_issuer_name_cmp(const X509 *a, const X509 *b) | ||
| 123 | { | ||
| 124 | return (X509_NAME_cmp(a->cert_info->issuer, b->cert_info->issuer)); | ||
| 125 | } | ||
| 126 | |||
| 127 | int | ||
| 128 | X509_subject_name_cmp(const X509 *a, const X509 *b) | ||
| 129 | { | ||
| 130 | return (X509_NAME_cmp(a->cert_info->subject, b->cert_info->subject)); | ||
| 131 | } | ||
| 132 | |||
| 133 | int | ||
| 134 | X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b) | ||
| 135 | { | ||
| 136 | return (X509_NAME_cmp(a->crl->issuer, b->crl->issuer)); | ||
| 137 | } | ||
| 138 | |||
| 139 | #ifndef OPENSSL_NO_SHA | ||
| 140 | int | ||
| 141 | X509_CRL_match(const X509_CRL *a, const X509_CRL *b) | ||
| 142 | { | ||
| 143 | return memcmp(a->sha1_hash, b->sha1_hash, 20); | ||
| 144 | } | ||
| 145 | #endif | ||
| 146 | |||
| 147 | X509_NAME * | ||
| 148 | X509_get_issuer_name(X509 *a) | ||
| 149 | { | ||
| 150 | return (a->cert_info->issuer); | ||
| 151 | } | ||
| 152 | |||
| 153 | unsigned long | ||
| 154 | X509_issuer_name_hash(X509 *x) | ||
| 155 | { | ||
| 156 | return (X509_NAME_hash(x->cert_info->issuer)); | ||
| 157 | } | ||
| 158 | |||
| 159 | #ifndef OPENSSL_NO_MD5 | ||
| 160 | unsigned long | ||
| 161 | X509_issuer_name_hash_old(X509 *x) | ||
| 162 | { | ||
| 163 | return (X509_NAME_hash_old(x->cert_info->issuer)); | ||
| 164 | } | ||
| 165 | #endif | ||
| 166 | |||
| 167 | X509_NAME * | ||
| 168 | X509_get_subject_name(X509 *a) | ||
| 169 | { | ||
| 170 | return (a->cert_info->subject); | ||
| 171 | } | ||
| 172 | |||
| 173 | ASN1_INTEGER * | ||
| 174 | X509_get_serialNumber(X509 *a) | ||
| 175 | { | ||
| 176 | return (a->cert_info->serialNumber); | ||
| 177 | } | ||
| 178 | |||
| 179 | unsigned long | ||
| 180 | X509_subject_name_hash(X509 *x) | ||
| 181 | { | ||
| 182 | return (X509_NAME_hash(x->cert_info->subject)); | ||
| 183 | } | ||
| 184 | |||
| 185 | #ifndef OPENSSL_NO_MD5 | ||
| 186 | unsigned long | ||
| 187 | X509_subject_name_hash_old(X509 *x) | ||
| 188 | { | ||
| 189 | return (X509_NAME_hash_old(x->cert_info->subject)); | ||
| 190 | } | ||
| 191 | #endif | ||
| 192 | |||
| 193 | #ifndef OPENSSL_NO_SHA | ||
| 194 | /* Compare two certificates: they must be identical for | ||
| 195 | * this to work. NB: Although "cmp" operations are generally | ||
| 196 | * prototyped to take "const" arguments (eg. for use in | ||
| 197 | * STACKs), the way X509 handling is - these operations may | ||
| 198 | * involve ensuring the hashes are up-to-date and ensuring | ||
| 199 | * certain cert information is cached. So this is the point | ||
| 200 | * where the "depth-first" constification tree has to halt | ||
| 201 | * with an evil cast. | ||
| 202 | */ | ||
| 203 | int | ||
| 204 | X509_cmp(const X509 *a, const X509 *b) | ||
| 205 | { | ||
| 206 | /* ensure hash is valid */ | ||
| 207 | X509_check_purpose((X509 *)a, -1, 0); | ||
| 208 | X509_check_purpose((X509 *)b, -1, 0); | ||
| 209 | |||
| 210 | return memcmp(a->sha1_hash, b->sha1_hash, SHA_DIGEST_LENGTH); | ||
| 211 | } | ||
| 212 | #endif | ||
| 213 | |||
| 214 | int | ||
| 215 | X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b) | ||
| 216 | { | ||
| 217 | int ret; | ||
| 218 | |||
| 219 | /* Ensure canonical encoding is present and up to date */ | ||
| 220 | if (!a->canon_enc || a->modified) { | ||
| 221 | ret = i2d_X509_NAME((X509_NAME *)a, NULL); | ||
| 222 | if (ret < 0) | ||
| 223 | return -2; | ||
| 224 | } | ||
| 225 | if (!b->canon_enc || b->modified) { | ||
| 226 | ret = i2d_X509_NAME((X509_NAME *)b, NULL); | ||
| 227 | if (ret < 0) | ||
| 228 | return -2; | ||
| 229 | } | ||
| 230 | ret = a->canon_enclen - b->canon_enclen; | ||
| 231 | if (ret) | ||
| 232 | return ret; | ||
| 233 | return memcmp(a->canon_enc, b->canon_enc, a->canon_enclen); | ||
| 234 | } | ||
| 235 | |||
| 236 | unsigned long | ||
| 237 | X509_NAME_hash(X509_NAME *x) | ||
| 238 | { | ||
| 239 | unsigned long ret = 0; | ||
| 240 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
| 241 | |||
| 242 | /* Make sure X509_NAME structure contains valid cached encoding */ | ||
| 243 | i2d_X509_NAME(x, NULL); | ||
| 244 | if (!EVP_Digest(x->canon_enc, x->canon_enclen, md, NULL, EVP_sha1(), | ||
| 245 | NULL)) | ||
| 246 | return 0; | ||
| 247 | |||
| 248 | ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) | | ||
| 249 | ((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)) & | ||
| 250 | 0xffffffffL; | ||
| 251 | return (ret); | ||
| 252 | } | ||
| 253 | |||
| 254 | |||
| 255 | #ifndef OPENSSL_NO_MD5 | ||
| 256 | /* I now DER encode the name and hash it. Since I cache the DER encoding, | ||
| 257 | * this is reasonably efficient. */ | ||
| 258 | |||
| 259 | unsigned long | ||
| 260 | X509_NAME_hash_old(X509_NAME *x) | ||
| 261 | { | ||
| 262 | EVP_MD_CTX md_ctx; | ||
| 263 | unsigned long ret = 0; | ||
| 264 | unsigned char md[16]; | ||
| 265 | |||
| 266 | /* Make sure X509_NAME structure contains valid cached encoding */ | ||
| 267 | i2d_X509_NAME(x, NULL); | ||
| 268 | EVP_MD_CTX_init(&md_ctx); | ||
| 269 | if (EVP_DigestInit_ex(&md_ctx, EVP_md5(), NULL) && | ||
| 270 | EVP_DigestUpdate(&md_ctx, x->bytes->data, x->bytes->length) && | ||
| 271 | EVP_DigestFinal_ex(&md_ctx, md, NULL)) | ||
| 272 | ret = (((unsigned long)md[0]) | | ||
| 273 | ((unsigned long)md[1] << 8L) | | ||
| 274 | ((unsigned long)md[2] << 16L) | | ||
| 275 | ((unsigned long)md[3] << 24L)) & | ||
| 276 | 0xffffffffL; | ||
| 277 | EVP_MD_CTX_cleanup(&md_ctx); | ||
| 278 | |||
| 279 | return (ret); | ||
| 280 | } | ||
| 281 | #endif | ||
| 282 | |||
| 283 | /* Search a stack of X509 for a match */ | ||
| 284 | X509 * | ||
| 285 | X509_find_by_issuer_and_serial(STACK_OF(X509) *sk, X509_NAME *name, | ||
| 286 | ASN1_INTEGER *serial) | ||
| 287 | { | ||
| 288 | int i; | ||
| 289 | X509_CINF cinf; | ||
| 290 | X509 x, *x509 = NULL; | ||
| 291 | |||
| 292 | if (!sk) | ||
| 293 | return NULL; | ||
| 294 | |||
| 295 | x.cert_info = &cinf; | ||
| 296 | cinf.serialNumber = serial; | ||
| 297 | cinf.issuer = name; | ||
| 298 | |||
| 299 | for (i = 0; i < sk_X509_num(sk); i++) { | ||
| 300 | x509 = sk_X509_value(sk, i); | ||
| 301 | if (X509_issuer_and_serial_cmp(x509, &x) == 0) | ||
| 302 | return (x509); | ||
| 303 | } | ||
| 304 | return (NULL); | ||
| 305 | } | ||
| 306 | |||
| 307 | X509 * | ||
| 308 | X509_find_by_subject(STACK_OF(X509) *sk, X509_NAME *name) | ||
| 309 | { | ||
| 310 | X509 *x509; | ||
| 311 | int i; | ||
| 312 | |||
| 313 | for (i = 0; i < sk_X509_num(sk); i++) { | ||
| 314 | x509 = sk_X509_value(sk, i); | ||
| 315 | if (X509_NAME_cmp(X509_get_subject_name(x509), name) == 0) | ||
| 316 | return (x509); | ||
| 317 | } | ||
| 318 | return (NULL); | ||
| 319 | } | ||
| 320 | |||
| 321 | EVP_PKEY * | ||
| 322 | X509_get_pubkey(X509 *x) | ||
| 323 | { | ||
| 324 | if ((x == NULL) || (x->cert_info == NULL)) | ||
| 325 | return (NULL); | ||
| 326 | return (X509_PUBKEY_get(x->cert_info->key)); | ||
| 327 | } | ||
| 328 | |||
| 329 | ASN1_BIT_STRING * | ||
| 330 | X509_get0_pubkey_bitstr(const X509 *x) | ||
| 331 | { | ||
| 332 | if (!x) | ||
| 333 | return NULL; | ||
| 334 | return x->cert_info->key->public_key; | ||
| 335 | } | ||
| 336 | |||
| 337 | int | ||
| 338 | X509_check_private_key(X509 *x, EVP_PKEY *k) | ||
| 339 | { | ||
| 340 | EVP_PKEY *xk; | ||
| 341 | int ret; | ||
| 342 | |||
| 343 | xk = X509_get_pubkey(x); | ||
| 344 | |||
| 345 | if (xk) | ||
| 346 | ret = EVP_PKEY_cmp(xk, k); | ||
| 347 | else | ||
| 348 | ret = -2; | ||
| 349 | |||
| 350 | switch (ret) { | ||
| 351 | case 1: | ||
| 352 | break; | ||
| 353 | case 0: | ||
| 354 | X509err(X509_F_X509_CHECK_PRIVATE_KEY, | ||
| 355 | X509_R_KEY_VALUES_MISMATCH); | ||
| 356 | break; | ||
| 357 | case -1: | ||
| 358 | X509err(X509_F_X509_CHECK_PRIVATE_KEY, | ||
| 359 | X509_R_KEY_TYPE_MISMATCH); | ||
| 360 | break; | ||
| 361 | case -2: | ||
| 362 | X509err(X509_F_X509_CHECK_PRIVATE_KEY, | ||
| 363 | X509_R_UNKNOWN_KEY_TYPE); | ||
| 364 | } | ||
| 365 | EVP_PKEY_free(xk); | ||
| 366 | if (ret > 0) | ||
| 367 | return 1; | ||
| 368 | return 0; | ||
| 369 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_d2.c b/src/lib/libcrypto/x509/x509_d2.c deleted file mode 100644 index 5b0f80adda..0000000000 --- a/src/lib/libcrypto/x509/x509_d2.c +++ /dev/null | |||
| @@ -1,128 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_d2.c,v 1.10 2015/01/22 09:06:39 reyk Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <sys/uio.h> | ||
| 61 | |||
| 62 | #include <openssl/crypto.h> | ||
| 63 | #include <openssl/err.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | |||
| 66 | int | ||
| 67 | X509_STORE_set_default_paths(X509_STORE *ctx) | ||
| 68 | { | ||
| 69 | X509_LOOKUP *lookup; | ||
| 70 | |||
| 71 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file()); | ||
| 72 | if (lookup == NULL) | ||
| 73 | return (0); | ||
| 74 | X509_LOOKUP_load_file(lookup, NULL, X509_FILETYPE_DEFAULT); | ||
| 75 | |||
| 76 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir()); | ||
| 77 | if (lookup == NULL) | ||
| 78 | return (0); | ||
| 79 | X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT); | ||
| 80 | |||
| 81 | /* clear any errors */ | ||
| 82 | ERR_clear_error(); | ||
| 83 | |||
| 84 | return (1); | ||
| 85 | } | ||
| 86 | |||
| 87 | int | ||
| 88 | X509_STORE_load_locations(X509_STORE *ctx, const char *file, const char *path) | ||
| 89 | { | ||
| 90 | X509_LOOKUP *lookup; | ||
| 91 | |||
| 92 | if (file != NULL) { | ||
| 93 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_file()); | ||
| 94 | if (lookup == NULL) | ||
| 95 | return (0); | ||
| 96 | if (X509_LOOKUP_load_file(lookup, file, X509_FILETYPE_PEM) != 1) | ||
| 97 | return (0); | ||
| 98 | } | ||
| 99 | if (path != NULL) { | ||
| 100 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_hash_dir()); | ||
| 101 | if (lookup == NULL) | ||
| 102 | return (0); | ||
| 103 | if (X509_LOOKUP_add_dir(lookup, path, X509_FILETYPE_PEM) != 1) | ||
| 104 | return (0); | ||
| 105 | } | ||
| 106 | if ((path == NULL) && (file == NULL)) | ||
| 107 | return (0); | ||
| 108 | return (1); | ||
| 109 | } | ||
| 110 | |||
| 111 | int | ||
| 112 | X509_STORE_load_mem(X509_STORE *ctx, void *buf, int len) | ||
| 113 | { | ||
| 114 | X509_LOOKUP *lookup; | ||
| 115 | struct iovec iov; | ||
| 116 | |||
| 117 | lookup = X509_STORE_add_lookup(ctx, X509_LOOKUP_mem()); | ||
| 118 | if (lookup == NULL) | ||
| 119 | return (0); | ||
| 120 | |||
| 121 | iov.iov_base = buf; | ||
| 122 | iov.iov_len = len; | ||
| 123 | |||
| 124 | if (X509_LOOKUP_add_mem(lookup, &iov, X509_FILETYPE_PEM) != 1) | ||
| 125 | return (0); | ||
| 126 | |||
| 127 | return (1); | ||
| 128 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_def.c b/src/lib/libcrypto/x509/x509_def.c deleted file mode 100644 index 5e570eb9a2..0000000000 --- a/src/lib/libcrypto/x509/x509_def.c +++ /dev/null | |||
| @@ -1,98 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_def.c,v 1.5 2014/06/12 15:49:31 deraadt Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include "cryptlib.h" | ||
| 61 | #include <openssl/crypto.h> | ||
| 62 | #include <openssl/x509.h> | ||
| 63 | |||
| 64 | const char * | ||
| 65 | X509_get_default_private_dir(void) | ||
| 66 | { | ||
| 67 | return (X509_PRIVATE_DIR); | ||
| 68 | } | ||
| 69 | |||
| 70 | const char * | ||
| 71 | X509_get_default_cert_area(void) | ||
| 72 | { | ||
| 73 | return (X509_CERT_AREA); | ||
| 74 | } | ||
| 75 | |||
| 76 | const char * | ||
| 77 | X509_get_default_cert_dir(void) | ||
| 78 | { | ||
| 79 | return (X509_CERT_DIR); | ||
| 80 | } | ||
| 81 | |||
| 82 | const char * | ||
| 83 | X509_get_default_cert_file(void) | ||
| 84 | { | ||
| 85 | return (X509_CERT_FILE); | ||
| 86 | } | ||
| 87 | |||
| 88 | const char * | ||
| 89 | X509_get_default_cert_dir_env(void) | ||
| 90 | { | ||
| 91 | return (X509_CERT_DIR_EVP); | ||
| 92 | } | ||
| 93 | |||
| 94 | const char * | ||
| 95 | X509_get_default_cert_file_env(void) | ||
| 96 | { | ||
| 97 | return (X509_CERT_FILE_EVP); | ||
| 98 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_err.c b/src/lib/libcrypto/x509/x509_err.c deleted file mode 100644 index 6a15ac9fd0..0000000000 --- a/src/lib/libcrypto/x509/x509_err.c +++ /dev/null | |||
| @@ -1,164 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_err.c,v 1.12 2014/07/10 22:45:58 jsing Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@OpenSSL.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | |||
| 63 | #include <openssl/opensslconf.h> | ||
| 64 | |||
| 65 | #include <openssl/err.h> | ||
| 66 | #include <openssl/x509.h> | ||
| 67 | |||
| 68 | /* BEGIN ERROR CODES */ | ||
| 69 | #ifndef OPENSSL_NO_ERR | ||
| 70 | |||
| 71 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_X509,func,0) | ||
| 72 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_X509,0,reason) | ||
| 73 | |||
| 74 | static ERR_STRING_DATA X509_str_functs[] = { | ||
| 75 | {ERR_FUNC(X509_F_ADD_CERT_DIR), "ADD_CERT_DIR"}, | ||
| 76 | {ERR_FUNC(X509_F_BY_FILE_CTRL), "BY_FILE_CTRL"}, | ||
| 77 | {ERR_FUNC(X509_F_CHECK_POLICY), "CHECK_POLICY"}, | ||
| 78 | {ERR_FUNC(X509_F_DIR_CTRL), "DIR_CTRL"}, | ||
| 79 | {ERR_FUNC(X509_F_GET_CERT_BY_SUBJECT), "GET_CERT_BY_SUBJECT"}, | ||
| 80 | {ERR_FUNC(X509_F_NETSCAPE_SPKI_B64_DECODE), "NETSCAPE_SPKI_b64_decode"}, | ||
| 81 | {ERR_FUNC(X509_F_NETSCAPE_SPKI_B64_ENCODE), "NETSCAPE_SPKI_b64_encode"}, | ||
| 82 | {ERR_FUNC(X509_F_X509AT_ADD1_ATTR), "X509at_add1_attr"}, | ||
| 83 | {ERR_FUNC(X509_F_X509V3_ADD_EXT), "X509v3_add_ext"}, | ||
| 84 | {ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_NID), "X509_ATTRIBUTE_create_by_NID"}, | ||
| 85 | {ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ), "X509_ATTRIBUTE_create_by_OBJ"}, | ||
| 86 | {ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_TXT), "X509_ATTRIBUTE_create_by_txt"}, | ||
| 87 | {ERR_FUNC(X509_F_X509_ATTRIBUTE_GET0_DATA), "X509_ATTRIBUTE_get0_data"}, | ||
| 88 | {ERR_FUNC(X509_F_X509_ATTRIBUTE_SET1_DATA), "X509_ATTRIBUTE_set1_data"}, | ||
| 89 | {ERR_FUNC(X509_F_X509_CHECK_PRIVATE_KEY), "X509_check_private_key"}, | ||
| 90 | {ERR_FUNC(X509_F_X509_CRL_PRINT_FP), "X509_CRL_print_fp"}, | ||
| 91 | {ERR_FUNC(X509_F_X509_EXTENSION_CREATE_BY_NID), "X509_EXTENSION_create_by_NID"}, | ||
| 92 | {ERR_FUNC(X509_F_X509_EXTENSION_CREATE_BY_OBJ), "X509_EXTENSION_create_by_OBJ"}, | ||
| 93 | {ERR_FUNC(X509_F_X509_GET_PUBKEY_PARAMETERS), "X509_get_pubkey_parameters"}, | ||
| 94 | {ERR_FUNC(X509_F_X509_LOAD_CERT_CRL_FILE), "X509_load_cert_crl_file"}, | ||
| 95 | {ERR_FUNC(X509_F_X509_LOAD_CERT_FILE), "X509_load_cert_file"}, | ||
| 96 | {ERR_FUNC(X509_F_X509_LOAD_CRL_FILE), "X509_load_crl_file"}, | ||
| 97 | {ERR_FUNC(X509_F_X509_NAME_ADD_ENTRY), "X509_NAME_add_entry"}, | ||
| 98 | {ERR_FUNC(X509_F_X509_NAME_ENTRY_CREATE_BY_NID), "X509_NAME_ENTRY_create_by_NID"}, | ||
| 99 | {ERR_FUNC(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT), "X509_NAME_ENTRY_create_by_txt"}, | ||
| 100 | {ERR_FUNC(X509_F_X509_NAME_ENTRY_SET_OBJECT), "X509_NAME_ENTRY_set_object"}, | ||
| 101 | {ERR_FUNC(X509_F_X509_NAME_ONELINE), "X509_NAME_oneline"}, | ||
| 102 | {ERR_FUNC(X509_F_X509_NAME_PRINT), "X509_NAME_print"}, | ||
| 103 | {ERR_FUNC(X509_F_X509_PRINT_EX_FP), "X509_print_ex_fp"}, | ||
| 104 | {ERR_FUNC(X509_F_X509_PUBKEY_GET), "X509_PUBKEY_get"}, | ||
| 105 | {ERR_FUNC(X509_F_X509_PUBKEY_SET), "X509_PUBKEY_set"}, | ||
| 106 | {ERR_FUNC(X509_F_X509_REQ_CHECK_PRIVATE_KEY), "X509_REQ_check_private_key"}, | ||
| 107 | {ERR_FUNC(X509_F_X509_REQ_PRINT_EX), "X509_REQ_print_ex"}, | ||
| 108 | {ERR_FUNC(X509_F_X509_REQ_PRINT_FP), "X509_REQ_print_fp"}, | ||
| 109 | {ERR_FUNC(X509_F_X509_REQ_TO_X509), "X509_REQ_to_X509"}, | ||
| 110 | {ERR_FUNC(X509_F_X509_STORE_ADD_CERT), "X509_STORE_add_cert"}, | ||
| 111 | {ERR_FUNC(X509_F_X509_STORE_ADD_CRL), "X509_STORE_add_crl"}, | ||
| 112 | {ERR_FUNC(X509_F_X509_STORE_CTX_GET1_ISSUER), "X509_STORE_CTX_get1_issuer"}, | ||
| 113 | {ERR_FUNC(X509_F_X509_STORE_CTX_INIT), "X509_STORE_CTX_init"}, | ||
| 114 | {ERR_FUNC(X509_F_X509_STORE_CTX_NEW), "X509_STORE_CTX_new"}, | ||
| 115 | {ERR_FUNC(X509_F_X509_STORE_CTX_PURPOSE_INHERIT), "X509_STORE_CTX_purpose_inherit"}, | ||
| 116 | {ERR_FUNC(X509_F_X509_TO_X509_REQ), "X509_to_X509_REQ"}, | ||
| 117 | {ERR_FUNC(X509_F_X509_TRUST_ADD), "X509_TRUST_add"}, | ||
| 118 | {ERR_FUNC(X509_F_X509_TRUST_SET), "X509_TRUST_set"}, | ||
| 119 | {ERR_FUNC(X509_F_X509_VERIFY_CERT), "X509_verify_cert"}, | ||
| 120 | {0, NULL} | ||
| 121 | }; | ||
| 122 | |||
| 123 | static ERR_STRING_DATA X509_str_reasons[] = { | ||
| 124 | {ERR_REASON(X509_R_BAD_X509_FILETYPE) , "bad x509 filetype"}, | ||
| 125 | {ERR_REASON(X509_R_BASE64_DECODE_ERROR) , "base64 decode error"}, | ||
| 126 | {ERR_REASON(X509_R_CANT_CHECK_DH_KEY) , "cant check dh key"}, | ||
| 127 | {ERR_REASON(X509_R_CERT_ALREADY_IN_HASH_TABLE), "cert already in hash table"}, | ||
| 128 | {ERR_REASON(X509_R_ERR_ASN1_LIB) , "err asn1 lib"}, | ||
| 129 | {ERR_REASON(X509_R_INVALID_DIRECTORY) , "invalid directory"}, | ||
| 130 | {ERR_REASON(X509_R_INVALID_FIELD_NAME) , "invalid field name"}, | ||
| 131 | {ERR_REASON(X509_R_INVALID_TRUST) , "invalid trust"}, | ||
| 132 | {ERR_REASON(X509_R_KEY_TYPE_MISMATCH) , "key type mismatch"}, | ||
| 133 | {ERR_REASON(X509_R_KEY_VALUES_MISMATCH) , "key values mismatch"}, | ||
| 134 | {ERR_REASON(X509_R_LOADING_CERT_DIR) , "loading cert dir"}, | ||
| 135 | {ERR_REASON(X509_R_LOADING_DEFAULTS) , "loading defaults"}, | ||
| 136 | {ERR_REASON(X509_R_METHOD_NOT_SUPPORTED) , "method not supported"}, | ||
| 137 | {ERR_REASON(X509_R_NO_CERT_SET_FOR_US_TO_VERIFY), "no cert set for us to verify"}, | ||
| 138 | {ERR_REASON(X509_R_PUBLIC_KEY_DECODE_ERROR), "public key decode error"}, | ||
| 139 | {ERR_REASON(X509_R_PUBLIC_KEY_ENCODE_ERROR), "public key encode error"}, | ||
| 140 | {ERR_REASON(X509_R_SHOULD_RETRY) , "should retry"}, | ||
| 141 | {ERR_REASON(X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN), "unable to find parameters in chain"}, | ||
| 142 | {ERR_REASON(X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY), "unable to get certs public key"}, | ||
| 143 | {ERR_REASON(X509_R_UNKNOWN_KEY_TYPE) , "unknown key type"}, | ||
| 144 | {ERR_REASON(X509_R_UNKNOWN_NID) , "unknown nid"}, | ||
| 145 | {ERR_REASON(X509_R_UNKNOWN_PURPOSE_ID) , "unknown purpose id"}, | ||
| 146 | {ERR_REASON(X509_R_UNKNOWN_TRUST_ID) , "unknown trust id"}, | ||
| 147 | {ERR_REASON(X509_R_UNSUPPORTED_ALGORITHM), "unsupported algorithm"}, | ||
| 148 | {ERR_REASON(X509_R_WRONG_LOOKUP_TYPE) , "wrong lookup type"}, | ||
| 149 | {ERR_REASON(X509_R_WRONG_TYPE) , "wrong type"}, | ||
| 150 | {0, NULL} | ||
| 151 | }; | ||
| 152 | |||
| 153 | #endif | ||
| 154 | |||
| 155 | void | ||
| 156 | ERR_load_X509_strings(void) | ||
| 157 | { | ||
| 158 | #ifndef OPENSSL_NO_ERR | ||
| 159 | if (ERR_func_error_string(X509_str_functs[0].error) == NULL) { | ||
| 160 | ERR_load_strings(0, X509_str_functs); | ||
| 161 | ERR_load_strings(0, X509_str_reasons); | ||
| 162 | } | ||
| 163 | #endif | ||
| 164 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_ext.c b/src/lib/libcrypto/x509/x509_ext.c deleted file mode 100644 index e90befaba1..0000000000 --- a/src/lib/libcrypto/x509/x509_ext.c +++ /dev/null | |||
| @@ -1,232 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_ext.c,v 1.9 2015/02/10 08:33:10 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/evp.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/stack.h> | ||
| 65 | #include <openssl/x509.h> | ||
| 66 | #include <openssl/x509v3.h> | ||
| 67 | |||
| 68 | int | ||
| 69 | X509_CRL_get_ext_count(X509_CRL *x) | ||
| 70 | { | ||
| 71 | return (X509v3_get_ext_count(x->crl->extensions)); | ||
| 72 | } | ||
| 73 | |||
| 74 | int | ||
| 75 | X509_CRL_get_ext_by_NID(X509_CRL *x, int nid, int lastpos) | ||
| 76 | { | ||
| 77 | return (X509v3_get_ext_by_NID(x->crl->extensions, nid, lastpos)); | ||
| 78 | } | ||
| 79 | |||
| 80 | int | ||
| 81 | X509_CRL_get_ext_by_OBJ(X509_CRL *x, ASN1_OBJECT *obj, int lastpos) | ||
| 82 | { | ||
| 83 | return (X509v3_get_ext_by_OBJ(x->crl->extensions, obj, lastpos)); | ||
| 84 | } | ||
| 85 | |||
| 86 | int | ||
| 87 | X509_CRL_get_ext_by_critical(X509_CRL *x, int crit, int lastpos) | ||
| 88 | { | ||
| 89 | return (X509v3_get_ext_by_critical(x->crl->extensions, crit, lastpos)); | ||
| 90 | } | ||
| 91 | |||
| 92 | X509_EXTENSION * | ||
| 93 | X509_CRL_get_ext(X509_CRL *x, int loc) | ||
| 94 | { | ||
| 95 | return (X509v3_get_ext(x->crl->extensions, loc)); | ||
| 96 | } | ||
| 97 | |||
| 98 | X509_EXTENSION * | ||
| 99 | X509_CRL_delete_ext(X509_CRL *x, int loc) | ||
| 100 | { | ||
| 101 | return (X509v3_delete_ext(x->crl->extensions, loc)); | ||
| 102 | } | ||
| 103 | |||
| 104 | void * | ||
| 105 | X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx) | ||
| 106 | { | ||
| 107 | return X509V3_get_d2i(x->crl->extensions, nid, crit, idx); | ||
| 108 | } | ||
| 109 | |||
| 110 | int | ||
| 111 | X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit, | ||
| 112 | unsigned long flags) | ||
| 113 | { | ||
| 114 | return X509V3_add1_i2d(&x->crl->extensions, nid, value, crit, flags); | ||
| 115 | } | ||
| 116 | |||
| 117 | int | ||
| 118 | X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc) | ||
| 119 | { | ||
| 120 | return (X509v3_add_ext(&(x->crl->extensions), ex, loc) != NULL); | ||
| 121 | } | ||
| 122 | |||
| 123 | int | ||
| 124 | X509_get_ext_count(X509 *x) | ||
| 125 | { | ||
| 126 | return (X509v3_get_ext_count(x->cert_info->extensions)); | ||
| 127 | } | ||
| 128 | |||
| 129 | int | ||
| 130 | X509_get_ext_by_NID(X509 *x, int nid, int lastpos) | ||
| 131 | { | ||
| 132 | return (X509v3_get_ext_by_NID(x->cert_info->extensions, nid, lastpos)); | ||
| 133 | } | ||
| 134 | |||
| 135 | int | ||
| 136 | X509_get_ext_by_OBJ(X509 *x, ASN1_OBJECT *obj, int lastpos) | ||
| 137 | { | ||
| 138 | return (X509v3_get_ext_by_OBJ(x->cert_info->extensions, obj, lastpos)); | ||
| 139 | } | ||
| 140 | |||
| 141 | int | ||
| 142 | X509_get_ext_by_critical(X509 *x, int crit, int lastpos) | ||
| 143 | { | ||
| 144 | return (X509v3_get_ext_by_critical(x->cert_info->extensions, crit, | ||
| 145 | lastpos)); | ||
| 146 | } | ||
| 147 | |||
| 148 | X509_EXTENSION * | ||
| 149 | X509_get_ext(X509 *x, int loc) | ||
| 150 | { | ||
| 151 | return (X509v3_get_ext(x->cert_info->extensions, loc)); | ||
| 152 | } | ||
| 153 | |||
| 154 | X509_EXTENSION * | ||
| 155 | X509_delete_ext(X509 *x, int loc) | ||
| 156 | { | ||
| 157 | return (X509v3_delete_ext(x->cert_info->extensions, loc)); | ||
| 158 | } | ||
| 159 | |||
| 160 | int | ||
| 161 | X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc) | ||
| 162 | { | ||
| 163 | return (X509v3_add_ext(&(x->cert_info->extensions), ex, loc) != NULL); | ||
| 164 | } | ||
| 165 | |||
| 166 | void * | ||
| 167 | X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx) | ||
| 168 | { | ||
| 169 | return X509V3_get_d2i(x->cert_info->extensions, nid, crit, idx); | ||
| 170 | } | ||
| 171 | |||
| 172 | int | ||
| 173 | X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit, unsigned long flags) | ||
| 174 | { | ||
| 175 | return X509V3_add1_i2d(&x->cert_info->extensions, nid, value, crit, | ||
| 176 | flags); | ||
| 177 | } | ||
| 178 | |||
| 179 | int | ||
| 180 | X509_REVOKED_get_ext_count(X509_REVOKED *x) | ||
| 181 | { | ||
| 182 | return (X509v3_get_ext_count(x->extensions)); | ||
| 183 | } | ||
| 184 | |||
| 185 | int | ||
| 186 | X509_REVOKED_get_ext_by_NID(X509_REVOKED *x, int nid, int lastpos) | ||
| 187 | { | ||
| 188 | return (X509v3_get_ext_by_NID(x->extensions, nid, lastpos)); | ||
| 189 | } | ||
| 190 | |||
| 191 | int | ||
| 192 | X509_REVOKED_get_ext_by_OBJ(X509_REVOKED *x, ASN1_OBJECT *obj, int lastpos) | ||
| 193 | { | ||
| 194 | return (X509v3_get_ext_by_OBJ(x->extensions, obj, lastpos)); | ||
| 195 | } | ||
| 196 | |||
| 197 | int | ||
| 198 | X509_REVOKED_get_ext_by_critical(X509_REVOKED *x, int crit, int lastpos) | ||
| 199 | { | ||
| 200 | return (X509v3_get_ext_by_critical(x->extensions, crit, lastpos)); | ||
| 201 | } | ||
| 202 | |||
| 203 | X509_EXTENSION * | ||
| 204 | X509_REVOKED_get_ext(X509_REVOKED *x, int loc) | ||
| 205 | { | ||
| 206 | return (X509v3_get_ext(x->extensions, loc)); | ||
| 207 | } | ||
| 208 | |||
| 209 | X509_EXTENSION * | ||
| 210 | X509_REVOKED_delete_ext(X509_REVOKED *x, int loc) | ||
| 211 | { | ||
| 212 | return (X509v3_delete_ext(x->extensions, loc)); | ||
| 213 | } | ||
| 214 | |||
| 215 | int | ||
| 216 | X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc) | ||
| 217 | { | ||
| 218 | return (X509v3_add_ext(&(x->extensions), ex, loc) != NULL); | ||
| 219 | } | ||
| 220 | |||
| 221 | void * | ||
| 222 | X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx) | ||
| 223 | { | ||
| 224 | return X509V3_get_d2i(x->extensions, nid, crit, idx); | ||
| 225 | } | ||
| 226 | |||
| 227 | int | ||
| 228 | X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit, | ||
| 229 | unsigned long flags) | ||
| 230 | { | ||
| 231 | return X509V3_add1_i2d(&x->extensions, nid, value, crit, flags); | ||
| 232 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_lcl.h b/src/lib/libcrypto/x509/x509_lcl.h deleted file mode 100644 index b16df78ad7..0000000000 --- a/src/lib/libcrypto/x509/x509_lcl.h +++ /dev/null | |||
| @@ -1,59 +0,0 @@ | |||
| 1 | /* x509_lcl.h */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 2013. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2013 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 | int x509_check_cert_time(X509_STORE_CTX *ctx, X509 *x, int quiet); | ||
diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c deleted file mode 100644 index fdb10023be..0000000000 --- a/src/lib/libcrypto/x509/x509_lu.c +++ /dev/null | |||
| @@ -1,739 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_lu.c,v 1.20 2015/04/25 16:02:55 doug Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/err.h> | ||
| 62 | #include <openssl/lhash.h> | ||
| 63 | #include <openssl/x509.h> | ||
| 64 | #include <openssl/x509v3.h> | ||
| 65 | #include "x509_lcl.h" | ||
| 66 | |||
| 67 | X509_LOOKUP * | ||
| 68 | X509_LOOKUP_new(X509_LOOKUP_METHOD *method) | ||
| 69 | { | ||
| 70 | X509_LOOKUP *ret; | ||
| 71 | |||
| 72 | ret = malloc(sizeof(X509_LOOKUP)); | ||
| 73 | if (ret == NULL) | ||
| 74 | return NULL; | ||
| 75 | |||
| 76 | ret->init = 0; | ||
| 77 | ret->skip = 0; | ||
| 78 | ret->method = method; | ||
| 79 | ret->method_data = NULL; | ||
| 80 | ret->store_ctx = NULL; | ||
| 81 | if ((method->new_item != NULL) && !method->new_item(ret)) { | ||
| 82 | free(ret); | ||
| 83 | return NULL; | ||
| 84 | } | ||
| 85 | return ret; | ||
| 86 | } | ||
| 87 | |||
| 88 | void | ||
| 89 | X509_LOOKUP_free(X509_LOOKUP *ctx) | ||
| 90 | { | ||
| 91 | if (ctx == NULL) | ||
| 92 | return; | ||
| 93 | if ((ctx->method != NULL) && (ctx->method->free != NULL)) | ||
| 94 | (*ctx->method->free)(ctx); | ||
| 95 | free(ctx); | ||
| 96 | } | ||
| 97 | |||
| 98 | int | ||
| 99 | X509_LOOKUP_init(X509_LOOKUP *ctx) | ||
| 100 | { | ||
| 101 | if (ctx->method == NULL) | ||
| 102 | return 0; | ||
| 103 | if (ctx->method->init != NULL) | ||
| 104 | return ctx->method->init(ctx); | ||
| 105 | else | ||
| 106 | return 1; | ||
| 107 | } | ||
| 108 | |||
| 109 | int | ||
| 110 | X509_LOOKUP_shutdown(X509_LOOKUP *ctx) | ||
| 111 | { | ||
| 112 | if (ctx->method == NULL) | ||
| 113 | return 0; | ||
| 114 | if (ctx->method->shutdown != NULL) | ||
| 115 | return ctx->method->shutdown(ctx); | ||
| 116 | else | ||
| 117 | return 1; | ||
| 118 | } | ||
| 119 | |||
| 120 | int | ||
| 121 | X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, long argl, | ||
| 122 | char **ret) | ||
| 123 | { | ||
| 124 | if (ctx->method == NULL) | ||
| 125 | return -1; | ||
| 126 | if (ctx->method->ctrl != NULL) | ||
| 127 | return ctx->method->ctrl(ctx, cmd, argc, argl, ret); | ||
| 128 | else | ||
| 129 | return 1; | ||
| 130 | } | ||
| 131 | |||
| 132 | int | ||
| 133 | X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name, | ||
| 134 | X509_OBJECT *ret) | ||
| 135 | { | ||
| 136 | if ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL)) | ||
| 137 | return X509_LU_FAIL; | ||
| 138 | if (ctx->skip) | ||
| 139 | return 0; | ||
| 140 | return ctx->method->get_by_subject(ctx, type, name, ret); | ||
| 141 | } | ||
| 142 | |||
| 143 | int | ||
| 144 | X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name, | ||
| 145 | ASN1_INTEGER *serial, X509_OBJECT *ret) | ||
| 146 | { | ||
| 147 | if ((ctx->method == NULL) || | ||
| 148 | (ctx->method->get_by_issuer_serial == NULL)) | ||
| 149 | return X509_LU_FAIL; | ||
| 150 | return ctx->method->get_by_issuer_serial(ctx, type, name, serial, ret); | ||
| 151 | } | ||
| 152 | |||
| 153 | int | ||
| 154 | X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type, unsigned char *bytes, | ||
| 155 | int len, X509_OBJECT *ret) | ||
| 156 | { | ||
| 157 | if ((ctx->method == NULL) || (ctx->method->get_by_fingerprint == NULL)) | ||
| 158 | return X509_LU_FAIL; | ||
| 159 | return ctx->method->get_by_fingerprint(ctx, type, bytes, len, ret); | ||
| 160 | } | ||
| 161 | |||
| 162 | int | ||
| 163 | X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, int len, | ||
| 164 | X509_OBJECT *ret) | ||
| 165 | { | ||
| 166 | if ((ctx->method == NULL) || (ctx->method->get_by_alias == NULL)) | ||
| 167 | return X509_LU_FAIL; | ||
| 168 | return ctx->method->get_by_alias(ctx, type, str, len, ret); | ||
| 169 | } | ||
| 170 | |||
| 171 | static int | ||
| 172 | x509_object_cmp(const X509_OBJECT * const *a, const X509_OBJECT * const *b) | ||
| 173 | { | ||
| 174 | int ret; | ||
| 175 | |||
| 176 | ret = ((*a)->type - (*b)->type); | ||
| 177 | if (ret) | ||
| 178 | return ret; | ||
| 179 | switch ((*a)->type) { | ||
| 180 | case X509_LU_X509: | ||
| 181 | ret = X509_subject_name_cmp((*a)->data.x509, (*b)->data.x509); | ||
| 182 | break; | ||
| 183 | case X509_LU_CRL: | ||
| 184 | ret = X509_CRL_cmp((*a)->data.crl, (*b)->data.crl); | ||
| 185 | break; | ||
| 186 | default: | ||
| 187 | /* abort(); */ | ||
| 188 | return 0; | ||
| 189 | } | ||
| 190 | return ret; | ||
| 191 | } | ||
| 192 | |||
| 193 | X509_STORE * | ||
| 194 | X509_STORE_new(void) | ||
| 195 | { | ||
| 196 | X509_STORE *ret; | ||
| 197 | |||
| 198 | if ((ret = malloc(sizeof(X509_STORE))) == NULL) | ||
| 199 | return NULL; | ||
| 200 | ret->objs = sk_X509_OBJECT_new(x509_object_cmp); | ||
| 201 | ret->cache = 1; | ||
| 202 | ret->get_cert_methods = sk_X509_LOOKUP_new_null(); | ||
| 203 | ret->verify = 0; | ||
| 204 | ret->verify_cb = 0; | ||
| 205 | |||
| 206 | if ((ret->param = X509_VERIFY_PARAM_new()) == NULL) | ||
| 207 | goto err; | ||
| 208 | |||
| 209 | ret->get_issuer = 0; | ||
| 210 | ret->check_issued = 0; | ||
| 211 | ret->check_revocation = 0; | ||
| 212 | ret->get_crl = 0; | ||
| 213 | ret->check_crl = 0; | ||
| 214 | ret->cert_crl = 0; | ||
| 215 | ret->lookup_certs = 0; | ||
| 216 | ret->lookup_crls = 0; | ||
| 217 | ret->cleanup = 0; | ||
| 218 | |||
| 219 | if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data)) | ||
| 220 | goto err; | ||
| 221 | |||
| 222 | ret->references = 1; | ||
| 223 | return ret; | ||
| 224 | |||
| 225 | err: | ||
| 226 | X509_VERIFY_PARAM_free(ret->param); | ||
| 227 | sk_X509_LOOKUP_free(ret->get_cert_methods); | ||
| 228 | sk_X509_OBJECT_free(ret->objs); | ||
| 229 | free(ret); | ||
| 230 | return NULL; | ||
| 231 | } | ||
| 232 | |||
| 233 | static void | ||
| 234 | cleanup(X509_OBJECT *a) | ||
| 235 | { | ||
| 236 | if (a->type == X509_LU_X509) { | ||
| 237 | X509_free(a->data.x509); | ||
| 238 | } else if (a->type == X509_LU_CRL) { | ||
| 239 | X509_CRL_free(a->data.crl); | ||
| 240 | } else { | ||
| 241 | /* abort(); */ | ||
| 242 | } | ||
| 243 | |||
| 244 | free(a); | ||
| 245 | } | ||
| 246 | |||
| 247 | void | ||
| 248 | X509_STORE_free(X509_STORE *vfy) | ||
| 249 | { | ||
| 250 | int i; | ||
| 251 | STACK_OF(X509_LOOKUP) *sk; | ||
| 252 | X509_LOOKUP *lu; | ||
| 253 | |||
| 254 | if (vfy == NULL) | ||
| 255 | return; | ||
| 256 | |||
| 257 | i = CRYPTO_add(&vfy->references, -1, CRYPTO_LOCK_X509_STORE); | ||
| 258 | if (i > 0) | ||
| 259 | return; | ||
| 260 | |||
| 261 | sk = vfy->get_cert_methods; | ||
| 262 | for (i = 0; i < sk_X509_LOOKUP_num(sk); i++) { | ||
| 263 | lu = sk_X509_LOOKUP_value(sk, i); | ||
| 264 | X509_LOOKUP_shutdown(lu); | ||
| 265 | X509_LOOKUP_free(lu); | ||
| 266 | } | ||
| 267 | sk_X509_LOOKUP_free(sk); | ||
| 268 | sk_X509_OBJECT_pop_free(vfy->objs, cleanup); | ||
| 269 | |||
| 270 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE, vfy, &vfy->ex_data); | ||
| 271 | X509_VERIFY_PARAM_free(vfy->param); | ||
| 272 | free(vfy); | ||
| 273 | } | ||
| 274 | |||
| 275 | X509_LOOKUP * | ||
| 276 | X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m) | ||
| 277 | { | ||
| 278 | int i; | ||
| 279 | STACK_OF(X509_LOOKUP) *sk; | ||
| 280 | X509_LOOKUP *lu; | ||
| 281 | |||
| 282 | sk = v->get_cert_methods; | ||
| 283 | for (i = 0; i < sk_X509_LOOKUP_num(sk); i++) { | ||
| 284 | lu = sk_X509_LOOKUP_value(sk, i); | ||
| 285 | if (m == lu->method) { | ||
| 286 | return lu; | ||
| 287 | } | ||
| 288 | } | ||
| 289 | /* a new one */ | ||
| 290 | lu = X509_LOOKUP_new(m); | ||
| 291 | if (lu == NULL) | ||
| 292 | return NULL; | ||
| 293 | else { | ||
| 294 | lu->store_ctx = v; | ||
| 295 | if (sk_X509_LOOKUP_push(v->get_cert_methods, lu)) | ||
| 296 | return lu; | ||
| 297 | else { | ||
| 298 | X509_LOOKUP_free(lu); | ||
| 299 | return NULL; | ||
| 300 | } | ||
| 301 | } | ||
| 302 | } | ||
| 303 | |||
| 304 | int | ||
| 305 | X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name, | ||
| 306 | X509_OBJECT *ret) | ||
| 307 | { | ||
| 308 | X509_STORE *ctx = vs->ctx; | ||
| 309 | X509_LOOKUP *lu; | ||
| 310 | X509_OBJECT stmp, *tmp; | ||
| 311 | int i, j; | ||
| 312 | |||
| 313 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 314 | tmp = X509_OBJECT_retrieve_by_subject(ctx->objs, type, name); | ||
| 315 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 316 | |||
| 317 | if (tmp == NULL || type == X509_LU_CRL) { | ||
| 318 | for (i = vs->current_method; | ||
| 319 | i < sk_X509_LOOKUP_num(ctx->get_cert_methods); i++) { | ||
| 320 | lu = sk_X509_LOOKUP_value(ctx->get_cert_methods, i); | ||
| 321 | j = X509_LOOKUP_by_subject(lu, type, name, &stmp); | ||
| 322 | if (j < 0) { | ||
| 323 | vs->current_method = j; | ||
| 324 | return j; | ||
| 325 | } else if (j) { | ||
| 326 | tmp = &stmp; | ||
| 327 | break; | ||
| 328 | } | ||
| 329 | } | ||
| 330 | vs->current_method = 0; | ||
| 331 | if (tmp == NULL) | ||
| 332 | return 0; | ||
| 333 | } | ||
| 334 | |||
| 335 | /* if (ret->data.ptr != NULL) | ||
| 336 | X509_OBJECT_free_contents(ret); */ | ||
| 337 | |||
| 338 | ret->type = tmp->type; | ||
| 339 | ret->data.ptr = tmp->data.ptr; | ||
| 340 | |||
| 341 | X509_OBJECT_up_ref_count(ret); | ||
| 342 | |||
| 343 | return 1; | ||
| 344 | } | ||
| 345 | |||
| 346 | int | ||
| 347 | X509_STORE_add_cert(X509_STORE *ctx, X509 *x) | ||
| 348 | { | ||
| 349 | X509_OBJECT *obj; | ||
| 350 | int ret = 1; | ||
| 351 | |||
| 352 | if (x == NULL) | ||
| 353 | return 0; | ||
| 354 | obj = malloc(sizeof(X509_OBJECT)); | ||
| 355 | if (obj == NULL) { | ||
| 356 | X509err(X509_F_X509_STORE_ADD_CERT, ERR_R_MALLOC_FAILURE); | ||
| 357 | return 0; | ||
| 358 | } | ||
| 359 | obj->type = X509_LU_X509; | ||
| 360 | obj->data.x509 = x; | ||
| 361 | |||
| 362 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 363 | |||
| 364 | X509_OBJECT_up_ref_count(obj); | ||
| 365 | |||
| 366 | if (X509_OBJECT_retrieve_match(ctx->objs, obj)) { | ||
| 367 | X509_OBJECT_free_contents(obj); | ||
| 368 | free(obj); | ||
| 369 | X509err(X509_F_X509_STORE_ADD_CERT, | ||
| 370 | X509_R_CERT_ALREADY_IN_HASH_TABLE); | ||
| 371 | ret = 0; | ||
| 372 | } else | ||
| 373 | sk_X509_OBJECT_push(ctx->objs, obj); | ||
| 374 | |||
| 375 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 376 | |||
| 377 | return ret; | ||
| 378 | } | ||
| 379 | |||
| 380 | int | ||
| 381 | X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) | ||
| 382 | { | ||
| 383 | X509_OBJECT *obj; | ||
| 384 | int ret = 1; | ||
| 385 | |||
| 386 | if (x == NULL) | ||
| 387 | return 0; | ||
| 388 | obj = malloc(sizeof(X509_OBJECT)); | ||
| 389 | if (obj == NULL) { | ||
| 390 | X509err(X509_F_X509_STORE_ADD_CRL, ERR_R_MALLOC_FAILURE); | ||
| 391 | return 0; | ||
| 392 | } | ||
| 393 | obj->type = X509_LU_CRL; | ||
| 394 | obj->data.crl = x; | ||
| 395 | |||
| 396 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 397 | |||
| 398 | X509_OBJECT_up_ref_count(obj); | ||
| 399 | |||
| 400 | if (X509_OBJECT_retrieve_match(ctx->objs, obj)) { | ||
| 401 | X509_OBJECT_free_contents(obj); | ||
| 402 | free(obj); | ||
| 403 | X509err(X509_F_X509_STORE_ADD_CRL, | ||
| 404 | X509_R_CERT_ALREADY_IN_HASH_TABLE); | ||
| 405 | ret = 0; | ||
| 406 | } else | ||
| 407 | sk_X509_OBJECT_push(ctx->objs, obj); | ||
| 408 | |||
| 409 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 410 | |||
| 411 | return ret; | ||
| 412 | } | ||
| 413 | |||
| 414 | void | ||
| 415 | X509_OBJECT_up_ref_count(X509_OBJECT *a) | ||
| 416 | { | ||
| 417 | switch (a->type) { | ||
| 418 | case X509_LU_X509: | ||
| 419 | CRYPTO_add(&a->data.x509->references, 1, CRYPTO_LOCK_X509); | ||
| 420 | break; | ||
| 421 | case X509_LU_CRL: | ||
| 422 | CRYPTO_add(&a->data.crl->references, 1, CRYPTO_LOCK_X509_CRL); | ||
| 423 | break; | ||
| 424 | } | ||
| 425 | } | ||
| 426 | |||
| 427 | void | ||
| 428 | X509_OBJECT_free_contents(X509_OBJECT *a) | ||
| 429 | { | ||
| 430 | switch (a->type) { | ||
| 431 | case X509_LU_X509: | ||
| 432 | X509_free(a->data.x509); | ||
| 433 | break; | ||
| 434 | case X509_LU_CRL: | ||
| 435 | X509_CRL_free(a->data.crl); | ||
| 436 | break; | ||
| 437 | } | ||
| 438 | } | ||
| 439 | |||
| 440 | static int | ||
| 441 | x509_object_idx_cnt(STACK_OF(X509_OBJECT) *h, int type, X509_NAME *name, | ||
| 442 | int *pnmatch) | ||
| 443 | { | ||
| 444 | X509_OBJECT stmp; | ||
| 445 | X509 x509_s; | ||
| 446 | X509_CINF cinf_s; | ||
| 447 | X509_CRL crl_s; | ||
| 448 | X509_CRL_INFO crl_info_s; | ||
| 449 | int idx; | ||
| 450 | |||
| 451 | stmp.type = type; | ||
| 452 | switch (type) { | ||
| 453 | case X509_LU_X509: | ||
| 454 | stmp.data.x509 = &x509_s; | ||
| 455 | x509_s.cert_info = &cinf_s; | ||
| 456 | cinf_s.subject = name; | ||
| 457 | break; | ||
| 458 | case X509_LU_CRL: | ||
| 459 | stmp.data.crl = &crl_s; | ||
| 460 | crl_s.crl = &crl_info_s; | ||
| 461 | crl_info_s.issuer = name; | ||
| 462 | break; | ||
| 463 | default: | ||
| 464 | /* abort(); */ | ||
| 465 | return -1; | ||
| 466 | } | ||
| 467 | |||
| 468 | idx = sk_X509_OBJECT_find(h, &stmp); | ||
| 469 | if (idx >= 0 && pnmatch) { | ||
| 470 | int tidx; | ||
| 471 | const X509_OBJECT *tobj, *pstmp; | ||
| 472 | *pnmatch = 1; | ||
| 473 | pstmp = &stmp; | ||
| 474 | for (tidx = idx + 1; tidx < sk_X509_OBJECT_num(h); tidx++) { | ||
| 475 | tobj = sk_X509_OBJECT_value(h, tidx); | ||
| 476 | if (x509_object_cmp(&tobj, &pstmp)) | ||
| 477 | break; | ||
| 478 | (*pnmatch)++; | ||
| 479 | } | ||
| 480 | } | ||
| 481 | return idx; | ||
| 482 | } | ||
| 483 | |||
| 484 | int | ||
| 485 | X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type, X509_NAME *name) | ||
| 486 | { | ||
| 487 | return x509_object_idx_cnt(h, type, name, NULL); | ||
| 488 | } | ||
| 489 | |||
| 490 | X509_OBJECT * | ||
| 491 | X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, int type, | ||
| 492 | X509_NAME *name) | ||
| 493 | { | ||
| 494 | int idx; | ||
| 495 | |||
| 496 | idx = X509_OBJECT_idx_by_subject(h, type, name); | ||
| 497 | if (idx == -1) | ||
| 498 | return NULL; | ||
| 499 | return sk_X509_OBJECT_value(h, idx); | ||
| 500 | } | ||
| 501 | |||
| 502 | STACK_OF(X509) * | ||
| 503 | X509_STORE_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm) | ||
| 504 | { | ||
| 505 | int i, idx, cnt; | ||
| 506 | STACK_OF(X509) *sk; | ||
| 507 | X509 *x; | ||
| 508 | X509_OBJECT *obj; | ||
| 509 | |||
| 510 | sk = sk_X509_new_null(); | ||
| 511 | if (sk == NULL) | ||
| 512 | return NULL; | ||
| 513 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 514 | idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt); | ||
| 515 | if (idx < 0) { | ||
| 516 | /* Nothing found in cache: do lookup to possibly add new | ||
| 517 | * objects to cache | ||
| 518 | */ | ||
| 519 | X509_OBJECT xobj; | ||
| 520 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 521 | if (!X509_STORE_get_by_subject(ctx, X509_LU_X509, nm, &xobj)) { | ||
| 522 | sk_X509_free(sk); | ||
| 523 | return NULL; | ||
| 524 | } | ||
| 525 | X509_OBJECT_free_contents(&xobj); | ||
| 526 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 527 | idx = x509_object_idx_cnt(ctx->ctx->objs, | ||
| 528 | X509_LU_X509, nm, &cnt); | ||
| 529 | if (idx < 0) { | ||
| 530 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 531 | sk_X509_free(sk); | ||
| 532 | return NULL; | ||
| 533 | } | ||
| 534 | } | ||
| 535 | for (i = 0; i < cnt; i++, idx++) { | ||
| 536 | obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx); | ||
| 537 | x = obj->data.x509; | ||
| 538 | CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); | ||
| 539 | if (!sk_X509_push(sk, x)) { | ||
| 540 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 541 | X509_free(x); | ||
| 542 | sk_X509_pop_free(sk, X509_free); | ||
| 543 | return NULL; | ||
| 544 | } | ||
| 545 | } | ||
| 546 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 547 | return sk; | ||
| 548 | |||
| 549 | } | ||
| 550 | |||
| 551 | STACK_OF(X509_CRL) * | ||
| 552 | X509_STORE_get1_crls(X509_STORE_CTX *ctx, X509_NAME *nm) | ||
| 553 | { | ||
| 554 | int i, idx, cnt; | ||
| 555 | STACK_OF(X509_CRL) *sk; | ||
| 556 | X509_CRL *x; | ||
| 557 | X509_OBJECT *obj, xobj; | ||
| 558 | |||
| 559 | sk = sk_X509_CRL_new_null(); | ||
| 560 | if (sk == NULL) | ||
| 561 | return NULL; | ||
| 562 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 563 | /* Check cache first */ | ||
| 564 | idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_CRL, nm, &cnt); | ||
| 565 | |||
| 566 | /* Always do lookup to possibly add new CRLs to cache | ||
| 567 | */ | ||
| 568 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 569 | if (!X509_STORE_get_by_subject(ctx, X509_LU_CRL, nm, &xobj)) { | ||
| 570 | sk_X509_CRL_free(sk); | ||
| 571 | return NULL; | ||
| 572 | } | ||
| 573 | X509_OBJECT_free_contents(&xobj); | ||
| 574 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 575 | idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_CRL, nm, &cnt); | ||
| 576 | if (idx < 0) { | ||
| 577 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 578 | sk_X509_CRL_free(sk); | ||
| 579 | return NULL; | ||
| 580 | } | ||
| 581 | |||
| 582 | for (i = 0; i < cnt; i++, idx++) { | ||
| 583 | obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx); | ||
| 584 | x = obj->data.crl; | ||
| 585 | CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509_CRL); | ||
| 586 | if (!sk_X509_CRL_push(sk, x)) { | ||
| 587 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 588 | X509_CRL_free(x); | ||
| 589 | sk_X509_CRL_pop_free(sk, X509_CRL_free); | ||
| 590 | return NULL; | ||
| 591 | } | ||
| 592 | } | ||
| 593 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 594 | return sk; | ||
| 595 | } | ||
| 596 | |||
| 597 | X509_OBJECT * | ||
| 598 | X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x) | ||
| 599 | { | ||
| 600 | int idx, i; | ||
| 601 | X509_OBJECT *obj; | ||
| 602 | |||
| 603 | idx = sk_X509_OBJECT_find(h, x); | ||
| 604 | if (idx == -1) | ||
| 605 | return NULL; | ||
| 606 | if ((x->type != X509_LU_X509) && (x->type != X509_LU_CRL)) | ||
| 607 | return sk_X509_OBJECT_value(h, idx); | ||
| 608 | for (i = idx; i < sk_X509_OBJECT_num(h); i++) { | ||
| 609 | obj = sk_X509_OBJECT_value(h, i); | ||
| 610 | if (x509_object_cmp((const X509_OBJECT **)&obj, | ||
| 611 | (const X509_OBJECT **)&x)) | ||
| 612 | return NULL; | ||
| 613 | if (x->type == X509_LU_X509) { | ||
| 614 | if (!X509_cmp(obj->data.x509, x->data.x509)) | ||
| 615 | return obj; | ||
| 616 | } else if (x->type == X509_LU_CRL) { | ||
| 617 | if (!X509_CRL_match(obj->data.crl, x->data.crl)) | ||
| 618 | return obj; | ||
| 619 | } else | ||
| 620 | return obj; | ||
| 621 | } | ||
| 622 | return NULL; | ||
| 623 | } | ||
| 624 | |||
| 625 | |||
| 626 | /* Try to get issuer certificate from store. Due to limitations | ||
| 627 | * of the API this can only retrieve a single certificate matching | ||
| 628 | * a given subject name. However it will fill the cache with all | ||
| 629 | * matching certificates, so we can examine the cache for all | ||
| 630 | * matches. | ||
| 631 | * | ||
| 632 | * Return values are: | ||
| 633 | * 1 lookup successful. | ||
| 634 | * 0 certificate not found. | ||
| 635 | * -1 some other error. | ||
| 636 | */ | ||
| 637 | int | ||
| 638 | X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x) | ||
| 639 | { | ||
| 640 | X509_NAME *xn; | ||
| 641 | X509_OBJECT obj, *pobj; | ||
| 642 | int i, ok, idx, ret; | ||
| 643 | |||
| 644 | *issuer = NULL; | ||
| 645 | xn = X509_get_issuer_name(x); | ||
| 646 | ok = X509_STORE_get_by_subject(ctx, X509_LU_X509, xn, &obj); | ||
| 647 | if (ok != X509_LU_X509) { | ||
| 648 | if (ok == X509_LU_RETRY) { | ||
| 649 | X509_OBJECT_free_contents(&obj); | ||
| 650 | X509err(X509_F_X509_STORE_CTX_GET1_ISSUER, | ||
| 651 | X509_R_SHOULD_RETRY); | ||
| 652 | return -1; | ||
| 653 | } else if (ok != X509_LU_FAIL) { | ||
| 654 | X509_OBJECT_free_contents(&obj); | ||
| 655 | /* not good :-(, break anyway */ | ||
| 656 | return -1; | ||
| 657 | } | ||
| 658 | return 0; | ||
| 659 | } | ||
| 660 | /* If certificate matches all OK */ | ||
| 661 | if (ctx->check_issued(ctx, x, obj.data.x509)) { | ||
| 662 | if (x509_check_cert_time(ctx, obj.data.x509, 1)) { | ||
| 663 | *issuer = obj.data.x509; | ||
| 664 | return 1; | ||
| 665 | } | ||
| 666 | } | ||
| 667 | X509_OBJECT_free_contents(&obj); | ||
| 668 | |||
| 669 | /* Else find index of first cert accepted by 'check_issued' */ | ||
| 670 | ret = 0; | ||
| 671 | CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); | ||
| 672 | idx = X509_OBJECT_idx_by_subject(ctx->ctx->objs, X509_LU_X509, xn); | ||
| 673 | if (idx != -1) /* should be true as we've had at least one match */ { | ||
| 674 | /* Look through all matching certs for suitable issuer */ | ||
| 675 | for (i = idx; i < sk_X509_OBJECT_num(ctx->ctx->objs); i++) { | ||
| 676 | pobj = sk_X509_OBJECT_value(ctx->ctx->objs, i); | ||
| 677 | /* See if we've run past the matches */ | ||
| 678 | if (pobj->type != X509_LU_X509) | ||
| 679 | break; | ||
| 680 | if (X509_NAME_cmp(xn, | ||
| 681 | X509_get_subject_name(pobj->data.x509))) | ||
| 682 | break; | ||
| 683 | if (ctx->check_issued(ctx, x, pobj->data.x509)) { | ||
| 684 | *issuer = pobj->data.x509; | ||
| 685 | ret = 1; | ||
| 686 | /* | ||
| 687 | * If times check, exit with match, | ||
| 688 | * otherwise keep looking. Leave last | ||
| 689 | * match in issuer so we return nearest | ||
| 690 | * match if no certificate time is OK. | ||
| 691 | */ | ||
| 692 | if (x509_check_cert_time(ctx, *issuer, 1)) | ||
| 693 | break; | ||
| 694 | } | ||
| 695 | } | ||
| 696 | } | ||
| 697 | CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); | ||
| 698 | if (*issuer) | ||
| 699 | CRYPTO_add(&(*issuer)->references, 1, CRYPTO_LOCK_X509); | ||
| 700 | return ret; | ||
| 701 | } | ||
| 702 | |||
| 703 | int | ||
| 704 | X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags) | ||
| 705 | { | ||
| 706 | return X509_VERIFY_PARAM_set_flags(ctx->param, flags); | ||
| 707 | } | ||
| 708 | |||
| 709 | int | ||
| 710 | X509_STORE_set_depth(X509_STORE *ctx, int depth) | ||
| 711 | { | ||
| 712 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); | ||
| 713 | return 1; | ||
| 714 | } | ||
| 715 | |||
| 716 | int | ||
| 717 | X509_STORE_set_purpose(X509_STORE *ctx, int purpose) | ||
| 718 | { | ||
| 719 | return X509_VERIFY_PARAM_set_purpose(ctx->param, purpose); | ||
| 720 | } | ||
| 721 | |||
| 722 | int | ||
| 723 | X509_STORE_set_trust(X509_STORE *ctx, int trust) | ||
| 724 | { | ||
| 725 | return X509_VERIFY_PARAM_set_trust(ctx->param, trust); | ||
| 726 | } | ||
| 727 | |||
| 728 | int | ||
| 729 | X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *param) | ||
| 730 | { | ||
| 731 | return X509_VERIFY_PARAM_set1(ctx->param, param); | ||
| 732 | } | ||
| 733 | |||
| 734 | void | ||
| 735 | X509_STORE_set_verify_cb(X509_STORE *ctx, | ||
| 736 | int (*verify_cb)(int, X509_STORE_CTX *)) | ||
| 737 | { | ||
| 738 | ctx->verify_cb = verify_cb; | ||
| 739 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_obj.c b/src/lib/libcrypto/x509/x509_obj.c deleted file mode 100644 index f7f2a380a1..0000000000 --- a/src/lib/libcrypto/x509/x509_obj.c +++ /dev/null | |||
| @@ -1,179 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_obj.c,v 1.16 2014/07/11 08:44:49 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | |||
| 62 | #include <openssl/buffer.h> | ||
| 63 | #include <openssl/err.h> | ||
| 64 | #include <openssl/lhash.h> | ||
| 65 | #include <openssl/objects.h> | ||
| 66 | #include <openssl/x509.h> | ||
| 67 | |||
| 68 | char * | ||
| 69 | X509_NAME_oneline(X509_NAME *a, char *buf, int len) | ||
| 70 | { | ||
| 71 | X509_NAME_ENTRY *ne; | ||
| 72 | int i; | ||
| 73 | int n, lold, l, l1, l2, num, j, type; | ||
| 74 | const char *s; | ||
| 75 | char *p; | ||
| 76 | unsigned char *q; | ||
| 77 | BUF_MEM *b = NULL; | ||
| 78 | static const char hex[17] = "0123456789ABCDEF"; | ||
| 79 | int gs_doit[4]; | ||
| 80 | char tmp_buf[80]; | ||
| 81 | |||
| 82 | if (buf == NULL) { | ||
| 83 | if ((b = BUF_MEM_new()) == NULL) | ||
| 84 | goto err; | ||
| 85 | if (!BUF_MEM_grow(b, 200)) | ||
| 86 | goto err; | ||
| 87 | b->data[0] = '\0'; | ||
| 88 | len = 200; | ||
| 89 | } | ||
| 90 | if (a == NULL) { | ||
| 91 | if (b) { | ||
| 92 | buf = b->data; | ||
| 93 | free(b); | ||
| 94 | } | ||
| 95 | strlcpy(buf, "NO X509_NAME", len); | ||
| 96 | return buf; | ||
| 97 | } | ||
| 98 | |||
| 99 | len--; /* space for '\0' */ | ||
| 100 | l = 0; | ||
| 101 | for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { | ||
| 102 | ne = sk_X509_NAME_ENTRY_value(a->entries, i); | ||
| 103 | n = OBJ_obj2nid(ne->object); | ||
| 104 | if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) { | ||
| 105 | i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object); | ||
| 106 | s = tmp_buf; | ||
| 107 | } | ||
| 108 | l1 = strlen(s); | ||
| 109 | |||
| 110 | type = ne->value->type; | ||
| 111 | num = ne->value->length; | ||
| 112 | q = ne->value->data; | ||
| 113 | if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) { | ||
| 114 | gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0; | ||
| 115 | for (j = 0; j < num; j++) | ||
| 116 | if (q[j] != 0) | ||
| 117 | gs_doit[j & 3] = 1; | ||
| 118 | |||
| 119 | if (gs_doit[0]|gs_doit[1]|gs_doit[2]) | ||
| 120 | gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1; | ||
| 121 | else { | ||
| 122 | gs_doit[0] = gs_doit[1] = gs_doit[2] = 0; | ||
| 123 | gs_doit[3] = 1; | ||
| 124 | } | ||
| 125 | } else | ||
| 126 | gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1; | ||
| 127 | |||
| 128 | for (l2 = j=0; j < num; j++) { | ||
| 129 | if (!gs_doit[j&3]) | ||
| 130 | continue; | ||
| 131 | l2++; | ||
| 132 | if ((q[j] < ' ') || (q[j] > '~')) | ||
| 133 | l2 += 3; | ||
| 134 | } | ||
| 135 | |||
| 136 | lold = l; | ||
| 137 | l += 1 + l1 + 1 + l2; | ||
| 138 | if (b != NULL) { | ||
| 139 | if (!BUF_MEM_grow(b, l + 1)) | ||
| 140 | goto err; | ||
| 141 | p = &(b->data[lold]); | ||
| 142 | } else if (l > len) { | ||
| 143 | break; | ||
| 144 | } else | ||
| 145 | p = &(buf[lold]); | ||
| 146 | *(p++) = '/'; | ||
| 147 | memcpy(p, s, l1); | ||
| 148 | p += l1; | ||
| 149 | *(p++) = '='; | ||
| 150 | q = ne->value->data; | ||
| 151 | for (j = 0; j < num; j++) { | ||
| 152 | if (!gs_doit[j & 3]) | ||
| 153 | continue; | ||
| 154 | n = q[j]; | ||
| 155 | if ((n < ' ') || (n > '~')) { | ||
| 156 | *(p++) = '\\'; | ||
| 157 | *(p++) = 'x'; | ||
| 158 | *(p++) = hex[(n >> 4) & 0x0f]; | ||
| 159 | *(p++) = hex[n & 0x0f]; | ||
| 160 | } else | ||
| 161 | *(p++) = n; | ||
| 162 | } | ||
| 163 | *p = '\0'; | ||
| 164 | } | ||
| 165 | if (b != NULL) { | ||
| 166 | p = b->data; | ||
| 167 | free(b); | ||
| 168 | } else | ||
| 169 | p = buf; | ||
| 170 | if (i == 0) | ||
| 171 | *p = '\0'; | ||
| 172 | return (p); | ||
| 173 | |||
| 174 | err: | ||
| 175 | X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE); | ||
| 176 | if (b != NULL) | ||
| 177 | BUF_MEM_free(b); | ||
| 178 | return (NULL); | ||
| 179 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_r2x.c b/src/lib/libcrypto/x509/x509_r2x.c deleted file mode 100644 index 9a9a59d9bb..0000000000 --- a/src/lib/libcrypto/x509/x509_r2x.c +++ /dev/null | |||
| @@ -1,115 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_r2x.c,v 1.9 2014/07/11 08:44:49 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/bn.h> | ||
| 63 | #include <openssl/buffer.h> | ||
| 64 | #include <openssl/err.h> | ||
| 65 | #include <openssl/evp.h> | ||
| 66 | #include <openssl/objects.h> | ||
| 67 | #include <openssl/x509.h> | ||
| 68 | |||
| 69 | X509 * | ||
| 70 | X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey) | ||
| 71 | { | ||
| 72 | X509 *ret = NULL; | ||
| 73 | X509_CINF *xi = NULL; | ||
| 74 | X509_NAME *xn; | ||
| 75 | |||
| 76 | if ((ret = X509_new()) == NULL) { | ||
| 77 | X509err(X509_F_X509_REQ_TO_X509, ERR_R_MALLOC_FAILURE); | ||
| 78 | goto err; | ||
| 79 | } | ||
| 80 | |||
| 81 | /* duplicate the request */ | ||
| 82 | xi = ret->cert_info; | ||
| 83 | |||
| 84 | if (sk_X509_ATTRIBUTE_num(r->req_info->attributes) != 0) { | ||
| 85 | if ((xi->version = M_ASN1_INTEGER_new()) == NULL) | ||
| 86 | goto err; | ||
| 87 | if (!ASN1_INTEGER_set(xi->version, 2)) | ||
| 88 | goto err; | ||
| 89 | /* xi->extensions=ri->attributes; <- bad, should not ever be done | ||
| 90 | ri->attributes=NULL; */ | ||
| 91 | } | ||
| 92 | |||
| 93 | xn = X509_REQ_get_subject_name(r); | ||
| 94 | if (X509_set_subject_name(ret, X509_NAME_dup(xn)) == 0) | ||
| 95 | goto err; | ||
| 96 | if (X509_set_issuer_name(ret, X509_NAME_dup(xn)) == 0) | ||
| 97 | goto err; | ||
| 98 | |||
| 99 | if (X509_gmtime_adj(xi->validity->notBefore, 0) == NULL) | ||
| 100 | goto err; | ||
| 101 | if (X509_gmtime_adj(xi->validity->notAfter, | ||
| 102 | (long)60 * 60 * 24 * days) == NULL) | ||
| 103 | goto err; | ||
| 104 | |||
| 105 | X509_set_pubkey(ret, X509_REQ_get_pubkey(r)); | ||
| 106 | |||
| 107 | if (!X509_sign(ret, pkey, EVP_md5())) | ||
| 108 | goto err; | ||
| 109 | if (0) { | ||
| 110 | err: | ||
| 111 | X509_free(ret); | ||
| 112 | ret = NULL; | ||
| 113 | } | ||
| 114 | return (ret); | ||
| 115 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c deleted file mode 100644 index 8813f372cc..0000000000 --- a/src/lib/libcrypto/x509/x509_req.c +++ /dev/null | |||
| @@ -1,347 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_req.c,v 1.17 2015/03/15 22:52:17 doug Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/opensslconf.h> | ||
| 62 | |||
| 63 | #include <openssl/asn1.h> | ||
| 64 | #include <openssl/asn1t.h> | ||
| 65 | #include <openssl/bn.h> | ||
| 66 | #include <openssl/buffer.h> | ||
| 67 | #include <openssl/err.h> | ||
| 68 | #include <openssl/evp.h> | ||
| 69 | #include <openssl/objects.h> | ||
| 70 | #include <openssl/pem.h> | ||
| 71 | #include <openssl/x509.h> | ||
| 72 | |||
| 73 | X509_REQ * | ||
| 74 | X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) | ||
| 75 | { | ||
| 76 | X509_REQ *ret; | ||
| 77 | X509_REQ_INFO *ri; | ||
| 78 | int i; | ||
| 79 | EVP_PKEY *pktmp; | ||
| 80 | |||
| 81 | ret = X509_REQ_new(); | ||
| 82 | if (ret == NULL) { | ||
| 83 | X509err(X509_F_X509_TO_X509_REQ, ERR_R_MALLOC_FAILURE); | ||
| 84 | goto err; | ||
| 85 | } | ||
| 86 | |||
| 87 | ri = ret->req_info; | ||
| 88 | |||
| 89 | if ((ri->version = M_ASN1_INTEGER_new()) == NULL) | ||
| 90 | goto err; | ||
| 91 | if (ASN1_INTEGER_set(ri->version, 0) == 0) | ||
| 92 | goto err; | ||
| 93 | |||
| 94 | if (!X509_REQ_set_subject_name(ret, X509_get_subject_name(x))) | ||
| 95 | goto err; | ||
| 96 | |||
| 97 | if ((pktmp = X509_get_pubkey(x)) == NULL) | ||
| 98 | goto err; | ||
| 99 | |||
| 100 | i = X509_REQ_set_pubkey(ret, pktmp); | ||
| 101 | EVP_PKEY_free(pktmp); | ||
| 102 | if (!i) | ||
| 103 | goto err; | ||
| 104 | |||
| 105 | if (pkey != NULL) { | ||
| 106 | if (!X509_REQ_sign(ret, pkey, md)) | ||
| 107 | goto err; | ||
| 108 | } | ||
| 109 | return (ret); | ||
| 110 | |||
| 111 | err: | ||
| 112 | X509_REQ_free(ret); | ||
| 113 | return (NULL); | ||
| 114 | } | ||
| 115 | |||
| 116 | EVP_PKEY * | ||
| 117 | X509_REQ_get_pubkey(X509_REQ *req) | ||
| 118 | { | ||
| 119 | if ((req == NULL) || (req->req_info == NULL)) | ||
| 120 | return (NULL); | ||
| 121 | return (X509_PUBKEY_get(req->req_info->pubkey)); | ||
| 122 | } | ||
| 123 | |||
| 124 | int | ||
| 125 | X509_REQ_check_private_key(X509_REQ *x, EVP_PKEY *k) | ||
| 126 | { | ||
| 127 | EVP_PKEY *xk = NULL; | ||
| 128 | int ok = 0; | ||
| 129 | |||
| 130 | xk = X509_REQ_get_pubkey(x); | ||
| 131 | switch (EVP_PKEY_cmp(xk, k)) { | ||
| 132 | case 1: | ||
| 133 | ok = 1; | ||
| 134 | break; | ||
| 135 | case 0: | ||
| 136 | X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, | ||
| 137 | X509_R_KEY_VALUES_MISMATCH); | ||
| 138 | break; | ||
| 139 | case -1: | ||
| 140 | X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, | ||
| 141 | X509_R_KEY_TYPE_MISMATCH); | ||
| 142 | break; | ||
| 143 | case -2: | ||
| 144 | #ifndef OPENSSL_NO_EC | ||
| 145 | if (k->type == EVP_PKEY_EC) { | ||
| 146 | X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, | ||
| 147 | ERR_R_EC_LIB); | ||
| 148 | break; | ||
| 149 | } | ||
| 150 | #endif | ||
| 151 | #ifndef OPENSSL_NO_DH | ||
| 152 | if (k->type == EVP_PKEY_DH) { | ||
| 153 | /* No idea */ | ||
| 154 | X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, | ||
| 155 | X509_R_CANT_CHECK_DH_KEY); | ||
| 156 | break; | ||
| 157 | } | ||
| 158 | #endif | ||
| 159 | X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, | ||
| 160 | X509_R_UNKNOWN_KEY_TYPE); | ||
| 161 | } | ||
| 162 | |||
| 163 | EVP_PKEY_free(xk); | ||
| 164 | return (ok); | ||
| 165 | } | ||
| 166 | |||
| 167 | /* It seems several organisations had the same idea of including a list of | ||
| 168 | * extensions in a certificate request. There are at least two OIDs that are | ||
| 169 | * used and there may be more: so the list is configurable. | ||
| 170 | */ | ||
| 171 | |||
| 172 | static int ext_nid_list[] = {NID_ext_req, NID_ms_ext_req, NID_undef}; | ||
| 173 | |||
| 174 | static int *ext_nids = ext_nid_list; | ||
| 175 | |||
| 176 | int | ||
| 177 | X509_REQ_extension_nid(int req_nid) | ||
| 178 | { | ||
| 179 | int i, nid; | ||
| 180 | |||
| 181 | for (i = 0; ; i++) { | ||
| 182 | nid = ext_nids[i]; | ||
| 183 | if (nid == NID_undef) | ||
| 184 | return 0; | ||
| 185 | else if (req_nid == nid) | ||
| 186 | return 1; | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | int * | ||
| 191 | X509_REQ_get_extension_nids(void) | ||
| 192 | { | ||
| 193 | return ext_nids; | ||
| 194 | } | ||
| 195 | |||
| 196 | void | ||
| 197 | X509_REQ_set_extension_nids(int *nids) | ||
| 198 | { | ||
| 199 | ext_nids = nids; | ||
| 200 | } | ||
| 201 | |||
| 202 | STACK_OF(X509_EXTENSION) * | ||
| 203 | X509_REQ_get_extensions(X509_REQ *req) | ||
| 204 | { | ||
| 205 | X509_ATTRIBUTE *attr; | ||
| 206 | ASN1_TYPE *ext = NULL; | ||
| 207 | int idx, *pnid; | ||
| 208 | const unsigned char *p; | ||
| 209 | |||
| 210 | if ((req == NULL) || (req->req_info == NULL) || !ext_nids) | ||
| 211 | return (NULL); | ||
| 212 | for (pnid = ext_nids; *pnid != NID_undef; pnid++) { | ||
| 213 | idx = X509_REQ_get_attr_by_NID(req, *pnid, -1); | ||
| 214 | if (idx == -1) | ||
| 215 | continue; | ||
| 216 | attr = X509_REQ_get_attr(req, idx); | ||
| 217 | if (attr->single) | ||
| 218 | ext = attr->value.single; | ||
| 219 | else if (sk_ASN1_TYPE_num(attr->value.set)) | ||
| 220 | ext = sk_ASN1_TYPE_value(attr->value.set, 0); | ||
| 221 | break; | ||
| 222 | } | ||
| 223 | if (!ext || (ext->type != V_ASN1_SEQUENCE)) | ||
| 224 | return NULL; | ||
| 225 | p = ext->value.sequence->data; | ||
| 226 | return (STACK_OF(X509_EXTENSION) *)ASN1_item_d2i(NULL, &p, | ||
| 227 | ext->value.sequence->length, ASN1_ITEM_rptr(X509_EXTENSIONS)); | ||
| 228 | } | ||
| 229 | |||
| 230 | /* Add a STACK_OF extensions to a certificate request: allow alternative OIDs | ||
| 231 | * in case we want to create a non standard one. | ||
| 232 | */ | ||
| 233 | |||
| 234 | int | ||
| 235 | X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts, | ||
| 236 | int nid) | ||
| 237 | { | ||
| 238 | ASN1_TYPE *at = NULL; | ||
| 239 | X509_ATTRIBUTE *attr = NULL; | ||
| 240 | |||
| 241 | if (!(at = ASN1_TYPE_new()) || | ||
| 242 | !(at->value.sequence = ASN1_STRING_new())) | ||
| 243 | goto err; | ||
| 244 | |||
| 245 | at->type = V_ASN1_SEQUENCE; | ||
| 246 | /* Generate encoding of extensions */ | ||
| 247 | at->value.sequence->length = ASN1_item_i2d((ASN1_VALUE *)exts, | ||
| 248 | &at->value.sequence->data, ASN1_ITEM_rptr(X509_EXTENSIONS)); | ||
| 249 | if (!(attr = X509_ATTRIBUTE_new())) | ||
| 250 | goto err; | ||
| 251 | if (!(attr->value.set = sk_ASN1_TYPE_new_null())) | ||
| 252 | goto err; | ||
| 253 | if (!sk_ASN1_TYPE_push(attr->value.set, at)) | ||
| 254 | goto err; | ||
| 255 | at = NULL; | ||
| 256 | attr->single = 0; | ||
| 257 | attr->object = OBJ_nid2obj(nid); | ||
| 258 | if (!req->req_info->attributes) { | ||
| 259 | if (!(req->req_info->attributes = sk_X509_ATTRIBUTE_new_null())) | ||
| 260 | goto err; | ||
| 261 | } | ||
| 262 | if (!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) | ||
| 263 | goto err; | ||
| 264 | return 1; | ||
| 265 | |||
| 266 | err: | ||
| 267 | X509_ATTRIBUTE_free(attr); | ||
| 268 | ASN1_TYPE_free(at); | ||
| 269 | return 0; | ||
| 270 | } | ||
| 271 | |||
| 272 | /* This is the normal usage: use the "official" OID */ | ||
| 273 | int | ||
| 274 | X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts) | ||
| 275 | { | ||
| 276 | return X509_REQ_add_extensions_nid(req, exts, NID_ext_req); | ||
| 277 | } | ||
| 278 | |||
| 279 | /* Request attribute functions */ | ||
| 280 | |||
| 281 | int | ||
| 282 | X509_REQ_get_attr_count(const X509_REQ *req) | ||
| 283 | { | ||
| 284 | return X509at_get_attr_count(req->req_info->attributes); | ||
| 285 | } | ||
| 286 | |||
| 287 | int | ||
| 288 | X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid, int lastpos) | ||
| 289 | { | ||
| 290 | return X509at_get_attr_by_NID(req->req_info->attributes, nid, lastpos); | ||
| 291 | } | ||
| 292 | |||
| 293 | int | ||
| 294 | X509_REQ_get_attr_by_OBJ(const X509_REQ *req, ASN1_OBJECT *obj, int lastpos) | ||
| 295 | { | ||
| 296 | return X509at_get_attr_by_OBJ(req->req_info->attributes, obj, lastpos); | ||
| 297 | } | ||
| 298 | |||
| 299 | X509_ATTRIBUTE * | ||
| 300 | X509_REQ_get_attr(const X509_REQ *req, int loc) | ||
| 301 | { | ||
| 302 | return X509at_get_attr(req->req_info->attributes, loc); | ||
| 303 | } | ||
| 304 | |||
| 305 | X509_ATTRIBUTE * | ||
| 306 | X509_REQ_delete_attr(X509_REQ *req, int loc) | ||
| 307 | { | ||
| 308 | return X509at_delete_attr(req->req_info->attributes, loc); | ||
| 309 | } | ||
| 310 | |||
| 311 | int | ||
| 312 | X509_REQ_add1_attr(X509_REQ *req, X509_ATTRIBUTE *attr) | ||
| 313 | { | ||
| 314 | if (X509at_add1_attr(&req->req_info->attributes, attr)) | ||
| 315 | return 1; | ||
| 316 | return 0; | ||
| 317 | } | ||
| 318 | |||
| 319 | int | ||
| 320 | X509_REQ_add1_attr_by_OBJ(X509_REQ *req, const ASN1_OBJECT *obj, int type, | ||
| 321 | const unsigned char *bytes, int len) | ||
| 322 | { | ||
| 323 | if (X509at_add1_attr_by_OBJ(&req->req_info->attributes, obj, | ||
| 324 | type, bytes, len)) | ||
| 325 | return 1; | ||
| 326 | return 0; | ||
| 327 | } | ||
| 328 | |||
| 329 | int | ||
| 330 | X509_REQ_add1_attr_by_NID(X509_REQ *req, int nid, int type, | ||
| 331 | const unsigned char *bytes, int len) | ||
| 332 | { | ||
| 333 | if (X509at_add1_attr_by_NID(&req->req_info->attributes, nid, | ||
| 334 | type, bytes, len)) | ||
| 335 | return 1; | ||
| 336 | return 0; | ||
| 337 | } | ||
| 338 | |||
| 339 | int | ||
| 340 | X509_REQ_add1_attr_by_txt(X509_REQ *req, const char *attrname, int type, | ||
| 341 | const unsigned char *bytes, int len) | ||
| 342 | { | ||
| 343 | if (X509at_add1_attr_by_txt(&req->req_info->attributes, attrname, | ||
| 344 | type, bytes, len)) | ||
| 345 | return 1; | ||
| 346 | return 0; | ||
| 347 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_set.c b/src/lib/libcrypto/x509/x509_set.c deleted file mode 100644 index c6160b90b0..0000000000 --- a/src/lib/libcrypto/x509/x509_set.c +++ /dev/null | |||
| @@ -1,154 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_set.c,v 1.10 2015/07/29 14:58:34 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/evp.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | |||
| 66 | int | ||
| 67 | X509_set_version(X509 *x, long version) | ||
| 68 | { | ||
| 69 | if (x == NULL) | ||
| 70 | return (0); | ||
| 71 | if (x->cert_info->version == NULL) { | ||
| 72 | if ((x->cert_info->version = M_ASN1_INTEGER_new()) == NULL) | ||
| 73 | return (0); | ||
| 74 | } | ||
| 75 | return (ASN1_INTEGER_set(x->cert_info->version, version)); | ||
| 76 | } | ||
| 77 | |||
| 78 | int | ||
| 79 | X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial) | ||
| 80 | { | ||
| 81 | ASN1_INTEGER *in; | ||
| 82 | |||
| 83 | if (x == NULL) | ||
| 84 | return (0); | ||
| 85 | in = x->cert_info->serialNumber; | ||
| 86 | if (in != serial) { | ||
| 87 | in = ASN1_STRING_dup(serial); | ||
| 88 | if (in != NULL) { | ||
| 89 | M_ASN1_INTEGER_free(x->cert_info->serialNumber); | ||
| 90 | x->cert_info->serialNumber = in; | ||
| 91 | } | ||
| 92 | } | ||
| 93 | return (in != NULL); | ||
| 94 | } | ||
| 95 | |||
| 96 | int | ||
| 97 | X509_set_issuer_name(X509 *x, X509_NAME *name) | ||
| 98 | { | ||
| 99 | if ((x == NULL) || (x->cert_info == NULL)) | ||
| 100 | return (0); | ||
| 101 | return (X509_NAME_set(&x->cert_info->issuer, name)); | ||
| 102 | } | ||
| 103 | |||
| 104 | int | ||
| 105 | X509_set_subject_name(X509 *x, X509_NAME *name) | ||
| 106 | { | ||
| 107 | if ((x == NULL) || (x->cert_info == NULL)) | ||
| 108 | return (0); | ||
| 109 | return (X509_NAME_set(&x->cert_info->subject, name)); | ||
| 110 | } | ||
| 111 | |||
| 112 | int | ||
| 113 | X509_set_notBefore(X509 *x, const ASN1_TIME *tm) | ||
| 114 | { | ||
| 115 | ASN1_TIME *in; | ||
| 116 | |||
| 117 | if ((x == NULL) || (x->cert_info->validity == NULL)) | ||
| 118 | return (0); | ||
| 119 | in = x->cert_info->validity->notBefore; | ||
| 120 | if (in != tm) { | ||
| 121 | in = ASN1_STRING_dup(tm); | ||
| 122 | if (in != NULL) { | ||
| 123 | M_ASN1_TIME_free(x->cert_info->validity->notBefore); | ||
| 124 | x->cert_info->validity->notBefore = in; | ||
| 125 | } | ||
| 126 | } | ||
| 127 | return (in != NULL); | ||
| 128 | } | ||
| 129 | |||
| 130 | int | ||
| 131 | X509_set_notAfter(X509 *x, const ASN1_TIME *tm) | ||
| 132 | { | ||
| 133 | ASN1_TIME *in; | ||
| 134 | |||
| 135 | if ((x == NULL) || (x->cert_info->validity == NULL)) | ||
| 136 | return (0); | ||
| 137 | in = x->cert_info->validity->notAfter; | ||
| 138 | if (in != tm) { | ||
| 139 | in = ASN1_STRING_dup(tm); | ||
| 140 | if (in != NULL) { | ||
| 141 | M_ASN1_TIME_free(x->cert_info->validity->notAfter); | ||
| 142 | x->cert_info->validity->notAfter = in; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | return (in != NULL); | ||
| 146 | } | ||
| 147 | |||
| 148 | int | ||
| 149 | X509_set_pubkey(X509 *x, EVP_PKEY *pkey) | ||
| 150 | { | ||
| 151 | if ((x == NULL) || (x->cert_info == NULL)) | ||
| 152 | return (0); | ||
| 153 | return (X509_PUBKEY_set(&(x->cert_info->key), pkey)); | ||
| 154 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c deleted file mode 100644 index 42fb97f571..0000000000 --- a/src/lib/libcrypto/x509/x509_trs.c +++ /dev/null | |||
| @@ -1,332 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_trs.c,v 1.20 2015/02/10 11:22:21 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/err.h> | ||
| 63 | #include <openssl/x509v3.h> | ||
| 64 | |||
| 65 | static int tr_cmp(const X509_TRUST * const *a, const X509_TRUST * const *b); | ||
| 66 | static void trtable_free(X509_TRUST *p); | ||
| 67 | |||
| 68 | static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags); | ||
| 69 | static int trust_1oid(X509_TRUST *trust, X509 *x, int flags); | ||
| 70 | static int trust_compat(X509_TRUST *trust, X509 *x, int flags); | ||
| 71 | |||
| 72 | static int obj_trust(int id, X509 *x, int flags); | ||
| 73 | static int (*default_trust)(int id, X509 *x, int flags) = obj_trust; | ||
| 74 | |||
| 75 | /* WARNING: the following table should be kept in order of trust | ||
| 76 | * and without any gaps so we can just subtract the minimum trust | ||
| 77 | * value to get an index into the table | ||
| 78 | */ | ||
| 79 | |||
| 80 | static X509_TRUST trstandard[] = { | ||
| 81 | {X509_TRUST_COMPAT, 0, trust_compat, "compatible", 0, NULL}, | ||
| 82 | {X509_TRUST_SSL_CLIENT, 0, trust_1oidany, "SSL Client", NID_client_auth, NULL}, | ||
| 83 | {X509_TRUST_SSL_SERVER, 0, trust_1oidany, "SSL Server", NID_server_auth, NULL}, | ||
| 84 | {X509_TRUST_EMAIL, 0, trust_1oidany, "S/MIME email", NID_email_protect, NULL}, | ||
| 85 | {X509_TRUST_OBJECT_SIGN, 0, trust_1oidany, "Object Signer", NID_code_sign, NULL}, | ||
| 86 | {X509_TRUST_OCSP_SIGN, 0, trust_1oid, "OCSP responder", NID_OCSP_sign, NULL}, | ||
| 87 | {X509_TRUST_OCSP_REQUEST, 0, trust_1oid, "OCSP request", NID_ad_OCSP, NULL}, | ||
| 88 | {X509_TRUST_TSA, 0, trust_1oidany, "TSA server", NID_time_stamp, NULL} | ||
| 89 | }; | ||
| 90 | |||
| 91 | #define X509_TRUST_COUNT (sizeof(trstandard)/sizeof(X509_TRUST)) | ||
| 92 | |||
| 93 | static STACK_OF(X509_TRUST) *trtable = NULL; | ||
| 94 | |||
| 95 | static int | ||
| 96 | tr_cmp(const X509_TRUST * const *a, const X509_TRUST * const *b) | ||
| 97 | { | ||
| 98 | return (*a)->trust - (*b)->trust; | ||
| 99 | } | ||
| 100 | |||
| 101 | int | ||
| 102 | (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int) | ||
| 103 | { | ||
| 104 | int (*oldtrust)(int , X509 *, int); | ||
| 105 | |||
| 106 | oldtrust = default_trust; | ||
| 107 | default_trust = trust; | ||
| 108 | return oldtrust; | ||
| 109 | } | ||
| 110 | |||
| 111 | int | ||
| 112 | X509_check_trust(X509 *x, int id, int flags) | ||
| 113 | { | ||
| 114 | X509_TRUST *pt; | ||
| 115 | int idx; | ||
| 116 | |||
| 117 | if (id == -1) | ||
| 118 | return 1; | ||
| 119 | idx = X509_TRUST_get_by_id(id); | ||
| 120 | if (idx == -1) | ||
| 121 | return default_trust(id, x, flags); | ||
| 122 | pt = X509_TRUST_get0(idx); | ||
| 123 | return pt->check_trust(pt, x, flags); | ||
| 124 | } | ||
| 125 | |||
| 126 | int | ||
| 127 | X509_TRUST_get_count(void) | ||
| 128 | { | ||
| 129 | if (!trtable) | ||
| 130 | return X509_TRUST_COUNT; | ||
| 131 | return sk_X509_TRUST_num(trtable) + X509_TRUST_COUNT; | ||
| 132 | } | ||
| 133 | |||
| 134 | X509_TRUST * | ||
| 135 | X509_TRUST_get0(int idx) | ||
| 136 | { | ||
| 137 | if (idx < 0) | ||
| 138 | return NULL; | ||
| 139 | if (idx < (int)X509_TRUST_COUNT) | ||
| 140 | return trstandard + idx; | ||
| 141 | return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT); | ||
| 142 | } | ||
| 143 | |||
| 144 | int | ||
| 145 | X509_TRUST_get_by_id(int id) | ||
| 146 | { | ||
| 147 | X509_TRUST tmp; | ||
| 148 | int idx; | ||
| 149 | |||
| 150 | if ((id >= X509_TRUST_MIN) && (id <= X509_TRUST_MAX)) | ||
| 151 | return id - X509_TRUST_MIN; | ||
| 152 | tmp.trust = id; | ||
| 153 | if (!trtable) | ||
| 154 | return -1; | ||
| 155 | idx = sk_X509_TRUST_find(trtable, &tmp); | ||
| 156 | if (idx == -1) | ||
| 157 | return -1; | ||
| 158 | return idx + X509_TRUST_COUNT; | ||
| 159 | } | ||
| 160 | |||
| 161 | int | ||
| 162 | X509_TRUST_set(int *t, int trust) | ||
| 163 | { | ||
| 164 | if (X509_TRUST_get_by_id(trust) == -1) { | ||
| 165 | X509err(X509_F_X509_TRUST_SET, X509_R_INVALID_TRUST); | ||
| 166 | return 0; | ||
| 167 | } | ||
| 168 | *t = trust; | ||
| 169 | return 1; | ||
| 170 | } | ||
| 171 | |||
| 172 | int | ||
| 173 | X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int), | ||
| 174 | char *name, int arg1, void *arg2) | ||
| 175 | { | ||
| 176 | int idx; | ||
| 177 | X509_TRUST *trtmp; | ||
| 178 | char *name_dup; | ||
| 179 | |||
| 180 | /* This is set according to what we change: application can't set it */ | ||
| 181 | flags &= ~X509_TRUST_DYNAMIC; | ||
| 182 | /* This will always be set for application modified trust entries */ | ||
| 183 | flags |= X509_TRUST_DYNAMIC_NAME; | ||
| 184 | /* Get existing entry if any */ | ||
| 185 | idx = X509_TRUST_get_by_id(id); | ||
| 186 | /* Need a new entry */ | ||
| 187 | if (idx == -1) { | ||
| 188 | if (!(trtmp = malloc(sizeof(X509_TRUST)))) { | ||
| 189 | X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE); | ||
| 190 | return 0; | ||
| 191 | } | ||
| 192 | trtmp->flags = X509_TRUST_DYNAMIC; | ||
| 193 | } else { | ||
| 194 | trtmp = X509_TRUST_get0(idx); | ||
| 195 | if (trtmp == NULL) { | ||
| 196 | X509err(X509_F_X509_TRUST_ADD, X509_R_INVALID_TRUST); | ||
| 197 | return 0; | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | if ((name_dup = strdup(name)) == NULL) | ||
| 202 | goto err; | ||
| 203 | |||
| 204 | /* free existing name if dynamic */ | ||
| 205 | if (trtmp->flags & X509_TRUST_DYNAMIC_NAME) | ||
| 206 | free(trtmp->name); | ||
| 207 | /* dup supplied name */ | ||
| 208 | trtmp->name = name_dup; | ||
| 209 | /* Keep the dynamic flag of existing entry */ | ||
| 210 | trtmp->flags &= X509_TRUST_DYNAMIC; | ||
| 211 | /* Set all other flags */ | ||
| 212 | trtmp->flags |= flags; | ||
| 213 | |||
| 214 | trtmp->trust = id; | ||
| 215 | trtmp->check_trust = ck; | ||
| 216 | trtmp->arg1 = arg1; | ||
| 217 | trtmp->arg2 = arg2; | ||
| 218 | |||
| 219 | /* If it's a new entry, manage the dynamic table */ | ||
| 220 | if (idx == -1) { | ||
| 221 | if (trtable == NULL && | ||
| 222 | (trtable = sk_X509_TRUST_new(tr_cmp)) == NULL) | ||
| 223 | goto err; | ||
| 224 | if (sk_X509_TRUST_push(trtable, trtmp) == 0) | ||
| 225 | goto err; | ||
| 226 | } | ||
| 227 | return 1; | ||
| 228 | |||
| 229 | err: | ||
| 230 | free(name_dup); | ||
| 231 | if (idx == -1) | ||
| 232 | free(trtmp); | ||
| 233 | X509err(X509_F_X509_TRUST_ADD, ERR_R_MALLOC_FAILURE); | ||
| 234 | return 0; | ||
| 235 | } | ||
| 236 | |||
| 237 | static void | ||
| 238 | trtable_free(X509_TRUST *p) | ||
| 239 | { | ||
| 240 | if (!p) | ||
| 241 | return; | ||
| 242 | if (p->flags & X509_TRUST_DYNAMIC) { | ||
| 243 | if (p->flags & X509_TRUST_DYNAMIC_NAME) | ||
| 244 | free(p->name); | ||
| 245 | free(p); | ||
| 246 | } | ||
| 247 | } | ||
| 248 | |||
| 249 | void | ||
| 250 | X509_TRUST_cleanup(void) | ||
| 251 | { | ||
| 252 | unsigned int i; | ||
| 253 | |||
| 254 | for (i = 0; i < X509_TRUST_COUNT; i++) | ||
| 255 | trtable_free(trstandard + i); | ||
| 256 | sk_X509_TRUST_pop_free(trtable, trtable_free); | ||
| 257 | trtable = NULL; | ||
| 258 | } | ||
| 259 | |||
| 260 | int | ||
| 261 | X509_TRUST_get_flags(X509_TRUST *xp) | ||
| 262 | { | ||
| 263 | return xp->flags; | ||
| 264 | } | ||
| 265 | |||
| 266 | char * | ||
| 267 | X509_TRUST_get0_name(X509_TRUST *xp) | ||
| 268 | { | ||
| 269 | return xp->name; | ||
| 270 | } | ||
| 271 | |||
| 272 | int | ||
| 273 | X509_TRUST_get_trust(X509_TRUST *xp) | ||
| 274 | { | ||
| 275 | return xp->trust; | ||
| 276 | } | ||
| 277 | |||
| 278 | static int | ||
| 279 | trust_1oidany(X509_TRUST *trust, X509 *x, int flags) | ||
| 280 | { | ||
| 281 | if (x->aux && (x->aux->trust || x->aux->reject)) | ||
| 282 | return obj_trust(trust->arg1, x, flags); | ||
| 283 | /* we don't have any trust settings: for compatibility | ||
| 284 | * we return trusted if it is self signed | ||
| 285 | */ | ||
| 286 | return trust_compat(trust, x, flags); | ||
| 287 | } | ||
| 288 | |||
| 289 | static int | ||
| 290 | trust_1oid(X509_TRUST *trust, X509 *x, int flags) | ||
| 291 | { | ||
| 292 | if (x->aux) | ||
| 293 | return obj_trust(trust->arg1, x, flags); | ||
| 294 | return X509_TRUST_UNTRUSTED; | ||
| 295 | } | ||
| 296 | |||
| 297 | static int | ||
| 298 | trust_compat(X509_TRUST *trust, X509 *x, int flags) | ||
| 299 | { | ||
| 300 | X509_check_purpose(x, -1, 0); | ||
| 301 | if (x->ex_flags & EXFLAG_SS) | ||
| 302 | return X509_TRUST_TRUSTED; | ||
| 303 | else | ||
| 304 | return X509_TRUST_UNTRUSTED; | ||
| 305 | } | ||
| 306 | |||
| 307 | static int | ||
| 308 | obj_trust(int id, X509 *x, int flags) | ||
| 309 | { | ||
| 310 | ASN1_OBJECT *obj; | ||
| 311 | int i; | ||
| 312 | X509_CERT_AUX *ax; | ||
| 313 | |||
| 314 | ax = x->aux; | ||
| 315 | if (!ax) | ||
| 316 | return X509_TRUST_UNTRUSTED; | ||
| 317 | if (ax->reject) { | ||
| 318 | for (i = 0; i < sk_ASN1_OBJECT_num(ax->reject); i++) { | ||
| 319 | obj = sk_ASN1_OBJECT_value(ax->reject, i); | ||
| 320 | if (OBJ_obj2nid(obj) == id) | ||
| 321 | return X509_TRUST_REJECTED; | ||
| 322 | } | ||
| 323 | } | ||
| 324 | if (ax->trust) { | ||
| 325 | for (i = 0; i < sk_ASN1_OBJECT_num(ax->trust); i++) { | ||
| 326 | obj = sk_ASN1_OBJECT_value(ax->trust, i); | ||
| 327 | if (OBJ_obj2nid(obj) == id) | ||
| 328 | return X509_TRUST_TRUSTED; | ||
| 329 | } | ||
| 330 | } | ||
| 331 | return X509_TRUST_UNTRUSTED; | ||
| 332 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_txt.c b/src/lib/libcrypto/x509/x509_txt.c deleted file mode 100644 index 14fa2378c4..0000000000 --- a/src/lib/libcrypto/x509/x509_txt.c +++ /dev/null | |||
| @@ -1,189 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_txt.c,v 1.19 2014/07/11 08:44:49 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | #include <time.h> | ||
| 62 | |||
| 63 | #include <openssl/asn1.h> | ||
| 64 | #include <openssl/buffer.h> | ||
| 65 | #include <openssl/evp.h> | ||
| 66 | #include <openssl/lhash.h> | ||
| 67 | #include <openssl/objects.h> | ||
| 68 | #include <openssl/x509.h> | ||
| 69 | |||
| 70 | const char * | ||
| 71 | X509_verify_cert_error_string(long n) | ||
| 72 | { | ||
| 73 | static char buf[100]; | ||
| 74 | |||
| 75 | switch ((int)n) { | ||
| 76 | case X509_V_OK: | ||
| 77 | return("ok"); | ||
| 78 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: | ||
| 79 | return("unable to get issuer certificate"); | ||
| 80 | case X509_V_ERR_UNABLE_TO_GET_CRL: | ||
| 81 | return("unable to get certificate CRL"); | ||
| 82 | case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: | ||
| 83 | return("unable to decrypt certificate's signature"); | ||
| 84 | case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: | ||
| 85 | return("unable to decrypt CRL's signature"); | ||
| 86 | case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: | ||
| 87 | return("unable to decode issuer public key"); | ||
| 88 | case X509_V_ERR_CERT_SIGNATURE_FAILURE: | ||
| 89 | return("certificate signature failure"); | ||
| 90 | case X509_V_ERR_CRL_SIGNATURE_FAILURE: | ||
| 91 | return("CRL signature failure"); | ||
| 92 | case X509_V_ERR_CERT_NOT_YET_VALID: | ||
| 93 | return("certificate is not yet valid"); | ||
| 94 | case X509_V_ERR_CRL_NOT_YET_VALID: | ||
| 95 | return("CRL is not yet valid"); | ||
| 96 | case X509_V_ERR_CERT_HAS_EXPIRED: | ||
| 97 | return("certificate has expired"); | ||
| 98 | case X509_V_ERR_CRL_HAS_EXPIRED: | ||
| 99 | return("CRL has expired"); | ||
| 100 | case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: | ||
| 101 | return("format error in certificate's notBefore field"); | ||
| 102 | case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: | ||
| 103 | return("format error in certificate's notAfter field"); | ||
| 104 | case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: | ||
| 105 | return("format error in CRL's lastUpdate field"); | ||
| 106 | case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: | ||
| 107 | return("format error in CRL's nextUpdate field"); | ||
| 108 | case X509_V_ERR_OUT_OF_MEM: | ||
| 109 | return("out of memory"); | ||
| 110 | case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: | ||
| 111 | return("self signed certificate"); | ||
| 112 | case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: | ||
| 113 | return("self signed certificate in certificate chain"); | ||
| 114 | case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: | ||
| 115 | return("unable to get local issuer certificate"); | ||
| 116 | case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: | ||
| 117 | return("unable to verify the first certificate"); | ||
| 118 | case X509_V_ERR_CERT_CHAIN_TOO_LONG: | ||
| 119 | return("certificate chain too long"); | ||
| 120 | case X509_V_ERR_CERT_REVOKED: | ||
| 121 | return("certificate revoked"); | ||
| 122 | case X509_V_ERR_INVALID_CA: | ||
| 123 | return ("invalid CA certificate"); | ||
| 124 | case X509_V_ERR_INVALID_NON_CA: | ||
| 125 | return ("invalid non-CA certificate (has CA markings)"); | ||
| 126 | case X509_V_ERR_PATH_LENGTH_EXCEEDED: | ||
| 127 | return ("path length constraint exceeded"); | ||
| 128 | case X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED: | ||
| 129 | return("proxy path length constraint exceeded"); | ||
| 130 | case X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED: | ||
| 131 | return("proxy certificates not allowed, please set the appropriate flag"); | ||
| 132 | case X509_V_ERR_INVALID_PURPOSE: | ||
| 133 | return ("unsupported certificate purpose"); | ||
| 134 | case X509_V_ERR_CERT_UNTRUSTED: | ||
| 135 | return ("certificate not trusted"); | ||
| 136 | case X509_V_ERR_CERT_REJECTED: | ||
| 137 | return ("certificate rejected"); | ||
| 138 | case X509_V_ERR_APPLICATION_VERIFICATION: | ||
| 139 | return("application verification failure"); | ||
| 140 | case X509_V_ERR_SUBJECT_ISSUER_MISMATCH: | ||
| 141 | return("subject issuer mismatch"); | ||
| 142 | case X509_V_ERR_AKID_SKID_MISMATCH: | ||
| 143 | return("authority and subject key identifier mismatch"); | ||
| 144 | case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH: | ||
| 145 | return("authority and issuer serial number mismatch"); | ||
| 146 | case X509_V_ERR_KEYUSAGE_NO_CERTSIGN: | ||
| 147 | return("key usage does not include certificate signing"); | ||
| 148 | case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER: | ||
| 149 | return("unable to get CRL issuer certificate"); | ||
| 150 | case X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION: | ||
| 151 | return("unhandled critical extension"); | ||
| 152 | case X509_V_ERR_KEYUSAGE_NO_CRL_SIGN: | ||
| 153 | return("key usage does not include CRL signing"); | ||
| 154 | case X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE: | ||
| 155 | return("key usage does not include digital signature"); | ||
| 156 | case X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION: | ||
| 157 | return("unhandled critical CRL extension"); | ||
| 158 | case X509_V_ERR_INVALID_EXTENSION: | ||
| 159 | return("invalid or inconsistent certificate extension"); | ||
| 160 | case X509_V_ERR_INVALID_POLICY_EXTENSION: | ||
| 161 | return("invalid or inconsistent certificate policy extension"); | ||
| 162 | case X509_V_ERR_NO_EXPLICIT_POLICY: | ||
| 163 | return("no explicit policy"); | ||
| 164 | case X509_V_ERR_DIFFERENT_CRL_SCOPE: | ||
| 165 | return("Different CRL scope"); | ||
| 166 | case X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE: | ||
| 167 | return("Unsupported extension feature"); | ||
| 168 | case X509_V_ERR_UNNESTED_RESOURCE: | ||
| 169 | return("RFC 3779 resource not subset of parent's resources"); | ||
| 170 | case X509_V_ERR_PERMITTED_VIOLATION: | ||
| 171 | return("permitted subtree violation"); | ||
| 172 | case X509_V_ERR_EXCLUDED_VIOLATION: | ||
| 173 | return("excluded subtree violation"); | ||
| 174 | case X509_V_ERR_SUBTREE_MINMAX: | ||
| 175 | return("name constraints minimum and maximum not supported"); | ||
| 176 | case X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE: | ||
| 177 | return("unsupported name constraint type"); | ||
| 178 | case X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX: | ||
| 179 | return("unsupported or invalid name constraint syntax"); | ||
| 180 | case X509_V_ERR_UNSUPPORTED_NAME_SYNTAX: | ||
| 181 | return("unsupported or invalid name syntax"); | ||
| 182 | case X509_V_ERR_CRL_PATH_VALIDATION_ERROR: | ||
| 183 | return("CRL path validation error"); | ||
| 184 | |||
| 185 | default: | ||
| 186 | (void) snprintf(buf, sizeof buf, "error number %ld", n); | ||
| 187 | return(buf); | ||
| 188 | } | ||
| 189 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c deleted file mode 100644 index a9f3fdb10e..0000000000 --- a/src/lib/libcrypto/x509/x509_v3.c +++ /dev/null | |||
| @@ -1,300 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_v3.c,v 1.12 2015/07/29 14:58:34 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include <openssl/evp.h> | ||
| 64 | #include <openssl/objects.h> | ||
| 65 | #include <openssl/stack.h> | ||
| 66 | #include <openssl/x509.h> | ||
| 67 | #include <openssl/x509v3.h> | ||
| 68 | |||
| 69 | int | ||
| 70 | X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x) | ||
| 71 | { | ||
| 72 | if (x == NULL) | ||
| 73 | return (0); | ||
| 74 | return (sk_X509_EXTENSION_num(x)); | ||
| 75 | } | ||
| 76 | |||
| 77 | int | ||
| 78 | X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, int nid, int lastpos) | ||
| 79 | { | ||
| 80 | ASN1_OBJECT *obj; | ||
| 81 | |||
| 82 | obj = OBJ_nid2obj(nid); | ||
| 83 | if (obj == NULL) | ||
| 84 | return (-2); | ||
| 85 | return (X509v3_get_ext_by_OBJ(x, obj, lastpos)); | ||
| 86 | } | ||
| 87 | |||
| 88 | int | ||
| 89 | X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk, ASN1_OBJECT *obj, | ||
| 90 | int lastpos) | ||
| 91 | { | ||
| 92 | int n; | ||
| 93 | X509_EXTENSION *ex; | ||
| 94 | |||
| 95 | if (sk == NULL) | ||
| 96 | return (-1); | ||
| 97 | lastpos++; | ||
| 98 | if (lastpos < 0) | ||
| 99 | lastpos = 0; | ||
| 100 | n = sk_X509_EXTENSION_num(sk); | ||
| 101 | for (; lastpos < n; lastpos++) { | ||
| 102 | ex = sk_X509_EXTENSION_value(sk, lastpos); | ||
| 103 | if (OBJ_cmp(ex->object, obj) == 0) | ||
| 104 | return (lastpos); | ||
| 105 | } | ||
| 106 | return (-1); | ||
| 107 | } | ||
| 108 | |||
| 109 | int | ||
| 110 | X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit, | ||
| 111 | int lastpos) | ||
| 112 | { | ||
| 113 | int n; | ||
| 114 | X509_EXTENSION *ex; | ||
| 115 | |||
| 116 | if (sk == NULL) | ||
| 117 | return (-1); | ||
| 118 | lastpos++; | ||
| 119 | if (lastpos < 0) | ||
| 120 | lastpos = 0; | ||
| 121 | n = sk_X509_EXTENSION_num(sk); | ||
| 122 | for (; lastpos < n; lastpos++) { | ||
| 123 | ex = sk_X509_EXTENSION_value(sk, lastpos); | ||
| 124 | if (((ex->critical > 0) && crit) || | ||
| 125 | ((ex->critical <= 0) && !crit)) | ||
| 126 | return (lastpos); | ||
| 127 | } | ||
| 128 | return (-1); | ||
| 129 | } | ||
| 130 | |||
| 131 | X509_EXTENSION * | ||
| 132 | X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc) | ||
| 133 | { | ||
| 134 | if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0) | ||
| 135 | return NULL; | ||
| 136 | else | ||
| 137 | return sk_X509_EXTENSION_value(x, loc); | ||
| 138 | } | ||
| 139 | |||
| 140 | X509_EXTENSION * | ||
| 141 | X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc) | ||
| 142 | { | ||
| 143 | X509_EXTENSION *ret; | ||
| 144 | |||
| 145 | if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0) | ||
| 146 | return (NULL); | ||
| 147 | ret = sk_X509_EXTENSION_delete(x, loc); | ||
| 148 | return (ret); | ||
| 149 | } | ||
| 150 | |||
| 151 | STACK_OF(X509_EXTENSION) * | ||
| 152 | X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, X509_EXTENSION *ex, int loc) | ||
| 153 | { | ||
| 154 | X509_EXTENSION *new_ex = NULL; | ||
| 155 | int n; | ||
| 156 | STACK_OF(X509_EXTENSION) *sk = NULL; | ||
| 157 | |||
| 158 | if (x == NULL) { | ||
| 159 | X509err(X509_F_X509V3_ADD_EXT, ERR_R_PASSED_NULL_PARAMETER); | ||
| 160 | goto err2; | ||
| 161 | } | ||
| 162 | |||
| 163 | if (*x == NULL) { | ||
| 164 | if ((sk = sk_X509_EXTENSION_new_null()) == NULL) | ||
| 165 | goto err; | ||
| 166 | } else | ||
| 167 | sk= *x; | ||
| 168 | |||
| 169 | n = sk_X509_EXTENSION_num(sk); | ||
| 170 | if (loc > n) | ||
| 171 | loc = n; | ||
| 172 | else if (loc < 0) | ||
| 173 | loc = n; | ||
| 174 | |||
| 175 | if ((new_ex = X509_EXTENSION_dup(ex)) == NULL) | ||
| 176 | goto err2; | ||
| 177 | if (!sk_X509_EXTENSION_insert(sk, new_ex, loc)) | ||
| 178 | goto err; | ||
| 179 | if (*x == NULL) | ||
| 180 | *x = sk; | ||
| 181 | return (sk); | ||
| 182 | |||
| 183 | err: | ||
| 184 | X509err(X509_F_X509V3_ADD_EXT, ERR_R_MALLOC_FAILURE); | ||
| 185 | err2: | ||
| 186 | if (new_ex != NULL) | ||
| 187 | X509_EXTENSION_free(new_ex); | ||
| 188 | if (sk != NULL && (x != NULL && sk != *x)) | ||
| 189 | sk_X509_EXTENSION_free(sk); | ||
| 190 | return (NULL); | ||
| 191 | } | ||
| 192 | |||
| 193 | X509_EXTENSION * | ||
| 194 | X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid, int crit, | ||
| 195 | ASN1_OCTET_STRING *data) | ||
| 196 | { | ||
| 197 | ASN1_OBJECT *obj; | ||
| 198 | X509_EXTENSION *ret; | ||
| 199 | |||
| 200 | obj = OBJ_nid2obj(nid); | ||
| 201 | if (obj == NULL) { | ||
| 202 | X509err(X509_F_X509_EXTENSION_CREATE_BY_NID, | ||
| 203 | X509_R_UNKNOWN_NID); | ||
| 204 | return (NULL); | ||
| 205 | } | ||
| 206 | ret = X509_EXTENSION_create_by_OBJ(ex, obj, crit, data); | ||
| 207 | if (ret == NULL) | ||
| 208 | ASN1_OBJECT_free(obj); | ||
| 209 | return (ret); | ||
| 210 | } | ||
| 211 | |||
| 212 | X509_EXTENSION * | ||
| 213 | X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, ASN1_OBJECT *obj, int crit, | ||
| 214 | ASN1_OCTET_STRING *data) | ||
| 215 | { | ||
| 216 | X509_EXTENSION *ret; | ||
| 217 | |||
| 218 | if ((ex == NULL) || (*ex == NULL)) { | ||
| 219 | if ((ret = X509_EXTENSION_new()) == NULL) { | ||
| 220 | X509err(X509_F_X509_EXTENSION_CREATE_BY_OBJ, | ||
| 221 | ERR_R_MALLOC_FAILURE); | ||
| 222 | return (NULL); | ||
| 223 | } | ||
| 224 | } else | ||
| 225 | ret= *ex; | ||
| 226 | |||
| 227 | if (!X509_EXTENSION_set_object(ret, obj)) | ||
| 228 | goto err; | ||
| 229 | if (!X509_EXTENSION_set_critical(ret, crit)) | ||
| 230 | goto err; | ||
| 231 | if (!X509_EXTENSION_set_data(ret, data)) | ||
| 232 | goto err; | ||
| 233 | |||
| 234 | if ((ex != NULL) && (*ex == NULL)) | ||
| 235 | *ex = ret; | ||
| 236 | return (ret); | ||
| 237 | |||
| 238 | err: | ||
| 239 | if ((ex == NULL) || (ret != *ex)) | ||
| 240 | X509_EXTENSION_free(ret); | ||
| 241 | return (NULL); | ||
| 242 | } | ||
| 243 | |||
| 244 | int | ||
| 245 | X509_EXTENSION_set_object(X509_EXTENSION *ex, ASN1_OBJECT *obj) | ||
| 246 | { | ||
| 247 | if ((ex == NULL) || (obj == NULL)) | ||
| 248 | return (0); | ||
| 249 | ASN1_OBJECT_free(ex->object); | ||
| 250 | ex->object = OBJ_dup(obj); | ||
| 251 | return (1); | ||
| 252 | } | ||
| 253 | |||
| 254 | int | ||
| 255 | X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit) | ||
| 256 | { | ||
| 257 | if (ex == NULL) | ||
| 258 | return (0); | ||
| 259 | ex->critical = (crit) ? 0xFF : -1; | ||
| 260 | return (1); | ||
| 261 | } | ||
| 262 | |||
| 263 | int | ||
| 264 | X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data) | ||
| 265 | { | ||
| 266 | int i; | ||
| 267 | |||
| 268 | if (ex == NULL) | ||
| 269 | return (0); | ||
| 270 | i = ASN1_STRING_set(ex->value, data->data, data->length); | ||
| 271 | if (!i) | ||
| 272 | return (0); | ||
| 273 | return (1); | ||
| 274 | } | ||
| 275 | |||
| 276 | ASN1_OBJECT * | ||
| 277 | X509_EXTENSION_get_object(X509_EXTENSION *ex) | ||
| 278 | { | ||
| 279 | if (ex == NULL) | ||
| 280 | return (NULL); | ||
| 281 | return (ex->object); | ||
| 282 | } | ||
| 283 | |||
| 284 | ASN1_OCTET_STRING * | ||
| 285 | X509_EXTENSION_get_data(X509_EXTENSION *ex) | ||
| 286 | { | ||
| 287 | if (ex == NULL) | ||
| 288 | return (NULL); | ||
| 289 | return (ex->value); | ||
| 290 | } | ||
| 291 | |||
| 292 | int | ||
| 293 | X509_EXTENSION_get_critical(X509_EXTENSION *ex) | ||
| 294 | { | ||
| 295 | if (ex == NULL) | ||
| 296 | return (0); | ||
| 297 | if (ex->critical > 0) | ||
| 298 | return 1; | ||
| 299 | return 0; | ||
| 300 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c deleted file mode 100644 index f2dc356dc8..0000000000 --- a/src/lib/libcrypto/x509/x509_vfy.c +++ /dev/null | |||
| @@ -1,2210 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_vfy.c,v 1.44 2015/07/19 05:42:55 miod Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <stdio.h> | ||
| 61 | #include <string.h> | ||
| 62 | #include <time.h> | ||
| 63 | #include <unistd.h> | ||
| 64 | |||
| 65 | #include <openssl/opensslconf.h> | ||
| 66 | |||
| 67 | #include <openssl/asn1.h> | ||
| 68 | #include <openssl/buffer.h> | ||
| 69 | #include <openssl/crypto.h> | ||
| 70 | #include <openssl/err.h> | ||
| 71 | #include <openssl/evp.h> | ||
| 72 | #include <openssl/lhash.h> | ||
| 73 | #include <openssl/objects.h> | ||
| 74 | #include <openssl/x509.h> | ||
| 75 | #include <openssl/x509v3.h> | ||
| 76 | #include "x509_lcl.h" | ||
| 77 | |||
| 78 | /* CRL score values */ | ||
| 79 | |||
| 80 | /* No unhandled critical extensions */ | ||
| 81 | |||
| 82 | #define CRL_SCORE_NOCRITICAL 0x100 | ||
| 83 | |||
| 84 | /* certificate is within CRL scope */ | ||
| 85 | |||
| 86 | #define CRL_SCORE_SCOPE 0x080 | ||
| 87 | |||
| 88 | /* CRL times valid */ | ||
| 89 | |||
| 90 | #define CRL_SCORE_TIME 0x040 | ||
| 91 | |||
| 92 | /* Issuer name matches certificate */ | ||
| 93 | |||
| 94 | #define CRL_SCORE_ISSUER_NAME 0x020 | ||
| 95 | |||
| 96 | /* If this score or above CRL is probably valid */ | ||
| 97 | |||
| 98 | #define CRL_SCORE_VALID (CRL_SCORE_NOCRITICAL|CRL_SCORE_TIME|CRL_SCORE_SCOPE) | ||
| 99 | |||
| 100 | /* CRL issuer is certificate issuer */ | ||
| 101 | |||
| 102 | #define CRL_SCORE_ISSUER_CERT 0x018 | ||
| 103 | |||
| 104 | /* CRL issuer is on certificate path */ | ||
| 105 | |||
| 106 | #define CRL_SCORE_SAME_PATH 0x008 | ||
| 107 | |||
| 108 | /* CRL issuer matches CRL AKID */ | ||
| 109 | |||
| 110 | #define CRL_SCORE_AKID 0x004 | ||
| 111 | |||
| 112 | /* Have a delta CRL with valid times */ | ||
| 113 | |||
| 114 | #define CRL_SCORE_TIME_DELTA 0x002 | ||
| 115 | |||
| 116 | static int null_callback(int ok, X509_STORE_CTX *e); | ||
| 117 | static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); | ||
| 118 | static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x); | ||
| 119 | static int check_chain_extensions(X509_STORE_CTX *ctx); | ||
| 120 | static int check_name_constraints(X509_STORE_CTX *ctx); | ||
| 121 | static int check_trust(X509_STORE_CTX *ctx); | ||
| 122 | static int check_revocation(X509_STORE_CTX *ctx); | ||
| 123 | static int check_cert(X509_STORE_CTX *ctx); | ||
| 124 | static int check_policy(X509_STORE_CTX *ctx); | ||
| 125 | |||
| 126 | static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer, | ||
| 127 | unsigned int *preasons, X509_CRL *crl, X509 *x); | ||
| 128 | static int get_crl_delta(X509_STORE_CTX *ctx, | ||
| 129 | X509_CRL **pcrl, X509_CRL **pdcrl, X509 *x); | ||
| 130 | static void get_delta_sk(X509_STORE_CTX *ctx, X509_CRL **dcrl, int *pcrl_score, | ||
| 131 | X509_CRL *base, STACK_OF(X509_CRL) *crls); | ||
| 132 | static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer, | ||
| 133 | int *pcrl_score); | ||
| 134 | static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score, | ||
| 135 | unsigned int *preasons); | ||
| 136 | static int check_crl_path(X509_STORE_CTX *ctx, X509 *x); | ||
| 137 | static int check_crl_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *cert_path, | ||
| 138 | STACK_OF(X509) *crl_path); | ||
| 139 | |||
| 140 | static int internal_verify(X509_STORE_CTX *ctx); | ||
| 141 | |||
| 142 | static int | ||
| 143 | null_callback(int ok, X509_STORE_CTX *e) | ||
| 144 | { | ||
| 145 | return ok; | ||
| 146 | } | ||
| 147 | |||
| 148 | #if 0 | ||
| 149 | static int | ||
| 150 | x509_subject_cmp(X509 **a, X509 **b) | ||
| 151 | { | ||
| 152 | return X509_subject_name_cmp(*a, *b); | ||
| 153 | } | ||
| 154 | #endif | ||
| 155 | |||
| 156 | int | ||
| 157 | X509_verify_cert(X509_STORE_CTX *ctx) | ||
| 158 | { | ||
| 159 | X509 *x, *xtmp, *chain_ss = NULL; | ||
| 160 | int bad_chain = 0; | ||
| 161 | X509_VERIFY_PARAM *param = ctx->param; | ||
| 162 | int depth, i, ok = 0; | ||
| 163 | int num; | ||
| 164 | int (*cb)(int xok, X509_STORE_CTX *xctx); | ||
| 165 | STACK_OF(X509) *sktmp = NULL; | ||
| 166 | |||
| 167 | if (ctx->cert == NULL) { | ||
| 168 | X509err(X509_F_X509_VERIFY_CERT, | ||
| 169 | X509_R_NO_CERT_SET_FOR_US_TO_VERIFY); | ||
| 170 | return -1; | ||
| 171 | } | ||
| 172 | |||
| 173 | cb = ctx->verify_cb; | ||
| 174 | |||
| 175 | /* first we make sure the chain we are going to build is | ||
| 176 | * present and that the first entry is in place */ | ||
| 177 | if (ctx->chain == NULL) { | ||
| 178 | if (((ctx->chain = sk_X509_new_null()) == NULL) || | ||
| 179 | (!sk_X509_push(ctx->chain, ctx->cert))) { | ||
| 180 | X509err(X509_F_X509_VERIFY_CERT, ERR_R_MALLOC_FAILURE); | ||
| 181 | goto end; | ||
| 182 | } | ||
| 183 | CRYPTO_add(&ctx->cert->references, 1, CRYPTO_LOCK_X509); | ||
| 184 | ctx->last_untrusted = 1; | ||
| 185 | } | ||
| 186 | |||
| 187 | /* We use a temporary STACK so we can chop and hack at it */ | ||
| 188 | if (ctx->untrusted != NULL && | ||
| 189 | (sktmp = sk_X509_dup(ctx->untrusted)) == NULL) { | ||
| 190 | X509err(X509_F_X509_VERIFY_CERT, ERR_R_MALLOC_FAILURE); | ||
| 191 | goto end; | ||
| 192 | } | ||
| 193 | |||
| 194 | num = sk_X509_num(ctx->chain); | ||
| 195 | x = sk_X509_value(ctx->chain, num - 1); | ||
| 196 | depth = param->depth; | ||
| 197 | |||
| 198 | for (;;) { | ||
| 199 | /* If we have enough, we break */ | ||
| 200 | if (depth < num) | ||
| 201 | break; /* FIXME: If this happens, we should take | ||
| 202 | * note of it and, if appropriate, use the | ||
| 203 | * X509_V_ERR_CERT_CHAIN_TOO_LONG error | ||
| 204 | * code later. | ||
| 205 | */ | ||
| 206 | |||
| 207 | /* If we are self signed, we break */ | ||
| 208 | if (ctx->check_issued(ctx, x, x)) | ||
| 209 | break; | ||
| 210 | |||
| 211 | /* If we were passed a cert chain, use it first */ | ||
| 212 | if (ctx->untrusted != NULL) { | ||
| 213 | xtmp = find_issuer(ctx, sktmp, x); | ||
| 214 | if (xtmp != NULL) { | ||
| 215 | if (!sk_X509_push(ctx->chain, xtmp)) { | ||
| 216 | X509err(X509_F_X509_VERIFY_CERT, | ||
| 217 | ERR_R_MALLOC_FAILURE); | ||
| 218 | goto end; | ||
| 219 | } | ||
| 220 | CRYPTO_add(&xtmp->references, 1, | ||
| 221 | CRYPTO_LOCK_X509); | ||
| 222 | (void)sk_X509_delete_ptr(sktmp, xtmp); | ||
| 223 | ctx->last_untrusted++; | ||
| 224 | x = xtmp; | ||
| 225 | num++; | ||
| 226 | /* reparse the full chain for | ||
| 227 | * the next one */ | ||
| 228 | continue; | ||
| 229 | } | ||
| 230 | } | ||
| 231 | break; | ||
| 232 | } | ||
| 233 | sk_X509_free(sktmp); | ||
| 234 | sktmp = NULL; | ||
| 235 | |||
| 236 | /* at this point, chain should contain a list of untrusted | ||
| 237 | * certificates. We now need to add at least one trusted one, | ||
| 238 | * if possible, otherwise we complain. */ | ||
| 239 | |||
| 240 | /* Examine last certificate in chain and see if it | ||
| 241 | * is self signed. | ||
| 242 | */ | ||
| 243 | |||
| 244 | i = sk_X509_num(ctx->chain); | ||
| 245 | x = sk_X509_value(ctx->chain, i - 1); | ||
| 246 | if (ctx->check_issued(ctx, x, x)) { | ||
| 247 | /* we have a self signed certificate */ | ||
| 248 | if (sk_X509_num(ctx->chain) == 1) { | ||
| 249 | /* We have a single self signed certificate: see if | ||
| 250 | * we can find it in the store. We must have an exact | ||
| 251 | * match to avoid possible impersonation. | ||
| 252 | */ | ||
| 253 | ok = ctx->get_issuer(&xtmp, ctx, x); | ||
| 254 | if ((ok <= 0) || X509_cmp(x, xtmp)) { | ||
| 255 | ctx->error = | ||
| 256 | X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT; | ||
| 257 | ctx->current_cert = x; | ||
| 258 | ctx->error_depth = i - 1; | ||
| 259 | if (ok == 1) | ||
| 260 | X509_free(xtmp); | ||
| 261 | bad_chain = 1; | ||
| 262 | ok = cb(0, ctx); | ||
| 263 | if (!ok) | ||
| 264 | goto end; | ||
| 265 | } else { | ||
| 266 | /* We have a match: replace certificate with store version | ||
| 267 | * so we get any trust settings. | ||
| 268 | */ | ||
| 269 | X509_free(x); | ||
| 270 | x = xtmp; | ||
| 271 | (void)sk_X509_set(ctx->chain, i - 1, x); | ||
| 272 | ctx->last_untrusted = 0; | ||
| 273 | } | ||
| 274 | } else { | ||
| 275 | /* extract and save self signed certificate for later use */ | ||
| 276 | chain_ss = sk_X509_pop(ctx->chain); | ||
| 277 | ctx->last_untrusted--; | ||
| 278 | num--; | ||
| 279 | x = sk_X509_value(ctx->chain, num - 1); | ||
| 280 | } | ||
| 281 | } | ||
| 282 | |||
| 283 | /* We now lookup certs from the certificate store */ | ||
| 284 | for (;;) { | ||
| 285 | /* If we have enough, we break */ | ||
| 286 | if (depth < num) | ||
| 287 | break; | ||
| 288 | |||
| 289 | /* If we are self signed, we break */ | ||
| 290 | if (ctx->check_issued(ctx, x, x)) | ||
| 291 | break; | ||
| 292 | |||
| 293 | ok = ctx->get_issuer(&xtmp, ctx, x); | ||
| 294 | if (ok < 0) | ||
| 295 | return ok; | ||
| 296 | if (ok == 0) | ||
| 297 | break; | ||
| 298 | |||
| 299 | x = xtmp; | ||
| 300 | if (!sk_X509_push(ctx->chain, x)) { | ||
| 301 | X509_free(xtmp); | ||
| 302 | X509err(X509_F_X509_VERIFY_CERT, ERR_R_MALLOC_FAILURE); | ||
| 303 | return 0; | ||
| 304 | } | ||
| 305 | num++; | ||
| 306 | } | ||
| 307 | |||
| 308 | /* we now have our chain, lets check it... */ | ||
| 309 | |||
| 310 | /* Is last certificate looked up self signed? */ | ||
| 311 | if (!ctx->check_issued(ctx, x, x)) { | ||
| 312 | if ((chain_ss == NULL) || | ||
| 313 | !ctx->check_issued(ctx, x, chain_ss)) { | ||
| 314 | if (ctx->last_untrusted >= num) | ||
| 315 | ctx->error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY; | ||
| 316 | else | ||
| 317 | ctx->error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT; | ||
| 318 | ctx->current_cert = x; | ||
| 319 | } else { | ||
| 320 | |||
| 321 | if (!sk_X509_push(ctx->chain, chain_ss)) { | ||
| 322 | X509_free(chain_ss); | ||
| 323 | X509err(X509_F_X509_VERIFY_CERT, ERR_R_MALLOC_FAILURE); | ||
| 324 | return 0; | ||
| 325 | } | ||
| 326 | num++; | ||
| 327 | ctx->last_untrusted = num; | ||
| 328 | ctx->current_cert = chain_ss; | ||
| 329 | ctx->error = X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN; | ||
| 330 | chain_ss = NULL; | ||
| 331 | } | ||
| 332 | |||
| 333 | ctx->error_depth = num - 1; | ||
| 334 | bad_chain = 1; | ||
| 335 | ok = cb(0, ctx); | ||
| 336 | if (!ok) | ||
| 337 | goto end; | ||
| 338 | } | ||
| 339 | |||
| 340 | /* We have the chain complete: now we need to check its purpose */ | ||
| 341 | ok = check_chain_extensions(ctx); | ||
| 342 | |||
| 343 | if (!ok) | ||
| 344 | goto end; | ||
| 345 | |||
| 346 | /* Check name constraints */ | ||
| 347 | |||
| 348 | ok = check_name_constraints(ctx); | ||
| 349 | |||
| 350 | if (!ok) | ||
| 351 | goto end; | ||
| 352 | |||
| 353 | /* The chain extensions are OK: check trust */ | ||
| 354 | |||
| 355 | if (param->trust > 0) | ||
| 356 | ok = check_trust(ctx); | ||
| 357 | |||
| 358 | if (!ok) | ||
| 359 | goto end; | ||
| 360 | |||
| 361 | /* We may as well copy down any DSA parameters that are required */ | ||
| 362 | X509_get_pubkey_parameters(NULL, ctx->chain); | ||
| 363 | |||
| 364 | /* Check revocation status: we do this after copying parameters | ||
| 365 | * because they may be needed for CRL signature verification. | ||
| 366 | */ | ||
| 367 | |||
| 368 | ok = ctx->check_revocation(ctx); | ||
| 369 | if (!ok) | ||
| 370 | goto end; | ||
| 371 | |||
| 372 | /* At this point, we have a chain and need to verify it */ | ||
| 373 | if (ctx->verify != NULL) | ||
| 374 | ok = ctx->verify(ctx); | ||
| 375 | else | ||
| 376 | ok = internal_verify(ctx); | ||
| 377 | if (!ok) | ||
| 378 | goto end; | ||
| 379 | |||
| 380 | /* If we get this far evaluate policies */ | ||
| 381 | if (!bad_chain && (ctx->param->flags & X509_V_FLAG_POLICY_CHECK)) | ||
| 382 | ok = ctx->check_policy(ctx); | ||
| 383 | if (!ok) | ||
| 384 | goto end; | ||
| 385 | if (0) { | ||
| 386 | end: | ||
| 387 | X509_get_pubkey_parameters(NULL, ctx->chain); | ||
| 388 | } | ||
| 389 | if (sktmp != NULL) | ||
| 390 | sk_X509_free(sktmp); | ||
| 391 | if (chain_ss != NULL) | ||
| 392 | X509_free(chain_ss); | ||
| 393 | return ok; | ||
| 394 | } | ||
| 395 | |||
| 396 | |||
| 397 | /* Given a STACK_OF(X509) find the issuer of cert (if any) | ||
| 398 | */ | ||
| 399 | |||
| 400 | static X509 * | ||
| 401 | find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x) | ||
| 402 | { | ||
| 403 | int i; | ||
| 404 | X509 *issuer, *rv = NULL; | ||
| 405 | |||
| 406 | for (i = 0; i < sk_X509_num(sk); i++) { | ||
| 407 | issuer = sk_X509_value(sk, i); | ||
| 408 | if (ctx->check_issued(ctx, x, issuer)) { | ||
| 409 | rv = issuer; | ||
| 410 | if (x509_check_cert_time(ctx, rv, 1)) | ||
| 411 | break; | ||
| 412 | } | ||
| 413 | } | ||
| 414 | return rv; | ||
| 415 | } | ||
| 416 | |||
| 417 | /* Given a possible certificate and issuer check them */ | ||
| 418 | |||
| 419 | static int | ||
| 420 | check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer) | ||
| 421 | { | ||
| 422 | int ret; | ||
| 423 | |||
| 424 | ret = X509_check_issued(issuer, x); | ||
| 425 | if (ret == X509_V_OK) | ||
| 426 | return 1; | ||
| 427 | /* If we haven't asked for issuer errors don't set ctx */ | ||
| 428 | if (!(ctx->param->flags & X509_V_FLAG_CB_ISSUER_CHECK)) | ||
| 429 | return 0; | ||
| 430 | |||
| 431 | ctx->error = ret; | ||
| 432 | ctx->current_cert = x; | ||
| 433 | ctx->current_issuer = issuer; | ||
| 434 | return ctx->verify_cb(0, ctx); | ||
| 435 | } | ||
| 436 | |||
| 437 | /* Alternative lookup method: look from a STACK stored in other_ctx */ | ||
| 438 | |||
| 439 | static int | ||
| 440 | get_issuer_sk(X509 **issuer, X509_STORE_CTX *ctx, X509 *x) | ||
| 441 | { | ||
| 442 | *issuer = find_issuer(ctx, ctx->other_ctx, x); | ||
| 443 | if (*issuer) { | ||
| 444 | CRYPTO_add(&(*issuer)->references, 1, CRYPTO_LOCK_X509); | ||
| 445 | return 1; | ||
| 446 | } else | ||
| 447 | return 0; | ||
| 448 | } | ||
| 449 | |||
| 450 | /* Check a certificate chains extensions for consistency | ||
| 451 | * with the supplied purpose | ||
| 452 | */ | ||
| 453 | |||
| 454 | static int | ||
| 455 | check_chain_extensions(X509_STORE_CTX *ctx) | ||
| 456 | { | ||
| 457 | #ifdef OPENSSL_NO_CHAIN_VERIFY | ||
| 458 | return 1; | ||
| 459 | #else | ||
| 460 | int i, ok = 0, must_be_ca, plen = 0; | ||
| 461 | X509 *x; | ||
| 462 | int (*cb)(int xok, X509_STORE_CTX *xctx); | ||
| 463 | int proxy_path_length = 0; | ||
| 464 | int purpose; | ||
| 465 | int allow_proxy_certs; | ||
| 466 | |||
| 467 | cb = ctx->verify_cb; | ||
| 468 | |||
| 469 | /* must_be_ca can have 1 of 3 values: | ||
| 470 | -1: we accept both CA and non-CA certificates, to allow direct | ||
| 471 | use of self-signed certificates (which are marked as CA). | ||
| 472 | 0: we only accept non-CA certificates. This is currently not | ||
| 473 | used, but the possibility is present for future extensions. | ||
| 474 | 1: we only accept CA certificates. This is currently used for | ||
| 475 | all certificates in the chain except the leaf certificate. | ||
| 476 | */ | ||
| 477 | must_be_ca = -1; | ||
| 478 | |||
| 479 | /* CRL path validation */ | ||
| 480 | if (ctx->parent) { | ||
| 481 | allow_proxy_certs = 0; | ||
| 482 | purpose = X509_PURPOSE_CRL_SIGN; | ||
| 483 | } else { | ||
| 484 | allow_proxy_certs = | ||
| 485 | !!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS); | ||
| 486 | purpose = ctx->param->purpose; | ||
| 487 | } | ||
| 488 | |||
| 489 | /* Check all untrusted certificates */ | ||
| 490 | for (i = 0; i < ctx->last_untrusted; i++) { | ||
| 491 | int ret; | ||
| 492 | x = sk_X509_value(ctx->chain, i); | ||
| 493 | if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL) && | ||
| 494 | (x->ex_flags & EXFLAG_CRITICAL)) { | ||
| 495 | ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION; | ||
| 496 | ctx->error_depth = i; | ||
| 497 | ctx->current_cert = x; | ||
| 498 | ok = cb(0, ctx); | ||
| 499 | if (!ok) | ||
| 500 | goto end; | ||
| 501 | } | ||
| 502 | if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY)) { | ||
| 503 | ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED; | ||
| 504 | ctx->error_depth = i; | ||
| 505 | ctx->current_cert = x; | ||
| 506 | ok = cb(0, ctx); | ||
| 507 | if (!ok) | ||
| 508 | goto end; | ||
| 509 | } | ||
| 510 | ret = X509_check_ca(x); | ||
| 511 | switch (must_be_ca) { | ||
| 512 | case -1: | ||
| 513 | if ((ctx->param->flags & X509_V_FLAG_X509_STRICT) && | ||
| 514 | (ret != 1) && (ret != 0)) { | ||
| 515 | ret = 0; | ||
| 516 | ctx->error = X509_V_ERR_INVALID_CA; | ||
| 517 | } else | ||
| 518 | ret = 1; | ||
| 519 | break; | ||
| 520 | case 0: | ||
| 521 | if (ret != 0) { | ||
| 522 | ret = 0; | ||
| 523 | ctx->error = X509_V_ERR_INVALID_NON_CA; | ||
| 524 | } else | ||
| 525 | ret = 1; | ||
| 526 | break; | ||
| 527 | default: | ||
| 528 | if ((ret == 0) || | ||
| 529 | ((ctx->param->flags & X509_V_FLAG_X509_STRICT) && | ||
| 530 | (ret != 1))) { | ||
| 531 | ret = 0; | ||
| 532 | ctx->error = X509_V_ERR_INVALID_CA; | ||
| 533 | } else | ||
| 534 | ret = 1; | ||
| 535 | break; | ||
| 536 | } | ||
| 537 | if (ret == 0) { | ||
| 538 | ctx->error_depth = i; | ||
| 539 | ctx->current_cert = x; | ||
| 540 | ok = cb(0, ctx); | ||
| 541 | if (!ok) | ||
| 542 | goto end; | ||
| 543 | } | ||
| 544 | if (ctx->param->purpose > 0) { | ||
| 545 | ret = X509_check_purpose(x, purpose, must_be_ca > 0); | ||
| 546 | if ((ret == 0) || | ||
| 547 | ((ctx->param->flags & X509_V_FLAG_X509_STRICT) && | ||
| 548 | (ret != 1))) { | ||
| 549 | ctx->error = X509_V_ERR_INVALID_PURPOSE; | ||
| 550 | ctx->error_depth = i; | ||
| 551 | ctx->current_cert = x; | ||
| 552 | ok = cb(0, ctx); | ||
| 553 | if (!ok) | ||
| 554 | goto end; | ||
| 555 | } | ||
| 556 | } | ||
| 557 | /* Check pathlen if not self issued */ | ||
| 558 | if ((i > 1) && !(x->ex_flags & EXFLAG_SI) && | ||
| 559 | (x->ex_pathlen != -1) && | ||
| 560 | (plen > (x->ex_pathlen + proxy_path_length + 1))) { | ||
| 561 | ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED; | ||
| 562 | ctx->error_depth = i; | ||
| 563 | ctx->current_cert = x; | ||
| 564 | ok = cb(0, ctx); | ||
| 565 | if (!ok) | ||
| 566 | goto end; | ||
| 567 | } | ||
| 568 | /* Increment path length if not self issued */ | ||
| 569 | if (!(x->ex_flags & EXFLAG_SI)) | ||
| 570 | plen++; | ||
| 571 | /* If this certificate is a proxy certificate, the next | ||
| 572 | certificate must be another proxy certificate or a EE | ||
| 573 | certificate. If not, the next certificate must be a | ||
| 574 | CA certificate. */ | ||
| 575 | if (x->ex_flags & EXFLAG_PROXY) { | ||
| 576 | if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen) { | ||
| 577 | ctx->error = | ||
| 578 | X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED; | ||
| 579 | ctx->error_depth = i; | ||
| 580 | ctx->current_cert = x; | ||
| 581 | ok = cb(0, ctx); | ||
| 582 | if (!ok) | ||
| 583 | goto end; | ||
| 584 | } | ||
| 585 | proxy_path_length++; | ||
| 586 | must_be_ca = 0; | ||
| 587 | } else | ||
| 588 | must_be_ca = 1; | ||
| 589 | } | ||
| 590 | ok = 1; | ||
| 591 | |||
| 592 | end: | ||
| 593 | return ok; | ||
| 594 | #endif | ||
| 595 | } | ||
| 596 | |||
| 597 | static int | ||
| 598 | check_name_constraints(X509_STORE_CTX *ctx) | ||
| 599 | { | ||
| 600 | X509 *x; | ||
| 601 | int i, j, rv; | ||
| 602 | |||
| 603 | /* Check name constraints for all certificates */ | ||
| 604 | for (i = sk_X509_num(ctx->chain) - 1; i >= 0; i--) { | ||
| 605 | x = sk_X509_value(ctx->chain, i); | ||
| 606 | /* Ignore self issued certs unless last in chain */ | ||
| 607 | if (i && (x->ex_flags & EXFLAG_SI)) | ||
| 608 | continue; | ||
| 609 | /* Check against constraints for all certificates higher in | ||
| 610 | * chain including trust anchor. Trust anchor not strictly | ||
| 611 | * speaking needed but if it includes constraints it is to be | ||
| 612 | * assumed it expects them to be obeyed. | ||
| 613 | */ | ||
| 614 | for (j = sk_X509_num(ctx->chain) - 1; j > i; j--) { | ||
| 615 | NAME_CONSTRAINTS *nc = sk_X509_value(ctx->chain, j)->nc; | ||
| 616 | if (nc) { | ||
| 617 | rv = NAME_CONSTRAINTS_check(x, nc); | ||
| 618 | if (rv != X509_V_OK) { | ||
| 619 | ctx->error = rv; | ||
| 620 | ctx->error_depth = i; | ||
| 621 | ctx->current_cert = x; | ||
| 622 | if (!ctx->verify_cb(0, ctx)) | ||
| 623 | return 0; | ||
| 624 | } | ||
| 625 | } | ||
| 626 | } | ||
| 627 | } | ||
| 628 | return 1; | ||
| 629 | } | ||
| 630 | |||
| 631 | static int | ||
| 632 | check_trust(X509_STORE_CTX *ctx) | ||
| 633 | { | ||
| 634 | #ifdef OPENSSL_NO_CHAIN_VERIFY | ||
| 635 | return 1; | ||
| 636 | #else | ||
| 637 | int i, ok; | ||
| 638 | X509 *x; | ||
| 639 | int (*cb)(int xok, X509_STORE_CTX *xctx); | ||
| 640 | |||
| 641 | cb = ctx->verify_cb; | ||
| 642 | /* For now just check the last certificate in the chain */ | ||
| 643 | i = sk_X509_num(ctx->chain) - 1; | ||
| 644 | x = sk_X509_value(ctx->chain, i); | ||
| 645 | ok = X509_check_trust(x, ctx->param->trust, 0); | ||
| 646 | if (ok == X509_TRUST_TRUSTED) | ||
| 647 | return 1; | ||
| 648 | ctx->error_depth = i; | ||
| 649 | ctx->current_cert = x; | ||
| 650 | if (ok == X509_TRUST_REJECTED) | ||
| 651 | ctx->error = X509_V_ERR_CERT_REJECTED; | ||
| 652 | else | ||
| 653 | ctx->error = X509_V_ERR_CERT_UNTRUSTED; | ||
| 654 | ok = cb(0, ctx); | ||
| 655 | return ok; | ||
| 656 | #endif | ||
| 657 | } | ||
| 658 | |||
| 659 | static int | ||
| 660 | check_revocation(X509_STORE_CTX *ctx) | ||
| 661 | { | ||
| 662 | int i, last, ok; | ||
| 663 | |||
| 664 | if (!(ctx->param->flags & X509_V_FLAG_CRL_CHECK)) | ||
| 665 | return 1; | ||
| 666 | if (ctx->param->flags & X509_V_FLAG_CRL_CHECK_ALL) | ||
| 667 | last = sk_X509_num(ctx->chain) - 1; | ||
| 668 | else { | ||
| 669 | /* If checking CRL paths this isn't the EE certificate */ | ||
| 670 | if (ctx->parent) | ||
| 671 | return 1; | ||
| 672 | last = 0; | ||
| 673 | } | ||
| 674 | for (i = 0; i <= last; i++) { | ||
| 675 | ctx->error_depth = i; | ||
| 676 | ok = check_cert(ctx); | ||
| 677 | if (!ok) | ||
| 678 | return ok; | ||
| 679 | } | ||
| 680 | return 1; | ||
| 681 | } | ||
| 682 | |||
| 683 | static int | ||
| 684 | check_cert(X509_STORE_CTX *ctx) | ||
| 685 | { | ||
| 686 | X509_CRL *crl = NULL, *dcrl = NULL; | ||
| 687 | X509 *x; | ||
| 688 | int ok, cnum; | ||
| 689 | unsigned int last_reasons; | ||
| 690 | |||
| 691 | cnum = ctx->error_depth; | ||
| 692 | x = sk_X509_value(ctx->chain, cnum); | ||
| 693 | ctx->current_cert = x; | ||
| 694 | ctx->current_issuer = NULL; | ||
| 695 | ctx->current_crl_score = 0; | ||
| 696 | ctx->current_reasons = 0; | ||
| 697 | while (ctx->current_reasons != CRLDP_ALL_REASONS) { | ||
| 698 | last_reasons = ctx->current_reasons; | ||
| 699 | /* Try to retrieve relevant CRL */ | ||
| 700 | if (ctx->get_crl) | ||
| 701 | ok = ctx->get_crl(ctx, &crl, x); | ||
| 702 | else | ||
| 703 | ok = get_crl_delta(ctx, &crl, &dcrl, x); | ||
| 704 | /* If error looking up CRL, nothing we can do except | ||
| 705 | * notify callback | ||
| 706 | */ | ||
| 707 | if (!ok) { | ||
| 708 | ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL; | ||
| 709 | ok = ctx->verify_cb(0, ctx); | ||
| 710 | goto err; | ||
| 711 | } | ||
| 712 | ctx->current_crl = crl; | ||
| 713 | ok = ctx->check_crl(ctx, crl); | ||
| 714 | if (!ok) | ||
| 715 | goto err; | ||
| 716 | |||
| 717 | if (dcrl) { | ||
| 718 | ok = ctx->check_crl(ctx, dcrl); | ||
| 719 | if (!ok) | ||
| 720 | goto err; | ||
| 721 | ok = ctx->cert_crl(ctx, dcrl, x); | ||
| 722 | if (!ok) | ||
| 723 | goto err; | ||
| 724 | } else | ||
| 725 | ok = 1; | ||
| 726 | |||
| 727 | /* Don't look in full CRL if delta reason is removefromCRL */ | ||
| 728 | if (ok != 2) { | ||
| 729 | ok = ctx->cert_crl(ctx, crl, x); | ||
| 730 | if (!ok) | ||
| 731 | goto err; | ||
| 732 | } | ||
| 733 | |||
| 734 | ctx->current_crl = NULL; | ||
| 735 | X509_CRL_free(crl); | ||
| 736 | X509_CRL_free(dcrl); | ||
| 737 | crl = NULL; | ||
| 738 | dcrl = NULL; | ||
| 739 | /* If reasons not updated we wont get anywhere by | ||
| 740 | * another iteration, so exit loop. | ||
| 741 | */ | ||
| 742 | if (last_reasons == ctx->current_reasons) { | ||
| 743 | ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL; | ||
| 744 | ok = ctx->verify_cb(0, ctx); | ||
| 745 | goto err; | ||
| 746 | } | ||
| 747 | } | ||
| 748 | |||
| 749 | err: | ||
| 750 | ctx->current_crl = NULL; | ||
| 751 | X509_CRL_free(crl); | ||
| 752 | X509_CRL_free(dcrl); | ||
| 753 | return ok; | ||
| 754 | } | ||
| 755 | |||
| 756 | /* Check CRL times against values in X509_STORE_CTX */ | ||
| 757 | |||
| 758 | static int | ||
| 759 | check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) | ||
| 760 | { | ||
| 761 | time_t *ptime; | ||
| 762 | int i; | ||
| 763 | |||
| 764 | if (notify) | ||
| 765 | ctx->current_crl = crl; | ||
| 766 | if (ctx->param->flags & X509_V_FLAG_USE_CHECK_TIME) | ||
| 767 | ptime = &ctx->param->check_time; | ||
| 768 | else | ||
| 769 | ptime = NULL; | ||
| 770 | |||
| 771 | i = X509_cmp_time(X509_CRL_get_lastUpdate(crl), ptime); | ||
| 772 | if (i == 0) { | ||
| 773 | if (!notify) | ||
| 774 | return 0; | ||
| 775 | ctx->error = X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD; | ||
| 776 | if (!ctx->verify_cb(0, ctx)) | ||
| 777 | return 0; | ||
| 778 | } | ||
| 779 | |||
| 780 | if (i > 0) { | ||
| 781 | if (!notify) | ||
| 782 | return 0; | ||
| 783 | ctx->error = X509_V_ERR_CRL_NOT_YET_VALID; | ||
| 784 | if (!ctx->verify_cb(0, ctx)) | ||
| 785 | return 0; | ||
| 786 | } | ||
| 787 | |||
| 788 | if (X509_CRL_get_nextUpdate(crl)) { | ||
| 789 | i = X509_cmp_time(X509_CRL_get_nextUpdate(crl), ptime); | ||
| 790 | |||
| 791 | if (i == 0) { | ||
| 792 | if (!notify) | ||
| 793 | return 0; | ||
| 794 | ctx->error = X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD; | ||
| 795 | if (!ctx->verify_cb(0, ctx)) | ||
| 796 | return 0; | ||
| 797 | } | ||
| 798 | /* Ignore expiry of base CRL is delta is valid */ | ||
| 799 | if ((i < 0) && | ||
| 800 | !(ctx->current_crl_score & CRL_SCORE_TIME_DELTA)) { | ||
| 801 | if (!notify) | ||
| 802 | return 0; | ||
| 803 | ctx->error = X509_V_ERR_CRL_HAS_EXPIRED; | ||
| 804 | if (!ctx->verify_cb(0, ctx)) | ||
| 805 | return 0; | ||
| 806 | } | ||
| 807 | } | ||
| 808 | |||
| 809 | if (notify) | ||
| 810 | ctx->current_crl = NULL; | ||
| 811 | |||
| 812 | return 1; | ||
| 813 | } | ||
| 814 | |||
| 815 | static int | ||
| 816 | get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl, | ||
| 817 | X509 **pissuer, int *pscore, unsigned int *preasons, | ||
| 818 | STACK_OF(X509_CRL) *crls) | ||
| 819 | { | ||
| 820 | int i, crl_score, best_score = *pscore; | ||
| 821 | unsigned int reasons, best_reasons = 0; | ||
| 822 | X509 *x = ctx->current_cert; | ||
| 823 | X509_CRL *crl, *best_crl = NULL; | ||
| 824 | X509 *crl_issuer = NULL, *best_crl_issuer = NULL; | ||
| 825 | |||
| 826 | for (i = 0; i < sk_X509_CRL_num(crls); i++) { | ||
| 827 | crl = sk_X509_CRL_value(crls, i); | ||
| 828 | reasons = *preasons; | ||
| 829 | crl_score = get_crl_score(ctx, &crl_issuer, &reasons, crl, x); | ||
| 830 | |||
| 831 | if (crl_score > best_score) { | ||
| 832 | best_crl = crl; | ||
| 833 | best_crl_issuer = crl_issuer; | ||
| 834 | best_score = crl_score; | ||
| 835 | best_reasons = reasons; | ||
| 836 | } | ||
| 837 | } | ||
| 838 | |||
| 839 | if (best_crl) { | ||
| 840 | if (*pcrl) | ||
| 841 | X509_CRL_free(*pcrl); | ||
| 842 | *pcrl = best_crl; | ||
| 843 | *pissuer = best_crl_issuer; | ||
| 844 | *pscore = best_score; | ||
| 845 | *preasons = best_reasons; | ||
| 846 | CRYPTO_add(&best_crl->references, 1, CRYPTO_LOCK_X509_CRL); | ||
| 847 | if (*pdcrl) { | ||
| 848 | X509_CRL_free(*pdcrl); | ||
| 849 | *pdcrl = NULL; | ||
| 850 | } | ||
| 851 | get_delta_sk(ctx, pdcrl, pscore, best_crl, crls); | ||
| 852 | } | ||
| 853 | |||
| 854 | if (best_score >= CRL_SCORE_VALID) | ||
| 855 | return 1; | ||
| 856 | |||
| 857 | return 0; | ||
| 858 | } | ||
| 859 | |||
| 860 | /* Compare two CRL extensions for delta checking purposes. They should be | ||
| 861 | * both present or both absent. If both present all fields must be identical. | ||
| 862 | */ | ||
| 863 | |||
| 864 | static int | ||
| 865 | crl_extension_match(X509_CRL *a, X509_CRL *b, int nid) | ||
| 866 | { | ||
| 867 | ASN1_OCTET_STRING *exta, *extb; | ||
| 868 | int i; | ||
| 869 | |||
| 870 | i = X509_CRL_get_ext_by_NID(a, nid, -1); | ||
| 871 | if (i >= 0) { | ||
| 872 | /* Can't have multiple occurrences */ | ||
| 873 | if (X509_CRL_get_ext_by_NID(a, nid, i) != -1) | ||
| 874 | return 0; | ||
| 875 | exta = X509_EXTENSION_get_data(X509_CRL_get_ext(a, i)); | ||
| 876 | } else | ||
| 877 | exta = NULL; | ||
| 878 | |||
| 879 | i = X509_CRL_get_ext_by_NID(b, nid, -1); | ||
| 880 | |||
| 881 | if (i >= 0) { | ||
| 882 | if (X509_CRL_get_ext_by_NID(b, nid, i) != -1) | ||
| 883 | return 0; | ||
| 884 | extb = X509_EXTENSION_get_data(X509_CRL_get_ext(b, i)); | ||
| 885 | } else | ||
| 886 | extb = NULL; | ||
| 887 | |||
| 888 | if (!exta && !extb) | ||
| 889 | return 1; | ||
| 890 | |||
| 891 | if (!exta || !extb) | ||
| 892 | return 0; | ||
| 893 | |||
| 894 | if (ASN1_OCTET_STRING_cmp(exta, extb)) | ||
| 895 | return 0; | ||
| 896 | |||
| 897 | return 1; | ||
| 898 | } | ||
| 899 | |||
| 900 | /* See if a base and delta are compatible */ | ||
| 901 | |||
| 902 | static int | ||
| 903 | check_delta_base(X509_CRL *delta, X509_CRL *base) | ||
| 904 | { | ||
| 905 | /* Delta CRL must be a delta */ | ||
| 906 | if (!delta->base_crl_number) | ||
| 907 | return 0; | ||
| 908 | /* Base must have a CRL number */ | ||
| 909 | if (!base->crl_number) | ||
| 910 | return 0; | ||
| 911 | /* Issuer names must match */ | ||
| 912 | if (X509_NAME_cmp(X509_CRL_get_issuer(base), | ||
| 913 | X509_CRL_get_issuer(delta))) | ||
| 914 | return 0; | ||
| 915 | /* AKID and IDP must match */ | ||
| 916 | if (!crl_extension_match(delta, base, NID_authority_key_identifier)) | ||
| 917 | return 0; | ||
| 918 | if (!crl_extension_match(delta, base, NID_issuing_distribution_point)) | ||
| 919 | return 0; | ||
| 920 | /* Delta CRL base number must not exceed Full CRL number. */ | ||
| 921 | if (ASN1_INTEGER_cmp(delta->base_crl_number, base->crl_number) > 0) | ||
| 922 | return 0; | ||
| 923 | /* Delta CRL number must exceed full CRL number */ | ||
| 924 | if (ASN1_INTEGER_cmp(delta->crl_number, base->crl_number) > 0) | ||
| 925 | return 1; | ||
| 926 | return 0; | ||
| 927 | } | ||
| 928 | |||
| 929 | /* For a given base CRL find a delta... maybe extend to delta scoring | ||
| 930 | * or retrieve a chain of deltas... | ||
| 931 | */ | ||
| 932 | |||
| 933 | static void | ||
| 934 | get_delta_sk(X509_STORE_CTX *ctx, X509_CRL **dcrl, int *pscore, X509_CRL *base, | ||
| 935 | STACK_OF(X509_CRL) *crls) | ||
| 936 | { | ||
| 937 | X509_CRL *delta; | ||
| 938 | int i; | ||
| 939 | |||
| 940 | if (!(ctx->param->flags & X509_V_FLAG_USE_DELTAS)) | ||
| 941 | return; | ||
| 942 | if (!((ctx->current_cert->ex_flags | base->flags) & EXFLAG_FRESHEST)) | ||
| 943 | return; | ||
| 944 | for (i = 0; i < sk_X509_CRL_num(crls); i++) { | ||
| 945 | delta = sk_X509_CRL_value(crls, i); | ||
| 946 | if (check_delta_base(delta, base)) { | ||
| 947 | if (check_crl_time(ctx, delta, 0)) | ||
| 948 | *pscore |= CRL_SCORE_TIME_DELTA; | ||
| 949 | CRYPTO_add(&delta->references, 1, CRYPTO_LOCK_X509_CRL); | ||
| 950 | *dcrl = delta; | ||
| 951 | return; | ||
| 952 | } | ||
| 953 | } | ||
| 954 | *dcrl = NULL; | ||
| 955 | } | ||
| 956 | |||
| 957 | /* For a given CRL return how suitable it is for the supplied certificate 'x'. | ||
| 958 | * The return value is a mask of several criteria. | ||
| 959 | * If the issuer is not the certificate issuer this is returned in *pissuer. | ||
| 960 | * The reasons mask is also used to determine if the CRL is suitable: if | ||
| 961 | * no new reasons the CRL is rejected, otherwise reasons is updated. | ||
| 962 | */ | ||
| 963 | |||
| 964 | static int | ||
| 965 | get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer, unsigned int *preasons, | ||
| 966 | X509_CRL *crl, X509 *x) | ||
| 967 | { | ||
| 968 | int crl_score = 0; | ||
| 969 | unsigned int tmp_reasons = *preasons, crl_reasons; | ||
| 970 | |||
| 971 | /* First see if we can reject CRL straight away */ | ||
| 972 | |||
| 973 | /* Invalid IDP cannot be processed */ | ||
| 974 | if (crl->idp_flags & IDP_INVALID) | ||
| 975 | return 0; | ||
| 976 | /* Reason codes or indirect CRLs need extended CRL support */ | ||
| 977 | if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT)) { | ||
| 978 | if (crl->idp_flags & (IDP_INDIRECT | IDP_REASONS)) | ||
| 979 | return 0; | ||
| 980 | } else if (crl->idp_flags & IDP_REASONS) { | ||
| 981 | /* If no new reasons reject */ | ||
| 982 | if (!(crl->idp_reasons & ~tmp_reasons)) | ||
| 983 | return 0; | ||
| 984 | } | ||
| 985 | /* Don't process deltas at this stage */ | ||
| 986 | else if (crl->base_crl_number) | ||
| 987 | return 0; | ||
| 988 | /* If issuer name doesn't match certificate need indirect CRL */ | ||
| 989 | if (X509_NAME_cmp(X509_get_issuer_name(x), X509_CRL_get_issuer(crl))) { | ||
| 990 | if (!(crl->idp_flags & IDP_INDIRECT)) | ||
| 991 | return 0; | ||
| 992 | } else | ||
| 993 | crl_score |= CRL_SCORE_ISSUER_NAME; | ||
| 994 | |||
| 995 | if (!(crl->flags & EXFLAG_CRITICAL)) | ||
| 996 | crl_score |= CRL_SCORE_NOCRITICAL; | ||
| 997 | |||
| 998 | /* Check expiry */ | ||
| 999 | if (check_crl_time(ctx, crl, 0)) | ||
| 1000 | crl_score |= CRL_SCORE_TIME; | ||
| 1001 | |||
| 1002 | /* Check authority key ID and locate certificate issuer */ | ||
| 1003 | crl_akid_check(ctx, crl, pissuer, &crl_score); | ||
| 1004 | |||
| 1005 | /* If we can't locate certificate issuer at this point forget it */ | ||
| 1006 | |||
| 1007 | if (!(crl_score & CRL_SCORE_AKID)) | ||
| 1008 | return 0; | ||
| 1009 | |||
| 1010 | /* Check cert for matching CRL distribution points */ | ||
| 1011 | |||
| 1012 | if (crl_crldp_check(x, crl, crl_score, &crl_reasons)) { | ||
| 1013 | /* If no new reasons reject */ | ||
| 1014 | if (!(crl_reasons & ~tmp_reasons)) | ||
| 1015 | return 0; | ||
| 1016 | tmp_reasons |= crl_reasons; | ||
| 1017 | crl_score |= CRL_SCORE_SCOPE; | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | *preasons = tmp_reasons; | ||
| 1021 | |||
| 1022 | return crl_score; | ||
| 1023 | } | ||
| 1024 | |||
| 1025 | static void | ||
| 1026 | crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer, | ||
| 1027 | int *pcrl_score) | ||
| 1028 | { | ||
| 1029 | X509 *crl_issuer = NULL; | ||
| 1030 | X509_NAME *cnm = X509_CRL_get_issuer(crl); | ||
| 1031 | int cidx = ctx->error_depth; | ||
| 1032 | int i; | ||
| 1033 | |||
| 1034 | if (cidx != sk_X509_num(ctx->chain) - 1) | ||
| 1035 | cidx++; | ||
| 1036 | |||
| 1037 | crl_issuer = sk_X509_value(ctx->chain, cidx); | ||
| 1038 | |||
| 1039 | if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) { | ||
| 1040 | if (*pcrl_score & CRL_SCORE_ISSUER_NAME) { | ||
| 1041 | *pcrl_score |= CRL_SCORE_AKID|CRL_SCORE_ISSUER_CERT; | ||
| 1042 | *pissuer = crl_issuer; | ||
| 1043 | return; | ||
| 1044 | } | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | for (cidx++; cidx < sk_X509_num(ctx->chain); cidx++) { | ||
| 1048 | crl_issuer = sk_X509_value(ctx->chain, cidx); | ||
| 1049 | if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm)) | ||
| 1050 | continue; | ||
| 1051 | if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) { | ||
| 1052 | *pcrl_score |= CRL_SCORE_AKID|CRL_SCORE_SAME_PATH; | ||
| 1053 | *pissuer = crl_issuer; | ||
| 1054 | return; | ||
| 1055 | } | ||
| 1056 | } | ||
| 1057 | |||
| 1058 | /* Anything else needs extended CRL support */ | ||
| 1059 | |||
| 1060 | if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT)) | ||
| 1061 | return; | ||
| 1062 | |||
| 1063 | /* Otherwise the CRL issuer is not on the path. Look for it in the | ||
| 1064 | * set of untrusted certificates. | ||
| 1065 | */ | ||
| 1066 | for (i = 0; i < sk_X509_num(ctx->untrusted); i++) { | ||
| 1067 | crl_issuer = sk_X509_value(ctx->untrusted, i); | ||
| 1068 | if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm)) | ||
| 1069 | continue; | ||
| 1070 | if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) { | ||
| 1071 | *pissuer = crl_issuer; | ||
| 1072 | *pcrl_score |= CRL_SCORE_AKID; | ||
| 1073 | return; | ||
| 1074 | } | ||
| 1075 | } | ||
| 1076 | } | ||
| 1077 | |||
| 1078 | /* Check the path of a CRL issuer certificate. This creates a new | ||
| 1079 | * X509_STORE_CTX and populates it with most of the parameters from the | ||
| 1080 | * parent. This could be optimised somewhat since a lot of path checking | ||
| 1081 | * will be duplicated by the parent, but this will rarely be used in | ||
| 1082 | * practice. | ||
| 1083 | */ | ||
| 1084 | |||
| 1085 | static int | ||
| 1086 | check_crl_path(X509_STORE_CTX *ctx, X509 *x) | ||
| 1087 | { | ||
| 1088 | X509_STORE_CTX crl_ctx; | ||
| 1089 | int ret; | ||
| 1090 | |||
| 1091 | /* Don't allow recursive CRL path validation */ | ||
| 1092 | if (ctx->parent) | ||
| 1093 | return 0; | ||
| 1094 | if (!X509_STORE_CTX_init(&crl_ctx, ctx->ctx, x, ctx->untrusted)) { | ||
| 1095 | ret = -1; | ||
| 1096 | goto err; | ||
| 1097 | } | ||
| 1098 | |||
| 1099 | crl_ctx.crls = ctx->crls; | ||
| 1100 | /* Copy verify params across */ | ||
| 1101 | X509_STORE_CTX_set0_param(&crl_ctx, ctx->param); | ||
| 1102 | |||
| 1103 | crl_ctx.parent = ctx; | ||
| 1104 | crl_ctx.verify_cb = ctx->verify_cb; | ||
| 1105 | |||
| 1106 | /* Verify CRL issuer */ | ||
| 1107 | ret = X509_verify_cert(&crl_ctx); | ||
| 1108 | |||
| 1109 | if (ret <= 0) | ||
| 1110 | goto err; | ||
| 1111 | |||
| 1112 | /* Check chain is acceptable */ | ||
| 1113 | ret = check_crl_chain(ctx, ctx->chain, crl_ctx.chain); | ||
| 1114 | |||
| 1115 | err: | ||
| 1116 | X509_STORE_CTX_cleanup(&crl_ctx); | ||
| 1117 | return ret; | ||
| 1118 | } | ||
| 1119 | |||
| 1120 | /* RFC3280 says nothing about the relationship between CRL path | ||
| 1121 | * and certificate path, which could lead to situations where a | ||
| 1122 | * certificate could be revoked or validated by a CA not authorised | ||
| 1123 | * to do so. RFC5280 is more strict and states that the two paths must | ||
| 1124 | * end in the same trust anchor, though some discussions remain... | ||
| 1125 | * until this is resolved we use the RFC5280 version | ||
| 1126 | */ | ||
| 1127 | |||
| 1128 | static int | ||
| 1129 | check_crl_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *cert_path, | ||
| 1130 | STACK_OF(X509) *crl_path) | ||
| 1131 | { | ||
| 1132 | X509 *cert_ta, *crl_ta; | ||
| 1133 | |||
| 1134 | cert_ta = sk_X509_value(cert_path, sk_X509_num(cert_path) - 1); | ||
| 1135 | crl_ta = sk_X509_value(crl_path, sk_X509_num(crl_path) - 1); | ||
| 1136 | if (!X509_cmp(cert_ta, crl_ta)) | ||
| 1137 | return 1; | ||
| 1138 | return 0; | ||
| 1139 | } | ||
| 1140 | |||
| 1141 | /* Check for match between two dist point names: three separate cases. | ||
| 1142 | * 1. Both are relative names and compare X509_NAME types. | ||
| 1143 | * 2. One full, one relative. Compare X509_NAME to GENERAL_NAMES. | ||
| 1144 | * 3. Both are full names and compare two GENERAL_NAMES. | ||
| 1145 | * 4. One is NULL: automatic match. | ||
| 1146 | */ | ||
| 1147 | |||
| 1148 | static int | ||
| 1149 | idp_check_dp(DIST_POINT_NAME *a, DIST_POINT_NAME *b) | ||
| 1150 | { | ||
| 1151 | X509_NAME *nm = NULL; | ||
| 1152 | GENERAL_NAMES *gens = NULL; | ||
| 1153 | GENERAL_NAME *gena, *genb; | ||
| 1154 | int i, j; | ||
| 1155 | |||
| 1156 | if (!a || !b) | ||
| 1157 | return 1; | ||
| 1158 | if (a->type == 1) { | ||
| 1159 | if (!a->dpname) | ||
| 1160 | return 0; | ||
| 1161 | /* Case 1: two X509_NAME */ | ||
| 1162 | if (b->type == 1) { | ||
| 1163 | if (!b->dpname) | ||
| 1164 | return 0; | ||
| 1165 | if (!X509_NAME_cmp(a->dpname, b->dpname)) | ||
| 1166 | return 1; | ||
| 1167 | else | ||
| 1168 | return 0; | ||
| 1169 | } | ||
| 1170 | /* Case 2: set name and GENERAL_NAMES appropriately */ | ||
| 1171 | nm = a->dpname; | ||
| 1172 | gens = b->name.fullname; | ||
| 1173 | } else if (b->type == 1) { | ||
| 1174 | if (!b->dpname) | ||
| 1175 | return 0; | ||
| 1176 | /* Case 2: set name and GENERAL_NAMES appropriately */ | ||
| 1177 | gens = a->name.fullname; | ||
| 1178 | nm = b->dpname; | ||
| 1179 | } | ||
| 1180 | |||
| 1181 | /* Handle case 2 with one GENERAL_NAMES and one X509_NAME */ | ||
| 1182 | if (nm) { | ||
| 1183 | for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) { | ||
| 1184 | gena = sk_GENERAL_NAME_value(gens, i); | ||
| 1185 | if (gena->type != GEN_DIRNAME) | ||
| 1186 | continue; | ||
| 1187 | if (!X509_NAME_cmp(nm, gena->d.directoryName)) | ||
| 1188 | return 1; | ||
| 1189 | } | ||
| 1190 | return 0; | ||
| 1191 | } | ||
| 1192 | |||
| 1193 | /* Else case 3: two GENERAL_NAMES */ | ||
| 1194 | |||
| 1195 | for (i = 0; i < sk_GENERAL_NAME_num(a->name.fullname); i++) { | ||
| 1196 | gena = sk_GENERAL_NAME_value(a->name.fullname, i); | ||
| 1197 | for (j = 0; j < sk_GENERAL_NAME_num(b->name.fullname); j++) { | ||
| 1198 | genb = sk_GENERAL_NAME_value(b->name.fullname, j); | ||
| 1199 | if (!GENERAL_NAME_cmp(gena, genb)) | ||
| 1200 | return 1; | ||
| 1201 | } | ||
| 1202 | } | ||
| 1203 | |||
| 1204 | return 0; | ||
| 1205 | } | ||
| 1206 | |||
| 1207 | static int | ||
| 1208 | crldp_check_crlissuer(DIST_POINT *dp, X509_CRL *crl, int crl_score) | ||
| 1209 | { | ||
| 1210 | int i; | ||
| 1211 | X509_NAME *nm = X509_CRL_get_issuer(crl); | ||
| 1212 | |||
| 1213 | /* If no CRLissuer return is successful iff don't need a match */ | ||
| 1214 | if (!dp->CRLissuer) | ||
| 1215 | return !!(crl_score & CRL_SCORE_ISSUER_NAME); | ||
| 1216 | for (i = 0; i < sk_GENERAL_NAME_num(dp->CRLissuer); i++) { | ||
| 1217 | GENERAL_NAME *gen = sk_GENERAL_NAME_value(dp->CRLissuer, i); | ||
| 1218 | if (gen->type != GEN_DIRNAME) | ||
| 1219 | continue; | ||
| 1220 | if (!X509_NAME_cmp(gen->d.directoryName, nm)) | ||
| 1221 | return 1; | ||
| 1222 | } | ||
| 1223 | return 0; | ||
| 1224 | } | ||
| 1225 | |||
| 1226 | /* Check CRLDP and IDP */ | ||
| 1227 | |||
| 1228 | static int | ||
| 1229 | crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score, unsigned int *preasons) | ||
| 1230 | { | ||
| 1231 | int i; | ||
| 1232 | |||
| 1233 | if (crl->idp_flags & IDP_ONLYATTR) | ||
| 1234 | return 0; | ||
| 1235 | if (x->ex_flags & EXFLAG_CA) { | ||
| 1236 | if (crl->idp_flags & IDP_ONLYUSER) | ||
| 1237 | return 0; | ||
| 1238 | } else { | ||
| 1239 | if (crl->idp_flags & IDP_ONLYCA) | ||
| 1240 | return 0; | ||
| 1241 | } | ||
| 1242 | *preasons = crl->idp_reasons; | ||
| 1243 | for (i = 0; i < sk_DIST_POINT_num(x->crldp); i++) { | ||
| 1244 | DIST_POINT *dp = sk_DIST_POINT_value(x->crldp, i); | ||
| 1245 | if (crldp_check_crlissuer(dp, crl, crl_score)) { | ||
| 1246 | if (!crl->idp || | ||
| 1247 | idp_check_dp(dp->distpoint, crl->idp->distpoint)) { | ||
| 1248 | *preasons &= dp->dp_reasons; | ||
| 1249 | return 1; | ||
| 1250 | } | ||
| 1251 | } | ||
| 1252 | } | ||
| 1253 | if ((!crl->idp || !crl->idp->distpoint) && | ||
| 1254 | (crl_score & CRL_SCORE_ISSUER_NAME)) | ||
| 1255 | return 1; | ||
| 1256 | return 0; | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | /* Retrieve CRL corresponding to current certificate. | ||
| 1260 | * If deltas enabled try to find a delta CRL too | ||
| 1261 | */ | ||
| 1262 | |||
| 1263 | static int | ||
| 1264 | get_crl_delta(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl, X509 *x) | ||
| 1265 | { | ||
| 1266 | int ok; | ||
| 1267 | X509 *issuer = NULL; | ||
| 1268 | int crl_score = 0; | ||
| 1269 | unsigned int reasons; | ||
| 1270 | X509_CRL *crl = NULL, *dcrl = NULL; | ||
| 1271 | STACK_OF(X509_CRL) *skcrl; | ||
| 1272 | X509_NAME *nm = X509_get_issuer_name(x); | ||
| 1273 | |||
| 1274 | reasons = ctx->current_reasons; | ||
| 1275 | ok = get_crl_sk(ctx, &crl, &dcrl, &issuer, &crl_score, &reasons, | ||
| 1276 | ctx->crls); | ||
| 1277 | if (ok) | ||
| 1278 | goto done; | ||
| 1279 | |||
| 1280 | /* Lookup CRLs from store */ | ||
| 1281 | skcrl = ctx->lookup_crls(ctx, nm); | ||
| 1282 | |||
| 1283 | /* If no CRLs found and a near match from get_crl_sk use that */ | ||
| 1284 | if (!skcrl && crl) | ||
| 1285 | goto done; | ||
| 1286 | |||
| 1287 | get_crl_sk(ctx, &crl, &dcrl, &issuer, &crl_score, &reasons, skcrl); | ||
| 1288 | |||
| 1289 | sk_X509_CRL_pop_free(skcrl, X509_CRL_free); | ||
| 1290 | |||
| 1291 | done: | ||
| 1292 | |||
| 1293 | /* If we got any kind of CRL use it and return success */ | ||
| 1294 | if (crl) { | ||
| 1295 | ctx->current_issuer = issuer; | ||
| 1296 | ctx->current_crl_score = crl_score; | ||
| 1297 | ctx->current_reasons = reasons; | ||
| 1298 | *pcrl = crl; | ||
| 1299 | *pdcrl = dcrl; | ||
| 1300 | return 1; | ||
| 1301 | } | ||
| 1302 | |||
| 1303 | return 0; | ||
| 1304 | } | ||
| 1305 | |||
| 1306 | /* Check CRL validity */ | ||
| 1307 | static int | ||
| 1308 | check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) | ||
| 1309 | { | ||
| 1310 | X509 *issuer = NULL; | ||
| 1311 | EVP_PKEY *ikey = NULL; | ||
| 1312 | int ok = 0, chnum, cnum; | ||
| 1313 | |||
| 1314 | cnum = ctx->error_depth; | ||
| 1315 | chnum = sk_X509_num(ctx->chain) - 1; | ||
| 1316 | /* if we have an alternative CRL issuer cert use that */ | ||
| 1317 | if (ctx->current_issuer) { | ||
| 1318 | issuer = ctx->current_issuer; | ||
| 1319 | } else if (cnum < chnum) { | ||
| 1320 | /* Else find CRL issuer: if not last certificate then issuer | ||
| 1321 | * is next certificate in chain. | ||
| 1322 | */ | ||
| 1323 | issuer = sk_X509_value(ctx->chain, cnum + 1); | ||
| 1324 | } else { | ||
| 1325 | issuer = sk_X509_value(ctx->chain, chnum); | ||
| 1326 | /* If not self signed, can't check signature */ | ||
| 1327 | if (!ctx->check_issued(ctx, issuer, issuer)) { | ||
| 1328 | ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER; | ||
| 1329 | ok = ctx->verify_cb(0, ctx); | ||
| 1330 | if (!ok) | ||
| 1331 | goto err; | ||
| 1332 | } | ||
| 1333 | } | ||
| 1334 | |||
| 1335 | if (issuer) { | ||
| 1336 | /* Skip most tests for deltas because they have already | ||
| 1337 | * been done | ||
| 1338 | */ | ||
| 1339 | if (!crl->base_crl_number) { | ||
| 1340 | /* Check for cRLSign bit if keyUsage present */ | ||
| 1341 | if ((issuer->ex_flags & EXFLAG_KUSAGE) && | ||
| 1342 | !(issuer->ex_kusage & KU_CRL_SIGN)) { | ||
| 1343 | ctx->error = X509_V_ERR_KEYUSAGE_NO_CRL_SIGN; | ||
| 1344 | ok = ctx->verify_cb(0, ctx); | ||
| 1345 | if (!ok) | ||
| 1346 | goto err; | ||
| 1347 | } | ||
| 1348 | |||
| 1349 | if (!(ctx->current_crl_score & CRL_SCORE_SCOPE)) { | ||
| 1350 | ctx->error = X509_V_ERR_DIFFERENT_CRL_SCOPE; | ||
| 1351 | ok = ctx->verify_cb(0, ctx); | ||
| 1352 | if (!ok) | ||
| 1353 | goto err; | ||
| 1354 | } | ||
| 1355 | |||
| 1356 | if (!(ctx->current_crl_score & CRL_SCORE_SAME_PATH)) { | ||
| 1357 | if (check_crl_path(ctx, | ||
| 1358 | ctx->current_issuer) <= 0) { | ||
| 1359 | ctx->error = X509_V_ERR_CRL_PATH_VALIDATION_ERROR; | ||
| 1360 | ok = ctx->verify_cb(0, ctx); | ||
| 1361 | if (!ok) | ||
| 1362 | goto err; | ||
| 1363 | } | ||
| 1364 | } | ||
| 1365 | |||
| 1366 | if (crl->idp_flags & IDP_INVALID) { | ||
| 1367 | ctx->error = X509_V_ERR_INVALID_EXTENSION; | ||
| 1368 | ok = ctx->verify_cb(0, ctx); | ||
| 1369 | if (!ok) | ||
| 1370 | goto err; | ||
| 1371 | } | ||
| 1372 | |||
| 1373 | |||
| 1374 | } | ||
| 1375 | |||
| 1376 | if (!(ctx->current_crl_score & CRL_SCORE_TIME)) { | ||
| 1377 | ok = check_crl_time(ctx, crl, 1); | ||
| 1378 | if (!ok) | ||
| 1379 | goto err; | ||
| 1380 | } | ||
| 1381 | |||
| 1382 | /* Attempt to get issuer certificate public key */ | ||
| 1383 | ikey = X509_get_pubkey(issuer); | ||
| 1384 | |||
| 1385 | if (!ikey) { | ||
| 1386 | ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY; | ||
| 1387 | ok = ctx->verify_cb(0, ctx); | ||
| 1388 | if (!ok) | ||
| 1389 | goto err; | ||
| 1390 | } else { | ||
| 1391 | /* Verify CRL signature */ | ||
| 1392 | if (X509_CRL_verify(crl, ikey) <= 0) { | ||
| 1393 | ctx->error = X509_V_ERR_CRL_SIGNATURE_FAILURE; | ||
| 1394 | ok = ctx->verify_cb(0, ctx); | ||
| 1395 | if (!ok) | ||
| 1396 | goto err; | ||
| 1397 | } | ||
| 1398 | } | ||
| 1399 | } | ||
| 1400 | |||
| 1401 | ok = 1; | ||
| 1402 | |||
| 1403 | err: | ||
| 1404 | EVP_PKEY_free(ikey); | ||
| 1405 | return ok; | ||
| 1406 | } | ||
| 1407 | |||
| 1408 | /* Check certificate against CRL */ | ||
| 1409 | static int | ||
| 1410 | cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) | ||
| 1411 | { | ||
| 1412 | int ok; | ||
| 1413 | X509_REVOKED *rev; | ||
| 1414 | |||
| 1415 | /* The rules changed for this... previously if a CRL contained | ||
| 1416 | * unhandled critical extensions it could still be used to indicate | ||
| 1417 | * a certificate was revoked. This has since been changed since | ||
| 1418 | * critical extension can change the meaning of CRL entries. | ||
| 1419 | */ | ||
| 1420 | if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL) && | ||
| 1421 | (crl->flags & EXFLAG_CRITICAL)) { | ||
| 1422 | ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION; | ||
| 1423 | ok = ctx->verify_cb(0, ctx); | ||
| 1424 | if (!ok) | ||
| 1425 | return 0; | ||
| 1426 | } | ||
| 1427 | /* Look for serial number of certificate in CRL | ||
| 1428 | * If found make sure reason is not removeFromCRL. | ||
| 1429 | */ | ||
| 1430 | if (X509_CRL_get0_by_cert(crl, &rev, x)) { | ||
| 1431 | if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) | ||
| 1432 | return 2; | ||
| 1433 | ctx->error = X509_V_ERR_CERT_REVOKED; | ||
| 1434 | ok = ctx->verify_cb(0, ctx); | ||
| 1435 | if (!ok) | ||
| 1436 | return 0; | ||
| 1437 | } | ||
| 1438 | |||
| 1439 | return 1; | ||
| 1440 | } | ||
| 1441 | |||
| 1442 | static int | ||
| 1443 | check_policy(X509_STORE_CTX *ctx) | ||
| 1444 | { | ||
| 1445 | int ret; | ||
| 1446 | |||
| 1447 | if (ctx->parent) | ||
| 1448 | return 1; | ||
| 1449 | ret = X509_policy_check(&ctx->tree, &ctx->explicit_policy, ctx->chain, | ||
| 1450 | ctx->param->policies, ctx->param->flags); | ||
| 1451 | if (ret == 0) { | ||
| 1452 | X509err(X509_F_CHECK_POLICY, ERR_R_MALLOC_FAILURE); | ||
| 1453 | return 0; | ||
| 1454 | } | ||
| 1455 | /* Invalid or inconsistent extensions */ | ||
| 1456 | if (ret == -1) { | ||
| 1457 | /* Locate certificates with bad extensions and notify | ||
| 1458 | * callback. | ||
| 1459 | */ | ||
| 1460 | X509 *x; | ||
| 1461 | int i; | ||
| 1462 | for (i = 1; i < sk_X509_num(ctx->chain); i++) { | ||
| 1463 | x = sk_X509_value(ctx->chain, i); | ||
| 1464 | if (!(x->ex_flags & EXFLAG_INVALID_POLICY)) | ||
| 1465 | continue; | ||
| 1466 | ctx->current_cert = x; | ||
| 1467 | ctx->error = X509_V_ERR_INVALID_POLICY_EXTENSION; | ||
| 1468 | if (!ctx->verify_cb(0, ctx)) | ||
| 1469 | return 0; | ||
| 1470 | } | ||
| 1471 | return 1; | ||
| 1472 | } | ||
| 1473 | if (ret == -2) { | ||
| 1474 | ctx->current_cert = NULL; | ||
| 1475 | ctx->error = X509_V_ERR_NO_EXPLICIT_POLICY; | ||
| 1476 | return ctx->verify_cb(0, ctx); | ||
| 1477 | } | ||
| 1478 | |||
| 1479 | if (ctx->param->flags & X509_V_FLAG_NOTIFY_POLICY) { | ||
| 1480 | ctx->current_cert = NULL; | ||
| 1481 | ctx->error = X509_V_OK; | ||
| 1482 | if (!ctx->verify_cb(2, ctx)) | ||
| 1483 | return 0; | ||
| 1484 | } | ||
| 1485 | |||
| 1486 | return 1; | ||
| 1487 | } | ||
| 1488 | |||
| 1489 | int | ||
| 1490 | x509_check_cert_time(X509_STORE_CTX *ctx, X509 *x, int quiet) | ||
| 1491 | { | ||
| 1492 | time_t *ptime; | ||
| 1493 | int i; | ||
| 1494 | |||
| 1495 | if (ctx->param->flags & X509_V_FLAG_USE_CHECK_TIME) | ||
| 1496 | ptime = &ctx->param->check_time; | ||
| 1497 | else | ||
| 1498 | ptime = NULL; | ||
| 1499 | |||
| 1500 | i = X509_cmp_time(X509_get_notBefore(x), ptime); | ||
| 1501 | if (i == 0) { | ||
| 1502 | if (quiet) | ||
| 1503 | return 0; | ||
| 1504 | ctx->error = X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD; | ||
| 1505 | ctx->current_cert = x; | ||
| 1506 | if (!ctx->verify_cb(0, ctx)) | ||
| 1507 | return 0; | ||
| 1508 | } | ||
| 1509 | |||
| 1510 | if (i > 0) { | ||
| 1511 | if (quiet) | ||
| 1512 | return 0; | ||
| 1513 | ctx->error = X509_V_ERR_CERT_NOT_YET_VALID; | ||
| 1514 | ctx->current_cert = x; | ||
| 1515 | if (!ctx->verify_cb(0, ctx)) | ||
| 1516 | return 0; | ||
| 1517 | } | ||
| 1518 | |||
| 1519 | i = X509_cmp_time(X509_get_notAfter(x), ptime); | ||
| 1520 | if (i == 0) { | ||
| 1521 | if (quiet) | ||
| 1522 | return 0; | ||
| 1523 | ctx->error = X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD; | ||
| 1524 | ctx->current_cert = x; | ||
| 1525 | if (!ctx->verify_cb(0, ctx)) | ||
| 1526 | return 0; | ||
| 1527 | } | ||
| 1528 | |||
| 1529 | if (i < 0) { | ||
| 1530 | if (quiet) | ||
| 1531 | return 0; | ||
| 1532 | ctx->error = X509_V_ERR_CERT_HAS_EXPIRED; | ||
| 1533 | ctx->current_cert = x; | ||
| 1534 | if (!ctx->verify_cb(0, ctx)) | ||
| 1535 | return 0; | ||
| 1536 | } | ||
| 1537 | |||
| 1538 | return 1; | ||
| 1539 | } | ||
| 1540 | |||
| 1541 | static int | ||
| 1542 | internal_verify(X509_STORE_CTX *ctx) | ||
| 1543 | { | ||
| 1544 | int ok = 0, n; | ||
| 1545 | X509 *xs, *xi; | ||
| 1546 | EVP_PKEY *pkey = NULL; | ||
| 1547 | int (*cb)(int xok, X509_STORE_CTX *xctx); | ||
| 1548 | |||
| 1549 | cb = ctx->verify_cb; | ||
| 1550 | |||
| 1551 | n = sk_X509_num(ctx->chain); | ||
| 1552 | ctx->error_depth = n - 1; | ||
| 1553 | n--; | ||
| 1554 | xi = sk_X509_value(ctx->chain, n); | ||
| 1555 | |||
| 1556 | if (ctx->check_issued(ctx, xi, xi)) | ||
| 1557 | xs = xi; | ||
| 1558 | else { | ||
| 1559 | if (n <= 0) { | ||
| 1560 | ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE; | ||
| 1561 | ctx->current_cert = xi; | ||
| 1562 | ok = cb(0, ctx); | ||
| 1563 | goto end; | ||
| 1564 | } else { | ||
| 1565 | n--; | ||
| 1566 | ctx->error_depth = n; | ||
| 1567 | xs = sk_X509_value(ctx->chain, n); | ||
| 1568 | } | ||
| 1569 | } | ||
| 1570 | |||
| 1571 | /* ctx->error=0; not needed */ | ||
| 1572 | while (n >= 0) { | ||
| 1573 | ctx->error_depth = n; | ||
| 1574 | |||
| 1575 | /* Skip signature check for self signed certificates unless | ||
| 1576 | * explicitly asked for. It doesn't add any security and | ||
| 1577 | * just wastes time. | ||
| 1578 | */ | ||
| 1579 | if (!xs->valid && (xs != xi || | ||
| 1580 | (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE))) { | ||
| 1581 | if ((pkey = X509_get_pubkey(xi)) == NULL) { | ||
| 1582 | ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY; | ||
| 1583 | ctx->current_cert = xi; | ||
| 1584 | ok = (*cb)(0, ctx); | ||
| 1585 | if (!ok) | ||
| 1586 | goto end; | ||
| 1587 | } else if (X509_verify(xs, pkey) <= 0) { | ||
| 1588 | ctx->error = X509_V_ERR_CERT_SIGNATURE_FAILURE; | ||
| 1589 | ctx->current_cert = xs; | ||
| 1590 | ok = (*cb)(0, ctx); | ||
| 1591 | if (!ok) { | ||
| 1592 | EVP_PKEY_free(pkey); | ||
| 1593 | goto end; | ||
| 1594 | } | ||
| 1595 | } | ||
| 1596 | EVP_PKEY_free(pkey); | ||
| 1597 | pkey = NULL; | ||
| 1598 | } | ||
| 1599 | |||
| 1600 | xs->valid = 1; | ||
| 1601 | |||
| 1602 | ok = x509_check_cert_time(ctx, xs, 0); | ||
| 1603 | if (!ok) | ||
| 1604 | goto end; | ||
| 1605 | |||
| 1606 | /* The last error (if any) is still in the error value */ | ||
| 1607 | ctx->current_issuer = xi; | ||
| 1608 | ctx->current_cert = xs; | ||
| 1609 | ok = (*cb)(1, ctx); | ||
| 1610 | if (!ok) | ||
| 1611 | goto end; | ||
| 1612 | |||
| 1613 | n--; | ||
| 1614 | if (n >= 0) { | ||
| 1615 | xi = xs; | ||
| 1616 | xs = sk_X509_value(ctx->chain, n); | ||
| 1617 | } | ||
| 1618 | } | ||
| 1619 | ok = 1; | ||
| 1620 | |||
| 1621 | end: | ||
| 1622 | return ok; | ||
| 1623 | } | ||
| 1624 | |||
| 1625 | int | ||
| 1626 | X509_cmp_current_time(const ASN1_TIME *ctm) | ||
| 1627 | { | ||
| 1628 | return X509_cmp_time(ctm, NULL); | ||
| 1629 | } | ||
| 1630 | |||
| 1631 | int | ||
| 1632 | X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time) | ||
| 1633 | { | ||
| 1634 | char *str; | ||
| 1635 | ASN1_TIME atm; | ||
| 1636 | long offset; | ||
| 1637 | char buff1[24], buff2[24], *p; | ||
| 1638 | int i, j; | ||
| 1639 | |||
| 1640 | p = buff1; | ||
| 1641 | i = ctm->length; | ||
| 1642 | str = (char *)ctm->data; | ||
| 1643 | if (ctm->type == V_ASN1_UTCTIME) { | ||
| 1644 | if ((i < 11) || (i > 17)) | ||
| 1645 | return 0; | ||
| 1646 | memcpy(p, str, 10); | ||
| 1647 | p += 10; | ||
| 1648 | str += 10; | ||
| 1649 | i -= 10; | ||
| 1650 | } else { | ||
| 1651 | if (i < 13) | ||
| 1652 | return 0; | ||
| 1653 | memcpy(p, str, 12); | ||
| 1654 | p += 12; | ||
| 1655 | str += 12; | ||
| 1656 | i -= 12; | ||
| 1657 | } | ||
| 1658 | |||
| 1659 | if (i < 1) | ||
| 1660 | return 0; | ||
| 1661 | if ((*str == 'Z') || (*str == '-') || (*str == '+')) { | ||
| 1662 | *(p++) = '0'; | ||
| 1663 | *(p++) = '0'; | ||
| 1664 | } else { | ||
| 1665 | if (i < 2) | ||
| 1666 | return 0; | ||
| 1667 | *(p++) = *(str++); | ||
| 1668 | *(p++) = *(str++); | ||
| 1669 | i -= 2; | ||
| 1670 | if (i < 1) | ||
| 1671 | return 0; | ||
| 1672 | /* Skip any fractional seconds... */ | ||
| 1673 | if (*str == '.') { | ||
| 1674 | str++; | ||
| 1675 | i--; | ||
| 1676 | while (i > 1 && (*str >= '0') && (*str <= '9')) { | ||
| 1677 | str++; | ||
| 1678 | i--; | ||
| 1679 | } | ||
| 1680 | } | ||
| 1681 | } | ||
| 1682 | *(p++) = 'Z'; | ||
| 1683 | *(p++) = '\0'; | ||
| 1684 | |||
| 1685 | if (i < 1) | ||
| 1686 | return 0; | ||
| 1687 | if (*str == 'Z') { | ||
| 1688 | if (i != 1) | ||
| 1689 | return 0; | ||
| 1690 | offset = 0; | ||
| 1691 | } else { | ||
| 1692 | if (i != 5) | ||
| 1693 | return 0; | ||
| 1694 | if ((*str != '+') && (*str != '-')) | ||
| 1695 | return 0; | ||
| 1696 | if (str[1] < '0' || str[1] > '9' || | ||
| 1697 | str[2] < '0' || str[2] > '9' || | ||
| 1698 | str[3] < '0' || str[3] > '9' || | ||
| 1699 | str[4] < '0' || str[4] > '9') | ||
| 1700 | return 0; | ||
| 1701 | offset = ((str[1] - '0') * 10 + (str[2] - '0')) * 60; | ||
| 1702 | offset += (str[3] - '0') * 10 + (str[4] - '0'); | ||
| 1703 | if (*str == '-') | ||
| 1704 | offset = -offset; | ||
| 1705 | } | ||
| 1706 | atm.type = ctm->type; | ||
| 1707 | atm.flags = 0; | ||
| 1708 | atm.length = sizeof(buff2); | ||
| 1709 | atm.data = (unsigned char *)buff2; | ||
| 1710 | |||
| 1711 | if (X509_time_adj(&atm, offset * 60, cmp_time) == NULL) | ||
| 1712 | return 0; | ||
| 1713 | |||
| 1714 | if (ctm->type == V_ASN1_UTCTIME) { | ||
| 1715 | i = (buff1[0] - '0') * 10 + (buff1[1] - '0'); | ||
| 1716 | if (i < 50) | ||
| 1717 | i += 100; /* cf. RFC 2459 */ | ||
| 1718 | j = (buff2[0] - '0') * 10 + (buff2[1] - '0'); | ||
| 1719 | if (j < 50) | ||
| 1720 | j += 100; | ||
| 1721 | if (i < j) | ||
| 1722 | return -1; | ||
| 1723 | if (i > j) | ||
| 1724 | return 1; | ||
| 1725 | } | ||
| 1726 | i = strcmp(buff1, buff2); | ||
| 1727 | if (i == 0) /* wait a second then return younger :-) */ | ||
| 1728 | return -1; | ||
| 1729 | else | ||
| 1730 | return i; | ||
| 1731 | } | ||
| 1732 | |||
| 1733 | ASN1_TIME * | ||
| 1734 | X509_gmtime_adj(ASN1_TIME *s, long adj) | ||
| 1735 | { | ||
| 1736 | return X509_time_adj(s, adj, NULL); | ||
| 1737 | } | ||
| 1738 | |||
| 1739 | ASN1_TIME * | ||
| 1740 | X509_time_adj(ASN1_TIME *s, long offset_sec, time_t *in_tm) | ||
| 1741 | { | ||
| 1742 | return X509_time_adj_ex(s, 0, offset_sec, in_tm); | ||
| 1743 | } | ||
| 1744 | |||
| 1745 | ASN1_TIME * | ||
| 1746 | X509_time_adj_ex(ASN1_TIME *s, int offset_day, long offset_sec, time_t *in_tm) | ||
| 1747 | { | ||
| 1748 | time_t t; | ||
| 1749 | |||
| 1750 | if (in_tm) | ||
| 1751 | t = *in_tm; | ||
| 1752 | else | ||
| 1753 | time(&t); | ||
| 1754 | |||
| 1755 | if (s && !(s->flags & ASN1_STRING_FLAG_MSTRING)) { | ||
| 1756 | if (s->type == V_ASN1_UTCTIME) | ||
| 1757 | return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); | ||
| 1758 | if (s->type == V_ASN1_GENERALIZEDTIME) | ||
| 1759 | return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, | ||
| 1760 | offset_sec); | ||
| 1761 | } | ||
| 1762 | return ASN1_TIME_adj(s, t, offset_day, offset_sec); | ||
| 1763 | } | ||
| 1764 | |||
| 1765 | int | ||
| 1766 | X509_get_pubkey_parameters(EVP_PKEY *pkey, STACK_OF(X509) *chain) | ||
| 1767 | { | ||
| 1768 | EVP_PKEY *ktmp = NULL, *ktmp2; | ||
| 1769 | int i, j; | ||
| 1770 | |||
| 1771 | if ((pkey != NULL) && !EVP_PKEY_missing_parameters(pkey)) | ||
| 1772 | return 1; | ||
| 1773 | |||
| 1774 | for (i = 0; i < sk_X509_num(chain); i++) { | ||
| 1775 | ktmp = X509_get_pubkey(sk_X509_value(chain, i)); | ||
| 1776 | if (ktmp == NULL) { | ||
| 1777 | X509err(X509_F_X509_GET_PUBKEY_PARAMETERS, | ||
| 1778 | X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY); | ||
| 1779 | return 0; | ||
| 1780 | } | ||
| 1781 | if (!EVP_PKEY_missing_parameters(ktmp)) | ||
| 1782 | break; | ||
| 1783 | else { | ||
| 1784 | EVP_PKEY_free(ktmp); | ||
| 1785 | ktmp = NULL; | ||
| 1786 | } | ||
| 1787 | } | ||
| 1788 | if (ktmp == NULL) { | ||
| 1789 | X509err(X509_F_X509_GET_PUBKEY_PARAMETERS, | ||
| 1790 | X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN); | ||
| 1791 | return 0; | ||
| 1792 | } | ||
| 1793 | |||
| 1794 | /* first, populate the other certs */ | ||
| 1795 | for (j = i - 1; j >= 0; j--) { | ||
| 1796 | ktmp2 = X509_get_pubkey(sk_X509_value(chain, j)); | ||
| 1797 | EVP_PKEY_copy_parameters(ktmp2, ktmp); | ||
| 1798 | EVP_PKEY_free(ktmp2); | ||
| 1799 | } | ||
| 1800 | |||
| 1801 | if (pkey != NULL) | ||
| 1802 | EVP_PKEY_copy_parameters(pkey, ktmp); | ||
| 1803 | EVP_PKEY_free(ktmp); | ||
| 1804 | return 1; | ||
| 1805 | } | ||
| 1806 | |||
| 1807 | int | ||
| 1808 | X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 1809 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
| 1810 | { | ||
| 1811 | /* This function is (usually) called only once, by | ||
| 1812 | * SSL_get_ex_data_X509_STORE_CTX_idx (ssl/ssl_cert.c). */ | ||
| 1813 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509_STORE_CTX, | ||
| 1814 | argl, argp, new_func, dup_func, free_func); | ||
| 1815 | } | ||
| 1816 | |||
| 1817 | int | ||
| 1818 | X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data) | ||
| 1819 | { | ||
| 1820 | return CRYPTO_set_ex_data(&ctx->ex_data, idx, data); | ||
| 1821 | } | ||
| 1822 | |||
| 1823 | void * | ||
| 1824 | X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx) | ||
| 1825 | { | ||
| 1826 | return CRYPTO_get_ex_data(&ctx->ex_data, idx); | ||
| 1827 | } | ||
| 1828 | |||
| 1829 | int | ||
| 1830 | X509_STORE_CTX_get_error(X509_STORE_CTX *ctx) | ||
| 1831 | { | ||
| 1832 | return ctx->error; | ||
| 1833 | } | ||
| 1834 | |||
| 1835 | void | ||
| 1836 | X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err) | ||
| 1837 | { | ||
| 1838 | ctx->error = err; | ||
| 1839 | } | ||
| 1840 | |||
| 1841 | int | ||
| 1842 | X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx) | ||
| 1843 | { | ||
| 1844 | return ctx->error_depth; | ||
| 1845 | } | ||
| 1846 | |||
| 1847 | X509 * | ||
| 1848 | X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx) | ||
| 1849 | { | ||
| 1850 | return ctx->current_cert; | ||
| 1851 | } | ||
| 1852 | |||
| 1853 | STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx) | ||
| 1854 | { | ||
| 1855 | return ctx->chain; | ||
| 1856 | } | ||
| 1857 | |||
| 1858 | STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx) | ||
| 1859 | { | ||
| 1860 | int i; | ||
| 1861 | X509 *x; | ||
| 1862 | STACK_OF(X509) *chain; | ||
| 1863 | |||
| 1864 | if (!ctx->chain || !(chain = sk_X509_dup(ctx->chain))) | ||
| 1865 | return NULL; | ||
| 1866 | for (i = 0; i < sk_X509_num(chain); i++) { | ||
| 1867 | x = sk_X509_value(chain, i); | ||
| 1868 | CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); | ||
| 1869 | } | ||
| 1870 | return chain; | ||
| 1871 | } | ||
| 1872 | |||
| 1873 | X509 * | ||
| 1874 | X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx) | ||
| 1875 | { | ||
| 1876 | return ctx->current_issuer; | ||
| 1877 | } | ||
| 1878 | |||
| 1879 | X509_CRL * | ||
| 1880 | X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx) | ||
| 1881 | { | ||
| 1882 | return ctx->current_crl; | ||
| 1883 | } | ||
| 1884 | |||
| 1885 | X509_STORE_CTX * | ||
| 1886 | X509_STORE_CTX_get0_parent_ctx(X509_STORE_CTX *ctx) | ||
| 1887 | { | ||
| 1888 | return ctx->parent; | ||
| 1889 | } | ||
| 1890 | |||
| 1891 | void | ||
| 1892 | X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x) | ||
| 1893 | { | ||
| 1894 | ctx->cert = x; | ||
| 1895 | } | ||
| 1896 | |||
| 1897 | void | ||
| 1898 | X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk) | ||
| 1899 | { | ||
| 1900 | ctx->untrusted = sk; | ||
| 1901 | } | ||
| 1902 | |||
| 1903 | void | ||
| 1904 | X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, STACK_OF(X509_CRL) *sk) | ||
| 1905 | { | ||
| 1906 | ctx->crls = sk; | ||
| 1907 | } | ||
| 1908 | |||
| 1909 | int | ||
| 1910 | X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose) | ||
| 1911 | { | ||
| 1912 | return X509_STORE_CTX_purpose_inherit(ctx, 0, purpose, 0); | ||
| 1913 | } | ||
| 1914 | |||
| 1915 | int | ||
| 1916 | X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust) | ||
| 1917 | { | ||
| 1918 | return X509_STORE_CTX_purpose_inherit(ctx, 0, 0, trust); | ||
| 1919 | } | ||
| 1920 | |||
| 1921 | /* This function is used to set the X509_STORE_CTX purpose and trust | ||
| 1922 | * values. This is intended to be used when another structure has its | ||
| 1923 | * own trust and purpose values which (if set) will be inherited by | ||
| 1924 | * the ctx. If they aren't set then we will usually have a default | ||
| 1925 | * purpose in mind which should then be used to set the trust value. | ||
| 1926 | * An example of this is SSL use: an SSL structure will have its own | ||
| 1927 | * purpose and trust settings which the application can set: if they | ||
| 1928 | * aren't set then we use the default of SSL client/server. | ||
| 1929 | */ | ||
| 1930 | |||
| 1931 | int | ||
| 1932 | X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose, | ||
| 1933 | int purpose, int trust) | ||
| 1934 | { | ||
| 1935 | int idx; | ||
| 1936 | |||
| 1937 | /* If purpose not set use default */ | ||
| 1938 | if (!purpose) | ||
| 1939 | purpose = def_purpose; | ||
| 1940 | /* If we have a purpose then check it is valid */ | ||
| 1941 | if (purpose) { | ||
| 1942 | X509_PURPOSE *ptmp; | ||
| 1943 | idx = X509_PURPOSE_get_by_id(purpose); | ||
| 1944 | if (idx == -1) { | ||
| 1945 | X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT, | ||
| 1946 | X509_R_UNKNOWN_PURPOSE_ID); | ||
| 1947 | return 0; | ||
| 1948 | } | ||
| 1949 | ptmp = X509_PURPOSE_get0(idx); | ||
| 1950 | if (ptmp->trust == X509_TRUST_DEFAULT) { | ||
| 1951 | idx = X509_PURPOSE_get_by_id(def_purpose); | ||
| 1952 | if (idx == -1) { | ||
| 1953 | X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT, | ||
| 1954 | X509_R_UNKNOWN_PURPOSE_ID); | ||
| 1955 | return 0; | ||
| 1956 | } | ||
| 1957 | ptmp = X509_PURPOSE_get0(idx); | ||
| 1958 | } | ||
| 1959 | /* If trust not set then get from purpose default */ | ||
| 1960 | if (!trust) | ||
| 1961 | trust = ptmp->trust; | ||
| 1962 | } | ||
| 1963 | if (trust) { | ||
| 1964 | idx = X509_TRUST_get_by_id(trust); | ||
| 1965 | if (idx == -1) { | ||
| 1966 | X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT, | ||
| 1967 | X509_R_UNKNOWN_TRUST_ID); | ||
| 1968 | return 0; | ||
| 1969 | } | ||
| 1970 | } | ||
| 1971 | |||
| 1972 | if (purpose && !ctx->param->purpose) | ||
| 1973 | ctx->param->purpose = purpose; | ||
| 1974 | if (trust && !ctx->param->trust) | ||
| 1975 | ctx->param->trust = trust; | ||
| 1976 | return 1; | ||
| 1977 | } | ||
| 1978 | |||
| 1979 | X509_STORE_CTX * | ||
| 1980 | X509_STORE_CTX_new(void) | ||
| 1981 | { | ||
| 1982 | X509_STORE_CTX *ctx; | ||
| 1983 | |||
| 1984 | ctx = calloc(1, sizeof(X509_STORE_CTX)); | ||
| 1985 | if (!ctx) { | ||
| 1986 | X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE); | ||
| 1987 | return NULL; | ||
| 1988 | } | ||
| 1989 | return ctx; | ||
| 1990 | } | ||
| 1991 | |||
| 1992 | void | ||
| 1993 | X509_STORE_CTX_free(X509_STORE_CTX *ctx) | ||
| 1994 | { | ||
| 1995 | if (ctx == NULL) | ||
| 1996 | return; | ||
| 1997 | |||
| 1998 | X509_STORE_CTX_cleanup(ctx); | ||
| 1999 | free(ctx); | ||
| 2000 | } | ||
| 2001 | |||
| 2002 | int | ||
| 2003 | X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509, | ||
| 2004 | STACK_OF(X509) *chain) | ||
| 2005 | { | ||
| 2006 | int param_ret = 1; | ||
| 2007 | |||
| 2008 | /* | ||
| 2009 | * Make sure everything is initialized properly even in case of an | ||
| 2010 | * early return due to an error. | ||
| 2011 | * | ||
| 2012 | * While this 'ctx' can be reused, X509_STORE_CTX_cleanup() will have | ||
| 2013 | * freed everything and memset ex_data anyway. This also allows us | ||
| 2014 | * to safely use X509_STORE_CTX variables from the stack which will | ||
| 2015 | * have uninitialized data. | ||
| 2016 | */ | ||
| 2017 | memset(ctx, 0, sizeof(*ctx)); | ||
| 2018 | |||
| 2019 | /* | ||
| 2020 | * Set values other than 0. Keep this in the same order as | ||
| 2021 | * X509_STORE_CTX except for values that may fail. All fields that | ||
| 2022 | * may fail should go last to make sure 'ctx' is as consistent as | ||
| 2023 | * possible even on early exits. | ||
| 2024 | */ | ||
| 2025 | ctx->ctx = store; | ||
| 2026 | ctx->cert = x509; | ||
| 2027 | ctx->untrusted = chain; | ||
| 2028 | |||
| 2029 | if (store && store->verify) | ||
| 2030 | ctx->verify = store->verify; | ||
| 2031 | else | ||
| 2032 | ctx->verify = internal_verify; | ||
| 2033 | |||
| 2034 | if (store && store->verify_cb) | ||
| 2035 | ctx->verify_cb = store->verify_cb; | ||
| 2036 | else | ||
| 2037 | ctx->verify_cb = null_callback; | ||
| 2038 | |||
| 2039 | if (store && store->get_issuer) | ||
| 2040 | ctx->get_issuer = store->get_issuer; | ||
| 2041 | else | ||
| 2042 | ctx->get_issuer = X509_STORE_CTX_get1_issuer; | ||
| 2043 | |||
| 2044 | if (store && store->check_issued) | ||
| 2045 | ctx->check_issued = store->check_issued; | ||
| 2046 | else | ||
| 2047 | ctx->check_issued = check_issued; | ||
| 2048 | |||
| 2049 | if (store && store->check_revocation) | ||
| 2050 | ctx->check_revocation = store->check_revocation; | ||
| 2051 | else | ||
| 2052 | ctx->check_revocation = check_revocation; | ||
| 2053 | |||
| 2054 | if (store && store->get_crl) | ||
| 2055 | ctx->get_crl = store->get_crl; | ||
| 2056 | else | ||
| 2057 | ctx->get_crl = NULL; | ||
| 2058 | |||
| 2059 | if (store && store->check_crl) | ||
| 2060 | ctx->check_crl = store->check_crl; | ||
| 2061 | else | ||
| 2062 | ctx->check_crl = check_crl; | ||
| 2063 | |||
| 2064 | if (store && store->cert_crl) | ||
| 2065 | ctx->cert_crl = store->cert_crl; | ||
| 2066 | else | ||
| 2067 | ctx->cert_crl = cert_crl; | ||
| 2068 | |||
| 2069 | ctx->check_policy = check_policy; | ||
| 2070 | |||
| 2071 | if (store && store->lookup_certs) | ||
| 2072 | ctx->lookup_certs = store->lookup_certs; | ||
| 2073 | else | ||
| 2074 | ctx->lookup_certs = X509_STORE_get1_certs; | ||
| 2075 | |||
| 2076 | if (store && store->lookup_crls) | ||
| 2077 | ctx->lookup_crls = store->lookup_crls; | ||
| 2078 | else | ||
| 2079 | ctx->lookup_crls = X509_STORE_get1_crls; | ||
| 2080 | |||
| 2081 | if (store && store->cleanup) | ||
| 2082 | ctx->cleanup = store->cleanup; | ||
| 2083 | else | ||
| 2084 | ctx->cleanup = NULL; | ||
| 2085 | |||
| 2086 | ctx->param = X509_VERIFY_PARAM_new(); | ||
| 2087 | if (!ctx->param) { | ||
| 2088 | X509err(X509_F_X509_STORE_CTX_INIT, ERR_R_MALLOC_FAILURE); | ||
| 2089 | return 0; | ||
| 2090 | } | ||
| 2091 | |||
| 2092 | /* Inherit callbacks and flags from X509_STORE if not set | ||
| 2093 | * use defaults. | ||
| 2094 | */ | ||
| 2095 | if (store) | ||
| 2096 | param_ret = X509_VERIFY_PARAM_inherit(ctx->param, store->param); | ||
| 2097 | else | ||
| 2098 | ctx->param->inh_flags |= X509_VP_FLAG_DEFAULT|X509_VP_FLAG_ONCE; | ||
| 2099 | |||
| 2100 | if (param_ret) | ||
| 2101 | param_ret = X509_VERIFY_PARAM_inherit(ctx->param, | ||
| 2102 | X509_VERIFY_PARAM_lookup("default")); | ||
| 2103 | |||
| 2104 | if (param_ret == 0) { | ||
| 2105 | X509err(X509_F_X509_STORE_CTX_INIT, ERR_R_MALLOC_FAILURE); | ||
| 2106 | return 0; | ||
| 2107 | } | ||
| 2108 | |||
| 2109 | if (CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, ctx, | ||
| 2110 | &(ctx->ex_data)) == 0) { | ||
| 2111 | X509err(X509_F_X509_STORE_CTX_INIT, ERR_R_MALLOC_FAILURE); | ||
| 2112 | return 0; | ||
| 2113 | } | ||
| 2114 | return 1; | ||
| 2115 | } | ||
| 2116 | |||
| 2117 | /* Set alternative lookup method: just a STACK of trusted certificates. | ||
| 2118 | * This avoids X509_STORE nastiness where it isn't needed. | ||
| 2119 | */ | ||
| 2120 | |||
| 2121 | void | ||
| 2122 | X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk) | ||
| 2123 | { | ||
| 2124 | ctx->other_ctx = sk; | ||
| 2125 | ctx->get_issuer = get_issuer_sk; | ||
| 2126 | } | ||
| 2127 | |||
| 2128 | void | ||
| 2129 | X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx) | ||
| 2130 | { | ||
| 2131 | if (ctx->cleanup) | ||
| 2132 | ctx->cleanup(ctx); | ||
| 2133 | if (ctx->param != NULL) { | ||
| 2134 | if (ctx->parent == NULL) | ||
| 2135 | X509_VERIFY_PARAM_free(ctx->param); | ||
| 2136 | ctx->param = NULL; | ||
| 2137 | } | ||
| 2138 | if (ctx->tree != NULL) { | ||
| 2139 | X509_policy_tree_free(ctx->tree); | ||
| 2140 | ctx->tree = NULL; | ||
| 2141 | } | ||
| 2142 | if (ctx->chain != NULL) { | ||
| 2143 | sk_X509_pop_free(ctx->chain, X509_free); | ||
| 2144 | ctx->chain = NULL; | ||
| 2145 | } | ||
| 2146 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, | ||
| 2147 | ctx, &(ctx->ex_data)); | ||
| 2148 | memset(&ctx->ex_data, 0, sizeof(CRYPTO_EX_DATA)); | ||
| 2149 | } | ||
| 2150 | |||
| 2151 | void | ||
| 2152 | X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth) | ||
| 2153 | { | ||
| 2154 | X509_VERIFY_PARAM_set_depth(ctx->param, depth); | ||
| 2155 | } | ||
| 2156 | |||
| 2157 | void | ||
| 2158 | X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags) | ||
| 2159 | { | ||
| 2160 | X509_VERIFY_PARAM_set_flags(ctx->param, flags); | ||
| 2161 | } | ||
| 2162 | |||
| 2163 | void | ||
| 2164 | X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags, time_t t) | ||
| 2165 | { | ||
| 2166 | X509_VERIFY_PARAM_set_time(ctx->param, t); | ||
| 2167 | } | ||
| 2168 | |||
| 2169 | void | ||
| 2170 | X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx, | ||
| 2171 | int (*verify_cb)(int, X509_STORE_CTX *)) | ||
| 2172 | { | ||
| 2173 | ctx->verify_cb = verify_cb; | ||
| 2174 | } | ||
| 2175 | |||
| 2176 | X509_POLICY_TREE * | ||
| 2177 | X509_STORE_CTX_get0_policy_tree(X509_STORE_CTX *ctx) | ||
| 2178 | { | ||
| 2179 | return ctx->tree; | ||
| 2180 | } | ||
| 2181 | |||
| 2182 | int | ||
| 2183 | X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx) | ||
| 2184 | { | ||
| 2185 | return ctx->explicit_policy; | ||
| 2186 | } | ||
| 2187 | |||
| 2188 | int | ||
| 2189 | X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name) | ||
| 2190 | { | ||
| 2191 | const X509_VERIFY_PARAM *param; | ||
| 2192 | param = X509_VERIFY_PARAM_lookup(name); | ||
| 2193 | if (!param) | ||
| 2194 | return 0; | ||
| 2195 | return X509_VERIFY_PARAM_inherit(ctx->param, param); | ||
| 2196 | } | ||
| 2197 | |||
| 2198 | X509_VERIFY_PARAM * | ||
| 2199 | X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx) | ||
| 2200 | { | ||
| 2201 | return ctx->param; | ||
| 2202 | } | ||
| 2203 | |||
| 2204 | void | ||
| 2205 | X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param) | ||
| 2206 | { | ||
| 2207 | if (ctx->param) | ||
| 2208 | X509_VERIFY_PARAM_free(ctx->param); | ||
| 2209 | ctx->param = param; | ||
| 2210 | } | ||
diff --git a/src/lib/libcrypto/x509/x509_vfy.h b/src/lib/libcrypto/x509/x509_vfy.h deleted file mode 100644 index e760279b52..0000000000 --- a/src/lib/libcrypto/x509/x509_vfy.h +++ /dev/null | |||
| @@ -1,559 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_vfy.h,v 1.15 2015/02/07 13:19:15 doug Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_X509_H | ||
| 60 | #include <openssl/x509.h> | ||
| 61 | /* openssl/x509.h ends up #include-ing this file at about the only | ||
| 62 | * appropriate moment. */ | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #ifndef HEADER_X509_VFY_H | ||
| 66 | #define HEADER_X509_VFY_H | ||
| 67 | |||
| 68 | #include <openssl/opensslconf.h> | ||
| 69 | |||
| 70 | #ifndef OPENSSL_NO_LHASH | ||
| 71 | #include <openssl/lhash.h> | ||
| 72 | #endif | ||
| 73 | #include <openssl/bio.h> | ||
| 74 | #include <openssl/crypto.h> | ||
| 75 | |||
| 76 | #ifdef __cplusplus | ||
| 77 | extern "C" { | ||
| 78 | #endif | ||
| 79 | |||
| 80 | typedef struct x509_file_st | ||
| 81 | { | ||
| 82 | int num_paths; /* number of paths to files or directories */ | ||
| 83 | int num_alloced; | ||
| 84 | char **paths; /* the list of paths or directories */ | ||
| 85 | int *path_type; | ||
| 86 | } X509_CERT_FILE_CTX; | ||
| 87 | |||
| 88 | /*******************************/ | ||
| 89 | /* | ||
| 90 | SSL_CTX -> X509_STORE | ||
| 91 | -> X509_LOOKUP | ||
| 92 | ->X509_LOOKUP_METHOD | ||
| 93 | -> X509_LOOKUP | ||
| 94 | ->X509_LOOKUP_METHOD | ||
| 95 | |||
| 96 | SSL -> X509_STORE_CTX | ||
| 97 | ->X509_STORE | ||
| 98 | |||
| 99 | The X509_STORE holds the tables etc for verification stuff. | ||
| 100 | A X509_STORE_CTX is used while validating a single certificate. | ||
| 101 | The X509_STORE has X509_LOOKUPs for looking up certs. | ||
| 102 | The X509_STORE then calls a function to actually verify the | ||
| 103 | certificate chain. | ||
| 104 | */ | ||
| 105 | |||
| 106 | #define X509_LU_RETRY -1 | ||
| 107 | #define X509_LU_FAIL 0 | ||
| 108 | #define X509_LU_X509 1 | ||
| 109 | #define X509_LU_CRL 2 | ||
| 110 | #define X509_LU_PKEY 3 | ||
| 111 | |||
| 112 | typedef struct x509_object_st | ||
| 113 | { | ||
| 114 | /* one of the above types */ | ||
| 115 | int type; | ||
| 116 | union { | ||
| 117 | char *ptr; | ||
| 118 | X509 *x509; | ||
| 119 | X509_CRL *crl; | ||
| 120 | EVP_PKEY *pkey; | ||
| 121 | } data; | ||
| 122 | } X509_OBJECT; | ||
| 123 | |||
| 124 | typedef struct x509_lookup_st X509_LOOKUP; | ||
| 125 | |||
| 126 | DECLARE_STACK_OF(X509_LOOKUP) | ||
| 127 | DECLARE_STACK_OF(X509_OBJECT) | ||
| 128 | |||
| 129 | /* This is a static that defines the function interface */ | ||
| 130 | typedef struct x509_lookup_method_st | ||
| 131 | { | ||
| 132 | const char *name; | ||
| 133 | int (*new_item)(X509_LOOKUP *ctx); | ||
| 134 | void (*free)(X509_LOOKUP *ctx); | ||
| 135 | int (*init)(X509_LOOKUP *ctx); | ||
| 136 | int (*shutdown)(X509_LOOKUP *ctx); | ||
| 137 | int (*ctrl)(X509_LOOKUP *ctx,int cmd,const char *argc,long argl, | ||
| 138 | char **ret); | ||
| 139 | int (*get_by_subject)(X509_LOOKUP *ctx,int type,X509_NAME *name, | ||
| 140 | X509_OBJECT *ret); | ||
| 141 | int (*get_by_issuer_serial)(X509_LOOKUP *ctx,int type,X509_NAME *name, | ||
| 142 | ASN1_INTEGER *serial,X509_OBJECT *ret); | ||
| 143 | int (*get_by_fingerprint)(X509_LOOKUP *ctx,int type, | ||
| 144 | unsigned char *bytes,int len, | ||
| 145 | X509_OBJECT *ret); | ||
| 146 | int (*get_by_alias)(X509_LOOKUP *ctx,int type,char *str,int len, | ||
| 147 | X509_OBJECT *ret); | ||
| 148 | } X509_LOOKUP_METHOD; | ||
| 149 | |||
| 150 | /* This structure hold all parameters associated with a verify operation | ||
| 151 | * by including an X509_VERIFY_PARAM structure in related structures the | ||
| 152 | * parameters used can be customized | ||
| 153 | */ | ||
| 154 | |||
| 155 | typedef struct X509_VERIFY_PARAM_st | ||
| 156 | { | ||
| 157 | char *name; | ||
| 158 | time_t check_time; /* Time to use */ | ||
| 159 | unsigned long inh_flags; /* Inheritance flags */ | ||
| 160 | unsigned long flags; /* Various verify flags */ | ||
| 161 | int purpose; /* purpose to check untrusted certificates */ | ||
| 162 | int trust; /* trust setting to check */ | ||
| 163 | int depth; /* Verify depth */ | ||
| 164 | STACK_OF(ASN1_OBJECT) *policies; /* Permissible policies */ | ||
| 165 | } X509_VERIFY_PARAM; | ||
| 166 | |||
| 167 | DECLARE_STACK_OF(X509_VERIFY_PARAM) | ||
| 168 | |||
| 169 | /* This is used to hold everything. It is used for all certificate | ||
| 170 | * validation. Once we have a certificate chain, the 'verify' | ||
| 171 | * function is then called to actually check the cert chain. */ | ||
| 172 | struct x509_store_st | ||
| 173 | { | ||
| 174 | /* The following is a cache of trusted certs */ | ||
| 175 | int cache; /* if true, stash any hits */ | ||
| 176 | STACK_OF(X509_OBJECT) *objs; /* Cache of all objects */ | ||
| 177 | |||
| 178 | /* These are external lookup methods */ | ||
| 179 | STACK_OF(X509_LOOKUP) *get_cert_methods; | ||
| 180 | |||
| 181 | X509_VERIFY_PARAM *param; | ||
| 182 | |||
| 183 | /* Callbacks for various operations */ | ||
| 184 | int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */ | ||
| 185 | int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */ | ||
| 186 | int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */ | ||
| 187 | int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */ | ||
| 188 | int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */ | ||
| 189 | int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */ | ||
| 190 | int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */ | ||
| 191 | int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */ | ||
| 192 | STACK_OF(X509) * (*lookup_certs)(X509_STORE_CTX *ctx, X509_NAME *nm); | ||
| 193 | STACK_OF(X509_CRL) * (*lookup_crls)(X509_STORE_CTX *ctx, X509_NAME *nm); | ||
| 194 | int (*cleanup)(X509_STORE_CTX *ctx); | ||
| 195 | |||
| 196 | CRYPTO_EX_DATA ex_data; | ||
| 197 | int references; | ||
| 198 | } /* X509_STORE */; | ||
| 199 | |||
| 200 | int X509_STORE_set_depth(X509_STORE *store, int depth); | ||
| 201 | |||
| 202 | #define X509_STORE_set_verify_cb_func(ctx,func) ((ctx)->verify_cb=(func)) | ||
| 203 | #define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func)) | ||
| 204 | |||
| 205 | /* This is the functions plus an instance of the local variables. */ | ||
| 206 | struct x509_lookup_st | ||
| 207 | { | ||
| 208 | int init; /* have we been started */ | ||
| 209 | int skip; /* don't use us. */ | ||
| 210 | X509_LOOKUP_METHOD *method; /* the functions */ | ||
| 211 | char *method_data; /* method data */ | ||
| 212 | |||
| 213 | X509_STORE *store_ctx; /* who owns us */ | ||
| 214 | } /* X509_LOOKUP */; | ||
| 215 | |||
| 216 | /* This is a used when verifying cert chains. Since the | ||
| 217 | * gathering of the cert chain can take some time (and have to be | ||
| 218 | * 'retried', this needs to be kept and passed around. */ | ||
| 219 | struct x509_store_ctx_st /* X509_STORE_CTX */ | ||
| 220 | { | ||
| 221 | X509_STORE *ctx; | ||
| 222 | int current_method; /* used when looking up certs */ | ||
| 223 | |||
| 224 | /* The following are set by the caller */ | ||
| 225 | X509 *cert; /* The cert to check */ | ||
| 226 | STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */ | ||
| 227 | STACK_OF(X509_CRL) *crls; /* set of CRLs passed in */ | ||
| 228 | |||
| 229 | X509_VERIFY_PARAM *param; | ||
| 230 | void *other_ctx; /* Other info for use with get_issuer() */ | ||
| 231 | |||
| 232 | /* Callbacks for various operations */ | ||
| 233 | int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */ | ||
| 234 | int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */ | ||
| 235 | int (*get_issuer)(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); /* get issuers cert from ctx */ | ||
| 236 | int (*check_issued)(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); /* check issued */ | ||
| 237 | int (*check_revocation)(X509_STORE_CTX *ctx); /* Check revocation status of chain */ | ||
| 238 | int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */ | ||
| 239 | int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */ | ||
| 240 | int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */ | ||
| 241 | int (*check_policy)(X509_STORE_CTX *ctx); | ||
| 242 | STACK_OF(X509) * (*lookup_certs)(X509_STORE_CTX *ctx, X509_NAME *nm); | ||
| 243 | STACK_OF(X509_CRL) * (*lookup_crls)(X509_STORE_CTX *ctx, X509_NAME *nm); | ||
| 244 | int (*cleanup)(X509_STORE_CTX *ctx); | ||
| 245 | |||
| 246 | /* The following is built up */ | ||
| 247 | int valid; /* if 0, rebuild chain */ | ||
| 248 | int last_untrusted; /* index of last untrusted cert */ | ||
| 249 | STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */ | ||
| 250 | X509_POLICY_TREE *tree; /* Valid policy tree */ | ||
| 251 | |||
| 252 | int explicit_policy; /* Require explicit policy value */ | ||
| 253 | |||
| 254 | /* When something goes wrong, this is why */ | ||
| 255 | int error_depth; | ||
| 256 | int error; | ||
| 257 | X509 *current_cert; | ||
| 258 | X509 *current_issuer; /* cert currently being tested as valid issuer */ | ||
| 259 | X509_CRL *current_crl; /* current CRL */ | ||
| 260 | |||
| 261 | int current_crl_score; /* score of current CRL */ | ||
| 262 | unsigned int current_reasons; /* Reason mask */ | ||
| 263 | |||
| 264 | X509_STORE_CTX *parent; /* For CRL path validation: parent context */ | ||
| 265 | |||
| 266 | CRYPTO_EX_DATA ex_data; | ||
| 267 | } /* X509_STORE_CTX */; | ||
| 268 | |||
| 269 | void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); | ||
| 270 | |||
| 271 | #define X509_STORE_CTX_set_app_data(ctx,data) \ | ||
| 272 | X509_STORE_CTX_set_ex_data(ctx,0,data) | ||
| 273 | #define X509_STORE_CTX_get_app_data(ctx) \ | ||
| 274 | X509_STORE_CTX_get_ex_data(ctx,0) | ||
| 275 | |||
| 276 | #define X509_L_FILE_LOAD 1 | ||
| 277 | #define X509_L_ADD_DIR 2 | ||
| 278 | #define X509_L_MEM 3 | ||
| 279 | |||
| 280 | #define X509_LOOKUP_load_file(x,name,type) \ | ||
| 281 | X509_LOOKUP_ctrl((x),X509_L_FILE_LOAD,(name),(long)(type),NULL) | ||
| 282 | |||
| 283 | #define X509_LOOKUP_add_dir(x,name,type) \ | ||
| 284 | X509_LOOKUP_ctrl((x),X509_L_ADD_DIR,(name),(long)(type),NULL) | ||
| 285 | |||
| 286 | #define X509_LOOKUP_add_mem(x,iov,type) \ | ||
| 287 | X509_LOOKUP_ctrl((x),X509_L_MEM,(const char *)(iov),\ | ||
| 288 | (long)(type),NULL) | ||
| 289 | |||
| 290 | #define X509_V_OK 0 | ||
| 291 | /* illegal error (for uninitialized values, to avoid X509_V_OK): 1 */ | ||
| 292 | |||
| 293 | #define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 | ||
| 294 | #define X509_V_ERR_UNABLE_TO_GET_CRL 3 | ||
| 295 | #define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 | ||
| 296 | #define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 | ||
| 297 | #define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 | ||
| 298 | #define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 | ||
| 299 | #define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 | ||
| 300 | #define X509_V_ERR_CERT_NOT_YET_VALID 9 | ||
| 301 | #define X509_V_ERR_CERT_HAS_EXPIRED 10 | ||
| 302 | #define X509_V_ERR_CRL_NOT_YET_VALID 11 | ||
| 303 | #define X509_V_ERR_CRL_HAS_EXPIRED 12 | ||
| 304 | #define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 | ||
| 305 | #define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 | ||
| 306 | #define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 | ||
| 307 | #define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 | ||
| 308 | #define X509_V_ERR_OUT_OF_MEM 17 | ||
| 309 | #define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 | ||
| 310 | #define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 | ||
| 311 | #define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 | ||
| 312 | #define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 | ||
| 313 | #define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 | ||
| 314 | #define X509_V_ERR_CERT_REVOKED 23 | ||
| 315 | #define X509_V_ERR_INVALID_CA 24 | ||
| 316 | #define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 | ||
| 317 | #define X509_V_ERR_INVALID_PURPOSE 26 | ||
| 318 | #define X509_V_ERR_CERT_UNTRUSTED 27 | ||
| 319 | #define X509_V_ERR_CERT_REJECTED 28 | ||
| 320 | /* These are 'informational' when looking for issuer cert */ | ||
| 321 | #define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 | ||
| 322 | #define X509_V_ERR_AKID_SKID_MISMATCH 30 | ||
| 323 | #define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 | ||
| 324 | #define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 | ||
| 325 | |||
| 326 | #define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 | ||
| 327 | #define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 | ||
| 328 | #define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 | ||
| 329 | #define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 | ||
| 330 | #define X509_V_ERR_INVALID_NON_CA 37 | ||
| 331 | #define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 | ||
| 332 | #define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 | ||
| 333 | #define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 | ||
| 334 | |||
| 335 | #define X509_V_ERR_INVALID_EXTENSION 41 | ||
| 336 | #define X509_V_ERR_INVALID_POLICY_EXTENSION 42 | ||
| 337 | #define X509_V_ERR_NO_EXPLICIT_POLICY 43 | ||
| 338 | #define X509_V_ERR_DIFFERENT_CRL_SCOPE 44 | ||
| 339 | #define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45 | ||
| 340 | |||
| 341 | #define X509_V_ERR_UNNESTED_RESOURCE 46 | ||
| 342 | |||
| 343 | #define X509_V_ERR_PERMITTED_VIOLATION 47 | ||
| 344 | #define X509_V_ERR_EXCLUDED_VIOLATION 48 | ||
| 345 | #define X509_V_ERR_SUBTREE_MINMAX 49 | ||
| 346 | #define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51 | ||
| 347 | #define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52 | ||
| 348 | #define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53 | ||
| 349 | #define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54 | ||
| 350 | |||
| 351 | /* The application is not happy */ | ||
| 352 | #define X509_V_ERR_APPLICATION_VERIFICATION 50 | ||
| 353 | |||
| 354 | /* Certificate verify flags */ | ||
| 355 | |||
| 356 | /* Send issuer+subject checks to verify_cb */ | ||
| 357 | #define X509_V_FLAG_CB_ISSUER_CHECK 0x1 | ||
| 358 | /* Use check time instead of current time */ | ||
| 359 | #define X509_V_FLAG_USE_CHECK_TIME 0x2 | ||
| 360 | /* Lookup CRLs */ | ||
| 361 | #define X509_V_FLAG_CRL_CHECK 0x4 | ||
| 362 | /* Lookup CRLs for whole chain */ | ||
| 363 | #define X509_V_FLAG_CRL_CHECK_ALL 0x8 | ||
| 364 | /* Ignore unhandled critical extensions */ | ||
| 365 | #define X509_V_FLAG_IGNORE_CRITICAL 0x10 | ||
| 366 | /* Disable workarounds for broken certificates */ | ||
| 367 | #define X509_V_FLAG_X509_STRICT 0x20 | ||
| 368 | /* Enable proxy certificate validation */ | ||
| 369 | #define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 | ||
| 370 | /* Enable policy checking */ | ||
| 371 | #define X509_V_FLAG_POLICY_CHECK 0x80 | ||
| 372 | /* Policy variable require-explicit-policy */ | ||
| 373 | #define X509_V_FLAG_EXPLICIT_POLICY 0x100 | ||
| 374 | /* Policy variable inhibit-any-policy */ | ||
| 375 | #define X509_V_FLAG_INHIBIT_ANY 0x200 | ||
| 376 | /* Policy variable inhibit-policy-mapping */ | ||
| 377 | #define X509_V_FLAG_INHIBIT_MAP 0x400 | ||
| 378 | /* Notify callback that policy is OK */ | ||
| 379 | #define X509_V_FLAG_NOTIFY_POLICY 0x800 | ||
| 380 | /* Extended CRL features such as indirect CRLs, alternate CRL signing keys */ | ||
| 381 | #define X509_V_FLAG_EXTENDED_CRL_SUPPORT 0x1000 | ||
| 382 | /* Delta CRL support */ | ||
| 383 | #define X509_V_FLAG_USE_DELTAS 0x2000 | ||
| 384 | /* Check selfsigned CA signature */ | ||
| 385 | #define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 | ||
| 386 | |||
| 387 | |||
| 388 | #define X509_VP_FLAG_DEFAULT 0x1 | ||
| 389 | #define X509_VP_FLAG_OVERWRITE 0x2 | ||
| 390 | #define X509_VP_FLAG_RESET_FLAGS 0x4 | ||
| 391 | #define X509_VP_FLAG_LOCKED 0x8 | ||
| 392 | #define X509_VP_FLAG_ONCE 0x10 | ||
| 393 | |||
| 394 | /* Internal use: mask of policy related options */ | ||
| 395 | #define X509_V_FLAG_POLICY_MASK (X509_V_FLAG_POLICY_CHECK \ | ||
| 396 | | X509_V_FLAG_EXPLICIT_POLICY \ | ||
| 397 | | X509_V_FLAG_INHIBIT_ANY \ | ||
| 398 | | X509_V_FLAG_INHIBIT_MAP) | ||
| 399 | |||
| 400 | int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type, | ||
| 401 | X509_NAME *name); | ||
| 402 | X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h,int type,X509_NAME *name); | ||
| 403 | X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x); | ||
| 404 | void X509_OBJECT_up_ref_count(X509_OBJECT *a); | ||
| 405 | void X509_OBJECT_free_contents(X509_OBJECT *a); | ||
| 406 | X509_STORE *X509_STORE_new(void ); | ||
| 407 | void X509_STORE_free(X509_STORE *v); | ||
| 408 | |||
| 409 | STACK_OF(X509)* X509_STORE_get1_certs(X509_STORE_CTX *st, X509_NAME *nm); | ||
| 410 | STACK_OF(X509_CRL)* X509_STORE_get1_crls(X509_STORE_CTX *st, X509_NAME *nm); | ||
| 411 | int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags); | ||
| 412 | int X509_STORE_set_purpose(X509_STORE *ctx, int purpose); | ||
| 413 | int X509_STORE_set_trust(X509_STORE *ctx, int trust); | ||
| 414 | int X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *pm); | ||
| 415 | |||
| 416 | void X509_STORE_set_verify_cb(X509_STORE *ctx, | ||
| 417 | int (*verify_cb)(int, X509_STORE_CTX *)); | ||
| 418 | |||
| 419 | X509_STORE_CTX *X509_STORE_CTX_new(void); | ||
| 420 | |||
| 421 | int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x); | ||
| 422 | |||
| 423 | void X509_STORE_CTX_free(X509_STORE_CTX *ctx); | ||
| 424 | int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, | ||
| 425 | X509 *x509, STACK_OF(X509) *chain); | ||
| 426 | void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk); | ||
| 427 | void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); | ||
| 428 | |||
| 429 | X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m); | ||
| 430 | |||
| 431 | X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); | ||
| 432 | X509_LOOKUP_METHOD *X509_LOOKUP_file(void); | ||
| 433 | X509_LOOKUP_METHOD *X509_LOOKUP_mem(void); | ||
| 434 | |||
| 435 | int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); | ||
| 436 | int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); | ||
| 437 | |||
| 438 | int X509_STORE_get_by_subject(X509_STORE_CTX *vs,int type,X509_NAME *name, | ||
| 439 | X509_OBJECT *ret); | ||
| 440 | |||
| 441 | int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, | ||
| 442 | long argl, char **ret); | ||
| 443 | |||
| 444 | int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type); | ||
| 445 | int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type); | ||
| 446 | int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type); | ||
| 447 | |||
| 448 | |||
| 449 | X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method); | ||
| 450 | void X509_LOOKUP_free(X509_LOOKUP *ctx); | ||
| 451 | int X509_LOOKUP_init(X509_LOOKUP *ctx); | ||
| 452 | int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name, | ||
| 453 | X509_OBJECT *ret); | ||
| 454 | int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, X509_NAME *name, | ||
| 455 | ASN1_INTEGER *serial, X509_OBJECT *ret); | ||
| 456 | int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type, | ||
| 457 | unsigned char *bytes, int len, X509_OBJECT *ret); | ||
| 458 | int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, | ||
| 459 | int len, X509_OBJECT *ret); | ||
| 460 | int X509_LOOKUP_shutdown(X509_LOOKUP *ctx); | ||
| 461 | |||
| 462 | int X509_STORE_load_locations (X509_STORE *ctx, | ||
| 463 | const char *file, const char *dir); | ||
| 464 | int X509_STORE_load_mem(X509_STORE *ctx, void *buf, int len); | ||
| 465 | int X509_STORE_set_default_paths(X509_STORE *ctx); | ||
| 466 | |||
| 467 | int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 468 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
| 469 | int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx,int idx,void *data); | ||
| 470 | void * X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx,int idx); | ||
| 471 | int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); | ||
| 472 | void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx,int s); | ||
| 473 | int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); | ||
| 474 | X509 * X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx); | ||
| 475 | X509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx); | ||
| 476 | X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx); | ||
| 477 | X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(X509_STORE_CTX *ctx); | ||
| 478 | STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx); | ||
| 479 | STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx); | ||
| 480 | void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x); | ||
| 481 | void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk); | ||
| 482 | void X509_STORE_CTX_set0_crls(X509_STORE_CTX *c,STACK_OF(X509_CRL) *sk); | ||
| 483 | int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose); | ||
| 484 | int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust); | ||
| 485 | int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose, | ||
| 486 | int purpose, int trust); | ||
| 487 | void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags); | ||
| 488 | void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags, | ||
| 489 | time_t t); | ||
| 490 | void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx, | ||
| 491 | int (*verify_cb)(int, X509_STORE_CTX *)); | ||
| 492 | |||
| 493 | X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(X509_STORE_CTX *ctx); | ||
| 494 | int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx); | ||
| 495 | |||
| 496 | X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx); | ||
| 497 | void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param); | ||
| 498 | int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name); | ||
| 499 | |||
| 500 | /* X509_VERIFY_PARAM functions */ | ||
| 501 | |||
| 502 | X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void); | ||
| 503 | void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param); | ||
| 504 | int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to, | ||
| 505 | const X509_VERIFY_PARAM *from); | ||
| 506 | int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, | ||
| 507 | const X509_VERIFY_PARAM *from); | ||
| 508 | int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name); | ||
| 509 | int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags); | ||
| 510 | int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param, | ||
| 511 | unsigned long flags); | ||
| 512 | unsigned long X509_VERIFY_PARAM_get_flags(X509_VERIFY_PARAM *param); | ||
| 513 | int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose); | ||
| 514 | int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust); | ||
| 515 | void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth); | ||
| 516 | void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t); | ||
| 517 | int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param, | ||
| 518 | ASN1_OBJECT *policy); | ||
| 519 | int X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param, | ||
| 520 | STACK_OF(ASN1_OBJECT) *policies); | ||
| 521 | int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param); | ||
| 522 | |||
| 523 | int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param); | ||
| 524 | const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name); | ||
| 525 | void X509_VERIFY_PARAM_table_cleanup(void); | ||
| 526 | |||
| 527 | int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy, | ||
| 528 | STACK_OF(X509) *certs, | ||
| 529 | STACK_OF(ASN1_OBJECT) *policy_oids, | ||
| 530 | unsigned int flags); | ||
| 531 | |||
| 532 | void X509_policy_tree_free(X509_POLICY_TREE *tree); | ||
| 533 | |||
| 534 | int X509_policy_tree_level_count(const X509_POLICY_TREE *tree); | ||
| 535 | X509_POLICY_LEVEL * | ||
| 536 | X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, int i); | ||
| 537 | |||
| 538 | STACK_OF(X509_POLICY_NODE) * | ||
| 539 | X509_policy_tree_get0_policies(const X509_POLICY_TREE *tree); | ||
| 540 | |||
| 541 | STACK_OF(X509_POLICY_NODE) * | ||
| 542 | X509_policy_tree_get0_user_policies(const X509_POLICY_TREE *tree); | ||
| 543 | |||
| 544 | int X509_policy_level_node_count(X509_POLICY_LEVEL *level); | ||
| 545 | |||
| 546 | X509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, int i); | ||
| 547 | |||
| 548 | const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node); | ||
| 549 | |||
| 550 | STACK_OF(POLICYQUALINFO) * | ||
| 551 | X509_policy_node_get0_qualifiers(const X509_POLICY_NODE *node); | ||
| 552 | const X509_POLICY_NODE * | ||
| 553 | X509_policy_node_get0_parent(const X509_POLICY_NODE *node); | ||
| 554 | |||
| 555 | #ifdef __cplusplus | ||
| 556 | } | ||
| 557 | #endif | ||
| 558 | #endif | ||
| 559 | |||
diff --git a/src/lib/libcrypto/x509/x509_vpm.c b/src/lib/libcrypto/x509/x509_vpm.c deleted file mode 100644 index 8ec972050d..0000000000 --- a/src/lib/libcrypto/x509/x509_vpm.c +++ /dev/null | |||
| @@ -1,449 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509_vpm.c,v 1.11 2014/09/29 04:16:49 miod Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 2004. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2004 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/buffer.h> | ||
| 63 | #include <openssl/crypto.h> | ||
| 64 | #include <openssl/lhash.h> | ||
| 65 | #include <openssl/x509.h> | ||
| 66 | #include <openssl/x509v3.h> | ||
| 67 | |||
| 68 | /* X509_VERIFY_PARAM functions */ | ||
| 69 | |||
| 70 | static void | ||
| 71 | x509_verify_param_zero(X509_VERIFY_PARAM *param) | ||
| 72 | { | ||
| 73 | if (!param) | ||
| 74 | return; | ||
| 75 | param->name = NULL; | ||
| 76 | param->purpose = 0; | ||
| 77 | param->trust = 0; | ||
| 78 | /*param->inh_flags = X509_VP_FLAG_DEFAULT;*/ | ||
| 79 | param->inh_flags = 0; | ||
| 80 | param->flags = 0; | ||
| 81 | param->depth = -1; | ||
| 82 | if (param->policies) { | ||
| 83 | sk_ASN1_OBJECT_pop_free(param->policies, ASN1_OBJECT_free); | ||
| 84 | param->policies = NULL; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | X509_VERIFY_PARAM * | ||
| 89 | X509_VERIFY_PARAM_new(void) | ||
| 90 | { | ||
| 91 | X509_VERIFY_PARAM *param; | ||
| 92 | |||
| 93 | param = calloc(1, sizeof(X509_VERIFY_PARAM)); | ||
| 94 | x509_verify_param_zero(param); | ||
| 95 | return param; | ||
| 96 | } | ||
| 97 | |||
| 98 | void | ||
| 99 | X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param) | ||
| 100 | { | ||
| 101 | x509_verify_param_zero(param); | ||
| 102 | free(param); | ||
| 103 | } | ||
| 104 | |||
| 105 | /* This function determines how parameters are "inherited" from one structure | ||
| 106 | * to another. There are several different ways this can happen. | ||
| 107 | * | ||
| 108 | * 1. If a child structure needs to have its values initialized from a parent | ||
| 109 | * they are simply copied across. For example SSL_CTX copied to SSL. | ||
| 110 | * 2. If the structure should take on values only if they are currently unset. | ||
| 111 | * For example the values in an SSL structure will take appropriate value | ||
| 112 | * for SSL servers or clients but only if the application has not set new | ||
| 113 | * ones. | ||
| 114 | * | ||
| 115 | * The "inh_flags" field determines how this function behaves. | ||
| 116 | * | ||
| 117 | * Normally any values which are set in the default are not copied from the | ||
| 118 | * destination and verify flags are ORed together. | ||
| 119 | * | ||
| 120 | * If X509_VP_FLAG_DEFAULT is set then anything set in the source is copied | ||
| 121 | * to the destination. Effectively the values in "to" become default values | ||
| 122 | * which will be used only if nothing new is set in "from". | ||
| 123 | * | ||
| 124 | * If X509_VP_FLAG_OVERWRITE is set then all value are copied across whether | ||
| 125 | * they are set or not. Flags is still Ored though. | ||
| 126 | * | ||
| 127 | * If X509_VP_FLAG_RESET_FLAGS is set then the flags value is copied instead | ||
| 128 | * of ORed. | ||
| 129 | * | ||
| 130 | * If X509_VP_FLAG_LOCKED is set then no values are copied. | ||
| 131 | * | ||
| 132 | * If X509_VP_FLAG_ONCE is set then the current inh_flags setting is zeroed | ||
| 133 | * after the next call. | ||
| 134 | */ | ||
| 135 | |||
| 136 | /* Macro to test if a field should be copied from src to dest */ | ||
| 137 | |||
| 138 | #define test_x509_verify_param_copy(field, def) \ | ||
| 139 | (to_overwrite || \ | ||
| 140 | ((src->field != def) && (to_default || (dest->field == def)))) | ||
| 141 | |||
| 142 | /* Macro to test and copy a field if necessary */ | ||
| 143 | |||
| 144 | #define x509_verify_param_copy(field, def) \ | ||
| 145 | if (test_x509_verify_param_copy(field, def)) \ | ||
| 146 | dest->field = src->field | ||
| 147 | |||
| 148 | |||
| 149 | int | ||
| 150 | X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *dest, const X509_VERIFY_PARAM *src) | ||
| 151 | { | ||
| 152 | unsigned long inh_flags; | ||
| 153 | int to_default, to_overwrite; | ||
| 154 | |||
| 155 | if (!src) | ||
| 156 | return 1; | ||
| 157 | inh_flags = dest->inh_flags | src->inh_flags; | ||
| 158 | |||
| 159 | if (inh_flags & X509_VP_FLAG_ONCE) | ||
| 160 | dest->inh_flags = 0; | ||
| 161 | |||
| 162 | if (inh_flags & X509_VP_FLAG_LOCKED) | ||
| 163 | return 1; | ||
| 164 | |||
| 165 | if (inh_flags & X509_VP_FLAG_DEFAULT) | ||
| 166 | to_default = 1; | ||
| 167 | else | ||
| 168 | to_default = 0; | ||
| 169 | |||
| 170 | if (inh_flags & X509_VP_FLAG_OVERWRITE) | ||
| 171 | to_overwrite = 1; | ||
| 172 | else | ||
| 173 | to_overwrite = 0; | ||
| 174 | |||
| 175 | x509_verify_param_copy(purpose, 0); | ||
| 176 | x509_verify_param_copy(trust, 0); | ||
| 177 | x509_verify_param_copy(depth, -1); | ||
| 178 | |||
| 179 | /* If overwrite or check time not set, copy across */ | ||
| 180 | |||
| 181 | if (to_overwrite || !(dest->flags & X509_V_FLAG_USE_CHECK_TIME)) { | ||
| 182 | dest->check_time = src->check_time; | ||
| 183 | dest->flags &= ~X509_V_FLAG_USE_CHECK_TIME; | ||
| 184 | /* Don't need to copy flag: that is done below */ | ||
| 185 | } | ||
| 186 | |||
| 187 | if (inh_flags & X509_VP_FLAG_RESET_FLAGS) | ||
| 188 | dest->flags = 0; | ||
| 189 | |||
| 190 | dest->flags |= src->flags; | ||
| 191 | |||
| 192 | if (test_x509_verify_param_copy(policies, NULL)) { | ||
| 193 | if (!X509_VERIFY_PARAM_set1_policies(dest, src->policies)) | ||
| 194 | return 0; | ||
| 195 | } | ||
| 196 | |||
| 197 | return 1; | ||
| 198 | } | ||
| 199 | |||
| 200 | int | ||
| 201 | X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, const X509_VERIFY_PARAM *from) | ||
| 202 | { | ||
| 203 | unsigned long save_flags = to->inh_flags; | ||
| 204 | int ret; | ||
| 205 | |||
| 206 | to->inh_flags |= X509_VP_FLAG_DEFAULT; | ||
| 207 | ret = X509_VERIFY_PARAM_inherit(to, from); | ||
| 208 | to->inh_flags = save_flags; | ||
| 209 | return ret; | ||
| 210 | } | ||
| 211 | |||
| 212 | int | ||
| 213 | X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name) | ||
| 214 | { | ||
| 215 | free(param->name); | ||
| 216 | param->name = NULL; | ||
| 217 | if (name == NULL) | ||
| 218 | return 1; | ||
| 219 | param->name = strdup(name); | ||
| 220 | if (param->name) | ||
| 221 | return 1; | ||
| 222 | return 0; | ||
| 223 | } | ||
| 224 | |||
| 225 | int | ||
| 226 | X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags) | ||
| 227 | { | ||
| 228 | param->flags |= flags; | ||
| 229 | if (flags & X509_V_FLAG_POLICY_MASK) | ||
| 230 | param->flags |= X509_V_FLAG_POLICY_CHECK; | ||
| 231 | return 1; | ||
| 232 | } | ||
| 233 | |||
| 234 | int | ||
| 235 | X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param, unsigned long flags) | ||
| 236 | { | ||
| 237 | param->flags &= ~flags; | ||
| 238 | return 1; | ||
| 239 | } | ||
| 240 | |||
| 241 | unsigned long | ||
| 242 | X509_VERIFY_PARAM_get_flags(X509_VERIFY_PARAM *param) | ||
| 243 | { | ||
| 244 | return param->flags; | ||
| 245 | } | ||
| 246 | |||
| 247 | int | ||
| 248 | X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose) | ||
| 249 | { | ||
| 250 | return X509_PURPOSE_set(¶m->purpose, purpose); | ||
| 251 | } | ||
| 252 | |||
| 253 | int | ||
| 254 | X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust) | ||
| 255 | { | ||
| 256 | return X509_TRUST_set(¶m->trust, trust); | ||
| 257 | } | ||
| 258 | |||
| 259 | void | ||
| 260 | X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth) | ||
| 261 | { | ||
| 262 | param->depth = depth; | ||
| 263 | } | ||
| 264 | |||
| 265 | void | ||
| 266 | X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t) | ||
| 267 | { | ||
| 268 | param->check_time = t; | ||
| 269 | param->flags |= X509_V_FLAG_USE_CHECK_TIME; | ||
| 270 | } | ||
| 271 | |||
| 272 | int | ||
| 273 | X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param, ASN1_OBJECT *policy) | ||
| 274 | { | ||
| 275 | if (!param->policies) { | ||
| 276 | param->policies = sk_ASN1_OBJECT_new_null(); | ||
| 277 | if (!param->policies) | ||
| 278 | return 0; | ||
| 279 | } | ||
| 280 | if (!sk_ASN1_OBJECT_push(param->policies, policy)) | ||
| 281 | return 0; | ||
| 282 | return 1; | ||
| 283 | } | ||
| 284 | |||
| 285 | int | ||
| 286 | X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param, | ||
| 287 | STACK_OF(ASN1_OBJECT) *policies) | ||
| 288 | { | ||
| 289 | int i; | ||
| 290 | ASN1_OBJECT *oid, *doid; | ||
| 291 | |||
| 292 | if (!param) | ||
| 293 | return 0; | ||
| 294 | if (param->policies) | ||
| 295 | sk_ASN1_OBJECT_pop_free(param->policies, ASN1_OBJECT_free); | ||
| 296 | |||
| 297 | if (!policies) { | ||
| 298 | param->policies = NULL; | ||
| 299 | return 1; | ||
| 300 | } | ||
| 301 | |||
| 302 | param->policies = sk_ASN1_OBJECT_new_null(); | ||
| 303 | if (!param->policies) | ||
| 304 | return 0; | ||
| 305 | |||
| 306 | for (i = 0; i < sk_ASN1_OBJECT_num(policies); i++) { | ||
| 307 | oid = sk_ASN1_OBJECT_value(policies, i); | ||
| 308 | doid = OBJ_dup(oid); | ||
| 309 | if (!doid) | ||
| 310 | return 0; | ||
| 311 | if (!sk_ASN1_OBJECT_push(param->policies, doid)) { | ||
| 312 | ASN1_OBJECT_free(doid); | ||
| 313 | return 0; | ||
| 314 | } | ||
| 315 | } | ||
| 316 | param->flags |= X509_V_FLAG_POLICY_CHECK; | ||
| 317 | return 1; | ||
| 318 | } | ||
| 319 | |||
| 320 | int | ||
| 321 | X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param) | ||
| 322 | { | ||
| 323 | return param->depth; | ||
| 324 | } | ||
| 325 | |||
| 326 | /* Default verify parameters: these are used for various | ||
| 327 | * applications and can be overridden by the user specified table. | ||
| 328 | * NB: the 'name' field *must* be in alphabetical order because it | ||
| 329 | * will be searched using OBJ_search. | ||
| 330 | */ | ||
| 331 | |||
| 332 | static const X509_VERIFY_PARAM default_table[] = { | ||
| 333 | { | ||
| 334 | "default", /* X509 default parameters */ | ||
| 335 | 0, /* Check time */ | ||
| 336 | 0, /* internal flags */ | ||
| 337 | 0, /* flags */ | ||
| 338 | 0, /* purpose */ | ||
| 339 | 0, /* trust */ | ||
| 340 | 100, /* depth */ | ||
| 341 | NULL /* policies */ | ||
| 342 | }, | ||
| 343 | { | ||
| 344 | "pkcs7", /* S/MIME sign parameters */ | ||
| 345 | 0, /* Check time */ | ||
| 346 | 0, /* internal flags */ | ||
| 347 | 0, /* flags */ | ||
| 348 | X509_PURPOSE_SMIME_SIGN, /* purpose */ | ||
| 349 | X509_TRUST_EMAIL, /* trust */ | ||
| 350 | -1, /* depth */ | ||
| 351 | NULL /* policies */ | ||
| 352 | }, | ||
| 353 | { | ||
| 354 | "smime_sign", /* S/MIME sign parameters */ | ||
| 355 | 0, /* Check time */ | ||
| 356 | 0, /* internal flags */ | ||
| 357 | 0, /* flags */ | ||
| 358 | X509_PURPOSE_SMIME_SIGN, /* purpose */ | ||
| 359 | X509_TRUST_EMAIL, /* trust */ | ||
| 360 | -1, /* depth */ | ||
| 361 | NULL /* policies */ | ||
| 362 | }, | ||
| 363 | { | ||
| 364 | "ssl_client", /* SSL/TLS client parameters */ | ||
| 365 | 0, /* Check time */ | ||
| 366 | 0, /* internal flags */ | ||
| 367 | 0, /* flags */ | ||
| 368 | X509_PURPOSE_SSL_CLIENT, /* purpose */ | ||
| 369 | X509_TRUST_SSL_CLIENT, /* trust */ | ||
| 370 | -1, /* depth */ | ||
| 371 | NULL /* policies */ | ||
| 372 | }, | ||
| 373 | { | ||
| 374 | "ssl_server", /* SSL/TLS server parameters */ | ||
| 375 | 0, /* Check time */ | ||
| 376 | 0, /* internal flags */ | ||
| 377 | 0, /* flags */ | ||
| 378 | X509_PURPOSE_SSL_SERVER, /* purpose */ | ||
| 379 | X509_TRUST_SSL_SERVER, /* trust */ | ||
| 380 | -1, /* depth */ | ||
| 381 | NULL /* policies */ | ||
| 382 | } | ||
| 383 | }; | ||
| 384 | |||
| 385 | static STACK_OF(X509_VERIFY_PARAM) *param_table = NULL; | ||
| 386 | |||
| 387 | static int | ||
| 388 | table_cmp(const X509_VERIFY_PARAM *a, const X509_VERIFY_PARAM *b) | ||
| 389 | { | ||
| 390 | return strcmp(a->name, b->name); | ||
| 391 | } | ||
| 392 | |||
| 393 | DECLARE_OBJ_BSEARCH_CMP_FN(X509_VERIFY_PARAM, X509_VERIFY_PARAM, table); | ||
| 394 | IMPLEMENT_OBJ_BSEARCH_CMP_FN(X509_VERIFY_PARAM, X509_VERIFY_PARAM, table); | ||
| 395 | |||
| 396 | static int | ||
| 397 | param_cmp(const X509_VERIFY_PARAM * const *a, | ||
| 398 | const X509_VERIFY_PARAM * const *b) | ||
| 399 | { | ||
| 400 | return strcmp((*a)->name, (*b)->name); | ||
| 401 | } | ||
| 402 | |||
| 403 | int | ||
| 404 | X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param) | ||
| 405 | { | ||
| 406 | int idx; | ||
| 407 | X509_VERIFY_PARAM *ptmp; | ||
| 408 | |||
| 409 | if (!param_table) { | ||
| 410 | param_table = sk_X509_VERIFY_PARAM_new(param_cmp); | ||
| 411 | if (!param_table) | ||
| 412 | return 0; | ||
| 413 | } else { | ||
| 414 | idx = sk_X509_VERIFY_PARAM_find(param_table, param); | ||
| 415 | if (idx != -1) { | ||
| 416 | ptmp = sk_X509_VERIFY_PARAM_value(param_table, idx); | ||
| 417 | X509_VERIFY_PARAM_free(ptmp); | ||
| 418 | (void)sk_X509_VERIFY_PARAM_delete(param_table, idx); | ||
| 419 | } | ||
| 420 | } | ||
| 421 | if (!sk_X509_VERIFY_PARAM_push(param_table, param)) | ||
| 422 | return 0; | ||
| 423 | return 1; | ||
| 424 | } | ||
| 425 | |||
| 426 | const X509_VERIFY_PARAM * | ||
| 427 | X509_VERIFY_PARAM_lookup(const char *name) | ||
| 428 | { | ||
| 429 | int idx; | ||
| 430 | X509_VERIFY_PARAM pm; | ||
| 431 | |||
| 432 | pm.name = (char *)name; | ||
| 433 | if (param_table) { | ||
| 434 | idx = sk_X509_VERIFY_PARAM_find(param_table, &pm); | ||
| 435 | if (idx != -1) | ||
| 436 | return sk_X509_VERIFY_PARAM_value(param_table, idx); | ||
| 437 | } | ||
| 438 | return OBJ_bsearch_table(&pm, default_table, | ||
| 439 | sizeof(default_table)/sizeof(X509_VERIFY_PARAM)); | ||
| 440 | } | ||
| 441 | |||
| 442 | void | ||
| 443 | X509_VERIFY_PARAM_table_cleanup(void) | ||
| 444 | { | ||
| 445 | if (param_table) | ||
| 446 | sk_X509_VERIFY_PARAM_pop_free(param_table, | ||
| 447 | X509_VERIFY_PARAM_free); | ||
| 448 | param_table = NULL; | ||
| 449 | } | ||
diff --git a/src/lib/libcrypto/x509/x509cset.c b/src/lib/libcrypto/x509/x509cset.c deleted file mode 100644 index 94c419301a..0000000000 --- a/src/lib/libcrypto/x509/x509cset.c +++ /dev/null | |||
| @@ -1,173 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509cset.c,v 1.9 2015/07/29 14:58:34 jsing Exp $ */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project 2001. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2001 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 | |||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/evp.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | |||
| 66 | int | ||
| 67 | X509_CRL_set_version(X509_CRL *x, long version) | ||
| 68 | { | ||
| 69 | if (x == NULL) | ||
| 70 | return (0); | ||
| 71 | if (x->crl->version == NULL) { | ||
| 72 | if ((x->crl->version = M_ASN1_INTEGER_new()) == NULL) | ||
| 73 | return (0); | ||
| 74 | } | ||
| 75 | return (ASN1_INTEGER_set(x->crl->version, version)); | ||
| 76 | } | ||
| 77 | |||
| 78 | int | ||
| 79 | X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name) | ||
| 80 | { | ||
| 81 | if ((x == NULL) || (x->crl == NULL)) | ||
| 82 | return (0); | ||
| 83 | return (X509_NAME_set(&x->crl->issuer, name)); | ||
| 84 | } | ||
| 85 | |||
| 86 | int | ||
| 87 | X509_CRL_set_lastUpdate(X509_CRL *x, const ASN1_TIME *tm) | ||
| 88 | { | ||
| 89 | ASN1_TIME *in; | ||
| 90 | |||
| 91 | if (x == NULL) | ||
| 92 | return (0); | ||
| 93 | in = x->crl->lastUpdate; | ||
| 94 | if (in != tm) { | ||
| 95 | in = ASN1_STRING_dup(tm); | ||
| 96 | if (in != NULL) { | ||
| 97 | M_ASN1_TIME_free(x->crl->lastUpdate); | ||
| 98 | x->crl->lastUpdate = in; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | return (in != NULL); | ||
| 102 | } | ||
| 103 | |||
| 104 | int | ||
| 105 | X509_CRL_set_nextUpdate(X509_CRL *x, const ASN1_TIME *tm) | ||
| 106 | { | ||
| 107 | ASN1_TIME *in; | ||
| 108 | |||
| 109 | if (x == NULL) | ||
| 110 | return (0); | ||
| 111 | in = x->crl->nextUpdate; | ||
| 112 | if (in != tm) { | ||
| 113 | in = ASN1_STRING_dup(tm); | ||
| 114 | if (in != NULL) { | ||
| 115 | M_ASN1_TIME_free(x->crl->nextUpdate); | ||
| 116 | x->crl->nextUpdate = in; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | return (in != NULL); | ||
| 120 | } | ||
| 121 | |||
| 122 | int | ||
| 123 | X509_CRL_sort(X509_CRL *c) | ||
| 124 | { | ||
| 125 | int i; | ||
| 126 | X509_REVOKED *r; | ||
| 127 | |||
| 128 | /* sort the data so it will be written in serial | ||
| 129 | * number order */ | ||
| 130 | sk_X509_REVOKED_sort(c->crl->revoked); | ||
| 131 | for (i = 0; i < sk_X509_REVOKED_num(c->crl->revoked); i++) { | ||
| 132 | r = sk_X509_REVOKED_value(c->crl->revoked, i); | ||
| 133 | r->sequence = i; | ||
| 134 | } | ||
| 135 | c->crl->enc.modified = 1; | ||
| 136 | return 1; | ||
| 137 | } | ||
| 138 | |||
| 139 | int | ||
| 140 | X509_REVOKED_set_revocationDate(X509_REVOKED *x, ASN1_TIME *tm) | ||
| 141 | { | ||
| 142 | ASN1_TIME *in; | ||
| 143 | |||
| 144 | if (x == NULL) | ||
| 145 | return (0); | ||
| 146 | in = x->revocationDate; | ||
| 147 | if (in != tm) { | ||
| 148 | in = ASN1_STRING_dup(tm); | ||
| 149 | if (in != NULL) { | ||
| 150 | M_ASN1_TIME_free(x->revocationDate); | ||
| 151 | x->revocationDate = in; | ||
| 152 | } | ||
| 153 | } | ||
| 154 | return (in != NULL); | ||
| 155 | } | ||
| 156 | |||
| 157 | int | ||
| 158 | X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial) | ||
| 159 | { | ||
| 160 | ASN1_INTEGER *in; | ||
| 161 | |||
| 162 | if (x == NULL) | ||
| 163 | return (0); | ||
| 164 | in = x->serialNumber; | ||
| 165 | if (in != serial) { | ||
| 166 | in = ASN1_STRING_dup(serial); | ||
| 167 | if (in != NULL) { | ||
| 168 | M_ASN1_INTEGER_free(x->serialNumber); | ||
| 169 | x->serialNumber = in; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | return (in != NULL); | ||
| 173 | } | ||
diff --git a/src/lib/libcrypto/x509/x509name.c b/src/lib/libcrypto/x509/x509name.c deleted file mode 100644 index 14634013cf..0000000000 --- a/src/lib/libcrypto/x509/x509name.c +++ /dev/null | |||
| @@ -1,410 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509name.c,v 1.13 2014/09/29 04:17:24 miod Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | |||
| 62 | #include <openssl/asn1.h> | ||
| 63 | #include <openssl/err.h> | ||
| 64 | #include <openssl/evp.h> | ||
| 65 | #include <openssl/objects.h> | ||
| 66 | #include <openssl/stack.h> | ||
| 67 | #include <openssl/x509.h> | ||
| 68 | |||
| 69 | int | ||
| 70 | X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf, int len) | ||
| 71 | { | ||
| 72 | ASN1_OBJECT *obj; | ||
| 73 | |||
| 74 | obj = OBJ_nid2obj(nid); | ||
| 75 | if (obj == NULL) | ||
| 76 | return (-1); | ||
| 77 | return (X509_NAME_get_text_by_OBJ(name, obj, buf, len)); | ||
| 78 | } | ||
| 79 | |||
| 80 | int | ||
| 81 | X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf, | ||
| 82 | int len) | ||
| 83 | { | ||
| 84 | int i; | ||
| 85 | ASN1_STRING *data; | ||
| 86 | |||
| 87 | i = X509_NAME_get_index_by_OBJ(name, obj, -1); | ||
| 88 | if (i < 0) | ||
| 89 | return (-1); | ||
| 90 | data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i)); | ||
| 91 | i = (data->length > (len - 1)) ? (len - 1) : data->length; | ||
| 92 | if (buf == NULL) | ||
| 93 | return (data->length); | ||
| 94 | if (i >= 0) { | ||
| 95 | memcpy(buf, data->data, i); | ||
| 96 | buf[i] = '\0'; | ||
| 97 | } | ||
| 98 | return (i); | ||
| 99 | } | ||
| 100 | |||
| 101 | int | ||
| 102 | X509_NAME_entry_count(X509_NAME *name) | ||
| 103 | { | ||
| 104 | if (name == NULL) | ||
| 105 | return (0); | ||
| 106 | return (sk_X509_NAME_ENTRY_num(name->entries)); | ||
| 107 | } | ||
| 108 | |||
| 109 | int | ||
| 110 | X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos) | ||
| 111 | { | ||
| 112 | ASN1_OBJECT *obj; | ||
| 113 | |||
| 114 | obj = OBJ_nid2obj(nid); | ||
| 115 | if (obj == NULL) | ||
| 116 | return (-2); | ||
| 117 | return (X509_NAME_get_index_by_OBJ(name, obj, lastpos)); | ||
| 118 | } | ||
| 119 | |||
| 120 | /* NOTE: you should be passsing -1, not 0 as lastpos */ | ||
| 121 | int | ||
| 122 | X509_NAME_get_index_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int lastpos) | ||
| 123 | { | ||
| 124 | int n; | ||
| 125 | X509_NAME_ENTRY *ne; | ||
| 126 | STACK_OF(X509_NAME_ENTRY) *sk; | ||
| 127 | |||
| 128 | if (name == NULL) | ||
| 129 | return (-1); | ||
| 130 | if (lastpos < 0) | ||
| 131 | lastpos = -1; | ||
| 132 | sk = name->entries; | ||
| 133 | n = sk_X509_NAME_ENTRY_num(sk); | ||
| 134 | for (lastpos++; lastpos < n; lastpos++) { | ||
| 135 | ne = sk_X509_NAME_ENTRY_value(sk, lastpos); | ||
| 136 | if (OBJ_cmp(ne->object, obj) == 0) | ||
| 137 | return (lastpos); | ||
| 138 | } | ||
| 139 | return (-1); | ||
| 140 | } | ||
| 141 | |||
| 142 | X509_NAME_ENTRY * | ||
| 143 | X509_NAME_get_entry(X509_NAME *name, int loc) | ||
| 144 | { | ||
| 145 | if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc || | ||
| 146 | loc < 0) | ||
| 147 | return (NULL); | ||
| 148 | else | ||
| 149 | return (sk_X509_NAME_ENTRY_value(name->entries, loc)); | ||
| 150 | } | ||
| 151 | |||
| 152 | X509_NAME_ENTRY * | ||
| 153 | X509_NAME_delete_entry(X509_NAME *name, int loc) | ||
| 154 | { | ||
| 155 | X509_NAME_ENTRY *ret; | ||
| 156 | int i, n, set_prev, set_next; | ||
| 157 | STACK_OF(X509_NAME_ENTRY) *sk; | ||
| 158 | |||
| 159 | if (name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc || | ||
| 160 | loc < 0) | ||
| 161 | return (NULL); | ||
| 162 | sk = name->entries; | ||
| 163 | ret = sk_X509_NAME_ENTRY_delete(sk, loc); | ||
| 164 | n = sk_X509_NAME_ENTRY_num(sk); | ||
| 165 | name->modified = 1; | ||
| 166 | if (loc == n) | ||
| 167 | return (ret); | ||
| 168 | |||
| 169 | /* else we need to fixup the set field */ | ||
| 170 | if (loc != 0) | ||
| 171 | set_prev = (sk_X509_NAME_ENTRY_value(sk, loc - 1))->set; | ||
| 172 | else | ||
| 173 | set_prev = ret->set - 1; | ||
| 174 | set_next = sk_X509_NAME_ENTRY_value(sk, loc)->set; | ||
| 175 | |||
| 176 | /* set_prev is the previous set | ||
| 177 | * set is the current set | ||
| 178 | * set_next is the following | ||
| 179 | * prev 1 1 1 1 1 1 1 1 | ||
| 180 | * set 1 1 2 2 | ||
| 181 | * next 1 1 2 2 2 2 3 2 | ||
| 182 | * so basically only if prev and next differ by 2, then | ||
| 183 | * re-number down by 1 */ | ||
| 184 | if (set_prev + 1 < set_next) | ||
| 185 | for (i = loc; i < n; i++) | ||
| 186 | sk_X509_NAME_ENTRY_value(sk, i)->set--; | ||
| 187 | return (ret); | ||
| 188 | } | ||
| 189 | |||
| 190 | int | ||
| 191 | X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, | ||
| 192 | unsigned char *bytes, int len, int loc, int set) | ||
| 193 | { | ||
| 194 | X509_NAME_ENTRY *ne; | ||
| 195 | int ret; | ||
| 196 | |||
| 197 | ne = X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len); | ||
| 198 | if (!ne) | ||
| 199 | return 0; | ||
| 200 | ret = X509_NAME_add_entry(name, ne, loc, set); | ||
| 201 | X509_NAME_ENTRY_free(ne); | ||
| 202 | return ret; | ||
| 203 | } | ||
| 204 | |||
| 205 | int | ||
| 206 | X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, | ||
| 207 | unsigned char *bytes, int len, int loc, int set) | ||
| 208 | { | ||
| 209 | X509_NAME_ENTRY *ne; | ||
| 210 | int ret; | ||
| 211 | |||
| 212 | ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len); | ||
| 213 | if (!ne) | ||
| 214 | return 0; | ||
| 215 | ret = X509_NAME_add_entry(name, ne, loc, set); | ||
| 216 | X509_NAME_ENTRY_free(ne); | ||
| 217 | return ret; | ||
| 218 | } | ||
| 219 | |||
| 220 | int | ||
| 221 | X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, | ||
| 222 | const unsigned char *bytes, int len, int loc, int set) | ||
| 223 | { | ||
| 224 | X509_NAME_ENTRY *ne; | ||
| 225 | int ret; | ||
| 226 | |||
| 227 | ne = X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len); | ||
| 228 | if (!ne) | ||
| 229 | return 0; | ||
| 230 | ret = X509_NAME_add_entry(name, ne, loc, set); | ||
| 231 | X509_NAME_ENTRY_free(ne); | ||
| 232 | return ret; | ||
| 233 | } | ||
| 234 | |||
| 235 | /* if set is -1, append to previous set, 0 'a new one', and 1, | ||
| 236 | * prepend to the guy we are about to stomp on. */ | ||
| 237 | int | ||
| 238 | X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, int set) | ||
| 239 | { | ||
| 240 | X509_NAME_ENTRY *new_name = NULL; | ||
| 241 | int n, i, inc; | ||
| 242 | STACK_OF(X509_NAME_ENTRY) *sk; | ||
| 243 | |||
| 244 | if (name == NULL) | ||
| 245 | return (0); | ||
| 246 | sk = name->entries; | ||
| 247 | n = sk_X509_NAME_ENTRY_num(sk); | ||
| 248 | if (loc > n) | ||
| 249 | loc = n; | ||
| 250 | else if (loc < 0) | ||
| 251 | loc = n; | ||
| 252 | |||
| 253 | name->modified = 1; | ||
| 254 | |||
| 255 | if (set == -1) { | ||
| 256 | if (loc == 0) { | ||
| 257 | set = 0; | ||
| 258 | inc = 1; | ||
| 259 | } else { | ||
| 260 | set = sk_X509_NAME_ENTRY_value(sk, loc - 1)->set; | ||
| 261 | inc = 0; | ||
| 262 | } | ||
| 263 | } else /* if (set >= 0) */ { | ||
| 264 | if (loc >= n) { | ||
| 265 | if (loc != 0) | ||
| 266 | set = sk_X509_NAME_ENTRY_value(sk, loc - 1)->set + 1; | ||
| 267 | else | ||
| 268 | set = 0; | ||
| 269 | } else | ||
| 270 | set = sk_X509_NAME_ENTRY_value(sk, loc)->set; | ||
| 271 | inc = (set == 0) ? 1 : 0; | ||
| 272 | } | ||
| 273 | |||
| 274 | if ((new_name = X509_NAME_ENTRY_dup(ne)) == NULL) | ||
| 275 | goto err; | ||
| 276 | new_name->set = set; | ||
| 277 | if (!sk_X509_NAME_ENTRY_insert(sk, new_name, loc)) { | ||
| 278 | X509err(X509_F_X509_NAME_ADD_ENTRY, ERR_R_MALLOC_FAILURE); | ||
| 279 | goto err; | ||
| 280 | } | ||
| 281 | if (inc) { | ||
| 282 | n = sk_X509_NAME_ENTRY_num(sk); | ||
| 283 | for (i = loc + 1; i < n; i++) | ||
| 284 | sk_X509_NAME_ENTRY_value(sk, i - 1)->set += 1; | ||
| 285 | } | ||
| 286 | return (1); | ||
| 287 | |||
| 288 | err: | ||
| 289 | if (new_name != NULL) | ||
| 290 | X509_NAME_ENTRY_free(new_name); | ||
| 291 | return (0); | ||
| 292 | } | ||
| 293 | |||
| 294 | X509_NAME_ENTRY * | ||
| 295 | X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, | ||
| 296 | const char *field, int type, const unsigned char *bytes, int len) | ||
| 297 | { | ||
| 298 | ASN1_OBJECT *obj; | ||
| 299 | X509_NAME_ENTRY *nentry; | ||
| 300 | |||
| 301 | obj = OBJ_txt2obj(field, 0); | ||
| 302 | if (obj == NULL) { | ||
| 303 | X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_TXT, | ||
| 304 | X509_R_INVALID_FIELD_NAME); | ||
| 305 | ERR_asprintf_error_data("name=%s", field); | ||
| 306 | return (NULL); | ||
| 307 | } | ||
| 308 | nentry = X509_NAME_ENTRY_create_by_OBJ(ne, obj, type, bytes, len); | ||
| 309 | ASN1_OBJECT_free(obj); | ||
| 310 | return nentry; | ||
| 311 | } | ||
| 312 | |||
| 313 | X509_NAME_ENTRY * | ||
| 314 | X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, int type, | ||
| 315 | unsigned char *bytes, int len) | ||
| 316 | { | ||
| 317 | ASN1_OBJECT *obj; | ||
| 318 | X509_NAME_ENTRY *nentry; | ||
| 319 | |||
| 320 | obj = OBJ_nid2obj(nid); | ||
| 321 | if (obj == NULL) { | ||
| 322 | X509err(X509_F_X509_NAME_ENTRY_CREATE_BY_NID, | ||
| 323 | X509_R_UNKNOWN_NID); | ||
| 324 | return (NULL); | ||
| 325 | } | ||
| 326 | nentry = X509_NAME_ENTRY_create_by_OBJ(ne, obj, type, bytes, len); | ||
| 327 | ASN1_OBJECT_free(obj); | ||
| 328 | return nentry; | ||
| 329 | } | ||
| 330 | |||
| 331 | X509_NAME_ENTRY * | ||
| 332 | X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, ASN1_OBJECT *obj, int type, | ||
| 333 | const unsigned char *bytes, int len) | ||
| 334 | { | ||
| 335 | X509_NAME_ENTRY *ret; | ||
| 336 | |||
| 337 | if ((ne == NULL) || (*ne == NULL)) { | ||
| 338 | if ((ret = X509_NAME_ENTRY_new()) == NULL) | ||
| 339 | return (NULL); | ||
| 340 | } else | ||
| 341 | ret= *ne; | ||
| 342 | |||
| 343 | if (!X509_NAME_ENTRY_set_object(ret, obj)) | ||
| 344 | goto err; | ||
| 345 | if (!X509_NAME_ENTRY_set_data(ret, type, bytes, len)) | ||
| 346 | goto err; | ||
| 347 | |||
| 348 | if ((ne != NULL) && (*ne == NULL)) | ||
| 349 | *ne = ret; | ||
| 350 | return (ret); | ||
| 351 | |||
| 352 | err: | ||
| 353 | if ((ne == NULL) || (ret != *ne)) | ||
| 354 | X509_NAME_ENTRY_free(ret); | ||
| 355 | return (NULL); | ||
| 356 | } | ||
| 357 | |||
| 358 | int | ||
| 359 | X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj) | ||
| 360 | { | ||
| 361 | if ((ne == NULL) || (obj == NULL)) { | ||
| 362 | X509err(X509_F_X509_NAME_ENTRY_SET_OBJECT, | ||
| 363 | ERR_R_PASSED_NULL_PARAMETER); | ||
| 364 | return (0); | ||
| 365 | } | ||
| 366 | ASN1_OBJECT_free(ne->object); | ||
| 367 | ne->object = OBJ_dup(obj); | ||
| 368 | return ((ne->object == NULL) ? 0 : 1); | ||
| 369 | } | ||
| 370 | |||
| 371 | int | ||
| 372 | X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, | ||
| 373 | const unsigned char *bytes, int len) | ||
| 374 | { | ||
| 375 | int i; | ||
| 376 | |||
| 377 | if ((ne == NULL) || ((bytes == NULL) && (len != 0))) | ||
| 378 | return (0); | ||
| 379 | if ((type > 0) && (type & MBSTRING_FLAG)) | ||
| 380 | return ASN1_STRING_set_by_NID(&ne->value, bytes, len, type, | ||
| 381 | OBJ_obj2nid(ne->object)) ? 1 : 0; | ||
| 382 | if (len < 0) | ||
| 383 | len = strlen((const char *)bytes); | ||
| 384 | i = ASN1_STRING_set(ne->value, bytes, len); | ||
| 385 | if (!i) | ||
| 386 | return (0); | ||
| 387 | if (type != V_ASN1_UNDEF) { | ||
| 388 | if (type == V_ASN1_APP_CHOOSE) | ||
| 389 | ne->value->type = ASN1_PRINTABLE_type(bytes, len); | ||
| 390 | else | ||
| 391 | ne->value->type = type; | ||
| 392 | } | ||
| 393 | return (1); | ||
| 394 | } | ||
| 395 | |||
| 396 | ASN1_OBJECT * | ||
| 397 | X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne) | ||
| 398 | { | ||
| 399 | if (ne == NULL) | ||
| 400 | return (NULL); | ||
| 401 | return (ne->object); | ||
| 402 | } | ||
| 403 | |||
| 404 | ASN1_STRING * | ||
| 405 | X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne) | ||
| 406 | { | ||
| 407 | if (ne == NULL) | ||
| 408 | return (NULL); | ||
| 409 | return (ne->value); | ||
| 410 | } | ||
diff --git a/src/lib/libcrypto/x509/x509rset.c b/src/lib/libcrypto/x509/x509rset.c deleted file mode 100644 index cfac977636..0000000000 --- a/src/lib/libcrypto/x509/x509rset.c +++ /dev/null | |||
| @@ -1,88 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509rset.c,v 1.6 2014/07/11 08:44:49 jsing Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/asn1.h> | ||
| 62 | #include <openssl/evp.h> | ||
| 63 | #include <openssl/objects.h> | ||
| 64 | #include <openssl/x509.h> | ||
| 65 | |||
| 66 | int | ||
| 67 | X509_REQ_set_version(X509_REQ *x, long version) | ||
| 68 | { | ||
| 69 | if (x == NULL) | ||
| 70 | return (0); | ||
| 71 | return (ASN1_INTEGER_set(x->req_info->version, version)); | ||
| 72 | } | ||
| 73 | |||
| 74 | int | ||
| 75 | X509_REQ_set_subject_name(X509_REQ *x, X509_NAME *name) | ||
| 76 | { | ||
| 77 | if ((x == NULL) || (x->req_info == NULL)) | ||
| 78 | return (0); | ||
| 79 | return (X509_NAME_set(&x->req_info->subject, name)); | ||
| 80 | } | ||
| 81 | |||
| 82 | int | ||
| 83 | X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey) | ||
| 84 | { | ||
| 85 | if ((x == NULL) || (x->req_info == NULL)) | ||
| 86 | return (0); | ||
| 87 | return (X509_PUBKEY_set(&x->req_info->pubkey, pkey)); | ||
| 88 | } | ||
diff --git a/src/lib/libcrypto/x509/x509spki.c b/src/lib/libcrypto/x509/x509spki.c deleted file mode 100644 index cd29a8138a..0000000000 --- a/src/lib/libcrypto/x509/x509spki.c +++ /dev/null | |||
| @@ -1,132 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509spki.c,v 1.12 2014/07/11 08:44:49 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/err.h> | ||
| 63 | #include <openssl/x509.h> | ||
| 64 | |||
| 65 | int | ||
| 66 | NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *x, EVP_PKEY *pkey) | ||
| 67 | { | ||
| 68 | if ((x == NULL) || (x->spkac == NULL)) | ||
| 69 | return (0); | ||
| 70 | return (X509_PUBKEY_set(&(x->spkac->pubkey), pkey)); | ||
| 71 | } | ||
| 72 | |||
| 73 | EVP_PKEY * | ||
| 74 | NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x) | ||
| 75 | { | ||
| 76 | if ((x == NULL) || (x->spkac == NULL)) | ||
| 77 | return (NULL); | ||
| 78 | return (X509_PUBKEY_get(x->spkac->pubkey)); | ||
| 79 | } | ||
| 80 | |||
| 81 | /* Load a Netscape SPKI from a base64 encoded string */ | ||
| 82 | |||
| 83 | NETSCAPE_SPKI * | ||
| 84 | NETSCAPE_SPKI_b64_decode(const char *str, int len) | ||
| 85 | { | ||
| 86 | unsigned char *spki_der; | ||
| 87 | const unsigned char *p; | ||
| 88 | int spki_len; | ||
| 89 | NETSCAPE_SPKI *spki; | ||
| 90 | |||
| 91 | if (len <= 0) | ||
| 92 | len = strlen(str); | ||
| 93 | if (!(spki_der = malloc(len + 1))) { | ||
| 94 | X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE); | ||
| 95 | return NULL; | ||
| 96 | } | ||
| 97 | spki_len = EVP_DecodeBlock(spki_der, (const unsigned char *)str, len); | ||
| 98 | if (spki_len < 0) { | ||
| 99 | X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, | ||
| 100 | X509_R_BASE64_DECODE_ERROR); | ||
| 101 | free(spki_der); | ||
| 102 | return NULL; | ||
| 103 | } | ||
| 104 | p = spki_der; | ||
| 105 | spki = d2i_NETSCAPE_SPKI(NULL, &p, spki_len); | ||
| 106 | free(spki_der); | ||
| 107 | return spki; | ||
| 108 | } | ||
| 109 | |||
| 110 | /* Generate a base64 encoded string from an SPKI */ | ||
| 111 | |||
| 112 | char * | ||
| 113 | NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki) | ||
| 114 | { | ||
| 115 | unsigned char *der_spki, *p; | ||
| 116 | char *b64_str; | ||
| 117 | int der_len; | ||
| 118 | der_len = i2d_NETSCAPE_SPKI(spki, NULL); | ||
| 119 | der_spki = malloc(der_len); | ||
| 120 | b64_str = reallocarray(NULL, der_len, 2); | ||
| 121 | if (!der_spki || !b64_str) { | ||
| 122 | X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE); | ||
| 123 | free(der_spki); | ||
| 124 | free(b64_str); | ||
| 125 | return NULL; | ||
| 126 | } | ||
| 127 | p = der_spki; | ||
| 128 | i2d_NETSCAPE_SPKI(spki, &p); | ||
| 129 | EVP_EncodeBlock((unsigned char *)b64_str, der_spki, der_len); | ||
| 130 | free(der_spki); | ||
| 131 | return b64_str; | ||
| 132 | } | ||
diff --git a/src/lib/libcrypto/x509/x509type.c b/src/lib/libcrypto/x509/x509type.c deleted file mode 100644 index d0dcffb290..0000000000 --- a/src/lib/libcrypto/x509/x509type.c +++ /dev/null | |||
| @@ -1,130 +0,0 @@ | |||
| 1 | /* $OpenBSD: x509type.c,v 1.12 2015/06/13 08:38:10 doug Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/evp.h> | ||
| 62 | #include <openssl/objects.h> | ||
| 63 | #include <openssl/x509.h> | ||
| 64 | |||
| 65 | int | ||
| 66 | X509_certificate_type(X509 *x, EVP_PKEY *pkey) | ||
| 67 | { | ||
| 68 | EVP_PKEY *pk; | ||
| 69 | int ret = 0, i; | ||
| 70 | |||
| 71 | if (x == NULL) | ||
| 72 | return (0); | ||
| 73 | |||
| 74 | if (pkey == NULL) | ||
| 75 | pk = X509_get_pubkey(x); | ||
| 76 | else | ||
| 77 | pk = pkey; | ||
| 78 | |||
| 79 | if (pk == NULL) | ||
| 80 | return (0); | ||
| 81 | |||
| 82 | switch (pk->type) { | ||
| 83 | case EVP_PKEY_RSA: | ||
| 84 | ret = EVP_PK_RSA|EVP_PKT_SIGN; | ||
| 85 | /* if (!sign only extension) */ | ||
| 86 | ret |= EVP_PKT_ENC; | ||
| 87 | break; | ||
| 88 | case EVP_PKEY_DSA: | ||
| 89 | ret = EVP_PK_DSA|EVP_PKT_SIGN; | ||
| 90 | break; | ||
| 91 | case EVP_PKEY_EC: | ||
| 92 | ret = EVP_PK_EC|EVP_PKT_SIGN|EVP_PKT_EXCH; | ||
| 93 | break; | ||
| 94 | case EVP_PKEY_DH: | ||
| 95 | ret = EVP_PK_DH|EVP_PKT_EXCH; | ||
| 96 | break; | ||
| 97 | case NID_id_GostR3410_94: | ||
| 98 | case NID_id_GostR3410_2001: | ||
| 99 | ret = EVP_PKT_EXCH|EVP_PKT_SIGN; | ||
| 100 | break; | ||
| 101 | default: | ||
| 102 | break; | ||
| 103 | } | ||
| 104 | |||
| 105 | i = OBJ_obj2nid(x->sig_alg->algorithm); | ||
| 106 | if (i && OBJ_find_sigid_algs(i, NULL, &i)) { | ||
| 107 | switch (i) { | ||
| 108 | case NID_rsaEncryption: | ||
| 109 | case NID_rsa: | ||
| 110 | ret |= EVP_PKS_RSA; | ||
| 111 | break; | ||
| 112 | case NID_dsa: | ||
| 113 | case NID_dsa_2: | ||
| 114 | ret |= EVP_PKS_DSA; | ||
| 115 | break; | ||
| 116 | case NID_X9_62_id_ecPublicKey: | ||
| 117 | ret |= EVP_PKS_EC; | ||
| 118 | break; | ||
| 119 | default: | ||
| 120 | break; | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | /* /8 because it's 1024 bits we look for, not bytes */ | ||
| 125 | if (EVP_PKEY_size(pk) <= 1024 / 8) | ||
| 126 | ret |= EVP_PKT_EXP; | ||
| 127 | if (pkey == NULL) | ||
| 128 | EVP_PKEY_free(pk); | ||
| 129 | return (ret); | ||
| 130 | } | ||
diff --git a/src/lib/libcrypto/x509/x_all.c b/src/lib/libcrypto/x509/x_all.c deleted file mode 100644 index 28a81c14a7..0000000000 --- a/src/lib/libcrypto/x509/x_all.c +++ /dev/null | |||
| @@ -1,609 +0,0 @@ | |||
| 1 | /* $OpenBSD: x_all.c,v 1.19 2015/01/28 04:14:31 beck Exp $ */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | #include <openssl/opensslconf.h> | ||
| 62 | |||
| 63 | #include <openssl/asn1.h> | ||
| 64 | #include <openssl/buffer.h> | ||
| 65 | #include <openssl/evp.h> | ||
| 66 | #include <openssl/stack.h> | ||
| 67 | #include <openssl/x509.h> | ||
| 68 | |||
| 69 | #ifndef OPENSSL_NO_DSA | ||
| 70 | #include <openssl/dsa.h> | ||
| 71 | #endif | ||
| 72 | #ifndef OPENSSL_NO_RSA | ||
| 73 | #include <openssl/rsa.h> | ||
| 74 | #endif | ||
| 75 | |||
| 76 | int | ||
| 77 | X509_verify(X509 *a, EVP_PKEY *r) | ||
| 78 | { | ||
| 79 | if (X509_ALGOR_cmp(a->sig_alg, a->cert_info->signature)) | ||
| 80 | return 0; | ||
| 81 | return(ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF), a->sig_alg, | ||
| 82 | a->signature, a->cert_info, r)); | ||
| 83 | } | ||
| 84 | |||
| 85 | int | ||
| 86 | X509_REQ_verify(X509_REQ *a, EVP_PKEY *r) | ||
| 87 | { | ||
| 88 | return( ASN1_item_verify(ASN1_ITEM_rptr(X509_REQ_INFO), | ||
| 89 | a->sig_alg, a->signature, a->req_info, r)); | ||
| 90 | } | ||
| 91 | |||
| 92 | int | ||
| 93 | NETSCAPE_SPKI_verify(NETSCAPE_SPKI *a, EVP_PKEY *r) | ||
| 94 | { | ||
| 95 | return(ASN1_item_verify(ASN1_ITEM_rptr(NETSCAPE_SPKAC), | ||
| 96 | a->sig_algor, a->signature, a->spkac, r)); | ||
| 97 | } | ||
| 98 | |||
| 99 | int | ||
| 100 | X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) | ||
| 101 | { | ||
| 102 | x->cert_info->enc.modified = 1; | ||
| 103 | return (ASN1_item_sign(ASN1_ITEM_rptr(X509_CINF), | ||
| 104 | x->cert_info->signature, x->sig_alg, x->signature, | ||
| 105 | x->cert_info, pkey, md)); | ||
| 106 | } | ||
| 107 | |||
| 108 | int | ||
| 109 | X509_sign_ctx(X509 *x, EVP_MD_CTX *ctx) | ||
| 110 | { | ||
| 111 | x->cert_info->enc.modified = 1; | ||
| 112 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CINF), | ||
| 113 | x->cert_info->signature, x->sig_alg, x->signature, | ||
| 114 | x->cert_info, ctx); | ||
| 115 | } | ||
| 116 | |||
| 117 | int | ||
| 118 | X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md) | ||
| 119 | { | ||
| 120 | return (ASN1_item_sign(ASN1_ITEM_rptr(X509_REQ_INFO), | ||
| 121 | x->sig_alg, NULL, x->signature, x->req_info, pkey, md)); | ||
| 122 | } | ||
| 123 | |||
| 124 | int | ||
| 125 | X509_REQ_sign_ctx(X509_REQ *x, EVP_MD_CTX *ctx) | ||
| 126 | { | ||
| 127 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_REQ_INFO), | ||
| 128 | x->sig_alg, NULL, x->signature, x->req_info, ctx); | ||
| 129 | } | ||
| 130 | |||
| 131 | int | ||
| 132 | X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md) | ||
| 133 | { | ||
| 134 | x->crl->enc.modified = 1; | ||
| 135 | return(ASN1_item_sign(ASN1_ITEM_rptr(X509_CRL_INFO), x->crl->sig_alg, | ||
| 136 | x->sig_alg, x->signature, x->crl, pkey, md)); | ||
| 137 | } | ||
| 138 | |||
| 139 | int | ||
| 140 | X509_CRL_sign_ctx(X509_CRL *x, EVP_MD_CTX *ctx) | ||
| 141 | { | ||
| 142 | x->crl->enc.modified = 1; | ||
| 143 | return ASN1_item_sign_ctx(ASN1_ITEM_rptr(X509_CRL_INFO), | ||
| 144 | x->crl->sig_alg, x->sig_alg, x->signature, x->crl, ctx); | ||
| 145 | } | ||
| 146 | |||
| 147 | int | ||
| 148 | NETSCAPE_SPKI_sign(NETSCAPE_SPKI *x, EVP_PKEY *pkey, const EVP_MD *md) | ||
| 149 | { | ||
| 150 | return (ASN1_item_sign(ASN1_ITEM_rptr(NETSCAPE_SPKAC), | ||
| 151 | x->sig_algor, NULL, x->signature, x->spkac, pkey, md)); | ||
| 152 | } | ||
| 153 | |||
| 154 | X509 * | ||
| 155 | d2i_X509_fp(FILE *fp, X509 **x509) | ||
| 156 | { | ||
| 157 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509), fp, x509); | ||
| 158 | } | ||
| 159 | |||
| 160 | int | ||
| 161 | i2d_X509_fp(FILE *fp, X509 *x509) | ||
| 162 | { | ||
| 163 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509), fp, x509); | ||
| 164 | } | ||
| 165 | |||
| 166 | X509 * | ||
| 167 | d2i_X509_bio(BIO *bp, X509 **x509) | ||
| 168 | { | ||
| 169 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509), bp, x509); | ||
| 170 | } | ||
| 171 | |||
| 172 | int | ||
| 173 | i2d_X509_bio(BIO *bp, X509 *x509) | ||
| 174 | { | ||
| 175 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bp, x509); | ||
| 176 | } | ||
| 177 | |||
| 178 | X509_CRL * | ||
| 179 | d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl) | ||
| 180 | { | ||
| 181 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); | ||
| 182 | } | ||
| 183 | |||
| 184 | int | ||
| 185 | i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl) | ||
| 186 | { | ||
| 187 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_CRL), fp, crl); | ||
| 188 | } | ||
| 189 | |||
| 190 | X509_CRL * | ||
| 191 | d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl) | ||
| 192 | { | ||
| 193 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); | ||
| 194 | } | ||
| 195 | |||
| 196 | int | ||
| 197 | i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl) | ||
| 198 | { | ||
| 199 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_CRL), bp, crl); | ||
| 200 | } | ||
| 201 | |||
| 202 | PKCS7 * | ||
| 203 | d2i_PKCS7_fp(FILE *fp, PKCS7 **p7) | ||
| 204 | { | ||
| 205 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); | ||
| 206 | } | ||
| 207 | |||
| 208 | int | ||
| 209 | i2d_PKCS7_fp(FILE *fp, PKCS7 *p7) | ||
| 210 | { | ||
| 211 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(PKCS7), fp, p7); | ||
| 212 | } | ||
| 213 | |||
| 214 | PKCS7 * | ||
| 215 | d2i_PKCS7_bio(BIO *bp, PKCS7 **p7) | ||
| 216 | { | ||
| 217 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); | ||
| 218 | } | ||
| 219 | |||
| 220 | int | ||
| 221 | i2d_PKCS7_bio(BIO *bp, PKCS7 *p7) | ||
| 222 | { | ||
| 223 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(PKCS7), bp, p7); | ||
| 224 | } | ||
| 225 | |||
| 226 | X509_REQ * | ||
| 227 | d2i_X509_REQ_fp(FILE *fp, X509_REQ **req) | ||
| 228 | { | ||
| 229 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); | ||
| 230 | } | ||
| 231 | |||
| 232 | int | ||
| 233 | i2d_X509_REQ_fp(FILE *fp, X509_REQ *req) | ||
| 234 | { | ||
| 235 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(X509_REQ), fp, req); | ||
| 236 | } | ||
| 237 | |||
| 238 | X509_REQ * | ||
| 239 | d2i_X509_REQ_bio(BIO *bp, X509_REQ **req) | ||
| 240 | { | ||
| 241 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); | ||
| 242 | } | ||
| 243 | |||
| 244 | int | ||
| 245 | i2d_X509_REQ_bio(BIO *bp, X509_REQ *req) | ||
| 246 | { | ||
| 247 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509_REQ), bp, req); | ||
| 248 | } | ||
| 249 | |||
| 250 | #ifndef OPENSSL_NO_RSA | ||
| 251 | |||
| 252 | RSA * | ||
| 253 | d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa) | ||
| 254 | { | ||
| 255 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); | ||
| 256 | } | ||
| 257 | |||
| 258 | int | ||
| 259 | i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa) | ||
| 260 | { | ||
| 261 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPrivateKey), fp, rsa); | ||
| 262 | } | ||
| 263 | |||
| 264 | RSA * | ||
| 265 | d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa) | ||
| 266 | { | ||
| 267 | return ASN1_item_d2i_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); | ||
| 268 | } | ||
| 269 | |||
| 270 | |||
| 271 | RSA * | ||
| 272 | d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa) | ||
| 273 | { | ||
| 274 | return ASN1_d2i_fp((void *(*)(void))RSA_new, | ||
| 275 | (D2I_OF(void))d2i_RSA_PUBKEY, fp, (void **)rsa); | ||
| 276 | } | ||
| 277 | |||
| 278 | int | ||
| 279 | i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa) | ||
| 280 | { | ||
| 281 | return ASN1_item_i2d_fp(ASN1_ITEM_rptr(RSAPublicKey), fp, rsa); | ||
| 282 | } | ||
| 283 | |||
| 284 | int | ||
| 285 | i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa) | ||
| 286 | { | ||
| 287 | return ASN1_i2d_fp((I2D_OF(void))i2d_RSA_PUBKEY, fp, rsa); | ||
| 288 | } | ||
| 289 | |||
| 290 | RSA * | ||
| 291 | d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa) | ||
| 292 | { | ||
| 293 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); | ||
| 294 | } | ||
| 295 | |||
| 296 | int | ||
| 297 | i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa) | ||
| 298 | { | ||
| 299 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPrivateKey), bp, rsa); | ||
| 300 | } | ||
| 301 | |||
| 302 | RSA * | ||
| 303 | d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa) | ||
| 304 | { | ||
| 305 | return ASN1_item_d2i_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); | ||
| 306 | } | ||
| 307 | |||
| 308 | |||
| 309 | RSA * | ||
| 310 | d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa) | ||
| 311 | { | ||
| 312 | return ASN1_d2i_bio_of(RSA, RSA_new, d2i_RSA_PUBKEY, bp, rsa); | ||
| 313 | } | ||
| 314 | |||
| 315 | int | ||
| 316 | i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa) | ||
| 317 | { | ||
| 318 | return ASN1_item_i2d_bio(ASN1_ITEM_rptr(RSAPublicKey), bp, rsa); | ||
| 319 | } | ||
| 320 | |||
| 321 | int | ||
| 322 | i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa) | ||
| 323 | { | ||
| 324 | return ASN1_i2d_bio_of(RSA, i2d_RSA_PUBKEY, bp, rsa); | ||
| 325 | } | ||
| 326 | #endif | ||
| 327 | |||
| 328 | #ifndef OPENSSL_NO_DSA | ||
| 329 | DSA * | ||
| 330 | d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa) | ||
| 331 | { | ||
| 332 | return ASN1_d2i_fp_of(DSA, DSA_new, d2i_DSAPrivateKey, fp, dsa); | ||
| 333 | } | ||
| 334 | |||
| 335 | int | ||
| 336 | i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa) | ||
| 337 | { | ||
| 338 | return ASN1_i2d_fp_of_const(DSA, i2d_DSAPrivateKey, fp, dsa); | ||
| 339 | } | ||
| 340 | |||
| 341 | DSA * | ||
| 342 | d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa) | ||
| 343 | { | ||
| 344 | return ASN1_d2i_fp_of(DSA, DSA_new, d2i_DSA_PUBKEY, fp, dsa); | ||
| 345 | } | ||
| 346 | |||
| 347 | int | ||
| 348 | i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa) | ||
| 349 | { | ||
| 350 | return ASN1_i2d_fp_of(DSA, i2d_DSA_PUBKEY, fp, dsa); | ||
| 351 | } | ||
| 352 | |||
| 353 | DSA * | ||
| 354 | d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa) | ||
| 355 | { | ||
| 356 | return ASN1_d2i_bio_of(DSA, DSA_new, d2i_DSAPrivateKey, bp, dsa); | ||
| 357 | } | ||
| 358 | |||
| 359 | int | ||
| 360 | i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa) | ||
| 361 | { | ||
| 362 | return ASN1_i2d_bio_of_const(DSA, i2d_DSAPrivateKey, bp, dsa); | ||
| 363 | } | ||
| 364 | |||
| 365 | DSA * | ||
| 366 | d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa) | ||
| 367 | { | ||
| 368 | return ASN1_d2i_bio_of(DSA, DSA_new, d2i_DSA_PUBKEY, bp, dsa); | ||
| 369 | } | ||
| 370 | |||
| 371 | int | ||
| 372 | i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa) | ||
| 373 | { | ||
| 374 | return ASN1_i2d_bio_of(DSA, i2d_DSA_PUBKEY, bp, dsa); | ||
| 375 | } | ||
| 376 | |||
| 377 | #endif | ||
| 378 | |||
| 379 | #ifndef OPENSSL_NO_EC | ||
| 380 | EC_KEY * | ||
| 381 | d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey) | ||
| 382 | { | ||
| 383 | return ASN1_d2i_fp_of(EC_KEY, EC_KEY_new, d2i_EC_PUBKEY, fp, eckey); | ||
| 384 | } | ||
| 385 | |||
| 386 | int | ||
| 387 | i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey) | ||
| 388 | { | ||
| 389 | return ASN1_i2d_fp_of(EC_KEY, i2d_EC_PUBKEY, fp, eckey); | ||
| 390 | } | ||
| 391 | |||
| 392 | EC_KEY * | ||
| 393 | d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey) | ||
| 394 | { | ||
| 395 | return ASN1_d2i_fp_of(EC_KEY, EC_KEY_new, d2i_ECPrivateKey, fp, eckey); | ||
| 396 | } | ||
| 397 | |||
| 398 | int | ||
| 399 | i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey) | ||
| 400 | { | ||
| 401 | return ASN1_i2d_fp_of(EC_KEY, i2d_ECPrivateKey, fp, eckey); | ||
| 402 | } | ||
| 403 | EC_KEY * | ||
| 404 | d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey) | ||
| 405 | { | ||
| 406 | return ASN1_d2i_bio_of(EC_KEY, EC_KEY_new, d2i_EC_PUBKEY, bp, eckey); | ||
| 407 | } | ||
| 408 | |||
| 409 | int | ||
| 410 | i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *ecdsa) | ||
| 411 | { | ||
| 412 | return ASN1_i2d_bio_of(EC_KEY, i2d_EC_PUBKEY, bp, ecdsa); | ||
| 413 | } | ||
| 414 | |||
| 415 | EC_KEY * | ||
| 416 | d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey) | ||
| 417 | { | ||
| 418 | return ASN1_d2i_bio_of(EC_KEY, EC_KEY_new, d2i_ECPrivateKey, bp, eckey); | ||
| 419 | } | ||
| 420 | |||
| 421 | int | ||
| 422 | i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey) | ||
| 423 | { | ||
| 424 | return ASN1_i2d_bio_of(EC_KEY, i2d_ECPrivateKey, bp, eckey); | ||
| 425 | } | ||
| 426 | #endif | ||
| 427 | |||
| 428 | |||
| 429 | int | ||
| 430 | X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md, | ||
| 431 | unsigned int *len) | ||
| 432 | { | ||
| 433 | ASN1_BIT_STRING *key; | ||
| 434 | key = X509_get0_pubkey_bitstr(data); | ||
| 435 | if (!key) | ||
| 436 | return 0; | ||
| 437 | return EVP_Digest(key->data, key->length, md, len, type, NULL); | ||
| 438 | } | ||
| 439 | |||
| 440 | int | ||
| 441 | X509_digest(const X509 *data, const EVP_MD *type, unsigned char *md, | ||
| 442 | unsigned int *len) | ||
| 443 | { | ||
| 444 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509), type, (char *)data, | ||
| 445 | md, len)); | ||
| 446 | } | ||
| 447 | |||
| 448 | int | ||
| 449 | X509_CRL_digest(const X509_CRL *data, const EVP_MD *type, unsigned char *md, | ||
| 450 | unsigned int *len) | ||
| 451 | { | ||
| 452 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509_CRL), type, (char *)data, | ||
| 453 | md, len)); | ||
| 454 | } | ||
| 455 | |||
| 456 | int | ||
| 457 | X509_REQ_digest(const X509_REQ *data, const EVP_MD *type, unsigned char *md, | ||
| 458 | unsigned int *len) | ||
| 459 | { | ||
| 460 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509_REQ), type, (char *)data, | ||
| 461 | md, len)); | ||
| 462 | } | ||
| 463 | |||
| 464 | int | ||
| 465 | X509_NAME_digest(const X509_NAME *data, const EVP_MD *type, unsigned char *md, | ||
| 466 | unsigned int *len) | ||
| 467 | { | ||
| 468 | return (ASN1_item_digest(ASN1_ITEM_rptr(X509_NAME), type, (char *)data, | ||
| 469 | md, len)); | ||
| 470 | } | ||
| 471 | |||
| 472 | int | ||
| 473 | PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, | ||
| 474 | const EVP_MD *type, unsigned char *md, unsigned int *len) | ||
| 475 | { | ||
| 476 | return(ASN1_item_digest(ASN1_ITEM_rptr(PKCS7_ISSUER_AND_SERIAL), type, | ||
| 477 | (char *)data, md, len)); | ||
| 478 | } | ||
| 479 | |||
| 480 | |||
| 481 | X509_SIG * | ||
| 482 | d2i_PKCS8_fp(FILE *fp, X509_SIG **p8) | ||
| 483 | { | ||
| 484 | return ASN1_d2i_fp_of(X509_SIG, X509_SIG_new, d2i_X509_SIG, fp, p8); | ||
| 485 | } | ||
| 486 | |||
| 487 | int | ||
| 488 | i2d_PKCS8_fp(FILE *fp, X509_SIG *p8) | ||
| 489 | { | ||
| 490 | return ASN1_i2d_fp_of(X509_SIG, i2d_X509_SIG, fp, p8); | ||
| 491 | } | ||
| 492 | |||
| 493 | X509_SIG * | ||
| 494 | d2i_PKCS8_bio(BIO *bp, X509_SIG **p8) | ||
| 495 | { | ||
| 496 | return ASN1_d2i_bio_of(X509_SIG, X509_SIG_new, d2i_X509_SIG, bp, p8); | ||
| 497 | } | ||
| 498 | |||
| 499 | int | ||
| 500 | i2d_PKCS8_bio(BIO *bp, X509_SIG *p8) | ||
| 501 | { | ||
| 502 | return ASN1_i2d_bio_of(X509_SIG, i2d_X509_SIG, bp, p8); | ||
| 503 | } | ||
| 504 | |||
| 505 | PKCS8_PRIV_KEY_INFO * | ||
| 506 | d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO **p8inf) | ||
| 507 | { | ||
| 508 | return ASN1_d2i_fp_of(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_new, | ||
| 509 | d2i_PKCS8_PRIV_KEY_INFO, fp, p8inf); | ||
| 510 | } | ||
| 511 | |||
| 512 | int | ||
| 513 | i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf) | ||
| 514 | { | ||
| 515 | return ASN1_i2d_fp_of(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO, | ||
| 516 | fp, p8inf); | ||
| 517 | } | ||
| 518 | |||
| 519 | int | ||
| 520 | i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key) | ||
| 521 | { | ||
| 522 | PKCS8_PRIV_KEY_INFO *p8inf; | ||
| 523 | int ret; | ||
| 524 | p8inf = EVP_PKEY2PKCS8(key); | ||
| 525 | if (!p8inf) | ||
| 526 | return 0; | ||
| 527 | ret = i2d_PKCS8_PRIV_KEY_INFO_fp(fp, p8inf); | ||
| 528 | PKCS8_PRIV_KEY_INFO_free(p8inf); | ||
| 529 | return ret; | ||
| 530 | } | ||
| 531 | |||
| 532 | int | ||
| 533 | i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey) | ||
| 534 | { | ||
| 535 | return ASN1_i2d_fp_of(EVP_PKEY, i2d_PrivateKey, fp, pkey); | ||
| 536 | } | ||
| 537 | |||
| 538 | EVP_PKEY * | ||
| 539 | d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a) | ||
| 540 | { | ||
| 541 | return ASN1_d2i_fp_of(EVP_PKEY, EVP_PKEY_new, d2i_AutoPrivateKey, | ||
| 542 | fp, a); | ||
| 543 | } | ||
| 544 | |||
| 545 | int | ||
| 546 | i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey) | ||
| 547 | { | ||
| 548 | return ASN1_i2d_fp_of(EVP_PKEY, i2d_PUBKEY, fp, pkey); | ||
| 549 | } | ||
| 550 | |||
| 551 | EVP_PKEY * | ||
| 552 | d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a) | ||
| 553 | { | ||
| 554 | return ASN1_d2i_fp_of(EVP_PKEY, EVP_PKEY_new, d2i_PUBKEY, fp, a); | ||
| 555 | } | ||
| 556 | |||
| 557 | |||
| 558 | PKCS8_PRIV_KEY_INFO * | ||
| 559 | d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO **p8inf) | ||
| 560 | { | ||
| 561 | return ASN1_d2i_bio_of(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO_new, | ||
| 562 | d2i_PKCS8_PRIV_KEY_INFO, bp, p8inf); | ||
| 563 | } | ||
| 564 | |||
| 565 | int | ||
| 566 | i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf) | ||
| 567 | { | ||
| 568 | return ASN1_i2d_bio_of(PKCS8_PRIV_KEY_INFO, i2d_PKCS8_PRIV_KEY_INFO, | ||
| 569 | bp, p8inf); | ||
| 570 | } | ||
| 571 | |||
| 572 | int | ||
| 573 | i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) | ||
| 574 | { | ||
| 575 | PKCS8_PRIV_KEY_INFO *p8inf; | ||
| 576 | int ret; | ||
| 577 | |||
| 578 | p8inf = EVP_PKEY2PKCS8(key); | ||
| 579 | if (!p8inf) | ||
| 580 | return 0; | ||
| 581 | ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf); | ||
| 582 | PKCS8_PRIV_KEY_INFO_free(p8inf); | ||
| 583 | return ret; | ||
| 584 | } | ||
| 585 | |||
| 586 | int | ||
| 587 | i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey) | ||
| 588 | { | ||
| 589 | return ASN1_i2d_bio_of(EVP_PKEY, i2d_PrivateKey, bp, pkey); | ||
| 590 | } | ||
| 591 | |||
| 592 | EVP_PKEY * | ||
| 593 | d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a) | ||
| 594 | { | ||
| 595 | return ASN1_d2i_bio_of(EVP_PKEY, EVP_PKEY_new, d2i_AutoPrivateKey, | ||
| 596 | bp, a); | ||
| 597 | } | ||
| 598 | |||
| 599 | int | ||
| 600 | i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey) | ||
| 601 | { | ||
| 602 | return ASN1_i2d_bio_of(EVP_PKEY, i2d_PUBKEY, bp, pkey); | ||
| 603 | } | ||
| 604 | |||
| 605 | EVP_PKEY * | ||
| 606 | d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a) | ||
| 607 | { | ||
| 608 | return ASN1_d2i_bio_of(EVP_PKEY, EVP_PKEY_new, d2i_PUBKEY, bp, a); | ||
| 609 | } | ||
