Botan 1.10.17
Botan::CVC_EAC Namespace Reference

Functions

EAC1_1_ADO create_ado_req (Private_Key const &key, EAC1_1_Req const &req, ASN1_Car const &car, RandomNumberGenerator &rng)
EAC1_1_Req create_cvc_req (Private_Key const &key, ASN1_Chr const &chr, std::string const &hash_alg, RandomNumberGenerator &rng)
EAC1_1_CVC create_self_signed_cert (Private_Key const &key, EAC1_1_CVC_Options const &opt, RandomNumberGenerator &rng)

Detailed Description

This namespace represents general EAC 1.1 convenience functions.

Function Documentation

◆ create_ado_req()

EAC1_1_ADO BOTAN_DLL Botan::CVC_EAC::create_ado_req ( Private_Key const & priv_key,
EAC1_1_Req const & req,
ASN1_Car const & car,
RandomNumberGenerator & rng )

Create an ADO from a request object.

Parameters
priv_keythe private key used to sign the ADO
reqthe request forming the body of the ADO
carthe CAR forming the body of the ADO, i.e. the CHR of the entity associated with the provided private key
rngthe rng to use

Definition at line 156 of file cvc_self.cpp.

160 {
161
162 ECDSA_PrivateKey const* priv_key = dynamic_cast<ECDSA_PrivateKey const*>(&key);
163 if (priv_key == 0)
164 {
165 throw Invalid_Argument("CVC_EAC::create_self_signed_cert(): unsupported key type");
166 }
167 std::string padding_and_hash = padding_and_hash_from_oid(req.signature_algorithm().oid);
168 PK_Signer signer(*priv_key, padding_and_hash);
169 SecureVector<byte> tbs_bits = req.BER_encode();
170 tbs_bits += DER_Encoder().encode(car).get_contents();
171
172 MemoryVector<byte> signed_cert =
173 EAC1_1_ADO::make_signed(signer, tbs_bits, rng);
174
175 DataSource_Memory source(signed_cert);
176 return EAC1_1_ADO(source);
177 }
SecureVector< byte > get_contents()
Definition der_enc.cpp:122
DER_Encoder & encode(bool b)
Definition der_enc.cpp:209
EAC1_1_ADO(const std::string &str)
Definition cvc_ado.cpp:20
static MemoryVector< byte > make_signed(PK_Signer &signer, const MemoryRegion< byte > &tbs_bits, RandomNumberGenerator &rng)
Definition cvc_ado.cpp:48
std::invalid_argument Invalid_Argument
Definition exceptn.h:20

References Botan::EAC_Signed_Object::BER_encode(), create_ado_req(), Botan::EAC1_1_ADO::EAC1_1_ADO(), Botan::DER_Encoder::encode(), Botan::DER_Encoder::get_contents(), Botan::EAC1_1_ADO::make_signed(), Botan::AlgorithmIdentifier::oid, and Botan::EAC_Signed_Object::signature_algorithm().

Referenced by create_ado_req().

◆ create_cvc_req()

EAC1_1_Req BOTAN_DLL Botan::CVC_EAC::create_cvc_req ( Private_Key const & priv_key,
ASN1_Chr const & chr,
std::string const & hash_alg,
RandomNumberGenerator & rng )

Create a CVC request. The key encoding will be according to the provided private key.

Parameters
priv_keythe private key associated with the requesting entity
chrthe chr to appear in the certificate (to be provided without sequence number)
hash_algthe string defining the hash algorithm to be used for the creation of the signature
rngthe rng to use
Returns
the new request

Definition at line 119 of file cvc_self.cpp.

