ItsPki_TestCases.ttcn 122 KB
Newer Older
garciay's avatar
garciay committed
1
2
3
4
5
6
7
8
9
10
11
12
/**
 *  @author   ETSI / STF545
 *  @version  $URL$
 *            $Id$
 *  @desc     Testcases  file for Security Protocol
 *  @reference   ETSI TS ITS-00546v006
 *  @copyright   ETSI Copyright Notification
 *               No part may be reproduced except as authorized by written permission.
 *               The copyright and the foregoing restriction extend to reproduction in all media.
 *               All rights reserved.
 */
module ItsPki_TestCases {
Yann Garcia's avatar
Yann Garcia committed
13
  
garciay's avatar
garciay committed
14
15
16
17
18
  // Libcommon
  import from LibCommon_Time all;
  import from LibCommon_VerdictControl all;
  import from LibCommon_Sync all;
  import from LibCommon_BasicTypesAndValues all;
Yann Garcia's avatar
Yann Garcia committed
19
  import from LibCommon_DataStrings all;
Yann Garcia's avatar
Yann Garcia committed
20
  
garciay's avatar
garciay committed
21
22
23
24
25
  // LibIts
  import from IEEE1609dot2BaseTypes language "ASN.1:1997" all;
  import from IEEE1609dot2 language "ASN.1:1997" all;
  import from EtsiTs102941BaseTypes language "ASN.1:1997" all;
  import from EtsiTs102941TypesEnrolment language "ASN.1:1997" all;
26
27
  import from EtsiTs102941TypesAuthorization language "ASN.1:1997" all;
  import from EtsiTs102941TypesAuthorizationValidation language "ASN.1:1997" all;
28
  import from EtsiTs102941MessagesCa language "ASN.1:1997" all;
garciay's avatar
garciay committed
29
30
31
  import from EtsiTs103097Module language "ASN.1:1997" all;
  import from ITS_Container language "ASN.1:1997" all;
  import from CAM_PDU_Descriptions language "ASN.1:1997" all;
Yann Garcia's avatar
Yann Garcia committed
32
  
garciay's avatar
garciay committed
33
  // LibItsCommon
Yann Garcia's avatar
Yann Garcia committed
34
  import from LibItsCommon_TypesAndValues all;
garciay's avatar
garciay committed
35
  import from LibItsCommon_Functions all;
Yann Garcia's avatar
Yann Garcia committed
36
  import from LibItsCommon_TypesAndValues all;
garciay's avatar
garciay committed
37
  import from LibItsCommon_ASN1_NamedNumbers all;
Yann Garcia's avatar
Yann Garcia committed
38
39
  
