Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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/build.h>
13 #if defined(BOTAN_HAS_X509_CERTIFICATES)
14
15 #include <botan/p11_object.h>
16
17 #include <botan/x509cert.h>
18
19 #include <vector>
20
21 namespace Botan {
22 namespace PKCS11 {
23
24 class Session;
25
26 /// Common attributes of all PKCS#11 X509 certificates
27 class BOTAN_DLL X509_CertificateProperties final : public CertificateProperties
28 {
29 public:
30 /**
31 * @param subject DER-encoding of the certificate subject name
32 * @param value BER-encoding of the certificate
33 */
34 X509_CertificateProperties(const std::vector<uint8_t>& subject, const std::vector<uint8_t>& value);
35
36 /// @param id key identifier for public/private key pair
37 inline void set_id(const std::vector<uint8_t>& id)
38 {
39 add_binary(AttributeType::Id, id);
40 }
41
42 /// @param issuer DER-encoding of the certificate issuer name
43 inline void set_issuer(const std::vector<uint8_t>& issuer)
44 {
45 add_binary(AttributeType::Issuer, issuer);
46 }
47
48 /// @param serial DER-encoding of the certificate serial number
49 inline void set_serial(const std::vector<uint8_t>& serial)
50 {
51 add_binary(AttributeType::SerialNumber, serial);
52 }
53
54 /// @param hash hash value of the subject public key
55 inline void set_subject_pubkey_hash(const std::vector<uint8_t>& hash)
56 {
57 add_binary(AttributeType::HashOfSubjectPublicKey, hash);
58 }
59
60 /// @param hash hash value of the issuer public key
61 inline void set_issuer_pubkey_hash(const std::vector<uint8_t>& hash)
62 {
63 add_binary(AttributeType::HashOfIssuerPublicKey, hash);
64 }
65
66 /// @param alg defines the mechanism used to calculate `CKA_HASH_OF_SUBJECT_PUBLIC_KEY` and `CKA_HASH_OF_ISSUER_PUBLIC_KEY`
67 inline void set_hash_alg(MechanismType alg)
68 {
69 add_numeric(AttributeType::NameHashAlgorithm, static_cast<Ulong>(alg));
70 }
71
72 /// @return the subject
73 inline const std::vector<uint8_t>& subject() const
74 {
75 return m_subject;
76 }
77
78 /// @return the BER-encoding of the certificate
79 inline const std::vector<uint8_t>& value() const
80 {
81 return m_value;
82 }
83
84 private:
85 const std::vector<uint8_t> m_subject;
86 const std::vector<uint8_t> m_value;
87 };
88
89 /// Represents a PKCS#11 X509 certificate
90 class BOTAN_DLL PKCS11_X509_Certificate final : public Object, public X509_Certificate
91 {
92 public:
93 static const ObjectClass Class = ObjectClass::Certificate;
94
95 /**
96 * Create a PKCS11_X509_Certificate object from an existing PKCS#11 X509 cert
97 * @param session the session to use
98 * @param handle the handle of the X.509 certificate
99 */
100 PKCS11_X509_Certificate(Session& session, ObjectHandle handle);
101
102 /**
103 * Imports a X.509 certificate
104 * @param session the session to use
105 * @param props the attributes of the X.509 certificate
106 */
107 PKCS11_X509_Certificate(Session& session, const X509_CertificateProperties& props);
108 };
109
110 }
111 }
112
113 #endif
114
115 #endif
Botan::PKCS11::AttributeType::SerialNumber
Botan::PKCS11::ObjectClass
ObjectClass
Definition: p11.h:678
Botan::PKCS11::AttributeType::MechanismType
Botan::PKCS11::AttributeType::HashOfIssuerPublicKey
Botan::PKCS11::AttributeType::Class
Botan::PKCS11::AttributeType::Issuer
Botan
Definition: alg_id.cpp:13
Botan::PKCS11::ObjectHandle
CK_OBJECT_HANDLE ObjectHandle
Definition: p11.h:846
Botan::PKCS11::ObjectClass::Certificate
Botan::PKCS11::AttributeType::HashOfSubjectPublicKey
Botan::PKCS11::AttributeType::Id
hash
MechanismType hash
Definition: p11_mechanism.cpp:63
Botan::PKCS11::AttributeType::NameHashAlgorithm