Botan  2.13.0
Crypto and TLS for C++11
p11_x509.h
Go to the documentation of this file.
1 /*
2 * PKCS#11 X.509
3 * (C) 2016 Daniel Neus, Sirrix AG
4 * (C) 2016 Philipp Weber, Sirrix AG
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8 
9 #ifndef BOTAN_P11_X509_H_
10 #define BOTAN_P11_X509_H_
11 
12 #include <botan/p11_object.h>
13 
14 #if defined(BOTAN_HAS_X509_CERTIFICATES)
15 
16 #include <botan/x509cert.h>
17 #include <vector>
18 
19 namespace Botan {
20 namespace PKCS11 {
21 
22 class Session;
23 
24 /// Common attributes of all PKCS#11 X509 certificates
25 class BOTAN_PUBLIC_API(2,0) X509_CertificateProperties final : public CertificateProperties
26  {
27  public:
28  /**
29  * @param subject DER-encoding of the certificate subject name
30  * @param value BER-encoding of the certificate
31  */
32  X509_CertificateProperties(const std::vector<uint8_t>& subject, const std::vector<uint8_t>& value);
33 
34  X509_CertificateProperties(const X509_Certificate& cert) :
35  X509_CertificateProperties(cert.raw_subject_dn(), cert.BER_encode())
36  {}
37 
38  /// @param id key identifier for public/private key pair
39  inline void set_id(const std::vector<uint8_t>& id)
40  {
41  add_binary(AttributeType::Id, id);
42  }
43 
44  /// @param issuer DER-encoding of the certificate issuer name
45  inline void set_issuer(const std::vector<uint8_t>& issuer)
46  {
47  add_binary(AttributeType::Issuer, issuer);
48  }
49 
50  /// @param serial DER-encoding of the certificate serial number
51  inline void set_serial(const std::vector<uint8_t>& serial)
52  {
53  add_binary(AttributeType::SerialNumber, serial);
54  }
55 
56  /// @param hash hash value of the subject public key
57  inline void set_subject_pubkey_hash(const std::vector<uint8_t>& hash)
58  {
60  }
61 
62  /// @param hash hash value of the issuer public key
63  inline void set_issuer_pubkey_hash(const std::vector<uint8_t>& hash)
64  {
66  }
67 
68  /// @param alg defines the mechanism used to calculate `CKA_HASH_OF_SUBJECT_PUBLIC_KEY` and `CKA_HASH_OF_ISSUER_PUBLIC_KEY`
69  inline void set_hash_alg(MechanismType alg)
70  {
71  add_numeric(AttributeType::NameHashAlgorithm, static_cast<Ulong>(alg));
72  }
73 
74  /// @return the subject
75  inline const std::vector<uint8_t>& subject() const
76  {
77  return m_subject;
78  }
79 
80  /// @return the BER-encoding of the certificate
81  inline const std::vector<uint8_t>& value() const
82  {
83  return m_value;
84  }
85 
86  private:
87  const std::vector<uint8_t> m_subject;
88  const std::vector<uint8_t> m_value;
89  };
90 
91 /// Represents a PKCS#11 X509 certificate
92 class BOTAN_PUBLIC_API(2,0) PKCS11_X509_Certificate final : public Object, public X509_Certificate
93  {
94  public:
96 
97  /**
98  * Create a PKCS11_X509_Certificate object from an existing PKCS#11 X509 cert
99  * @param session the session to use
100  * @param handle the handle of the X.509 certificate
101  */
102  PKCS11_X509_Certificate(Session& session, ObjectHandle handle);
103 
104  /**
105  * Imports a X.509 certificate
106  * @param session the session to use
107  * @param props the attributes of the X.509 certificate
108  */
109  PKCS11_X509_Certificate(Session& session, const X509_CertificateProperties& props);
110  };
111 
112 }
113 }
114 
115 #endif
116 
117 #endif
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Definition: alg_id.cpp:13
CK_OBJECT_HANDLE ObjectHandle
Definition: p11.h:846
secure_vector< uint8_t > BER_encode(const Private_Key &key)
Definition: pkcs8.cpp:139
MechanismType hash