Vanetza
 
Loading...
Searching...
No Matches
certificate.hpp
1#ifndef CERTIFICATE_HPP_LWBWIAVL
2#define CERTIFICATE_HPP_LWBWIAVL
3
4#include <vanetza/common/byte_buffer.hpp>
5#include <vanetza/common/its_aid.hpp>
6#include <vanetza/security/backend.hpp>
7#include <vanetza/security/ecdsa256.hpp>
8#include <vanetza/security/v2/basic_elements.hpp>
9#include <vanetza/security/v2/ecc_point.hpp>
10#include <vanetza/security/v2/serialization.hpp>
11#include <vanetza/security/v2/signature.hpp>
12#include <vanetza/security/v2/signer_info.hpp>
13#include <vanetza/security/v2/subject_attribute.hpp>
14#include <vanetza/security/v2/subject_info.hpp>
15#include <vanetza/security/v2/validity_restriction.hpp>
16#include <boost/optional/optional.hpp>
17#include <boost/variant/get.hpp>
18
19namespace vanetza
20{
21namespace security
22{
23namespace v2
24{
25
26/// described in TS 103 097 v1.2.1 (2015-06), section 6.1
28{
29 SignerInfo signer_info;
30 SubjectInfo subject_info;
31 std::list<SubjectAttribute> subject_attributes;
32 std::list<ValidityRestriction> validity_restriction;
33 Signature signature;
34 // certificate version is two, for conformance with the present standard
35 uint8_t version() const { return 2; }
36
37 /**
38 * Get subject attribute of a certain type (if present)
39 * \param type of subject attribute
40 */
41 const SubjectAttribute* get_attribute(SubjectAttributeType type) const;
42
43 /**
44 * Get validity restriction of a certain type (if present)
45 * \param type of validity restriction
46 */
47 const ValidityRestriction* get_restriction(ValidityRestrictionType type) const;
48
49 /**
50 * Remove subject attribute of a certain type (if present)
51 * \param type of subject attribute
52 */
53 void remove_attribute(SubjectAttributeType type);
54
55 /**
56 * Remove validity restriction of a certain type (if present)
57 * \param type of validity restriction
58 */
59 void remove_restriction(ValidityRestrictionType type);
60
61 /**
62 * Add ITS-AID to certificate's subject attributes
63 * \param aid ITS-AID
64 */
65 void add_permission(ItsAid aid);
66
67 /**
68 * Add ITS-AID along with SSP to certificate's subject attributes
69 * \param aid ITS-AID
70 * \param ssp Service Specific Permissions
71 */
72 void add_permission(ItsAid aid, const ByteBuffer& ssp);
73
74 /**
75 * Get subject attribute by type
76 * \tparam T subject attribute type
77 * \return subject attribute, nullptr if not found
78 */
79 template<SubjectAttributeType T>
80 const subject_attribute_type<T>* get_attribute() const
81 {
82 using type = subject_attribute_type<T>;
83 const SubjectAttribute* field = get_attribute(T);
84 return boost::get<type>(field);
85 }
86
87 /**
88 * Get validity restriction by type
89 * \tparam T validity restriction type
90 * \return validity restriction, nullptr if not found
91 */
92 template<ValidityRestrictionType T>
93 const validity_restriction_type<T>* get_restriction() const
94 {
95 using type = validity_restriction_type<T>;
96 const ValidityRestriction* field = get_restriction(T);
97 return boost::get<type>(field);
98 }
99};
100
101/**
102 * \brief Calculates size of an certificate object
103 *
104 * \param cert
105 * \return number of octets needed to serialize the object
106 */
107size_t get_size(const Certificate&);
108
109/**
110 * \brief Serializes an object into a binary archive
111 *
112 * \param ar archive to serialize in
113 * \param cert to serialize
114 */
115void serialize(OutputArchive&, const Certificate&);
116
117/**
118 * \brief Deserializes an object from a binary archive
119 *
120 * \param ar archive with a serialized object at the beginning
121 * \param cert to deserialize
122 * \return size of the deserialized object
123 */
124size_t deserialize(InputArchive&, Certificate&);
125
126/**
127* \brief Serialize parts of a Certificate for signature calculation
128*
129* Uses version, signer_field, subject_info, subject_attributes (+ length),
130* validity_restriction (+ length).
131*
132* \param cert certificate to be converted
133* \return binary representation
134*/
135ByteBuffer convert_for_signing(const Certificate&);
136
137/**
138 * \brief Sort lists in the certificate to be in the correct order for serialization
139 *
140 * \param cert certificate to sort
141 */
142void sort(Certificate& certificate);
143
144/**
145 * \brief Extract public key from certificate
146 * \param cert Certificate
147 * \param backend Backend
148 * \return Uncompressed public key (if available)
149 */
150boost::optional<Uncompressed> get_uncompressed_public_key(const Certificate&, Backend& backend);
151
152/**
153 * \brief Extract public ECDSA256 key from certificate
154 * \param cert Certificate
155 * \param backend Backend
156 * \return public key (if available)
157 */
158boost::optional<ecdsa256::PublicKey> get_public_key(const Certificate&, Backend& backend);
159
160/**
161 * Calculate hash id of certificate
162 * \param cert Certificate
163 * \return hash
164 */
165HashedId8 calculate_hash(const Certificate&);
166
167} // namespace v2
168} // namespace security
169} // namespace vanetza
170
171#endif /* CERTIFICATE_HPP_LWBWIAVL */
described in TS 103 097 v1.2.1 (2015-06), section 6.1
Definition: certificate.hpp:28
const validity_restriction_type< T > * get_restriction() const
Definition: certificate.hpp:93
void remove_attribute(SubjectAttributeType type)
const subject_attribute_type< T > * get_attribute() const
Definition: certificate.hpp:80
void remove_restriction(ValidityRestrictionType type)
described in TS 103 097 v1.2.1, section 6.2