Commit 077f7a79 authored by garciay's avatar garciay
Browse files

STF507 week#11: Add testing functions to validate ITS Security ATS against itself

parent 62485491
Loading
Loading
Loading
Loading
+83 −8
Original line number Diff line number Diff line
@@ -2553,8 +2553,9 @@ module LibItsGeoNetworking_Functions {
         * @desc  Wait for GN message with security containing digest as a signer info
         * @return the digest of the certificate been used to sign received message
         */
        function f_waitForDigest(out HashedId8 p_digest)
        runs on ItsGeoNetworking return boolean {
        function f_waitForDigest(
                                 out HashedId8 p_digest
        ) runs on ItsGeoNetworking return boolean {
            // Local variables
            var SecuredMessage v_recv;
            var boolean v_ret := false;
@@ -2572,6 +2573,37 @@ module LibItsGeoNetworking_Functions {
            return v_ret;
        } // End of function f_waitForDigest
        
        /**
         * @desc Send a CAM message with a certificate and wait the certificate chain request message
         * @remark  This function is used only for testing against another ATS
         * @param p_certificate The certificate identifier
         * @param p_CamPayload  The CAM paylaod
         * @return true on success, flase otherwise
         */
        function f_sendCertificateAndWaitForCertificateChainRequest(
                                                                    in charstring p_certificate, 
                                                                    in template(value) octetstring p_CamPayload
        ) runs on ItsGeoNetworking return boolean {
            // Local variables
            var SecuredMessage v_recv;
            
            f_sendCertificate(p_certificate, p_CamPayload);
            alt {
                [] a_securedMessage (
                    mdw_securedMessage(
                        superset(
                            mw_header_field_unrecognised_certificate
                    )),
                    v_recv
                ) {
                    // Nothing to do
                    log("*** " & testcasename() & ": DEBUG: Receive certificate ***")
                }
            } // End of 'alt' statement
            
            return true;
        } // End of function f_sendCertificateAndWaitForCertificateChainRequest
        
    } // End of group waitingHelpers
        
    group CertRequests{
@@ -2579,9 +2611,7 @@ module LibItsGeoNetworking_Functions {
        function f_sendCertificateRequest(
                                          in template (value) HashedId8 p_digest,
                                          in template (value) octetstring p_payload
        )
        runs on ItsGeoNetworking
        {
        ) runs on ItsGeoNetworking {
            var GeoNetworkingReq v_gnReq;
            var GnNonSecuredPacket v_gnNonSecuredPacket;
            var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessage;
@@ -2619,6 +2649,51 @@ module LibItsGeoNetworking_Functions {
            
        } // End of function f_sendCertificateRequest
        
        /**
         * @desc Send a CAM message with a certificate
         * @remark  This function is used only for testing against another ATS
         * @param p_certificate The certificate identifier
         * @param p_CamPayload  The CAM paylaod
         * @return true on success, flase otherwise
         * @see     f_sendCertificateAndWaitForCertificateChainRequest
         */
        function f_sendCertificate(
                                   in charstring p_certificate,
                                   in template (value) octetstring p_payload
        ) runs on ItsGeoNetworking {
            var GeoNetworkingReq v_gnReq;
            var GnNonSecuredPacket v_gnNonSecuredPacket;
            var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessage;
            var template (value) SecuredMessage v_securedMessage;
                
            // Build signed SecuredMessage
            v_gnNonSecuredPacket := valueof(m_geoNwShbPacket(
                f_getPosition(c_compNodeC) // FIXME To be verified YANN
            ));
            // Add CAM payload
            v_gnNonSecuredPacket.payload := valueof(f_adaptPayload_m(p_payload));
            
            f_buildGnSecuredCam(
                v_securedMessage,
                m_payload_signed(bit2oct(encvalue(v_gnNonSecuredPacket))),
                e_certificate,
                -,
                p_certificate
            );
                
            // Build secured Gn packet
            v_gnReq := valueof(m_geoNwReq_linkLayerBroadcast(
                m_geoNwSecPdu(
                    v_gnNonSecuredPacket,
                    v_securedMessage
                ) // End of template m_geoNwSecPdu
            )); // End of template m_geoNwReq_linkLayerBroadcast
            
            // Send Message
            f_sendGeoNetMessage(v_gnReq);
            
        } // End of function f_sendCertificate
        
    } // End of group CertRequests 
    
    group messageGetters {