test_LibItsGeoNetworking_TypesAndValues.ttcn 148 KB
Newer Older
filatov's avatar
filatov committed
1
module test_LibItsGeoNetworking_TypesAndValues /*language "TTCN-3:2009 Advanced Parameterization"*/ {
2
3
    
    // LibCommon
filatov's avatar
filatov committed
4
5
    import from LibCommon_BasicTypesAndValues all;
    import from LibCommon_DataStrings all;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
    
    // LibIts
    import from ITS_Container language "ASN.1:1997" all;
    import from CAM_PDU_Descriptions language "ASN.1:1997"all;
    import from DENM_PDU_Descriptions language "ASN.1:1997" all;
    
    // LibItsCommon
    import from LibItsCommon_TypesAndValues all;
    import from LibItsCommon_Functions all;
    
    // LibItsExternal
    import from LibItsExternal_TypesAndValues all;
    
    // LibItsCam
    import from LibItsCam_TypesAndValues all;
    import from LibItsCam_TestSystem all;
    import from LibItsCam_Templates {
        template m_camReq;
        group camTemplateFunctions
    };
    
    // LibItsDenm
    import from LibItsDenm_Templates all;
    import from LibItsDenm_TestSystem all;
    
    // LibItsSecurity
    import from LibItsSecurity_TypesAndValues all;
    import from LibItsSecurity_Templates all;
    import from LibItsSecurity_Functions all;
    import from LibItsSecurity_Pixits all;
    
    // LibItsGeoNetworking
filatov's avatar
filatov committed
38
39
40
    import from LibItsGeoNetworking_TypesAndValues all;
    import from LibItsGeoNetworking_Templates all;
    import from LibItsGeoNetworking_Functions all;
41
42
43
44
45
46
47
    import from LibItsGeoNetworking_TestSystem all;
    import from LibItsGeoNetworking_Pixits all;
    import from LibItsGeoNetworking_Pics all;
    
//    import from LibItsIpv6OverGeoNetworking_TypesAndValues all;
//    import from LibItsIpv6OverGeoNetworking_Templates all;
//    import from LibItsExternal_TypesAndValues all;
filatov's avatar
filatov committed
48
49
50
51
52
53
54

    import from test_CommonCodec all;
    