  // LibItsGeoNetworking
40
  import from LibItsGeoNetworking_TypesAndValues all;
Yann Garcia's avatar
Yann Garcia committed
41
42
43
  import from LibItsGeoNetworking_Functions all;
  import from LibItsGeoNetworking_Templates all;
  import from LibItsGeoNetworking_Pics all;
44
  import from LibItsGeoNetworking_TestSystem all;
Yann Garcia's avatar
Yann Garcia committed
45
  
garciay's avatar
garciay committed
46
47
48
49
50
51
52
  // LibItsSecurity
  import from LibItsSecurity_TypesAndValues all;
  import from LibItsSecurity_TestSystem all;
  import from LibItsSecurity_Templates all;
  import from LibItsSecurity_Functions all;
  import from LibItsSecurity_Pixits all;
  import from LibItsSecurity_Pics all;
Yann Garcia's avatar
Yann Garcia committed
53
  
garciay's avatar
garciay committed
54
55
56
57
58
  // LibItsHttp
  import from LibItsHttp_TypesAndValues all;
  import from LibItsHttp_Templates all;
  import from LibItsHttp_BinaryTemplates all;
  import from LibItsHttp_Functions all;
Yann Garcia's avatar
Yann Garcia committed
59
  import from LibItsHttp_TestSystem all;
garciay's avatar
garciay committed
60
  
garciay's avatar
garciay committed
61
62
  // LibItsPki
  import from LibItsPki_Templates all;
Yann Garcia's avatar
Yann Garcia committed
63
  import from LibItsPki_Functions all;
garciay's avatar
garciay committed
64
  import from LibItsPki_TestSystem all;
garciay's avatar
garciay committed
65
  import from LibItsPki_Pics all;
66
  import from LibItsPki_Pixits all;
garciay's avatar
garciay committed
67
  
garciay's avatar
garciay committed
68
69
70
71
72
73
  /**
   * @desc 5.2	ITS-S behaviour
   */
  group itss_behavior {

    group itss_manufacturing {
Yann Garcia's avatar
Yann Garcia committed
74
      
garciay's avatar
garciay committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
      /**
       * @desc Check that IUT sends an enrolment request when triggered.
       * <pre>
       * Pics Selection: 
       * Initial conditions: 
       *     with {
       *         the IUT being in the "initial state"
       *     }
       * Expected behaviour:
       *     ensure that {
       *         when {
       *             the IUT is triggered to requested a new Enrolment Certificate (EC)
       *         }
       *         then {
       *             the IUT sends to EA an EnrolmentRequestMessage
       *         }
       *     }
       * </pre>
       * 
       * @see       ETSI TS ITS-00546v006 TP 2
       * @reference ETSI TS 102 941 [2], clause 6.1.3
       */
97
      testcase TC_SEC_PKI_ITSS_ENR_BV_01() runs on ItsMtc /*system ItsPkiItssSystem*/ {
garciay's avatar
garciay committed
98
        // Local variables
99
        var Oct32      v_private_key;
Yann Garcia's avatar
Yann Garcia committed
100
101
102
103
        var Oct32      v_public_key_x;
        var Oct32      v_public_key_y;
        var Oct32      v_public_compressed_key;
        var integer    v_compressed_mode;
Yann Garcia's avatar
Yann Garcia committed
104
        var ItsPkiItss v_itss;
Yann Garcia's avatar
Yann Garcia committed
105
        var ItsPkiHttp v_ea;
Yann Garcia's avatar
Yann Garcia committed
106
        
garciay's avatar
garciay committed
107
108
109
110
111
112
        // Test control
        if (not PICS_IUT_ITS_S_ROLE) {
          log("*** " & testcasename() & ": PICS_IUT_ITS_S_ROLE required for executing the TC ***");
          setverdict(inconc);
          stop;
        }
113
        
garciay's avatar
garciay committed
114
        // Test component configuration
Yann Garcia's avatar
Yann Garcia committed
115
        
Yann Garcia's avatar
Yann Garcia committed
116
        if (f_generate_key_pair_nistp256(v_private_key, v_public_key_x, v_public_key_y, v_public_compressed_key, v_compressed_mode) == false) {
117
118
119
120
          log("*** " & testcasename() & ": FAIL: Failed to setup InnerEcRequest message ***")
          setverdict(inconc);
          stop;
        }
Yann Garcia's avatar
Yann Garcia committed
121
122
        v_itss.start(f_TC_SEC_PKI_ITSS_ENR_BV_01_itss(cc_taCert_A, v_private_key, v_public_compressed_key, v_compressed_mode));
        v_ea.start(f_TC_SEC_PKI_ITSS_ENR_BV_01_pki(cc_taCert_A, v_private_key, v_public_compressed_key, v_compressed_mode));
Yann Garcia's avatar
Yann Garcia committed
123
124
125
        
        // Synchronization
        f_serverSync2ClientsAndStop({c_prDone, c_tbDone, c_poDone});
garciay's avatar
garciay committed
126
        
Yann Garcia's avatar
Yann Garcia committed
127
        // Cleanup
garciay's avatar
garciay committed
128
129
130
        
      } // End of testcase TC_SEC_PKI_ITSS_ENR_BV_01
      
Yann Garcia's avatar
Yann Garcia committed
131
132
      group f_TC_SEC_PKI_ITSS_ENR_BV_01 {
        
133
        function f_TC_SEC_PKI_ITSS_ENR_BV_01_itss(
garciay's avatar
garciay committed
134
135
136
                                                  in charstring p_certificate_id,
                                                  in octetstring p_private_key,
                                                  in octetstring p_publicKeyCompressed,
Yann Garcia's avatar
Yann Garcia committed
137
                                                  in integer p_compressed_mode
garciay's avatar
garciay committed
138
                                                  ) runs on ItsPkiItss /*system ItsPkiItssSystem*/ {
garciay's avatar
garciay committed
139
          // Local variables
140
          
garciay's avatar
garciay committed
141
142
          // Test component configuration
          f_cfUp_itss();
143
          
garciay's avatar
garciay committed
144
          // Test adapter configuration
145
          
garciay's avatar
garciay committed
146
          // Preamble
Yann Garcia's avatar
Yann Garcia committed
147
          f_sendUtTriggerPrimitive(PICS_ITS_S_CANONICAL_ID, '00'O, p_private_key, p_publicKeyCompressed, p_compressed_mode);
Yann Garcia's avatar
Yann Garcia committed
148
          f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
149
          
garciay's avatar
garciay committed
150
          // Test Body
Yann Garcia's avatar
Yann Garcia committed
151
152
          f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
          
garciay's avatar
garciay committed
153
154
          // Postamble
          f_cfDown_itss();
Yann Garcia's avatar
Yann Garcia committed
155
        } // End of function f_TC_SEC_PKI_ITSS_ENR_BV_01_itss
Yann Garcia's avatar
Yann Garcia committed
156
        
157
158
159
160
        function f_TC_SEC_PKI_ITSS_ENR_BV_01_pki(
                                                 in charstring p_certificate_id,
                                                 in octetstring p_private_key,
                                                 in octetstring p_publicKeyCompressed,
Yann Garcia's avatar
Yann Garcia committed
161
                                                 in integer p_compressed_mode
Yann Garcia's avatar
Yann Garcia committed
162
163
164
165
166
                                                 ) runs on ItsPkiHttp /*system ItsPkiHttpSystem*/ {
          // Local variable
          var HttpMessage v_response;
          var EtsiTs102941Data v_etsi_ts_102941_data;
          var InnerEcRequest v_inner_ec_request;
167
168
          
          // Test component configuration
Yann Garcia's avatar
Yann Garcia committed
169
          f_cfHttpUp();
Yann Garcia's avatar
Yann Garcia committed
170
          
171
172
          // Test adapter configuration
          
173
          // Preamble
Yann Garcia's avatar
Yann Garcia committed
174
          f_selfOrClientSyncAndVerdictTestBody(c_prDone, e_success);
Yann Garcia's avatar
Yann Garcia committed
175
176
          
          // Test Body
177
178
          tc_ac.start;
          alt {
Yann Garcia's avatar
Yann Garcia committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
            [] httpPort.receive(
                                mw_http_response(
                                                 mw_http_response_ok(
                                                                     mw_http_message_body_binary(
                                                                                                 mw_binary_body_ieee1609dot2_data(
                                                                                                                                  mw_enrolmentRequestMessage(
                                                                                                                                                             mw_encryptedData(
                                                                                                                                                                              -,
                                                                                                                                                                              mw_SymmetricCiphertext_aes128ccm
                                                                                                                                                                              ))))))) -> value v_response {
              tc_ac.stop;
              
              /*if (f_verify_pki_message(vc_eaPrivateEncKey, int2oct(0, 32), vc_eaCertificate, v_response.response.body.binary_body.ieee1609dot2_data, false, v_etsi_ts_102941_data) == false) {
                log("*** " & testcasename() & ": FAIL: Failed to verify PKI message ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
              } else {
                log("*** " & testcasename() & ": LOG: Receive ", v_etsi_ts_102941_data, " ***");
                log("*** " & testcasename() & ": DEBUG: match ", match(v_etsi_ts_102941_data.content, mw_enrolmentRequest(mw_innerEcRequestSignedForPop(mw_signedData))), " ***"); // TODO In TITAN, this is the only way to get the unmatching in log
                if (match(v_etsi_ts_102941_data.content, mw_enrolmentRequest(mw_innerEcRequestSignedForPop(mw_signedData)))) {
                  // TODO Verify signature of mw_innerEcRequestSignedForPop
                  log("*** " & testcasename() & ": PASS: InnerEcRequestSignedForPop received ***");
                  f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                } else {
                  log("*** " & testcasename() & ": FAIL: Unexpected message received ***");
                  f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                }
                }*/
206
207
208
            }
            [] tc_ac.timeout {
              log("*** " & testcasename() & ": INCONC: Expected message not received ***");
Yann Garcia's avatar
Yann Garcia committed
209
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
210
211
212
213
            }
          } // End of 'alt' statement
          
          // Postamble
Yann Garcia's avatar
Yann Garcia committed
214
          f_cfHttpDown();
Yann Garcia's avatar
Yann Garcia committed
215
        } // End of function f_TC_SEC_PKI_ITSS_ENR_BV_01_pki
Yann Garcia's avatar
Yann Garcia committed
216
        
Yann Garcia's avatar
Yann Garcia committed
217
      } // End of group f_TC_SEC_PKI_ITSS_ENR_BV_01
218
      
garciay's avatar
garciay committed
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
      /**
       * @desc If the enrolment request of the IUT is an initial enrolment request, the itsId 
       *       (contained in the InnerECRequest) shall be set to the canonical identifier, the 
       *       signer (contained in the outer EtsiTs1030971Data-Signed) shall be set to self and 
       *       the outer signature shall be computed using the canonical private key.
       * <pre>
       * Pics Selection: 
       * Expected behaviour:
       *     ensure that {
       *         when {
       *             the IUT is requested to send an EnrolmentRequestMessage
       *         }
       *         then {
       *             the IUT sends an EtsiTs103097Data-Encrypted
       *                 containing an encrypted EtsiTs103097Data-Signed
       *                     containing EtsiTs103097Data
       *                          containing InnerECRequestSignedForPOP
       *                             containing InnerEcRequest
       *                                 containing itsId
       *                                     indicating the canonical identifier of the ITS-S 
       *                 and containing signer
       *                     declared as self
       *                 and containing signature 
       *                     computed using the canonical private key
       *         }
       *     }
       * </pre>
       * 
       * @see       ETSI TS ITS-00546v006 TP 3
       * @reference ETSI TS 102 941, clause 6.1.3
       */
250
      testcase TC_SEC_PKI_ITSS_ENR_BV_02() runs on ItsMtc /*system ItsPkiItssSystem*/ {
251
252
        // Local variables
        var Oct32      v_private_key;
Yann Garcia's avatar
Yann Garcia committed
253
254
255
256
        var Oct32      v_public_key_x;
        var Oct32      v_public_key_y;
        var Oct32      v_public_compressed_key;
        var integer    v_compressed_mode;
257
258
        var ItsPkiItss v_itss;
        var ItsPkiHttp v_ea;
garciay's avatar
garciay committed
259
        
260
261
262
263
264
265
266
267
268
        // Test control
        if (not PICS_IUT_ITS_S_ROLE) {
          log("*** " & testcasename() & ": PICS_IUT_ITS_S_ROLE required for executing the TC ***");
          setverdict(inconc);
          stop;
        }
        
        // Test component configuration
        
Yann Garcia's avatar
Yann Garcia committed
269
        if (f_generate_key_pair_nistp256(v_private_key, v_public_key_x, v_public_key_y, v_public_compressed_key, v_compressed_mode) == false) {
270
271
272
273
          log("*** " & testcasename() & ": FAIL: Failed to setup InnerEcRequest message ***")
          setverdict(inconc);
          stop;
        }
Yann Garcia's avatar
Yann Garcia committed
274
275
        v_itss.start(f_TC_SEC_PKI_ITSS_ENR_BV_02_itss(cc_taCert_A, v_private_key, v_public_compressed_key, v_compressed_mode));
        v_ea.start(f_TC_SEC_PKI_ITSS_ENR_BV_02_pki(cc_taCert_A, v_private_key, v_public_compressed_key, v_compressed_mode));
276
277
278
279
280
281
282
283
284
285
286
287
288
289
        
        // Synchronization
        f_serverSync2ClientsAndStop({c_prDone, c_tbDone, c_poDone});
        
        // Cleanup
        
      } // End of TC_SEC_PKI_ITSS_ENR_BV_02
      
      group f_TC_SEC_PKI_ITSS_ENR_BV_02 {
        
        function f_TC_SEC_PKI_ITSS_ENR_BV_02_itss(
                                                  in charstring p_certificate_id,
                                                  in octetstring p_private_key,
                                                  in octetstring p_publicKeyCompressed,
Yann Garcia's avatar
Yann Garcia committed
290
                                                  in integer p_compressed_mode
291
                                                  ) runs on ItsPkiItss /*system ItsPkiItssSystem*/ {
292
293
294
295
296
297
298
299
          // Local variables
          
          // Test component configuration
          f_cfUp_itss();
          
          // Test adapter configuration
          
          // Preamble
Yann Garcia's avatar
Yann Garcia committed
300
          f_sendUtTriggerPrimitive(PICS_ITS_S_CANONICAL_ID, '00'O, p_private_key, p_publicKeyCompressed, p_compressed_mode);
Yann Garcia's avatar
Yann Garcia committed
301
          f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
302
303
304
305
306
307
          
          // Test Body
          f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
          
          // Postamble
          f_cfDown_itss();
Yann Garcia's avatar
Yann Garcia committed
308
        } // End of function f_TC_SEC_PKI_ITSS_ENR_BV_02_itss
309
310
311
312
313
        
        function f_TC_SEC_PKI_ITSS_ENR_BV_02_pki(
                                                 in charstring p_certificate_id,
                                                 in octetstring p_private_key,
                                                 in octetstring p_publicKeyCompressed,
Yann Garcia's avatar
Yann Garcia committed
314
                                                 in integer p_compressed_mode
Yann Garcia's avatar
Yann Garcia committed
315
                                                 ) runs on ItsPkiHttp /*system ItsPkiHttpSystem*/ {
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
          // Local variable
          var HttpMessage v_response;
          var EtsiTs102941Data v_etsi_ts_102941_data;
          var InnerEcRequest v_inner_ec_request;
          
          // Test component configuration
          f_cfHttpUp();
          
          // Test adapter configuration
          
          // Preamble
          f_selfOrClientSyncAndVerdictTestBody(c_prDone, e_success);
          
          // Test Body
          tc_ac.start;
          alt {
            [] httpPort.receive(
                                mw_http_response(
                                                 mw_http_response_ok(
                                                                     mw_http_message_body_binary(
                                                                                                 mw_binary_body_ieee1609dot2_data(
                                                                                                                                  mw_enrolmentRequestMessage(
                                                                                                                                                             mw_encryptedData(
                                                                                                                                                                              -,
                                                                                                                                                                              mw_SymmetricCiphertext_aes128ccm
                                                                                                                                                                              ))))))) -> value v_response {
              tc_ac.stop;
              
344
              /*if (f_verify_pki_message(vc_eaPrivateEncKey, int2oct(0, 32), vc_eaCertificate, v_response.response.body.binary_body.ieee1609dot2_data, false, v_etsi_ts_102941_data) == false) {
345
346
347
348
                log("*** " & testcasename() & ": FAIL: Failed to verify PKI message ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
              } else {
                log("*** " & testcasename() & ": LOG: Receive ", v_etsi_ts_102941_data, " ***");
349
                log("*** " & testcasename() & ": DEBUG: match ", match(v_etsi_ts_102941_data.content, mw_enrolmentRequest(mw_innerEcRequestSignedForPop(mw_signedData))), " ***"); // TODO In TITAN, this is the only way to get the unmatching in log
350
351
352
353
354
355
356
357
                if (match(v_etsi_ts_102941_data.content, mw_enrolmentRequest(mw_innerEcRequestSignedForPop(mw_signedData)))) {
                  // TODO Verify signature of mw_innerEcRequestSignedForPop
                  log("*** " & testcasename() & ": PASS: InnerEcRequestSignedForPop received ***");
                  f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                } else {
                  log("*** " & testcasename() & ": FAIL: Unexpected message received ***");
                  f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                }
358
                }*/
359
360
361
362
363
364
365
366
367
            }
            [] tc_ac.timeout {
              log("*** " & testcasename() & ": INCONC: Expected message not received ***");
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
            }
          } // End of 'alt' statement
          
          // Postamble
          f_cfHttpDown();
Yann Garcia's avatar
Yann Garcia committed
368
        } // End of function f_TC_SEC_PKI_ITSS_ENR_BV_02_pki
369
        
370
371
      } // End of f_TC_SEC_PKI_ITSS_ENR_BV_02
      
garciay's avatar
garciay committed
372
373
374
    } // End of group itss_manufacturing
    
  } // End of group itss_behavior
Yann Garcia's avatar
Yann Garcia committed
375
  
garciay's avatar
garciay committed
376
  group ea_behavior {
garciay's avatar
garciay committed
377
378

    group enrolment_request_handling {
garciay's avatar
garciay committed
379
      
garciay's avatar
garciay committed
380
      /**
Yann Garcia's avatar
Yann Garcia committed
381
       * @desc The EnrolmentResponse message shall be sent by the EA to the  ITS-S across the interface at reference point S3 in response 
garciay's avatar
garciay committed
382
383
       *       to a received EnrolmentRequest message.
       * <pre>
garciay's avatar
garciay committed
384
       * Pics Selection: PICS_IUT_EA_ROLE
garciay's avatar
garciay committed
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
       * Initial conditions: 
       *     with {
       *         the IUT being in the "operational state"
       *     }
       * Expected behaviour:
       *     ensure that {
       *         when {
       *             the IUT receives an EnrolmentRequestMessage across the interface at the reference point S3
       *         }
       *         then {
       *             the IUT answers with an EnrolmentResponseMessage across the interface at reference point S3
       *         }
       *     }
       * </pre>
       * 
       * @see       ETSI TS ITS-00546v006 TP 20
       * @reference ETSI TS 102 941, clause 6.2.3.2.2
       */
Yann Garcia's avatar
Yann Garcia committed
403
      testcase TC_SEC_PKI_SND_EA_BV_01() runs on ItsPkiHttp system ItsPkiHttpSystem {
garciay's avatar
garciay committed
404
405
        // Local variables
        var Oct32 v_private_key;
Yann Garcia's avatar
Yann Garcia committed
406
407
        var Oct32 v_public_compressed_key;
        var integer v_compressed_mode;
408
        var Oct32 v_request_hash;
Yann Garcia's avatar
Yann Garcia committed
409
410
411
412
413
414
415
416
417
        var Oct16 v_encrypted_sym_key;
        var Oct16 v_aes_sym_key;
        var Oct16 v_authentication_vector;
        var Oct12 v_nonce;
        var octetstring v_salt;
        var Ieee1609Dot2Data v_ieee1609dot2_signed_and_encrypted_data;
        var HeaderLines v_headers;
        var HttpMessage v_response;
        var EtsiTs102941Data v_etsi_ts_102941_data;
garciay's avatar
garciay committed
418
419
420
421
422
423
        
        // Test control
        if (not PICS_IUT_EA_ROLE) {
          log("*** " & testcasename() & ": PICS_IUT_EA_ROLE required for executing the TC ***");
          setverdict(inconc);
          stop;
Yann Garcia's avatar
Yann Garcia committed
424
        }
garciay's avatar
garciay committed
425
426
        
        // Test component configuration
427
        f_cfHttpUp(PICS_TS_EA_CERTIFICATE_ID);
garciay's avatar
garciay committed
428
429
430
431
        
        // Test adapter configuration
        
        // Preamble
Yann Garcia's avatar
Yann Garcia committed
432
        f_http_build_inner_ec_request(v_private_key, v_public_compressed_key, v_compressed_mode, v_aes_sym_key, v_encrypted_sym_key, v_authentication_vector, v_nonce, v_salt, v_ieee1609dot2_signed_and_encrypted_data, v_request_hash);
433
        f_init_default_headers_list(-, "inner_ec_request", v_headers);
garciay's avatar
garciay committed
434
435
436
        f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
        
        // Test Body
Yann Garcia's avatar
Yann Garcia committed
437
438
439
        httpPort.send(
                      m_http_request(
                                     m_http_request_post(
440
                                                         PICS_HTTP_POST_URI,
Yann Garcia's avatar
Yann Garcia committed
441
442
443
444
445
                                                         v_headers,
                                                         m_http_message_body_binary(
                                                                                    m_binary_body_ieee1609dot2_data(
                                                                                                                    v_ieee1609dot2_signed_and_encrypted_data
                                                                                                                    )))));
garciay's avatar
garciay committed
446
447
        tc_ac.start;
        alt {
Yann Garcia's avatar
Yann Garcia committed
448
449
450
451
452
453
454
455
456
457
          [] httpPort.receive(
                              mw_http_response(
                                               mw_http_response_ok(
                                                                   mw_http_message_body_binary(
                                                                                               mw_binary_body_ieee1609dot2_data(
                                                                                                                                mw_enrolmentResponseMessage(
                                                                                                                                                            mw_encryptedData(
                                                                                                                                                                             -,
                                                                                                                                                                             mw_SymmetricCiphertext_aes128ccm
                                                                                                                                                                             ))))))) -> value v_response {
garciay's avatar
garciay committed
458
            tc_ac.stop;
Yann Garcia's avatar
Yann Garcia committed
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475

            if (f_verify_pki_message(v_private_key, v_aes_sym_key, v_authentication_vector, vc_eaWholeHash, vc_eaCertificate, v_response.response.body.binary_body.ieee1609dot2_data, false, v_etsi_ts_102941_data) == false) {
              log("*** " & testcasename() & ": FAIL: Failed to verify PKI message ***");
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
            } else {
              log("*** " & testcasename() & ": PASS: InnerEcResponse received ***");
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
            }
          }
          [] httpPort.receive(
                              mw_http_response(
                                               mw_http_response_ko
                                               )) {
            tc_ac.stop;
            
            log("*** " & testcasename() & ": FAIL: Unexpected message received ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
garciay's avatar
garciay committed
476
477
478
479
480
481
          }
          [] tc_ac.timeout {
            log("*** " & testcasename() & ": INCONC: Expected message not received ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
          }
        } // End of 'alt' statement
482
        
garciay's avatar
garciay committed
483
        // Postamble
Yann Garcia's avatar
Yann Garcia committed
484
        f_cfHttpDown();
485
        
garciay's avatar
garciay committed
486
      } // End of testcase TC_SEC_PKI_SND_EA_BV_01
487
      
garciay's avatar
garciay committed
488
    } // End of group enrolment_request_handling
489
    
garciay's avatar
garciay committed
490
491
492
493
494
495
496
    group enrolment_response {
      
      /**
       * @desc The EnrolmentResponse message shall be encrypted using an ETSI TS 103 097 approved 
       *       algorithm and the encryption shall be done with the same AES key as the one used 
       *       by the ITS-S requestor for the encryption of the EnrolmentRequest message
       * <pre>
garciay's avatar
garciay committed
497
       * Pics Selection: PICS_IUT_EA_ROLE
garciay's avatar
garciay committed
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
       * Expected behaviour:
       *     ensure that {
       *         when {
       *             the IUT receives an EnrolmentRequestMessage
       *                 containing encKey
       *                     containing an encrypted AES key (SYMKEY)
       *         }
       *         then {
       *             the IUT answers with an EnrolmentResponseMessage
       *                 containing cipherTex
       *                     being encrypted
       *                         using SYMKEY
       *                         and using an ETSI TS 103 097 approved algorithm
       *         }
       *     }
       * </pre>
       * 
       * @see       ETSI TS ITS-00546v006 TP 22
       * @reference ETSI TS 102 941, clause 6.2.3.2.2
       */
      testcase TC_SEC_PKI_SND_EA_BV_02() runs on ItsPkiHttp system ItsPkiHttpSystem {
        // Local variables
        var Oct32 v_private_key;
Yann Garcia's avatar
Yann Garcia committed
521
522
        var Oct32 v_public_compressed_key;
        var integer v_compressed_mode;
523
        var Oct32 v_request_hash;
524
525
526
527
528
        var Oct16 v_encrypted_sym_key;
        var Oct16 v_aes_sym_key;
        var Oct16 v_authentication_vector;
        var Oct12 v_nonce;
        var octetstring v_salt;
garciay's avatar
garciay committed
529
530
531
532
        var Ieee1609Dot2Data v_ieee1609dot2_signed_and_encrypted_data;
        var HeaderLines v_headers;
        var HttpMessage v_response;
        var EtsiTs102941Data v_etsi_ts_102941_data;
533
        
garciay's avatar
garciay committed
534
535
536
537
538
539
        // Test control
        if (not PICS_IUT_EA_ROLE) {
          log("*** " & testcasename() & ": PICS_IUT_EA_ROLE required for executing the TC ***");
          setverdict(inconc);
          stop;
        }
540
        
garciay's avatar
garciay committed
541
        // Test component configuration
542
        f_cfHttpUp(PICS_TS_EA_CERTIFICATE_ID);
543
        
garciay's avatar
garciay committed
544
        // Test adapter configuration
545
        
garciay's avatar
garciay committed
546
        // Preamble
Yann Garcia's avatar
Yann Garcia committed
547
        f_http_build_inner_ec_request(v_private_key, v_public_compressed_key, v_compressed_mode, v_aes_sym_key, v_encrypted_sym_key, v_authentication_vector, v_nonce, v_salt, v_ieee1609dot2_signed_and_encrypted_data, v_request_hash);
548
        f_init_default_headers_list(-, "inner_ec_request", v_headers);
garciay's avatar
garciay committed
549
        f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
550
        
garciay's avatar
garciay committed
551
552
553
        // Test Body
        httpPort.send(
                      m_http_request(
garciay's avatar
garciay committed
554
                                     m_http_request_post(
555
                                                         PICS_HTTP_POST_URI,
garciay's avatar
garciay committed
556
557
558
559
560
                                                         v_headers,
                                                         m_http_message_body_binary(
                                                                                    m_binary_body_ieee1609dot2_data(
                                                                                                                    v_ieee1609dot2_signed_and_encrypted_data
                                                                                                                    )))));
garciay's avatar
garciay committed
561
562
563
564
565
566
567
568
569
570
571
572
573
        tc_ac.start;
        alt {
          [] httpPort.receive(
                              mw_http_response(
                                               mw_http_response_ok(
                                                                   mw_http_message_body_binary(
                                                                                               mw_binary_body_ieee1609dot2_data(
                                                                                                                                mw_enrolmentResponseMessage(
                                                                                                                                                            mw_encryptedData(
                                                                                                                                                                             -,
                                                                                                                                                                             mw_SymmetricCiphertext_aes128ccm
                                                                                                                                                                             ))))))) -> value v_response {
            tc_ac.stop;
574

Yann Garcia's avatar
Yann Garcia committed
575
            if (f_verify_pki_message(v_private_key, v_aes_sym_key, v_authentication_vector, vc_eaWholeHash, vc_eaCertificate, v_response.response.body.binary_body.ieee1609dot2_data, false, v_etsi_ts_102941_data) == false) {
garciay's avatar
garciay committed
576
              log("*** " & testcasename() & ": FAIL: Failed to verify PKI message ***");
577
578
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
            } else {
garciay's avatar
garciay committed
579
              log("*** " & testcasename() & ": LOG: Receive ", v_etsi_ts_102941_data, " ***");
580
581
              log("*** " & testcasename() & ": DEBUG: match ", match(v_etsi_ts_102941_data.content, mw_enrolmentResponse(mw_innerEcResponse_ok(substr(v_request_hash, 0, 16)))), " ***"); // TODO In TITAN, this is the only way to get the unmatching in log
              if (match(v_etsi_ts_102941_data.content, mw_enrolmentResponse(mw_innerEcResponse_ok(substr(v_request_hash, 0, 16))))) {
garciay's avatar
garciay committed
582
583
                log("*** " & testcasename() & ": PASS: InnerEcResponse received ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
584
585
586
              } else {
                log("*** " & testcasename() & ": FAIL: Unexpected message received ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
garciay's avatar
garciay committed
587
              }
588
589
            }
          }
garciay's avatar
garciay committed
590
591
592
593
594
595
596
597
598
          [] httpPort.receive(
                              mw_http_response(
                                               mw_http_response_ko
                                               )) {
            tc_ac.stop;
            
            log("*** " & testcasename() & ": FAIL: Unexpected message received ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
          }
garciay's avatar
garciay committed
599
600
601
602
603
          [] tc_ac.timeout {
            log("*** " & testcasename() & ": INCONC: Expected message not received ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
          }
        } // End of 'alt' statement
604
    
garciay's avatar
garciay committed
605
606
        // Postamble
        f_cfHttpDown();
607
    
garciay's avatar
garciay committed
608
      } // End of testcase TC_SEC_PKI_SND_EA_BV_02
609
    
garciay's avatar
garciay committed
610
611
612
613
614
615
616
617
      /**
       * @desc The outermost structure is an EtsiTs103097Data-Encrypted structure containing 
       *       the component recipients containing one instance of RecipientInfo of choice 
       *       pskRecipInfo, which contains the HashedId8 of the symmetric key used by the 
       *       ITS-S to encrypt the EnrolmentRequest message to which the response is built 
       *       and containing the component ciphertext, once decrypted, contains an 
       *       EtsiTs103097Data-Signed structure
       * <pre>
garciay's avatar
garciay committed
618
       * Pics Selection: PICS_IUT_EA_ROLE
garciay's avatar
garciay committed
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
       * Expected behaviour:
       *     ensure that {
       *         when {
       *             the IUT receives an EnrolmentRequestMessage
       *         }
       *         then {
       *             the IUT sends an EtsiTs103097Data-Encrypted structure
       *                 containing recipients
       *                     containing one instance of RecipientInfo of choice pskRecipInfo
       *                         containing the HashedId8 of the symmetric key used to encrypt the EnrolmentRequestMessage
       *                 and containing cipherText
       *                     being an encrypted EtsiTs103097Data-Signed structure
       *         }
       *     }
       * </pre>
       * 
       * @see       ETSI TS ITS-00546v006 TP 24
       * @reference ETSI TS 102 941, clause 6.2.3.2.2
       */
      testcase TC_SEC_PKI_SND_EA_BV_03() runs on ItsPkiHttp system ItsPkiHttpSystem {
        // Local variables
        var Oct32 v_private_key;
Yann Garcia's avatar
Yann Garcia committed
641
642
        var Oct32 v_public_compressed_key;
        var integer v_compressed_mode;
643
        var Oct32 v_request_hash;
garciay's avatar
garciay committed
644
        var Ieee1609Dot2Data v_ieee1609dot2_signed_and_encrypted_data;
645
646
647
648
649
        var Oct16 v_aes_sym_key;
        var Oct16 v_encrypted_sym_key;
        var Oct16 v_authentication_vector;
        var Oct12 v_nonce;
        var octetstring v_salt;
garciay's avatar
garciay committed
650
651
652
        var HeaderLines v_headers;
        var HttpMessage v_response;
        var EtsiTs102941Data v_etsi_ts_102941_data;
653
        
garciay's avatar
garciay committed
654
655
656
657
658
659
        // Test control
        if (not PICS_IUT_EA_ROLE) {
          log("*** " & testcasename() & ": PICS_IUT_EA_ROLE required for executing the TC ***");
          setverdict(inconc);
          stop;
        }
660
        
garciay's avatar
garciay committed
661
        // Test component configuration
662
        f_cfHttpUp(PICS_TS_EA_CERTIFICATE_ID);
663
        
garciay's avatar
garciay committed
664
        // Test adapter configuration
665
        
garciay's avatar
garciay committed
666
        // Preamble
Yann Garcia's avatar
Yann Garcia committed
667
        f_http_build_inner_ec_request(v_private_key, v_public_compressed_key, v_compressed_mode, v_aes_sym_key, v_encrypted_sym_key, v_authentication_vector, v_nonce, v_salt, v_ieee1609dot2_signed_and_encrypted_data, v_request_hash);
668
        f_init_default_headers_list(-, "inner_ec_request", v_headers);
garciay's avatar
garciay committed
669
670
        httpPort.send(
                      m_http_request(
garciay's avatar
garciay committed
671
                                     m_http_request_post(
672
                                                         PICS_HTTP_POST_URI,
garciay's avatar
garciay committed
673
674
675
676
677
                                                         v_headers,
                                                         m_http_message_body_binary(
                                                                                    m_binary_body_ieee1609dot2_data(
                                                                                                                    v_ieee1609dot2_signed_and_encrypted_data
                                                                                                                    )))));
garciay's avatar
garciay committed
678
        f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
garciay's avatar
garciay committed
679
        
garciay's avatar
garciay committed
680
681
682
683
684
685
686
687
688
689
690
691
692
693
        // Test Body
        tc_ac.start;
        alt {
          [] httpPort.receive(
                              mw_http_response(
                                               mw_http_response_ok(
                                                                   mw_http_message_body_binary(
                                                                                               mw_binary_body_ieee1609dot2_data(
                                                                                                                                mw_enrolmentResponseMessage(
                                                                                                                                                            mw_encryptedData(
                                                                                                                                                                             -,
                                                                                                                                                                             mw_SymmetricCiphertext_aes128ccm
                                                                                                                                                                             ))))))) -> value v_response {
            tc_ac.stop;
694
            
695
            if (f_verify_pki_message(v_private_key, v_aes_sym_key, v_authentication_vector, vc_eaWholeHash, vc_eaCertificate, v_response.response.body.binary_body.ieee1609dot2_data, true, v_etsi_ts_102941_data) == false) {
garciay's avatar
garciay committed
696
              log("*** " & testcasename() & ": FAIL: Failed to verify PKI message ***");
697
698
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
            } else {
garciay's avatar
garciay committed
699
              log("*** " & testcasename() & ": LOG: Receive ", v_etsi_ts_102941_data, " ***");
700
701
              log("*** " & testcasename() & ": DEBUG: match ", match(v_etsi_ts_102941_data.content, mw_enrolmentResponse(mw_innerEcResponse_ok(substr(v_request_hash, 0, 16)))), " ***"); // TODO In TITAN, this is the only way to get the unmatching in log
              if (match(v_etsi_ts_102941_data.content, mw_enrolmentResponse(mw_innerEcResponse_ok(substr(v_request_hash, 0, 16))))) {
garciay's avatar
garciay committed
702
703
                log("*** " & testcasename() & ": PASS: InnerEcResponse received ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
704
705
706
              } else {
                log("*** " & testcasename() & ": FAIL: Unexpected message received ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
garciay's avatar
garciay committed
707
              }
708
            }
709
          }
710
711
712
713
714
715
716
717
718
719
          [] tc_ac.timeout {
            log("*** " & testcasename() & ": INCONC: Expected message not received ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
          }
        } // End of 'alt' statement
        
        // Postamble
        f_cfHttpDown();
        
      } // End of testcase TC_SEC_PKI_SND_EA_BV_03
720
      
721
722
723
724
725
726
727
      /**
       * @desc If the ITS-S has been able to decrypt the content, this expected EtsiTs103097Data-Signed structure shall 
       *       contain hashId, tbsData, signer and signature. The hashId shall indicate the hash algorithm to be used as 
       *       specified in ETSI TS 103 097, the signer shall be declared as a digest, containing the HashedId8 of the 
       *       EA certificate and the signature over tbsData shall be computed using the EA private key corresponding to 
       *       its publicVerificationKey found in the referenced EA certificate.
       * <pre>
garciay's avatar
garciay committed
728
       * Pics Selection: PICS_IUT_EA_ROLE
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
       * Expected behaviour:
       *     ensure that {
       *         when {
       *             the IUT receives an EnrolmentRequestMessage
       *         }
       *         then {
       *             the IUT sends an EtsiTs103097Data-Encrypted structure
       *                 containing an encrypted EtsiTs103097Data-Signed structure
       *                     containing hashId
       *                        indicating the hash algorithm to be used as specified in ETSI TS 103 097
       *                     and containing tbsData
       *                     and containing signer
       *                         declared as a digest
       *                             containing the HashedId8 of the EA certificate
       *                     and containing signature
       *                         computed over tbsData
       *                             using the EA private key
       *                                 corresponding to the publicVerificationKey found in the referenced EA certificate
       *         }
       *     }
       * </pre>
       * 
       * @see       ETSI TS ITS-00546v006 TP 25
       * @reference ETSI TS 102 941, clause 6.2.3.2.2
       */
      testcase TC_SEC_PKI_SND_EA_BV_04() runs on ItsPkiHttp system ItsPkiHttpSystem {
        // Local variables
        var Oct32 v_private_key;
Yann Garcia's avatar
Yann Garcia committed
757
758
        var Oct32 v_public_compressed_key;
        var integer v_compressed_mode;
759
        var Oct32 v_request_hash;
760
        var Ieee1609Dot2Data v_ieee1609dot2_signed_and_encrypted_data;
761
762
763
764
765
        var Oct16 v_aes_sym_key;
        var Oct16 v_encrypted_sym_key;
        var Oct16 v_authentication_vector;
        var Oct12 v_nonce;
        var octetstring v_salt;
766
767
768
769
770
771
772
773
774
775
776
777
        var HeaderLines v_headers;
        var HttpMessage v_response;
        var EtsiTs102941Data v_etsi_ts_102941_data;
      
        // Test control
        if (not PICS_IUT_EA_ROLE) {
          log("*** " & testcasename() & ": PICS_IUT_EA_ROLE required for executing the TC ***");
          setverdict(inconc);
          stop;
        }
        
        // Test component configuration
778
        f_cfHttpUp(PICS_TS_EA_CERTIFICATE_ID);
779
780
781
782
        
        // Test adapter configuration
        
        // Preamble
Yann Garcia's avatar
Yann Garcia committed
783
        f_http_build_inner_ec_request(v_private_key, v_public_compressed_key, v_compressed_mode, v_aes_sym_key, v_encrypted_sym_key, v_authentication_vector, v_nonce, v_salt, v_ieee1609dot2_signed_and_encrypted_data, v_request_hash);
784
        f_init_default_headers_list(-, "inner_ec_request", v_headers);
785
786
        httpPort.send(
                      m_http_request(
garciay's avatar
garciay committed
787
                                     m_http_request_post(
788
                                                         PICS_HTTP_POST_URI,
garciay's avatar
garciay committed
789
790
791
792
793
                                                         v_headers,
                                                         m_http_message_body_binary(
                                                                                    m_binary_body_ieee1609dot2_data(
                                                                                                                    v_ieee1609dot2_signed_and_encrypted_data
                                                                                                                    )))));
794
795
796
797
798
799
        f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
        
        // Test Body
        tc_ac.start;
        alt {
          [] httpPort.receive(
garciay's avatar
garciay committed
800
                              mw_http_response(
801
802
803
804
805
806
807
808
                                               mw_http_response_ok(
                                                                   mw_http_message_body_binary(
                                                                                               mw_binary_body_ieee1609dot2_data(
                                                                                                                                mw_enrolmentResponseMessage(
                                                                                                                                                            mw_encryptedData(
                                                                                                                                                                             -,
                                                                                                                                                                             mw_SymmetricCiphertext_aes128ccm
                                                                                                                                                                             ))))))) -> value v_response {
garciay's avatar
garciay committed
809
            tc_ac.stop;
810
            
811
            if (f_verify_pki_message(v_private_key, v_aes_sym_key, v_authentication_vector, vc_eaWholeHash, vc_eaCertificate, v_response.response.body.binary_body.ieee1609dot2_data, true, v_etsi_ts_102941_data) == false) {
812
813
814
815
              log("*** " & testcasename() & ": FAIL: Failed to verify PKI message ***");
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
            } else {
              log("*** " & testcasename() & ": LOG: Receive ", v_etsi_ts_102941_data, " ***");
816
817
              log("*** " & testcasename() & ": DEBUG: match ", match(v_etsi_ts_102941_data.content, mw_enrolmentResponse(mw_innerEcResponse_ok(substr(v_request_hash, 0, 16)))), " ***"); // TODO In TITAN, this is the only way to get the unmatching in log
              if (match(v_etsi_ts_102941_data.content, mw_enrolmentResponse(mw_innerEcResponse_ok(substr(v_request_hash, 0, 16))))) {
Yann Garcia's avatar
Yann Garcia committed
818
                if (f_verify_ec_certificate(v_etsi_ts_102941_data.content.enrolmentResponse.certificate, v_public_compressed_key, v_compressed_mode)) {
819
820
821
                  log("*** " & testcasename() & ": PASS: Well-secured EA certificate received ***");
                  f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                } else {
Yann Garcia's avatar
Yann Garcia committed
822
                  log("*** " & testcasename() & ": FAIL: Cannot verify EC certificate signature ***");
823
824
825
826
827
828
                  f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                }
              } else {
                log("*** " & testcasename() & ": FAIL: Unexpected message received ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
              }
829
            }
830
831
832
833
          }
          [] tc_ac.timeout {
            log("*** " & testcasename() & ": INCONC: Expected message not received ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
garciay's avatar
garciay committed
834
          }
835
836
837
838
839
840
841
842
        } // End of 'alt' statement
        
        // Postamble
        f_cfHttpDown();
        
      } // End of testcase TC_SEC_PKI_SND_EA_BV_04
      
      /**
Yann Garcia's avatar
Yann Garcia committed
843
       * @desc Within the headerInfo of the tbsData, the psid shall be set to “secured certificate request� as assigned in 
844
845
       *       ETSI TS 102 965 and the generationTime shall be present.
       * <pre>
garciay's avatar
garciay committed
846
       * Pics Selection: PICS_IUT_EA_ROLE
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
       * Expected behaviour:
       *     ensure that {
       *         when {
       *             the IUT receives an EnrolmentRequestMessage
       *         }
       *         then {
       *             the IUT sends an EtsiTs103097Data-Encrypted structure
       *                 containing an encrypted EtsiTs103097Data-Signed structure
       *                     containing tbsData
       *                         containing headerInfo
       *                             containing psid
       *                                 indicating AID_CERT_REQ
       *                             and containing generationTime
       *         }
       *     }
       * </pre>
       * 
       * @see       ETSI TS ITS-00546v006 TP 26
       * @reference ETSI TS 102 941, clause 6.2.3.2.2
       */
      testcase TC_SEC_PKI_SND_EA_BV_05() runs on ItsPkiHttp system ItsPkiHttpSystem {
        // Local variables
        var Oct32 v_private_key;
Yann Garcia's avatar
Yann Garcia committed
870
871
        var Oct32 v_public_compressed_key;
        var integer v_compressed_mode;
872
        var Oct32 v_request_hash;
873
        var Ieee1609Dot2Data v_ieee1609dot2_signed_and_encrypted_data;
874
875
876
877
878
        var Oct16 v_aes_sym_key;
        var Oct16 v_encrypted_sym_key;
        var Oct16 v_authentication_vector;
        var Oct12 v_nonce;
        var octetstring v_salt;
879
880
881
882
883
884
885
886
887
888
889
890
        var HeaderLines v_headers;
        var HttpMessage v_response;
        var EtsiTs102941Data v_etsi_ts_102941_data;
        
        // Test control
        if (not PICS_IUT_EA_ROLE) {
          log("*** " & testcasename() & ": PICS_IUT_EA_ROLE required for executing the TC ***");
          setverdict(inconc);
          stop;
        }
        
        // Test component configuration
891
        f_cfHttpUp(PICS_TS_EA_CERTIFICATE_ID);
892
893
894
895
        
        // Test adapter configuration
        
        // Preamble
Yann Garcia's avatar
Yann Garcia committed
896
        f_http_build_inner_ec_request(v_private_key, v_public_compressed_key, v_compressed_mode, v_aes_sym_key, v_encrypted_sym_key, v_authentication_vector, v_nonce, v_salt, v_ieee1609dot2_signed_and_encrypted_data, v_request_hash);
897
        f_init_default_headers_list(-, "inner_ec_request", v_headers);
898
899
        httpPort.send(
                      m_http_request(
garciay's avatar
garciay committed
900
                                     m_http_request_post(
901
902
903
904
905
906
                                                         PICS_HTTP_POST_URI,
                                                         v_headers,
                                                         m_http_message_body_binary(
                                                                                    m_binary_body_ieee1609dot2_data(
                                                                                                                    v_ieee1609dot2_signed_and_encrypted_data
                                                                                                                    )))));
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
        f_selfOrClientSyncAndVerdictPreamble(c_prDone, e_success);
        
        // Test Body
        tc_ac.start;
        alt {
          [] httpPort.receive(
                              mw_http_response(
                                               mw_http_response_ok(
                                                                   mw_http_message_body_binary(
                                                                                               mw_binary_body_ieee1609dot2_data(
                                                                                                                                mw_enrolmentResponseMessage(
                                                                                                                                                            mw_encryptedData(
                                                                                                                                                                             -,
                                                                                                                                                                             mw_SymmetricCiphertext_aes128ccm
                                                                                                                                                                             ))))))) -> value v_response {
garciay's avatar
garciay committed
922
            tc_ac.stop;
923
            
924
            if (f_verify_pki_message(v_private_key, v_aes_sym_key, v_authentication_vector, vc_eaWholeHash, vc_eaCertificate, v_response.response.body.binary_body.ieee1609dot2_data, true, v_etsi_ts_102941_data) == false) {
925
926
927
928
              log("*** " & testcasename() & ": FAIL: Failed to verify PKI message ***");
              f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
            } else {
              log("*** " & testcasename() & ": LOG: Receive ", v_etsi_ts_102941_data, " ***");
929
930
              log("*** " & testcasename() & ": DEBUG: match ", match(v_etsi_ts_102941_data.content, mw_enrolmentResponse(mw_innerEcResponse_ok(substr(v_request_hash, 0, 16)))), " ***"); // TODO In TITAN, this is the only way to get the unmatching in log
              if (match(v_etsi_ts_102941_data.content, mw_enrolmentResponse(mw_innerEcResponse_ok(substr(v_request_hash, 0, 16))))) {
Yann Garcia's avatar
Yann Garcia committed
931
                if (f_verify_ec_certificate(v_etsi_ts_102941_data.content.enrolmentResponse.certificate, v_public_compressed_key, v_compressed_mode)) {
932
933
934
935
936
937
938
939
940
941
                  log("*** " & testcasename() & ": PASS: Well-secured EA certificate received ***");
                  f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_success);
                } else {
                  log("*** " & testcasename() & ": FAIL: Cannot verify EA certificate signature ***");
                  f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
                }
              } else {
                log("*** " & testcasename() & ": FAIL: Unexpected message received ***");
                f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
              }
942
            }
garciay's avatar
garciay committed
943
944
945
946
947
948
949
950
951
952
          }
          [] tc_ac.timeout {
            log("*** " & testcasename() & ": INCONC: Expected message not received ***");
            f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_timeout);
          }
        } // End of 'alt' statement
        
        // Postamble
        f_cfHttpDown();
        
953
954
955
956
957
958
      } // End of testcase TC_SEC_PKI_SND_EA_BV_05
      
      /**
       * @desc Within the headerInfo of the tbsData, aside from psid and generationTime, 
       *       all other components of the component tbsData.headerInfo not used and absent.
       * <pre>
garciay's avatar
garciay committed
959
       * Pics Selection: PICS_IUT_EA_ROLE
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
       * Expected behaviour:
       *     ensure that {
       *         when {
       *             the IUT receives an EnrolmentRequestMessage
       *         }
       *         then {
       *             the IUT sends an EtsiTs103097Data-Encrypted structure
       *                 containing an encrypted EtsiTs103097Data-Signed structure
       *                     containing tbsData
       *                         containing headerInfo
       *                             containing psid
       *                             and containing generationTime
       *         }
       *     }
       * </pre>
       * 
       * @see       ETSI TS ITS-00546v006 TP 27
       * @reference ETSI TS 102 941, clause 6.2.3.2.2
       */
      testcase TC_SEC_PKI_SND_EA_BV_06() runs on ItsPkiHttp system ItsPkiHttpSystem {
        // Local variables
        var Oct32 v_private_key;
Yann Garcia's avatar
Yann Garcia committed
982
983
        var Oct32 v_public_compressed_key;
        var integer v_compressed_mode;
984
        var Oct32 v_request_hash;
985
        var Ieee1609Dot2Data v_ieee1609dot2_signed_and_encrypted_data;
986
987
988
989
990
        var Oct16 v_aes_sym_key;
        var Oct16 v_encrypted_sym_key;
        var Oct16 v_authentication_vector;
        var Oct12 v_nonce;
        var octetstring v_salt;
991
992
993
994
995
996
997
998
999
1000
        var HeaderLines v_headers;
        var HttpMessage v_response;
        var EtsiTs102941Data v_etsi_ts_102941_data;
      
        // Test control
        if (not PICS_IUT_EA_ROLE) {
          log("*** " & testcasename() & ": PICS_IUT_EA_ROLE required for executing the TC ***");
          setverdict(inconc);
          stop;
        }
For faster browsing, not all history is shown. View entire blame