Commit 4a00a066 authored by YannGarcia's avatar YannGarcia
Browse files

Support of implicit certificates

parent b6a1fb3c
Loading
Loading
Loading
Loading
+34 −24
Original line number Original line Diff line number Diff line
@@ -4413,7 +4413,7 @@ module ItsSecurity_TestCases {
            /**
            /**
             * @desc    Check that IUT accepts a valid secured CAM message signed with a known implicit certificate
             * @desc    Check that IUT accepts a valid secured CAM message signed with a known implicit certificate
             * <pre>
             * <pre>
             * Pics Selection: PICS_GN_SECURITY
             * Pics Selection: PICS_GN_SECURITY and (PICS_SEC_NIST_P256 or PICS_SEC_BRAINPOOL_P256R1)
             * Config Id: CF01
             * Config Id: CF01
             * Initial conditions:
             * Initial conditions:
             *  with {
             *  with {
@@ -4451,13 +4451,14 @@ module ItsSecurity_TestCases {
            testcase TC_SEC_ITSS_RCV_IMPLICIT_CERT_01_BV() runs on ItsGeoNetworking system ItsSecSystem {
            testcase TC_SEC_ITSS_RCV_IMPLICIT_CERT_01_BV() runs on ItsGeoNetworking system ItsSecSystem {
                // Local variables
                // Local variables
                var EtsiTs103097Certificate v_aaCertificate, v_atCertificate;
                var integer i;
                var integer i;
                var GeoNetworkingPdu v_securedGnPdu;
                var GeoNetworkingPdu v_securedGnPdu;
                var GnRawPayload v_sentRawPayload;
                var GnRawPayload v_sentRawPayload;
                
                
                // Test adapter configuration
                // Test adapter configuration
                if (not(PICS_GN_SECURITY)) {
                if (not(PICS_GN_SECURITY and (PICS_SEC_NIST_P256 or PICS_SEC_BRAINPOOL_P256R1))) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY and (PICS_SEC_NIST_P256 or PICS_SEC_BRAINPOOL_P256R1)' required for executing the TC ***");
                    stop;
                    stop;
                }
                }
                
                
@@ -4469,13 +4470,14 @@ module ItsSecurity_TestCases {
                
                
                // Preamble
                // Preamble
                f_prNeighbour();
                f_prNeighbour();
                f_prepareCertificates(cc_iutCert_A_IMP, v_aaCertificate, v_atCertificate);
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                
                
                // Test Body
                // Test Body
                v_securedGnPdu := f_sendSecuredCam(
                v_securedGnPdu := f_sendSecuredCam(
                                                cc_taCert_A,
                                                   cc_iutCert_A_IMP,
                                                   valueof(m_headerInfo_cam(-, (f_getCurrentTime() * 1000)/*us*/)),
                                                   valueof(m_headerInfo_cam(-, (f_getCurrentTime() * 1000)/*us*/)),
                                                valueof(m_signerIdentifier_certificate(vc_atCertificate)),
                                                   valueof(m_signerIdentifier_certificate(v_atCertificate)),
                                                   f_getTsStationId()
                                                   f_getTsStationId()
                                                   );
                                                   );