    import from test_LibItsBtp_TypesAndValues {
        template all 
    };

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    group LibItsGeoNetworking_testCases {
        
        group LibItsGeoNetworking_DummyTemplates {
            
            /**
             * @desc    Dummy template for GN_Address 
             */
            template (value) GN_Address m_dummyGnAddrIut := {
                typeOfAddress := e_manual,
                stationType := e_roadSideUnit,
                stationCountryCode := 33,
                mid := 'a4fedecabeef'O
            }
    
            /**
             * @desc    Dummy template for long position vector
             */
            template (value) LongPosVector m_dummyLongPosVectorIut := {
                gnAddr := m_dummyGnAddrIut,
                timestamp := 123456,
                latitude := 4856,
                longitude := 675,
                pai := '1'B,
                speed := 55,
                heading := 9876
filatov's avatar
filatov committed
80
81
            }
            
82
83
84
85
86
            template (value) GN_Address m_dummyGnAddrNodeA := {
                typeOfAddress := e_manual,
                stationType := e_pedestrian,
                stationCountryCode := 49,
                mid := 'a4fdea5ea5ed'O
filatov's avatar
filatov committed
87
            }
88
89
90
91
92
93
            
            template (value) GN_Address m_dummyGnAddrNodeB := {
                typeOfAddress := e_manual,
                stationType := e_specialVehicle,
                stationCountryCode := 50,
                mid := 'a40102030405'O
filatov's avatar
filatov committed
94
            }
95
96
97
98
99
100
    
            template (value) GN_Address m_dummyGnAddrNodeC := {
                typeOfAddress := e_manual,
                stationType := e_moped,
                stationCountryCode := 42,
                mid := 'deadbabebeef'O
filatov's avatar
filatov committed
101
            }
102
103
104
105
106
107
108
109
110
    
            template (value) LongPosVector m_dummyLongPosVectorNodeA := {
                gnAddr := m_dummyGnAddrNodeA,
                timestamp := 875,
                latitude := 265,
                longitude := 789,
                pai := '0'B,
                speed := 80,
                heading := 548
filatov's avatar
filatov committed
111
            }
112
113
114
115
116
117
118
119
120
    
            template (value) LongPosVector m_dummyLongPosVectorNodeB := {
                gnAddr := m_dummyGnAddrNodeB,
                timestamp := 4585,
                latitude := 126,
                longitude := 123,
                pai := '0'B,
                speed := 45,
                heading := 125
filatov's avatar
filatov committed
121
            }
122
123
124
125
126
127
128
129
130
            
            template (value) LongPosVector m_dummyLongPosVectorNodeC := {
                gnAddr := m_dummyGnAddrNodeC,
                timestamp := 23644,
                latitude := 23754,
                longitude := 49645,
                pai := '0'B,
                speed := 110,
                heading := 23
filatov's avatar
filatov committed
131
            }
132
133
134
135
136
137
138
            
            template (value) Area m_dummyArea1 := {
                geoAreaPosLatitude := 298376,
                geoAreaPosLongitude := 32745,
                distanceA := 1234,
                distanceB := 5678,
                angle := 9123
filatov's avatar
filatov committed
139
            }
140
141
142
143
144
145
146
    
            template (value) Area m_dummyArea2 := {
                geoAreaPosLatitude := 873548,
                geoAreaPosLongitude := 2837,
                distanceA := 8765,
                distanceB := 4321,
                angle := 4567
filatov's avatar
filatov committed
147
            }
148
149
150
151
    
            template (value) GeoBroadcastArea m_dummyGeoBroadcastArea1 := {
                geoBroadcastSubType := e_geoBroadcastRect,
                geoBroadcastArea := m_dummyArea1
filatov's avatar
filatov committed
152
            }
153
154
155
156
    
            template (value) GeoBroadcastArea m_dummyGeoBroadcastArea2 := {
                geoBroadcastSubType := e_geoBroadcastElip,
                geoBroadcastArea := m_dummyArea2
filatov's avatar
filatov committed
157
            }
158
159
160
161
162
163
164
165
166
167
168
    
            template (value) GeoAnycastArea m_dummyGeoAnycastArea1 := {
                geoAnycastSubType := e_geoAnycastCircle,
                geoAnycastArea := m_dummyArea1
            }
    
            template (value) GeoAnycastArea m_dummyGeoAnycastArea2 := {
                geoAnycastSubType := e_geoAnycastRect,
                geoAnycastArea := m_dummyArea2
            }
    
filatov's avatar
filatov committed
169
            /**
170
171
172
173
174
             * @desc    Send template for GeoUnicast header
             * @param   p_sourceLongPosVec      Long position vector of source 
             * @param   p_destinationLongPosVec Long position vector of destination 
             * @param   p_senderLongPosVec      Long position vector of sender
             * @param   p_seqNumber             Sequence number of GeoUnicast packet
filatov's avatar
filatov committed
175
             */
176
177
178
179
180
181
182
183
184
185
186
            template (value) ExtendedHeader m_geoUnicastHeaderBtp(
                in template (value) LongPosVector p_sourceLongPosVec,
                in template (value) ShortPosVector p_dstPosVector,
                in template (value) UInt16 p_seqNumber
            ) := {
                geoUnicastHeader := {
                    seqNumber := p_seqNumber,
                    reserved := c_uInt8Zero,
                    srcPosVector := p_sourceLongPosVec,
                    dstPosVector := p_dstPosVector
                }
filatov's avatar
filatov committed
187
            }
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
            
        } // End of group LibItsGeoNetworking_DummyTemplates
        
        group camTemplates {
            
            template (value) CAM m_camMsg(
                StationID p_stationId,
                GenerationDeltaTime p_generationTime
            ) := {
                header := {
                    protocolVersion := 1,
                    messageID := 2,
                    stationID := p_stationId
                },
                cam := {
                    generationDeltaTime := p_generationTime,
                    camParameters := {
                        basicContainer := {
                            stationType := c_stationType_passengerCar,
                            referencePosition := {
                                latitude := f_integer2Latitude(f_getTsLatitude()),
                                longitude := f_integer2Longitude(f_getTsLongitude()),
                                positionConfidenceEllipse := {
                                    semiMajorConfidence   := c_semiAxisLengthOneCentimeter,
                                    semiMinorConfidence   := c_semiAxisLengthOneCentimeter,
                                    semiMajorOrientation  := c_headingValue_wgs84North
                                },
                                altitude := {
                                    altitudeValue := c_altitudeValue_seaLevel,
                                    altitudeConfidence := unavailable
                                }
                            }
                        },
                        highFrequencyContainer := {
                            basicVehicleContainerHighFrequency := {
                                heading := {
                                    headingValue := c_headingValue_wgs84North, //0
                                    headingConfidence := 10
                                },
                                speed := {
                                    speedValue := 45,
                                    speedConfidence := 5
                                },
                                driveDirection := forward,
                                vehicleLength := {
                                    vehicleLengthValue := 50,
                                    vehicleLengthConfidenceIndication := noTrailerPresent
                                },
                                vehicleWidth := 21,
                                longitudinalAcceleration := {
                                    longitudinalAccelerationValue := c_longitudinalAccelerationValue_unavailable,
                                    longitudinalAccelerationConfidence := c_accelerationConfidence_unavailable
                                },
                                curvature := {
                                    curvatureValue := c_curvatureValue_straight,
                                    curvatureConfidence := unavailable
                                },
                                curvatureCalculationMode := yawRateUsed,
                                yawRate := {
                                    yawRateValue := c_yawRateValue_straight,
                                    yawRateConfidence := unavailable
                                },
                                accelerationControl := omit,
                                lanePosition := omit,
                                steeringWheelAngle := omit,
                                lateralAcceleration := omit,
                                verticalAcceleration := omit, 
                                performanceClass := omit,
                                cenDsrcTollingZone := omit
                                
                            }
                        },
                        lowFrequencyContainer := omit,
                        specialVehicleContainer := omit
                    }
                }
            };
            
        } // End of group camTemplates
        
        group securityTemplates {
            
            template (value) Oct32 m_devicePrivateKey := '3aa27835bfe11dc6711b7c471fd3994b3ee94bcf59bcb0cade6abffe7c2f6530'O;
            
            template (value) Certificate m_deviceCertificate := {
                version             := 2,
                signer_info         := m_signerInfo_digest('0727A031EE3F372C'O),
                subject_info        := m_subject_info_authorization_ticket,
                subject_attributes  := {
                    m_subject_attribute_verification_key(
                        m_publicKey_eccPoint(
                            m_eccPointecdsa_nistp256_with_sha256_uncompressed(
                                'cd2904aee519278f5c1d0c89810d2b846b7796ba244944d2a15fa5665bc2d1c2'O,
                                'ec0dd4f97c194c7c3e92b7e9af4c25b43b1c8de9bba8261c2b8454ec51b42e8e'O
                            )
                        )
                    ),
                    m_subject_attribute_encryption_key(
                        m_publicKey_aesccm(
                            m_aesccm(
                                m_eccPointecdsa_nistp256_with_sha256_uncompressed(
                                    'ad4334139b7659360d46b423e01971aae009bd15a77c9144e67312ff7c6f7d93'O,
                                    '01068089afad1f25941e2e1ab230eebf8bf022dadd201e64311d62868d2a3ec0'O
                                )
                            )
                        )
                    ),
                    m_subject_attribute_assurance_level(
                        m_subjectAssurance(
                            '001'B, 
                            '00'B
                        )
                    ),
                    m_subject_attribute_its_aid_list(
                        { 
                            16512,
                            16513
                        }
                    )
                },
                validity_restrictions   := {
                    m_validity_restriction_time_start_and_end(
                        1405173485,
                        1513691885
                    )
                },
                signature_              := m_signature(
                    m_ecdsaSignature(
                        m_eccPointecdsa_nistp256_with_sha256_x_coordinate_only(
                            '54c524c932ac1d7fb2cf3c7e5a6f9d0e46092d84eab0fa7240c47b202eb1566d'O
                        ),
                        '98f54758fb46e4f3254aedfa59dda07c1e49f19b2dee2ab6922a7526d32f9842'O
                    )
                )
                
            } // End of template m_deviceCertificate
            
        } // End of group securityTemplates
        
        group testAcPrimitives {
filatov's avatar
filatov committed
328

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
//            /**
//             * 
//             * @desc validate StartBeaconing primitive
//             * @verdict Pass on success, Fail otherwise
//             */
//            testcase tc_startBeaconing() runs on TCType system TCType {
//                test_PDU<AcGnPrimitive>(
//                    m_startBeaconing(
//                        m_beaconHeader(m_dummyLongPosVectorIut).beaconHeader), 
//                    true,
//                    oct2bit('010027050024001000000000000a9421a4fedecabeef0001e240000012f8000002a300372694020e6248'O) // Check for 'LibItsGeoNetworking_TypesAndValues.encode:' output in codec traces to get the dump
//                );
//            }
//
//            /**
//             * 
//             * @desc validate StartBeaconing primitive for roadside equipment
//             * @verdict Pass on success, Fail otherwise
//             */
//            testcase tc_startBeaconingRoadside() runs on TCType system TCType {
//                test_PDU<AcGnPrimitive>(
//                    m_startBeaconingRoadSide, 
//                    true,
//                    oct2bit('010027050024001000000000000a4c00deadbeef00030000000017d75cf005f5e10003e8000000140000'O) // Check for 'LibItsGeoNetworking_TypesAndValues.encode:' output in codec traces to get the dump
//                );
//            }
//            testcase tc_startBeaconingRoadside_NEC() runs on TCType system TCType {
//                test_PDU<AcGnPrimitive>(
//                    m_startBeaconingRoadSide_NEC, 
//                    true,
//                    oct2bit('010027050024101000000000000a4c00deadbeef0002c90c152800004e20000000000000000000000000'O) // Check for 'LibItsGeoNetworking_TypesAndValues.encode:' output in codec traces to get the dump
//                );
//            }
//            testcase tc_startBeaconingRoadside_NEC_1() runs on TCType system TCType {
//                test_PDU<AcGnPrimitive>(
//                    m_startBeaconingRoadSide_NEC_1, 
//                    true,
//                    oct2bit('010027050024101000000000000a4c00deadbeef0003c926268affffd8f0000000000000000000000000'O) // Check for 'LibItsGeoNetworking_TypesAndValues.encode:' output in codec traces to get the dump
//                );
//            }
//
//            /**
//             * @desc validate StartPassBeaconing primitive
//             * @verdict Pass on success, Fail otherwise
//             */
//            testcase tc_startPassBeaconing() runs on TCType system TCType {
//                test_PDU<AcGnPrimitive>(
//                    m_startPassBeaconing(
//                        m_beaconHeader(m_dummyLongPosVectorIut).beaconHeader), 
//                    true,
//                    oct2bit('010027070024001000000000000a9421a4fedecabeef0001e240000012f8000002a300372694020e6248'O) // Check for 'LibItsGeoNetworking_TypesAndValues.encode:' output in codec traces to get the dump
//                );
//            }
//
//            /**
//             * @desc validate StartBeaconingMultipleNeighbour primitive
//             * @verdict Pass on success, Fail otherwise
//             */
//            testcase tc_startBeaconingMultipleNeighbour() runs on TCType system TCType {
//                test_PDU<AcGnPrimitive>(
//                    m_startBeaconingMultipleNeighbour(
//                        m_beaconHeader(m_dummyLongPosVectorIut).beaconHeader,
//                        3), 
//                    true,
//                    oct2bit('01002b090028001000000000000a9421a4fedecabeef0001e240000012f8000002a300372694020e624800000003'O) // Check for 'LibItsGeoNetworking_TypesAndValues.encode:' output in codec traces to get the dump
//                );
//            }
//
filatov's avatar
filatov committed
397
398
399
400
401
            /**
             * @desc validate StopBeaconing primitive
             * @verdict Pass on success, Fail otherwise
             */
            testcase tc_stopBeaconing() runs on TCType system TCType {
402
                test_PDU<AcGnPrimitive>(m_stopBeaconing, true, oct2bit('0001'O));
filatov's avatar
filatov committed
403
404
405
406
407
408
409
            }

            /**
             * @desc validate StopPassBeaconing primitive
             * @verdict Pass on success, Fail otherwise
             */
            testcase tc_stopPassBeaconing() runs on TCType system TCType {
410
                test_PDU<AcGnPrimitive>(m_stopPassBeaconing, true, oct2bit('0003'O));
filatov's avatar
filatov committed
411
412
413
414
415
416
417
            }

            /**
             * @desc validate StopBeaconingMultipleNeighbour
             * @verdict Pass on success, Fail otherwise
             */
            testcase tc_stopBeaconingMultipleNeighbour() runs on TCType system TCType {
418
                test_PDU<AcGnPrimitive>(m_stopBeaconingMultipleNeighbour, true, oct2bit('0005'O));
filatov's avatar
filatov committed
419
420
421
422
423
424
425
            }

            /**
             * @desc validate AcGetLongPosVector
             * @verdict Pass on success, Fail otherwise
             */
            testcase tc_getLongPosVector() runs on TCType system TCType {
426
                test_PDU<AcGnPrimitive>(m_getLongPosVector(m_dummyGnAddrIut), true, oct2bit('0006BC21A4FEDECABEEF'O)); // Check log for TC_GEONW_FDV_COH_BV_01 TC to retrieve the frame
filatov's avatar
filatov committed
427
428
            }

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
//            /**
//             * @desc validate AcGnResponse
//             * @verdict Pass on success, Fail otherwise
//             */
//            testcase tc_longPosVector() runs on TCType system TCType {
//                test_decodePDU<AcGnResponse>(mw_getLongPosVectorAny(m_dummyGnAddrIut), '0300270c00249421a4fedecabeef000030aa000030aa000030aa000030aa000030aa000030aa000030aa'O); // Check log for TC_GEONW_FDV_COH_BV_01 TC to retrieve the frame
//            }
//
//            /**
//             * @desc validate AcGnResponse with a NULL LongPosVector
//             * @verdict Pass on success, Fail otherwise
//             */
//            testcase tc_longPosVectorWithNullLongPosVector() runs on TCType system TCType {
//                test_decodePDU<AcGnResponse>(mw_getLongPosVectorAny(m_dummyGnAddrIut), '03000b0c00088400000000000001FFFFFFFFFFFF'O); // Check log for TC_GEONW_PON_LPV_BV_01 TC to retrieve the frame
//            }
//
filatov's avatar
filatov committed
445
            /**
446
             * @desc validate AcEnableSecurity
filatov's avatar
filatov committed
447
448
             * @verdict Pass on success, Fail otherwise
             */
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
            testcase tc_enableSecurity() runs on TCType system TCType {
                var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessageDigest;
                var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessageCertificate;
                
                if (f_loadCertificates("dummy") == true) {
                    setverdict(fail);
                    stop;
                }
                
                // Setup certificates memory cache
                if (f_loadCertificates("cfg01") == false) {
                    setverdict(fail);
                    stop;
                }
                f_setGenerationLocation(
                    f_getTsLatitude(),
                    f_getTsLongitude()
                );
                
                // Build the beacon template
                v_toBeSignedSecuredMessageDigest := f_buildSecuredMessagePayloadToBeSigned();
                v_toBeSignedSecuredMessageCertificate := f_buildSecuredMessagePayloadToBeSigned(true);
                
                test_PDU<AcGnPrimitive>(
                    AcGnPrimitive:{ acEnableSecurity := m_enableSecurity(
                        "TA_CERT_A"
                    ) }, 
                    false
                ); 
filatov's avatar
filatov committed
478
            }
479
            
filatov's avatar
filatov committed
480
            /**
481
             * @desc validate AcDisableSecurity
filatov's avatar
filatov committed
482
483
             * @verdict Pass on success, Fail otherwise
             */
484
485
486
487
488
            testcase tc_disableSecurity() runs on TCType system TCType {
                test_PDU<AcGnPrimitive>(
                    AcGnPrimitive:{ acDisableSecurity := m_disableSecurity }, 
                    false
                ); 
filatov's avatar
filatov committed
489
490
491
            }

        } // End of group testAcPrimitives
492
493
494
        
        group testDeviceSigning {
            
filatov's avatar
filatov committed
495
            /**
496
497
498
499
500
501
502
             * @desc This function build and sign the SecureMessage part covered by the signature process
             * @param p_securedMessage      The signed  SecureMessage part
             * @param p_unsecuredPayload    The unsigned payload (e.g. a beacon)
             * @param p_threeDLocation      The ThreeDLocation value
             * @param p_headerFileds        Additional HeaderFields
             * @return true on success, false otherwise
             * @verdict Unchanged
filatov's avatar
filatov committed
503
             */
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
            function f_buildGnSecuredOtherMessageWithDeviceCertificate(
                                                                       out template (value) SecuredMessage p_securedMessage, 
                                                                       in octetstring p_signedPayload, 
                                                                       in ThreeDLocation p_threeDLocation, 
                                                                       in template (value) Certificate p_deviceCertificate,
                                                                       in Oct32 p_devicePrivateKey,
                                                                       in template (omit) HeaderFields p_hearderFields := omit
            ) return boolean {
                
                // Local variables
                var octetstring v_secPayload, v_signature;
                var Oct32 v_hash;
                var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessage;
                 
//                 log("f_buildGnSecuredOtherMessageWithDeviceCertificate: p_unsecuredPayload: ", p_unsecuredPayload);
                 
                // Create SecuredMessage payload to be signed
                v_toBeSignedSecuredMessage := m_toBeSignedSecuredMessage(
                    { // Field HeaderFields
                        m_header_field_signer_info(
                            m_signerInfo_certificate(
                                p_deviceCertificate
                            ) // End of template m_signerInfo_certificate
                        ), // End of template m_header_field_signer_info
                        m_header_field_generation_time(1000 * f_getCurrentTime()), // In us
                        m_header_field_generation_location(
                            p_threeDLocation
                        )
                    }, // End of field HeaderFields
                    m_payload_signed(
                        p_signedPayload
                    ),
                    e_signature
                );
                v_secPayload := bit2oct(encvalue(v_toBeSignedSecuredMessage));
//                log("f_buildGnSecuredOtherMessageWithDeviceCertificate:ithDeviceCertificate v_toBeSignedSecuredMessage: ", v_secPayload);
                
                // Calculate the hash of the SecuredMessage payload to be signed
                v_hash := f_hashWithSha256(v_secPayload);
//                log("f_buildGnSecuredOtherMessageWithDeviceCertificate: v_hash: ", v_hash);
                
                // Signed payload
                v_signature := fx_signWithEcdsaNistp256WithSha256(
                    v_hash, 
                    p_devicePrivateKey
                );
//                log("f_buildGnSecuredOtherMessageWithDeviceCertificate: v_signature: ", v_signature);
                
                p_securedMessage := m_securedMessage( // See Clause 7.3   Generic security profile for other signed messages
                    v_toBeSignedSecuredMessage.header_fields,
                    v_toBeSignedSecuredMessage.payload_field,
                    {
                        m_trailer_field_signature(
                            m_signature(
                                m_ecdsaSignature(
                                    m_eccPointecdsa_nistp256_with_sha256_y_coordinate_only(
                                        substr(v_signature, 2, 32)
                                    ),
                                    substr(v_signature, 34, 32)
                                )
                            )
                        )
                    }
                ); // End of template md_securedMessage_profileOther
                
                return true;
            } // End of function f_buildGnSecuredOtherMessageWithDeviceCertificate
            
            testcase tc_checkDeviceSignature() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_gnPayload, v_encMsg;
                var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessage;
                var template (value) SecuredMessage v_securedMessageBeacon;
filatov's avatar
filatov committed
577
578
579
580
581
582
                
                if (PX_GN_UPPER_LAYER != e_any) {
                    log("PX_GN_UPPER_LAYER shall be set to e_any");
                    stop;
                }
                
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
                // Build signed SecuredMessage
                v_gnPayload := bit2oct( // Create GN payload
                    encvalue(
                        m_geoNwBeaconPacket( // Non secured GN beacon
                            m_dummyLongPosVectorIut
                        )
                    )
                );
                f_buildGnSecuredOtherMessageWithDeviceCertificate(
                    v_securedMessageBeacon,
                    v_gnPayload, 
                    m_threeDLocation(
                        1234,
                        5678,
                        '002F'O
                    ),
                    m_deviceCertificate,
                    m_devicePrivateKey
filatov's avatar
filatov committed
601
                );
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
                
                // Build secured Gn packet
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwSecPdu(
                        m_geoNwBeaconPacket(
                            m_dummyLongPosVectorIut
                        ),
                        v_securedMessageBeacon
                    ) // End of template m_geoNwBeaconPacket
                ); // End of template m_geoNwReq_linkLayerBroadcast
                
                // Encode it
                v_encMsg := bit2oct(encvalue(v_gnReq));
                if (not isbound(v_encMsg)) {
                    setverdict(fail, "Encoding failed!");
                    stop;
                }
                log("Secured beacon: ", v_encMsg);
                setverdict(pass, "Encoding passed.");
                // Decode it
filatov's avatar
filatov committed
622
                test_decodePDU<GeoNetworkingReq>(
623
624
                    v_gnReq, 
                    v_encMsg
filatov's avatar
filatov committed
625
                );
626
627
628
629
630
631
632
633
634
635
                
                if (decvalue(oct2bit(v_encMsg), v_gnReq) == 0) {
                    if (f_verifyGnSecuredMessageSignatureWithCertificate(v_securedMessageBeacon, m_deviceCertificate) == true) {
                        setverdict(pass, "Signature check succeed.");
                    } else {
                        setverdict(fail, "Signature check failed.");
                    } 
                } else {
                    setverdict(fail, "Decoding failed.");
                }
filatov's avatar
filatov committed
636
637
            }
            
638
639
640
        } // End of group testSecurityFunctions
        
        group testGeoNetPrimitiveMessages {
filatov's avatar
filatov committed
641
642
            
            /**
643
             * @desc validate GeoNetworkingReq/Beacon
filatov's avatar
filatov committed
644
645
             * @verdict Pass on success, Fail otherwise
             */
646
647
648
            testcase tc_GeoNetReq_Beacon() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_buffer := '01002B0A0010800000000100BC21A4FEDECABEEF0001E240000012F8000002A380372694FFFFFFFFFFFF'O;
filatov's avatar
filatov committed
649
650
651
652
653
                
                if (PX_GN_UPPER_LAYER != e_any) {
                    log("PX_GN_UPPER_LAYER shall be set to e_any");
                    stop;
                }
654
655
656
657
658
659
                
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwPdu(
                        m_geoNwBeaconPacket(
                            m_dummyLongPosVectorIut
                    )));
