Rev

Rev 3349 | Details | Compare with Previous | Last modification | View Log | SVN | Bug Tracker

Rev Author Line No. Line
3177 garciay 1
/*!
2
 * \file      certificate_loader.hh
3
 * \brief     Header file for ITS certificates loader definition.
4
 * \author    ETSI STF525
5
 * \copyright ETSI Copyright Notification
6
 *            No part may be reproduced except as authorized by written permission.
7
 *            The copyright and the foregoing restriction extend to reproduction in all media.
8
 *            All rights reserved.
9
 * \version   0.1
10
 * \remark Use xxd -p -c32 <file name> to make a hexdump or do the reverse (e.g. xxd -p -c32 CERT_IUT_A_RCA.vkey)
11
 */
3033 garciay 12
#pragma once
13
 
14
#include <set>
15
#include <map>
16
#include <string>
3253 garciay 17
#include <vector>
3033 garciay 18
 
19
#include <experimental/filesystem>
20
 
21
#include "security_db_record.hh"
3350 garciay 22
#include "security_cache.hh"
3347 garciay 23
#include "security_ecc.hh"
3033 garciay 24
 
3256 garciay 25
namespace IEEE1609dot2BaseTypes {
3259 garciay 26
  class EccP256CurvePoint; //! Declare TITAN class
27
  class EccP384CurvePoint; //! Declare TITAN class
3256 garciay 28
}
29
 
3033 garciay 30
/*!
31
 * \class certificates_loader
32
 * \brief This class provides mechanism  to load the certificates from the filesystem according the struecture defined in ETSI TS 103 099
33
 * \remark Singleton pattern
34
 */
35
class certificates_loader {
3347 garciay 36
  std::string _certificateExt;                    //! COER encoding certificate extension. Default: .oer
37
  std::string _privateKeyExt;                     //! Private signing key extension. Default: .vkey
38
  std::string _privateEncKeyExt;                  //! Private cyphering key extension. Default: .ekey
3259 garciay 39
  std::experimental::filesystem::path _full_path; //! The full folder path to load certificates
40
  bool _is_cache_initialized;                     //! Set to true when certificates are successfully loaded from file system
41
  std::set<std::string> _directory_filter;        //! Directory filter (for local development purposes only)
42
  static certificates_loader* instance;           //! Unique static object reference of this class
3256 garciay 43
 
3033 garciay 44
  /*!
45
   * \brief Default private ctor
46
   */
47
  certificates_loader();
48
  /*!
49
   * \brief Default private dtor
50
   */
51
  ~certificates_loader() {
52
    if (instance != NULL) {
53
      delete instance;
54
      instance = NULL;
55
    }
56
  };
57
 
58
public: /*! \publicsection */
59
 
60
  /*!
61
   * \brief Public accessor to the single object reference
62
   */
63
  inline static certificates_loader& get_instance() {
64
    if (instance == NULL) instance = new certificates_loader();
65
    return *instance;
66
  };
67
 
68
  int build_path(const std::string& p_root_directory);
69
 
3350 garciay 70
  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);
3342 garciay 71
  //int load_certificate(std::unique_ptr<security_db_record> >& p_certificate, std::map<const OCTETSTRING, const std::string&>& p_hashed_id8s);
3038 garciay 72
  int save_certificate(const security_db_record& p_certificate);
73
 
3033 garciay 74
private:
75
  int retrieve_certificates_list(std::set<std::experimental::filesystem::path>& p_files);
76
 
3350 garciay 77
  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);
3033 garciay 78
 
3347 garciay 79
  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);
80
  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);
3033 garciay 81
}; // End of class certificates_loader