Commit bbf3737e authored by garciay's avatar garciay
Browse files

Bug fixed on self signed certificate signature

parent 429d7c9a
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -171,9 +171,9 @@ module ItsGenCert_Functions {
    // Sign the certificate using ECDSA/SHA-256 (NIST p-256)
    if (p_certificate_params.curve == e_nist_p256) {
      if (p_issuer_certificate_details.certificate_id != p_certificate_details.certificate_id) { // This is not a CA certificate
        v_issuer := p_certificate_details.issuer;
        v_issuer := p_certificate_details.hash;
      } else {
        v_issuer := int2oct(0, 8); // Hash of empty string
        v_issuer := int2oct(0, 32); // Hash of empty string
      }
      v_signature := f_signWithEcdsaNistp256WithSha256(bit2oct(v_enc_msg), v_issuer, p_issuer_certificate_details.private_key);
      if (lengthof(v_signature) != 64) {
@@ -191,9 +191,9 @@ module ItsGenCert_Functions {
                                                                                        ));
    } else if (p_certificate_params.curve == e_brainpool_p256) {
      if (p_issuer_certificate_details.issuer != p_issuer_certificate_details.hashid8) { // This is not a CA certificate
        v_issuer := p_certificate_details.issuer;
        v_issuer := p_certificate_details.hash;
      } else {
        v_issuer := int2oct(0, 8); // Hash of empty string
        v_issuer := int2oct(0, 32); // Hash of empty string
      }
      v_signature := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_enc_msg), v_issuer, p_issuer_certificate_details.private_key);
      if (lengthof(v_signature) != 64) {
@@ -211,9 +211,9 @@ module ItsGenCert_Functions {
                                                                                               ));
    } else if (p_certificate_params.curve == e_brainpool_p384) {
      if (p_issuer_certificate_details.issuer != p_issuer_certificate_details.hashid8) { // This is not a CA certificate
        v_issuer := p_issuer_certificate_details.issuer;
        v_issuer := p_issuer_certificate_details.hash;
      } else {
        v_issuer := int2oct(0, 8);
        v_issuer := int2oct(0, 48);
      }
      v_signature := f_signWithEcdsaBrainpoolp384WithSha384(bit2oct(v_enc_msg), v_issuer, p_issuer_certificate_details.private_key);
      if (lengthof(v_signature) != 96) {
@@ -271,9 +271,11 @@ module ItsGenCert_Functions {
    p_certificate_details.enc_cert := bit2oct(encvalue(p_certificate_details.certificate));
    // Calculate the whole HashedId8 as defined in IEEE Std 1609.2-20XX Clause 6.4.3 CertificateBase
    if (p_certificate_params.hash_algorithm == sha256) {
      p_certificate_details.hashid8 := f_HashedId8FromSha256(f_hashWithSha256(p_certificate_details.enc_cert));
      p_certificate_details.hash := f_hashWithSha256(p_certificate_details.enc_cert);
      p_certificate_details.hashid8 := f_HashedId8FromSha256(p_certificate_details.hash);
    } else {
      p_certificate_details.hashid8 := f_HashedId8FromSha384(f_hashWithSha384(p_certificate_details.enc_cert));
      p_certificate_details.hash := f_hashWithSha384(p_certificate_details.enc_cert);
      p_certificate_details.hashid8 := f_HashedId8FromSha384(p_certificate_details.hash);
    }
    if (p_certificate_params.certificate_id == p_certificate_params.signed_by) { // Root certificate
      log("f_finalyse_certificate: Root certificate");
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ module ItsGencert_TestCases {
      
      // Setup
      v_certificate_params := PICS_CERTFICATES[v_counter];
      v_details := { v_certificate_params.certificate_id, {}, ''O, ''O, ''O, ''O, ''O, 0, '0000000000000000'O, '0000000000000000'O, omit, omit, omit, omit, omit };
      v_details := { v_certificate_params.certificate_id, {}, ''O, ''O, ''O, ''O, ''O, 0, ''O, '0000000000000000'O, '0000000000000000'O, omit, omit, omit, omit, omit };
      
      // Generate Private/Public signing and encryption keys for the certificate
      if (f_generate_signing_keys(v_certificate_params, v_details) == -1) {
+2 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ module ItsGenCert_TypeAndValues {
    /**
     * @desc Certificate description
     * @member enc_cert The COER encoding of the whole certificate, including the signature
     * @member hash     The whole certificate (including the signature) Hash
     * @member hashid8  The whole certificate (including the signature) HashedId8, as defined in IEEE Std 1609.2-20XX Clause 6.4.3 CertificateBase
     * @member issuer   The HashedId8 of the certificate issuer or 0 in case of self signed certificate (root certificate)
     */
@@ -103,6 +104,7 @@ module ItsGenCert_TypeAndValues {
      octetstring               public_key_y,
      octetstring               public_key_compressed,
      integer                   public_key_compressed_mode,
      octetstring               hash,
      HashedId8                 hashid8,
      HashedId8                 issuer,
      octetstring               private_enc_key optional,
+16 −16
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), int2oct(0, 8), v_private_key);
    v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_encMsg), int2oct(0, 32), v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -122,7 +122,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaNistp256WithSha256(
                                            bit2oct(v_encMsg), 
                                            int2oct(0, 8),
                                            int2oct(0, 32),
                                            v_cert_dec.signature_.ecdsaNistP256Signature.rSig.x_only & v_cert_dec.signature_.ecdsaNistP256Signature.sSig,
                                            v_publicKeyCompressed,
                                            v_compressedMode
@@ -193,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), int2oct(0, 8), v_private_key);
    v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_encMsg), int2oct(0, 32), v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -224,7 +224,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaBrainpoolp256WithSha256(
                                                 bit2oct(v_encMsg), 
                                                 int2oct(0, 8),
                                                 int2oct(0, 32),
                                                 v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.rSig.x_only & v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.sSig,
                                                 v_publicKeyCompressed,
                                                 v_compressedMode
@@ -311,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), int2oct(0, 8), v_private_key);
    v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_encMsg), int2oct(0, 32), v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -342,7 +342,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaBrainpoolp256WithSha256(
                                                 bit2oct(v_encMsg), 
                                                 int2oct(0, 8),
                                                 int2oct(0, 32),
                                                 v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.rSig.x_only & v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.sSig,
                                                 v_publicKeyCompressed,
                                                 v_compressedMode
@@ -413,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), int2oct(0, 8), v_private_key);
    v_sig := f_signWithEcdsaBrainpoolp384WithSha384(bit2oct(v_encMsg), int2oct(0, 48), v_private_key);
    if (lengthof(v_sig) != 96) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -444,7 +444,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaBrainpoolp384WithSha384(
                                                 bit2oct(v_encMsg), 
                                                 int2oct(0, 8),
                                                 int2oct(0, 48),
                                                 v_cert_dec.signature_.ecdsaBrainpoolP384r1Signature.rSig.x_only & v_cert_dec.signature_.ecdsaBrainpoolP384r1Signature.sSig,
                                                 v_publicKeyCompressed,
                                                 v_compressedMode
@@ -511,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), int2oct(0, 8), v_private_key);
    v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_encMsg), int2oct(10, 32), v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -543,7 +543,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaNistp256WithSha256(
                                            bit2oct(v_encMsg), 
                                            int2oct(0, 8),
                                            int2oct(10, 32),
                                            v_cert_dec.signature_.ecdsaNistP256Signature.rSig.x_only & v_cert_dec.signature_.ecdsaNistP256Signature.sSig,
                                            v_publicKeyCompressed,
                                            v_compressedMode
@@ -609,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), int2oct(0, 8), v_private_key);
    v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_encMsg), int2oct(11, 32), v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -639,7 +639,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaNistp256WithSha256(
                                            bit2oct(v_encMsg), 
                                            int2oct(0, 8),
                                            int2oct(11, 32),
                                            v_cert_dec.signature_.ecdsaNistP256Signature.rSig.x_only & v_cert_dec.signature_.ecdsaNistP256Signature.sSig,
                                            v_publicKeyCompressed,
                                            v_compressedMode
@@ -702,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), int2oct(0, 8), v_private_key);
    v_sig := f_signWithEcdsaBrainpoolp256WithSha256(bit2oct(v_encMsg), int2oct(10, 32), v_private_key);
    if (lengthof(v_sig) != 64) {
      log("Invalid signature: ", v_sig);
      setverdict(fail);
@@ -732,7 +732,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaBrainpoolp256WithSha256(
                                                 bit2oct(v_encMsg), 
                                                 int2oct(0, 8),
                                                 int2oct(10, 32),
                                                 v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.rSig.x_only & v_cert_dec.signature_.ecdsaBrainpoolP256r1Signature.sSig,
                                                 v_publicKeyCompressed,
                                                 v_compressedMode
@@ -889,7 +889,7 @@ module TestCodec_Certificates {

    // Create signature and compare with cprovide one
    v_enc_msg := encvalue(v_cert_exp.toBeSigned);
    v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_enc_msg), int2oct(0, 8), v_private_key);
    v_sig := f_signWithEcdsaNistp256WithSha256(bit2oct(v_enc_msg), int2oct(0, 32), v_private_key);
    if (not(match(v_sig, v_cert_dec.signature_.ecdsaNistP256Signature.rSig.x_only & v_cert_dec.signature_.ecdsaNistP256Signature.sSig))) {
        setverdict(fail, "Signature generation mismatch");
      } else {
@@ -905,7 +905,7 @@ module TestCodec_Certificates {
    }
    if (f_verifyWithEcdsaNistp256WithSha256(
                                            bit2oct(v_enc_msg), 
                                            int2oct(0, 8),
                                            int2oct(0, 32),
                                            v_cert_dec.signature_.ecdsaNistP256Signature.rSig.x_only & v_cert_dec.signature_.ecdsaNistP256Signature.sSig,
                                            v_publicKeyCompressed,
                                            v_compressedMode
+41 −29

File changed.

Preview size limit exceeded, changes collapsed.

Loading