ItsSecurity_TestCases.ttcn 1.53 MB
Newer Older
6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445
             *                              and containing duration
             *                                  indicating value > GEN_TIME - X_START_VALIDITY 
             *     }
             * }
             * </pre>
             *
             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_GENMSG_05_BV
             * @reference   ETSI TS 103 097 [1] Clauses 7.1.3
             * @reference   IEEE 1609.2 [2], clause 6.3.4
             */
            testcase TC_SEC_ITSS_SND_GENMSG_05_BV() runs on ItsGeoNetworking system ItsSecSystem {
                    
                // Local variables
                const integer        c_timeLimit := 10 * 60 * 1000000; // us
                var LongPosVector v_longPosVectorIut;
                var GeoNetworkingInd v_geoNwInd;
                var HeaderInfo       v_headerInfo;
                var Time64           v_generationTime;
                var Time64           v_curTime;
                var SignerIdentifier v_signerIdentifier;
                var ValidityPeriod   v_validityPeriod;
                var Certificate      v_cert;
                    
                // Test control
                if (not(PICS_GN_SECURITY) or not(PICS_SEC_ITS_AID_OTHER)) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY and PICS_SEC_ITS_AID_OTHER' required for executing the TC ***");
                    stop;
                }
                
                // Test component configuration
                f_cf01Up(); // Initialise IUT with CERT_IUT_A_AT signed with CERT_IUT_A_AA
                v_longPosVectorIut := f_getPosition(c_compIut);
                    
                // Test adapter configuration
                
                // Preamble
                f_prNeighbour();
                f_acTriggerEvent(m_startPassBeaconing(m_beaconHeader(v_longPosVectorIut).beaconHeader)); // Authorize the TA to forward the received beacons
                alt {
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_gn
                                        ),
                                        mw_signerIdentifier_certificate // containing certificate
                                    )
                                )
                    ))) {
                        tc_ac.stop;
                        log("*** " & testcasename() & ": INFO: Initial conditions: First GN message with certificate received ***");
                        f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                    }
                    [] tc_ac.timeout {
                        log("*** " & testcasename() & ": INCONC: Initial conditions: GN message with certificate not received ***");
                        f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_timeout);
                    }
                } // End of 'alt' statement
                
                // Test Body
                tc_ac.start;
                alt {
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_gn
                                        ),
                                        mw_signerIdentifier_certificate // containing certificate
                                    )
                                )
                    ))) -> value v_geoNwInd {
                        tc_ac.stop;
                        f_getMsgHeaderInfo(f_getSecuredMessage(v_geoNwInd.msgIn), v_headerInfo);
                        v_generationTime := v_headerInfo.generationTime;
                        v_curTime := f_getCurrentTime();
                        v_curTime := v_curTime * 1000; // Time64 is in microseconds 
                        log("v_curTime (us)=", v_curTime);
                        // Check generation time
                        if (not match(v_generationTime, Time64:(v_curTime - c_timeLimit, v_curTime + c_timeLimit))) {
                            log("*** " & testcasename() & ": FAIL: GN generation time is not in 5 min range");
                            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                        } else {
                            // Check certificate validity period
                            f_getMsgSignerIdentifier (f_getSecuredMessage(v_geoNwInd.msgIn), v_signerIdentifier);
                            if (not match(v_signerIdentifier.certificate[0].toBeSigned.validityPeriod, Time64:(v_curTime - c_timeLimit, v_curTime + c_timeLimit))) {
                                log("*** " & testcasename() & ": FAIL: GN certificate validity period is not in 5 min range");
                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                            } else {
                                log("*** " & testcasename() & ": PASS: Generation of GN messages including certificate was successful ***");
                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                            }
                        }
                    }
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_gn
                                        ),
                                        mw_signerIdentifier_digest // containing digest
                                    )
                                )
                    ))) {
                        log("*** " & testcasename() & ": PASS: Correct secured packet received, containing digest ***");
                        repeat;
                    }
                    [] tc_ac.timeout {
                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
                    }
                } // End of 'alt' statement
                
                // Postamble
                f_acTriggerEvent(m_stopPassBeaconing);
                f_poNeighbour();
                f_cf01Down();
                
            } // End of testcase TC_SEC_ITSS_SND_GENMSG_05_BV
            
            /**
             * @desc    Check that IUT sends the secured message using the 'data' field in signed data payload, 
             *          containing the EtsiTs103097Data of type unsecured, 
             *          containing the data payload or using the extDataHash field containing the SHA256 hash of data payload.
             * <pre>
             * Pics Selection: PICS_GN_SECURITY and PICS_SEC_ITS_AID_OTHER
             * Config Id: CF01
             * Initial conditions:
             *  with {
             *      the IUT is authorized with AT certificate (CERT_IUT_A_AT)
             *  }
             * Expected behaviour:
             * ensure that {
             *     when { 
             *         the IUT is requested to send a secured Beacon
             *     } then {
             *          the IUT sends a message of type EtsiTs103097Data
             *              contains content
             *                  contains signedData
             *                      containing tbsData
             *                          containing payload
             *                              containing data
             *                                  containing content
             *                                      containing unsecuredData
             *                                          containing not-empty data
             *     }
             * }
             * </pre>
             *
             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_GENMSG_06_BV
             * @reference   ETSI TS 103 097 [1] Clauses 7.1.3
             */
            testcase TC_SEC_ITSS_SND_GENMSG_06_BV() runs on ItsGeoNetworking system ItsSecSystem {
                    
                // Local variables
                var LongPosVector v_longPosVectorIut;
                    
                // Test control
                if (not(PICS_GN_SECURITY) or not(PICS_SEC_ITS_AID_OTHER)) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY and PICS_SEC_ITS_AID_OTHER' required for executing the TC ***");
                    stop;
                }
                
                // Test component configuration
                f_cf01Up(); // Initialise IUT with CERT_IUT_A_AT signed with CERT_IUT_A_AA
                v_longPosVectorIut := f_getPosition(c_compIut);
                    
                // Test adapter configuration
                
                // Preamble
                f_prNeighbour();
                f_acTriggerEvent(m_startPassBeaconing(m_beaconHeader(v_longPosVectorIut).beaconHeader)); // Authorize the TA to forward the received beacons
                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_ieee1609Dot2Data(
                                                    mw_ieee1609Dot2Data_unsecured
                                            )),
                                            mw_headerInfo_gn
                                        )
                                    )
                                )
                    ))) {
                        tc_ac.stop;
                        log("*** " & testcasename() & ": PASS: GN received with a well formated payload ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                    }
                    [] tc_ac.timeout {
                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
                    }
                } // End of 'alt' statement
                
                // Postamble
                f_acTriggerEvent(m_stopPassBeaconing);
                f_poNeighbour();
                f_cf01Down();
                
            } // End of testcase TC_SEC_ITSS_SND_GENMSG_06_BV
            
            /**
             * @desc    Check that the IUT sends the secured messages signed with the certificate 
             *          containing appPermisions allowing to sign these messages.
             * <pre>
             * Pics Selection: PICS_GN_SECURITY and PICS_SEC_ITS_AID_OTHER
             * Config Id: CF01
             * Initial conditions:
             *  with {
             *      the IUT is authorized with AT certificate (CERT_IUT_A_AT)
             *  }
             * Expected behaviour:
             * ensure that {
             *     when { 
             *         the IUT is requested to send a secured Beacon
             *     } then {
             *         the IUT sends a message of type EtsiTs103097Data
             *              contains content
             *                  contains signedData
             *                      containing tbsData
             *                          containing payload
             *                              containing data
             *                                  containing content
             *                                      containing unsecuredData
             *                                          containing not-empty data
             *     }
             * }
             * </pre>
             *
             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_GENMSG_07_BV
             * @reference   ETSI TS 103 097 [1] Clauses 7.1.3
             * @reference   IEEE 1609.2 [2], clause 5.2.3.2.2
             */
            testcase TC_SEC_ITSS_SND_GENMSG_07_BV() runs on ItsGeoNetworking system ItsSecSystem {
                    
                // Local variables
                var LongPosVector v_longPosVectorIut;
                    
                // Test control
                if (not(PICS_GN_SECURITY) or not(PICS_SEC_ITS_AID_OTHER)) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY and PICS_SEC_ITS_AID_OTHER' required for executing the TC ***");
                    stop;
                }
                
                // Test component configuration
                f_cf01Up(); // Initialise IUT with CERT_IUT_A_AT signed with CERT_IUT_A_AA
                v_longPosVectorIut := f_getPosition(c_compIut);
                    
                // Test adapter configuration
                
                // Preamble
                f_prNeighbour();
                f_acTriggerEvent(m_startPassBeaconing(m_beaconHeader(v_longPosVectorIut).beaconHeader)); // Authorize the TA to forward the received beacons
                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_gn
                                        ),
                                        mw_signerIdentifier_digest // containing digest
                                    )
                                )
                    ))) {
                        tc_ac.stop;
                        log("*** " & testcasename() & ": PASS: Correct secured packet received, containing digest ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                    }
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        -, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload(
                                                mw_ieee1609Dot2Data(
                                                    mw_ieee1609Dot2Data_unsecured
                                            )),
                                            mw_headerInfo_gn
                                        )
                                    )
                                )
                    ))) {
                        tc_ac.stop;
                        log("*** " & testcasename() & ": PASS: received with a well formated payload ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                    }
                    [] tc_ac.timeout {
                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
                    }
                } // End of 'alt' statement
                
                // Postamble
                f_acTriggerEvent(m_stopPassBeaconing);
                f_poNeighbour();
                f_cf01Down();
                
            } // End of testcase TC_SEC_ITSS_SND_GENMSG_07_BV
                        
            /**
             * @desc    Check that IUT sends the secured GeoNetworking message containing signature;
             *          Check that the signature is calculated over the right fields and using right 
             *          hash algorythm by cryptographically verifying the signature.
             * <pre>
             * Pics Selection: PICS_GN_SECURITY and PICS_SEC_ITS_AID_OTHER
             * Config Id: CF01
             * Initial conditions:
             *  with {
             *      the IUT is authorized with AT certificate (X_CERTIFICATE) 
             *  }
             *  ensure that {
             *      when {
             *          the IUT is requested to send a secured beacon
             *      } then {
             *          the IUT sends a message of type EtsiTs103097Data
             *              containing signedData
             *                  containing signer
             *                       containing digest
             *                           referencing the certificate X_CERTIFICATE
             *                       or containing certificate
             *                           indicating X_CERTIFICATE
             *                  and containing signature
             *                      containing X_SIGNATURE
             *                          verifiable using KEY 
             *      }
             *  }
             * </pre>
             *
             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_GENMSG_08_BV
             * @reference   ETSI TS 103 097 [1], clauses 5.2, 7.1.3
             * @reference   IEEE 1609.2 [2], clauses 5.3.1, 6.3.4, 6.3.29, 6.3.30, 6.3.31
             */
            testcase TC_SEC_ITSS_SND_GENMSG_08_BV() runs on ItsGeoNetworking system ItsSecSystem {
                    
                // Local variables
                var LongPosVector           v_longPosVectorIut;
                var EtsiTs103097Certificate v_certificate;
                var Signature               v_signature;
                var GeoNetworkingInd        v_geoNwInd;
                    
                // Test control
                if (not(PICS_GN_SECURITY) or not(PICS_SEC_ITS_AID_OTHER)) {
                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY and PICS_SEC_ITS_AID_OTHER' required for executing the TC ***");
                    stop;
                }
                
                // Test component configuration
                vc_hashedId8ToBeUsed := PICS_CERTFICATES_FOI[PICS_CERTFICATES_VAR].certificate_id;
                f_cf01Up();
                v_longPosVectorIut := f_getPosition(c_compIut);
                    
                // Test adapter configuration
                
                // Preamble
                f_prNeighbour();
                f_readCertificate(vc_hashedId8ToBeUsed, v_certificate);
                f_acTriggerEvent(m_startPassBeaconing(m_beaconHeader(v_longPosVectorIut).beaconHeader)); // Authorize the TA to forward the received beacons
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                
                // Test Body
                tc_ac.start;
                alt {
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        PICS_CERTFICATES_FOI[PICS_CERTFICATES_VAR].hashAlgorithm, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_gn
                                        ),
                                        mw_signerIdentifier_digest( // containing digest referencing the certificate X_CERTIFICATE
                                            PICS_CERTFICATES_FOI[PICS_CERTFICATES_VAR].issuer
                                        )
                                    )
                                )
                    ))) -> value v_geoNwInd {
                        tc_ac.stop;
                        log("*** " & testcasename() & ": INFO: GN message with digest received ***");
                    }
                    [] geoNetworkingPort.receive(
                        mw_geoNwInd(
                            mw_geoNwSecPdu(
                                mw_etsiTs103097Data_signed(
                                    mw_signedData(
                                        PICS_CERTFICATES_FOI[PICS_CERTFICATES_VAR].hashAlgorithm, 
                                        mw_toBeSignedData(
                                            mw_signedDataPayload,
                                            mw_headerInfo_gn
                                        ),
                                        mw_signerIdentifier_certificate( // or containing containing certificate indicating X_CERTIFICATE
                                            v_certificate
                                        )
                                    )
                                )
                    ))) -> value v_geoNwInd {
                        tc_ac.stop;
                        log("*** " & testcasename() & ": INFO: GN message with certificate received ***");
                    }
                    [] tc_ac.timeout {
                        log("*** " & testcasename() & ": INCONC: Expected message not received ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
                    }
                } // End of 'alt' statement
                
                // Postamble
                f_acTriggerEvent(m_stopPassBeaconing);
                f_poNeighbour();
                f_cf01Down();
                
            } // End of testcase TC_SEC_ITSS_SND_GENMSG_08_BV
                        
        } // End of group sendOtherProfile
         * @desc Sending behaviour test cases for certificates profile
         * @see ETSI TS 103 096-2 V1.3.32 (2018-01) Clause 5.2.7 Encrypted messages profile
        group encryptedMessagesProfile {
            
            // TODO
            
        } // End of group encryptedMessagesProfile
        
        /**
         * @desc Sending behaviour test cases for certificates profile
         * @see ETSI TS 103 096-2 V1.3.32 (2018-01) Clause 5.2.8 Profiles for certificates
         */
        group sendCertificatesProfile {
            
        /**
         * @desc    Check that IUT certificate is explicit and has version 3.
         * <pre>
         * Pics Selection: PICS_GN_SECURITY
         * Config Id: CF01
         * Initial conditions:
         *  with {
         *      the IUT being in the 'authorized' state
         *  }
         * Expected behaviour:
         * ensure that {
         *     when { 
         *         the AA is issued the certificate
         *     } then {
         *         this certificate is of type EtsiTs103097Certificate
         *             containing version
         *                 indicating 3
         *             and containing type
         *                 indicating ‘explicit’
         *             and containing toBeSigned
         *                 containing verifyKeyIndicator
         *                     containing verificationKey
         *     }
         * }
         * </pre>
         *
         * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_01_BV
         * @reference   ETSI TS 103 097 [1], clauses 6
         * @reference   IEEE 1609.2 [2], clause 6.4.3
         */
        testcase TC_SEC_ITSS_SND_CERT_01_BV() runs on ItsGeoNetworking system ItsSecSystem {
                
            // Local variables
            var Ieee1609Dot2Data v_recv;
            var Certificate v_cert;
            var HashedId8 v_digest;
                
            // 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();
            // Wait for the message with the certificate to retrieve the AA digest.
            // Ask for the chain, containing AT and AA certificate
            // Check AA Certificate
            log("*** " & testcasename() & ": INFO: Wait for certificate and ask for certificate chain  ***");
            tc_ac.start;
            f_askForCertificateChain(f_generateDefaultCam());
            tc_ac.stop;
            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_ieee1609Dot2_headerInfo_request_certificate(
                                            -,
                                            mw_etsiTs103097Certificate(
                                                -,
                                                mw_toBeSignedCertificate_aa
                )))))))) {
                    tc_ac.stop;
                    log("*** " & testcasename() & ": PASS: Security protocol version set to 3 ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                }
                [] 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_01_BV
        
//            /**
//             * @desc    Check that AA certificate has version 2
//             * <pre>
//             * Pics Selection: PICS_GN_SECURITY
//             * Config Id: CF01
//             * Initial conditions:
//             * with {
//             *   the IUT being in the 'authorized' state
//             *      the IUT being requested to include certificate chain in the next CAM
//             * }
//             * Expected Behaviour:
//             * 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'
//             *             and containing certificates
//             *                 indicating length > 0
//             *                 and containing certificates[n] (0..N)
//             *                     containing version
//             *                         indicating '2'
//             *   }
//             * }
//             * </pre>
garciay's avatar
garciay committed
//             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_01_02_BV
//             * @reference   ETSI TS 103 097 [1] Clauses 6.1 and 7.4.1
//             */
//            testcase TC_SEC_ITSS_SND_CERT_01_02_BV() runs on ItsGeoNetworking system ItsSecSystem {
//                // Local variables
//                var Ieee1609Dot2Data v_recv;
//                var Certificate v_cert;
//                var SignerInfo v_si;
//                var HashedId8 v_digest;
//                
//                // 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();
//                
//                // Wait for the message with the certificate to retrieve the AA digest.
//                // Ask for the chain, containing AT and AA certificate
//                // Check AA Certificate
//                log("*** " & testcasename() & ": INFO: Wait for certificate and ask for certificate chain  ***");
//                tc_ac.start;
//                f_askForCertificateChain(f_generateDefaultCam());
//                tc_ac.stop;
//                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
//                
//                // Test Body
//                tc_ac.start;
//                alt {
//                    [] geoNetworkingPort.receive(
//                        mw_geoNwInd(
//                            mw_geoNwSecPdu(
//                                mw_securedMessage(
//                                    superset(
//                                        mw_header_info_signer_info_certificate_chain(
//                                            superset(
//                                                mw_aa_certificate
//                    ))))))) {
//                        tc_ac.stop;
//                        log("*** " & testcasename() & ": PASS: AA certificate version set to " & int2char(c_certificate_version) & " ***");
//                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
//                    }
//                    [] geoNetworkingPort.receive(
//                        mw_geoNwInd(
//                            mw_geoNwSecPdu(
//                                mw_securedMessage(
//                                    superset(
//                                        mw_header_info_signer_info_certificate_chain
//                    ))))) {
//                        tc_ac.stop;
//                        log("*** " & testcasename() & ": FAIL: AA certificate version mismatch or no AA cert 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_01_02_BV
//            
//            /**
//             * @desc    Check that the references in the certificate chain are valid
//             *          Check that signer_info type of all certificates in the chain are 'certificate_digest_with_sha256', 
//             *          'certificate_digest_with_other_algorithm' or 'self'
//             * <pre>
//             * Pics Selection: PICS_GN_SECURITY
//             * Config Id: CF01
//             * Initial conditions:
//             * 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'
//             *             and containing certificates
//             *                 indicating length > 0
//             *             and containing certificates[0]
//             *                 containing signer_info
//             *                     containing type
//             *                         indicating 'certificate_digest_with_sha256'
//             *                         or indicating 'certificate_digest_with_other_algorythm'
//             *                     and containing digest
//             *                         referenced to the trusted certificate
//             *                 or containing signer_info
//             *                     containing type
//             *                         indicating 'self'
//             *             and containing certificates[n] (1..N)
//             *                 containing signer_info
//             *                     containing type
//             *                         indicating 'certificate_digest_with_sha256'
//             *                         or indicating 'certificate_digest_with_other_algorythm'
//             *                     and containing digest
//             *                         referenced to the certificates[n-1]
//             * }
//             * </pre>
garciay's avatar
garciay committed
//             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_02_01_BV
//             * @reference   ETSI TS 103 097 [1], clause 4.2.10, 6.1 and 7.4.1
//             */
//            testcase TC_SEC_ITSS_SND_CERT_02_01_BV() runs on ItsGeoNetworking system ItsSecSystem {
//                // Local declarations
//                var SequenceOfCertificate v_chain;
//                var SignerInfo v_si;
//                var HashedId8 v_digest;
//                
//                // 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);
//                
//                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;
//                
//                // Test Body
//                for (var integer v_counter := lengthof(v_chain) - 1; v_counter > 1; v_counter := v_counter - 1) { // Loop on []N-1..1]
//                    if (not f_getCertificateSignerInfo(v_chain[v_counter], v_si)) {
//                        log("*** " & testcasename() & ": FAIL: Certificate[ " & int2str(v_counter) & "] doesn't contain signer info ***");
//                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                    }
//                    if (v_si.type_ != e_certificate_digest_with_sha256) {
//                        if (v_si.type_ != e_certificate_digest_with_other_algorithm or PICS_PLUGTEST_VERSION) {
//                            log("*** " & testcasename() & ": FAIL: Certificate is not signed with digest ***");
//                            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                        }
//                    }
//                    // signer_info.type indicates 'certificate_digest_with_sha256' or 'certificate_digest_with_other_algorythm'
//                    
//                    v_digest := f_calculateDigestFromCertificate(v_chain[v_counter - 1]);
//                    if (not match (v_si.signerInfo.digest, v_digest)) {
//                        log("*** " & testcasename() & ": FAIL: Certificate chain is not valid ***");
//                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                    }
//                } // End of 'for' statement
//                // Process certificate[0]
//                if (not f_getCertificateSignerInfo(v_chain[0], v_si)) {
//                    log("*** " & testcasename() & ": FAIL: Certificate[0] doesn't contain signer info ***");
//                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                }
//                // Process certificate[0]
//                if (v_si.type_ != e_certificate_digest_with_sha256) {
//                    log("*** " & testcasename() & ": FAIL: Certificate[0] is not signed with digest ***");
//                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                }
//                // signer_info.type indicates 'certificate_digest_with_sha256' only
//                log("*** " & testcasename() & ": PASS: Certificate chain is well signed ***");
//                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
//                
//                // Postamble
//                f_poNeighbour();
//                f_cf01Down();
//                
//            } // End of testcase TC_SEC_ITSS_SND_CERT_02_01_BV
//            
//            /**
//             * @desc Check that the rectangular region validity restriction of the message signing certificate 
//             *       contains not more than six valid rectangles; 
//             *       Check that the rectangular region validity restriction of the message signing certificate is 
//             *       continuous and does not contain any holes 
//             * <pre>
//             * Pics Selection: PICS_GN_SECURITY and PICS_CERTIFICATE_SELECTION and PICS_USE_RECTANGULAR_REGION
//             * Config Id: CF01
//             * with {
//             *   the IUT being in the 'authorized' state
//             *   the IUT being requested to include certificate 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
garciay's avatar
garciay committed
//             *                 containing certificate
//             *             containing certificate
//             *                 containing validity_restrictions['region']
//             *                     containing region_type
//             *                         indicating 'rectangle'
//             *                     and containing rectangular_region
//             *                         indicating length <= 6
//             *                         and containing elements of type RectangularRegion
//             *                             indicating continuous region without holes
//             *                             and containing northwest and southeast
//             *                                 indicating northwest is on the north from southeast
//             *   }
//             * }
//             * @remark Certificate: cc_taCert_C
//             * </pre>
garciay's avatar
garciay committed
//             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_04_01_BV
//             * @reference   ETSI TS 103 097 [1] Clauses 4.2.20 and 4.2.23
//             */
//            testcase TC_SEC_ITSS_SND_CERT_04_01_BV() runs on ItsGeoNetworking system ItsSecSystem {
//                // Local variables
//                var Certificate         v_cert;
//                var ValidityRestriction v_vr;
//                var integer             v_counter;
//                
//                // Test control
//                if (not(PICS_GN_SECURITY) or not(PICS_CERTIFICATE_SELECTION) or not(PICS_USE_RECTANGULAR_REGION)) {
//                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY and PICS_CERTIFICATE_SELECTION and PICS_USE_RECTANGULAR_REGION' required for executing the TC ***");
//                    stop;
//                }
//                    
//                // Test component configuration
//                vc_hashedId8ToBeUsed := cc_iutCert_C;
//                f_cf01Up();
//                    
//                // Test adapter configuration
//                    
//                // Preamble
//                f_prNeighbour();
//                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
//                
//                // Test body
//                tc_ac.start;
//                if (not f_waitForCertificate(v_cert)) {
//                    log("*** " & testcasename() & ": INCONC: Expected message not received ***");
//                    f_selfOrClientSyncAndVerdictPreamble(c_tbDone, e_timeout);
//                }
//                tc_ac.stop;
//                if (f_getCertificateValidityRestriction(v_cert, e_region, v_vr)) {
//                    if (v_vr.validity.region.region_type == e_rectangle) {
//                        var RectangularRegions v_rects := v_vr.validity.region.region.rectangular_region;
//                        if (lengthof(v_rects) > 6) {
//                            log("*** " & testcasename() & ": FAIL: Rectangular regions count is greather than 6 ***");
//                            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                        }
//                        for (v_counter := 0; v_counter<lengthof(v_rects); v_counter := v_counter + 1) {
//                            var RectangularRegion v_rect := v_rects[v_counter];
//                            if (true != f_isValidTwoDLocation(v_rect.northwest)) {
//                                log("*** " & testcasename() & ": FAIL: Northwest location is invalid in rect " & int2str(v_counter) & " ***");
//                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                            }
//                            if (true != f_isValidTwoDLocation(v_rect.southeast)) {
//                                log("*** " & testcasename() & ": FAIL: Southeast location is invalid in rect " & int2str(v_counter) & " ***");
//                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                            }
//                            // Check normality of the rectangle
//                            if (v_rect.northwest.latitude < v_rect.southeast.latitude) {
//                                log("*** " & testcasename() & ": FAIL: Rectangular region " & int2str(v_counter) & " is not normalized ***");
//                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                            }
//                        } // End of 'for' statement
//                        
//                        // Check for continuous rectangles
//                        if (lengthof(v_rects) > 1) { 
//                            if (true !=  f_isContinuousRectangularRegions(v_rects)) { // FIXME Not implemented
//                                log("*** " & testcasename() & ": FAIL: Rectangular regions are not connected all together ***");
//                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                            } else {
//                                log("*** " & testcasename() & ": PASS: Certificate has a valid rectangular region restrictions ***");
//                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
//                            }
//                        }
//                    } else {
//                        log("*** " & testcasename() & ": INCONC: Certificate has other region type ***");
//                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout); // to be inconc
//                    }
//                } else {
//                    log("*** " & testcasename() & ": PASS: Certificate doesn't have any location restrictions ***");
//                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
//                }
//                
//                // Postamble
//                f_poNeighbour();
//                f_cf01Down();
//                
//            } // End of testcase TC_SEC_ITSS_SND_CERT_04_01_BV
//            
//            /**
//             * @desc Check that the rectangular region validity restriction of all certificates contains not more than 
//             *       six valid rectangles; 
//             *       Check that the rectangular region validity restriction of the AT certificate is continuous and 
//             *       does not contain any holes 
//             *       Check that the rectangular certificate validity region of the subordinate certificate is well formed and 
//             *       inside the validity region of the issuing certificate 
//             * <pre>
//             * Pics Selection: PICS_GN_SECURITY and PICS_CERTIFICATE_SELECTION and PICS_USE_RECTANGULAR_REGION
//             * 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
//             *                indicating length N > 0
//             *                and containing certificates [n] 0..n
//             *                    containing validity_restrictions['region']
//             *                        containing region_type
//             *                            indicating 'rectangle'
//             *                        and containing rectangular_region
//             *                            indicating length <= 6
//             *                            and containing elements of type RectangularRegion
//             *                                containing northwest and southeast
//             *                                    indicating northwest  on the north from southeast
//             *                                and indicating continuous region without holes
//             *    }
//             * }
//             * </pre>
garciay's avatar
garciay committed
//             * @see         ETSI TS 103 096-2 v1.3.2 TP_SEC_ITSS_SND_CERT_04_02_BV
//             * @reference   ETSI TS 103 097 [1] Clauses 4.2.20 and 4.2.23
//             */
//            testcase TC_SEC_ITSS_SND_CERT_04_02_BV() runs on ItsGeoNetworking system ItsSecSystem {
//                // Local variables
//                var SequenceOfCertificate    v_chain;
//                var ValidityRestriction v_vr := valueof(m_validity_restriction_unknown), v_vri := valueof(m_validity_restriction_unknown);  // current and issuing cert validity restrictions
//                var boolean             f_vr := false, f_vri := false;
//                
//                // Test control
//                if (not(PICS_GN_SECURITY) or not(PICS_CERTIFICATE_SELECTION) or not(PICS_USE_RECTANGULAR_REGION)) {
//                    log("*** " & testcasename() & ":ERROR: 'PICS_GN_SECURITY and PICS_CERTIFICATE_SELECTION and PICS_USE_RECTANGULAR_REGION' required for executing the TC ***");
//                    stop;
//                }
//                    
//                // Test component configuration
//                vc_hashedId8ToBeUsed := cc_iutCert_C;
//                f_cf01Up();
//                    
//                // Test adapter configuration
//                    
//                // Preamble
//                f_prNeighbour();
//                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);
//                } else {
//                    f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
//                }
//                
//                // Test Body
//                tc_ac.stop;
//                for (var integer v_counter := 0; v_counter < lengthof(v_chain); v_counter := v_counter + 1) {
//                    v_vri := v_vr;
//                    f_vri := f_vr;
//                    f_vr := f_getCertificateValidityRestriction(v_chain[v_counter], e_region, v_vr);
//                    log("v_chain[v_counter]=", v_chain[v_counter]);
//                    if (f_vr) {
//                        var RectangularRegions v_rects;
//                        if (v_vr.validity.region.region_type != e_rectangle) {
//                            log("*** " & testcasename() & ": INCONC: Certificate validity restriction region is not rectangular ***");
//                            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                        }
//                        v_rects := v_vr.validity.region.region.rectangular_region;
//                        log("v_rects=", v_rects);
//                        if (lengthof(v_rects) > 6) {
//                            log("*** " & testcasename() & ": FAIL: Rectangular regions count is greather than 6 ***");
//                            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                        }
//                        for (var integer j:=0; j<lengthof(v_rects); j:=j + 1) {
//                            var RectangularRegion v_rect := v_rects[j];
//                            if (true != f_isValidTwoDLocation(v_rect.northwest)) {
//                                log("*** " & testcasename() & ": FAIL: Northwest location is invalid in rect " & int2str(v_counter) & " ***");
//                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                            }
//                            if (true != f_isValidTwoDLocation(v_rect.southeast)) {
//                                log("*** " & testcasename() & ": FAIL: Southeast location is invalid in rect " & int2str(v_counter) & " ***");
//                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                            }
//                            // Check normality of the rectangle
//                            if (v_rect.northwest.latitude < v_rect.southeast.latitude) {
//                                log("*** " & testcasename() & ": FAIL: Rectangle " & int2str(v_counter) & " is not normalized ***");
//                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                            }
//                        }
//                        if (f_vri) {
//                            // current restrictions must be inside of the parent one
//                            if (not f_isRectangularRegionsInside(v_vri.validity.region.region.rectangular_region, v_rects)) {
//                                log("*** " & testcasename() & ": FAIL: Certificate validity restriction region is not inside the issuing one ***");
//                                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                            }
//                        }
//                    } else {
//                        // Region validity restriction is not exist
//                        if (f_vri) {
//                            log("*** " & testcasename() & ": FAIL: Certificate validity restriction region must be set if thi restriction exists in the issuing certificate ***");
//                            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
//                        }
//                    }
//                } // End of 'for' statement
//                // FIXME Check holes
//                log("*** " & testcasename() & ": PASS: All certificates has a valid rectangular region restrictions ***");
//                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);