Newer
Older
1
2
3
4
5
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* @author
*
* @version
* 1.0
* @desc
*
* @remark
*
* @see
*
*/
module TestCodec_SignedAndEncryptedMessages {
// LibCommon
import from LibCommon_BasicTypesAndValues all;
import from LibCommon_DataStrings all;
// LibIts
import from IEEE1609dot2BaseTypes language "ASN.1:1997" all;
import from IEEE1609dot2 language "ASN.1:1997" all;
import from EtsiTs103097Module language "ASN.1:1997" all;
// LibItsGeoNetworking
import from LibItsGeoNetworking_EncdecDeclarations all;
import from LibItsGeoNetworking_TypesAndValues all;
import from LibItsGeoNetworking_Templates all;
// LibItsSecurity
import from LibItsSecurity_EncdecDeclarations all;
import from LibItsSecurity_TypesAndValues all;
import from LibItsSecurity_Templates all;
import from LibItsSecurity_Functions all;
import from LibItsSecurity_Pixits all;
// TestCodec
import from TestCodec_TestAndSystem all;
testcase tc_encrypted_signed_message() runs on TCType system TCType {
var template (value) EtsiTs103097Data v_signed_data;
var EtsiTs103097Data v_signed_data_dec;
var octetstring v_raw_payload_to_be_signed := 'CAFFEDECA0000001'O;
var HashedId8 v_digest := '0000000000000000'O;
var template (value) EtsiTs103097Data v_encryped_data;
var EtsiTs103097Data v_encrypted_data_dec;
var bitstring v_encMsg;
var Oct32 v_obuPrivateKey, v_obuPublicKeyX, v_obuPublicKeyY;
var Oct32 v_tsPrivateKey, v_tsPublicKeyX, v_tsPublicKeyY;
var Oct32 v_publicEncKeyX;
var Oct32 v_publicEncKeyY;
var Oct16 v_tag;
var Oct16 v_ephKey;
var Opaque v_cypheredPayload;
var Oct12 v_nonce;
var HashedId8 v_recipientId;
// Simulate OCU & Test System certificate, OBU and Test system exchange their public key
f_generate_key_pair_nistp256(v_obuPrivateKey, v_obuPublicKeyX, v_obuPublicKeyY);
f_generate_key_pair_nistp256(v_tsPrivateKey, v_tsPublicKeyX, v_tsPublicKeyY);
// The OBU is the sender, the Test System is te receiver
v_signed_data := m_etsiTs103097Data_signed(
m_signedData(
sha256,
m_toBeSignedData(
m_signedDataPayload(
m_etsiTs103097Data_unsecured(v_raw_payload_to_be_signed)
),
m_headerInfo_gn(
-,
12345
)
),
{ digest := v_digest },
m_signature_ecdsaNistP256(
m_ecdsaP256Signature(
m_eccP256CurvePoint_x_only(
'08B2030104020A0D010C0105C0F80BB1460239348D17405C1A845151D4061200'O
),
'2617CF4E6B25097F03F502AD0C6F2F125974700D31A60FD1EF12040E4D8231AB'O
)
)
)
);
log("v_signed_data = ", v_signed_data);
v_encMsg := encvalue(valueof(v_signed_data));
v_cypheredPayload := f_encryptWithEciesNistp256WithSha256(bit2oct(v_encMsg), v_tsPublicKeyX, v_tsPublicKeyY, v_publicEncKeyX, v_publicEncKeyY, v_ephKey, v_tag, v_nonce);
v_recipientId := f_HashedId8FromSha256(f_hashWithSha256(bit2oct(v_encMsg))); // IEEE Std 1609.2a-2017 Clause 6.3.34 PKRecipientInfo
v_encryped_data := m_etsiTs103097Data_encrypted(
m_encryptedData(
{
m_recipientInfo_signedDataRecipInfo(
m_pKRecipientInfo(
v_recipientId,
m_encryptedDataEncryptionKey_eciesNistP256(
m_evciesP256EncryptedKey(
m_eccP256CurvePoint_uncompressed(
v_publicEncKeyX,
v_publicEncKeyY
),
v_ephKey,
v_tag
))))
},
m_SymmetricCiphertext_aes128ccm(
m_aesCcmCiphertext(
v_nonce,
v_cypheredPayload
)
)
)
);
log("v_encryped_data = ", v_encryped_data);
v_encMsg := encvalue(valueof(v_encryped_data));
setverdict(pass, "Encoding passed.");
if (decvalue(v_encMsg, v_encrypted_data_dec) != 0) {
setverdict(fail);
stop;
} else if (not(match(valueof(v_signed_data), v_encrypted_data_dec))) {
setverdict(fail);
stop;
}
setverdict(pass, "Decoding passed.");
} // End of testcase tc_encrypted_message_unsecured
} // End of module TestCodec_SignedAndEncryptedMessages