x509_local.h 6.2 KB

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