filatov's avatar
filatov committed
660
                test_PDU<GeoNetworkingReq>(
661
662
663
                    v_gnReq, 
                    true, 
                    oct2bit(v_buffer)
filatov's avatar
filatov committed
664
665
666
667
                );
            }
            
            /**
668
             * @desc validate secured GeoNetworkingReq/Beacon with certificate digest in header fields
filatov's avatar
filatov committed
669
670
             * @verdict Pass on success, Fail otherwise
             */
671
672
673
674
675
            testcase tc_GeoNetReq_SecuredBeacon_digest() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_gnPayload, v_encMsg;
                var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessage;
                var template (value) SecuredMessage v_securedMessageBeacon;
filatov's avatar
filatov committed
676
677
678
679
680
                
                if (PX_GN_UPPER_LAYER != e_any) {
                    log("PX_GN_UPPER_LAYER shall be set to e_any");
                    stop;
                }
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
                
                // Load certificates & keys
                if (f_loadCertificates("cfg01") == false) {
                    setverdict(fail);
                    stop;
                }
                f_setGenerationLocation(
                    f_getTsLatitude(),
                    f_getTsLongitude()
                );
                
                // Build signed SecuredMessage
                v_gnPayload := bit2oct( // Create GN payload
                    encvalue(
                        m_geoNwBeaconPacket( // Non secured GN beacon
                            m_dummyLongPosVectorIut
filatov's avatar
filatov committed
697
                        )
698
699
700
701
702
703
704
705
706
707
708
                    )
                );
                f_buildGnSecuredOtherMessage(
                    v_securedMessageBeacon,
                    m_payload_signed(v_gnPayload),
                    e_certificate_digest_with_sha256,
                    m_threeDLocation(
                        1234,
                        5678,
                        '002F'O
                    )
filatov's avatar
filatov committed
709
710
                );
                
