Botan 1.10.17
cvc_cert.cpp
Go to the documentation of this file.
1/*
2 (C) 2007 FlexSecure GmbH
3 2008-2010 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#include <botan/cvc_cert.h>
9#include <botan/oids.h>
10
11namespace Botan {
12
14 {
15 return m_car;
16 }
17
19 {
20 return m_ced;
21 }
23 {
24 return m_cex;
25 }
27 {
28 return m_chat_val;
29 }
30
31/*
32* Decode the TBSCertificate data
33*/
34void EAC1_1_CVC::force_decode()
35 {
36 SecureVector<byte> enc_pk;
37 SecureVector<byte> enc_chat_val;
38 size_t cpi;
39 BER_Decoder tbs_cert(tbs_bits);
40 tbs_cert.decode(cpi, ASN1_Tag(41), APPLICATION)
41 .decode(m_car)
42 .start_cons(ASN1_Tag(73))
43 .raw_bytes(enc_pk)
44 .end_cons()
45 .decode(m_chr)
46 .start_cons(ASN1_Tag(76))
47 .decode(m_chat_oid)
48 .decode(enc_chat_val, OCTET_STRING, ASN1_Tag(19), APPLICATION)
49 .end_cons()
50 .decode(m_ced)
51 .decode(m_cex)
52 .verify_end();
53
54 if(enc_chat_val.size() != 1)
55 throw Decoding_Error("CertificateHolderAuthorizationValue was not of length 1");
56
57 if(cpi != 0)
58 throw Decoding_Error("EAC1_1 certificate's cpi was not 0");
59
61
62 m_chat_val = enc_chat_val[0];
63
64 self_signed = (m_car.iso_8859() == m_chr.iso_8859());
65 }
66
67/*
68* CVC Certificate Constructor
69*/
71 {
72 init(in);
73 self_signed = false;
74 do_decode();
75 }
76
77EAC1_1_CVC::EAC1_1_CVC(const std::string& in)
78 {
79 DataSource_Stream stream(in, true);
80 init(stream);
81 self_signed = false;
82 do_decode();
83 }
84
85bool EAC1_1_CVC::operator==(EAC1_1_CVC const& rhs) const
86 {
87 return (tbs_data() == rhs.tbs_data()
88 && get_concat_sig() == rhs.get_concat_sig());
89 }
90
93 {
94 throw Internal_Error("decode_eac1_1_key: Unimplemented");
95 return 0;
96 }
97
99 MemoryRegion<byte> const& public_key,
100 ASN1_Car const& car,
101 ASN1_Chr const& chr,
102 byte holder_auth_templ,
103 ASN1_Ced ced,
104 ASN1_Cex cex,
106 {
107 OID chat_oid(OIDS::lookup("CertificateHolderAuthorizationTemplate"));
108 MemoryVector<byte> enc_chat_val;
109 enc_chat_val.push_back(holder_auth_templ);
110
111 MemoryVector<byte> enc_cpi;
112 enc_cpi.push_back(0x00);
114 .encode(enc_cpi, OCTET_STRING, ASN1_Tag(41), APPLICATION) // cpi
115 .encode(car)
116 .raw_bytes(public_key)
117 .encode(chr)
119 .encode(chat_oid)
120 .encode(enc_chat_val, OCTET_STRING, ASN1_Tag(19), APPLICATION)
121 .end_cons()
122 .encode(ced)
123 .encode(cex)
124 .get_contents();
125
126 MemoryVector<byte> signed_cert =
129 rng);
130
131 DataSource_Memory source(signed_cert);
132 return EAC1_1_CVC(source);
133 }
134
135}
std::string iso_8859() const
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition der_enc.cpp:135
DER_Encoder & raw_bytes(const byte val[], size_t len)
Definition der_enc.cpp:188
SecureVector< byte > get_contents()
Definition der_enc.cpp:122
DER_Encoder & end_cons()
Definition der_enc.cpp:145
DER_Encoder & encode(bool b)
Definition der_enc.cpp:209
EAC1_1_CVC(DataSource &source)
Definition cvc_cert.cpp:70
ASN1_Cex get_cex() const
Definition cvc_cert.cpp:22
u32bit get_chat_value() const
Definition cvc_cert.cpp:26
bool operator==(const EAC1_1_CVC &) const
Definition cvc_cert.cpp:85
ASN1_Ced get_ced() const
Definition cvc_cert.cpp:18
ASN1_Car get_car() const
Definition cvc_cert.cpp:13
static SecureVector< byte > build_cert_body(MemoryRegion< byte > const &tbs)
SecureVector< byte > tbs_data() const
static MemoryVector< byte > make_signed(PK_Signer &signer, const MemoryRegion< byte > &tbs_bits, RandomNumberGenerator &rng)
void init(DataSource &in)
Definition eac_obj.h:38
SecureVector< byte > get_concat_sig() const
Definition eac_obj.h:27
SecureVector< byte > tbs_bits
Definition signed_obj.h:86
size_t size() const
Definition secmem.h:29
void push_back(T x)
Definition secmem.h:149
std::string lookup(const OID &oid)
Definition oids.cpp:31
ECDSA_PublicKey * decode_eac1_1_key(const MemoryRegion< byte > &, AlgorithmIdentifier &)
Definition cvc_cert.cpp:91
ASN1_Tag
Definition asn1_int.h:19
@ APPLICATION
Definition asn1_int.h:21
@ OCTET_STRING
Definition asn1_int.h:31
unsigned int u32bit
Definition types.h:32
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
Decoding_Error(const std::string &name)
Definition exceptn.h:140
Internal_Error(const std::string &err)
Definition exceptn.h:47