Commit ccf49d06 authored by YannGarcia's avatar YannGarcia
Browse files

CV2X#3 Validation against PKIs (Remote)

parent 710005fb
Loading
Loading
Loading
Loading
+367 −249

File changed.

Preview size limit exceeded, changes collapsed.

+17 −1
Original line number Diff line number Diff line
@@ -123,7 +123,17 @@ module LibItsPki_Pics {
  /**
   * @desc 
   */
  modulepar charstring PICS_HTTP_POST_URI_DC := "www.its.ec.org";
  modulepar charstring PICS_HTTP_POST_URI_DC := "/dc";
  
  /**
   * @desc 
   */
  modulepar charstring PICS_HTTP_POST_URI_CTL := "/ctl";
  
  /**
   * @desc 
   */
  modulepar charstring PICS_HTTP_POST_URI_CRL := "/crl";
  
  /**
   * @desc Certificate used by the Test System
@@ -264,4 +274,10 @@ module LibItsPki_Pics {

  modulepar boolean PICS_UC_SEC_05_2 := true;

  modulepar charstring PICS_DC_ENDPOINT := "http://www.etsi.org"

  modulepar charstring PICS_AA_ENDPOINT := "http://www.etsi.org"

  modulepar charstring PICS_EA_ENDPOINT := "http://www.etsi.org"

} // End of module LibItsPki_Pics
+8 −0
Original line number Diff line number Diff line
@@ -744,6 +744,14 @@ module LibItsPki_Templates {
    itsAccessPoint    := *
  } // End of template mw_ea_entry

  template (value) DcEntry m_dc_entry(
                                      in template (value) Url p_url,
                                      in template (value) HashedId8s p_cert
                                      ) := {
    url  := p_url,
    cert := p_cert
  } // End of template m_dc_entry

  template (present) DcEntry mw_dc_entry(
                                         template (present) Url p_url := ?,
                                         template (present) HashedId8s p_cert := ?
+49 −38
Original line number Diff line number Diff line
@@ -1705,12 +1705,11 @@ module LibItsPki_Functions {
                                                                                            )
                                                        );
      }

      // Secure the response
      log("f_http_build_authorization_validation_response: p_authorization_validation_response= ", p_authorization_validation_response);
      v_msg := bit2oct(encvalue(p_authorization_validation_response));
      // Encapsulte authorization validation response into EtsiTs102941Data
      v_msg := bit2oct(encvalue(m_etsiTs102941Data_authorization_validation_response(p_authorization_validation_response)));
      // Secure the response
      v_nonce := substr(f_hashWithSha256(int2oct((f_getCurrentTimeUtc() * 1000), 16)), 0, 12); // Random value
      // TODO Consider  Sha384: m_signerIdentifier_digest(f_hashedId8FromSha384(p_digest))
      if (f_build_pki_secured_response_message(p_private_key,
                                               valueof(m_signerIdentifier_digest(f_hashedId8FromSha256(p_digest))),//  in SignerIdentifier p_signer_identifier,
                                               v_msg,
@@ -3224,7 +3223,16 @@ module LibItsPki_Functions {
  
  group dc {

    function f_build_dc_ctl(
    function f_build_dc(
                        in charstring p_rca_certificate_id,
                        out EtsiTs103097Certificate p_rca_certificate
                        ) {
      log(">>> f_build_dc");

      // Load certificate
      f_readCertificate(p_rca_certificate_id, p_rca_certificate);
    }
    function f_build_ctl(
                         in charstring p_ea_certificate_id,
                         in charstring p_aa_certificate_id,
                         in charstring p_rca_certificate_id,
@@ -3234,30 +3242,32 @@ module LibItsPki_Functions {
      var EtsiTs103097Certificate v_ea_certificate;
      var EtsiTs103097Certificate v_aa_certificate;
      var EtsiTs103097Certificate v_rca_certificate;
      var Oct32 v_rca_hash;
      var CtlCommands v_ctl_commands;
      var ToBeSignedRcaCtl v_to_be_signed_rca_ctl;

      log(">>> f_build_dc_ctl");
      log(">>> f_build_ctl");

      // Load certificates
      f_readCertificate(p_ea_certificate_id, v_ea_certificate);
      f_readCertificate(p_aa_certificate_id, v_aa_certificate);
      f_readCertificate(p_rca_certificate_id, v_rca_certificate);
      // Create ctrlCommnand list
      f_getCertificateHash256(p_rca_certificate_id, v_rca_hash);
      // Create ctlCommnand list
      v_ctl_commands := {
        { add := { rca := valueof(m_root_ca_entry(v_rca_certificate)) } },
        { add := { aa := valueof(m_aa_entry(v_aa_certificate, "http://www.etsi.org")) } },
        { add := { ea := valueof(m_ea_entry(v_ea_certificate, "http://www.etsi.org")) } }
        { add := { ea := valueof(m_ea_entry(v_ea_certificate, PICS_EA_ENDPOINT)) } },
        { add := { aa := valueof(m_aa_entry(v_aa_certificate, PICS_AA_ENDPOINT)) } },
        { add := { dc := valueof(m_dc_entry(PICS_DC_ENDPOINT, { f_hashedId8FromSha256(v_rca_hash) })) } }
      };
      log("f_build_dc_ctl: v_ctl_commands= ", v_ctl_commands);
      log("f_build_ctl: v_ctl_commands= ", v_ctl_commands);
      // Build the main data structure
      p_to_be_signed_rca_ctl := valueof(m_to_be_signed_rca_full_ctl(1000, 1, v_ctl_commands));
      p_to_be_signed_rca_ctl := valueof(m_to_be_signed_rca_full_ctl(2 * f_getCurrentTime() * 1000/*us*/, 1, v_ctl_commands));

      log("<<< f_build_dc_ctl: p_to_be_signed_rca_ctl= ", p_to_be_signed_rca_ctl);
    } // End of function f_build_dc_ctl
      log("<<< f_build_ctl: p_to_be_signed_rca_ctl= ", p_to_be_signed_rca_ctl);
    } // End of function f_build_ctl

    function f_sign_dc_ctl(
                           in charstring p_issuer_certificate_id,
                           in charstring p_signer_certificate_id,
                           in ToBeSignedRcaCtl p_to_be_signed_rca_ctl,
                           out Ieee1609Dot2Data p_ieee_1609Dot2_signed_data
                           ) {
@@ -3274,8 +3284,9 @@ module LibItsPki_Functions {

      log(">>> f_sign_dc_ctl");

      f_readSigningKey(p_issuer_certificate_id, v_private_key);
      f_getCertificateHash(p_issuer_certificate_id, v_issuer);
      f_readSigningKey(p_signer_certificate_id, v_private_key);
      f_getCertificateHash(p_signer_certificate_id, v_issuer);
      f_readCertificate(p_signer_certificate_id, v_certificate);

      // Encode the main data structure
      v_etsi_ts_102941_data := valueof(m_etsiTs102941Data_to_be_signed_rca_ctl(p_to_be_signed_rca_ctl));
@@ -3286,7 +3297,7 @@ module LibItsPki_Functions {
                                        m_signedDataPayload(
                                                            m_etsiTs103097Data_unsecured(v_pki_message)
                                                            ),
                                        m_headerInfo_inner_pki_response(-, (f_getCurrentTime() * 1000)/*us*/)
                                        m_headerInfo_inner_cpoc_response(-, (f_getCurrentTime() * 1000)/*us*/)
                                        )
                       );
      v_tbs_encoded := encvalue(v_tbs);
@@ -3307,7 +3318,7 @@ module LibItsPki_Functions {
                                                                         m_signedData(
                                                                                      sha256,
                                                                                      v_tbs,
                                                                                      m_signerIdentifier_digest(v_issuer),
                                                                                      m_signerIdentifier_certificates({v_certificate}),
                                                                                      v_signature
                                                                                      )
                                                                         )
@@ -3327,7 +3338,7 @@ module LibItsPki_Functions {
                                                                         m_signedData(
                                                                                      sha384,
                                                                                      v_tbs,
                                                                                      m_signerIdentifier_digest(v_issuer),
                                                                                      m_signerIdentifier_certificates({v_certificate}),
                                                                                      v_signature
                                                                                      )
                                                                         )
@@ -4371,7 +4382,7 @@ module LibItsPki_Functions {
        [] a_await_dc_http_request_from_iut(
                                            mw_http_request(
                                                            mw_http_request_post(
                                                                                 PICS_HTTP_POST_URI_DC
                                                                                 PICS_HTTP_POST_URI_CRL
                                                                                 )),
                                            v_request
                                            ) {
@@ -4387,7 +4398,7 @@ module LibItsPki_Functions {
          f_init_default_headers_list(-, "ca_response", v_headers);
          
          // Send message
          f_build_dc_ctl(
          f_build_ctl(
                         p_rca_certificate_id,
                         p_aa_certificate_id,
                         p_ea_certificate_id,