711
712
713
714
715
716
717
718
719
720
721
722
723
724
                // Build secured Gn packet
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwSecPdu(
                        m_geoNwBeaconPacket(
                            m_dummyLongPosVectorIut
                        ),
                        v_securedMessageBeacon
                    ) // End of template m_geoNwBeaconPacket
                ); // End of template m_geoNwReq_linkLayerBroadcast
                
                // Encode it
                v_encMsg := bit2oct(encvalue(v_gnReq));
                if (not isbound(v_encMsg)) {
                    setverdict(fail, "Encoding failed!");
filatov's avatar
filatov committed
725
726
                    stop;
                }
727
728
729
                log("Secured beacon: ", v_encMsg);
                setverdict(pass, "Encoding passed.");
                // Decode it
filatov's avatar
filatov committed
730
                test_decodePDU<GeoNetworkingReq>(
731
732
                    v_gnReq, 
                    v_encMsg
filatov's avatar
filatov committed
733
                );
734
735
736
737
738
739
740
741
742
743
                
                if (decvalue(oct2bit(v_encMsg), v_gnReq) == 0) {
                    if (f_verifyGnSecuredMessageSignatureWithCertificate(v_gnReq.msgOut.gnPacket.securedMsg, vc_atCertificate) == true) {
                        setverdict(pass, "Signature check succeed.");
                    } else {
                        setverdict(fail, "Signature check failed.");
                    } 
                } else {
                    setverdict(fail, "Decoding failed.");
                }
