ItsSecurity_TestCases.ttcn 1.58 MB
Newer Older
9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408
             * @desc    Check the certificate signature.
             * <pre>
             * Pics Selection: PICS_GN_SECURITY
             * Config Id: CF01
             * Initial conditions:
             *  with {
             *      the CA is authorized with AA certificate 
             *          containing toBeSigned
             *              containing verifyKeyIndicator
             *                  containing verificationKey
             *                      containing X_KEY
             *  }
             * Expected behaviour:
             * ensure that {
             *     when { 
             *         the IUT issued the AT certificate 
             *     } then {
             *         this certificate is of type EtsiTs103097Certificate
             *             containing issuer
             *                referencing the certificate
             *                    containing toBeSigned
             *                        containing verifyKeyIndicator
             *                            containing verificationKey
             *                                containing X_KEY
             *                                    indicating KEY
             *             and containing signature
             *                containing X_SIGNATURE
             *                    verifiable using KEY
             *     }
             * }
             * </pre>
             *
             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_16_BV
             * @reference   ETSI TS 103 097 [1], Clauses 6
             */
            testcase TC_SEC_ITSS_SND_CERT_16_BV() runs on ItsGeoNetworking system ItsSecSystem {
                    
                // Local variables
                var SequenceOfCertificate v_aa_certificate;
                var SignerIdentifier      v_signerIdentifier;
                var GeoNetworkingInd      v_geoNwInd;
                
                // Test control
                if (not(PICS_GN_SECURITY)) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
                    stop;
                }
                
                // Test component configuration
                f_cf01Up(); // Initialise IUT with CERT_IUT_A_AT signed with CERT_IUT_A_AA
                    
                // Test adapter configuration
                
                // Preamble
                f_prNeighbour();
                log("*** " & testcasename() & ": INFO: Wait for certificate and ask for AA certificate ***");
                tc_ac.start;
                f_askAndWaitForCertificateChain(v_aa_certificate, f_generateDefaultCam());
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                
                // Test Body
                tc_ac.start;
                alt {
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_cam
                                        ),
                                        mw_signerIdentifier_certificate( // Get the AT certificate
                                            mw_etsiTs103097Certificate(
                                                -,
                                                mw_toBeSignedCertificate_at
                    ))))))) -> value v_geoNwInd {
                        tc_ac.stop;
                        if (f_getMsgSignerIdentifier(f_getSecuredMessage(v_geoNwInd.msgIn), v_signerIdentifier)) {
                            var integer v_counter;
                            var charstring v_psid;
                            var template charstring v_found_pattern; // Used in regex to verify that 'v_psid' was not found before
                            
                            // Check in AA certificate
                            var charstring v_psid_found_aa := ";"; // Used to build the list of the Psid already processed
                            
                            for (v_counter := 0; v_counter < lengthof(v_aa_certificate[0].toBeSigned.appPermissions); v_counter := v_counter + 1) {
                                v_psid := int2str(v_aa_certificate[0].toBeSigned.appPermissions[v_counter].psid);
                                v_found_pattern := pattern "*({v_psid})*";
                                if (regexp(v_psid_found_aa, v_found_pattern, 0) == v_psid) {
                                    break; // v_psid exist at least 2 times, uniqueness is not verified
                                }
                                v_psid_found_aa := v_psid_found_aa & v_psid & ";";
                            } // End of 'for' statement
                            if (v_counter == lengthof(v_aa_certificate[0].toBeSigned.appPermissions)) {
                                var charstring v_psid_found_at := ";"; // Used to build the list of the Psid already processed
                                
                                for (v_counter := 0; v_counter < lengthof(v_signerIdentifier.certificate[0].toBeSigned.appPermissions); v_counter := v_counter + 1) {
                                    v_psid := int2str(v_signerIdentifier.certificate[0].toBeSigned.appPermissions[v_counter].psid);
                                    v_found_pattern := pattern "*({v_psid})*";
                                    if (regexp(v_psid_found_at, v_found_pattern, 0) == v_psid) {
                                        log("*** " & testcasename() & ": FAIL: AT certificate contains duplicated Psid ***"); 
                                        break; // v_psid exist at least 2 times, uniqueness is not verified
                                    } else if (regexp(v_psid_found_aa, v_found_pattern, 0) == v_psid) {
                                        log("*** " & testcasename() & ": FAIL: AT certificate contains a Psid not contained in AA certificate ***"); 
                                        break;
                                    }
                                    v_psid_found_at := v_psid_found_at & v_psid & ";";
                                } // End of 'for' statement
                                if (v_counter == lengthof(v_signerIdentifier.certificate[0].toBeSigned.appPermissions)) {
                                    log("*** " & testcasename() & ": PASS: Psid are unique in certificates ***"); 
                                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                                } else {
                                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                                }
                            } else {
                                log("*** " & testcasename() & ": FAIL: AA certificate contains duplicated Psid ***"); 
                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                            }
                        } else {
                            log("*** " & testcasename() & ": FAIL: IMPOSSIBLE!!! CAM generation location or certificate region restriction header field does not exist ***"); 
                            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                        }
                    }
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_cam
                                        ),
                                        mw_signerIdentifier_digest // containing digest
                                    )
                                )
                    ))) {
                        log("*** " & testcasename() & ": INFO: Generation of CAM messages including digest ***");
                        repeat;
                    }
                    [] tc_ac.timeout {
                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
                    }
                } // End of 'alt' statement
                
                // Postamble
                f_poNeighbour();
                f_cf01Down();
                
            } // End of testcase TC_SEC_ITSS_SND_CERT_16_BV
            
            /**
             * @desc    Check that IUT supports at least 8 items in the appPermissions component of the certificate.
             * <pre>
             * Pics Selection: PICS_GN_SECURITY
             * Config Id: CF01
             * Initial conditions:
             *  with {
             *      the IUT is authorized with AT certificate (CERT_IUT_A_AT_A8)
             *          containing toBeSigned
             *              containing appPermissions
             *                  containing 8 entries
             *                      indicating the last item
             *                          containing psid
             *                              indicating the ‘AID_CAM’
             *  }
             * Expected behaviour:
             * ensure that {
             *     when { 
             *         the IUT is requested to send a secured CAM
             *     } then {
             *         this certificate is of type EtsiTs103097Certificate
             *             containing containing content
             *                containing signedData
             *                    containing tbsData
             *                        containing headerInfo
             *                            containing psid
             *                                indicating 'AID_CAM'
             *     }
             * }
             * </pre>
             *
             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_17_BV
             * @reference   ETSI TS 103 097 [1], Clauses 6
             */
            testcase TC_SEC_ITSS_SND_CERT_17_BV() runs on ItsGeoNetworking system ItsSecSystem {
                    
                // Local variables
                
                // Test control
                if (not(PICS_GN_SECURITY)) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
                    stop;
                }
                
                // Test component configuration
                vc_hashedId8ToBeUsed := PICS_CERTFICATES_FOI[PICS_CERTFICATES_VAR].certificate_id; // FIXME
                f_cf01Up();
                    
                // Test adapter configuration
                
                // Preamble
                f_prNeighbour();
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                
                // Test Body
                tc_ac.start;
                alt {
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_cam
                                        )
                    ))))) {
                        tc_ac.stop;
                        log("*** " & testcasename() & ": PASS: ATS_AID was received ***"); 
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                    [] tc_ac.timeout {
                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
                    }
                } // End of 'alt' statement
                
                // Postamble
                f_poNeighbour();
                f_cf01Down();
                
            } // End of testcase TC_SEC_ITSS_SND_CERT_17_BV
            
            /**
             * @desc    Check that all PSID entries of the certIssuePermissions component of the certificate are unique.
             * <pre>
             * Pics Selection: PICS_GN_SECURITY
             * Config Id: CF01
             * Initial conditions:
             *  with {
             *      
             *  }
             * Expected behaviour:
             * ensure that {
             *     when { 
             *         the IUT issued the certificate 
             *             containing toBeSigned
             *                 containing certIssuePermissions
             *     } then {
             *         this certificate is of type EtsiTs103097Certificate
             *             containing toBeSigned
             *                 containing certIssuePermissions
             *                     containing items of type PsidGroupPermissions
             *                     and containing subjectPermissions
             *                         containing explicit
             *                             containing items of type PsidSspRange
             *                                 containing psid
             *                                     indicating unique values in this sequence
             *     }
             * }
             * </pre>
             *
             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_18_BV
             * @reference   ETSI TS 103 097 [1], Clauses 6.4.28 & 5.1.2.4
             */
            testcase TC_SEC_ITSS_SND_CERT_18_BV() runs on ItsGeoNetworking system ItsSecSystem {
                    
                // Local variables
                var SequenceOfCertificate v_aa_certificate;
                var integer v_counter;
                var integer v_counter1;
                var charstring v_psid;
                var charstring v_psid_found_aa := ";"; // Used to build the list of the Psid already processed
                var template charstring v_found_pattern; // Used in regex to verify that 'v_psid' was not found before
                
                // Test control
                if (not(PICS_GN_SECURITY)) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
                    stop;
                }
                
                // Test component configuration
                f_cf01Up(); // Initialise IUT with CERT_IUT_A_AT signed with CERT_IUT_A_AA
                    
                // Test adapter configuration
                
                // Preamble
                f_prNeighbour();
                log("*** " & testcasename() & ": INFO: Wait for certificate and ask for AA certificate ***");
                tc_ac.start;
                f_askAndWaitForCertificateChain(v_aa_certificate, f_generateDefaultCam());
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                
                // Test Body
                if (not(ispresent(v_aa_certificate[0].toBeSigned.certIssuePermissions))) {
                    log("*** " & testcasename() & ": FAIL: PsidGroupPermissions required in AA certificate ***"); 
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                } else {
                    for (v_counter := 0; v_counter < lengthof(v_aa_certificate[0].toBeSigned.certIssuePermissions); v_counter := v_counter + 1) {
                        if (match(v_aa_certificate[0].toBeSigned.certIssuePermissions[v_counter], mw_psidGroupPermissions(mw_subjectPermissions_explicit)) == false){
                            break;
                        }
                        for (v_counter1 := 0; v_counter1 < lengthof(v_aa_certificate[0].toBeSigned.certIssuePermissions[v_counter].subjectPermissions.explicit); v_counter1 := v_counter1 + 1) {
                            v_psid := int2str(v_aa_certificate[0].toBeSigned.certIssuePermissions[v_counter].subjectPermissions.explicit[v_counter1].psid);
                            v_found_pattern := pattern "*({v_psid})*";
                            if (regexp(v_psid_found_aa, v_found_pattern, 0) == v_psid) {
                                break; // v_psid exist at least 2 times, uniqueness is not verified
                            }
                            v_psid_found_aa := v_psid_found_aa & v_psid & ";";
                        } // End of 'for' statement
                        if (v_counter < lengthof(v_aa_certificate[0].toBeSigned.certIssuePermissions[v_counter].subjectPermissions.explicit)) {
                            break;
                        }
                    } // End of 'for' statement
                    if (v_counter == lengthof(v_aa_certificate[0].toBeSigned.certIssuePermissions)) {
                        log("*** " & testcasename() & ": PASS: Psid are unique in certificates ***"); 
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    } else {
                        log("*** " & testcasename() & ": FAIL: Wrong PsidGroupPermissions in AA certificate ***"); 
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                }
                
                // Postamble
                f_poNeighbour();
                f_cf01Down();
                
            } // End of testcase TC_SEC_ITSS_SND_CERT_18_BV
            
            /**
             * @desc    Check that IUT supports at least 8 items in the certIssuePermissions component of the certificate.
             * <pre>
             * Pics Selection: PICS_GN_SECURITY
             * Config Id: CF01
             * Initial conditions:
             *  with {
             *      the IUT is authorized with AT certificate (CERT_IUT_A_AT_A8)
             *          containing appPermissions
             *              conformed to the certIssuePermissions
             *          issued by AA certificate (CERT_IUT_A_AA_C8)
             *              containing toBeSigned
             *                  containing certIssuePermissions
             *                      containing 8 entries
             *                          indicating the last item
             *                              containing psid
             *                                  indicating the ‘AID_CAM’
             *  }
             * Expected behaviour:
             * ensure that {
             *     when { 
             *         the IUT is requested to send a secured CAM
             *     } then {
             *         this certificate is of type EtsiTs103097Certificate
             *             containing containing content
             *                containing signedData
             *                    containing tbsData
             *                        containing headerInfo
             *                            containing psid
             *                                indicating 'AID_CAM'
             *     }
             * }
             * </pre>
             *
             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_19_BV
             * @reference   ETSI TS 103 097 [1], Clauses 6.4.8
             */
            testcase TC_SEC_ITSS_SND_CERT_19_BV() runs on ItsGeoNetworking system ItsSecSystem {
                    
                // Local variables
                
                // Test control
                if (not(PICS_GN_SECURITY)) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
                    stop;
                }
                
                // Test component configuration
                vc_hashedId8ToBeUsed := PICS_CERTFICATES_FOI[PICS_CERTFICATES_VAR].certificate_id; // FIXME
                f_cf01Up();
                    
                // Test adapter configuration
                
                // Preamble
                f_prNeighbour();
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                
                // Test Body
                tc_ac.start;
                alt {
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_cam
                                        )
                    ))))) {
                        tc_ac.stop;
                        log("*** " & testcasename() & ": PASS: ATS_AID was received ***"); 
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                    [] tc_ac.timeout {
                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
                    }
                } // End of 'alt' statement
                
                // Postamble
                f_poNeighbour();
                f_cf01Down();
                
            } // End of testcase TC_SEC_ITSS_SND_CERT_19_BV
             * @desc    Check that all PSID entries of the appPermissions component of the certificate are also 
             *          contained in the certIssuePermissions component in the issuing certificate.
             * <pre>
             * Pics Selection: PICS_GN_SECURITY
             * Config Id: CF01
             * Initial conditions:
             *  with {
             *  }
             * Expected behaviour:
             * ensure that {
             *     when { 
             *         the IUT issued the certificate 
             *             containing toBeSigned
             *                 containing certIssuePermissions
             *     } then {
             *         this certificate is of type EtsiTs103097Certificate
             *             containing issuer
             *                 referenced to the certificate
             *                     containing toBeSigned
             *                         containing certIssuePermissions
             *                             containing items of type PsidGroupPermissions
             *                                 containing eeType
             *                                     indicating app(0)
             *                                 and containing subjectPermissions
             *                                     containing explicit
             *                                         containing items of type PsidSspRange
             *                                             indicating X_PSID_RANGE_LIST
             *                                     or containing all
             *             and containing toBeSigned
             *                 containing appPermissions
             *                    containing items of type PsidSsp
             *                        containing psid
             *                            contained in the X_PSID_RANGE_LIST
             *                                as a psid
             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_20_BV
             * @reference   ETSI TS 103 097 [1], Clauses 6.4.28 & 5.1.2.4
            testcase TC_SEC_ITSS_SND_CERT_20_BV() runs on ItsGeoNetworking system ItsSecSystem {
                    
                // Local variables
                var SequenceOfCertificate v_aa_certificate;
                var SignerIdentifier      v_signerIdentifier;
                var GeoNetworkingInd      v_geoNwInd;
                
                // Test control
                if (not(PICS_GN_SECURITY)) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
                    stop;
                }
                
                // Test component configuration
                f_cf01Up(); // Initialise IUT with CERT_IUT_A_AT signed with CERT_IUT_A_AA
                    
                // Test adapter configuration
                
                // Preamble
                f_prNeighbour();
                log("*** " & testcasename() & ": INFO: Wait for certificate and ask for AA certificate ***");
                tc_ac.start;
                f_askAndWaitForCertificateChain(v_aa_certificate, f_generateDefaultCam());
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                // Test Body
                tc_ac.start;
                alt {
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_cam
                                        ),
                                        mw_signerIdentifier_certificate( // Get the AT certificate
                                            mw_etsiTs103097Certificate(
                                                -,
                                                mw_toBeSignedCertificate_at
                    ))))))) -> value v_geoNwInd {
                        tc_ac.stop;
                        if (f_getMsgSignerIdentifier(f_getSecuredMessage(v_geoNwInd.msgIn), v_signerIdentifier)) {
                            var integer v_counter;
                            var integer v_counter1;
                            var charstring v_psid;
                            var charstring v_psid_found_aa := ";"; // Used to build the list of the Psid already processed
                            var template charstring v_found_pattern; // Used in regex to verify that 'v_psid' was not found before
                            
                            // Check in AA certificate
                            if (not(ispresent(v_aa_certificate[0].toBeSigned.certIssuePermissions))) {
                                log("*** " & testcasename() & ": FAIL: PsidGroupPermissions required in AA certificate ***"); 
                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                            } else {
                                for (v_counter := 0; v_counter < lengthof(v_aa_certificate[0].toBeSigned.certIssuePermissions); v_counter := v_counter + 1) {
                                    if (match(v_aa_certificate[0].toBeSigned.certIssuePermissions[v_counter], mw_psidGroupPermissions(mw_subjectPermissions_explicit)) == false){
                                        break;
                                    }
                                    for (v_counter1 := 0; v_counter1 < lengthof(v_aa_certificate[0].toBeSigned.certIssuePermissions[v_counter].subjectPermissions.explicit); v_counter1 := v_counter1 + 1) {
                                        v_psid := int2str(v_aa_certificate[0].toBeSigned.certIssuePermissions[v_counter].subjectPermissions.explicit[v_counter1].psid);
                                        v_found_pattern := pattern "*({v_psid})*";
                                        if (regexp(v_psid_found_aa, v_found_pattern, 0) == v_psid) {
                                            break; // v_psid exist at least 2 times, uniqueness is not verified
                                        }
                                        v_psid_found_aa := v_psid_found_aa & v_psid & ";";
                                    } // End of 'for' statement
                                    if (v_counter < lengthof(v_aa_certificate[0].toBeSigned.certIssuePermissions[v_counter].subjectPermissions.explicit)) {
                                        break;
                                    }
                                } // End of 'for' statement
                                if (v_counter == lengthof(v_aa_certificate[0].toBeSigned.certIssuePermissions)) {
                                    /*var charstring v_psid_found_at := ";"; // Used to build the list of the Psid already processed
                                    
                                    for (v_counter := 0; v_counter < lengthof(v_signerIdentifier.certificate[0].toBeSigned.appPermissions); v_counter := v_counter + 1) {
                                        v_psid := int2str(v_signerIdentifier.certificate[0].toBeSigned.appPermissions[v_counter].psid);
                                        v_found_pattern := pattern "*({v_psid})*";
                                        if (regexp(v_psid_found_at, v_found_pattern, 0) == v_psid) {
                                            log("*** " & testcasename() & ": FAIL: AT certificate contains duplicated Psid ***"); 
                                            break; // v_psid exist at least 2 times, uniqueness is not verified
                                        } else if (regexp(v_psid_found_aa, v_found_pattern, 0) == v_psid) {
                                            log("*** " & testcasename() & ": FAIL: AT certificate contains a Psid not contained in AA certificate ***"); 
                                            break;
                                        }
                                        v_psid_found_at := v_psid_found_at & v_psid & ";";
                                    } // End of 'for' statement
                                    if (v_counter == lengthof(v_signerIdentifier.certificate[0].toBeSigned.appPermissions)) {
                                        log("*** " & testcasename() & ": PASS: Psid are unique in certificates ***"); 
                                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                                    } else {
                                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                                    }*/

                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    
                                    log("*** " & testcasename() & ": PASS: Psid are unique in certificates ***"); 
                                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                                } else {
                                    log("*** " & testcasename() & ": FAIL: Wrong PsidGroupPermissions in AA certificate ***"); 
                                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                                }
                            }
                        } else {
                            log("*** " & testcasename() & ": FAIL: IMPOSSIBLE!!! CAM generation location or certificate region restriction header field does not exist ***"); 
                            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                        }
                    }
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_cam
                                        ),
                                        mw_signerIdentifier_digest // containing digest
                                    )
                                )
                    ))) {
                        log("*** " & testcasename() & ": INFO: Generation of CAM messages including digest ***");
                        repeat;
                    }
                    [] tc_ac.timeout {
                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
                    }
                } // End of 'alt' statement
                
                // Postamble
                f_poNeighbour();
                f_cf01Down();
                
            } // End of testcase TC_SEC_ITSS_SND_CERT_20_BV
             * @desc    Check that SSP field in each entry of the appPermissions component of the AT certificate is 
             *          equal to or a subset of the SSP Range in the corresponding issuing entry.
             * <pre>
             * Pics Selection: PICS_GN_SECURITY
             * Config Id: CF01
             * Initial conditions:
             *  with {
             *  }
             * Expected behaviour:
             * ensure that {
             *     when { 
             *         the IUT issued the certificate 
             *             containing toBeSigned
             *                 containing certIssuePermissions
             *     } then {
             *         this certificate is of type EtsiTs103097Certificate
             *             containing issuer
             *                 referenced to the certificate
             *                     containing toBeSigned
             *                         containing certIssuePermissions
             *                             containing items of type PsidGroupPermissions
             *                                 containing eeType
             *                                     indicating app(0)
             *                                 and containing explicit
             *                                     containing psid
             *                                         indicating X_PSID_AA
             *                                     and containing sspRange
             *                                         indicating X_SSP_AA [ X_PSID_AA ]
             *                                 or containing all
             *             and containing toBeSigned
             *                 containing appPermissions
             *                    containing items of type PsidSsp
             *                        containing psid
             *                            indicating value equal to X_PSID_AA
             *                        and containing ssp
             *                            indicating value permitted by X_SSP_AA [ X_PSID_AA ]
             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_21_BV
             * @reference   ETSI TS 103 097 [1], Clauses 6.4.28 & 5.1.2.4
            testcase TC_SEC_ITSS_SND_CERT_21_BV() runs on ItsGeoNetworking system ItsSecSystem {
                    
                // Local variables
                var SequenceOfCertificate v_aa_certificate;
                var SignerIdentifier      v_signerIdentifier;
                var GeoNetworkingInd      v_geoNwInd;
                
                // Test control
                if (not(PICS_GN_SECURITY)) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
                    stop;
                }
                
                // Test component configuration
                f_cf01Up(); // Initialise IUT with CERT_IUT_A_AT signed with CERT_IUT_A_AA
                    
                // Test adapter configuration
                
                // Preamble
                f_prNeighbour();
                log("*** " & testcasename() & ": INFO: Wait for certificate and ask for AA certificate ***");
                tc_ac.start;
                f_askAndWaitForCertificateChain(v_aa_certificate, f_generateDefaultCam());
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                // Test Body
                tc_ac.start;
                alt {
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_cam
                                        ),
                                        mw_signerIdentifier_certificate( // Get the AT certificate
                                            mw_etsiTs103097Certificate(
                                                -,
                                                mw_toBeSignedCertificate_at
                    ))))))) -> value v_geoNwInd {
                        tc_ac.stop;
                        if (f_getMsgSignerIdentifier(f_getSecuredMessage(v_geoNwInd.msgIn), v_signerIdentifier)) {
                            // Check in AA certificate
                            if (not(ispresent(v_aa_certificate[0].toBeSigned.certIssuePermissions))) {
                                log("*** " & testcasename() & ": FAIL: PsidGroupPermissions required in AA certificate ***"); 
                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                            } else { // Parse AT SSP and compared it in AA
                                for (var integer v_counter := 0; v_counter < lengthof(v_signerIdentifier.certificate[0].toBeSigned.appPermissions); v_counter := v_counter + 1) {
                                    var Psid v_psid := v_signerIdentifier.certificate[0].toBeSigned.appPermissions[v_counter].psid;
                                    var ServiceSpecificPermissions v_ssp := v_signerIdentifier.certificate[0].toBeSigned.appPermissions[v_counter].ssp;
                                    for (var integer v_counter1 := 0; v_counter1 < lengthof(v_aa_certificate[0].toBeSigned.certIssuePermissions); v_counter1 := v_counter1 + 1) {
                                        var SequenceOfPsidSspRange v_psidSsps;
                                        var integer v_counter2;
                                        if (match(v_aa_certificate[0].toBeSigned.certIssuePermissions[v_counter], mw_psidGroupPermissions(mw_subjectPermissions_explicit)) == false){
                                            log("*** " & testcasename() & ": FAIL: AA  certificate field certIssuePermissions does not match ***");
                                            f_setVerdict(e_error);
                                            break;
                                        }
                                        v_psidSsps := v_aa_certificate[0].toBeSigned.certIssuePermissions[v_counter1].subjectPermissions.explicit;
                                        for (v_counter2 := 0; v_counter2 < lengthof(v_psidSsps); v_counter2 := v_counter2 + 1) {
                                            if (v_psidSsps[v_counter2].psid == v_psid) {
                                                if (ispresent(v_psidSsps[v_counter2].sspRange)) {
                                                    var SspRange v_sspRange := v_psidSsps[v_counter2].sspRange;
                                                    // Compare SSps
                                                    log(" Compare '", v_sspRange, "' with '", v_ssp, "'");
                                                    if (not(ischosen(v_sspRange.all_))) {
                                                        if (ischosen(v_sspRange.opaque) and ischosen(v_ssp.opaque)) {
                                                            // TODO How to compare values?
                                                        } else if (ischosen(v_sspRange.bitmapSspRange) and ischosen(v_ssp.bitmapSsp)) {
                                                            // TODO How to compare values?
                                                        } else {
                                                            log("*** " & testcasename() & ": FAIL: SSPs do not match ***");
                                                            f_setVerdict(e_error);
                                                            break;
                                                        }
                                                    } // else All rights are sey, nothing to check
                                                } else {
                                                    log("*** " & testcasename() & ": FAIL: AA certificate field SspRange field is missging ***");
                                                    f_setVerdict(e_error);
                                                    break;
                                                }
                                                break;
                                            }
                                        } // End of 'for' statement
                                        if (v_counter2 == lengthof(v_psidSsps)) { // Psid not found
                                            log("*** " & testcasename() & ": FAIL: psid ", v_psid, " not found in AT certificate ***");
                                            f_setVerdict(e_error);
                                            break;
                                        }
                                    } // End of 'for' statement
                                } // End of 'for' statement
                                if (getverdict == fail) {
                                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                                } else {
                                    log("*** " & testcasename() & ": PASS: SSP rage are well configured ***"); 
                                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                                }                                
                            }
                        } else {
                            log("*** " & testcasename() & ": FAIL: IMPOSSIBLE!!! CAM generation location or certificate region restriction header field does not exist ***"); 
                            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                        }
                    }
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_cam
                                        ),
                                        mw_signerIdentifier_digest // containing digest
                                    )
                                )
                    ))) {
                        log("*** " & testcasename() & ": INFO: Generation of CAM messages including digest ***");
                        repeat;
                    }
                    [] tc_ac.timeout {
                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
                    }
                } // End of 'alt' statement
                
                // Postamble
                f_poNeighbour();
                f_cf01Down();
                
            } // End of testcase TC_SEC_ITSS_SND_CERT_21_BV
