Botan  2.4.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  /// @param id key identifier for public/private key pair
35  inline void set_id(const std::vector<uint8_t>& id)
36  {
37  add_binary(AttributeType::Id, id);
38  }
39 
40  /// @param issuer DER-encoding of the certificate issuer name
41  inline void set_issuer(const std::vector<uint8_t>& issuer)
42  {
43  add_binary(AttributeType::Issuer, issuer);
44  }
45 
46  /// @param serial DER-encoding of the certificate serial number
47  inline void set_serial(const std::vector<uint8_t>& serial)
48  {
49  add_binary(AttributeType::SerialNumber, serial);
50  }
51 
52  /// @param hash hash value of the subject public key
53  inline void set_subject_pubkey_hash(const std::vector<uint8_t>& hash)
54  {
55  add_binary(AttributeType::HashOfSubjectPublicKey, hash);
56  }
57 
58  /// @param hash hash value of the issuer public key
59  inline void set_issuer_pubkey_hash(const std::vector<uint8_t>& hash)
60  {
61  add_binary(AttributeType::HashOfIssuerPublicKey, hash);
62  }
63 
64  /// @param alg defines the mechanism used to calculate `CKA_HASH_OF_SUBJECT_PUBLIC_KEY` and `CKA_HASH_OF_ISSUER_PUBLIC_KEY`
65  inline void set_hash_alg(MechanismType alg)
66  {
67  add_numeric(AttributeType::NameHashAlgorithm, static_cast<Ulong>(alg));
68  }
69 
70  /// @return the subject
71  inline const std::vector<uint8_t>& subject() const
72  {
73  return m_subject;
74  }
75 
76  /// @return the BER-encoding of the certificate
77  inline const std::vector<uint8_t>& value() const
78  {
79  return m_value;
80  }
81 
82  private:
83  const std::vector<uint8_t> m_subject;
84  const std::vector<uint8_t> m_value;
85  };
86 
87 /// Represents a PKCS#11 X509 certificate
88 class BOTAN_PUBLIC_API(2,0) PKCS11_X509_Certificate final : public Object, public X509_Certificate
89  {
90  public:
92 
93  /**
94  * Create a PKCS11_X509_Certificate object from an existing PKCS#11 X509 cert
95  * @param session the session to use
96  * @param handle the handle of the X.509 certificate
97  */
98  PKCS11_X509_Certificate(Session& session, ObjectHandle handle);
99 
100  /**
101  * Imports a X.509 certificate
102  * @param session the session to use
103  * @param props the attributes of the X.509 certificate
104  */
105  PKCS11_X509_Certificate(Session& session, const X509_CertificateProperties& props);
106  };
107 
108 }
109 }
110 
111 #endif
112 
113 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: alg_id.cpp:13
CK_OBJECT_HANDLE ObjectHandle
Definition: p11.h:846
MechanismType hash