filatov's avatar
filatov committed
744
745
746
            }
            
            /**
747
             * @desc validate secured GeoNetworkingReq/Beacon with certificate in header fields
filatov's avatar
filatov committed
748
749
             * @verdict Pass on success, Fail otherwise
             */
750
751
752
753
754
            testcase tc_GeoNetReq_SecuredBeacon_certificate() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_gnPayload, v_encMsg;
                var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessage;
                var template (value) SecuredMessage v_securedMessageBeacon;
filatov's avatar
filatov committed
755
756
757
758
759
                
                if (PX_GN_UPPER_LAYER != e_any) {
                    log("PX_GN_UPPER_LAYER shall be set to e_any");
                    stop;
                }
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
                
                // Load certificates & keys
                if (f_loadCertificates("cfg01") == false) {
                    setverdict(fail);
                    stop;
                }
                f_setGenerationLocation(
                    f_getTsLatitude(),
                    f_getTsLongitude()
                );
                
                // Build signed SecuredMessage
                v_gnPayload := bit2oct( // Create GN payload
                    encvalue(
                        m_geoNwBeaconPacket( // Non secured GN beacon
                            m_dummyLongPosVectorIut
filatov's avatar
filatov committed
776
                        )
777
778
779
780
781
782
783
784
785
786
787
                    )
                );
                f_buildGnSecuredOtherMessage(
                    v_securedMessageBeacon,
                    m_payload_signed(v_gnPayload),
                    e_certificate,
                    m_threeDLocation(
                        1234,
                        5678,
                        '002F'O
                    )
filatov's avatar
filatov committed
788
789
                );
                
790
791
792
793
794
795
796
797
798
799
800
801
802
803
                // Build secured Gn packet
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwSecPdu(
                        m_geoNwBeaconPacket(
                            m_dummyLongPosVectorIut
                        ),
                        v_securedMessageBeacon
                    ) // End of template m_geoNwBeaconPacket
                ); // End of template m_geoNwReq_linkLayerBroadcast
                
                // Encode it
                v_encMsg := bit2oct(encvalue(v_gnReq));
                if (not isbound(v_encMsg)) {
                    setverdict(fail, "Encoding failed!");
filatov's avatar
filatov committed
804
805
                    stop;
                }
806
807
808
                log("Secured beacon: ", v_encMsg);
                setverdict(pass, "Encoding passed.");
                // Decode it
filatov's avatar
filatov committed
809
                test_decodePDU<GeoNetworkingReq>(
810
811
                    v_gnReq, 
                    v_encMsg
filatov's avatar
filatov committed
812
                );
813
814
815
816
817
818
819
820
821
                
                if (decvalue(oct2bit(v_encMsg), v_gnReq) == 0) {
                    if (f_verifyGnSecuredMessageSignatureWithCertificate(v_gnReq.msgOut.gnPacket.securedMsg, vc_atCertificate) == true) {
                        setverdict(pass, "Signature check succeed.");
                    } else {
                        setverdict(fail, "Signature check failed.");
                    } 
                } else {
                    setverdict(fail, "Decoding failed.");
filatov's avatar
filatov committed
822
823
                }
            }
824
            
filatov's avatar
filatov committed
825
            /**
826
             * @desc validate secured GeoNetworkingReq/Beacon
filatov's avatar
filatov committed
827
828
             * @verdict Pass on success, Fail otherwise
             */
829
830
831
832
833
            testcase tc_GeoNetReq_SecuredBeacon_WithAdditionalHeaders() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_gnPayload, v_encMsg;
                var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessage;
                var template (value) SecuredMessage v_securedMessageBeacon;
filatov's avatar
filatov committed
834
                
835
836
                if (PX_GN_UPPER_LAYER != e_any) {
                    log("PX_GN_UPPER_LAYER shall be set to e_any");
filatov's avatar
filatov committed
837
838
                    stop;
                }
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
                
                // Load certificates & keys
                if (f_loadCertificates("cfg01") == false) {
                    setverdict(fail);
                    stop;
                }
                f_setGenerationLocation(
                    f_getTsLatitude(),
                    f_getTsLongitude()
                );
                log("vc_signingPrivateKey=", vc_signingPrivateKey);
                log("vc_encryptPrivateKey=", vc_encryptPrivateKey);
                log("vc_aaCertificate=", vc_aaCertificate);
                log("vc_atCertificate=", vc_atCertificate);
                
                // Build signed SecuredMessage
                v_gnPayload := bit2oct( // Create GN payload
                    encvalue(
                        m_geoNwBeaconPacket( // Non secured GN beacon
                            m_dummyLongPosVectorIut
filatov's avatar
filatov committed
859
                        )
860
                    )
filatov's avatar
filatov committed
861
                );
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
                f_buildGnSecuredOtherMessage(
                    v_securedMessageBeacon,
                    m_payload_signed(v_gnPayload),
                    e_certificate_digest_with_sha256,
                    m_threeDLocation(
                        1234,
                        5678,
                        '002F'O
                    ),
                    {
                        {
                            type_ := e_request_unrecognized_certificate,
                            headerField := {
                                digests := { '00CAFE'O }
                            }
                        }
                    }
                );
                log("v_securedMessageBeacon= ", v_securedMessageBeacon);
                
                // Build secured Gn packet
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwSecPdu(
                        m_geoNwBeaconPacket(
                            m_dummyLongPosVectorIut
                        ),
                        v_securedMessageBeacon
                    ) // End of template m_geoNwBeaconPacket
                ); // End of template m_geoNwReq_linkLayerBroadcast
                
                // Encode it
                v_encMsg := bit2oct(encvalue(v_gnReq));
                if (not isbound(v_encMsg)) {
                    setverdict(fail, "Encoding failed!");
filatov's avatar
filatov committed
896
897
                    stop;
                }
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
                log("Secured beacon: ", v_encMsg);
                setverdict(pass, "Encoding passed.");
                // Decode it
                test_decodePDU<GeoNetworkingReq>(
                    v_gnReq, 
                    v_encMsg
                );
                
                if (decvalue(oct2bit(v_encMsg), v_gnReq) == 0) {
                    if (f_verifyGnSecuredMessageSignatureWithCertificate(v_gnReq.msgOut.gnPacket.securedMsg, vc_atCertificate) == true) {
                        setverdict(pass, "Signature check succeed.");
                    } else {
                        setverdict(fail, "Signature check failed.");
                    } 
                } else {
                    setverdict(fail, "Decoding failed.");
                }
