[331] | 1 | /*
|
---|
| 2 | * Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
|
---|
| 3 | *
|
---|
| 4 | * Licensed under the OpenSSL license (the "License"). You may not use
|
---|
| 5 | * this file except in compliance with the License. You can obtain a copy
|
---|
| 6 | * in the file LICENSE in the source distribution or at
|
---|
| 7 | * https://www.openssl.org/source/license.html
|
---|
| 8 | */
|
---|
| 9 |
|
---|
| 10 | /*
|
---|
| 11 | * This structure holds all parameters associated with a verify operation by
|
---|
| 12 | * including an X509_VERIFY_PARAM structure in related structures the
|
---|
| 13 | * parameters used can be customized
|
---|
| 14 | */
|
---|
| 15 |
|
---|
| 16 | struct X509_VERIFY_PARAM_st {
|
---|
| 17 | char *name;
|
---|
| 18 | time_t check_time; /* Time to use */
|
---|
| 19 | uint32_t inh_flags; /* Inheritance flags */
|
---|
| 20 | unsigned long flags; /* Various verify flags */
|
---|
| 21 | int purpose; /* purpose to check untrusted certificates */
|
---|
| 22 | int trust; /* trust setting to check */
|
---|
| 23 | int depth; /* Verify depth */
|
---|
| 24 | int auth_level; /* Security level for chain verification */
|
---|
| 25 | STACK_OF(ASN1_OBJECT) *policies; /* Permissible policies */
|
---|
| 26 | /* Peer identity details */
|
---|
| 27 | STACK_OF(OPENSSL_STRING) *hosts; /* Set of acceptable names */
|
---|
| 28 | unsigned int hostflags; /* Flags to control matching features */
|
---|
| 29 | char *peername; /* Matching hostname in peer certificate */
|
---|
| 30 | char *email; /* If not NULL email address to match */
|
---|
| 31 | size_t emaillen;
|
---|
| 32 | unsigned char *ip; /* If not NULL IP address to match */
|
---|
| 33 | size_t iplen; /* Length of IP address */
|
---|
| 34 | };
|
---|
| 35 |
|
---|
| 36 | /* No error callback if depth < 0 */
|
---|
| 37 | int x509_check_cert_time(X509_STORE_CTX *ctx, X509 *x, int depth);
|
---|
| 38 |
|
---|
| 39 | /* a sequence of these are used */
|
---|
| 40 | struct x509_attributes_st {
|
---|
| 41 | ASN1_OBJECT *object;
|
---|
| 42 | STACK_OF(ASN1_TYPE) *set;
|
---|
| 43 | };
|
---|
| 44 |
|
---|
| 45 | struct X509_extension_st {
|
---|
| 46 | ASN1_OBJECT *object;
|
---|
| 47 | ASN1_BOOLEAN critical;
|
---|
| 48 | ASN1_OCTET_STRING value;
|
---|
| 49 | };
|
---|
| 50 |
|
---|
| 51 | /*
|
---|
| 52 | * Method to handle CRL access. In general a CRL could be very large (several
|
---|
| 53 | * Mb) and can consume large amounts of resources if stored in memory by
|
---|
| 54 | * multiple processes. This method allows general CRL operations to be
|
---|
| 55 | * redirected to more efficient callbacks: for example a CRL entry database.
|
---|
| 56 | */
|
---|
| 57 |
|
---|
| 58 | #define X509_CRL_METHOD_DYNAMIC 1
|
---|
| 59 |
|
---|
| 60 | struct x509_crl_method_st {
|
---|
| 61 | int flags;
|
---|
| 62 | int (*crl_init) (X509_CRL *crl);
|
---|
| 63 | int (*crl_free) (X509_CRL *crl);
|
---|
| 64 | int (*crl_lookup) (X509_CRL *crl, X509_REVOKED **ret,
|
---|
| 65 | ASN1_INTEGER *ser, X509_NAME *issuer);
|
---|
| 66 | int (*crl_verify) (X509_CRL *crl, EVP_PKEY *pk);
|
---|
| 67 | };
|
---|
| 68 |
|
---|
| 69 | struct x509_lookup_method_st {
|
---|
| 70 | const char *name;
|
---|
| 71 | int (*new_item) (X509_LOOKUP *ctx);
|
---|
| 72 | void (*free) (X509_LOOKUP *ctx);
|
---|
| 73 | int (*init) (X509_LOOKUP *ctx);
|
---|
| 74 | int (*shutdown) (X509_LOOKUP *ctx);
|
---|
| 75 | int (*ctrl) (X509_LOOKUP *ctx, int cmd, const char *argc, long argl,
|
---|
| 76 | char **ret);
|
---|
| 77 | int (*get_by_subject) (X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
|
---|
| 78 | X509_NAME *name, X509_OBJECT *ret);
|
---|
| 79 | int (*get_by_issuer_serial) (X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
|
---|
| 80 | X509_NAME *name, ASN1_INTEGER *serial,
|
---|
| 81 | X509_OBJECT *ret);
|
---|
| 82 | int (*get_by_fingerprint) (X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
|
---|
| 83 | const unsigned char *bytes, int len,
|
---|
| 84 | X509_OBJECT *ret);
|
---|
| 85 | int (*get_by_alias) (X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
|
---|
| 86 | const char *str, int len, X509_OBJECT *ret);
|
---|
| 87 | };
|
---|
| 88 |
|
---|
| 89 | /* This is the functions plus an instance of the local variables. */
|
---|
| 90 | struct x509_lookup_st {
|
---|
| 91 | int init; /* have we been started */
|
---|
| 92 | int skip; /* don't use us. */
|
---|
| 93 | X509_LOOKUP_METHOD *method; /* the functions */
|
---|
| 94 | char *method_data; /* method data */
|
---|
| 95 | X509_STORE *store_ctx; /* who owns us */
|
---|
| 96 | };
|
---|
| 97 |
|
---|
| 98 | /*
|
---|
| 99 | * This is used to hold everything. It is used for all certificate
|
---|
| 100 | * validation. Once we have a certificate chain, the 'verify' function is
|
---|
| 101 | * then called to actually check the cert chain.
|
---|
| 102 | */
|
---|
| 103 | struct x509_store_st {
|
---|
| 104 | /* The following is a cache of trusted certs */
|
---|
| 105 | int cache; /* if true, stash any hits */
|
---|
| 106 | STACK_OF(X509_OBJECT) *objs; /* Cache of all objects */
|
---|
| 107 | /* These are external lookup methods */
|
---|
| 108 | STACK_OF(X509_LOOKUP) *get_cert_methods;
|
---|
| 109 | X509_VERIFY_PARAM *param;
|
---|
| 110 | /* Callbacks for various operations */
|
---|
| 111 | /* called to verify a certificate */
|
---|
| 112 | int (*verify) (X509_STORE_CTX *ctx);
|
---|
| 113 | /* error callback */
|
---|
| 114 | int (*verify_cb) (int ok, X509_STORE_CTX *ctx);
|
---|
| 115 | /* get issuers cert from ctx */
|
---|
| 116 | int (*get_issuer) (X509 **issuer, X509_STORE_CTX *ctx, X509 *x);
|
---|
| 117 | /* check issued */
|
---|
| 118 | int (*check_issued) (X509_STORE_CTX *ctx, X509 *x, X509 *issuer);
|
---|
| 119 | /* Check revocation status of chain */
|
---|
| 120 | int (*check_revocation) (X509_STORE_CTX *ctx);
|
---|
| 121 | /* retrieve CRL */
|
---|
| 122 | int (*get_crl) (X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x);
|
---|
| 123 | /* Check CRL validity */
|
---|
| 124 | int (*check_crl) (X509_STORE_CTX *ctx, X509_CRL *crl);
|
---|
| 125 | /* Check certificate against CRL */
|
---|
| 126 | int (*cert_crl) (X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x);
|
---|
| 127 | /* Check policy status of the chain */
|
---|
| 128 | int (*check_policy) (X509_STORE_CTX *ctx);
|
---|
| 129 | STACK_OF(X509) *(*lookup_certs) (X509_STORE_CTX *ctx, X509_NAME *nm);
|
---|
| 130 | STACK_OF(X509_CRL) *(*lookup_crls) (X509_STORE_CTX *ctx, X509_NAME *nm);
|
---|
| 131 | int (*cleanup) (X509_STORE_CTX *ctx);
|
---|
| 132 | CRYPTO_EX_DATA ex_data;
|
---|
| 133 | int references;
|
---|
| 134 | CRYPTO_RWLOCK *lock;
|
---|
| 135 | };
|
---|
| 136 |
|
---|
| 137 | typedef struct lookup_dir_hashes_st BY_DIR_HASH;
|
---|
| 138 | typedef struct lookup_dir_entry_st BY_DIR_ENTRY;
|
---|
| 139 | DEFINE_STACK_OF(BY_DIR_HASH)
|
---|
| 140 | DEFINE_STACK_OF(BY_DIR_ENTRY)
|
---|
| 141 | typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY;
|
---|
| 142 | DEFINE_STACK_OF(STACK_OF_X509_NAME_ENTRY)
|
---|