TestCodec_SecuredMessages.ttcn 26.5 KB
Newer Older
garciay's avatar
garciay committed
/*
 * @author
 *         
 * @version
 *         1.0
 * @desc
 *         
 * @remark
 *         
 * @see
 *         
 */ 
module TestCodec_SecuredMessages {
    
garciay's avatar
garciay committed
  // LibCommon
  import from LibCommon_BasicTypesAndValues all;
  import from LibCommon_DataStrings all;
garciay's avatar
garciay committed
    
garciay's avatar
garciay committed
  // LibIts
  import from IEEE1609dot2BaseTypes language "ASN.1:1997" all;
  import from IEEE1609dot2 language "ASN.1:1997" all;
  import from EtsiTs103097Module language "ASN.1:1997" all;
garciay's avatar
garciay committed
    
garciay's avatar
garciay committed
  // LibItsGeoNetworking
  import from LibItsGeoNetworking_EncdecDeclarations all;
  import from LibItsGeoNetworking_TypesAndValues all;
  import from LibItsGeoNetworking_Templates all;
garciay's avatar
garciay committed
  // LibItsSecurity
  import from LibItsSecurity_EncdecDeclarations all;
  import from LibItsSecurity_TypesAndValues all;
  import from LibItsSecurity_Templates all;
  import from LibItsSecurity_Pixits all;
garciay's avatar
garciay committed
    
garciay's avatar
garciay committed
  // TestCodec
  import from TestCodec_TestAndSystem all;
garciay's avatar
garciay committed
    
garciay's avatar
garciay committed
  testcase tc_ssp_cam_1() runs on TCType system TCType {
    var SspCAM v_sspCAM := valueof(m_sspCAMContainer_sign_all);
    var bitstring v_encMsg;
garciay's avatar
garciay committed
  v_encMsg := encvalue(valueof(v_sspCAM));
    if (lengthof(v_encMsg) != 32) {
      setverdict(fail);
    } else {
      var SspCAM v_sspCAM_dec;
      if (decvalue(v_encMsg, v_sspCAM_dec) != 0) {
        setverdict(fail);
      } else if (not(match(v_sspCAM_dec, v_sspCAM))) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
    }
  } // End of testcase tc_ssp_cam_1
garciay's avatar
garciay committed
  testcase tc_ssp_cam_2() runs on TCType system TCType {
    var SspCAM v_sspCAM := valueof(m_sspCAMContainer_sign_all);
    var bitstring v_encMsg;
garciay's avatar
garciay committed
  v_sspCAM.publicTransport := '0'B;
  v_sspCAM.specialTransport := '0'B;
  v_sspCAM.dangerousGoods := '0'B;
  v_sspCAM.roadwork := '0'B;
  v_sspCAM.rescue := '0'B;
  v_encMsg := encvalue(valueof(v_sspCAM));
    if (lengthof(v_encMsg) != 32) {
      setverdict(fail);
    } else {
      var SspCAM v_sspCAM_dec;
      if (decvalue(v_encMsg, v_sspCAM_dec) != 0) {
        setverdict(fail);
      } else if (not(match(v_sspCAM_dec, v_sspCAM))) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
    }
  } // End of testcase tc_ssp_cam_2
garciay's avatar
garciay committed
  testcase tc_ssp_denm() runs on TCType system TCType {
    var SspDENM v_sspDENM := valueof(m_sspDENMContainer_sign_all);
    var bitstring v_encMsg;
garciay's avatar
garciay committed
  v_encMsg := encvalue(valueof(v_sspDENM));
    if (lengthof(v_encMsg) != 32) {
      setverdict(fail);
    } else {
      var SspDENM v_sspDENM_dec;
      if (decvalue(v_encMsg, v_sspDENM_dec) != 0) {
        setverdict(fail);
      } else if (not(match(v_sspDENM_dec, v_sspDENM))) {
        setverdict(fail);
      } else {
        setverdict(pass);
      }
    }
  } // End of testcase tc_ssp_denm
garciay's avatar
garciay committed
  testcase tc_secured_message_unsecured() runs on TCType system TCType {
    var template (value) EtsiTs103097Data v_unsigned_data;
    var EtsiTs103097Data v_unsigned_data_dec;
garciay's avatar
garciay committed
    var bitstring v_encMsg;
garciay's avatar
garciay committed
        
  v_unsigned_data := m_etsiTs103097Data_unsecured(
garciay's avatar
garciay committed
                                                 'CAFEDECA'O
                                                 );
  v_encMsg := encvalue(valueof(v_unsigned_data));
garciay's avatar
garciay committed
    setverdict(pass, "Encoding passed.");
    if (decvalue(v_encMsg, v_unsigned_data_dec) != 0) {
garciay's avatar
garciay committed
      setverdict(fail);
      stop;
    } else if (not(match(valueof(v_unsigned_data), v_unsigned_data_dec))) {
garciay's avatar
garciay committed
      setverdict(fail);
      stop;
    }
    setverdict(pass, "Decoding passed.");
garciay's avatar
garciay committed
  } // End of testcase tc_secured_message_unsecured
garciay's avatar
garciay committed
  testcase tc_secured_message_signed_1() runs on TCType system TCType {
    var template (value) EtsiTs103097Data v_signed_data;
    var EtsiTs103097Data v_signed_data_dec;
garciay's avatar
garciay committed
    var octetstring v_raw_payload_to_be_signed := 'CAFFEDECA0000001'O;
    var HashedId8 v_digest := '0000000000000000'O;
    var bitstring v_encMsg;
  v_signed_data := m_etsiTs103097Data_signed(
garciay's avatar
garciay committed
                                              m_signedData(
                                                           sha256,
                                                           m_toBeSignedData(
                                                                            m_signedDataPayload(
                                                                                                m_etsiTs103097Data_unsecured(v_raw_payload_to_be_signed)
                                                                                                ),
                                                                            m_headerInfo_gn(
                                                                                            -,
garciay's avatar
garciay committed
                                                                                            )
                                                                            ),
                                                           { digest := v_digest },
                                                           m_signature_ecdsaNistP256(
                                                                                     m_ecdsaP256Signature(
                                                                                                          m_eccP256CurvePoint_x_only(
                                                                                                                                     '08B2030104020A0D010C0105C0F80BB1460239348D17405C1A845151D4061200'O
                                                                                                                                     ),
                                                                                                          '2617CF4E6B25097F03F502AD0C6F2F125974700D31A60FD1EF12040E4D8231AB'O
                                                                                                          )
    log("v_signed_data = ", v_signed_data);
  v_encMsg := encvalue(valueof(v_signed_data));
garciay's avatar
garciay committed
    setverdict(pass, "Encoding passed.");
    if (decvalue(v_encMsg, v_signed_data_dec) != 0) {
garciay's avatar
garciay committed
      setverdict(fail);
      stop;
    } else if (not(match(valueof(v_signed_data), v_signed_data_dec))) {
garciay's avatar
garciay committed
      setverdict(fail);
      stop;
    }
    setverdict(pass, "Decoding passed.");
  } // End of testcase tc_secured_message_signed_1
garciay's avatar
garciay committed
  testcase tc_secured_message_signed_2() runs on TCType system TCType {
    var template (value) EtsiTs103097Data v_signed_data;
    var EtsiTs103097Data v_signed_data_dec;
garciay's avatar
garciay committed
    var template (value) GeoNetworkingPdu v_gnPacket;
    var octetstring v_raw_payload_to_be_signed := 'CAFFEDECA0000001'O;
garciay's avatar
garciay committed
    var HashedId8 v_digest := '0000000000000000'O;
    var bitstring v_encMsg;

  v_gnPacket := m_geoNwPdu(
                           m_geoNwShbPacket(
                                            LongPosVector: {
                                            gnAddr := {
                                              typeOfAddress := e_manual,
                                              stationType := e_roadSideUnit,
                                              stationCountryCode := 33,
                                              mid := 'a4fedecabeef'O
                                            },
                                              timestamp_ := 123456,
                                              latitude := 4856,
                                              longitude := 675,
                                              pai := '1'B,
                                              speed := 55,
                                              heading := 9876
                                              }
                                            )
                           );
  v_signed_data := m_etsiTs103097Data_signed(
garciay's avatar
garciay committed
                                              m_signedData(
                                                           sha256,
                                                           m_toBeSignedData(
garciay's avatar
garciay committed
                                                                    m_signedDataPayload(
                                                                                        m_etsiTs103097Data_unsecured(v_raw_payload_to_be_signed)
                                                                                        ),
                                                                    m_headerInfo_gn(
                                                                                    -,
garciay's avatar
garciay committed
                                                                                    )
                                                                    ),
garciay's avatar
garciay committed
                                                           { digest := v_digest },
                                                           m_signature_ecdsaNistP256(
                                                                                     m_ecdsaP256Signature(
                                                                                                          m_eccP256CurvePoint_x_only(
                                                                                                                                     '08B2030104020A0D010C0105C0F80BB1460239348D17405C1A845151D4061200'O
                                                                                                                                     ),
                                                                                                          '2617CF4E6B25097F03F502AD0C6F2F125974700D31A60FD1EF12040E4D8231AB'O
                                                                                                          )
    log("v_signed_data = ", v_signed_data);
  v_encMsg := encvalue(valueof(v_signed_data));
garciay's avatar
garciay committed
    setverdict(pass, "Encoding passed.");
    if (decvalue(v_encMsg, v_signed_data_dec) != 0) {
garciay's avatar
garciay committed
      setverdict(fail);
      stop;
    } else if (not(match(valueof(v_signed_data), v_signed_data_dec))) {
garciay's avatar
garciay committed
      setverdict(fail);
      stop;
garciay's avatar
garciay committed
    }
garciay's avatar
garciay committed
    setverdict(pass, "Decoding passed.");
  } // End of testcase tc_secured_message_signed_2
    
  testcase tc_secured_message_signed_and_encrypted_1() runs on TCType system TCType {
    var template (value) EtsiTs103097Data v_signed_data;
    var EtsiTs103097Data v_signed_data_dec;
    var template (value) EtsiTs103097Data v_encrypted_data;
    var EtsiTs103097Data v_encrypted_data_dec;
    var template (value) GeoNetworkingPdu v_gnPacket;
    var octetstring v_raw_payload_to_be_signed := 'CAFFEDECA0000001'O;
    var HashedId8 v_digest := '0000000000000000'O;
    var HashedId8 v_encrypted_hashedId8 := '0000000000000000'O;
    var bitstring v_encMsg;

  v_gnPacket := m_geoNwPdu(
                           m_geoNwShbPacket(
                                            LongPosVector: {
                                            gnAddr := {
                                              typeOfAddress := e_manual,
                                              stationType := e_roadSideUnit,
                                              stationCountryCode := 33,
                                              mid := 'a4fedecabeef'O
                                            },
                                              timestamp_ := 123456,
                                              latitude := 4856,
                                              longitude := 675,
                                              pai := '1'B,
                                              speed := 55,
                                              heading := 9876
                                              }
                                            ),
                           {
                             multiplier := c_defaultLifetime,
                             ltBase := e_100s
                           }
                           );
  v_signed_data := m_etsiTs103097Data_signed(
                                             m_signedData(
                                                          sha256,
                                                          m_toBeSignedData(
                                                                   m_signedDataPayload(
                                                                                       m_etsiTs103097Data_unsecured(v_raw_payload_to_be_signed)
                                                                                      ),
                                                                   m_headerInfo_gn(
                                                                                  -,
                                                                                  12345
                                                                                  )
                                                                   ),
                                                          { digest := v_digest },
                                                          m_signature_ecdsaNistP256(
                                                                                    m_ecdsaP256Signature(
                                                                                                         m_eccP256CurvePoint_x_only(
                                                                                                                                    '08B2030104020A0D010C0105C0F80BB1460239348D17405C1A845151D4061200'O
                                                                                                                                    ),
                                                                                                         '2617CF4E6B25097F03F502AD0C6F2F125974700D31A60FD1EF12040E4D8231AB'O
                                                                                                        )
                                                                                    )
                                                          )
                                            );
    log("v_signed_data = ", v_signed_data);
    v_encMsg := encvalue(valueof(v_signed_data));
      
    v_encrypted_data := m_etsiTs103097Data_encrypted(
                                                     m_encryptedData(
                                                                     {
                                                                      m_recipientInfo_certRecipInfo(
                                                                                                    m_pKRecipientInfo(
                                                                                                                      v_encrypted_hashedId8,
                                                                                                                      m_encryptedDataEncryptionKey_eciesNistP256(
                                                                                                                                                                 m_evciesP256EncryptedKey(
                                                                                                                                                                                          m_eccP256CurvePoint_x_only(
                                                                                                                                                                                                                     '08B2030104020A0D010C0105C0F80BB1460239348D17405C1A845151D4061200'O
                                                                                                                                                                                                                    ),
                                                                                                                                                                                          '01020304050607080010203040506070'O,
                                                                                                                                                                                          '01020304050607080010203040506070'O
                                                                                                                                                                                         )
                                                                                                                                                                 )
                                                                                                                     )
                                                                                                   )
                                                                     },
                                                                     m_SymmetricCiphertext_aes128ccm(
                                                                                                     m_aesCcmCiphertext(
                                                                                                                        '0102030405060708090a0b0c'O,
                                                                                                                        bit2oct(v_encMsg)
                                                                                                     )
                                                                                                    )
                                                                    )
                                                    );
  v_encMsg := encvalue(valueof(v_encrypted_data));
    setverdict(pass, "Encoding passed.");
    if (decvalue(v_encMsg, v_encrypted_data_dec) != 0) {
      setverdict(fail);
      stop;
    } else if (not(match(valueof(v_encrypted_data), v_encrypted_data_dec))) {
      setverdict(fail);
      stop;
    }
    setverdict(pass, "Decoding passed.");
  } // End of testcase tc_secured_message_signed_and_encrypted_1
    
  testcase tc_secured_message_signed_and_encrypted_2() runs on TCType system TCType {
    var template (value) EtsiTs103097Data v_signed_data;
    var EtsiTs103097Data v_signed_data_dec;
    var template (value) EtsiTs103097Data v_encrypted_data;
    var EtsiTs103097Data v_encrypted_data_dec;
    var template (value) GeoNetworkingPdu v_gnPacket;
    var octetstring v_raw_payload_to_be_signed := 'CAFFEDECA0000001'O;
    var HashedId8 v_digest := '0000000000000000'O;
    var HashedId8 v_encrypted_hashedId8 := '0000000000000000'O;
    var bitstring v_encMsg;

  v_gnPacket := m_geoNwPdu(
                           m_geoNwShbPacket(
                                            LongPosVector: {
                                            gnAddr := {
                                              typeOfAddress := e_manual,
                                              stationType := e_roadSideUnit,
                                              stationCountryCode := 33,
                                              mid := 'a4fedecabeef'O
                                            },
                                              timestamp_ := 123456,
                                              latitude := 4856,
                                              longitude := 675,
                                              pai := '1'B,
                                              speed := 55,
                                              heading := 9876
                                              }
                                            ),
                           {
                             multiplier := c_defaultLifetime,
                             ltBase := e_100s
                           }
                           );
  v_signed_data := m_etsiTs103097Data_signed(
                                             m_signedData(
                                                          sha256,
                                                          m_toBeSignedData(
                                                                   m_signedDataPayload(
                                                                                       m_etsiTs103097Data_unsecured(v_raw_payload_to_be_signed)
                                                                                      ),
                                                                   m_headerInfo_gn(
                                                                                  -,
                                                                                  12345
                                                                                  )
                                                                   ),
                                                          { digest := v_digest },
                                                          m_signature_ecdsaNistP256(
                                                                                    m_ecdsaP256Signature(
                                                                                                         m_eccP256CurvePoint_x_only(
                                                                                                                                    '08B2030104020A0D010C0105C0F80BB1460239348D17405C1A845151D4061200'O
                                                                                                                                    ),
                                                                                                         '2617CF4E6B25097F03F502AD0C6F2F125974700D31A60FD1EF12040E4D8231AB'O
                                                                                                        )
                                                                                    )
                                                          )
                                            );
    log("v_signed_data = ", v_signed_data);
    v_encMsg := encvalue(valueof(v_signed_data));
      
    v_encrypted_data := m_etsiTs103097Data_encrypted(
                                                     m_encryptedData(
                                                                     {
                                                                      m_recipientInfo_signedDataRecipInfo(
                                                                                                          m_pKRecipientInfo(
                                                                                                                            v_encrypted_hashedId8,
                                                                                                                            m_encryptedDataEncryptionKey_eciesNistP256(
                                                                                                                                                                       m_evciesP256EncryptedKey(
                                                                                                                                                                                                m_eccP256CurvePoint_x_only(
                                                                                                                                                                                                                           '08B2030104020A0D010C0105C0F80BB1460239348D17405C1A845151D4061200'O
                                                                                                                                                                                                                          ),
                                                                                                                                                                                                '01020304050607080010203040506070'O,
                                                                                                                                                                                                '01020304050607080010203040506070'O
                                                                                                                                                                                               )
                                                                                                                                                                       )
                                                                                                                           )
                                                                                                         )
                                                                     },
                                                                     m_SymmetricCiphertext_aes128ccm(
                                                                                                     m_aesCcmCiphertext(
                                                                                                                        '0102030405060708090a0b0c'O,
                                                                                                                        bit2oct(v_encMsg)
                                                                                                     )
                                                                                                    )
                                                                    )
                                                    );
  v_encMsg := encvalue(valueof(v_encrypted_data));
    setverdict(pass, "Encoding passed.");
    if (decvalue(v_encMsg, v_encrypted_data_dec) != 0) {
      setverdict(fail);
      stop;
    } else if (not(match(valueof(v_encrypted_data), v_encrypted_data_dec))) {
      setverdict(fail);
      stop;
    }
    setverdict(pass, "Decoding passed.");
  } // End of testcase tc_secured_message_signed_and_encrypted_2
    
garciay's avatar
garciay committed
  control {
    execute(tc_ssp_cam_1());
    execute(tc_ssp_cam_2());
    execute(tc_ssp_denm());
    execute(tc_secured_message_unsecured());
    execute(tc_secured_message_signed_1());
    execute(tc_secured_message_signed_2());
    execute(tc_secured_message_signed_and_encrypted_1());
    execute(tc_secured_message_signed_and_encrypted_2());
garciay's avatar
garciay committed
    
} // End of module TestCodec_SecuredMessages