ETSI STF525 / Internal Testing test suite This project provides an internal testing test suite and its associated Test Adapter/Codec

security_services.hh
Go to the documentation of this file.
1 #pragma once
2
3 #include <memory>
4
5 #include "Params.hh"
6
7 #include "security_db.hh"
8
9 #include "security_ecc.hh"
10
11 class OCTETSTRING;
12 class CHARSTRING;
13
14 namespace IEEE1609dot2BaseTypes {
15 class HashAlgorithm;
16 class Signature;}
17
18 namespace IEEE1609dot2 {
19 class Ieee1609Dot2Data;
20 class Ieee1609Dot2Content;
21 class ToBeSignedData;
22 class SignedData;
23 class EncryptedData;
24 class SignerIdentifier;
25 }
26
32 class security_services {
33
34 static constexpr unsigned int ProtocolVersion = 3;
35
39 static security_services* instance;
40 bool _setup_done;
41 std::unique_ptr<security_ecc> _ec_keys_enc;
42 std::unique_ptr<security_ecc> _ec_keys_dec;
43 std::unique_ptr<security_cache> _security_cache;
44 std::unique_ptr<security_db> _security_db;
45 unsigned long long _last_generation_time;
46 std::vector<unsigned char> _unknown_certificate;
47 int _latitude;
48 int _longitude;
49 int _elevation;
50
54 security_services();
58 ~security_services() {
59 _ec_keys_enc.reset(nullptr);
60 _security_db.reset(nullptr);
61 _security_cache.reset(nullptr);
62 if (instance != NULL) {
63 delete instance;
64 instance = NULL;
65 }
66 };
67
68 public:
72 inline static security_services& get_instance() {
73 if (instance == NULL) instance = new security_services();
74 return *instance;
75 };
76
88 int verify_and_extract_gn_payload(const OCTETSTRING& p_secured_gn_payload, const bool p_verify, IEEE1609dot2::Ieee1609Dot2Data& p_ieee_1609dot2_data, OCTETSTRING& p_unsecured_gn_payload, Params& p_params);
97 int secure_gn_payload(const OCTETSTRING& p_unsecured_gn_payload, OCTETSTRING& p_secured_gn_payload, Params& p_params);
98
99 int setup(Params &p_params);
100
101 int store_certificate(const CHARSTRING& p_cert_id, const OCTETSTRING& p_cert, const OCTETSTRING& p_private_key, const OCTETSTRING& p_public_key_x, const OCTETSTRING& p_public_key_y, const OCTETSTRING& p_hashid8, const OCTETSTRING& p_issuer, const OCTETSTRING& p_private_enc_key, const OCTETSTRING& p_public_enc_key_x, const OCTETSTRING& p_public_enc_key_y);
102
103 inline void set_position(const int p_latitude, const int p_longitude, const int p_elevation = 0) { _latitude = p_latitude; _longitude = p_longitude; _elevation = p_elevation; };
104
105 int read_certificate(const CHARSTRING& p_certificate_id, OCTETSTRING& p_certificate) const;
106 int read_certificate_digest(const CHARSTRING& p_certificate_id, OCTETSTRING& p_digest) const;
107 int read_certificate_from_digest(const OCTETSTRING& p_digest, CHARSTRING& p_certificate_id) const;
108 int read_private_key(const CHARSTRING& p_certificate_id, OCTETSTRING& p_private_key) const;
109 int read_private_enc_key(const CHARSTRING& p_certificate_id, OCTETSTRING& p_private_enc_key) const;
110
111 private:
120 int sign_gn_payload(const OCTETSTRING& p_unsecured_gn_payload, OCTETSTRING& p_signed_gn_payload, Params& p_params);
129 int encrypt_gn_payload(const OCTETSTRING& p_unsecured_gn_payload, OCTETSTRING& p_enc_gn_payload, Params& p_params);
138 int process_ieee_1609_dot2_content(const IEEE1609dot2::Ieee1609Dot2Content& p_ieee_1609_dot2_content, const bool p_verify, OCTETSTRING& p_unsecured_payload, Params& p_params);
139 int process_ieee_1609_dot2_signed_data(const IEEE1609dot2::SignedData& p_signed_data, const bool p_verify, OCTETSTRING& p_unsecured_payload, Params& p_params);
140 int process_ieee_1609_dot2_encrypted_data(const IEEE1609dot2::EncryptedData& p_encrypted_data, const bool p_verify, OCTETSTRING& p_unsecured_payload, Params& p_params);
141 int sign_tbs_data(const IEEE1609dot2::ToBeSignedData& p_tbs_data, const IEEE1609dot2BaseTypes::HashAlgorithm& p_hashAlgorithm, IEEE1609dot2BaseTypes::Signature& p_signature, Params& p_params);
142
143 int hash_sha256(const OCTETSTRING& p_data, OCTETSTRING& p_hash_data);
144 int hash_sha384(const OCTETSTRING& p_data, OCTETSTRING& p_hash_data);
145 int sign_ecdsa_nistp256(const OCTETSTRING& p_hash, IEEE1609dot2BaseTypes::Signature& p_signature, Params& p_params);
146 int verify_sign_ecdsa_nistp256(const OCTETSTRING& p_hash, const IEEE1609dot2BaseTypes::Signature& p_signature, const std::string& p_certificate_id, Params& p_params);
147
148 int extract_encryption_keys(const IEEE1609dot2::CertificateBase& p_cert, OCTETSTRING& p_public_enc_key_x, OCTETSTRING& p_public_enc_key_y);
149 }; // End of class security_services
security_services::_elevation
int _elevation
Definition: security_services.hh:49
security_services::_ec_keys_dec
std::unique_ptr< security_ecc > _ec_keys_dec
Definition: security_services.hh:42
security_services::instance
static security_services * instance
Unique static object reference of this class.
Definition: security_services.hh:39
security_services::_setup_done
bool _setup_done
Definition: security_services.hh:40
IEEE1609dot2BaseTypes
Definition: security_services.hh:14
security_services::set_position
void set_position(const int p_latitude, const int p_longitude, const int p_elevation=0)
Definition: security_services.hh:103
Params.hh
Header file for the parameter dictionary.
security_services::~security_services
~security_services()
Default private dtor.
Definition: security_services.hh:58
IEEE1609dot2
Definition: security_db_record.hh:8
security_services::verify_and_extract_gn_payload
int verify_and_extract_gn_payload(const OCTETSTRING &p_secured_gn_payload, const bool p_verify, IEEE1609dot2::Ieee1609Dot2Data &p_ieee_1609dot2_data, OCTETSTRING &p_unsecured_gn_payload, Params &p_params)
Verify and extract the unsecured payload from the provided secured payload. The secured payload could...
Definition: security_services.hh:75
security_ecc.hh
Header file for Elliptic Curve Cryptography.
security_services
This class provides security services for all layers as specified in TSI TS 102 723-8 and ETSI TS 103...
Definition: security_services.hh:32
security_services::_security_cache
std::unique_ptr< security_cache > _security_cache
Definition: security_services.hh:43
Params
This class provides basic functionalities for an ITS dictionary.
Definition: Params.hh:21
security_services::_ec_keys_enc
std::unique_ptr< security_ecc > _ec_keys_enc
Definition: security_services.hh:41
security_services::get_instance
static security_services & get_instance()
Public accessor to the single object reference.
Definition: security_services.hh:72
security_services::_longitude
int _longitude
Definition: security_services.hh:48
security_db.hh
security_services::_security_db
std::unique_ptr< security_db > _security_db
Definition: security_services.hh:44
security_services::_latitude
int _latitude
Definition: security_services.hh:47
security_services::_last_generation_time
unsigned long long _last_generation_time
Definition: security_services.hh:45
security_services::_unknown_certificate
std::vector< unsigned char > _unknown_certificate
Definition: security_services.hh:46