Skip to content
TestCodec_Certificates.ttcn 11 KiB
Newer Older
garciay's avatar
garciay committed
/*
 * @author
 *     
 * @version
 *     1.0
 * @desc
 *     
 * @remark
 *     
 * @see
 *     
 */ 
module TestCodec_Certificates {
  // LibCommon
  import from LibCommon_BasicTypesAndValues all;
  import from LibCommon_DataStrings all;
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;
  
  // LibItsSecurity
  import from LibItsSecurity_EncdecDeclarations all;
  
garciay's avatar
garciay committed
  // TestCodec
  import from TestCodec_TestAndSystem all;
  
  template (value) EtsiTs103097Certificate m_etsiTs103097Certificate(
                                                                     in template (value) IssuerIdentifier p_issuer,
                                                                     in template (value) ToBeSignedCertificate p_toBeSigned
  ) := {
    version     := 3,
    type_       := explicit,
    issuer      := p_issuer,
    toBeSigned  := p_toBeSigned,
    signature_  := omit
  } // End of template m_etsiTs103097Certificate
  
  template (value) IssuerIdentifier m_issuerIdentifier_sha256AndDigest(
                                                                       in template (value) HashedId8 p_sha256AndDigest
  ) := {
    sha256AndDigest  := p_sha256AndDigest
  } // End of template m_issuerIdentifier_sha256AndDigest

  template (value) IssuerIdentifier m_issuerIdentifier_sha384AndDigest(
                                                                       in template (value) HashedId8 p_sha384AndDigest
  ) := {
    sha384AndDigest  := p_sha384AndDigest
  } // End of template m_issuerIdentifier_sha384AndDigest

  template (omit) ToBeSignedCertificate m_toBeSignedCertificate(
                                                                in template (value) CertificateId p_id,
                                                                in template (value) HashedId3 p_cracaId,
                                                                in template (value) CrlSeries p_crlSeries,
                                                                in template (value) ValidityPeriod p_validityPeriod,
                                                                in template (value) SequenceOfPsidSsp p_appPermissions,
                                                                in template (value) SequenceOfPsidGroupPermissions p_certIssuePermissions,
                                                                in template (value) SequenceOfPsidGroupPermissions p_certRequestPermissions,
                                                                in template (value) VerificationKeyIndicator p_verifyKeyIndicator,
                                                                in template (omit) GeographicRegion p_region := omit,
                                                                in template (omit) SubjectAssurance p_assuranceLevel := omit,
                                                                in template (omit) PublicEncryptionKey p_encryptionKey := omit
    ) := { 
    id                     := p_id,
    cracaId                := p_cracaId,
    crlSeries              := p_crlSeries,
    validityPeriod         := p_validityPeriod,
    region                 := p_region,
    assuranceLevel         := p_assuranceLevel,
    appPermissions         := p_appPermissions,
    certIssuePermissions   := p_certIssuePermissions,
    certRequestPermissions := p_certRequestPermissions, 
    canRequestRollover     := omit,
    encryptionKey          := p_encryptionKey,
    verifyKeyIndicator     := p_verifyKeyIndicator
  } // End of template m_toBeSignedCertificate

  template (value) ValidityPeriod m_validity_period(
                                                    in Time32 p_start_,
                                                    in Duration p_duration       
  ) := {
    start_    := p_start_,
    duration  := p_duration
  } // End of template m_validity_period
  
  template (omit) PsidSsp m_psidSsp(
                                    in template (value) Psid p_psid,
                                    in template (omit) ServiceSpecificPermissions p_ssp := omit
    ) := {
    psid   := p_psid,
    ssp    := p_ssp
  } // End of template m_psidSsp

  template (omit) PsidSspRange m_psidSspRange(
                                              in Psid p_psid,
                                              in template (omit) SspRange p_sspRange := omit
  ) := {
    psid        := p_psid,
    sspRange    := p_sspRange
  } // End of template m_psidSspRange

  template (value) PsidGroupPermissions m_PsidGroupPermissions(
                                                               in template (value) SubjectPermissions p_subjectPermissions,
                                                               in integer p_minChainLength := 1,
                                                               in integer p_chainLengthRange := 0, 
                                                               in EndEntityType p_eeType := oct2bit('00'O)
  ) := {
    subjectPermissions := p_subjectPermissions,
    minChainLength     := p_minChainLength,
    chainLengthRange   := p_chainLengthRange, 
    eeType             := p_eeType
  } // End of template m_PsidGroupPermissions

