Botan 3.14.1
Crypto and TLS for C&
p11_object.h
Go to the documentation of this file.
1/*
2* PKCS#11 Object
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_OBJECT_H_
10#define BOTAN_P11_OBJECT_H_
11
12#include <botan/p11.h>
13#include <botan/p11_types.h>
14#include <botan/secmem.h>
15
16#include <concepts>
17#include <functional>
18#include <list>
19#include <string>
20#include <utility>
21#include <vector>
22
23namespace Botan::PKCS11 {
24
25class Module;
26
27/// Helper class to build the Attribute / CK_ATTRIBUTE structures
29 public:
30 AttributeContainer() = default;
31
32 /// @param object_class the class type of this container
34
35 virtual ~AttributeContainer() = default;
36
39
40 // Warning when implementing copy/assignment: m_attributes contains pointers to the other members which must be updated after a copy
41 AttributeContainer(const AttributeContainer& other) = delete;
43
44 /// @return the attributes this container contains
45 inline const std::vector<Attribute>& attributes() const { return m_attributes; }
46
47 /// @return raw attribute data
48 inline Attribute* data() const { return const_cast<Attribute*>(m_attributes.data()); }
49
50 /// @return the number of attributes in this container
51 inline size_t count() const { return m_attributes.size(); }
52
53 /**
54 * Add a class attribute (CKA_CLASS / AttributeType::Class).
55 * @param object_class class attribute to add
56 */
57 void add_class(ObjectClass object_class);
58
59 /**
60 * Add a string attribute (e.g. CKA_LABEL / AttributeType::Label).
61 * @param attribute attribute type
62 * @param value string value to add
63 */
64 void add_string(AttributeType attribute, std::string_view value);
65
66 /**
67 * Add a binary attribute (e.g. CKA_ID / AttributeType::Id).
68 * @param attribute attribute type
69 * @param value binary attribute value to add
70 * @param length size of the binary attribute value in bytes
71 */
72 void add_binary(AttributeType attribute, const uint8_t* value, size_t length);
73
74 /**
75 * Add a binary attribute (e.g. CKA_ID / AttributeType::Id).
76 * @param attribute attribute type
77 * @param binary binary attribute value to add
78 */
79 template <typename TAlloc>
80 void add_binary(AttributeType attribute, const std::vector<uint8_t, TAlloc>& binary) {
81 add_binary(attribute, binary.data(), binary.size());
82 }
83
84 /**
85 * Add a bool attribute (e.g. CKA_SENSITIVE / AttributeType::Sensitive).
86 * @param attribute attribute type
87 * @param value boolean value to add
88 */
89 void add_bool(AttributeType attribute, bool value);
90
91 /**
92 * Add a numeric attribute (e.g. CKA_MODULUS_BITS / AttributeType::ModulusBits).
93 * The value is always passed to the module as a CK_ULONG.
94 * @param attribute attribute type
95 * @param value numeric value to add
96 */
97 template <std::integral T>
98 void add_numeric(AttributeType attribute, T value) {
99 if(!std::in_range<Ulong>(value)) {
100 throw Invalid_Argument("PKCS #11 numeric attribute value exceeds CK_ULONG range");
101 }
102 add_ulong(attribute, static_cast<Ulong>(value));
103 }
104
105 protected:
106 /// Add an attribute with the given value and size to the attribute collection `m_attributes`
107 void add_attribute(AttributeType attribute, const uint8_t* value, Ulong size);
108
109 private:
110 void add_ulong(AttributeType attribute, Ulong value);
111
112 std::vector<Attribute> m_attributes;
113 std::list<Ulong> m_numerics;
114 std::list<Bbool> m_bools;
115 std::list<std::string> m_strings;
116 std::list<secure_vector<uint8_t>> m_vectors;
117};
118
119/// Manages calls to C_FindObjects* functions (C_FindObjectsInit -> C_FindObjects -> C_FindObjectsFinal)
121 public:
122 /**
123 * Initializes a search for token and session objects that match a template (calls C_FindObjectsInit)
124 * @param session the session to use for the search
125 * @param search_template the search_template as a vector of `Attribute`
126 */
127 ObjectFinder(Session& session, const std::vector<Attribute>& search_template);
128
129 ObjectFinder(const ObjectFinder& other) = delete;
130 ObjectFinder& operator=(const ObjectFinder& other) = delete;
131
132 ObjectFinder(ObjectFinder&& other) noexcept :
133 m_session(other.m_session), m_search_terminated(other.m_search_terminated) {
134 other.m_search_terminated = true;
135 }
136
138
139 /// Terminates a search for token and session objects (calls C_FindObjectsFinal)
140 ~ObjectFinder() noexcept;
141
142 /**
143 * Starts or continues a search for token and session objects that match a template, obtaining additional object handles (calls C_FindObjects)
144 * @param max_count maximum amount of object handles to retrieve. Default = 100
145 * @return the result of the search as a vector of `ObjectHandle`
146 */
147 std::vector<ObjectHandle> find(std::uint32_t max_count = 100) const;
148
149 /// Finishes the search operation manually to allow a new ObjectFinder to exist
150 void finish();
151
152 /// @return the module this `ObjectFinder` belongs to
153 inline Module& module() const { return m_session.get().module(); }
154
155 private:
156 const std::reference_wrapper<Session> m_session;
157 bool m_search_terminated;
158};
159
160/// Common attributes of all objects
162 public:
163 /// @param object_class the object class of the object
165
166 /// @return the object class of this object
167 inline ObjectClass object_class() const { return m_object_class; }
168
169 private:
170 const ObjectClass m_object_class;
171};
172
173/// Common attributes of all storage objects
175 public:
176 /// @param object_class the CK_OBJECT_CLASS this storage object belongs to
178
179 /// @param label description of the object (RFC2279 string)
180 inline void set_label(std::string_view label) { add_string(AttributeType::Label, label); }
181
182 /// @param value if true the object is a token object; otherwise the object is a session object
183 inline void set_token(bool value) { add_bool(AttributeType::Token, value); }
184
185 /**
186 * @param value if true the object is a private object; otherwise the object is a public object
187 * When private, a user may not access the object until the user has been authenticated to the token
188 */
189 inline void set_private(bool value) { add_bool(AttributeType::Private, value); }
190
191 /// @param value if true the object can be modified, otherwise it is read-only
193
194 /// @param value if true the object can be copied using C_CopyObject
195 void set_copyable(bool value) { add_bool(AttributeType::Copyable, value); }
196
197 /// @param value if true the object can be destroyed using C_DestroyObject
199};
200
201/// Common attributes of all data objects
203 public:
205
206 /// @param value description of the application that manages the object (RFC2279 string)
207 inline void set_application(std::string_view value) { add_string(AttributeType::Application, value); }
208
209 /// @param object_id DER-encoding of the object identifier indicating the data object type
210 inline void set_object_id(const std::vector<uint8_t>& object_id) {
212 }
213
214 /// @param value value of the object
216};
217
218/// Common attributes of all certificate objects
220 public:
221 /// @param cert_type type of certificate
223
224 /// @param value the certificate can be trusted for the application that it was created (can only be set to true by SO user)
225 inline void set_trusted(bool value) { add_bool(AttributeType::Trusted, value); }
226
227 /// @param category one of `CertificateCategory`
231
232 /**
233 * @param checksum the value of this attribute is derived from the certificate by taking the
234 * first three bytes of the SHA - 1 hash of the certificate object's `CKA_VALUE` attribute
235 */
236 inline void set_check_value(const std::vector<uint8_t>& checksum) {
238 }
239
240 /// @param date start date for the certificate
241 inline void set_start_date(Date date) {
242 add_binary(AttributeType::StartDate, reinterpret_cast<uint8_t*>(&date), sizeof(Date));
243 }
244
245 /// @param date end date for the certificate
246 inline void set_end_date(Date date) {
247 add_binary(AttributeType::EndDate, reinterpret_cast<uint8_t*>(&date), sizeof(Date));
248 }
249
250 /// @param pubkey_info DER-encoding of the SubjectPublicKeyInfo for the public key contained in this certificate
251 inline void set_public_key_info(const std::vector<uint8_t>& pubkey_info) {
253 }
254
255 /// @return the certificate type of this certificate object
256 inline CertificateType cert_type() const { return m_cert_type; }
257
258 private:
259 const CertificateType m_cert_type;
260};
261
262/// Common attributes of all key objects
264 public:
265 /**
266 * @param object_class the `CK_OBJECT_CLASS` this key object belongs to
267 * @param key_type type of key
268 */
270
271 /// @param id key identifier for key
272 inline void set_id(const std::vector<uint8_t>& id) { add_binary(AttributeType::Id, id); }
273
274 /// @param date start date for the key
275 inline void set_start_date(Date date) {
276 add_binary(AttributeType::StartDate, reinterpret_cast<uint8_t*>(&date), sizeof(Date));
277 }
278
279 /// @param date end date for the key
280 inline void set_end_date(Date date) {
281 add_binary(AttributeType::EndDate, reinterpret_cast<uint8_t*>(&date), sizeof(Date));
282 }
283
284 /// @param value true if key supports key derivation (i.e., if other keys can be derived from this one)
285 inline void set_derive(bool value) { add_bool(AttributeType::Derive, value); }
286
287 /**
288 * Sets a list of mechanisms allowed to be used with this key
289 * Not implemented
290 * TODO(Botan4) remove this
291 */
293 const std::vector<MechanismType>& /*mechanisms*/) { // NOLINT(*-convert-member-functions-to-static)
294 throw Not_Implemented("KeyProperties::set_allowed_mechanisms");
295 }
296
297 /// @return the key type of this key object
298 inline KeyType key_type() const { return m_key_type; }
299
300 private:
301 const KeyType m_key_type;
302};
303
304/// Common attributes of all public key objects
306 public:
307 /// @param key_type type of key
309
310 /// @param subject DER-encoding of the key subject name
311 inline void set_subject(const std::vector<uint8_t>& subject) { add_binary(AttributeType::Subject, subject); }
312
313 /// @param value true if the key supports encryption
314 inline void set_encrypt(bool value) { add_bool(AttributeType::Encrypt, value); }
315
316 /// @param value true if the key supports verification where the signature is an appendix to the data
317 inline void set_verify(bool value) { add_bool(AttributeType::Verify, value); }
318
319 /// @param value true if the key supports verification where the data is recovered from the signature
320 inline void set_verify_recover(bool value) { add_bool(AttributeType::VerifyRecover, value); }
321
322 /// @param value true if the key supports wrapping (i.e., can be used to wrap other keys)
323 inline void set_wrap(bool value) { add_bool(AttributeType::Wrap, value); }
324
325 /**
326 * @param value true if the key can be trusted for the application that it was created.
327 * The wrapping key can be used to wrap keys with `CKA_WRAP_WITH_TRUSTED` set to `CK_TRUE`
328 */
329 inline void set_trusted(bool value) { add_bool(AttributeType::Trusted, value); }
330
331 /**
332 * For wrapping keys
333 * The attribute template to match against any keys wrapped using this wrapping key.
334 * Keys that do not match cannot be wrapped
335 * Not implemented
336 * TODO(Botan4) remove this function
337 */
338 inline void set_wrap_template(
339 const AttributeContainer& /*unused*/) { // NOLINT(*-convert-member-functions-to-static)
340 throw Not_Implemented("PublicKeyProperties::set_wrap_template");
341 }
342
343 /// @param pubkey_info DER-encoding of the SubjectPublicKeyInfo for this public key
344 inline void set_public_key_info(const std::vector<uint8_t>& pubkey_info) {
346 }
347};
348
349/// Common attributes of all private keys
351 public:
352 /// @param key_type type of key
354
355 /// @param subject DER-encoding of the key subject name
356 inline void set_subject(const std::vector<uint8_t>& subject) { add_binary(AttributeType::Subject, subject); }
357
358 /// @param value true if the key is sensitive
359 inline void set_sensitive(bool value) { add_bool(AttributeType::Sensitive, value); }
360
361 /// @param value true if the key supports decryption
362 inline void set_decrypt(bool value) { add_bool(AttributeType::Decrypt, value); }
363
364 /// @param value true if the key supports signatures where the signature is an appendix to the data
365 inline void set_sign(bool value) { add_bool(AttributeType::Sign, value); }
366
367 /// @param value true if the key supports signatures where the data can be recovered from the signature
368 inline void set_sign_recover(bool value) { add_bool(AttributeType::SignRecover, value); }
369
370 /// @param value true if the key supports unwrapping (i.e., can be used to unwrap other keys)
371 inline void set_unwrap(bool value) { add_bool(AttributeType::Unwrap, value); }
372
373 /// @param value true if the key is extractable and can be wrapped
374 inline void set_extractable(bool value) { add_bool(AttributeType::Extractable, value); }
375
376 /// @param value true if the key can only be wrapped with a wrapping key that has `CKA_TRUSTED` set to `CK_TRUE`
378
379 /// @param value If true, the user has to supply the PIN for each use (sign or decrypt) with the key
381
382 /**
383 * For wrapping keys
384 * The attribute template to apply to any keys unwrapped using this wrapping key.
385 * Any user supplied template is applied after this template as if the object has already been created
386 * Not implemented
387 * TODO(Botan4) remove this function
388 */
390 const AttributeContainer& /*unused*/) { // NOLINT(*-convert-member-functions-to-static)
391 throw Not_Implemented("PrivateKeyProperties::set_unwrap_template");
392 }
393
394 /// @param pubkey_info DER-encoding of the SubjectPublicKeyInfo for this public key
395 inline void set_public_key_info(const std::vector<uint8_t>& pubkey_info) {
397 }
398};
399
400/// Common attributes of all secret (symmetric) keys
402 public:
403 /// @param key_type type of key
405
406 /// @param value true if the key is sensitive
407 inline void set_sensitive(bool value) { add_bool(AttributeType::Sensitive, value); }
408
409 /// @param value true if the key supports encryption
410 inline void set_encrypt(bool value) { add_bool(AttributeType::Encrypt, value); }
411
412 /// @param value true if the key supports decryption
413 inline void set_decrypt(bool value) { add_bool(AttributeType::Decrypt, value); }
414
415 /// @param value true if the key supports signatures where the signature is an appendix to the data
416 inline void set_sign(bool value) { add_bool(AttributeType::Sign, value); }
417
418 /// @param value true if the key supports verification where the signature is an appendix to the data
419 inline void set_verify(bool value) { add_bool(AttributeType::Verify, value); }
420
421 /// @param value true if the key supports unwrapping (i.e., can be used to unwrap other keys)
422 inline void set_unwrap(bool value) { add_bool(AttributeType::Unwrap, value); }
423
424 /// @param value true if the key is extractable and can be wrapped
425 inline void set_extractable(bool value) { add_bool(AttributeType::Extractable, value); }
426
427 /// @param value true if the key can only be wrapped with a wrapping key that has `CKA_TRUSTED` set to `CK_TRUE`
429
430 /// @param value if true, the user has to supply the PIN for each use (sign or decrypt) with the key
432
433 /// @param value true if the key supports wrapping (i.e., can be used to wrap other keys)
434 inline void set_wrap(bool value) { add_bool(AttributeType::Wrap, value); }
435
436 /**
437 * @param value the key can be trusted for the application that it was created.
438 * The wrapping key can be used to wrap keys with `CKA_WRAP_WITH_TRUSTED` set to `CK_TRUE`
439 */
440 inline void set_trusted(bool value) { add_bool(AttributeType::Trusted, value); }
441
442 /// @param checksum the key check value of this key
443 inline void set_check_value(const std::vector<uint8_t>& checksum) {
445 }
446
447 /**
448 * For wrapping keys
449 * The attribute template to match against any keys wrapped using this wrapping key.
450 * Keys that do not match cannot be wrapped
451 * Not implemented
452 * TODO(Botan4) remove this function
453 */
454 inline void set_wrap_template(
455 const AttributeContainer& /*unused*/) { // NOLINT(*-convert-member-functions-to-static)
456 throw Not_Implemented("SecretKeyProperties::set_wrap_template");
457 }
458
459 /**
460 * For wrapping keys
461 * The attribute template to apply to any keys unwrapped using this wrapping key
462 * Any user supplied template is applied after this template as if the object has already been created
463 * Not Implemented
464 * TODO(Botan4) remove this function
465 */
467 const AttributeContainer& /*unused*/) { // NOLINT(*-convert-member-functions-to-static)
468 throw Not_Implemented("SecretKeyProperties::set_unwrap_template");
469 }
470};
471
472/// Common attributes of domain parameter
474 public:
475 /// @param key_type type of key the domain parameters can be used to generate
477
478 /// @return the key type
479 inline KeyType key_type() const { return m_key_type; }
480
481 private:
482 const KeyType m_key_type;
483};
484
485/**
486* Represents a PKCS#11 object.
487*/
489 public:
490 /**
491 * Creates an `Object` from an existing PKCS#11 object
492 * @param session the session the object belongs to
493 * @param handle handle of the object
494 */
495
497
498 /**
499 * Creates the object
500 * @param session the session in which the object should be created
501 * @param obj_props properties of this object
502 */
503 Object(Session& session, const ObjectProperties& obj_props);
504
505 Object(const Object&) = default;
506 Object(Object&&) = default;
507 Object& operator=(const Object&) = delete;
508 Object& operator=(Object&&) = delete;
509
510 virtual ~Object() = default;
511
512 /// Searches for all objects of the given type that match `search_template`
513 template <typename T>
514 static std::vector<T> search(Session& session, const std::vector<Attribute>& search_template);
515
516 /// Searches for all objects of the given type using the label (`CKA_LABEL`)
517 template <typename T>
518 static std::vector<T> search(Session& session, std::string_view label);
519
520 /// Searches for all objects of the given type using the id (`CKA_ID`)
521 template <typename T>
522 static std::vector<T> search(Session& session, const std::vector<uint8_t>& id);
523
524 /// Searches for all objects of the given type using the label (`CKA_LABEL`) and id (`CKA_ID`)
525 template <typename T>
526 static std::vector<T> search(Session& session, std::string_view label, const std::vector<uint8_t>& id);
527
528 /// Searches for all objects of the given type
529 template <typename T>
530 static std::vector<T> search(Session& session);
531
532 /// @returns the value of the given attribute (using `C_GetAttributeValue`)
534
535 /// Sets the given value for the attribute (using `C_SetAttributeValue`)
536 void set_attribute_value(AttributeType attribute, const secure_vector<uint8_t>& value) const;
537
538 /**
539 * Destroys the object
540 *
541 * Afterwards handle() returns CK_INVALID_HANDLE. Copies of this object
542 * made earlier still hold the old handle and must no longer be used.
543 */
544 void destroy() const;
545
546 /**
547 * Copies the object
548 * @param modified_attributes the attributes of the copied object
549 */
550 ObjectHandle copy(const AttributeContainer& modified_attributes) const;
551
552 /// @return the handle of this object.
553 inline ObjectHandle handle() const { return m_handle; }
554
555 /// @return the session this objects belongs to
556 inline Session& session() const { return m_session; }
557
558 /// @return the module this object belongs to
559 inline Module& module() const { return m_session.get().module(); }
560
561 protected:
562 explicit Object(Session& session) : m_session(session) {}
563
564 /// The search template matching all objects of type T
565 template <typename T>
567 AttributeContainer search_template(T::Class);
568 // Several key types share an object class, so the key type is required as well
569 if constexpr(requires { T::Key_Type; }) {
570 search_template.add_numeric(AttributeType::KeyType, static_cast<CK_KEY_TYPE>(T::Key_Type));
571 }
572 return search_template;
573 }
574
576 if(m_handle != CK_INVALID_HANDLE) {
577 throw Invalid_Argument("Cannot reset handle on already valid PKCS11 object");
578 }
579 m_handle = handle;
580 }
581
582 private:
583 const std::reference_wrapper<Session> m_session;
584 // mutable since destroy() is const
585 mutable ObjectHandle m_handle = CK_INVALID_HANDLE;
586};
587
588template <typename T>
589std::vector<T> Object::search(Session& session, const std::vector<Attribute>& search_template) {
590 const ObjectFinder finder(session, search_template);
591 std::vector<T> result;
592 // C_FindObjects returns up to the requested batch; the search is exhausted
593 // when a call yields zero handles. Loop until then so callers see all matches.
594 for(;;) {
595 const std::vector<ObjectHandle> handles = finder.find();
596 if(handles.empty()) {
597 break;
598 }
599 result.reserve(result.size() + handles.size());
600 for(const auto& handle : handles) {
601 result.emplace_back(T(session, handle));
602 }
603 }
604 return result;
605}
606
607template <typename T>
608std::vector<T> Object::search(Session& session, std::string_view label) {
609 AttributeContainer search_template = search_template_for<T>();
610 search_template.add_string(AttributeType::Label, label);
611 return search<T>(session, search_template.attributes());
612}
613
614template <typename T>
615std::vector<T> Object::search(Session& session, const std::vector<uint8_t>& id) {
616 AttributeContainer search_template = search_template_for<T>();
617 search_template.add_binary(AttributeType::Id, id);
618 return search<T>(session, search_template.attributes());
619}
620
621template <typename T>
622std::vector<T> Object::search(Session& session, std::string_view label, const std::vector<uint8_t>& id) {
623 AttributeContainer search_template = search_template_for<T>();
624 search_template.add_string(AttributeType::Label, label);
625 search_template.add_binary(AttributeType::Id, id);
626 return search<T>(session, search_template.attributes());
627}
628
629template <typename T>
631 return search<T>(session, search_template_for<T>().attributes());
632}
633
634} // namespace Botan::PKCS11
635
636#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
#define BOTAN_FUTURE_EXPLICIT
Definition api.h:52
Helper class to build the Attribute / CK_ATTRIBUTE structures.
Definition p11_object.h:28
AttributeContainer & operator=(const AttributeContainer &other)=delete
AttributeContainer & operator=(AttributeContainer &&other)=default
virtual ~AttributeContainer()=default
void add_numeric(AttributeType attribute, T value)
Definition p11_object.h:98
void add_bool(AttributeType attribute, bool value)
AttributeContainer(AttributeContainer &&other)=default
const std::vector< Attribute > & attributes() const
Definition p11_object.h:45
void add_binary(AttributeType attribute, const std::vector< uint8_t, TAlloc > &binary)
Definition p11_object.h:80
void add_string(AttributeType attribute, std::string_view value)
void add_binary(AttributeType attribute, const uint8_t *value, size_t length)
AttributeContainer(const AttributeContainer &other)=delete
void set_public_key_info(const std::vector< uint8_t > &pubkey_info)
Definition p11_object.h:251
BOTAN_FUTURE_EXPLICIT CertificateProperties(CertificateType cert_type)
void set_check_value(const std::vector< uint8_t > &checksum)
Definition p11_object.h:236
CertificateType cert_type() const
Definition p11_object.h:256
void set_category(CertificateCategory category)
Definition p11_object.h:228
void set_application(std::string_view value)
Definition p11_object.h:207
void set_value(const secure_vector< uint8_t > &value)
Definition p11_object.h:215
void set_object_id(const std::vector< uint8_t > &object_id)
Definition p11_object.h:210
BOTAN_FUTURE_EXPLICIT DomainParameterProperties(KeyType key_type)
void set_derive(bool value)
Definition p11_object.h:285
void set_id(const std::vector< uint8_t > &id)
Definition p11_object.h:272
void set_start_date(Date date)
Definition p11_object.h:275
void set_end_date(Date date)
Definition p11_object.h:280
void set_allowed_mechanisms(const std::vector< MechanismType > &)
Definition p11_object.h:292
KeyProperties(ObjectClass object_class, KeyType key_type)
Manages calls to C_FindObjects* functions (C_FindObjectsInit -> C_FindObjects -> C_FindObjectsFinal).
Definition p11_object.h:120
std::vector< ObjectHandle > find(std::uint32_t max_count=100) const
ObjectFinder & operator=(ObjectFinder &&other)=delete
Module & module() const
Definition p11_object.h:153
void finish()
Finishes the search operation manually to allow a new ObjectFinder to exist.
ObjectFinder(ObjectFinder &&other) noexcept
Definition p11_object.h:132
ObjectFinder & operator=(const ObjectFinder &other)=delete
ObjectFinder(const ObjectFinder &other)=delete
ObjectFinder(Session &session, const std::vector< Attribute > &search_template)
Common attributes of all objects.
Definition p11_object.h:161
ObjectClass object_class() const
Definition p11_object.h:167
BOTAN_FUTURE_EXPLICIT ObjectProperties(ObjectClass object_class)
void reset_handle(ObjectHandle handle)
Definition p11_object.h:575
Module & module() const
Definition p11_object.h:559
static std::vector< T > search(Session &session, const std::vector< Attribute > &search_template)
Searches for all objects of the given type that match search_template.
Definition p11_object.h:589
Object(Object &&)=default
Object & operator=(const Object &)=delete
static AttributeContainer search_template_for()
The search template matching all objects of type T.
Definition p11_object.h:566
ObjectHandle handle() const
Definition p11_object.h:553
virtual ~Object()=default
Session & session() const
Definition p11_object.h:556
Object & operator=(Object &&)=delete
secure_vector< uint8_t > get_attribute_value(AttributeType attribute) const
Object(Session &session, ObjectHandle handle)
void set_attribute_value(AttributeType attribute, const secure_vector< uint8_t > &value) const
Sets the given value for the attribute (using C_SetAttributeValue).
Object(const Object &)=default
Object(Session &session)
Definition p11_object.h:562
ObjectHandle copy(const AttributeContainer &modified_attributes) const
BOTAN_FUTURE_EXPLICIT PrivateKeyProperties(KeyType key_type)
void set_subject(const std::vector< uint8_t > &subject)
Definition p11_object.h:356
void set_always_authenticate(bool value)
Definition p11_object.h:380
void set_unwrap_template(const AttributeContainer &)
Definition p11_object.h:389
void set_public_key_info(const std::vector< uint8_t > &pubkey_info)
Definition p11_object.h:395
BOTAN_FUTURE_EXPLICIT PublicKeyProperties(KeyType key_type)
void set_public_key_info(const std::vector< uint8_t > &pubkey_info)
Definition p11_object.h:344
void set_subject(const std::vector< uint8_t > &subject)
Definition p11_object.h:311
void set_wrap_template(const AttributeContainer &)
Definition p11_object.h:338
void set_check_value(const std::vector< uint8_t > &checksum)
Definition p11_object.h:443
void set_unwrap_template(const AttributeContainer &)
Definition p11_object.h:466
void set_wrap_template(const AttributeContainer &)
Definition p11_object.h:454
BOTAN_FUTURE_EXPLICIT SecretKeyProperties(KeyType key_type)
void set_wrap_with_trusted(bool value)
Definition p11_object.h:428
void set_always_authenticate(bool value)
Definition p11_object.h:431
Represents a PKCS#11 session.
Definition p11_types.h:139
void set_label(std::string_view label)
Definition p11_object.h:180
BOTAN_FUTURE_EXPLICIT StorageObjectProperties(ObjectClass object_class)
AttributeType
Definition p11.h:50
CertificateType
Definition p11.h:213
CK_OBJECT_HANDLE ObjectHandle
Definition p11.h:1214
CK_ATTRIBUTE Attribute
Definition p11.h:1213
CK_DATE Date
Definition p11.h:1219
CK_ULONG Ulong
Definition p11.h:1204
CertificateCategory
Definition p11.h:222
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
#define CK_INVALID_HANDLE
Definition pkcs11.h:35
CK_ULONG CK_CERTIFICATE_CATEGORY
Definition pkcs11.h:45
CK_ULONG CK_KEY_TYPE
Definition pkcs11.h:55