Commit b31f565a authored by Yann Garcia's avatar Yann Garcia
Browse files

Add unit tests

parent 6c6c9f38
Loading
Loading
Loading
Loading
+0 −13
Original line number Original line Diff line number Diff line
@@ -47,17 +47,4 @@ module LibItsHttp_BinaryTemplates {
    ieee1609dot2_data := p_ieee1609dot2_data
    ieee1609dot2_data := p_ieee1609dot2_data
  } // End of template mw_binary_body_ieee1609dot2_data
  } // End of template mw_binary_body_ieee1609dot2_data
  
  
  // Move to Pki
//  template (present) BinaryBody mw_binary_body_innerEcRequest(
//                                                              template (present) InnerEcRequest p_innerEcRequest := ?
//  ) := {
//    innerEcRequest := p_innerEcRequest
//  } // End of template mw_binary_body_innerEcRequest
//  
//  template (present) BinaryBody mw_binary_body_innerEcResponse(
//                                                               template (present) InnerEcResponse p_innerEcResponse := ?
//  ) := {
//    innerEcResponse := p_innerEcResponse
//  } // End of template mw_binary_body_innerEcResponse
//  
} // End of module LibItsHttp_BinaryTemplates
} // End of module LibItsHttp_BinaryTemplates
+34 −24
Original line number Original line Diff line number Diff line
@@ -188,13 +188,14 @@ module LibItsPki_Functions {
  group ac_port {
  group ac_port {


    function f_sendAcPkiPrimitive(
    function f_sendAcPkiPrimitive(
                                  in charstring p_certificate,
                                  in octetstring p_private_key,
                                  in octetstring p_private_key,
                                  in octetstring p_publicKeyCompressed,
                                  in octetstring p_publicKeyCompressed,
                                  in integer p_compressedMode
                                  in integer p_compressedMode
                                  ) runs on ItsPki {
                                  ) runs on ItsPki {
      var AcSetSecurityData v_ac_set_security_data;
      var AcSetSecurityData v_ac_set_security_data;
      
      
      v_ac_set_security_data := { PICS_TS_CERTIFICATE_ID, PICS_IUT_CERTIFICATE_ID, p_private_key, p_publicKeyCompressed, p_compressedMode };
      v_ac_set_security_data := { p_certificate, PICS_IUT_CERTIFICATE_ID, p_private_key, p_publicKeyCompressed, p_compressedMode };
      acPort.send(AcPkiPrimitive: { acSetSecurityData := v_ac_set_security_data });
      acPort.send(AcPkiPrimitive: { acSetSecurityData := v_ac_set_security_data });
      tc_ac.start;
      tc_ac.start;
      alt {
      alt {
@@ -278,26 +279,26 @@ module LibItsPki_Functions {


  group http {
  group http {


    function f_http_build_enrolment_request(
    function f_http_build_inner_ec_request(
                                            out octetstring p_private_key,
                                            out octetstring p_private_key,
                                            out octetstring p_publicKeyX,
                                            out octetstring p_publicKeyY,
                                            out octetstring p_publicKeyCompressed,
                                            out octetstring p_publicKeyCompressed,
                                            out integer p_compressedMode,
                                            out integer p_compressedMode,
                                            out Ieee1609Dot2Data p_ieee1609dot2_signed_and_encrypted_data,
                                            out Ieee1609Dot2Data p_ieee1609dot2_signed_and_encrypted_data,
                                            out Oct32 p_hash_inner_ec_request_signed_for_pop
                                            out Oct32 p_hash_inner_ec_request_signed_for_pop
                                            ) runs on ItsPkiHttp {
                                            ) runs on ItsPkiHttp {
      var octetstring v_publicKeyX;
      var octetstring v_publicKeyY
      var InnerEcRequest v_inner_ec_request;
      var InnerEcRequest v_inner_ec_request;
      var Ieee1609Dot2Data v_inner_ec_request_signed_for_pop;
      var Ieee1609Dot2Data v_inner_ec_request_signed_for_pop;
      var bitstring v_inner_ec_request_signed_for_pop_msg;
      var bitstring v_inner_ec_request_signed_for_pop_msg;
      
      
      if (f_generate_inner_ec_request(p_private_key, p_publicKeyX, p_publicKeyY, p_publicKeyCompressed, p_compressedMode, v_inner_ec_request) == false) {
      if (f_generate_inner_ec_request(p_private_key, p_publicKeyCompressed, p_compressedMode, v_inner_ec_request) == false) {
        log("*** f_http_build_enrolment_request: ERROR: Failed to generate InnerEcRequest ***");
        log("*** f_http_build_inner_ec_request: ERROR: Failed to generate InnerEcRequest ***");
        f_selfOrClientSyncAndVerdict("error", e_error);
        f_selfOrClientSyncAndVerdict("error", e_error);
      }
      }
      // Generate InnerEcRequestSignedForPoP
      // Generate InnerEcRequestSignedForPoP
      if (f_generate_inner_ec_request_signed_for_pop(p_private_key, v_inner_ec_request, v_inner_ec_request_signed_for_pop) == false) {
      if (f_generate_inner_ec_request_signed_for_pop(p_private_key, v_inner_ec_request, v_inner_ec_request_signed_for_pop) == false) {
        log("*** f_http_build_enrolment_request: ERROR: Failed to generate InnerEcRequestSignedForPop ***");
        log("*** f_http_build_inner_ec_request: ERROR: Failed to generate InnerEcRequestSignedForPop ***");
        f_selfOrClientSyncAndVerdict("error", e_error);
        f_selfOrClientSyncAndVerdict("error", e_error);
      }
      }
      // Secure InnerEcRequestSignedForPoP message
      // Secure InnerEcRequestSignedForPoP message
@@ -305,18 +306,16 @@ module LibItsPki_Functions {
      // Prepae for getting the 16 most bytes of SHA256 of InnerEcRequestSignedForPop
      // Prepae for getting the 16 most bytes of SHA256 of InnerEcRequestSignedForPop
      p_hash_inner_ec_request_signed_for_pop := f_hashWithSha256(bit2oct(v_inner_ec_request_signed_for_pop_msg));
      p_hash_inner_ec_request_signed_for_pop := f_hashWithSha256(bit2oct(v_inner_ec_request_signed_for_pop_msg));
      if (f_build_pki_secured_message(vc_eaPrivateKey, valueof(m_signerIdentifier_self), vc_eaHashedId8, p_publicKeyCompressed, p_compressedMode, bit2oct(v_inner_ec_request_signed_for_pop_msg), p_ieee1609dot2_signed_and_encrypted_data) == false) {
      if (f_build_pki_secured_message(vc_eaPrivateKey, valueof(m_signerIdentifier_self), vc_eaHashedId8, p_publicKeyCompressed, p_compressedMode, bit2oct(v_inner_ec_request_signed_for_pop_msg), p_ieee1609dot2_signed_and_encrypted_data) == false) {
        log("*** f_http_build_enrolment_request: ERROR: Failed to generate InnerEcRequestSignedForPop ***");
        log("*** f_http_build_inner_ec_request: ERROR: Failed to generate InnerEcRequestSignedForPop ***");
        f_selfOrClientSyncAndVerdict("error", e_error);
        f_selfOrClientSyncAndVerdict("error", e_error);
      }
      }
      log("*** f_http_build_enrolment_request: DEBUG: v_inner_ec_request_signed_for_pop_msg= ", v_inner_ec_request_signed_for_pop_msg);
      log("*** f_http_build_inner_ec_request: DEBUG: v_inner_ec_request_signed_for_pop_msg= ", v_inner_ec_request_signed_for_pop_msg);
      log("*** f_http_build_enrolment_request: DEBUG: p_ieee1609dot2_signed_and_encrypted_data= ", p_ieee1609dot2_signed_and_encrypted_data);
      log("*** f_http_build_inner_ec_request: DEBUG: p_ieee1609dot2_signed_and_encrypted_data= ", p_ieee1609dot2_signed_and_encrypted_data);
      log("*** f_http_build_enrolment_request: DEBUG: p_hash_inner_ec_request_signed_for_pop= ", p_hash_inner_ec_request_signed_for_pop);
      log("*** f_http_build_inner_ec_request: DEBUG: p_hash_inner_ec_request_signed_for_pop= ", p_hash_inner_ec_request_signed_for_pop);
    } // End of function f_http_build_enrolment_request
    } // End of function f_http_build_inner_ec_request


    function f_http_build_invalid_enrolment_request(
    function f_http_build_invalid_enrolment_request(
                                                    out octetstring p_private_key,
                                                    out octetstring p_private_key,
                                                    out octetstring p_publicKeyX,
                                                    out octetstring p_publicKeyY,
                                                    out octetstring p_publicKeyCompressed,
                                                    out octetstring p_publicKeyCompressed,
                                                    out integer p_compressedMode,
                                                    out integer p_compressedMode,
                                                    out Ieee1609Dot2Data p_ieee1609dot2_signed_and_encrypted_data,
                                                    out Ieee1609Dot2Data p_ieee1609dot2_signed_and_encrypted_data,
@@ -326,7 +325,7 @@ module LibItsPki_Functions {
      var Ieee1609Dot2Data v_inner_ec_request_signed_for_pop;
      var Ieee1609Dot2Data v_inner_ec_request_signed_for_pop;
      var bitstring v_inner_ec_request_signed_for_pop_msg;
      var bitstring v_inner_ec_request_signed_for_pop_msg;
      
      
      if (f_generate_inner_ec_request(p_private_key, p_publicKeyX, p_publicKeyY, p_publicKeyCompressed, p_compressedMode, v_inner_ec_request) == false) {
      if (f_generate_inner_ec_request(p_private_key, p_publicKeyCompressed, p_compressedMode, v_inner_ec_request) == false) {
        log("*** f_http_build_invalid_enrolment_request: ERROR: Failed to generate InnerEcRequest ***");
        log("*** f_http_build_invalid_enrolment_request: ERROR: Failed to generate InnerEcRequest ***");
        f_selfOrClientSyncAndVerdict("error", e_error);
        f_selfOrClientSyncAndVerdict("error", e_error);
      }
      }
@@ -346,6 +345,15 @@ module LibItsPki_Functions {
      log("*** f_http_build_invalid_enrolment_request: DEBUG: p_ieee1609dot2_signed_and_encrypted_data = ", p_ieee1609dot2_signed_and_encrypted_data);
      log("*** f_http_build_invalid_enrolment_request: DEBUG: p_ieee1609dot2_signed_and_encrypted_data = ", p_ieee1609dot2_signed_and_encrypted_data);
    } // End of function f_http_build_invalid_enrolment_request
    } // End of function f_http_build_invalid_enrolment_request
    
    
    function f_http_build_authorization_validation_request(
                                                    out octetstring p_private_key,
                                                    out octetstring p_publicKeyCompressed,
                                                    out integer p_compressedMode,
                                                    out Ieee1609Dot2Data p_ieee1609dot2_signed_and_encrypted_data
                                                    ) runs on ItsPkiHttp {
      log("*** f_http_build_invalid_enrolment_request: DEBUG: p_ieee1609dot2_signed_and_encrypted_data = ", p_ieee1609dot2_signed_and_encrypted_data);
    }
    
  } // End of group http
  } // End of group http


  group generate_certificates {
  group generate_certificates {
@@ -460,18 +468,18 @@ module LibItsPki_Functions {
    
    
    function f_generate_inner_ec_request(
    function f_generate_inner_ec_request(
                                         out octetstring p_private_key,
                                         out octetstring p_private_key,
                                         out octetstring p_publicKeyX,
                                         out octetstring p_publicKeyY,
                                         out octetstring p_publicKeyCompressed,
                                         out octetstring p_publicKeyCompressed,
                                         out integer p_compressedMode,
                                         out integer p_compressedMode,
                                         out InnerEcRequest p_inner_ec_request
                                         out InnerEcRequest p_inner_ec_request
                                         ) return boolean {
                                         ) return boolean {
      // Local variables
      // Local variables
      var Oct32 v_publicKeyX;
      var Oct32 v_publicKeyY;
      var EccP256CurvePoint v_eccP256_curve_point;
      var EccP256CurvePoint v_eccP256_curve_point;


      log (">>> f_generate_inner_ec_request");
      log (">>> f_generate_inner_ec_request");
      // Generate keys for the certificate to be requested
      // Generate keys for the certificate to be requested
      if (f_generate_key_pair_nistp256(p_private_key, p_publicKeyX, p_publicKeyY, p_publicKeyCompressed, p_compressedMode) == false) {
      if (f_generate_key_pair_nistp256(p_private_key, v_publicKeyX, v_publicKeyY, p_publicKeyCompressed, p_compressedMode) == false) {
        log ("f_generate_inner_ec_request: failed to generate keys");
        log ("f_generate_inner_ec_request: failed to generate keys");
        return false;
        return false;
      }
      }
@@ -588,14 +596,14 @@ module LibItsPki_Functions {
                                         in HashedId8 p_eaHashedId8,
                                         in HashedId8 p_eaHashedId8,
                                         in boolean p_itss_privacy,
                                         in boolean p_itss_privacy,
                                         out octetstring p_private_enc_key,
                                         out octetstring p_private_enc_key,
                                         out octetstring p_publicEncKeyX,
                                         out octetstring p_publicEncKeyY,
                                         out octetstring p_publicEncKeyCompressed,
                                         out octetstring p_publicEncKeyCompressed,
                                         out integer p_compressedMode,
                                         out integer p_compressedMode,
                                         out InnerAtRequest p_inner_at_request,
                                         out InnerAtRequest p_inner_at_request,
                                         out Ieee1609Dot2Data p_inner_at_request_data
                                         out Ieee1609Dot2Data p_inner_at_request_data
                                         ) return boolean {
                                         ) return boolean {
      // Local variables
      // Local variables
      var octetstring public_enc_key_x;
      var octetstring public_enc_key_y;
      var template (value) EccP256CurvePoint v_eccP256_curve_point;
      var template (value) EccP256CurvePoint v_eccP256_curve_point;
      var Oct32 v_hmac_key;
      var Oct32 v_hmac_key;
      var octetstring v_message_to_tag;
      var octetstring v_message_to_tag;
@@ -607,7 +615,7 @@ module LibItsPki_Functions {
      var Ieee1609Dot2Data v_signed_ec_signature;
      var Ieee1609Dot2Data v_signed_ec_signature;
      
      
      // Generate encryption keys for the certificate to be requested
      // Generate encryption keys for the certificate to be requested
      if (f_generate_key_pair_nistp256(p_private_enc_key, p_publicEncKeyX, p_publicEncKeyY, p_publicEncKeyCompressed, p_compressedMode) == false) {
      if (f_generate_key_pair_nistp256(p_private_enc_key, public_enc_key_x, public_enc_key_y, p_publicEncKeyCompressed, p_compressedMode) == false) {
        return false;
        return false;
      }
      }
      if (p_compressedMode == 0) {
      if (p_compressedMode == 0) {
@@ -785,14 +793,16 @@ module LibItsPki_Functions {
                                                         in Certificate p_certificate,
                                                         in Certificate p_certificate,
                                                         out AuthorizationValidationRequest p_authorization_validation_request
                                                         out AuthorizationValidationRequest p_authorization_validation_request
                                                         ) return boolean {
                                                         ) return boolean {
      // TODO
      p_authorization_validation_request.sharedAtRequest := p_inner_at_request.sharedAtRequest;
      return false;
      p_authorization_validation_request.ecSignature := p_inner_at_request.ecSignature;
      
      return true;
    } // End of function f_generate_authorization_validation_request
    } // End of function f_generate_authorization_validation_request
    
    
    function f_generate_authorization_validation_response(
    function f_generate_authorization_validation_response(
                                                          in InnerAtRequest p_inner_at_request,
                                                          in InnerAtRequest p_inner_at_request,
                                                          in Certificate p_certificate,
                                                          in Certificate p_certificate,
                                                          out AuthorizationValidationRequest p_authorization_validation_request
                                                          out AuthorizationValidationResponse p_authorization_validation_response
                                                          ) return boolean {
                                                          ) return boolean {
      // TODO
      // TODO
      return false;
      return false;
+11 −1
Original line number Original line Diff line number Diff line
@@ -21,10 +21,20 @@ module LibItsPki_Pics {
  modulepar charstring PICS_IUT_CERTIFICATE_ID := "CERT_IUT_A_EA";
  modulepar charstring PICS_IUT_CERTIFICATE_ID := "CERT_IUT_A_EA";


  /**
  /**
   * @desc Certificate used by the Test System
   * @desc Certificate used by the Test System acting as ITS-S
   */
   */
  modulepar charstring PICS_TS_CERTIFICATE_ID := "CERT_TS_A_EA";
  modulepar charstring PICS_TS_CERTIFICATE_ID := "CERT_TS_A_EA";
  
  
  /**
   * @desc Certificate used by the Test System acting as EA
   */
  modulepar charstring PICS_TS_EA_CERTIFICATE_ID := "CERT_TS_A_EA";
  
  /**
   * @desc Certificate used by the Test System acting as AA
   */
  modulepar charstring PICS_TS_AA_CERTIFICATE_ID := "CERT_TS_A_EA";
  
  /**
  /**
   * @desc Certificate used by the Test System
   * @desc Certificate used by the Test System
   */
   */
+6 −1
Original line number Original line Diff line number Diff line
@@ -78,6 +78,11 @@ module LibItsPki_Templates {
                                                                            ) modifies m_etsiTs103097Data_encrypted := {
                                                                            ) modifies m_etsiTs103097Data_encrypted := {
  } // End of template m_authorizationValidationRequestMessage
  } // End of template m_authorizationValidationRequestMessage
  
  
  template (present) EtsiTs103097Data mw_authorizationValidationResponseMessage(
                                                                                template (present) EncryptedData p_encryptedData := ?
                                                                                ) modifies mw_etsiTs103097Data_encrypted := {
  } // End of template mw_authorizationValidationResponseMessage
  
  template (present) EnrolmentRequestMessage mw_enrolmentRequestMessage(
  template (present) EnrolmentRequestMessage mw_enrolmentRequestMessage(
                                                                        template (present) EncryptedData p_encryptedData := ?
                                                                        template (present) EncryptedData p_encryptedData := ?
                                                                        ) modifies mw_etsiTs103097Data_encrypted := {
                                                                        ) modifies mw_etsiTs103097Data_encrypted := {