Skip to content
LibItsPki_Functions.ttcn 77 KiB
Newer Older
Yann Garcia's avatar
Yann Garcia committed
/**
 *  @author   ETSI / STF544
 *  @version  $URL$
 *            $Id$
 *  @desc     Module containing functions for ITS PKI ATS
 *  @copyright   ETSI Copyright Notification
 *               No part may be reproduced except as authorized by written permission.
 *               The copyright and the foregoing restriction extend to reproduction in all media.
 *               All rights reserved.
 *
 */
module LibItsPki_Functions {
    
  // LibCommon
  import from LibCommon_Time all;
  import from LibCommon_VerdictControl all;
  import from LibCommon_Sync all;
  import from LibCommon_BasicTypesAndValues all;
  import from LibCommon_DataStrings all;
  
  // LibIts
  import from IEEE1609dot2BaseTypes language "ASN.1:1997" all;
  import from IEEE1609dot2 language "ASN.1:1997" all;
  import from EtsiTs102941BaseTypes language "ASN.1:1997" all;
  import from EtsiTs102941TypesEnrolment language "ASN.1:1997" all;
  import from EtsiTs102941TypesAuthorization language "ASN.1:1997" all;
  import from EtsiTs102941TypesAuthorizationValidation language "ASN.1:1997" all;
  import from EtsiTs102941MessagesCa language "ASN.1:1997" all;
Yann Garcia's avatar
Yann Garcia committed
  import from EtsiTs103097Module language "ASN.1:1997" all;
  import from ITS_Container language "ASN.1:1997" all;
  import from CAM_PDU_Descriptions language "ASN.1:1997" all;
  
  // LibItsCommon
garciay's avatar
garciay committed
  import from LibItsCommon_TypesAndValues all;
Yann Garcia's avatar
Yann Garcia committed
  import from LibItsCommon_Functions all;
  import from LibItsCommon_ASN1_NamedNumbers all;
  import from LibItsCommon_Pixits all;
  // LibItsGeoNetworking
  import from LibItsGeoNetworking_Pixits all;
  
Yann Garcia's avatar
Yann Garcia committed
  // LibItsSecurity
  import from LibItsSecurity_TypesAndValues all;
  import from LibItsSecurity_Templates all;
  import from LibItsSecurity_Functions all;
  import from LibItsSecurity_Pixits all;
  import from LibItsSecurity_TestSystem all;
Yann Garcia's avatar
Yann Garcia committed
  // LibItsHttp
  import from LibItsHttp_TypesAndValues all;
  import from LibItsHttp_Templates all;
Yann Garcia's avatar
Yann Garcia committed
  import from LibItsHttp_TestSystem all;
Yann Garcia's avatar
Yann Garcia committed
  // LibItsPki
  import from LibItsPki_TypesAndValues all;
Yann Garcia's avatar
Yann Garcia committed
  import from LibItsPki_Templates all;
  import from LibItsPki_Pics all;
garciay's avatar
garciay committed
  import from LibItsPki_Pixits all;
Yann Garcia's avatar
Yann Garcia committed
  import from LibItsPki_TestSystem all;
  
