Commit 15ed5690 authored by garciay's avatar garciay
Browse files

STF545: Execute first EA tests

parent aabcd1ce
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -141,6 +141,9 @@ module LibItsCommon_TypesAndValues {
        encode "AdapterControl"
    }

    /**
     * @see ETSI TS 102 965 Intelligent Transport Systems (ITS); Application Object Identifier (ITS-AID); Registration list ETSI ITS registration list
     */
    group securityConstants {
		const integer c_its_aid_CAM   := 36; 
		const integer c_its_aid_DENM  := 37; 
@@ -149,6 +152,7 @@ module LibItsCommon_TypesAndValues {
		const integer c_its_aid_IVI   := 139; 
    const integer c_its_aid_TLC   := 140;
    const integer c_its_aid_GN    := 141;
		const integer c_its_aid_SCR   := 36; // Secured Certificate Request
    }
}
with {
+31 −23
Original line number Diff line number Diff line
@@ -3,10 +3,18 @@ module LibItsPki_EncdecDeclarations {
  // LibIts
  import from EtsiTs102941BaseTypes language "ASN.1:1997" all;
  import from EtsiTs102941TypesEnrolment language "ASN.1:1997" all;
  import from EtsiTs102941MessagesItss language "ASN.1:1997" all;
  import from EtsiTs103097Module language "ASN.1:1997" all;
  
  import from LibItsSecurity_TypesAndValues all;
    
  external function fx_enc_EtsiTs102941Data(in EtsiTs102941MessagesItss.EtsiTs102941Data p_etsi_ts_102941_data) return bitstring
  with {extension "prototype(convert) encode(PER)"}


  external function fx_dec_EtsiTs102941Data(inout bitstring b, out EtsiTs102941MessagesItss.EtsiTs102941Data p_etsi_ts_102941_data)return integer
  with {extension "prototype(sliding) decode(PER)"}
  
  /**
   * @desc Encoding function for EtsiTs102941TypesEnrolment InnerEcRequest
   * @param p The certificate to encode
+97 −30
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ module LibItsPki_Functions {
  import from CAM_PDU_Descriptions language "ASN.1:1997" all;
  
  // LibItsCommon
  import from LibItsCommon_TestSystem all;
  import from LibItsCommon_TypesAndValues all;
  import from LibItsCommon_Functions all;
  import from LibItsCommon_ASN1_NamedNumbers all;
  import from LibItsCommon_Pixits all;
@@ -128,7 +128,7 @@ module LibItsPki_Functions {
  
  group inner_ec_xxx {
    
    function f_generate_innerEcRequestSignedForPop(
    function f_generate_inner_ec_request(
                                         out Oct32 p_private_key,
                                         out Oct32 p_publicKeyX,
                                         out Oct32 p_publicKeyY,
@@ -152,10 +152,10 @@ module LibItsPki_Functions {
      } else {
        v_eccP256_curve_point := m_eccP256CurvePoint_compressed_y_1(p_publicKeyCompressed);
      }
      // Build the Proof of Possession InnerEcRequestSignedForPop
      // Build the Proof of Possession InnerEcRequest
      p_inner_ec_request := valueof(
                                    m_innerEcRequest(
                                                    "CanonicalItsId",
                                                     "CanonicalItsId", // TODO Use PIXIT
                                                     m_publicKeys(
                                                                  m_publicVerificationKey_ecdsaNistP256(v_eccP256_curve_point),
                                                                  m_encryptionKey(
@@ -165,40 +165,91 @@ module LibItsPki_Functions {
                                                                  ),
                                                     m_certificateSubjectAttributes(
                                                                                    { // ETSI TS 102 965 Table A.1: ETSI ITS standardized ITS-AIDs
                                                                                      valueof(m_appPermissions(36, { bitmapSsp := '830001'O })), 
                                                                                      valueof(m_appPermissions(37, { bitmapSsp := '830001'O })) 
                                                                                      valueof(m_appPermissions(36, { bitmapSsp := '830001'O })), // TODO Use PIXIT
                                                                                      valueof(m_appPermissions(37, { bitmapSsp := '830001'O })) // TODO Use PIXIT
                                                                                    },
                                                                                    m_validityPeriod(
                                                                                                             17469212,
                                                                                                             m_duration_years(10)
                                                                                                             m_duration_years(10) // TODO Use PIXIT
                                                                                                            ),
                                                                                    m_geographicRegion_identifiedRegion(
                                                                                                                                {
                                                                                                                                  m_identifiedRegion_country_only(12), 
                                                                                                                                  m_identifiedRegion_country_only(34)
                                                                                                                                  m_identifiedRegion_country_only(12), // TODO Use PIXIT
                                                                                                                                  m_identifiedRegion_country_only(34) // TODO Use PIXIT
                                                                                                                                }
                                                                                                                               ),
                                                                                    'C0'O
                                                                                    'C0'O // TODO Use PIXIT
                                                                                   )
                                            )
                                    );
      
      return true;
    } // End of function f_generate_innerEcRequestSignedForPop
    } // End of function f_generate_inner_ec_request
    
    function f_buildPkiSecuredinnerEcRequestSignedForPop(
    function f_generate_inner_ec_request_signed_for_pop(
                                                        in Oct32 p_private_key,
                                                        in InnerEcRequest p_inner_ec_request,
                                                        out Ieee1609Dot2Data p_inner_ec_request_signed_for_pop
    ) return boolean {
      // Local variables
      var template (value) EccP256CurvePoint v_eccP256_curve_point;
      var octetstring v_encoded_inner_ec_request;
      var template (value) ToBeSignedData v_tbs;
      var Oct32 v_tbs_signed;
      
      // Encode it
      v_encoded_inner_ec_request := bit2oct(encvalue(p_inner_ec_request));
      // Signed the encoded InnerEcRequestSignedForPop
      v_tbs := m_toBeSignedData(
                                m_signedDataPayload(
                                                    m_etsiTs103097Data_unsecured(
                                                                                 v_encoded_inner_ec_request
                                                                                 )
                                                   ),
                                m_headerInfo_inner_ec_request(
                                                              c_its_aid_SCR,
                                                              f_getCurrentTime())
                               );
      // Signed the encoded InnerEcRequestSignedForPop
      v_tbs_signed := f_signWithEcdsaNistp256WithSha256(bit2oct(encvalue(v_tbs)), int2oct(0, 32), p_private_key);
      // Finalyse signed InnerEcRequestSignedForPop
      p_inner_ec_request_signed_for_pop := valueof(
                                                   m_etsiTs103097Data_signed(
                                                                             m_signedData(
                                                                                          sha256,
                                                                                          v_tbs,
                                                                                          m_signerIdentifier_self,
                                                                                          m_signature_ecdsaNistP256(
                                                                                                                    m_ecdsaP256Signature(
                                                                                                                                         m_eccP256CurvePoint_x_only(
                                                                                                                                                                    substr(v_tbs_signed, 0, 32)
                                                                                                                                                                    ),
                                                                                                                                         substr(v_tbs_signed, 32, 32)
                                                                                                                                         )
                                                                                                                    )
                                                                                          )
                                                                             )
                                                   );
      return true;
    } // End of function f_generate_inner_ec_request_signed_for_pop
    
  } // End of group inner_ec_xxx

  group pki_functions {
    
    function f_build_pki_secured_message(
                                         in Oct32 p_private_key,
                                         in Oct32 p_publicKeyCompressed,
                                         in integer p_compressedMode,
                                                         in InnerEcRequest p_inner_ec_request, 
                                         in octetstring p_pki_message, 
                                         out Ieee1609Dot2Data p_ieee1609dot2_signed_and_encrypted_data
                                         ) return boolean {
      // Local variables
      var template (value) EccP256CurvePoint v_eccP256_curve_point;
      var octetstring v_encoded_inner_ec_request;
      var template (value) ToBeSignedData v_tbs;
      var Oct32 v_tbs_signed;
      var template (value) Ieee1609Dot2Data v_ieee1609dot2_signed_data;
      var octetstring v_encoded_inner_ec_request;
      var Oct12 v_nonce;
      var Oct16 v_authentication_vector;
      var Oct16 v_encrypted_sym_key;
@@ -207,12 +258,10 @@ module LibItsPki_Functions {
      var HashedId8 v_recipientId;
      var octetstring v_encrypted_inner_ec_request;
      
      // Encode it
      v_encoded_inner_ec_request := bit2oct(encvalue(p_inner_ec_request));
      // Signed the encoded InnerEcRequestSignedForPop
      v_tbs := m_toBeSignedData(
                                m_signedDataPayload(
                                                    m_etsiTs103097Data_unsecured(v_encoded_inner_ec_request)
                                                    m_etsiTs103097Data_unsecured(p_pki_message)
                                                   ),
                                m_headerInfo_inner_ec_request(12345, f_getCurrentTime()) // TODO Use PIXIT
                               );
@@ -223,7 +272,7 @@ module LibItsPki_Functions {
                                                              m_signedData(
                                                                           sha256,
                                                                           v_tbs,
                                                                           m_signerIdentifier_self,
                                                                           m_signerIdentifier_self, // TODO ETSI TS 102 941 Clause 6.2.3.2.1 bullet 5 dash 3: Using disgest of EC if non canonical indentifier
                                                                           m_signature_ecdsaNistP256(
                                                                                                     m_ecdsaP256Signature(
                                                                                                                          m_eccP256CurvePoint_x_only(
@@ -270,7 +319,25 @@ module LibItsPki_Functions {
                                                         );
      
      return true;
    } // End of function f_buildPkiSecuredinnerEcRequestSignedForPop
    } // End of function f_build_pki_secured_message
    
    function f_generate_inner_ec_response(
                                          in Oct32 p_inner_ec_request_hashed_id,
                                          in EtsiTs103097Certificate p_certificate,
                                          out InnerEcResponse p_inner_ec_response
                                         ) return boolean {
      // Local variables
      
      // Build the Proof of Possession InnerEcResponse
      p_inner_ec_response := valueof(
                                     m_innerEcResponse_ok(
                                                          substr(p_inner_ec_request_hashed_id, 0, 16),
                                                          p_certificate
                                                          )
                                     );
      
      return true;
    } // End of function f_generate_inner_ec_response
    
  } // End of group inner_ec_xxx
  
+152 −123
Original line number Diff line number Diff line
@@ -32,6 +32,24 @@ module LibItsPki_Templates {
  // LibItsSecurity
  import from LibItsSecurity_Templates all;

  template (value) EtsiTs102941Data m_etsiTs102941Data_inner_ec_request_signed_for_pop(
                                                                                       in template (value) InnerEcRequestSignedForPop p_inner_ec_request_signed_for_pop
                                                                                       ) := {
    version := 1,
    content := {
      enrolmentRequest := p_inner_ec_request_signed_for_pop
    }
  } // End of template m_etsiTs102941Data_inner_ec_request_signed_for_pop
  
  template (value) EtsiTs102941Data m_etsiTs102941Data_inner_ec_response(
                                                                         in template (value) InnerEcResponse p_inner_ec_response
                                                                         ) := {
    version := 1,
    content := {
      enrolmentResponse := p_inner_ec_response
    }
  } // End of template m_etsiTs102941Data_inner_ec_response

  template (value) EnrolmentRequestMessage m_enrolmentRequestMessage(
                                                                     in template (value) EncryptedData p_encryptedData
                                                                     ) modifies m_etsiTs103097Data_encrypted := {
@@ -57,7 +75,7 @@ module LibItsPki_Templates {
  template (value) InnerEcRequest m_innerEcRequest(
                                                   in template (value) charstring p_itsId,
                                                   in template (value) PublicKeys p_publicKeys,
                                                     in template (value) CertificateSubjectAttributes p_requestedSubjectAttributes //(WITH COMPONENTS{certIssuePermissions ABSENT}),
                                                   in template (value) CertificateSubjectAttributes p_requestedSubjectAttributes
                                                   ) := {
    itsId                      := p_itsId,
    certificateFormat          := 1,
@@ -65,6 +83,17 @@ module LibItsPki_Templates {
    requestedSubjectAttributes := p_requestedSubjectAttributes
  } // End of template m_innerEcRequest
  
  template (present) InnerEcRequest mw_innerEcRequest(
                                                      template (present) charstring p_itsId := ?,
                                                      template (present) PublicKeys p_publicKeys := ?,
                                                      template (present) CertificateSubjectAttributes p_requestedSubjectAttributes := ?
                                                      ) := {
    itsId                      := p_itsId,
    certificateFormat          := 1,
    publicKeys                 := p_publicKeys,
    requestedSubjectAttributes := p_requestedSubjectAttributes
  } // End of template mw_innerEcRequest
  
  template (omit) PublicKeys m_publicKeys(
                                          in template (value) PublicVerificationKey p_verificationKey,
                                          in template (omit) PublicEncryptionKey p_encryptionKey := omit