x509_lcl.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright 2014-2018 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. #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. ASN1_INTEGER *ser, 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. X509_NAME *name, X509_OBJECT *ret);
  71. int (*get_by_issuer_serial) (X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
  72. X509_NAME *name, ASN1_INTEGER *serial,
  73. X509_OBJECT *ret);
  74. int (*get_by_fingerprint) (X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
  75. const unsigned char *bytes, int len,
  76. X509_OBJECT *ret);
  77. int (*get_by_alias) (X509_LOOKUP *ctx, X509_LOOKUP_TYPE type,
  78. const char *str, int len, X509_OBJECT *ret);
  79. };
  80. /* This is the functions plus an instance of the local variables. */
  81. struct x509_lookup_st {
  82. int init; /* have we been started */
  83. int skip; /* don't use us. */
  84. X509_LOOKUP_METHOD *method; /* the functions */
  85. void *method_data; /* method data */
  86. X509_STORE *store_ctx; /* who owns us */
  87. };
  88. /*
  89. * This is used to hold everything. It is used for all certificate
  90. * validation. Once we have a certificate chain, the 'verify' function is
  91. * then called to actually check the cert chain.
  92. */
  93. struct x509_store_st {
  94. /* The following is a cache of trusted certs */
  95. int cache; /* if true, stash any hits */
  96. STACK_OF(X509_OBJECT) *objs; /* Cache of all objects */
  97. /* These are external lookup methods */
  98. STACK_OF(X509_LOOKUP) *get_cert_methods;
  99. X509_VERIFY_PARAM *param;
  100. /* Callbacks for various operations */
  101. /* called to verify a certificate */
  102. int (*verify) (X509_STORE_CTX *ctx);
  103. /* error callback */
  104. int (*verify_cb) (int ok, X509_STORE_CTX *ctx);
  105. /* get issuers cert from ctx */
  106. int (*get_issuer) (X509 **issuer, X509_STORE_CTX *ctx, X509 *x);
  107. /* check issued */
  108. int (*check_issued) (X509_STORE_CTX *ctx, X509 *x, X509 *issuer);
  109. /* Check revocation status of chain */
  110. int (*check_revocation) (X509_STORE_CTX *ctx);
  111. /* retrieve CRL */
  112. int (*get_crl) (X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x);
  113. /* Check CRL validity */
  114. int (*check_crl) (X509_STORE_CTX *ctx, X509_CRL *crl);
  115. /* Check certificate against CRL */
  116. int (*cert_crl) (X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x);
  117. /* Check policy status of the chain */
  118. int (*check_policy) (X509_STORE_CTX *ctx);
  119. STACK_OF(X509) *(*lookup_certs) (X509_STORE_CTX *ctx, X509_NAME *nm);
  120. STACK_OF(X509_CRL) *(*lookup_crls) (X509_STORE_CTX *ctx, X509_NAME *nm);
  121. int (*cleanup) (X509_STORE_CTX *ctx);
  122. CRYPTO_EX_DATA ex_data;
  123. CRYPTO_REF_COUNT references;
  124. CRYPTO_RWLOCK *lock;
  125. };
  126. typedef struct lookup_dir_hashes_st BY_DIR_HASH;
  127. typedef struct lookup_dir_entry_st BY_DIR_ENTRY;
  128. DEFINE_STACK_OF(BY_DIR_HASH)
  129. DEFINE_STACK_OF(BY_DIR_ENTRY)
  130. typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY;
  131. DEFINE_STACK_OF(STACK_OF_X509_NAME_ENTRY)
  132. void x509_set_signature_info(X509_SIG_INFO *siginf, const X509_ALGOR *alg,
  133. const ASN1_STRING *sig);