Commit 9fd3f291 authored by Yann Garcia's avatar Yann Garcia
Browse files

Add TLM test

parent 4b09f4e4
Loading
Loading
Loading
Loading
+82 −7
Original line number Original line Diff line number Diff line
@@ -3040,6 +3040,7 @@ module LibItsPki_Functions {
            log("f_verify_rca_crl_response_message: Invalid nextUpdate value");
            log("f_verify_rca_crl_response_message: Invalid nextUpdate value");
            return false;
            return false;
          }
          }
          // TODO Verify RCA certificate & signature
        }
        }
      }
      }


@@ -3066,7 +3067,7 @@ module LibItsPki_Functions {
          return false;
          return false;
        } else {
        } else {
          if (f_verify_ctl_entry(v_ctl_command.add) == false) {
          if (f_verify_ctl_entry(v_ctl_command.add) == false) {
            log("f_verify_full_ctl: ctlCommands contains inavlid entries");
            log("f_verify_full_ctl: ctlCommands contains invalid entries");
            return false;
            return false;
          }
          }
        }
        }
@@ -3116,7 +3117,7 @@ module LibItsPki_Functions {
          return false;
          return false;
        } else {
        } else {
          if (f_verify_ectl_entry(v_ectl_command.add) == false) {
          if (f_verify_ectl_entry(v_ectl_command.add) == false) {
            log("f_verify_full_ectl: ctlCommands contains inavlid entries");
            log("f_verify_full_ectl: ctlCommands contains invalid entries");
            return false;
            return false;
          }
          }
        }
        }