filatov's avatar
filatov committed
915
916
917
            }
            
            /**
918
             * @desc validate secured digest GeoNetworkingReq/LsRequest
filatov's avatar
filatov committed
919
920
             * @verdict Pass on success, Fail otherwise
             */
921
922
923
            testcase tc_GeoNetReq_LsRequestPacket() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_buffer := '01002B0A0060800000000A0030390000BC21A4FEDECABEEF0001E240000012F8000002A380372694BC21A4FEDECABEEFFFFFFFFFFFFF'O;
filatov's avatar
filatov committed
924
925
926
927
928
929
                
                if (PX_GN_UPPER_LAYER != e_any) {
                    log("PX_GN_UPPER_LAYER shall be set to e_any");
                    stop;
                }
                
930
931
932
933
934
935
936
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwPdu(
                        m_geoNwLsRequestPacket(
                            m_dummyLongPosVectorIut,
                            12345,
                            m_dummyGnAddrIut
                    )));
filatov's avatar
filatov committed
937
                test_PDU<GeoNetworkingReq>(
938
                    v_gnReq, 
filatov's avatar
filatov committed
939
                    false, 
940
941
                    oct2bit(v_buffer)
                );
filatov's avatar
filatov committed
942
                test_decodePDU<GeoNetworkingReq>(
943
                    v_gnReq, 
filatov's avatar
filatov committed
944
945
946
947
                    v_buffer
                );
            }
            
948
949
950
951
952
953
954
955
956
            /**
             * @desc validate secured digest GeoNetworkingReq/LsRequest
             * @verdict Pass on success, Fail otherwise
             */
            testcase tc_GeoNetReq_SecuredDigestLsRequestPacket() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_gnPayload, v_encMsg;
                var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessage;
                var template (value) SecuredMessage v_securedMessageBeacon;
filatov's avatar
filatov committed
957
958
959
960
961
962
                
                if (PX_GN_UPPER_LAYER != e_any) {
                    log("PX_GN_UPPER_LAYER shall be set to e_any");
                    stop;
                }
                
963
964
965
                // Load certificates & keys
                if (f_loadCertificates("cfg01") == false) {
                    setverdict(fail);
filatov's avatar
filatov committed
966
967
                    stop;
                }
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
                f_setGenerationLocation(
                    f_getTsLatitude(),
                    f_getTsLongitude()
                );
                
                // Build signed SecuredMessage
                v_gnPayload := bit2oct( // Create GN payload
                    encvalue(
                        m_geoNwLsRequestPacket(
                            m_dummyLongPosVectorIut,
                            12345,
                            m_dummyGnAddrIut
                        )
                    )
                );
                f_buildGnSecuredOtherMessage(
                    v_securedMessageBeacon,
                    m_payload_signed(v_gnPayload),
                    e_certificate_digest_with_sha256,
                    m_threeDLocation(
                        1234,
                        5678,
                        '002F'O
                    )
                );
                
                // Build secured Gn packet
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwSecPdu(
                        m_geoNwLsRequestPacket(
                            m_dummyLongPosVectorIut,
                            12345,
                            m_dummyGnAddrIut
                        ), // End of template m_geoNwLsRequestPacket
                        v_securedMessageBeacon
                    ) // End of template m_geoNwSecPdu
                ); // End of template m_geoNwReq_linkLayerBroadcast
                
                // Encode it
                v_encMsg := bit2oct(encvalue(v_gnReq));
                if (not isbound(v_encMsg)) {
                    setverdict(fail, "Encoding failed!");
filatov's avatar
filatov committed
1010
1011
1012
                    stop;
                }
                
1013
1014
1015
1016
1017
                setverdict(pass, "Encoding passed.");
                // Decode it
                test_decodePDU<GeoNetworkingReq>(
                    v_gnReq, 
                    v_encMsg
filatov's avatar
filatov committed
1018
                );
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
                log("Secured beacon: ", v_encMsg);
                if (decvalue(oct2bit(v_encMsg), v_gnReq) == 0) {
                    if (f_verifyGnSecuredMessageSignatureWithCertificate(v_gnReq.msgOut.gnPacket.securedMsg, vc_atCertificate) == true) {
                        setverdict(pass, "Signature check succeed.");
                    } else {
                        setverdict(fail, "Signature check failed.");
                    } 
                } else {
                    setverdict(fail, "Decoding failed.");
                }
filatov's avatar
filatov committed
1029
1030
1031
            }
            
            /**
1032
             * @desc validate GeoNetworkingReq/LsReply
filatov's avatar
filatov committed
1033
1034
             * @verdict Pass on success, Fail otherwise
             */
1035
1036
1037
            testcase tc_GeoNetReq_LsReplyPacket() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_buffer := '01002B0A0061800000000A0030390000BC21A4FEDECABEEF0001E240000012F8000002A3803726948431A4FDEA5EA5ED0000036B0000010900000315FFFFFFFFFFFF'O;
filatov's avatar
filatov committed
1038
1039
1040
1041
1042
                
                if (PX_GN_UPPER_LAYER != e_any) {
                    log("PX_GN_UPPER_LAYER shall be set to e_any");
                    stop;
                }
1043
1044
1045
1046
1047
1048
1049
1050
                
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwPdu(
                        m_geoNwLsReplyPacket(
                            m_dummyLongPosVectorIut,
                            f_longPosVector2ShortPosVector(m_dummyLongPosVectorNodeA),
                            12345
                )));
filatov's avatar
filatov committed
1051
                test_PDU<GeoNetworkingReq>(
1052
                    v_gnReq, 
filatov's avatar
filatov committed
1053
                    false, 
1054
1055
                    oct2bit(v_buffer)
                );
filatov's avatar
filatov committed
1056
                test_decodePDU<GeoNetworkingReq>(
1057
                    v_gnReq, 
filatov's avatar
filatov committed
1058
1059
1060
1061
1062
                    v_buffer
                );
            }
            
            /**
1063
             * @desc validate secured GeoNetworkingReq/LsReply
filatov's avatar
filatov committed
1064
1065
             * @verdict Pass on success, Fail otherwise
             */
1066
1067
1068
1069
1070
            testcase tc_GeoNetReq_SecuredLsReplyPacket() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_gnPayload, v_encMsg;
                var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessage;
                var template (value) SecuredMessage v_securedMessageBeacon;
