Compare Revisions

The credentials to download the source code are:
 Username: svnusers
 Password: svnusers

Ignore whitespace Rev 3349 → Rev 3350

/branches/STF525/ccsrc/Protocols/Security/certificates_loader.cc
48,7 → 48,7
return 0;
} // End of method build_path
 
int certificates_loader::load_certificates(std::map<std::string, std::unique_ptr<security_db_record> >& p_certificates, /*std::map<OCTETSTRING, std::string>*/std::map<std::vector<unsigned char>, std::string>& p_hashed_id8s) {
int certificates_loader::load_certificates(std::map<std::string, std::unique_ptr<security_db_record> >& p_certificates, std::map<OCTETSTRING/*std::vector<unsigned char>*/, std::string, security_cache_comp>& p_hashed_id8s) {
loggers::get_instance().log(">>> certificates_loader::load_certificates");
 
// Sanity check
119,7 → 119,7
return 0;
} // End of method retrieve_certificates_list
 
int certificates_loader::build_certificates_cache(std::set<std::experimental::filesystem::path>& p_files, std::map<std::string, std::unique_ptr<security_db_record> >& p_certificates, /*std::map<OCTETSTRING, std::string>*/std::map<std::vector<unsigned char>, std::string>& p_hashed_id8s) {
int certificates_loader::build_certificates_cache(std::set<std::experimental::filesystem::path>& p_files, std::map<std::string, std::unique_ptr<security_db_record> >& p_certificates, std::map<OCTETSTRING/*std::vector<unsigned char>*/, std::string, security_cache_comp>& p_hashed_id8s) {
loggers::get_instance().log(">>> certificates_loader::build_certificates_cache");
 
std::set<std::experimental::filesystem::path>::const_iterator it = p_files.cbegin();
299,10 → 299,10
}
loggers::get_instance().log_msg("certificates_loader::build_certificates_cache: add key: ", result.first->second.get()->hashed_id());
loggers::get_instance().log("certificates_loader::build_certificates_cache: for : %s", result.first->first.c_str());
//p_hashed_id8s.insert(std::pair<OCTETSTRING, std::string>(result.first->second.get()->hashed_id(), result.first->first));
std::vector<unsigned char> v(static_cast<const unsigned char*>(result.first->second.get()->hashed_id()), result.first->second.get()->hashed_id().lengthof() + static_cast<const unsigned char*>(result.first->second.get()->hashed_id()));
p_hashed_id8s.insert(std::pair<OCTETSTRING, std::string>(result.first->second.get()->hashed_id(), result.first->first));
/*std::vector<unsigned char> v(static_cast<const unsigned char*>(result.first->second.get()->hashed_id()), result.first->second.get()->hashed_id().lengthof() + static_cast<const unsigned char*>(result.first->second.get()->hashed_id()));
loggers::get_instance().log_to_hexa("security_cache::store_certificate: Converted hashed_id8: ", v.data(), v.size());
p_hashed_id8s.insert(std::pair<std::vector<unsigned char>, std::string>(v, result.first->first));
p_hashed_id8s.insert(std::pair<std::vector<unsigned char>, std::string>(v, result.first->first));*/
}
// Reset pointer
it = p_files.cbegin();
/branches/STF525/ccsrc/Protocols/Security/certificates_loader.hh
19,6 → 19,7
#include <experimental/filesystem>
 
#include "security_db_record.hh"
#include "security_cache.hh"
#include "security_ecc.hh"
 
namespace IEEE1609dot2BaseTypes {
66,7 → 67,7
 
int build_path(const std::string& p_root_directory);
 
int load_certificates(std::map<std::string, std::unique_ptr<security_db_record> >& p_certificates, /*std::map<OCTETSTRING, std::string>*/std::map<std::vector<unsigned char>, std::string>& p_hashed_id8s);
int load_certificates(std::map<std::string, std::unique_ptr<security_db_record> >& p_certificates, std::map<OCTETSTRING/*std::vector<unsigned char>*/, std::string, security_cache_comp>& p_hashed_id8s);
//int load_certificate(std::unique_ptr<security_db_record> >& p_certificate, std::map<const OCTETSTRING, const std::string&>& p_hashed_id8s);
int save_certificate(const security_db_record& p_certificate);
 
73,7 → 74,7
private:
int retrieve_certificates_list(std::set<std::experimental::filesystem::path>& p_files);
 
int build_certificates_cache(std::set<std::experimental::filesystem::path>& p_files, std::map<std::string, std::unique_ptr<security_db_record> >& p_certificates, /*std::map<OCTETSTRING, std::string>*/std::map<std::vector<unsigned char>, std::string>& p_hashed_id8s);
int build_certificates_cache(std::set<std::experimental::filesystem::path>& p_files, std::map<std::string, std::unique_ptr<security_db_record> >& p_certificates, std::map<OCTETSTRING/*std::vector<unsigned char>*/, std::string, security_cache_comp>& p_hashed_id8s);
void fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const IEEE1609dot2BaseTypes::EccP256CurvePoint& p_ecc_point, OCTETSTRING& p_public_comp_key, OCTETSTRING& p_public_key_x, OCTETSTRING& p_public_key_y);
void fill_public_key_vectors(const ec_elliptic_curves p_elliptic_curve, const IEEE1609dot2BaseTypes::EccP384CurvePoint& p_ecc_point, OCTETSTRING& p_public_comp_key, OCTETSTRING& p_public_key_x, OCTETSTRING& p_public_key_y);
/branches/STF525/ccsrc/Protocols/Security/security_cache.cc
22,23 → 22,25
 
#include "loggers.hh"
 
/*bool security_cache_comp::operator()(const OCTETSTRING& p_lhs, const OCTETSTRING& p_rhs) const {
bool security_cache_comp::operator()(const OCTETSTRING& p_lhs, const OCTETSTRING& p_rhs) const {
loggers::get_instance().log_msg(">>> security_cache_comp::operator(): ", p_lhs);
loggers::get_instance().log_msg(">>> security_cache_comp::operator(): ", p_rhs);
if (p_lhs.lengthof() != p_rhs.lengthof()) {
return !false;
} else {
for (int i = 0; i < p_lhs.lengthof(); i++) {
loggers::get_instance().log("security_cache_comp::operator(): compare %02x with %02x", p_lhs[i].get_octet(), p_rhs[i].get_octet());
if (p_lhs[i].get_octet() != p_rhs[i].get_octet()) {
loggers::get_instance().log("<<< security_cache_comp::operator(): false");
return !false;
}
unsigned char* first1 = (unsigned char*)static_cast<const unsigned char*>(p_lhs);
unsigned char* first2 = (unsigned char*)static_cast<const unsigned char*>(p_rhs);
unsigned char* last1 = p_lhs.lengthof() + (unsigned char*)static_cast<const unsigned char*>(p_lhs);
unsigned char* last2 = p_rhs.lengthof() + (unsigned char*)static_cast<const unsigned char*>(p_rhs);
 
while (first1 != last1) {
if ((first2 == last2) || (*first2 < *first1)) {
return false;
} else if (*first1 < *first2) {
return true;
}
}
loggers::get_instance().log("<<< security_cache_comp::operator(): true");
return !true;
}*/
++first1;
++first2;
} // End of 'while' statement
return (first2 != last2);
}
 