@@ -4501,7 +4503,7 @@ module ItsSecurity_TestCases {
            /**
            /**
             * @desc    Check that IUT accepts a valid secured CAM message signed with an unknown implicit certificate
             * @desc    Check that IUT accepts a valid secured CAM message signed with an unknown implicit certificate
             * <pre>
             * <pre>
             * Pics Selection: PICS_GN_SECURITY
             * Pics Selection: PICS_GN_SECURITY and (PICS_SEC_NIST_P256 or PICS_SEC_BRAINPOOL_P256R1)
             * Config Id: CF01
             * Config Id: CF01
             * Initial conditions:
             * Initial conditions:
             *  with {
             *  with {
@@ -4539,31 +4541,39 @@ module ItsSecurity_TestCases {
            testcase TC_SEC_ITSS_RCV_IMPLICIT_CERT_02_BV() runs on ItsGeoNetworking system ItsSecSystem {
            testcase TC_SEC_ITSS_RCV_IMPLICIT_CERT_02_BV() runs on ItsGeoNetworking system ItsSecSystem {
                // Local variables
                // Local variables
                var charstring v_certificate_id;
                var EtsiTs103097Certificate v_aaCertificate, v_atCertificate;
                var integer i;
                var integer i;
                var GeoNetworkingPdu v_securedGnPdu;
                var GeoNetworkingPdu v_securedGnPdu;
                var GnRawPayload v_sentRawPayload;
                var GnRawPayload v_sentRawPayload;
                
                
                // Test adapter configuration
                // Test adapter configuration
                if (not(PICS_GN_SECURITY)) {
                if (not(PICS_GN_SECURITY and (PICS_SEC_NIST_P256 or PICS_SEC_BRAINPOOL_P256R1))) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY and (PICS_SEC_NIST_P256 or PICS_SEC_BRAINPOOL_P256R1)' required for executing the TC ***");
                    stop;
                    stop;
                }
                }
                
                
                // Test component configuration
                // Test component configuration
                vc_hashedId8ToBeUsed := "CERT_TS_F3_AT_IMP";
                vc_hashedId8ToBeUsed := cc_iutCert_A_IMP;
                f_cf01Up();
                f_cf01Up();
                
                
                // Test adapter configuration
                // Test adapter configuration
                
                
                // Preamble
                // Preamble
                f_prNeighbour();
                f_prNeighbour();
                if (PICS_SEC_NIST_P256) {
                    v_certificate_id := "CERT_TS_F_AT_IMP";
                } else {
                    v_certificate_id := "CERT_TS_F3_AT_IMP";
                }
                f_prepareCertificates(v_certificate_id, v_aaCertificate, v_atCertificate);
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                // Test Body
                // Test Body
                v_securedGnPdu := f_sendSecuredCam(
                v_securedGnPdu := f_sendSecuredCam(
                                                cc_taCert_A,
                                                   v_certificate_id,
                                                   valueof(m_headerInfo_cam(-, (f_getCurrentTime() * 1000)/*us*/)),
                                                   valueof(m_headerInfo_cam(-, (f_getCurrentTime() * 1000)/*us*/)),
                                                valueof(m_signerIdentifier_certificate(vc_atCertificate)),
                                                   valueof(m_signerIdentifier_certificate(v_atCertificate)),
                                                   f_getTsStationId()
                                                   f_getTsStationId()
                                                   );
                                                   );
@@ -4589,7 +4599,7 @@ module ItsSecurity_TestCases {
            /**
            /**
             * @desc    Check that IUT discards a valid secured CAM message signed with implicit certificate containing signature
             * @desc    Check that IUT discards a valid secured CAM message signed with implicit certificate containing signature
             * <pre>
             * <pre>
             * Pics Selection: PICS_GN_SECURITY
             * Pics Selection: PICS_GN_SECURITY and (PICS_SEC_NIST_P256 or PICS_SEC_BRAINPOOL_P256R1)
             * Config Id: CF01
             * Config Id: CF01
             * Initial conditions:
             * Initial conditions:
             *  with {
             *  with {
@@ -4632,8 +4642,8 @@ module ItsSecurity_TestCases {
                var GnRawPayload v_sentRawPayload;
                var GnRawPayload v_sentRawPayload;
                
                
                // Test adapter configuration
                // Test adapter configuration
                if (not(PICS_GN_SECURITY)) {
                if (not(PICS_GN_SECURITY and (PICS_SEC_NIST_P256 or PICS_SEC_BRAINPOOL_P256R1))) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY and (PICS_SEC_NIST_P256 or PICS_SEC_BRAINPOOL_P256R1)' required for executing the TC ***");
                    stop;
                    stop;
                }
                }
                
                
@@ -4649,7 +4659,7 @@ module ItsSecurity_TestCases {
                
                
                // Test Body
                // Test Body
                v_securedGnPdu := f_sendSecuredCam(
                v_securedGnPdu := f_sendSecuredCam(
                                                cc_taCert_A,
                                                cc_iutCert_A_IMP_BO,
                                                valueof(m_headerInfo_cam(-, (f_getCurrentTime() * 1000)/*us*/)),
                                                valueof(m_headerInfo_cam(-, (f_getCurrentTime() * 1000)/*us*/)),
                                                valueof(m_signerIdentifier_certificate(vc_atCertificate)),
                                                valueof(m_signerIdentifier_certificate(vc_atCertificate)),
                                                f_getTsStationId()
                                                f_getTsStationId()