//            /**
//             * @desc Sending behaviour test cases for AA certificate profil
garciay's avatar
garciay committed
//             * @see ETSI TS 103 096-2 V1.3.32 (2018-01) Clause 5.2.7.7 AA certificate profile
//             */
//            group AA_Certificates {
//                
//                /**
//                 * @desc Check that the subject_type of the AA certificate is set to authorization_authority
//                 * <pre>
//                 * Pics Selection: PICS_GN_SECURITY
//                 * Config Id: CF01
//                 * with {
//                 *   the IUT being in the 'authorized' state
//                 *   the IUT being requested to include certificate chain in the next CAM
//                 * } ensure that {
//                 *    when {
//                 *     the IUT is requested to send a CAM
//                 *   } then {
//                 *     the IUT sends a Ieee1609Dot2Data
//                 *       containing header_fields['signer_info'].signer
//                 *         containing type
//                 *           indicating 'certificate_chain'
//                 *         containing certificates[last-1]
//                 *           containing subject_info.subject_type
//                 *             indicating 'authorization_authority' (2)
//                 *   }
//                 * }
//                 * </pre>
garciay's avatar
garciay committed
//                 * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_AA_01_01_BV
//                 * @reference   ETSI TS 103 097 [1], clause 7.4.4
//                 */
//                testcase TC_SEC_ITSS_SND_CERT_AA_01_01_BV() runs on ItsGeoNetworking system ItsSecSystem {
//                    var SequenceOfCertificate         v_chain;
//                    
//                    // Test control
//                    if (not(PICS_GN_SECURITY)) {
//                        log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
//                        stop;
//                    }
//                    
//                    // Test component configuration
//                    f_cf01Up();
//                    
//                    // Test adapter configuration
//                    
//                    // Preamble
//                    f_prNeighbour();
//                    f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
//                    
//                    // Test Body
//                    log("*** " & testcasename() & ": INFO: Request and waiting for the message containing certificate chain  ***");
//                    tc_ac.start;
//                    if (not f_askAndWaitForCertificateChain(v_chain, f_generateDefaultCam())) {
//                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
//                        f_selfOrClientSyncAndVerdictPreamble(c_tbDone, e_timeout);
//                    }
//                    tc_ac.stop;
//                    if (lengthof(v_chain) < 2) {
//                        log("*** " & testcasename() & ": FAIL: Certificate chain is too short ***");
//                        f_selfOrClientSyncAndVerdictPreamble(c_tbDone, e_error);
//                    }
//                    if (not match(v_chain[lengthof(v_chain) - 2], mw_aa_certificate)) {
//                        log("*** " & testcasename() & ": FAIL: AA certificate not found in the chain[last-1] ***");
//                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                    }
//                    log("*** " & testcasename() & ": PASS: AA certificate was found in the chain ***");
//                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
//                    
//                    // Postamble
//                    f_poNeighbour();
//                    f_cf01Down();
//                } // End of testcase TC_SEC_ITSS_SND_CERT_AA_01_01_BV
//                
//                /**
//                 * @desc Check that the AA certificsate subject_name variable-length vector contains 32 bytes maximum
//                 * <pre>
//                 * Pics Selection: PICS_GN_SECURITY
//                 * Config Id: CF01
//                 * with {
//                 *   the IUT being in the 'authorized' state
//                 *   the IUT being requested to include certificate chain in the next CAM
//                 * } ensure that {
//                 *    when {
//                 *     the IUT is requested to send a CAM
//                 *   } then {
//                 *     the IUT sends a Ieee1609Dot2Data
//                 *       containing header_fields['signer_info'].signer
//                 *         containing type
//                 *           indicating 'certificate_chain'
//                 *         containing certificates[last-1]
//                 *           containing subject_info.subject_name
//                 *             indicating length <= 32 bytes
//                 *   }
//                 * }
//                 * </pre>
garciay's avatar
garciay committed
//                 * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_AA_02_01_BV
//                 * @reference   ETSI TS 103 097 [1], clause 6.2
//                 */
//                testcase TC_SEC_ITSS_SND_CERT_AA_02_01_BV() runs on ItsGeoNetworking system ItsSecSystem {
//                    var SequenceOfCertificate         v_chain;
//                    
//                    // Test control
//                    if (not(PICS_GN_SECURITY)) {
//                        log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
//                        stop;
//                    }
//                    
//                    // Test component configuration
//                    f_cf01Up();
//                    
//                    // Test adapter configuration
//                    
//                    // Preamble
//                    f_prNeighbour();
//                    f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
//                    
//                    // Test Body
//                    log("*** " & testcasename() & ": INFO: Request and waiting for the message containing certificate chain  ***");
//                    tc_ac.start;
//                    if (not f_askAndWaitForCertificateChain(v_chain, f_generateDefaultCam())) {
//                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
//                        f_selfOrClientSyncAndVerdictPreamble(c_tbDone, e_timeout);
//                    }
//                    tc_ac.stop;
//                    if (lengthof(v_chain) < 2) {
//                        log("*** " & testcasename() & ": FAIL: Certificate chain is too short ***");
//                        f_selfOrClientSyncAndVerdictPreamble(c_tbDone, e_error);
//                    }
//                    // Verified automatically on decoding
//                    if (lengthof(v_chain[lengthof(v_chain) - 2].subject_info.subject_name) > 32 ) {
//                        log("*** " & testcasename() & ": FAIL: Subject name of the AA certificate is too long ***");
//                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                    }
//                    log("*** " & testcasename() & ": PASS: Subject name of the AA certificate is good ***");
//                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
//                    
//                    // Postamble
//                    f_poNeighbour();
//                    f_cf01Down();
//                } // End of testcase TC_SEC_ITSS_SND_CERT_AA_02_01_BV
//                
//                /**
//                 * @desc Check that signer_info type of AA certificates is set to 'certificate_digest_with_sha256'
//                 * <pre>
//                 * Pics Selection: PICS_GN_SECURITY
//                 * Config Id: CF01
//                 * with {
//                 *   the IUT being in the 'authorized' state
//                 *   the IUT being requested to include certificate chain in the next CAM
//                 * } ensure that {
//                 *    when {
//                 *     the IUT is requested to send a CAM
//                 *   } then {
//                 *     the IUT sends a Ieee1609Dot2Data
//                 *       containing header_fields['signer_info'].signer
//                 *         containing type
//                 *           indicating 'certificate_chain'
//                 *         containing certificates[last-1]
//                 *           containing signer_info
//                 *             containing type
//                 *               indicating 'certificate_digest_with_sha256'
//                 *   }
//                 * }
//                 * </pre>
garciay's avatar
garciay committed
//                 * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_AA_03_01_BV
//                 * @reference   ETSI TS 103 097 [1], clause 7.4.4
//                 */
//                testcase TC_SEC_ITSS_SND_CERT_AA_03_01_BV() runs on ItsGeoNetworking system ItsSecSystem {
//                    var SequenceOfCertificate         v_chain;
//                    var Certificate              v_aa_cert;
//                    
//                    // Test control
//                    if (not(PICS_GN_SECURITY)) {
//                        log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY' required for executing the TC ***");
//                        stop;
//                    }
//                    
//                    // Test component configuration
//                    f_cf01Up();
//                    
//                    // Test adapter configuration
//                    
//                    // Preamble
//                    f_prNeighbour();
//                    f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
//                    
//                    // Test Body
//                    log("*** " & testcasename() & ": INFO: Request and waiting for the message containing certificate chain  ***");
//                    tc_ac.start;
//                    if (not f_askAndWaitForCertificateChain(v_chain, f_generateDefaultCam())) {
//                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
//                        f_selfOrClientSyncAndVerdictPreamble(c_tbDone, e_timeout);
//                    }
//                    tc_ac.stop;
//                    if (lengthof(v_chain) < 2) {
//                        log("*** " & testcasename() & ": FAIL: Certificate chain is too short ***");
//                        f_selfOrClientSyncAndVerdictPreamble(c_tbDone, e_error);
//                    }
//                    v_aa_cert := v_chain[lengthof(v_chain) - 2];
//                    if (not match(v_aa_cert, mw_aa_certificate(mw_signerIdentifier_digest))) {
//                        log("*** " & testcasename() & ": FAIL: AA certificate not signed by digest ***");
//                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                    }
//                    log("*** " & testcasename() & ": PASS: AA certificate is signed by digest ***");
//                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
//