Botan 3.4.0
Crypto and TLS for C&
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
19namespace Botan::PKCS11 {
20
21class Session;
22
23/// Common attributes of all PKCS#11 X509 certificates
24class BOTAN_PUBLIC_API(2, 0) X509_CertificateProperties final : public CertificateProperties {
25 public:
26 /**
27 * @param subject DER-encoding of the certificate subject name
28 * @param value BER-encoding of the certificate
29 */
30 X509_CertificateProperties(const std::vector<uint8_t>& subject, const std::vector<uint8_t>& value);
31
32 X509_CertificateProperties(const X509_Certificate& cert) :
33 X509_CertificateProperties(cert.raw_subject_dn(), cert.BER_encode()) {}
34
35 /// @param id key identifier for public/private key pair
36 inline void set_id(const std::vector<uint8_t>& id) { add_binary(AttributeType::Id, id); }
37
38 /// @param issuer DER-encoding of the certificate issuer name
39 inline void set_issuer(const std::vector<uint8_t>& issuer) { add_binary(AttributeType::Issuer, issuer); }
40
41 /// @param serial DER-encoding of the certificate serial number
42 inline void set_serial(const std::vector<uint8_t>& serial) { add_binary(AttributeType::SerialNumber, serial); }
43
44 /// @param hash hash value of the subject public key
45 inline void set_subject_pubkey_hash(const std::vector<uint8_t>& hash) {
46 add_binary(AttributeType::HashOfSubjectPublicKey, hash);
47 }
48
49 /// @param hash hash value of the issuer public key
50 inline void set_issuer_pubkey_hash(const std::vector<uint8_t>& hash) {
51 add_binary(AttributeType::HashOfIssuerPublicKey, hash);
52 }
53
54 /// @param alg defines the mechanism used to calculate `CKA_HASH_OF_SUBJECT_PUBLIC_KEY` and `CKA_HASH_OF_ISSUER_PUBLIC_KEY`
55 inline void set_hash_alg(MechanismType alg) {
56 add_numeric(AttributeType::NameHashAlgorithm, static_cast<Ulong>(alg));
57 }
58
59 /// @return the subject
60 inline const std::vector<uint8_t>& subject() const { return m_subject; }
61
62 /// @return the BER-encoding of the certificate
63 inline const std::vector<uint8_t>& value() const { return m_value; }
64
65 private:
66 const std::vector<uint8_t> m_subject;
67 const std::vector<uint8_t> m_value;
68};
69
70/// Represents a PKCS#11 X509 certificate
71class BOTAN_PUBLIC_API(2, 0) PKCS11_X509_Certificate final : public Object,
72 public X509_Certificate {
73 public:
74 static const ObjectClass Class = ObjectClass::Certificate;
75
76 /**
77 * Create a PKCS11_X509_Certificate object from an existing PKCS#11 X509 cert
78 * @param session the session to use
79 * @param handle the handle of the X.509 certificate
80 */
81 PKCS11_X509_Certificate(Session& session, ObjectHandle handle);
82
83 /**
84 * Imports a X.509 certificate
85 * @param session the session to use
86 * @param props the attributes of the X.509 certificate
87 */
88 PKCS11_X509_Certificate(Session& session, const X509_CertificateProperties& props);
89};
90
91} // namespace Botan::PKCS11
92
93#endif
94
95#endif
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition compiler.h:31
CK_ULONG Ulong
Definition p11.h:814
std::vector< uint8_t > BER_encode(const Private_Key &key, RandomNumberGenerator &rng, std::string_view pass, std::chrono::milliseconds msec, std::string_view pbe_algo)
Definition pkcs8.cpp:163