x509_local.h 6.5 KB

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