@@ -3128,21 +3129,31 @@ module LibItsPki_Functions {
    function f_verify_ctl_entry(
    function f_verify_ctl_entry(
                                in CtlEntry p_ctl_entry
                                in CtlEntry p_ctl_entry
                                ) return boolean {
                                ) return boolean {
      log(">>> f_verify_ctl_entry: p_ctl_entry=", p_ctl_entry);

      if (ischosen(p_ctl_entry.rca)) {
      if (ischosen(p_ctl_entry.rca)) {
        if (match(p_ctl_entry.rca, mw_root_ca_entry(mw_etsiTs103097Certificate)) == false) {
        if (match(p_ctl_entry.rca, mw_root_ca_entry(mw_etsiTs103097Certificate)) == false) {
          return false;
          return false;
        } else {
          // TODO Verify RCA certificate & signature
        }
        }
     } else if (ischosen(p_ctl_entry.ea)) {
     } else if (ischosen(p_ctl_entry.ea)) {
        if (match(p_ctl_entry.ea, mw_ea_entry(mw_etsiTs103097Certificate)) == false) {
        if (match(p_ctl_entry.ea, mw_ea_entry(mw_etsiTs103097Certificate)) == false) {
          return false;
          return false;
        } else {
          // TODO Verify RCA certificate & signature
        }
        }
      } else if (ischosen(p_ctl_entry.aa)) {
      } else if (ischosen(p_ctl_entry.aa)) {
        if (match(p_ctl_entry.aa, mw_aa_entry(mw_etsiTs103097Certificate)) == false) {
        if (match(p_ctl_entry.aa, mw_aa_entry(mw_etsiTs103097Certificate)) == false) {
          return false;
          return false;
        } else {
          // TODO Verify RCA certificate & signature
        }
        }
      } else if (ischosen(p_ctl_entry.dc)) {
      } else if (ischosen(p_ctl_entry.dc)) {
        if (match(p_ctl_entry.dc, mw_dc_entry) == false) {
        if (match(p_ctl_entry.dc, mw_dc_entry) == false) {
          return false;
          return false;
        } else {
          // TODO Verify RCA certificate & signature
        }
        }
      } else {
      } else {
        return false;
        return false;
@@ -3154,12 +3165,20 @@ module LibItsPki_Functions {
    function f_verify_ectl_entry(
    function f_verify_ectl_entry(
                                 in CtlEntry p_ctl_entry
                                 in CtlEntry p_ctl_entry
                                 ) return boolean {
                                 ) return boolean {
      log(">>> f_verify_ectl_entry: p_ctl_entry=", p_ctl_entry);

      if (ischosen(p_ctl_entry.tlm)) {
      if (ischosen(p_ctl_entry.tlm)) {
        if (match(p_ctl_entry.tlm, mw_tlm_entry(mw_etsiTs103097Certificate)) == false) {
        if (match(p_ctl_entry.tlm, mw_tlm_entry(mw_etsiTs103097Certificate)) == false) {
          return false;
          return false;
        } else {
        } else {
          // TODO Verify selsigned certificate
          // TODO Verify selsigned certificate
        }
        }
      } else if (ischosen(p_ctl_entry.rca)) {
        if (match(p_ctl_entry.rca, mw_root_ca_entry(mw_etsiTs103097Certificate)) == false) {
          return false;
        } else {
          // TODO Verify RCA certificate & signature
        }
      } else {
      } else {
        return false;
        return false;
      }
      }
@@ -3169,6 +3188,62 @@ module LibItsPki_Functions {


  } // End of group rca
  } // End of group rca


  group tlm {

    function f_verify_tlm_ectl_response_message(
                                                in Ieee1609Dot2Data p_ieee1609dot2_signed_data,
                                                in boolean p_check_security := true,
                                                out ToBeSignedTlmCtl p_to_be_signed_tlm_ectl
                                                ) return boolean {
      var bitstring v_etsi_ts_102941_data_msg;
      var bitstring v_tbs;
      var Certificate v_certificate;
      var boolean v_result;
      var Oct32 v_issuer;
      var EtsiTs102941Data v_etsi_ts_102941_data;

      log(">>> f_verify_tlm_ectl_response_message: p_ieee1609dot2_signed_data= ", p_ieee1609dot2_signed_data);

      // 1. Verify signature
      log("f_verify_tlm_ectl_response_message: p_ieee1609dot2_signed_data.content.signedData.tbsData= ", p_ieee1609dot2_signed_data.content.signedData.tbsData);
      v_tbs := encvalue(p_ieee1609dot2_signed_data.content.signedData.tbsData);
      v_certificate := p_ieee1609dot2_signed_data.content.signedData.signer.certificate[0];
      if (ischosen(p_ieee1609dot2_signed_data.content.signedData.signature_.ecdsaBrainpoolP384r1Signature)) {
        v_result := f_verifyEcdsa(bit2oct(v_tbs), int2oct(0, 48), p_ieee1609dot2_signed_data.content.signedData.signature_, v_certificate.toBeSigned.verifyKeyIndicator.verificationKey);
      } else {
        v_result := f_verifyEcdsa(bit2oct(v_tbs), int2oct(0, 32), p_ieee1609dot2_signed_data.content.signedData.signature_, v_certificate.toBeSigned.verifyKeyIndicator.verificationKey);
      }
      if (v_result == false) {
        if (p_check_security == true) {
          return false;
        }
      }
      v_etsi_ts_102941_data_msg := oct2bit(p_ieee1609dot2_signed_data.content.signedData.tbsData.payload.data.content.unsecuredData);
      if (decvalue(v_etsi_ts_102941_data_msg, v_etsi_ts_102941_data) != 0) {
        log("f_verify_tlm_ectl_response_message: Failed to decode EtsiTs102941Data");
        return false;
      } else {
        log("f_verify_tlm_ectl_response_message: v_etsi_ts_102941_data= ", v_etsi_ts_102941_data);
        log("f_verify_pki_response_message: TlmCertificateTrustListMessage matching= ", match(v_etsi_ts_102941_data, mw_etsiTs102941Data_to_be_signed_tlm_ctl));
        if (match(v_etsi_ts_102941_data, mw_etsiTs102941Data_to_be_signed_tlm_ctl) == false) {
          log("f_verify_tlm_ectl_response_message: Failed to decode certificateTrustListTlm");
          return false;
        } else {
          p_to_be_signed_tlm_ectl := v_etsi_ts_102941_data.content.certificateTrustListTlm;
          log("f_verify_tlm_ectl_response_message: p_to_be_signed_tlm_ectl= ", p_to_be_signed_tlm_ectl);
          if (p_to_be_signed_tlm_ectl.nextUpdate <= f_getCurrentTime() / 1000) {
            log("f_verify_tlm_ectl_response_message: Invalid nextUpdate value: compared values=", p_to_be_signed_tlm_ectl.nextUpdate, "/", f_getCurrentTime() / 1000);
            return false;
          }
          // TODO Verify RCA certificate & signature
        }
      }

      return true;
    }

  } // End of group tlm

  group awaiting_messages {
  group awaiting_messages {


    function f_await_http_inner_ec_request_response(
    function f_await_http_inner_ec_request_response(
+9 −0
Original line number Original line Diff line number Diff line
@@ -169,6 +169,15 @@ module LibItsPki_Templates {
    }
    }
  } // End of template mw_etsiTs102941Data_to_be_signed_crl
  } // End of template mw_etsiTs102941Data_to_be_signed_crl


  template (present) EtsiTs102941Data mw_etsiTs102941Data_to_be_signed_tlm_ctl(
                                                                               template (present) ToBeSignedTlmCtl p_to_be_signed_tlm := ?
                                                                               ) := {
    version := PkiProtocolVersion,
    content := {
		certificateTrustListTlm := p_to_be_signed_tlm
    }
  } // End of template mw_etsiTs102941Data_to_be_signed_crl

  template (value) EtsiTs102941DataContent m_enrolmentRequest(
  template (value) EtsiTs102941DataContent m_enrolmentRequest(
                                                              in template (value) InnerEcRequestSignedForPop p_enrolmentRequest
                                                              in template (value) InnerEcRequestSignedForPop p_enrolmentRequest
                                                              ) := {
                                                              ) := {
+15 −15
Original line number Original line Diff line number Diff line
@@ -344,19 +344,19 @@ module LibItsSecurity_Templates {
                 * @desc Recv template for message signed with digest 
                 * @desc Recv template for message signed with digest 
                 */
                 */
                template (present) SignerIdentifier mw_signerIdentifier_digest(
                template (present) SignerIdentifier mw_signerIdentifier_digest(
                                                                               in template (present) HashedId8 p_digest  := ?
                                                                               template (present) HashedId8 p_digest  := ?
                ) := {
                ) := {
                    digest := p_digest
                    digest := p_digest
                } // End of template mw_signerIdentifier_digest
                } // End of template mw_signerIdentifier_digest
                
                
                template (present) SignerIdentifier mw_signerIdentifier_certificate(
                template (present) SignerIdentifier mw_signerIdentifier_certificate(
                                                                                    in template (present) EtsiTs103097Certificate p_certificate  := ?
                                                                                    template (present) EtsiTs103097Certificate p_certificate  := ?
                ) := {
                ) := {
                    certificate := { p_certificate }
                    certificate := { p_certificate }
                } // End of template m_signerIdentifier_certificate
                } // End of template m_signerIdentifier_certificate
                
                
                template (present) SignerIdentifier mw_signerIdentifier_certificates(
                template (present) SignerIdentifier mw_signerIdentifier_certificates(
                                                                                     in template (present) SequenceOfCertificate p_certificates := ?
                                                                                     template (present) SequenceOfCertificate p_certificates := ?
                ) := {
                ) := {
                    certificate := p_certificates
                    certificate := p_certificates
                } // End of template mw_signerIdentifier_certificates
                } // End of template mw_signerIdentifier_certificates
@@ -376,7 +376,7 @@ module LibItsSecurity_Templates {
                 * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.9   Signature
                 * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.9   Signature
                 */
                 */
                template (present) Signature mw_signature(
                template (present) Signature mw_signature(
                                                          in template (present) EcdsaP256Signature p_ecdsaSignature := ?
                                                          template (present) EcdsaP256Signature p_ecdsaSignature := ?
                ):= {
                ):= {
                    ecdsaNistP256Signature := p_ecdsaSignature
                    ecdsaNistP256Signature := p_ecdsaSignature
                } // End of template mw_signature
                } // End of template mw_signature
@@ -388,8 +388,8 @@ module LibItsSecurity_Templates {
                 * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.10   EcdsaP256Signature
                 * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.10   EcdsaP256Signature
                 */
                 */
                template (present) EcdsaP256Signature mw_ecdsaSignature(
                template (present) EcdsaP256Signature mw_ecdsaSignature(
                                                                        in template (present) EccP256CurvePoint p_rSig := ?,
                                                                        template (present) EccP256CurvePoint p_rSig := ?,
                                                                        in template (present) octetstring p_sSig := ?
                                                                        template (present) octetstring p_sSig := ?
                ) := {
                ) := {
                    rSig := p_rSig,
                    rSig := p_rSig,
                    sSig := p_sSig
                    sSig := p_sSig
@@ -404,8 +404,8 @@ module LibItsSecurity_Templates {
             * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.19    TwoDLocation
             * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.19    TwoDLocation
             */
             */
            template (present) TwoDLocation mw_twoDLocation(
            template (present) TwoDLocation mw_twoDLocation(
                                                            in template (present) SecLatitude p_latitude,
                                                            template (present) SecLatitude p_latitude,
                                                            in template (present) SecLongitude p_longitude
                                                            template (present) SecLongitude p_longitude
            ) := {
            ) := {
                latitude    := p_latitude,
                latitude    := p_latitude,
                longitude   := p_longitude
                longitude   := p_longitude
@@ -419,9 +419,9 @@ module LibItsSecurity_Templates {
             * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.20    ThreeDLocation
             * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.20    ThreeDLocation
             */
             */
            template (present) ThreeDLocation mw_threeDLocation(
            template (present) ThreeDLocation mw_threeDLocation(
                                                                in template (present) SecLatitude p_latitude,
                                                                template (present) SecLatitude p_latitude,
                                                                in template (present) SecLongitude p_longitude,
                                                                template (present) SecLongitude p_longitude,
                                                                in template (present) SecElevation p_elevation
                                                                template (present) SecElevation p_elevation
            ) := {
            ) := {
                latitude    := p_latitude,
                latitude    := p_latitude,
                longitude   := p_longitude,
                longitude   := p_longitude,
@@ -435,8 +435,8 @@ module LibItsSecurity_Templates {
             * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.21  GeographicRegion
             * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.21  GeographicRegion
             */
             */
            template (present) GeographicRegion mw_geographicRegion_circle(
            template (present) GeographicRegion mw_geographicRegion_circle(
                                                                           in template (present) TwoDLocation p_center := ?,
                                                                           template (present) TwoDLocation p_center := ?,
                                                                           in template (present) UInt16 p_radius := ?
                                                                           template (present) UInt16 p_radius := ?
            ) := {
            ) := {
                circularRegion := {
                circularRegion := {
                    center := p_center,
                    center := p_center,
@@ -460,7 +460,7 @@ module LibItsSecurity_Templates {
             * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.21  GeographicRegion
             * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.21  GeographicRegion
             */
             */
            template (present) GeographicRegion mw_geographicRegion_polygonal(
            template (present) GeographicRegion mw_geographicRegion_polygonal(
                                                                              in template (present) PolygonalRegion p_polygonal_region := ?
                                                                              template (present) PolygonalRegion p_polygonal_region := ?
            ) := {
            ) := {
                polygonalRegion := p_polygonal_region
                polygonalRegion := p_polygonal_region
            } // End of template mw_geographicRegion_polygonial
            } // End of template mw_geographicRegion_polygonial
@@ -471,7 +471,7 @@ module LibItsSecurity_Templates {
             * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.21  GeographicRegion
             * @see Draft ETSI TS 103 097 V1.3.1 Clause 4.2.21  GeographicRegion
             */
             */
            template (present) GeographicRegion mw_geographicRegion_identified(
            template (present) GeographicRegion mw_geographicRegion_identified(
                                                                               in template (present) SequenceOfIdentifiedRegion p_identifiedRegion := ?
                                                                               template (present) SequenceOfIdentifiedRegion p_identifiedRegion := ?
            ) := {
            ) := {
                identifiedRegion := p_identifiedRegion
                identifiedRegion := p_identifiedRegion
            } // End of template mw_geographicRegion_identifiedRegion
            } // End of template mw_geographicRegion_identifiedRegion