Commit 9309a219 authored by garciay's avatar garciay
Browse files

Major security bugs fixed for signature. Encryption to do.

parent b8d0459f
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -144,19 +144,18 @@ module ItsGenCert_Functions {
                                  inout certificate_details p_certificate_details
                                  ) return integer {
    var bitstring v_enc_msg;
    var octetstring v_raw_to_be_signed;
    var HashedId8 v_issuer := '0000000000000000'O;
    var octetstring v_signature;
        
    // Encode it ==> Get octetstring
    v_enc_msg := encvalue(p_certificate_details.certificate.toBeSigned);
    v_raw_to_be_signed := bit2oct(v_enc_msg);
    if (p_issuer_certificate_details.issuer != p_issuer_certificate_details.hashid8) { // This is not a CA certificate
      v_raw_to_be_signed := v_raw_to_be_signed & p_issuer_certificate_details.issuer;
      v_issuer := p_issuer_certificate_details.issuer;
    }
    
    // Sign the certificate using ECDSA/SHA-256 (NIST p-256)
    if (p_certificate_params.curve == e_nist_p256) {
      v_signature := f_signWithEcdsaNistp256WithSha256(v_raw_to_be_signed, p_issuer_certificate_details.private_key);
    v_signature := f_signWithEcdsaNistp256WithSha256(bit2oct(v_enc_msg), v_issuer, p_issuer_certificate_details.private_key);
      if (lengthof(v_signature) != 64) {
        setverdict(fail, "Wrong signature size, shall be 64 instead of ", lengthof(v_signature));
        stop;
@@ -171,7 +170,7 @@ module ItsGenCert_Functions {
                                                                                                             )
                                                                                        ));
    } else if (p_certificate_params.curve == e_brainpool_p256) {
      v_signature := f_signWithEcdsaBrainpoolp256WithSha256(v_raw_to_be_signed, p_issuer_certificate_details.private_key);
      v_signature := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_enc_msg), v_issuer, p_issuer_certificate_details.private_key);
      if (lengthof(v_signature) != 64) {
        setverdict(fail, "Wrong signature size, shall be 64 instead of ", lengthof(v_signature));
        stop;
@@ -186,7 +185,7 @@ module ItsGenCert_Functions {
                                                                                                                    )
                                                                                               ));
    } else if (p_certificate_params.curve == e_brainpool_p384) {
      v_signature := f_signWithEcdsaBrainpoolp384WithSha384(v_raw_to_be_signed, p_issuer_certificate_details.private_key);
      v_signature := f_signWithEcdsaBrainpoolp384WithSha384(bit2oct(v_enc_msg), v_issuer, p_issuer_certificate_details.private_key);
      if (lengthof(v_signature) != 96) {
        setverdict(fail, "Wrong signature size, shall be 96 instead of ", lengthof(v_signature));
        stop;
+14 −7
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ module TestCodec_Certificates {
    v_encMsg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (NIST p-256)
    // IEEE Std 1609.2-20XX Clause 5.3.1 ii) If the verification type is self-signed, signer identifier input shall be the empty string, i.e., a string of length 0.
    v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_encMsg), v_private_key);
    v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_encMsg), '0000000000000000'O, v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -122,6 +122,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaNistp256WithSha256(
                                            bit2oct(v_encMsg), 
                                            '0000000000000000'O,
                                            v_cert_dec.signature_.ecdsaNistP256Signature.rSig.x_only & v_cert_dec.signature_.ecdsaNistP256Signature.sSig,
                                            v_publicKeyCompressed,
                                            v_compressedMode
@@ -192,7 +193,7 @@ module TestCodec_Certificates {
    log("Encode template ", valueof(v_cert.toBeSigned));
    v_encMsg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (NIST p-256)
    v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_encMsg), v_private_key);
    v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_encMsg), '0000000000000000'O, v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -223,6 +224,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaBrainpoolp256WithSha256(
                                                 bit2oct(v_encMsg), 
                                                 '0000000000000000'O,
                                                 v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.rSig.x_only & v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.sSig,
                                                 v_publicKeyCompressed,
                                                 v_compressedMode
@@ -309,7 +311,7 @@ module TestCodec_Certificates {
    log("Encode template ", valueof(v_cert.toBeSigned));
    v_encMsg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (NIST p-256)
    v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_encMsg), v_private_key);
    v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_encMsg), '0000000000000000'O, v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -340,6 +342,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaBrainpoolp256WithSha256(
                                                 bit2oct(v_encMsg), 
                                                 '0000000000000000'O,
                                                 v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.rSig.x_only & v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.sSig,
                                                 v_publicKeyCompressed,
                                                 v_compressedMode
@@ -410,7 +413,7 @@ module TestCodec_Certificates {
    log("Encode template ", valueof(v_cert.toBeSigned));
    v_encMsg := encvalue(v_cert.toBeSigned);
    // Sign the certificate
    v_sig := f_signWithEcdsaBrainpoolp384WithSha384(bit2oct(v_encMsg), v_private_key);
    v_sig := f_signWithEcdsaBrainpoolp384WithSha384(bit2oct(v_encMsg), '0000000000000000'O, v_private_key);
    if (lengthof(v_sig) != 96) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -441,6 +444,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaBrainpoolp384WithSha384(
                                                 bit2oct(v_encMsg), 
                                                 '0000000000000000'O,
                                                 v_cert_dec.signature_.ecdsaBrainpoolP384r1Signature.rSig.x_only & v_cert_dec.signature_.ecdsaBrainpoolP384r1Signature.sSig,
                                                 v_publicKeyCompressed,
                                                 v_compressedMode
@@ -507,7 +511,7 @@ module TestCodec_Certificates {
    log("Encode template ", valueof(v_cert));
    v_encMsg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (NIST p-256)
    v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_encMsg), v_private_key);
    v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_encMsg), '0000000000000000'O, v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -539,6 +543,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaNistp256WithSha256(
                                            bit2oct(v_encMsg), 
                                            '0000000000000000'O,
                                            v_cert_dec.signature_.ecdsaNistP256Signature.rSig.x_only & v_cert_dec.signature_.ecdsaNistP256Signature.sSig,
                                            v_publicKeyCompressed,
                                            v_compressedMode
@@ -604,7 +609,7 @@ module TestCodec_Certificates {
    log("Encode template ", valueof(v_cert.toBeSigned));
    v_encMsg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (NIST p-256)
    v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_encMsg), v_private_key);
    v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_encMsg), '0000000000000000'O, v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -634,6 +639,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaNistp256WithSha256(
                                            bit2oct(v_encMsg), 
                                            '0000000000000000'O,
                                            v_cert_dec.signature_.ecdsaNistP256Signature.rSig.x_only & v_cert_dec.signature_.ecdsaNistP256Signature.sSig,
                                            v_publicKeyCompressed,
                                            v_compressedMode
@@ -696,7 +702,7 @@ module TestCodec_Certificates {
    log("Encode template ", valueof(v_cert.toBeSigned));
    v_encMsg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (BP p-256)
    v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_encMsg), v_private_key);
    v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_encMsg), '0000000000000000'O, v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -726,6 +732,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaBrainpoolp256WithSha256(
                                                 bit2oct(v_encMsg), 
                                                 '0000000000000000'O,
                                                 v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.rSig.x_only & v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.sSig,
                                                 v_publicKeyCompressed,
                                                 v_compressedMode
+25 −17
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ module TestCodec_ChainOfCertificates {
    }
    if (f_verifyWithEcdsaNistp256WithSha256(
                                            bit2oct(v_enc_msg), 
                                            '0000000000000000'O, 
                                            v_chain_sec_info.ca.cert.signature_.ecdsaNistP256Signature.rSig.x_only & v_chain_sec_info.ca.cert.signature_.ecdsaNistP256Signature.sSig,
                                            v_publicKeyCompressed,
                                            v_publicKeyCompressedMode
@@ -95,7 +96,8 @@ module TestCodec_ChainOfCertificates {
      v_publicKeyCompressedMode := 1;
    }
    if (f_verifyWithEcdsaNistp256WithSha256(
                                            bit2oct(v_enc_msg) & v_chain_sec_info.aa.issuer, 
                                            bit2oct(v_enc_msg),
                                            v_chain_sec_info.aa.issuer, 
                                            v_chain_sec_info.aa.cert.signature_.ecdsaNistP256Signature.rSig.x_only & v_chain_sec_info.aa.cert.signature_.ecdsaNistP256Signature.sSig,
                                            v_publicKeyCompressed,
                                            v_publicKeyCompressedMode
@@ -123,7 +125,8 @@ module TestCodec_ChainOfCertificates {
      v_publicKeyCompressedMode := 1;
    }
    if (f_verifyWithEcdsaNistp256WithSha256(
                                            bit2oct(v_enc_msg) & v_chain_sec_info.at.issuer, 
                                            bit2oct(v_enc_msg),
                                            v_chain_sec_info.at.issuer, 
                                            v_chain_sec_info.at.cert.signature_.ecdsaNistP256Signature.rSig.x_only & v_chain_sec_info.at.cert.signature_.ecdsaNistP256Signature.sSig,
                                            v_publicKeyCompressed,
                                            v_publicKeyCompressedMode
@@ -173,7 +176,8 @@ module TestCodec_ChainOfCertificates {
      v_publicKeyCompressedMode := 1;
    }
    if (f_verifyWithEcdsaNistp256WithSha256(
                                            bit2oct(v_enc_msg) & v_chain_sec_info.at.hashedid8,
                                            bit2oct(v_enc_msg), 
                                            v_chain_sec_info.at.hashedid8,
                                            valueof(v_secured_data.content.signedData.signature_.ecdsaNistP256Signature.rSig.x_only) & valueof(v_secured_data.content.signedData.signature_.ecdsaNistP256Signature.sSig),
                                            v_publicKeyCompressed,
                                            v_publicKeyCompressedMode
@@ -217,6 +221,7 @@ module TestCodec_ChainOfCertificates {
    }
    if (f_verifyWithEcdsaBrainpoolp256WithSha256(
                                                 bit2oct(v_enc_msg),
                                                 '0000000000000000'O,
                                                 v_chain_sec_info.ca.cert.signature_.ecdsaBrainpoolP256r1Signature.rSig.x_only & v_chain_sec_info.ca.cert.signature_.ecdsaBrainpoolP256r1Signature.sSig,
                                                 v_publicKeyCompressed,
                                                 v_publicKeyCompressedMode
@@ -242,7 +247,8 @@ module TestCodec_ChainOfCertificates {
      v_publicKeyCompressedMode := 1;
    }
    if (f_verifyWithEcdsaBrainpoolp256WithSha256(
                                                 bit2oct(v_enc_msg) & v_chain_sec_info.aa.issuer, 
                                                 bit2oct(v_enc_msg),
                                                 v_chain_sec_info.aa.issuer, 
                                                 v_chain_sec_info.aa.cert.signature_.ecdsaBrainpoolP256r1Signature.rSig.x_only & v_chain_sec_info.aa.cert.signature_.ecdsaBrainpoolP256r1Signature.sSig,
                                                 v_publicKeyCompressed,
                                                 v_publicKeyCompressedMode
@@ -268,7 +274,8 @@ module TestCodec_ChainOfCertificates {
      v_publicKeyCompressedMode := 1;
    }
    if (f_verifyWithEcdsaBrainpoolp256WithSha256(
                                                 bit2oct(v_enc_msg) & v_chain_sec_info.at.issuer, 
                                                 bit2oct(v_enc_msg),
                                                 v_chain_sec_info.at.issuer, 
                                                 v_chain_sec_info.at.cert.signature_.ecdsaBrainpoolP256r1Signature.rSig.x_only & v_chain_sec_info.at.cert.signature_.ecdsaBrainpoolP256r1Signature.sSig,
                                                 v_publicKeyCompressed,
                                                 v_publicKeyCompressedMode
@@ -316,7 +323,8 @@ module TestCodec_ChainOfCertificates {
      v_publicKeyCompressedMode := 1;
    }
    if (f_verifyWithEcdsaBrainpoolp256WithSha256(
                                                 bit2oct(v_enc_msg) & v_chain_sec_info.at.hashedid8,
                                                 bit2oct(v_enc_msg),
                                                 v_chain_sec_info.at.hashedid8,
                                                 valueof(v_secured_data.content.signedData.signature_.ecdsaBrainpoolP256r1Signature.rSig.x_only) & valueof(v_secured_data.content.signedData.signature_.ecdsaBrainpoolP256r1Signature.sSig),
                                                 v_publicKeyCompressed,
                                                 v_publicKeyCompressedMode
@@ -388,7 +396,7 @@ module TestCodec_ChainOfCertificates {
    // Encode it ==> Get octetstring
  v_enc_msg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (NIST p-256)
  v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_enc_msg), p_ca_sec_info.private_key);
  v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_enc_msg), '0000000000000000'O, p_ca_sec_info.private_key);
  v_cert.signature_ := m_signature_ecdsaNistP256(
                                                 m_ecdsaP256Signature(
                                                                      m_eccP256CurvePoint_x_only(
@@ -458,7 +466,7 @@ module TestCodec_ChainOfCertificates {
    // Encode it ==> Get octetstring
  v_enc_msg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (BRAINPOOL P-256)
  v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_enc_msg), p_ca_sec_info.private_key);
  v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_enc_msg), '0000000000000000'O, p_ca_sec_info.private_key);
  v_cert.signature_ := m_signature_ecdsaBrainpoolP256r1(
                                                        m_ecdsaP256Signature(
                                                                             m_eccP256CurvePoint_x_only(
@@ -524,7 +532,7 @@ module TestCodec_ChainOfCertificates {
    // Encode it ==> Get octetstring
  v_enc_msg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (NIST P-256)
  v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_enc_msg) & p_ca_sec_info.hashedid8, p_ca_sec_info.private_key);
  v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_enc_msg), p_ca_sec_info.hashedid8, p_ca_sec_info.private_key);
  v_cert.signature_ := m_signature_ecdsaNistP256(
                                                 m_ecdsaP256Signature(
                                                                      m_eccP256CurvePoint_x_only(
@@ -590,7 +598,7 @@ module TestCodec_ChainOfCertificates {
    // Encode it ==> Get octetstring
  v_enc_msg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (BRAINPOOL P-256)
  v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_enc_msg) & p_ca_sec_info.hashedid8, p_ca_sec_info.private_key);
  v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_enc_msg), p_ca_sec_info.hashedid8, p_ca_sec_info.private_key);
  v_cert.signature_ := m_signature_ecdsaBrainpoolP256r1(
                                                        m_ecdsaP256Signature(
                                                                             m_eccP256CurvePoint_x_only(
@@ -657,7 +665,7 @@ module TestCodec_ChainOfCertificates {
    log("Encode template ", valueof(v_cert));
  v_enc_msg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (NIST P-256)
  v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_enc_msg) & p_aa_sec_info.hashedid8, p_aa_sec_info.private_key);
  v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_enc_msg), p_aa_sec_info.hashedid8, p_aa_sec_info.private_key);
  v_cert.signature_ := m_signature_ecdsaNistP256(
                                                 m_ecdsaP256Signature(
                                                                      m_eccP256CurvePoint_x_only(
@@ -724,7 +732,7 @@ module TestCodec_ChainOfCertificates {
    log("Encode template ", valueof(v_cert));
  v_enc_msg := encvalue(v_cert.toBeSigned);
    // Sign the certificate using ECDSA/SHA-256 (BRAINPOOL P-256)
  v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_enc_msg) & p_aa_sec_info.hashedid8, p_aa_sec_info.private_key);
  v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_enc_msg), p_aa_sec_info.hashedid8, p_aa_sec_info.private_key);
  v_cert.signature_ := m_signature_ecdsaBrainpoolP256r1(
                                                        m_ecdsaP256Signature(
                                                                             m_eccP256CurvePoint_x_only(
@@ -760,8 +768,8 @@ module TestCodec_ChainOfCertificates {
                                                       )
                                       );
    // Signed it
  v_raw_payload_to_be_signed := bit2oct(encvalue(v_toBeSignedData)) & p_at_sec_info.hashedid8;
  v_sig := f_signWithEcdsaNistp256WithSha256(v_raw_payload_to_be_signed, p_at_sec_info.private_key);
  v_raw_payload_to_be_signed := bit2oct(encvalue(v_toBeSignedData));
  v_sig := f_signWithEcdsaNistp256WithSha256(v_raw_payload_to_be_signed, p_at_sec_info.hashedid8, p_at_sec_info.private_key);
    // Finalize the secured message
  v_secured_data := valueof(
                            m_etsiTs103097Data_signed(
@@ -806,8 +814,8 @@ module TestCodec_ChainOfCertificates {
                                                       )
                                       );
    // Signed it
  v_raw_payload_to_be_signed := bit2oct(encvalue(v_toBeSignedData)) & p_at_sec_info.hashedid8;
  v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_raw_payload_to_be_signed, p_at_sec_info.private_key);
  v_raw_payload_to_be_signed := bit2oct(encvalue(v_toBeSignedData));
  v_sig := f_signWithEcdsaBrainpoolp256WithSha256(v_raw_payload_to_be_signed, p_at_sec_info.hashedid8, p_at_sec_info.private_key);
    // Finalize the secured message
  v_secured_data := m_etsiTs103097Data_signed(
                                              m_signedData(
+52 −52

File changed.

Preview size limit exceeded, changes collapsed.