|
Botan 3.13.0
Crypto and TLS for C&
|
#include <pkcs12.h>
Public Member Functions | |
| void | add_certificate (X509_Certificate cert) |
| void | add_key (std::shared_ptr< Private_Key > key) |
| Add a private key. PKCS#12 supports multiple keys per file. | |
| std::vector< X509_Certificate > | ca_certificates () const |
| const std::vector< X509_Certificate > & | certificates () const |
| void | clear_friendly_name () |
| Clear the friendly-name attribute. | |
| void | clear_local_key_id () |
| Clear the localKeyId attribute. | |
| std::optional< X509_Certificate > | end_entity_certificate () const |
| std::vector< uint8_t > | export_to (const PKCS12_Export_Options &options, RandomNumberGenerator &rng) const |
| const std::optional< std::string > & | friendly_name () const |
| const std::optional< std::vector< uint8_t > > & | local_key_id () const |
| PKCS12 ()=default | |
| Construct an empty bundle. | |
| PKCS12 (std::span< const uint8_t > data, std::string_view password) | |
| const std::vector< std::shared_ptr< Private_Key > > & | private_keys () const |
| void | set_friendly_name (std::string name) |
| Set (or replace) the friendly-name attribute. | |
| void | set_local_key_id (std::vector< uint8_t > id) |
| Set (or replace) the localKeyId attribute. | |
| const std::vector< OID > & | unknown_bag_types () const |
PKCS#12/PFX bundle: parsed contents, mutable container, and exporter.
PKCS#12 is a file format for storing cryptographic objects (private keys and X.509 certificates) together, typically protected by a password.
The class can be used both to inspect an existing PFX and to build a new one. Construction from bytes parses an existing file; the default constructor produces an empty bundle that the caller populates with mutators (add_key, add_certificate, ...) before calling export_to to serialize.
|
default |
| Botan::PKCS12::PKCS12 | ( | std::span< const uint8_t > | data, |
| std::string_view | password ) |
Parse a PKCS#12/PFX file.
| data | the PFX file contents |
| password | the password to decrypt the file |
| Decoding_Error | if parsing fails |
| Invalid_Authentication_Tag | if MAC verification fails |
Definition at line 449 of file pkcs12.cpp.
References Botan::BER_Decoder::decode(), Botan::BER_Decoder::end_cons(), Botan::fmt(), friendly_name(), Botan::OID::from_string(), local_key_id(), Botan::BER_Decoder::more_items(), Botan::OctetString, Botan::AlgorithmIdentifier::oid(), Botan::PKCS12_MAX_ITERATIONS, Botan::BER_Decoder::start_context_specific(), Botan::BER_Decoder::start_sequence(), and Botan::BER_Decoder::verify_end().
| void Botan::PKCS12::add_certificate | ( | X509_Certificate | cert | ) |
Add a certificate. End-entity vs CA is determined at export time by matching against stored keys.
Definition at line 662 of file pkcs12.cpp.
| void Botan::PKCS12::add_key | ( | std::shared_ptr< Private_Key > | key | ) |
Add a private key. PKCS#12 supports multiple keys per file.
Definition at line 655 of file pkcs12.cpp.
| std::vector< X509_Certificate > Botan::PKCS12::ca_certificates | ( | ) | const |
Convenience helper: every certificate except the one returned by end_entity_certificate. Returned in storage order.
Definition at line 606 of file pkcs12.cpp.
References end_entity_certificate().
|
inline |
Certificates stored in the bundle, in the order they appear in the PFX or in insertion order. The end-entity certificate (if any) is not separated from CA/intermediate certificates at storage level; use end_entity_certificate to obtain it.
Definition at line 175 of file pkcs12.h.
| void Botan::PKCS12::clear_friendly_name | ( | ) |
Clear the friendly-name attribute.
Definition at line 670 of file pkcs12.cpp.
| void Botan::PKCS12::clear_local_key_id | ( | ) |
Clear the localKeyId attribute.
Definition at line 678 of file pkcs12.cpp.
| std::optional< X509_Certificate > Botan::PKCS12::end_entity_certificate | ( | ) | const |
nullopt if none match (e.g. a certificate-only or key-only bundle). Definition at line 637 of file pkcs12.cpp.
Referenced by ca_certificates().
| std::vector< uint8_t > Botan::PKCS12::export_to | ( | const PKCS12_Export_Options & | options, |
| RandomNumberGenerator & | rng ) const |
Serialize the bundle as a PKCS#12/PFX file.
| options | export options (password, algorithms, ...). |
| Random Number Generators | RNG used to generate salts, IVs and (if requested) the localKeyId when none is set explicitly. |
| Invalid_Argument | if options is internally inconsistent (e.g. an unsupported algorithm is requested). |
| Invalid_Argument | if a stored private key does not match any stored certificate (this implementation requires the end-entity cert to be present when a key is exported). |
Definition at line 682 of file pkcs12.cpp.
References Botan::DER_Encoder::add_object(), Botan::ASN1_Object::BER_encode(), Botan::PKCS8::BER_encode(), Botan::PKCS12_Export_Options::cert_encryption_algo(), Botan::ContextSpecific, Botan::HashFunction::create_or_throw(), Botan::MessageAuthenticationCode::create_or_throw(), Botan::PKCS12_KDF::derive_key(), Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::fmt(), friendly_name(), Botan::PKCS12_Export_Options::friendly_name(), Botan::OID::from_string(), Botan::PKCS12_Export_Options::include_mac(), Botan::PKCS12_Export_Options::iterations(), Botan::PKCS12_Export_Options::key_encryption_algo(), local_key_id(), Botan::PKCS12_Export_Options::mac_digest(), Botan::OctetString, Botan::PKCS12_Export_Options::password(), Botan::pkcs12_pbe_encrypt(), Botan::RandomNumberGenerator::randomize(), Botan::DER_Encoder::start_context_specific(), Botan::DER_Encoder::start_sequence(), Botan::unlock(), Botan::AlgorithmIdentifier::USE_EMPTY_PARAM, and Botan::AlgorithmIdentifier::USE_NULL_PARAM.
|
inline |
Friendly-name attribute attached to the private key / end-entity certificate bag, if present.
Definition at line 194 of file pkcs12.h.
Referenced by export_to(), and PKCS12().
|
inline |
localKeyId attribute attached to the private key / end-entity certificate bag, if present.
Definition at line 200 of file pkcs12.h.
Referenced by export_to(), and PKCS12().
|
inline |
Private keys stored in the bundle, in the order they appear in the PFX (for a parsed file) or in insertion order (for a built one). PKCS#12 allows multiple keys per file; parsing currently surfaces all KeyBag / PKCS8ShroudedKeyBag entries.
Definition at line 167 of file pkcs12.h.
| void Botan::PKCS12::set_friendly_name | ( | std::string | name | ) |
Set (or replace) the friendly-name attribute.
Definition at line 666 of file pkcs12.cpp.
| void Botan::PKCS12::set_local_key_id | ( | std::vector< uint8_t > | id | ) |
Set (or replace) the localKeyId attribute.
Definition at line 674 of file pkcs12.cpp.
|
inline |