Commit 2dc193a6 authored by filatov's avatar filatov
Browse files

helper functions, fix some templates, add receiving templates

parent 88af06b0
Loading
Loading
Loading
Loading
+70 −90
Original line number Diff line number Diff line
@@ -7,97 +7,24 @@
 */
module LibItsSecurity_Functions {
    
    // LibCommon
    
    // LibItsSecurity
    
//    group configurationFunctions {
//        
//       /**
//        * @desc 
//        */
//        function f_cf01Up() runs on ItsGnSecurity {
//            
//            // Map
//            map(self:acPort, system:acPort);
//            map(self:utPort, system:utPort);
//            map(self:gnSecurityPort, system:gnSecurityPort);
//            
//            // Connect
//            f_connect4SelfOrClientSync();
//            activate(a_cf01Down());
//            
//            // Initialze the IUT/DUT
//            f_initialState();
//            
//        } // End of function f_cf01Up
//        
//        function f_cf01Down() runs on ItsGnSecurity {
//            
//            // Unmap
//            unmap(self:acPort, system:acPort);
//            unmap(self:utPort, system:utPort);
//            unmap(self:gnSecurityPort, system:gnSecurityPort);
//            
//            // Disconnect
//            f_disconnect4SelfOrClientSync();
//        } // End of function f_cf01Down
//        
//    } // End of group configurationFunctions
//    
//    group preambles {
//        
//        /**
//         * @desc Brings the IUT into an initial state.
//         */
//        function f_initialState() runs on ItsBaseGnSecurity {
//            // TODO
//        }
//        
//    } // End of group preambles
//    
//    group postambles {
//        
//    } // End of group postambles
//    
//    group securityAltsteps {
//        
//        /**
//         * @desc The base default behavior.
//         */
//        altstep a_default() runs on ItsGnSecurity {
//            [] gnSecurityPort.receive(mw_gnSecurityInd(?)) {
//                log("*** a_default: WARNING: Received an unexpected message ***");
//                repeat;
//            }
//            [] gnSecurityPort.receive {
//                log("*** a_default: WARNING: Received an unexpected message ***");
//                repeat;
//            }
//            [] tc_wait.timeout {
//                log("*** a_default: ERROR: Timeout while awaiting reaction of the IUT prior to Upper Tester action ***");
//                f_selfOrClientSyncAndVerdict("error", e_timeout);
//            }
//            [] tc_ac.timeout {
//                log("*** a_default: ERROR: Timeout while awaiting the reception of a message ***");
//                f_selfOrClientSyncAndVerdict("error", e_timeout);
//            }
//            [] a_shutdown() {
//                log("*** a_default: INFO: TEST COMPONENT NOW STOPPING ITSELF! ***");
//                stop;
//            }
//        } // End of 'altstep' statement
//        
//        altstep a_cf01Down() runs on ItsGnSecurity {
//            [] a_shutdown() {
//                f_cf01Down();
//                log("*** a_cf01Down: INFO: TEST COMPONENT NOW STOPPING ITSELF! ***");
//                stop;
//            }
//        } // End of 'altstep' statement
//        
//    } // End of group securityAltsteps
//    
    // Libcommon
    
//    import from LibCommon_BasicTypesAndValues all;
//    import from LibCommon_DataStrings all;
//    import from LibCommon_VerdictControl {type FncRetCode;}
//    import from LibCommon_Sync all;
//    import from LibCommon_Time all;

    // LibIts
//    import from LibItsCommon_Functions all;
//    import from LibItsCommon_TestSystem all;
//    import from LibItsCommon_TypesAndValues all;
    import from LibItsGeoNetworking_TypesAndValues all;
    import from LibItsSecurity_TypesAndValues all;
//    import from LibItsGeoNetworking_TestSystem all;
//    import from LibItsGeoNetworking_Templates all;
//    import from LibItsGeoNetworking_Functions all;
    
