ItsSecurity_TestCases.ttcn3 456 KB
Newer Older
7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000
             * Config Id: CF01
             * Initial conditions:
             * with {
             *   the IUT being in the 'authorized' state
             * }
             * ensure that {
             *   when {
             *     the IUT is requested to send DENM
             *   } then {
             *     the IUT is receiving a SecuredMessage {
             *          containing header_fields['signer_info'].type
             *              indicating 'certificate'
             *          and containing  header_fields ['signer_info'].certificate (CERT_AT_B)
             *              containing validity_restrictions['region'] {
             *                  containing region{
             *                      containing region_type
             *                          indicating 'circle'
             *                      and containing circular_region
             *                          indicating REGION
             *                  }
             *              }
             *          and containing header_fields ['generation_location']
             *              containing generation_location
             *                  indicating position outside the REGION
             *          and containing header_fields['its_aid']
             *              indicating 'AID_DENM'
             *   }
             * }
             * </pre>
             * @see
             * @reference ETSI TS 103 097 V1.1.14, clause 7.2
             */
            testcase TC_SEC_ITSS_RCV_DENM_08_01a_EB() runs on ItsGeoNetworking system ItsSecSystem {
                
                // Local variables
                var integer i;
                var GeoNetworkingPdu v_securedGnPdu;
                
                //  Test component configuration
                f_cf01Up();
                
                // Preamble
                f_prNeighbour();
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                
                // Test Body
                v_securedGnPdu := f_sendSecuredDenm(cc_taCertB, omit, e_certificate);
                
                f_sleep(PX_TNOAC);
                if (lengthof(vc_utInds) == 0) {
                    log("*** " & testcasename() & ": PASS: DENM was dropped by the IUT ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                }
                else {
                    log("*** " & testcasename() & ": FAIL: DENM was transmitted to upper layer ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                }
                
                // Postamble
                f_poNeighbour();
                f_cf01Down();
            } // End of testcase TC_SEC_ITSS_RCV_DENM_08_01a_EB
            
            /**
             * @desc    Check that IUT discards Secured DENM if the HeaderField generation_location is outside of the rectangilar validity region of the signing certificate
             * <pre>
             * Pics Selection: none
             * Config Id: CF01
             * Initial conditions:
             * with {
             *   the IUT being in the 'authorized' state
             * }
             * ensure that {
             *   when {
             *     the IUT is requested to send DENM
             *   } then {
             *     the IUT is receiving a SecuredMessage {
             *          containing header_fields['signer_info'].type
             *              indicating 'certificate'
             *          and containing  header_fields ['signer_info'].certificate (CERT_AT_C)
             *              containing validity_restrictions['region'] {
             *                  containing region{
             *                      containing region_type
             *                          indicating 'rectangle'
             *                      and containing rectangular_regions
             *                          indicating REGION
             *                  }
             *              }
             *          and containing header_fields ['generation_location']
             *              containing generation_location
             *                  indicating position outside the REGION
             *          and containing header_fields['its_aid']
             *              indicating 'AID_DENM'
             *   }
             * }
             * </pre>
             * @see
             * @reference ETSI TS 103 097 V1.1.14, clause 7.2
             */
            testcase TC_SEC_ITSS_RCV_DENM_08_01b_EB() runs on ItsGeoNetworking system ItsSecSystem {
                
                // Local variables
                var integer i;
                var GeoNetworkingPdu v_securedGnPdu;
                
                //  Test component configuration
                f_cf01Up();
                
                // Preamble
                f_prNeighbour();
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                
                // Test Body
                v_securedGnPdu := f_sendSecuredDenm(cc_taCertC, omit, e_certificate);
                
                f_sleep(PX_TNOAC);
                if (lengthof(vc_utInds) == 0) {
                    log("*** " & testcasename() & ": PASS: DENM was dropped by the IUT ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                }
                else {
                    log("*** " & testcasename() & ": FAIL: DENM was transmitted to upper layer ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                }
                
                // Postamble
                f_poNeighbour();
                f_cf01Down();
            } // End of testcase TC_SEC_ITSS_RCV_DENM_08_01b_EB
            
            /**
             * @desc    Check that IUT discards Secured DENM if the HeaderField generation_location is outside of the polygonal validity region of the signing certificate    
             * <pre>
             * Pics Selection: none
             * Config Id: CF01
             * Initial conditions:
             * with {
             *   the IUT being in the 'authorized' state
             * }
             * ensure that {
             *   when {
             *     the IUT is requested to send DENM
             *   } then {
             *     the IUT is receiving a SecuredMessage {
             *          containing header_fields['signer_info'].type
             *              indicating 'certificate'
             *          and containing  header_fields ['signer_info'].certificate (CERT_AT_D)
             *              containing validity_restrictions['region'] {
             *                  containing region{
             *                      containing region_type
             *                          indicating 'polygon'
             *                      and containing polygonal_region
             *                          indicating REGION
             *                  }
             *              }
             *          and containing header_fields ['generation_location']
             *              containing generation_location
             *                  indicating position outside the REGION
             *          and containing header_fields['its_aid']
             *              indicating 'AID_DENM'
             *   }
             * }
             * </pre>
             * @see
             * @reference ETSI TS 103 097 V1.1.14, clause 7.2
             */
            testcase TC_SEC_ITSS_RCV_DENM_08_01c_EB() runs on ItsGeoNetworking system ItsSecSystem {
                
                // Local variables
                var integer i;
                var GeoNetworkingPdu v_securedGnPdu;
                
                //  Test component configuration
                f_cf01Up();
                
                // Preamble
                f_prNeighbour();
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                
                // Test Body
                v_securedGnPdu := f_sendSecuredDenm(cc_taCertD, omit, e_certificate);
                
                f_sleep(PX_TNOAC);
                if (lengthof(vc_utInds) == 0) {
                    log("*** " & testcasename() & ": PASS: DENM was dropped by the IUT ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                }
                else {
                    log("*** " & testcasename() & ": FAIL: DENM was transmitted to upper layer ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                }
                
                // Postamble
                f_poNeighbour();
                f_cf01Down();
            } // End of testcase TC_SEC_ITSS_RCV_DENM_08_01c_EB
            
            /**
             * @desc    Check that IUT discards Secured DENM if the HeaderField generation_location is outside of the identified validity region of the signing certificate 
             * <pre>
             * Pics Selection: none
             * Config Id: CF01
             * Initial conditions:
             * with {
             *   the IUT being in the 'authorized' state
             * }
             * ensure that {
             *   when {
             *     the IUT is requested to send DENM
             *   } then {
             *     the IUT is receiving a SecuredMessage {
             *          containing header_fields['signer_info'].type
             *              indicating 'certificate'
             *          and containing  header_fields ['signer_info'].certificate (CERT_AT_E)
             *              containing validity_restrictions['region'] {
             *                  containing region{
             *                      containing region_type
             *                          indicating 'id_region'
             *                      and containing identified_region
             *                          indicating REGION
             *                  }
             *              }
             *          and containing header_fields ['generation_location']
             *              containing generation_location
             *                  indicating position outside the REGION
             *          and containing header_fields['its_aid']
             *              indicating 'AID_DENM'
             *   }
             * }
             * </pre>
             * @see
             * @reference ETSI TS 103 097 V1.1.14, clause 7.2
             */
            testcase TC_SEC_ITSS_RCV_DENM_08_01d_EB() runs on ItsGeoNetworking system ItsSecSystem {
                
                // Local variables
                var integer i;
                var GeoNetworkingPdu v_securedGnPdu;
                
                //  Test component configuration
                f_cf01Up();
                
                // Preamble
                f_prNeighbour();
                f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
                
                // Test Body
                v_securedGnPdu := f_sendSecuredDenm(cc_taCertE, omit, e_certificate);
                
                f_sleep(PX_TNOAC);
                if (lengthof(vc_utInds) == 0) {
                    log("*** " & testcasename() & ": PASS: DENM was dropped by the IUT ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                }
                else {
                    log("*** " & testcasename() & ": FAIL: DENM was transmitted to upper layer ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                }
                
                // Postamble
                f_poNeighbour();
                f_cf01Down();
            } // End of testcase TC_SEC_ITSS_RCV_DENM_08_01d_EB
            
        } // End of group g_recvDenmProfile
        
    } // End of group g_receiverbehavior
    
    group g_Certificates {
        
        /**
         * @desc    Check that AT certificate has version 2
         * <pre>
         * Pics Selection: none
         * Config Id: CF01
         * Initial conditions:
         * with {
         *   the IUT being in the 'authorized' state
         *   the IUT being requested to include certificate in the next CAM
         * }
         * Expected Behaviour:
         * ensure that {
         *    when {
         *     the IUT is requested to send a CAM
         *   } then {
         *     the IUT sends a SecuredMessage
         *       containing header_fields['signer_info'].signer {
         *         containing type
         *           indicating certificate
         *         containing certificate {
         *           containing version
         *             indicating '2'
         *         }
         *       }
         *   }
         * }
         * </pre>
         * @reference ETSI TS 103 097 V1.1.14, clause 6.1
         */
        testcase TC_SEC_SND_CERT_01_01() runs on ItsGeoNetworking system ItsSecSystem {
            
            // Test component configuration
            f_cf01Up();
            
            // Preamble
            f_prNeighbour();
            f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
            
            // Test Body
            tc_ac.start;
            alt {
                [] geoNetworkingPort.receive(
                    mw_geoNwInd(
                        mw_geoNwSecPdu(
                            mdw_securedMessage(
                                superset(
                                    mw_header_field_signer_info_certificate(
                                        mw_certificate(
                ))))))) {
                    tc_ac.stop;
                    log("*** " & testcasename() & ": PASS: AT Certificate version set to " & int2char(c_certificate_version) & " ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                }
                [] geoNetworkingPort.receive(
                    mw_geoNwInd(
                        mw_geoNwSecPdu(
                            mdw_securedMessage(
                                superset(
                                    mw_header_field_signer_info_certificate(
                                        ?
                )))))) {
                    tc_ac.stop;
                    log("*** " & testcasename() & ": FAIL: AT Certificate version mismatch ***");
                    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_SND_CERT_01_01
        
        /**
         * @desc    Check that AA certificate has version 2
         * <pre>
         * Pics Selection: none
         * 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 SecuredMessage
         *       containing header_fields['signer_info'].signer {
         *         containing type
         *           indicating certificate_chain
         *         containing certificates.length >1
         *         containing certificates[last-1] {
         *           containing version
         *             indicating '2'
         *         }
         *       }
         *   }
         * }
         * </pre>
         * @reference ETSI TS 103 097 V1.1.14, clause 6.1
         */
        testcase TC_SEC_SND_CERT_01_02() runs on ItsGeoNetworking system ItsSecSystem {
            // Local declarations
            var SecuredMessage v_recv;
            var Certificate v_cert;
            var SignerInfo v_si;
            var HashedId8 v_digest;
            
            // Test component configuration
            f_cf01Up();
            
            // Preamble
            f_prNeighbour();
            f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
            
            // 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;
            
            // Test Body
            tc_ac.start;
            alt {
                [] geoNetworkingPort.receive(
                    mw_geoNwInd(
                        mw_geoNwSecPdu(
                            mdw_securedMessage(
                                superset(
                                    mw_header_field_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(
                            mdw_securedMessage(
                                superset(
                                    mw_header_field_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_SND_CERT_01_02
        
        /**
         * @desc    Check that the certificate chain is valid: Check signer_info 
         * <pre>
         * Pics Selection: none
         * 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 SecuredMessage
         *       containing header_fields['signer_info'].signer {
         *         containing type
         *           indicating certificate_chain
         *         containing certificates[N] {
         *           containing signer_info {
         *             containing type
         *               indicating 'certificate_digest_with_sha256'
         *             containing digest
         *               referenced to the certificates[N-1]
         *           }
         *         }
         *       }
         *   }
         * }
         * </pre>
         * @reference ETSI TS 103 097 V1.1.14, clause 6.1
         */
        testcase TC_SEC_SND_CERT_02_01() runs on ItsGeoNetworking system ItsSecSystem {
            // TODO: This TC is fully covered by TC_SEC_SND_CERT_09_02 
            // Local declarations
            var CertificateChain v_chain;
            var SignerInfo v_si;
            var HashedId8 v_digest;
            
            // Test component configuration
            f_cf01Up();
            
            // 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 > 0; v_counter := v_counter - 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 (not match (v_si.type_, e_certificate_digest_with_sha256)) {
                    log("*** " & testcasename() & ": FAIL: Certificate is not signed with digest ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                }
                
                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
            log("*** " & testcasename() & ": PASS: Certificate chain is well signed ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
            
            // Postamble
            f_poNeighbour();
            f_cf01Down();
            
        } // End of testcase TC_SEC_SND_CERT_02_01
        
        /**
         * @desc Check that the length of the vector of rectangles is less then 6.
         *       Check that region is continuous and does not contain any holes.
         *       Check that the rectangles are valid  
         * <pre>
         * Pics Selection: PIC_UseRectangularRegion
         * 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 SecuredMessage
         *       containing header_fields['signer_info'].signer {
         *         containing type
         *           indicating 'certificate'
         *         containing certificate {
         *           containing no validity restriction or validity_restrictions['region']{
         *             containing region_type
         *               indicating 'rectangle'
         *             containing rectangular_region {
         *               indicating length <= 6
         *               containing elements of type RectangularRegion
         *                 indicating continuous region without holes
         *                 containing northwest and southeast
         *                   indicating northwest is on the north from southeast
         *             }
         *           }
         *         }
         *       }
         *   }
         * }
         * </pre>
         * @reference ETSI TS 103 097 V1.1.14, clauses 4.2.21, 4.2.24
         */
        testcase TC_SEC_SND_CERT_04_01() runs on ItsGeoNetworking system ItsSecSystem {
            // Local declarations
            var Certificate         v_cert;
            var ValidityRestriction v_vr;
            var integer             v_counter;
            
            // Test component configuration
            f_cf01Up();
            
            // Preamble
            f_prNeighbour();
            f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
            
            // Test body
            tc_ac.start;
            f_waitForCertificate(v_cert);
            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 more then 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)) {
                            log("*** " & testcasename() & ": FAIL: Rectangular regions are not connected all together ***");
                            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                        }
                    }
                } else {
                    log("*** " & testcasename() & ": INCONC: Certificate has other region type ***");
                    f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout); // to be inconc
                }
                
                log("*** " & testcasename() & ": PASS: Certificate has a valid rectangular region restrictions ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
            } 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_SND_CERT_04_01
        
        /**
         * @desc Check that the rectangular region of the subordinate certificate is well formed 
         *       and inside the validity restrictions of the issuing certificate.  
         * <pre>
         * Pics Selection: PIC_UseRectangularRegion
         * 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 SecuredMessage
         *       containing header_fields['signer_info'].signer {
         *          containing type
         *            indicating 'certificate_chain'
         *         containing certificates
         *           indicating CERTIFICATES {
         *                containing CERTIFICATES[N] {
         *               containing validity_restrictions['region'] {
         *                 containing region_type
         *                   indicating 'rectangle'
         *                 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
         *                     which is inside the CERTIFICATES[N-1].validity_restrictions['region'] if region validity restriction is containted in certificate CERTIFICATES[N-1]
         *                    }
         *                  }
         *             }
         *           }
         *       }
         *       }
         * }
         * </pre>
         * @reference ETSI TS 103 097 V1.1.14, clauses 4.2.21, 4.2.24
         */
        testcase TC_SEC_SND_CERT_04_02() runs on ItsGeoNetworking system ItsSecSystem {
            // Local declarations
            var CertificateChain    v_chain;
            var ValidityRestriction v_vr, v_vri;  // current and issuing cert validity restrictions
            var boolean f_vr, f_vri;
            
            
            // Test component configuration
            f_cf01Up();
            
            // 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
            f_vr := false;
            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);
                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;
                    if (lengthof(v_rects) > 6) {
                        log("*** " & testcasename() & ": FAIL: Rectangular regions count is more then 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
                   
            log("*** " & testcasename() & ": PASS: All certificates has a valid rectangular region restrictions ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
            
            // Postamble
            f_poNeighbour();
            f_cf01Down();
            
        } // End of testcase TC_SEC_SND_CERT_04_02
        
        /**
         * @desc Check Polygonal Region:
         * Must contain at least 3 and no more then 12 points
         * Intersections and holes are not permited
         * <pre>
         * Pics Selection: PIC_UsePolygonalRegion
         * 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 SecuredMessage
         *       containing header_fields['signer_info'].signer {
         *         containing type
         *           indicating 'certificate'
         *         containing certificate {
         *           containing validity_restrictions['region']{
         *             containing region_type
         *               indicating 'polygon'
         *             containing polygonal_region {
         *               indicating length >=3 and <=12
         *               indicating continuous region without holes and intersections
         *             }
         *           }
         *         }
         *       }
         *   }
         * }
         * </pre>
         * @reference ETSI TS 103 097 V1.1.14, clauses 4.2.25
         */
        testcase TC_SEC_SND_CERT_05_01() runs on ItsGeoNetworking system ItsSecSystem {
            var Certificate         v_cert;
            var ValidityRestriction v_vr;
            var integer             v_counter;
            
            // Test component configuration
            f_cf01Up();
            
            // Preamble
            f_prNeighbour();
            f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
            
            // Test body
            tc_ac.start;
            f_waitForCertificate(v_cert);
            tc_ac.stop;
            if (f_getCertificateValidityRestriction(v_cert, e_region, v_vr)) { 
                if (v_vr.validity.region.region_type == e_polygon) {
                    var PolygonalRegion v_pr := v_vr.validity.region.region.polygonal_region;
                    var integer v_length := lengthof(v_pr);
                    if (v_length < 3) {
                        log("*** " & testcasename() & ": FAIL: Count of points in polygonal region is too small ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                    if (v_length > 12) {
                        log("*** " & testcasename() & ": FAIL: Count of points in polygonal region is too big ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                    if (true != f_isValidPolygonalRegion(v_pr)) {
                        log("*** " & testcasename() & ": FAIL: Polygonal region is not valid (self-intersected) ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                    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_SND_CERT_05_01

        /**
         * @desc Check Polygonal Region:
         * Must contain at least 3 and no more then 12 points.
         * Intersections and holes are not permited.
         * The region must be inside the issuing certificate restrictions.  
         * <pre>
         * Pics Selection: PIC_UsePolygonalRegion
         * 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 SecuredMessage
         *       containing header_fields['signer_info'].signer {
         *         containing type
         *           indicating 'certificate_chain'
         *         containing certificates
         *           indicating CERTIFICATES {
         *             containing CERTIFICATES[N] {
         *               containing validity_restrictions['region'] {
         *                 containing region_type
         *                   indicating 'polygon'
         *                 containing polygonal_region {
         *                   indicating length >=3 and <=12
         *                   indicating continuous region without holes and intersections
         *                     which is inside the CERTIFICATES[N-1].validity_restrictions['region'].polygonal_region 
         *                       if region validity restriction is containted in certificate CERTIFICATES[N-1]
         *                 }
         *               }
         *             }
         *           }
         *       }
         *   }
         * }
         * </pre>
         * @reference ETSI TS 103 097 V1.1.14, clauses 4.2.25
         */
        testcase TC_SEC_SND_CERT_05_02() runs on ItsGeoNetworking system ItsSecSystem {
            // Local declarations
            var CertificateChain    v_chain;
            var ValidityRestriction v_vr, v_vri;  // current and issuing cert validity restrictions
            var boolean f_vr, f_vri;
            
            // Test component configuration
            f_cf01Up();
            
            // 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;
            f_vr := false;
            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);
                if (f_vr) {
                    var PolygonalRegion v_pr;
                    var integer v_length;
                    
                    if (v_vr.validity.region.region_type != e_polygon) {
                        log("*** " & testcasename() & ": INCONC: Certificate validity restriction region is not polygonal ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                    
                    v_pr := v_vr.validity.region.region.polygonal_region;
                    v_length := lengthof(v_pr);
                    
                    if (v_length < 3) {
                        log("*** " & testcasename() & ": FAIL: Count of points in polygonal region is too small in cert " & int2str(v_counter) & " ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                    
                    if (v_length > 12) {
                        log("*** " & testcasename() & ": FAIL: Count of points in polygonal region is too big  in cert " & int2str(v_counter) & "***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                    
                    if (true != f_isValidPolygonalRegion(v_pr)) {
                        log("*** " & testcasename() & ": FAIL: Polygonal region is not valid (self-intersected) in cert " & int2str(v_counter) & " ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                    
                    if (f_vri) {
                        // current restrictions must be inside of the parent one
                        if (true != f_isPolygonalRegionInside(v_vri.validity.region.region.polygonal_region, v_pr)) {
                            log("*** " & testcasename() & ": FAIL: Certificate validity restriction region in cert " & int2str(v_counter) & " 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 in the certificate "  & int2str(v_counter) &
                                                              "because this restriction exists in the issuing certificate ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                }
            } // End of 'for' statement
            
            log("*** " & testcasename() & ": PASS: All certificates has a valid polygonal region restrictions ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
            
            // Postamble
            f_poNeighbour();
            f_cf01Down();
            
        } // End of testcase TC_SEC_SND_CERT_05_02

        /**
         * @desc Check Identified Region:
         * Must contain value that correspond to numeric country codes as defined in ISO 3166-1 
         * <pre>
         * Pics Selection: PIC_UseIdentifiedRegion, PIC_UseISO31661RegionDictionary
         * 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 SecuredMessage
         *       containing header_fields['signer_info'].signer {
         *         containing type
         *           indicating 'certificate'
         *         containing certificate {
         *           containing validity_restrictions['region']{
         *             containing region_type
         *               indicating 'id'
         *             containing id_region {
         *               containing region_dictionary
         *                 indicating 'iso_3166_1' (0)
         *               containing region_identifier
         *                 indicating valid value according to 'iso_3166_1'
         *               containing local_region
         *             }
         *           }
         *         }
         *       }
         *   }
         * }
         * </pre>
         * @reference ETSI TS 103 097 V1.1.14, clauses 4.2.27
         */
        testcase TC_SEC_SND_CERT_06_01() runs on ItsGeoNetworking system ItsSecSystem {
            var Certificate         v_cert;
            var ValidityRestriction v_vr;
            var integer             v_counter;
            
            // Test component configuration
            f_cf01Up();
            
            // Preamble
            f_prNeighbour();
            f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
            
            // Test body
            tc_ac.start;
            f_waitForCertificate(v_cert);
            tc_ac.stop;
            if (f_getCertificateValidityRestriction(v_cert, e_region, v_vr)) {
                if (v_vr.validity.region.region_type == e_id) {
                    if (not match (v_vr.validity.region, mw_geographicRegion_identified(mw_identifiedRegion_iso3166_any))) {
                        log("*** " & testcasename() & ": FAIL: Identified region is not conformed to ISO 3166-1 ***");
                        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                    }
                }