security_services.hh
Go to the documentation of this file.
#pragma once
#include <memory>
#include "Params.hh"
#include "security_db.hh"
#include "security_ecc.hh"
class OCTETSTRING;
class CHARSTRING;
namespace IEEE1609dot2BaseTypes {
class HashAlgorithm;
class Signature;}
namespace IEEE1609dot2 {
class Ieee1609Dot2Data;
class Ieee1609Dot2Content;
class ToBeSignedData;
class SignedData;
class EncryptedData;
class SignerIdentifier;
}
class security_services {
static constexpr unsigned int ProtocolVersion = 3;
static security_services* instance;
bool _setup_done;
std::unique_ptr<security_ecc> _ec_keys_enc;
std::unique_ptr<security_ecc> _ec_keys_dec;
std::unique_ptr<security_cache> _security_cache;
std::unique_ptr<security_db> _security_db;
unsigned long long _last_generation_time;
std::vector<unsigned char> _unknown_certificate;
int _latitude;
int _longitude;
int _elevation;
security_services();
~security_services() {
_ec_keys_enc.reset(nullptr);
_security_db.reset(nullptr);
_security_cache.reset(nullptr);
if (instance != NULL) {
delete instance;
instance = NULL;
}
};
public:
inline static security_services& get_instance() {
if (instance == NULL) instance = new security_services();
return *instance;
};
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);
int secure_gn_payload(const OCTETSTRING& p_unsecured_gn_payload, OCTETSTRING& p_secured_gn_payload, Params& p_params);
int setup(Params &p_params);
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);
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; };
int read_certificate(const CHARSTRING& p_certificate_id, OCTETSTRING& p_certificate) const;
int read_certificate_digest(const CHARSTRING& p_certificate_id, OCTETSTRING& p_digest) const;
int read_certificate_from_digest(const OCTETSTRING& p_digest, CHARSTRING& p_certificate_id) const;
int read_private_key(const CHARSTRING& p_certificate_id, OCTETSTRING& p_private_key) const;
int read_private_enc_key(const CHARSTRING& p_certificate_id, OCTETSTRING& p_private_enc_key) const;
private:
int sign_gn_payload(const OCTETSTRING& p_unsecured_gn_payload, OCTETSTRING& p_signed_gn_payload, Params& p_params);
int encrypt_gn_payload(const OCTETSTRING& p_unsecured_gn_payload, OCTETSTRING& p_enc_gn_payload, Params& p_params);
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);
int process_ieee_1609_dot2_signed_data(const IEEE1609dot2::SignedData& p_signed_data, const bool p_verify, OCTETSTRING& p_unsecured_payload, Params& p_params);
int process_ieee_1609_dot2_encrypted_data(const IEEE1609dot2::EncryptedData& p_encrypted_data, const bool p_verify, OCTETSTRING& p_unsecured_payload, Params& p_params);
int sign_tbs_data(const IEEE1609dot2::ToBeSignedData& p_tbs_data, const IEEE1609dot2BaseTypes::HashAlgorithm& p_hashAlgorithm, IEEE1609dot2BaseTypes::Signature& p_signature, Params& p_params);
int hash_sha256(const OCTETSTRING& p_data, OCTETSTRING& p_hash_data);
int hash_sha384(const OCTETSTRING& p_data, OCTETSTRING& p_hash_data);
int sign_ecdsa_nistp256(const OCTETSTRING& p_hash, IEEE1609dot2BaseTypes::Signature& p_signature, Params& p_params);
int verify_sign_ecdsa_nistp256(const OCTETSTRING& p_hash, const IEEE1609dot2BaseTypes::Signature& p_signature, const std::string& p_certificate_id, Params& p_params);
int extract_encryption_keys(const IEEE1609dot2::CertificateBase& p_cert, OCTETSTRING& p_public_enc_key_x, OCTETSTRING& p_public_enc_key_y);
}; // 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