security_cache::security_cache(): _certificates(), _hashed_id8s() {
loggers::get_instance().log(">>> security_cache::security_cache");
60,9 → 62,9
int security_cache::get_certificate_id(const OCTETSTRING& p_hashed_id8, std::string& p_certifcate_id) const {
loggers::get_instance().log_msg(">>> security_cache::get_certificate_id: ", p_hashed_id8);
 
//std::map<OCTETSTRING, std::string>::const_iterator it = _hashed_id8s.find(p_hashed_id8);
std::vector<unsigned char> v(static_cast<const unsigned char*>(p_hashed_id8), p_hashed_id8.lengthof() + static_cast<const unsigned char*>(p_hashed_id8));
std::map<std::vector<unsigned char>, std::string>::const_iterator it = _hashed_id8s.find(v);
std::map<OCTETSTRING, std::string>::const_iterator it = _hashed_id8s.find(p_hashed_id8);
//std::vector<unsigned char> v(static_cast<const unsigned char*>(p_hashed_id8), p_hashed_id8.lengthof() + static_cast<const unsigned char*>(p_hashed_id8));
//std::map<std::vector<unsigned char>, std::string>::const_iterator it = _hashed_id8s.find(v);
if (it == _hashed_id8s.cend()) {
dump();
p_certifcate_id = "";
291,16 → 293,14
 
_certificates.insert(std::pair<std::string, std::unique_ptr<security_db_record> >(key, std::unique_ptr<security_db_record>(p)));
 
//std::map<OCTETSTRING, std::string>::const_iterator h = _hashed_id8s.find(hashed_id8);
std::vector<unsigned char> v(static_cast<const unsigned char*>(hashed_id8), hashed_id8.lengthof() + static_cast<const unsigned char*>(hashed_id8));
loggers::get_instance().log_to_hexa("security_cache::store_certificate: Converted hashed_id8: ", v.data(), v.size());
std::map<std::vector<unsigned char>, std::string>::const_iterator h = _hashed_id8s.find(v);
std::map<OCTETSTRING, std::string>::const_iterator h = _hashed_id8s.find(hashed_id8);
//std::vector<unsigned char> v(static_cast<const unsigned char*>(hashed_id8), hashed_id8.lengthof() + static_cast<const unsigned char*>(hashed_id8));
//std::map<std::vector<unsigned char>, std::string>::const_iterator h = _hashed_id8s.find(v);
if (h != _hashed_id8s.cend()) {
_hashed_id8s.erase(h);
}
//_hashed_id8s.insert(std::pair<OCTETSTRING, std::string&>(hashed_id8, key));
loggers::get_instance().log("security_cache::store_certificate: Insert %s to _hashed_id8", key.c_str());
_hashed_id8s.insert(std::pair<std::vector<unsigned char>, std::string&>(v, key));
_hashed_id8s.insert(std::pair<OCTETSTRING, std::string&>(hashed_id8, key));
//_hashed_id8s.insert(std::pair<std::vector<unsigned char>, std::string&>(v, key));
//dump();
 
327,8 → 327,8
loggers::get_instance().log_msg("security_cache::dump: public_enc_comp_key = ", p->public_enc_comp_key());
} // End of 'for' statement
//for (std::map<OCTETSTRING, std::string>::const_iterator it = _hashed_id8s.cbegin(); it != _hashed_id8s.cend(); ++it) {
for (std::map<std::vector<unsigned char>, std::string>::const_iterator it = _hashed_id8s.cbegin(); it != _hashed_id8s.cend(); ++it) {
// loggers::get_instance().log_to_hexa("security_cache::dump: Hashedid8 key = ", it->first.data(), it->first.size());
for (std::map<OCTETSTRING/*std::vector<unsigned char>*/, std::string>::const_iterator it = _hashed_id8s.cbegin(); it != _hashed_id8s.cend(); ++it) {
loggers::get_instance().log_msg("security_cache::dump: Hashedid8 key = ", it->first);
loggers::get_instance().log("security_cache::dump: Hashedid8 idx ==> %s", it->second.c_str());
} // End of 'for' statement
} // End of method dump
/branches/STF525/ccsrc/Protocols/Security/security_cache.hh
22,9 → 22,9
class INTEGER; //! TITAN forward declaration
class CHARSTRING; //! TITAN forward declaration
 
/*struct security_cache_comp {
struct security_cache_comp {
bool operator()(const OCTETSTRING& p_lhs, const OCTETSTRING& p_rhs) const;
};*/
};
 
/*!
* \class security_cache
36,8 → 36,8
protected: /*! \protectedsection */
// TODO Enforce with const security_cache_record, and const std::string
std::map<std::string, std::unique_ptr<security_db_record> > _certificates; //! List of the certificates indexed by the certificate identifier
//std::map<OCTETSTRING, std::string, security_cache_comp> _hashed_id8s; //! List of the certificates indexed by the HashedId8
std::map<std::vector<unsigned char>, std::string> _hashed_id8s; //! List of the certificates indexed by the HashedId8
std::map<OCTETSTRING, std::string, security_cache_comp> _hashed_id8s; //! List of the certificates indexed by the HashedId8
//std::map<std::vector<unsigned char>, std::string> _hashed_id8s; //! List of the certificates indexed by the HashedId8
public: /*! \publicsection */
/*!
/branches/STF525/ccsrc/Protocols/Security/security_ecc.cc
739,9 → 739,11
const BIGNUM* r = nullptr;
const BIGNUM* s = nullptr;
::ECDSA_SIG_get0(signature, &r, &s);
loggers::get_instance().log("security_ecc::sign: r size: %d", BN_num_bytes(r));
p_r_sig = int2oct(0, BN_num_bytes(r));
::BN_bn2bin(r, (unsigned char*)static_cast<const unsigned char*>(p_r_sig));
loggers::get_instance().log_msg("security_ecc::sign: r=", p_r_sig);
loggers::get_instance().log("security_ecc::sign: s size: %d", BN_num_bytes(s));
p_s_sig = int2oct(0, BN_num_bytes(s));
::BN_bn2bin(s, (unsigned char*)static_cast<const unsigned char*>(p_s_sig));
loggers::get_instance().log_msg("security_ecc::sign: s=", p_s_sig);