  group pkiConfigurationFunctions {
Yann Garcia's avatar
Yann Garcia committed
     
    /**
     * @desc    Setups default configuration   
     * @param   p_certificateId The certificate identifier the TA shall use in case of secured IUT
     */
    function f_cfUp(
                    in charstring p_certificateId := "CERT_TS_A_EA", // TODO Use a constant
                    in charstring p_peerCertificateId := "CERT_IUT_A_EA"
Yann Garcia's avatar
Yann Garcia committed
                   ) runs on ItsPki /* TITAN TODO: system ItsPkiSystem */ {
Yann Garcia's avatar
Yann Garcia committed
      map(self:pkiPort, system:pkiPort);
garciay's avatar
garciay committed
      map(self:acPort, system:acPort);
Yann Garcia's avatar
Yann Garcia committed
      f_connect4SelfOrClientSync();
      
      f_initialiseSecuredMode(p_certificateId, p_peerCertificateId);
Yann Garcia's avatar
Yann Garcia committed
      
      f_readCertificate(p_certificateId, vc_eaCertificate);
      f_getCertificateDigest(p_certificateId, vc_eaHashedId8);
      
      activate(a_default_pki());
Yann Garcia's avatar
Yann Garcia committed
    } // End of function f_cfUp
    
    /**
     * @desc    Setups default configuration   
     * @param   p_certificateId The certificate identifier the TA shall use in case of secured IUT
     */
    function f_cfHttpUp(
garciay's avatar
garciay committed
                        in charstring p_ea_certificate_id := "CERT_TS_A_EA", // TODO Use a constant
                        in charstring p_ec_certificate_id := "CERT_TS_A_EC",
                        in charstring p_peerCertificateId := "CERT_IUT_A_EA"
garciay's avatar
garciay committed
                        ) runs on ItsPkiHttp /* TITAN TODO: system ItsPkiHttpSystem */ {
Yann Garcia's avatar
Yann Garcia committed
      
      map(self:httpPort, system:httpPort);
      f_connect4SelfOrClientSync();
garciay's avatar
garciay committed
      f_initialiseSecuredMode(p_ea_certificate_id, p_peerCertificateId);
Yann Garcia's avatar
Yann Garcia committed
      
garciay's avatar
garciay committed
      f_readCertificate(p_ea_certificate_id, vc_eaCertificate);
      f_readSigningKey(p_ea_certificate_id, vc_eaPrivateKey);
      f_readCertificate(p_ec_certificate_id, vc_ecCertificate);
      f_readSigningKey(p_ec_certificate_id, vc_ecPrivateKey);
      f_readEncryptingKey(p_ea_certificate_id, vc_eaPrivateEncKey);
      f_getCertificateDigest(p_ea_certificate_id, vc_eaHashedId8);
      f_getCertificateHash(p_ea_certificate_id, vc_eaWholeHash);
garciay's avatar
garciay committed
      f_getCertificateDigest(p_ec_certificate_id, vc_ecHashedId8);
      f_readCertificate(p_peerCertificateId, vc_peerEaCertificate);
      f_getCertificateHash(p_peerCertificateId, vc_eaPeerWholeHash);
      
      activate(a_default_pki_http());
Yann Garcia's avatar
Yann Garcia committed
    } // End of function f_cfHttpUp
    function f_cfUp_itss(
                         in charstring p_certificateId := "CERT_TS_A_EA" // TODO Use a constant
                         ) runs on ItsPkiItss /* TITAN TODO: system ItsPkiItssSystem */ {
      
      f_cfUp();
      
      map(self:geoNetworkingPort, system:geoNetworkingPort);
      map(self:utPort, system:utPort);
      map(self:acPort, system:acPort);
      activate(a_default_pki());
    } // End of function f_cfUp_itss
Yann Garcia's avatar
Yann Garcia committed
    /**
     * @desc    Deletes default configuration 
     */
    function f_cfDown() runs on ItsPki /* TITAN TODO: system ItsPkiSystem */ {
      unmap(self:pkiPort, system:pkiPort);
garciay's avatar
garciay committed
      unmap(self:acPort, system:acPort);
Yann Garcia's avatar
Yann Garcia committed
      f_disconnect4SelfOrClientSync();
Yann Garcia's avatar
Yann Garcia committed
    } // End of function f_cfDown
    
    /**
     * @desc    Deletes default configuration 
     */
    function f_cfHttpDown() runs on ItsPkiHttp /* TITAN TODO: system ItsPkiHttpSystem */ {
      unmap(self:httpPort, system:httpPort);
      f_disconnect4SelfOrClientSync();
Yann Garcia's avatar
Yann Garcia committed
    } // End of function f_cfHttpDown
    
    /**
     * @desc    Deletes default configuration 
     */
    function f_cfDown_itss() runs on ItsPkiItss /* TITAN TODO: system ItsPkiItssSystem */ {
      unmap(self:geoNetworkingPort, system:geoNetworkingPort);
      unmap(self:utPort, system:utPort);
      unmap(self:acPort, system:acPort);
      
      f_cfDown();
    } // End of function f_cfDown
    
Yann Garcia's avatar
Yann Garcia committed
    /**
     * @desc Initialise secure mode if required
     */
    function f_initialiseSecuredMode(
                                     in charstring p_certificateId  := "CERT_TS_A_EA", // TODO Use a constant
                                     in charstring p_peerCertificateId := "CERT_IUT_A_EA"
                                     ) runs on ItsSecurityBaseComponent {
Yann Garcia's avatar
Yann Garcia committed
      // Local variables
      
      // Load certificates
      if( not f_loadCertificates(PX_IUT_SEC_CONFIG_NAME) ) {
        log("*** INFO: TEST CASE NOW STOPPING ITSELF! ***");
      f_prepareCertificates(p_certificateId, vc_aaCertificate, vc_atCertificate);
Yann Garcia's avatar
Yann Garcia committed
    } // End of function f_initialiseSecuredMode()
    
    function f_uninitialiseSecuredMode() runs on ItsSecurityBaseComponent {
Yann Garcia's avatar
Yann Garcia committed
      f_unloadCertificates();
    } // End of function f_uninitialiseSecuredMode()
    
    function f_initializeState() runs on ItsPkiItss {
      var Oct8 v_hashedId8ToBeUsed := f_setupIutCertificate(vc_hashedId8ToBeUsed);

      f_utInitializeIut(UtPkiInitialize: { v_hashedId8ToBeUsed } );

      f_sleep(PX_NEIGHBOUR_DISCOVERY_DELAY);
      
      //      f_acLoadScenario(p_scenario);
      //      f_acStartScenario();
    }
    
Yann Garcia's avatar
Yann Garcia committed
  } // End of pkiConfigurationFunctions

  group ac_port {

    function f_sendAcPkiPrimitive(
Yann Garcia's avatar
Yann Garcia committed
                                  in charstring p_certificate,
                                  in octetstring p_private_key,
                                  in octetstring p_publicKeyCompressed,
                                  in integer p_compressedMode
Loading full blame...