filatov's avatar
filatov committed
1071
1072
1073
1074
1075
                
                if (PX_GN_UPPER_LAYER != e_any) {
                    log("PX_GN_UPPER_LAYER shall be set to e_any");
                    stop;
                }
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
                
                // Load certificates & keys
                if (f_loadCertificates("cfg01") == false) {
                    setverdict(fail);
                    stop;
                }
                f_setGenerationLocation(
                    f_getTsLatitude(),
                    f_getTsLongitude()
                );
                
                // Build signed SecuredMessage
                v_gnPayload := bit2oct( // Create GN payload
                    encvalue(
                        m_geoNwLsReplyPacket(
                            m_dummyLongPosVectorIut,
                            f_longPosVector2ShortPosVector(m_dummyLongPosVectorNodeA),
                            12345
                        )
                    )
                );
                f_buildGnSecuredOtherMessage(
                    v_securedMessageBeacon,
                    m_payload_signed(v_gnPayload),
                    e_certificate_digest_with_sha256,
                    m_threeDLocation(
                        1234,
                        5678,
                        '002F'O
                    )
                );
                
                // Build secured Gn packet
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwSecPdu(
                        m_geoNwLsReplyPacket(
                            m_dummyLongPosVectorIut,
                            f_longPosVector2ShortPosVector(m_dummyLongPosVectorNodeA),
                            12345
                        ), // End of template m_geoNwLsReplyPacket
                        v_securedMessageBeacon
                    ) // End of template m_geoNwSecPdu
                ); // End of template m_geoNwReq_linkLayerBroadcast
                
                // Encode it
                v_encMsg := bit2oct(encvalue(v_gnReq));
                if (not isbound(v_encMsg)) {
                    setverdict(fail, "Encoding failed!");
                    stop;
                }
                
                setverdict(pass, "Encoding passed.");
                // Decode it
filatov's avatar
filatov committed
1129
                test_decodePDU<GeoNetworkingReq>(
1130
1131
                    v_gnReq, 
                    v_encMsg
filatov's avatar
filatov committed
1132
                );
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
                log("Secured beacon: ", v_encMsg);
                if (decvalue(oct2bit(v_encMsg), v_gnReq) == 0) {
                    if (f_verifyGnSecuredMessageSignatureWithCertificate(v_gnReq.msgOut.gnPacket.securedMsg, vc_atCertificate) == true) {
                        setverdict(pass, "Signature check succeed.");
                    } else {
                        setverdict(fail, "Signature check failed.");
                    } 
                } else {
                    setverdict(fail, "Decoding failed.");
                }
            }
            
filatov's avatar
filatov committed
1145
            /**
1146
             * @desc validate GeoNetworkingReq/NwShb
filatov's avatar
filatov committed
1147
1148
             * @verdict Pass on success, Fail otherwise
             */
1149
1150
1151
            testcase tc_GeoNetReq_NwShbPacket() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_buffer := '01002B0A00508000000F0A00BC21A4FEDECABEEF0001E240000012F8000002A3803726940000000044454641554C545F5041594C4F4144FFFFFFFFFFFF'O;
filatov's avatar
filatov committed
1152
1153
1154
1155
1156
                
                if (PX_GN_UPPER_LAYER != e_any) {
                    log("PX_GN_UPPER_LAYER shall be set to e_any");
                    stop;
                }
1157
1158
1159
1160
1161
1162
                
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwPdu(
                        m_geoNwShbPacket(
                            m_dummyLongPosVectorIut
                )));
filatov's avatar
filatov committed
1163
                test_PDU<GeoNetworkingReq>(
1164
1165
1166
1167
                    v_gnReq, 
                    false
                );
                v_gnReq.msgOut.gnPacket.packet.commonHeader.plLength := 15;
filatov's avatar
filatov committed
1168
                test_decodePDU<GeoNetworkingReq>(
1169
                    v_gnReq, 
filatov's avatar
filatov committed
1170
1171
1172
1173
1174
                    v_buffer
                );
            }
            
            /**
1175
             * @desc validate GeoNetworkingReq/NwShb with a CAM payload
filatov's avatar
filatov committed
1176
1177
             * @verdict Pass on success, Fail otherwise
             */
1178
1179
1180
            testcase tc_GeoNetReq_NwShbPacketWithBtpPayloadCam() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_buffer := '01002B0A10508000002E0A00BC21A4FEDECABEEF0001E240000012F8000002A380372694000000000000000001020001B20788B80059F48D95CDEFC8C5E0020020002461A83C000004805A100C4528399D4C387FFF80FFFFFFFFFFFF'O;
filatov's avatar
filatov committed
1181
                
1182
1183
                if ((PX_GN_UPPER_LAYER != e_btpA) and (PX_GN_UPPER_LAYER != e_btpB)) {
                    log("PX_GN_UPPER_LAYER shall be set to e_btpA or e_btpB");
filatov's avatar
filatov committed
1184
1185
1186
                    setverdict(inconc);
                    stop;
                }
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
                
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwPdu(
                        m_geoNwShbPacket(
                            m_dummyLongPosVectorIut
                )));
                v_gnReq.msgOut.gnPacket.packet.payload := f_adaptPayload_m(
                    bit2oct(
                        encvalue(
                            m_camReq(
                                m_camMsg(
                                    f_getTsStationId(),
                                    35000
                                )
                            )
                        )
                    )
                );
                
filatov's avatar
filatov committed
1206
                test_PDU<GeoNetworkingReq>(
1207
1208
1209
1210
                    v_gnReq, 
                    false
                );
                v_gnReq.msgOut.gnPacket.packet.commonHeader.plLength := 46;
filatov's avatar
filatov committed
1211
                test_decodePDU<GeoNetworkingReq>(
1212
                    v_gnReq, 
filatov's avatar
filatov committed
1213
1214
1215
                    v_buffer
                );
            }
1216
            
filatov's avatar
filatov committed
1217
            /**
1218
             * @desc validate GeoNetworkingReq/NwShb with a DENM payload
filatov's avatar
filatov committed
1219
1220
             * @verdict Pass on success, Fail otherwise
             */
1221
1222
1223
1224
            testcase tc_GeoNetReq_NwShbPacketWithBtpPayloadDenm() runs on TCType system TCType {
                var template (value) SituationContainer v_situation := m_situation(c_causeVehicleBreakdown, c_subCauseCode_Unavailable);
                var GeoNetworkingReq v_gnReq;
                var octetstring v_buffer := '01002B0A2050800000380A00BC21A4FEDECABEEF0001E240000012F8000002A380372694000000000000000001010001B207C0000D903800000000006072000000188593E91B2B9BDF918C000400400061A80000B6000037FFFDFFFF63390100FFFFFFFFFFFF'O;
filatov's avatar
filatov committed
1225
                
1226
1227
                if (PX_GN_UPPER_LAYER != e_btpB) {
                    log("PX_GN_UPPER_LAYER shall be set to e_btpB");
filatov's avatar
filatov committed
1228
1229
1230
                    setverdict(inconc);
                    stop;
                }
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
                
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwPdu(
                        m_geoNwShbPacket(
                            m_dummyLongPosVectorIut
                )));
                v_gnReq.msgOut.gnPacket.packet.payload := f_adaptPayload_m(
                    bit2oct(
                        encvalue(
                            m_denmReq(
                                m_denmPdu(
                                    m_denm(
                                        m_denmMgmtCon(
                                            m_tsActionId
                                        ),
                                        v_situation,
                                        m_denmLocation_zeroDelta
                                    )
                               )
                           )
                        )
                    )
                );
                