123 {
124
125 ECDSA_PrivateKey const* priv_key = dynamic_cast<ECDSA_PrivateKey const*>(&key);
126 if (priv_key == 0)
127 {
128 throw Invalid_Argument("CVC_EAC::create_self_signed_cert(): unsupported key type");
129 }
130 AlgorithmIdentifier sig_algo;
131 std::string padding_and_hash("EMSA1_BSI(" + hash_alg + ")");
132 sig_algo.oid = OIDS::lookup(priv_key->algo_name() + "/" + padding_and_hash);
134
135 PK_Signer signer(*priv_key, padding_and_hash);
136
137 MemoryVector<byte> enc_public_key = eac_1_1_encoding(priv_key, sig_algo.oid);
138
139 MemoryVector<byte> enc_cpi;
140 enc_cpi.push_back(0x00);
142 .encode(enc_cpi, OCTET_STRING, ASN1_Tag(41), APPLICATION)
143 .raw_bytes(enc_public_key)
144 .encode(chr)
145 .get_contents();
146
147 MemoryVector<byte> signed_cert =
150 rng);
151
152 DataSource_Memory source(signed_cert);
153 return EAC1_1_Req(source);
154 }
DER_Encoder & raw_bytes(const byte val[], size_t len)
Definition der_enc.cpp:188
EAC1_1_Req(DataSource &source)
Definition cvc_req.cpp:38
static SecureVector< byte > build_cert_body(MemoryRegion< byte > const &tbs)
static MemoryVector< byte > make_signed(PK_Signer &signer, const MemoryRegion< byte > &tbs_bits, RandomNumberGenerator &rng)
std::string algo_name() const
Definition ecdsa.h:43
void push_back(T x)
Definition secmem.h:149
std::string lookup(const OID &oid)
Definition oids.cpp:31
ASN1_Tag
Definition asn1_int.h:19
@ APPLICATION
Definition asn1_int.h:21
@ OCTET_STRING
Definition asn1_int.h:31

References Botan::ECDSA_PublicKey::algo_name(), Botan::AlgorithmIdentifier::AlgorithmIdentifier(), Botan::APPLICATION, Botan::EAC1_1_gen_CVC< Derived >::build_cert_body(), create_cvc_req(), Botan::EAC1_1_Req::EAC1_1_Req(), Botan::DER_Encoder::encode(), Botan::DER_Encoder::get_contents(), Botan::OIDS::lookup(), Botan::EAC1_1_gen_CVC< Derived >::make_signed(), Botan::OCTET_STRING, Botan::AlgorithmIdentifier::oid, Botan::MemoryRegion< T >::push_back(), Botan::DER_Encoder::raw_bytes(), and Botan::AlgorithmIdentifier::USE_NULL_PARAM.

Referenced by create_cvc_req(), and Botan::DE_EAC::create_cvc_req().

◆ create_self_signed_cert()

EAC1_1_CVC BOTAN_DLL Botan::CVC_EAC::create_self_signed_cert ( Private_Key const & key,
EAC1_1_CVC_Options const & opts,
RandomNumberGenerator & rng )

Create a selfsigned CVCA

Parameters
rngthe rng to use
keythe ECDSA private key to be used to sign the certificate
optsused to set several parameters. Necessary are: car, holder_auth_templ, hash_alg, ced, cex and hash_alg
Returns
the self signed certificate

Definition at line 90 of file cvc_self.cpp.

93 {
94 // NOTE: we ignore the value of opt.chr
95
96 const ECDSA_PrivateKey* priv_key = dynamic_cast<const ECDSA_PrivateKey*>(&key);
97
98 if(priv_key == 0)
99 throw Invalid_Argument("CVC_EAC::create_self_signed_cert(): unsupported key type");
100
101 ASN1_Chr chr(opt.car.value());
102
103 AlgorithmIdentifier sig_algo;
104 std::string padding_and_hash("EMSA1_BSI(" + opt.hash_alg + ")");
105 sig_algo.oid = OIDS::lookup(priv_key->algo_name() + "/" + padding_and_hash);
107
108 PK_Signer signer(*priv_key, padding_and_hash);
109
110 MemoryVector<byte> enc_public_key = eac_1_1_encoding(priv_key, sig_algo.oid);
111
112 return make_cvc_cert(signer,
113 enc_public_key,
114 opt.car, chr,
115 opt.holder_auth_templ,
116 opt.ced, opt.cex, rng);
117 }
EAC1_1_CVC make_cvc_cert(PK_Signer &signer, MemoryRegion< byte > const &public_key, ASN1_Car const &car, ASN1_Chr const &chr, byte holder_auth_templ, ASN1_Ced ced, ASN1_Cex cex, RandomNumberGenerator &rng)
Definition cvc_cert.cpp:98

References Botan::ECDSA_PublicKey::algo_name(), Botan::AlgorithmIdentifier::AlgorithmIdentifier(), Botan::EAC1_1_CVC_Options::car, Botan::EAC1_1_CVC_Options::ced, Botan::EAC1_1_CVC_Options::cex, create_self_signed_cert(), Botan::EAC1_1_CVC_Options::hash_alg, Botan::EAC1_1_CVC_Options::holder_auth_templ, Botan::OIDS::lookup(), Botan::make_cvc_cert(), Botan::AlgorithmIdentifier::oid, Botan::AlgorithmIdentifier::USE_NULL_PARAM, and Botan::ASN1_EAC_String::value().

Referenced by Botan::DE_EAC::create_cvca(), and create_self_signed_cert().