    group helpersFunctions {
        
        /**
@@ -136,6 +63,59 @@ module LibItsSecurity_Functions {
            return false;
        }
        
        /**
         * @desc    Calculate digest over the certificate
         * @param   cert The certificate
         * @return  the digest
         */
        function f_calculateDigest(in Certificate cert) return HashedId8 {
            return 0;
        }
        
        group gettersAndSetters {
    
            /**
             * @desc    return SecuredMessage field of GeoNetworking packet 
             * @param   p_msg GeoNetworking packet
             * @return  the SecuredMessage if any
             */
            function f_getSecuredMessage(in GeoNetworkingPdu p_msg)
            return SecuredMessage {
                return p_msg.gnPacket.securedMsg;
            }
            
            /**
             * @desc    return SecuredMessage header field of given tipe or null if none 
             * @param   p_msg the SecuredMessage
             * @param   p_type header field type
             * @return  HeaderField of given type if any or null
             */
            function f_getMsgHeaderField(in SecuredMessage p_msg, in HeaderFieldType p_type)
            return HeaderField {
                var HeaderField v_return := null;
                var integer l := lengthof(p_msg.header_fields);
                var integer i;
                for(i:=0; i<l; i:=i+1){
                    if(p_msg.header_fields[i].type_ == p_type){
                        v_return := p_msg.header_fields[i]; 
                        break;
                    }
                }
                return v_return;
            }
            
            /**
             * @desc    return SignerInfo SecuredMessage field
             */
            function f_getMsgSignerInfo(in SecuredMessage p_msg) return SignerInfo {
                var HeaderField v_hf := f_getMsgHeaderField(p_msg, e_signer_info);
                if(v_hf != null){
                    return v_hf.headerField.signer;
                }
                return null;
            }
        }// End of group gettersAndSetters
    
    } // End of group helpersFunctions

