Skip to content
ItsPki_TestCases.ttcn 1.06 MiB
Newer Older
ASN.1 Documenter's avatar
ASN.1 Documenter committed
        // Preamble
        f_init_default_headers_list(PICS_HEADER_CTL_CONTENT_TYPE, "tlm_request", v_headers);
        action("The TLM is triggered to add new RootCA certificate (CERT_RCA) in the CTL");
        f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
ASN.1 Documenter's avatar
ASN.1 Documenter committed
        // Test Body
        f_http_send(
                    v_headers,
                    m_http_request(
                                   m_http_request_get(
                                                      PICS_HTTP_GET_URI_TLM,
ASN.1 Documenter's avatar
ASN.1 Documenter committed
                                                      v_headers
                                                      )));
        tc_ac.start;
        alt {
          [not(PICS_MULTIPLE_END_POINT)] httpPort.receive(
                                                          mw_http_response(
                                                                           mw_http_response_ok(
                                                                                               mw_http_message_body_binary(
                                                                                                                           mw_binary_body_ieee1609dot2_data(
                                                                                                                                                            mw_etsiTs103097Data_signed(
                                                                                                                                                                                       mw_signedData(
                                                                                                                                                                                                     -,
                                                                                                                                                                                                     mw_toBeSignedData(                                                                                                                                                            mw_signedDataPayload                                                                                                                                        ),
                                                                                                                                                                                                     - // Certificate or HasedId8
                                                                                                                                                                                                     ))))))) -> value v_response {
            var ToBeSignedTlmCtl v_to_be_signed_tlm_ectl;

            tc_ac.stop;

            // FIXME Can not verify signature, to be checked
            if (f_verify_tlm_ectl_response_message(v_response.response.body.binary_body.ieee1609dot2_data, false, v_to_be_signed_tlm_ectl) == false) {
              log("*** " & testcasename() & ": FAIL: Failed to verify RCA message ***");
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
            } else {
              if (f_verify_full_ectl(v_to_be_signed_tlm_ectl) == true) {
                log("*** " & testcasename() & ": PASS: ToBeSignedRcaCtl received ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
              } else {
                log("*** " & testcasename() & ": FAIL: Receive unexpected message ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
              }
            }
          }
          [PICS_MULTIPLE_END_POINT] httpTlmPort.receive(
                                                        mw_http_response(
                                                                         mw_http_response_ok(
                                                                                             mw_http_message_body_binary(
                                                                                                                         mw_binary_body_ieee1609dot2_data(
                                                                                                                                                          mw_etsiTs103097Data_signed(
                                                                                                                                                                                     mw_signedData(
                                                                                                                                                                                                   -,
                                                                                                                                                                                                   mw_toBeSignedData(                                                                                                                                                            mw_signedDataPayload                                                                                                                                        ),
                                                                                                                                                                                                   - // Certificate or HasedId8
                                                                                                                                                                                                   ))))))) -> value v_response {
            var ToBeSignedTlmCtl v_to_be_signed_tlm_ectl;

            tc_ac.stop;

            // FIXME Can not verify signature, to be checked
            if (f_verify_tlm_ectl_response_message(v_response.response.body.binary_body.ieee1609dot2_data, false, v_to_be_signed_tlm_ectl) == false) {
              log("*** " & testcasename() & ": FAIL: Failed to verify RCA message ***");
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
            } else {
              if (f_verify_full_ectl(v_to_be_signed_tlm_ectl) == true) {
                log("*** " & testcasename() & ": PASS: ToBeSignedRcaCtl received ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
              } else {
                log("*** " & testcasename() & ": FAIL: Receive unexpected message ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
              }
            }
          }
          [] tc_ac.timeout {
            log("*** " & testcasename() & ": INCONC: Expected message not received ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
          }
        } // End of 'alt' statement

        // Postamble
        f_cfHttpDown_tlm();

      } // End of testcase TC_TLM_ECTLGEN_01_BV

    } // End of group tlm_ctl_generation
ASN.1 Documenter's avatar
ASN.1 Documenter committed

  } // End of group tlm_behavior

  // ETSI TS 103 525-2 V2.0.2 (2023-07) Clause 5.9  CPOC behaviour
  group cpoc_behavior {

    /**
     * @desc Check that the TLM CTL is published and accessible when issued
     * <pre>
     * Pics Selection: 
     * Initial conditions: 
     *         the TLM issued a new CTL
     *     }
     * Expected behaviour:
     *     ensure that {
     *         when {
     *             the ITS-S asked the IUT for the newly issued CTL
     *         }
     *         then {
     *             the IUT is answered with this CTL
     *         }
     *     }
     * </pre>
     * 
     * @see       ETSI TS 103 525-2 TP SECPKI_CPOC_LISTDIST_01_BV
     * @reference ETSI TS 102 941, Clauses 6.3.2 and 6.3.3
     */
    testcase TC_SECPKI_CPOC_LISTDIST_01_BV() runs on ItsPkiHttp system ItsPkiHttpSystem {
      // Local variable
      var Headers v_headers;
      var HttpMessage v_response;
      // Test component configuration
      f_cfHttpUp(PICS_TS_EA_CERTIFICATE_ID, PICS_TS_AA_CERTIFICATE_ID);
      // Preamble
      f_init_default_headers_list(-, "cpoc_request", v_headers);
      f_http_send(
                  v_headers,
                  m_http_request(
                                 m_http_request_get(
                                                    PICS_HTTP_GET_URI_TLM,
                                                    v_headers
                                                    )));
      f_selfOrClientSyncAndVerdict(c_prDone, e_success);
      // Test Body
      tc_ac.start;
      alt {
        [not(PICS_MULTIPLE_END_POINT)] httpPort.receive(
                                                        mw_http_response(
                                                                         mw_http_response_ok(
                                                                                             mw_http_message_body_binary(
                                                                                                                         mw_binary_body_ieee1609dot2_data(
                                                                                                                                                          mw_etsiTs103097Data_signed(
                                                                                                                                                                                     mw_signedData(
                                                                                                                                                                                                   -,
                                                                                                                                                                                                   mw_toBeSignedData(
                                                                                                                                                                                                                     mw_signedDataPayload
                                                                                                                                                                                                                     )
                                                                                                                                                                                                   ))))))) -> value v_response {
            var ToBeSignedTlmCtl v_to_be_signed_tlm_ectl;

            tc_ac.stop;

            // FIXME Can not verify signature, to be checked
            if (f_verify_tlm_ectl_response_message(v_response.response.body.binary_body.ieee1609dot2_data, false, v_to_be_signed_tlm_ectl) == false) {
              log("*** " & testcasename() & ": FAIL: Failed to verify ECTL message ***");
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
            } else {
              if (f_verify_full_ectl(v_to_be_signed_tlm_ectl) == true) {
                log("*** " & testcasename() & ": PASS: ToBeSignedTlmCtl received ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
              } else {
                log("*** " & testcasename() & ": FAIL: Receive unexpected message ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
              }
            }
        }
        [PICS_MULTIPLE_END_POINT] httpPort.receive(
                                                   mw_http_response(
                                                                    mw_http_response_ok(
                                                                                        mw_http_message_body_binary(
                                                                                                                    mw_binary_body_ieee1609dot2_data(
                                                                                                                                                     mw_etsiTs103097Data_signed(
                                                                                                                                                                                mw_signedData(
                                                                                                                                                                                              -,
                                                                                                                                                                                              mw_toBeSignedData(
                                                                                                                                                                                                                mw_signedDataPayload
                                                                                                                                                                                                                )
                                                                                                                                                                                              ))))))) -> value v_response {
          var ToBeSignedTlmCtl v_to_be_signed_tlm_ectl;
          // FIXME Can not verify signature, to be checked
          if (f_verify_tlm_ectl_response_message(v_response.response.body.binary_body.ieee1609dot2_data, false, v_to_be_signed_tlm_ectl) == false) {
            log("*** " & testcasename() & ": FAIL: Failed to verify ECTL message ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
          } else {
            if (f_verify_full_ectl(v_to_be_signed_tlm_ectl) == true) {
              log("*** " & testcasename() & ": PASS: ToBeSignedTlmCtl received ***");
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
            } else {
              log("*** " & testcasename() & ": FAIL: Receive unexpected message ***");
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
            }
          }
        }
        [] tc_ac.timeout {
          log("*** " & testcasename() & ": INCONC: Expected message not received ***");
          f_selfOrClientSyncAndVerdict(c_tbDone, e_timeout);
        }
      } // End of 'alt' statement
      // Postamble
      f_cfHttpDown();
    } // End of testcase TC_SECPKI_CPOC_LISTDIST_01_BV
  group pki_platform_simu {
      /**
       * @desc Await for DC/CTL/CRL request and provides "CERT_IUT_A_RCA", "CERT_TS_A_AA", "CERT_TS_A_EA" certificates
       *       It simulates the ETSI point of certificates distribution
       *       Usage: curl 'http://192.168.1.43/dc/getctl/{hasehedid8}' --header 'Content-Type: application/x-its-ctl' --header 'Content-Text: ca_request' --output ctl.oer
       */
      testcase TC_PKI_PLTF_RCV_BV_01() runs on ItsPkiHttp system ItsPkiHttpSystem {
        // Local variables
        var charstring v_rca_certificate_id := "CERT_IUT_A_RCA";
        var charstring v_tlm_certificate_id := "CERT_IUT_A_RCA"; // TODO Need CERT_IUT_A_TLM certificate
        var charstring v_aa_certificate_id := "CERT_TS_A_AA";
        var charstring v_ea_certificate_id := "CERT_TS_A_EA";
        var Oct32 v_hash;
        var Oct8 v_rca_hashed_id8;
        var HttpMessage v_request;
        var boolean v_result := false;
        var ToBeSignedRcaCtl v_ctl;
        var Headers v_headers;
        var template (value) HttpMessage v_response;
        var Ieee1609Dot2Data v_ieee1609dot2_signed_and_encrypted_data;
        var EtsiTs102941Data v_etsi_ts_102941_data;
        var Oct16 v_request_hash;
        var Oct16 v_aes_enc_key;

        // Test component configuration
        f_cfHttpUp_ca();
        // Test control
        if (not PICS_IUT_CA_ROLE) {
          log("*** " & testcasename() & ": PICS_IUT_CA_ROLE required for executing the TC ***");
          setverdict(inconc);
          stop;
        }
        // Test component configuration
        f_cfHttpUp_ca();

        // Preamble
        f_getCertificateHash256(v_rca_certificate_id, v_hash);
        v_rca_hashed_id8 := f_hashedId8FromSha256(v_hash);
        log("*** " & testcasename() & ": DEBUG: v_rca_hashed_id8= ", v_rca_hashed_id8);
        f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
        // Test Body
        tc_wait.start;
        alt {
          [] a_await_dc_http_request_from_iut( // Await for DC request
                                              mw_http_request(
                                                              mw_http_request_get(
                                                                                  PICS_HTTP_GET_URI_DC & "/" & oct2str(v_rca_hashed_id8)
                                                                                  )),
                                              v_request
                                              ) {
            var EtsiTs103097Certificate v_rca_certificate;

            tc_wait.stop;
            f_init_default_headers_list(-, "ca_response", v_headers);

            // Send message
            f_build_dc(
                        v_rca_certificate_id,
                        v_rca_certificate
                        );
            log("*** " & testcasename() & ": INFO: v_rca_certificate: ", v_rca_certificate);
            v_response := m_http_response(m_http_response_ok(m_http_message_body_binary(m_binary_body_ieee1609dot2_certificate(v_rca_certificate)), v_headers));
            f_http_send(v_headers, v_response);
            log("*** " & testcasename() & ": INFO: ToBeSignedRcaCtl sent ***");

           tc_wait.start;
            repeat;
          }
          [] a_await_ctl_http_request_from_iut( // Await for CTL request
                                               mw_http_request(
                                                               mw_http_request_get(
                                                                                   PICS_HTTP_GET_URI_CTL & "/" & oct2str(v_rca_hashed_id8)
                                                                                   )),
                                               v_request
                                               ) {
            var ToBeSignedRcaCtl v_to_be_signed_rca_ctl;

            tc_wait.stop;
            f_init_default_headers_list(-, "ca_response", v_headers);
            // Send message
            f_build_ctl(
                        v_ea_certificate_id,
                        v_aa_certificate_id,
                        v_rca_certificate_id,
                        v_to_be_signed_rca_ctl
                        );
            log("*** " & testcasename() & ": INFO: v_to_be_signed_rca_ctl: ", v_to_be_signed_rca_ctl);
            f_sign_dc_ctl(v_rca_certificate_id, v_to_be_signed_rca_ctl, v_ieee1609dot2_signed_and_encrypted_data);
            log("*** " & testcasename() & ": INFO: v_ieee1609dot2_signed_and_encrypted_data: ", v_ieee1609dot2_signed_and_encrypted_data);
            v_response := m_http_response(m_http_response_ok(m_http_message_body_binary(m_binary_body_ieee1609dot2_data(v_ieee1609dot2_signed_and_encrypted_data)), v_headers));
            f_http_send(v_headers, v_response);
            log("*** " & testcasename() & ": INFO: ToBeSignedRcaCtl sent ***");

            tc_wait.start;
            repeat;
          }
          [] a_await_crl_http_request_from_iut( // Await for CTL request
                                               mw_http_request(
                                                               mw_http_request_get(
                                                                                   PICS_HTTP_GET_URI_CRL & "/" & oct2str(v_rca_hashed_id8)
                                                                                   )),
                                               v_request
                                               ) {
            var ToBeSignedCrl v_to_be_signed_crl;

            tc_wait.stop;
            f_init_default_headers_list(-, "ca_response", v_headers);
            // Send message
            f_build_crl(
                        -,
                        -,
                        v_to_be_signed_crl
                        );
            log("*** " & testcasename() & ": INFO: v_to_be_signed_crl: ", v_to_be_signed_crl);
            f_sign_dc_crl(v_rca_certificate_id, v_to_be_signed_crl, v_ieee1609dot2_signed_and_encrypted_data);
            log("*** " & testcasename() & ": INFO: v_ieee1609dot2_signed_and_encrypted_data: ", v_ieee1609dot2_signed_and_encrypted_data);
            v_response := m_http_response(m_http_response_ok(m_http_message_body_binary(m_binary_body_ieee1609dot2_data(v_ieee1609dot2_signed_and_encrypted_data)), v_headers));
            f_http_send(v_headers, v_response);
            log("*** " & testcasename() & ": INFO: ToBeSignedCRl sent ***");

            tc_wait.start;
            repeat;
          }
          [] a_await_cpoc_http_request_from_iut( // Await for TLM request (E-CPOC)
                                                mw_http_request(
                                                                mw_http_request_get(
                                                                                    PICS_HTTP_GET_URI_TLM & "/" & oct2str(v_rca_hashed_id8)
                                                                                    )),
                                                v_request
                                                ) {
            var ToBeSignedTlmCtl v_to_be_signed_tlm_ctl;

            tc_wait.stop;
            f_init_default_headers_list(-, "ca_response", v_headers);
            // Send message
            f_build_tlm(
                        v_tlm_certificate_id,
                        v_rca_certificate_id,
                        v_to_be_signed_tlm_ctl
                        );
            log("*** " & testcasename() & ": INFO: v_to_be_signed_tlm_ctl: ", v_to_be_signed_tlm_ctl);
            f_sign_dc_ctl(v_rca_certificate_id, v_to_be_signed_tlm_ctl, v_ieee1609dot2_signed_and_encrypted_data);
            log("*** " & testcasename() & ": INFO: v_ieee1609dot2_signed_and_encrypted_data: ", v_ieee1609dot2_signed_and_encrypted_data);
            v_response := m_http_response(m_http_response_ok(m_http_message_body_binary(m_binary_body_ieee1609dot2_data(v_ieee1609dot2_signed_and_encrypted_data)), v_headers));
            f_http_send(v_headers, v_response);
            log("*** " & testcasename() & ": INFO: ToBeSignedTlmCtl sent ***");

            tc_wait.start;
            repeat;
          }
          [] a_await_any_http_request_from_iut(
                                               mw_http_request,
                                               v_request
                                               ) {
            tc_wait.stop;
            f_init_default_headers_list(-, "ca_response", v_headers);

            v_response := m_http_response(m_http_response_400_bad_request(m_http_message_body_html("<!DOCTYPE html><html><body><h1>ETSI ITS PKI Infrastructure L0 simulator</h1><p>Request not supported</p></body></html>"), v_headers));
            f_http_send(v_headers, v_response);

            tc_wait.start;
            repeat;
          }
          [] tc_wait.timeout {
            //log("*** " & testcasename() & ": PASS: Terminate Generation/Distrbution server ***");
            //f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
            tc_wait.start;
            repeat;
          }
        } // End of 'alt' statement
        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);

        // Postamble
        f_cfHttpDown_ca();

      } // End of testcase TC_PKI_PLTF_RCV_BV_01

  } // End of group pki_platform_simu

ASN.1 Documenter's avatar
ASN.1 Documenter committed
} // End of module ItsPki_TestCases