filatov's avatar
filatov committed
1255
                test_PDU<GeoNetworkingReq>(
1256
1257
1258
1259
                    v_gnReq, 
                    false
                );
                v_gnReq.msgOut.gnPacket.packet.commonHeader.plLength := 56;
filatov's avatar
filatov committed
1260
                test_decodePDU<GeoNetworkingReq>(
1261
                    v_gnReq, 
filatov's avatar
filatov committed
1262
1263
1264
                    v_buffer
                );
            }
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
            
            /**
             * @desc validate secured GeoNetworkingReq/NwShb
             * @verdict Pass on success, Fail otherwise
             */
            testcase tc_GeoNetReq_SecuredNwShbPacket() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var octetstring v_gnPayload, v_encMsg;
                var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessage;
                var template (value) SecuredMessage v_securedMessageBeacon;
                
                if (PX_GN_UPPER_LAYER != e_any) {
                    log("PX_GN_UPPER_LAYER shall be set to e_any");
filatov's avatar
filatov committed
1278
1279
                    stop;
                }
1280
1281
1282
1283
                
                // Load certificates & keys
                if (f_loadCertificates("cfg01") == false) {
                    setverdict(fail);
filatov's avatar
filatov committed
1284
1285
                    stop;
                }
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
                f_setGenerationLocation(
                    f_getTsLatitude(),
                    f_getTsLongitude()
                );
                
                // Build signed SecuredMessage
                v_gnPayload := bit2oct( // Create GN payload
                    encvalue(
                        m_geoNwShbPacket( 
                            m_dummyLongPosVectorIut
                        )
                    )
                );
                f_buildGnSecuredOtherMessage(
                    v_securedMessageBeacon,
                    m_payload_signed(v_gnPayload),
                    e_certificate_digest_with_sha256,
                    m_threeDLocation(
                        1234,
                        5678,
                        '002F'O
                    )
                );
                
                // Build secured Gn packet
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwSecPdu(
                        m_geoNwShbPacket(
                            m_dummyLongPosVectorIut
                        ), // End of template m_geoNwLsReplyPacket
                        v_securedMessageBeacon
                    ) // End of template m_geoNwSecPdu
                ); // End of template m_geoNwReq_linkLayerBroadcast
                
                // Encode it
                v_encMsg := bit2oct(encvalue(v_gnReq));
                if (not isbound(v_encMsg)) {
                    setverdict(fail, "Encoding failed!");
filatov's avatar
filatov committed
1324
1325
                    stop;
                }
1326
1327
1328
1329
1330
1331
1332
                setverdict(pass, "Encoding passed.");
                // Decode it
                v_gnReq.msgOut.gnPacket.packet.commonHeader.plLength := 15;
                test_decodePDU<GeoNetworkingReq>(
                    v_gnReq, 
                    v_encMsg
                );
filatov's avatar
filatov committed
1333
                
1334
1335
1336
1337
1338
1339
                if (decvalue(oct2bit(v_encMsg), v_gnReq) == 0) {
                    if (f_verifyGnSecuredMessageSignatureWithCertificate(v_gnReq.msgOut.gnPacket.securedMsg, vc_atCertificate) == true) {
                        setverdict(pass, "Signature check succeed.");
                    } else {
                        setverdict(fail, "Signature check failed.");
                    } 
filatov's avatar
filatov committed
1340
                } else {
1341
                    setverdict(fail, "Decoding failed.");
filatov's avatar
filatov committed
1342
1343
                }
            }
1344
            
filatov's avatar
filatov committed
1345
            /**
1346
             * @desc validate secured with digest GeoNetworkingReq/NwShb with a CAM payload
filatov's avatar
filatov committed
1347
1348
             * @verdict Pass on success, Fail otherwise
             */
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
            testcase tc_GeoNetReq_SecuredDigestNwShbPacketWithBtpPayloadCam() runs on TCType system TCType {
                var GeoNetworkingReq v_gnReq;
                var GnNonSecuredPacket v_gnNonSecuredPacket;
                var octetstring v_gnPayload, v_encMsg;
                var template (value) ToBeSignedSecuredMessage v_toBeSignedSecuredMessage;
                var template (value) SecuredMessage v_securedMessageBeacon;
                
                if ((PX_GN_UPPER_LAYER != e_btpA) and (PX_GN_UPPER_LAYER != e_btpB)) {
                    log("PX_GN_UPPER_LAYER shall be set to e_btpA or e_btpB");
                    setverdict(inconc);
                    stop;
                }
                
                // Load certificates & keys
                if (f_loadCertificates("cfg01") == false) {
filatov's avatar
filatov committed
1364
                    setverdict(fail);
1365
                    stop;
filatov's avatar
filatov committed
1366
                }
1367
1368
1369
                f_setGenerationLocation(
                    f_getTsLatitude(),
                    f_getTsLongitude()
filatov's avatar
filatov committed
1370
                );
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
                
                // Build signed SecuredMessage
                v_gnNonSecuredPacket := m_geoNwShbPacket(
                    m_dummyLongPosVectorIut
                );
                log("v_gnNonSecuredPacket= ", v_gnNonSecuredPacket);
                // Add CAM payload
                v_gnNonSecuredPacket.payload := f_adaptPayload_m(
                    bit2oct(
                        encvalue(
                            m_camReq(
                                m_camMsg(
                                    f_getTsStationId(),
                                    35000
                                )
                            )
                        )
                    )
                );
                log("v_gnNonSecuredPacket.payload= ", v_gnNonSecuredPacket.payload);
                // Encode it
                v_gnPayload := bit2oct( 
                    encvalue(
                        v_gnNonSecuredPacket
                    )
                );
                log("v_gnPayload= ", v_gnPayload);
                f_buildGnSecuredCam(
                    v_securedMessageBeacon,
                    m_payload_signed(v_gnPayload)
                );
                log("v_securedMessageBeacon= ", v_securedMessageBeacon);
                
                // Build secured Gn packet
                v_gnReq := m_geoNwReq_linkLayerBroadcast(
                    m_geoNwSecPdu(
                        v_gnNonSecuredPacket,
                        v_securedMessageBeacon
                    ) // End of template m_geoNwSecPdu
                ); // End of template m_geoNwReq_linkLayerBroadcast
                
                // Encode it
                v_encMsg := bit2oct(encvalue(v_gnReq));
                log("v_encMsg= ", v_encMsg);
                if (not isbound(v_encMsg)) {
                    setverdict(fail, "Encoding failed!");
                    stop;
                }
                setverdict(pass, "Encoding passed.");
                // Decode it
                v_gnReq.msgOut.gnPacket.packet.commonHeader.plLength := 46;
                test_decodePDU<GeoNetworkingReq>(
                    v_gnReq, 
                    v_encMsg
filatov's avatar
filatov committed
1425
                );
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
                log("v_gnReq: ", v_gnReq);
                
                if (decvalue(oct2bit(v_encMsg), v_gnReq) == 0) {
                    if (f_verifyGnSecuredMessageSignatureWithCertificate(v_gnReq.msgOut.gnPacket.securedMsg, vc_atCertificate) == true) {
                        setverdict(pass, "Signature check succeed.");
                    } else {
                        setverdict(fail, "Signature check failed.");
                    } 
                } else {
                    setverdict(fail, "Decoding failed.");
                }
filatov's avatar
filatov committed
1437
            }
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576