    group externalFunctions {
+31 −0
Original line number Diff line number Diff line
module LibItsSecurity_GNTemplates {
    // LibCommon
    import from LibCommon_BasicTypesAndValues {
        type UInt8, UInt16, UInt32, 
             Int32 
    }
    import from LibCommon_DataStrings {
        type Oct2, Oct20
    }
    import from LibItsSecurity_TypesAndValues all;
    import from LibItsSecurity_Pixits all;
    import from LibItsGeoNetworking_TypesAndValues all;
    import from LibItsGeoNetworking_Templates {
        group geoNwHeadersTemplates, geoNwPduTemplates
    }

    /**
     * @desc    Receive template for GeoNetworking PDU with
     * @param   p_packet    GnNonSecuredPacket of GeoNetworking message
     * @param   p_lifeTime  Lifetime of GeoNetworking message (Default: ?)
     * @param   p_hopLimit  Router Hop limit of GeoNetworking message (Default: ?)
     */
    template (present) GeoNetworkingPdu mw_geoNwSecPdu(
        in template (present) SecuredMessage p_msg
    ) := {
        basicHeader := mw_basicHeader(),
        gnPacket := {
            securedMsg := p_msg
        }
    }
}
 No newline at end of file
+52 −22
Original line number Diff line number Diff line
@@ -1181,30 +1181,51 @@ module LibItsSecurity_Templates {
                } // End of template mw_header_field_multiple_digests
                
                /**
                 * @desc Receive template for HeaderField with generation location information
                 * @desc Receive template for HeaderField with signer information
                 * @see Draft ETSI TS 103 097 V1.1.6 Clause 5.4    HeaderField
                 */
                template (present) HeaderField mw_header_field_message_type(
                                                                            in template (present) UInt16 p_message_type
                template (present) HeaderField mw_header_field_signer_info(
                                                                           in template (present) SignerInfo p_signer
                ) := {
                    type_       := e_message_type,
                    type_       := e_signer_info,
                    headerField := {
                        message_type := p_message_type
                        signer := p_signer
                    }
                } // End of template mw_header_field_message_type
                } // End of template mw_header_field_signerInfo_signer_info
                
                /**
                 * @desc Receive template for HeaderField with signer information
                 *       containing certificate
                 * @see Draft ETSI TS 103 097 V1.1.6 Clause 5.4    HeaderField
                 */
                template (present) HeaderField mw_header_field_signer_info(
                                                                           in template (present) SignerInfo p_signer
                ) := {
                template (present) HeaderField mw_header_field_signer_info_certificate := {
                    type_       := e_signer_info,
                    headerField := {
                        signer := p_signer
                        signer := {
                            type_ := e_certificate,
                            signerInfo := {
                                certificate := ?
                            }
                } // End of template mw_header_field_signerInfo_signer_info
                        }
                    }
                } // End of template mw_header_field_signer_info_certificate

                /**
                 * @desc Receive template for HeaderField with signer information
                 *       containing certificate digest
                 * @see Draft ETSI TS 103 097 V1.1.6 Clause 5.4    HeaderField
                 */
                template (present) HeaderField mw_header_field_signer_info_digest := {
                    type_       := e_signer_info,
                    headerField := {
                        signer := {
                            type_ := e_certificate_digest_with_ecdsap256,
                            signerInfo := {
                                digest := ?
                            }
                        }
                    }
                } // End of template mw_header_field_signer_info_digest

                /**
                 * @desc Receive template for HeaderField with signer information
@@ -1593,11 +1614,21 @@ module LibItsSecurity_Templates {
         * @see Draft ETSI TS 103 097 V1.1.6 Clause 6   Specification of certificate format
         */
        group certificatesRecv {
            template (present) Certificate mw_certificate(
                                                          in template (present) SignerInfo p_signer_info,
                                                          in template (present) SubjectInfo p_subject_info,
                                                          in template (present) SubjectAttributes p_subject_attributes,
                                                          in template (present) ValidityRestrictions p_validity_restrictions,
                                                          in template (present) Signature p_signature
            ) := {
                version                 := c_certificate_version,
                signer_infos            := { p_signer_info },
                subject_info            := p_subject_info,
                subject_attributes      := p_subject_attributes,
                validity_restrictions   := p_validity_restrictions,
                signature_              := p_signature
            } // End of template m_certificate
            
            /**
             * @desc Receive templates for certificates
             * @see Draft ETSI TS 103 097 V1.1.6 Clause 6.2 SubjectInfo
             */
            group subjectInfo {
                
                template (present) SubjectInfo mw_subject_info_root_ca(
@@ -1738,12 +1769,12 @@ module LibItsSecurity_Templates {
                 */
                template (value) SecuredMessage md_secureMessageCAMs(
                                                                     in template (value) HeaderFields p_header_fields,
                                                                     in template (value) Payload p_payload_fields,
                                                                     in template (value) Payload p_payload_field,
                                                                     in template (value) TrailerFields p_trailer_fields
                ) modifies m_secureMessageCAMs_dummy := {
                    security_profile    := c_security_profileCAMs,
                    header_fields       := p_header_fields,
                    payload_fields      := { p_payload_fields },
                    payload_fields      := { p_payload_field },
                    trailer_fields      := p_trailer_fields
                } // End of template md_secureMessageCAMs
                
@@ -1771,7 +1802,7 @@ module LibItsSecurity_Templates {
                template (present) SecuredMessage mdw_secureMessageCAMs_dummy
                modifies mw_securedMessage_dummy := {
                    security_profile    := c_security_profileCAMs
                } // End of template mw_securedMessage_dummy
                } // End of template mdw_secureMessageCAMs_dummy
                
                /**
                 * @desc Generic received template for Security profile for CAMs
@@ -1781,9 +1812,8 @@ module LibItsSecurity_Templates {
                    header_fields       := ?,
                    payload_fields      := ?,
                    trailer_fields      := ?
                } // End of template mw_securedMessage_dummy
                
            } // End of group mdw_secureMessageCAMs_dummy
                } // End of template mdw_secureMessageCAMs
            } // End of group securityProfilesCAMsRecv
            
        } // End of group securityProfilesCAMs
        
+1 −1
Original line number Diff line number Diff line
@@ -591,7 +591,7 @@ module LibItsSecurity_TypesAndValues {
        /**
         * @desc Certificate description
         * @member version                  The certificate's version. Shall be set to 2
         * @member signer_info              The certificate's signer 
         * @member signer_infos             The certificate's signers 
         * @member subject_info             Information on the certificate's subject
         * @member subject_attributes       The certificate's subject
         * @member validity_restrictions    Restrictions regarding the certificate's validity