+12 −0
Original line number Original line Diff line number Diff line
@@ -1121,6 +1121,18 @@ module LibItsSecurity_Templates {
            ecdsaNistP384Signature := p_ecdsaNistP384Signature
            ecdsaNistP384Signature := p_ecdsaNistP384Signature
        } // End of template mw_signature_ecdsaNistP384
        } // End of template mw_signature_ecdsaNistP384
        
        
        template (value) Signature m_signature_ecsigSm2(
                                                             in template (value) EcsigP256Signature p_sm2Signature
        ) := {
            sm2Signature := p_sm2Signature
        } // End of template m_signature_ecsigSm2
        
        template (present) Signature mw_signature_ecsigSm2(
                                                                template (present) EcsigP256Signature p_sm2Signature := ?
        ) := {
            sm2Signature := p_sm2Signature
        } // End of template mw_signature_ecsigSm2
        
        template (value) EcdsaP256Signature m_ecdsaP256Signature(
        template (value) EcdsaP256Signature m_ecdsaP256Signature(
                                                                 in template (value) EccP256CurvePoint p_rSig,
                                                                 in template (value) EccP256CurvePoint p_rSig,
                                                                 in template (value) Oct32 p_sSig
                                                                 in template (value) Oct32 p_sSig
+88 −49
Original line number Original line Diff line number Diff line
@@ -1457,12 +1457,13 @@ module LibItsSecurity_Functions {
                var EtsiTs103097Certificate v_aaCertificate, v_atCertificate;
                var EtsiTs103097Certificate v_aaCertificate, v_atCertificate;


                log(">>> f_buildGnSecuredCam: p_payloadField= ", p_payloadField);
                log(">>> f_buildGnSecuredCam: p_payloadField= ", p_payloadField);
                log(">>> f_buildGnSecuredCam: p_certificateName= ", p_certificateName);
                
                
                // Load certificates if required
                // Load certificates if required
                if (f_prepareCertificates(p_certificateName, v_aaCertificate, v_atCertificate) == false) {
                if (f_prepareCertificates(p_certificateName, v_aaCertificate, v_atCertificate) == false) {
                    return false;
                    return false;
                }
                }
                //log("f_buildGnSecuredCam: v_atCertificate = ", v_atCertificate);
                log("f_buildGnSecuredCam: v_atCertificate = ", v_atCertificate);
                
                
                // Fill the structure with default values, these values will be updated later
                // Fill the structure with default values, these values will be updated later
                p_securedMessage := valueof(
                p_securedMessage := valueof(
@@ -1476,6 +1477,7 @@ module LibItsSecurity_Functions {
                ))));
                ))));
                // Prepare mandatory headers
                // Prepare mandatory headers
                log("f_buildGnSecuredCam: p_signerIdentifierType=", p_signerIdentifierType);
                log("f_buildGnSecuredCam: p_signerIdentifierType=", p_signerIdentifierType);
                if (v_atCertificate.type_ == explicit) {
                    if (ischosen(p_signerIdentifierType.digest)) { // Add the AT certificate digest
                    if (ischosen(p_signerIdentifierType.digest)) { // Add the AT certificate digest
                        if(p_signerIdentifierType.digest == '0000000000000000'O) {
                        if(p_signerIdentifierType.digest == '0000000000000000'O) {
                            if (ischosen(v_atCertificate.toBeSigned.verifyKeyIndicator.verificationKey.ecdsaNistP256) or
                            if (ischosen(v_atCertificate.toBeSigned.verifyKeyIndicator.verificationKey.ecdsaNistP256) or
@@ -1496,7 +1498,7 @@ module LibItsSecurity_Functions {
                    p_securedMessage.content.signedData.hashId := f_getHashAlgorithmOfVerificationKeyIndicator(v_atCertificate.toBeSigned.verifyKeyIndicator);
                    p_securedMessage.content.signedData.hashId := f_getHashAlgorithmOfVerificationKeyIndicator(v_atCertificate.toBeSigned.verifyKeyIndicator);


                    if (ischosen(v_atCertificate.toBeSigned.verifyKeyIndicator.verificationKey.ecdsaNistP256)) {
                    if (ischosen(v_atCertificate.toBeSigned.verifyKeyIndicator.verificationKey.ecdsaNistP256)) {
                    p_securedMessage.content.signedData.signature_ := valueof(  mw_signature_ecdsaNistP256(
                        p_securedMessage.content.signedData.signature_ := valueof(  m_signature_ecdsaNistP256(
                                                                                        m_ecdsaP256Signature(
                                                                                        m_ecdsaP256Signature(
                                                                                            m_eccP256CurvePoint_x_only(int2oct(0, 32)),
                                                                                            m_eccP256CurvePoint_x_only(int2oct(0, 32)),
                                                                                            int2oct(0, 32)
                                                                                            int2oct(0, 32)
@@ -1525,9 +1527,46 @@ module LibItsSecurity_Functions {
                                                                        ));
                                                                        ));
                    
                    
                    }
                    }
                } else { // Implicit certificate
                    if (ischosen(p_signerIdentifierType.digest)) { // Add the AT certificate digest
                        if(p_signerIdentifierType.digest == '0000000000000000'O) {
                            p_signerIdentifierType.digest := f_calculateDigestSha256FromCertificate(v_atCertificate);
                        }
                    } else if (ischosen(p_signerIdentifierType.certificate)) {
                        if(not(isvalue(p_signerIdentifierType.certificate))) {
                            p_signerIdentifierType.certificate := valueof({v_atCertificate});
                        }
                    } 
                    p_securedMessage.content.signedData.signer := valueof(p_signerIdentifierType);
                    if (ischosen(v_aaCertificate.toBeSigned.verifyKeyIndicator.verificationKey.ecdsaNistP256)) {
                        p_securedMessage.content.signedData.hashId := sha256;
                        p_securedMessage.content.signedData.signature_ := valueof(  m_signature_ecdsaNistP256(
                                                                                        m_ecdsaP256Signature(
                                                                                            m_eccP256CurvePoint_x_only(int2oct(0, 32)),
                                                                                            int2oct(0, 32)
                                                                                        )
                                                                        ));
                    } else if (ischosen(v_aaCertificate.toBeSigned.verifyKeyIndicator.verificationKey.ecdsaBrainpoolP256r1)) {
                        p_securedMessage.content.signedData.hashId := sha256;
                        p_securedMessage.content.signedData.signature_ := valueof(  m_signature_ecdsaBrainpoolP256r1(
                                                                                        m_ecdsaP256Signature(
                                                                                            m_eccP256CurvePoint_x_only(int2oct(0, 32)),
                                                                                            int2oct(0, 32)
                                                                                        )
                                                                        ));
                    } else if (ischosen(v_aaCertificate.toBeSigned.verifyKeyIndicator.verificationKey.ecsigSm2)) {
                        p_securedMessage.content.signedData.hashId := sm3; 
                        p_securedMessage.content.signedData.signature_ := valueof(  m_signature_ecsigSm2(
                                                                                        m_ecsigSm2P256Signature(
                                                                                            int2oct(0, 32),
                                                                                            int2oct(0, 32)
                                                                                        )
                                                                        ));
                    }
                }
                log("f_buildGnSecuredCam: p_securedMessage = ", p_securedMessage);
                log("f_buildGnSecuredCam: p_securedMessage = ", p_securedMessage);
                
                
                return f_buildGnSecuredMessage(p_securedMessage, p_certificateName, p_payloadField/*, v_mandatoryHeaders*/);
                return f_buildGnSecuredMessage(p_securedMessage, p_certificateName, p_payloadField);
                
                
            } // End of function f_buildGnSecuredCam
            } // End of function f_buildGnSecuredCam