  template (value) SubjectPermissions m_subjectPermissions_explicit(
                                                                    in SequenceOfPsidSspRange p_certIssuePermissions
  ) := {
      explicit := p_certIssuePermissions
  } // End of template m_subjectPermissions_explicit
  
  template (value) VerificationKeyIndicator m_verificationKeyIndicator_verificationKey(
                                                                                       in template (value) PublicVerificationKey p_verificationKey
  ) := {
    verificationKey := p_verificationKey
  } // End of template m_verificationKeyIndicator_verificationKey
  
  template (value) VerificationKeyIndicator m_verificationKeyIndicator_reconstructionValue(
                                                                                       in template (value) EccP256CurvePoint p_reconstructionValue
  ) := {
    reconstructionValue := p_reconstructionValue
  } // End of template m_verificationKeyIndicator_reconstructionValue

  template (value) PublicVerificationKey m_publicVerificationKey_ecdsaNistP256(
                                                                               in template (value) EccP256CurvePoint p_ecdsaNistP256
  ) := { 
    ecdsaNistP256 := p_ecdsaNistP256
  } // End of template m_publicVerificationKey_ecdsaNistP256
  
  template (value) EccP256CurvePoint m_eccP256CurvePoint_compressed_y_0(
                                                                        in Oct32 p_compressed_y_0
  ) := {
    compressed_y_0 := p_compressed_y_0
  } // End of template m_eccP256CurvePoint_compressed_y_0

  testcase tc_certificate_1() runs on TCType system TCType {
      var template (value) EtsiTs103097Certificate v_cert;
      var HashedId8 v_sha256AndDigest := '0000000000000000'O;
      var HashedId3 v_cracaId := '000000'O;
      var CrlSeries v_crlSeries := 0;
      var SequenceOfPsidSspRange v_certIssuePermissions := { valueof(m_psidSspRange(1)) };
      var SequenceOfPsidSspRange v_certRequestPermissions := { valueof(m_psidSspRange(2)) };
      var Oct32 v_compressed_y_0 := '0000000000000000000000000000000000000000000000000000000000000000'O;
      var bitstring v_encMsg;
      var integer v_res := 0;
      var bitstring v_expEncMsg := oct2bit('310020'O);

      v_cert := m_etsiTs103097Certificate(
                                          m_issuerIdentifier_sha256AndDigest(v_sha256AndDigest),
                                          m_toBeSignedCertificate(
                                                                  { name := "tc_certificate_1" },
                                                                  v_cracaId,
                                                                  v_crlSeries,
                                                                  m_validity_period(0, { milliseconds := 1000 }),
                                                                  { 
                                                                    m_psidSsp(1), 
                                                                    m_psidSsp(2, { bitmapSsp := '001100110011'O }) 
                                                                  },
                                                                  { 
                                                                      m_PsidGroupPermissions(
                                                                                             m_subjectPermissions_explicit(
                                                                                                                           v_certIssuePermissions
                                                                                            ))
                                                                  },
                                                                  { 
                                                                      m_PsidGroupPermissions(
                                                                                             m_subjectPermissions_explicit(
                                                                                                                           v_certRequestPermissions
                                                                                            ))
                                                                  },
                                                                  m_verificationKeyIndicator_verificationKey(
                                                                                                             m_publicVerificationKey_ecdsaNistP256(
                                                                                                                                                   m_eccP256CurvePoint_compressed_y_0(
                                                                                                                                                                                      v_compressed_y_0
                                                                                                            )))
                                                                 )
                                         );
      
      // Encode template
      log("Encode template ", valueof(v_cert));
      v_encMsg := encvalue(v_cert);
      log("Encoded message:  ", bit2oct(v_encMsg));
      // Check result
      if (not isbound(v_encMsg)) {
        setverdict(fail, "Encoding failed!");
        stop;
      }
      if (not match(v_encMsg, v_expEncMsg)) {
        log("Expected message: ", bit2oct(valueof(v_expEncMsg)));
        setverdict(fail, "Encoding failed, not the expected result!");
        stop;
      }
      setverdict(pass, "Encoding passed.");
   } // End of testcase tc_certificate_1
   
   control {
     execute(tc_certificate_1());
   }
   
} // End of module tc_certificate_1