Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TTCN-3 Libraries
LibIts
Commits
b1729a03
Commit
b1729a03
authored
Feb 12, 2019
by
Yann Garcia
Browse files
Bug fixed in AtsSecurity
parent
5be823f1
Changes
3
Show whitespace changes
Inline
Side-by-side
ttcn/Pki/LibItsPki_Functions.ttcn
View file @
b1729a03
...
...
@@ -37,6 +37,8 @@ module LibItsPki_Functions {
import
from
LibItsCommon_Pixits
all
;
// LibItsGeoNetworking
import
from
LibItsGeoNetworking_TypesAndValues
all
;
import
from
LibItsGeoNetworking_TestSystem
all
;
import
from
LibItsGeoNetworking_Pixits
all
;
// LibItsSecurity
...
...
@@ -63,6 +65,18 @@ module LibItsPki_Functions {
group
pkiConfigurationFunctions
{
function
f_cfMtcUp
(
out
ItsPkiItss
p_itss
,
out
ItsPkiHttp
p_pki
)
runs
on
ItsMtc
{
p_itss
:=
ItsPkiItss
.
create
(
"IUT"
)
alive
;
p_pki
:=
ItsPkiHttp
.
create
(
"TS"
)
alive
;
connect
(
self
:
syncPort
,
mtc
:
syncPort
);
connect
(
p_itss
:
syncPort
,
self
:
syncPort
);
connect
(
p_pki
:
syncPort
,
self
:
syncPort
);
}
/**
* @desc Setups default configuration
* @param p_certificate_id The certificate identifier the TA shall use in case of secured IUT
...
...
@@ -72,7 +86,7 @@ module LibItsPki_Functions {
in
charstring
p_aa_certificate_id
:=
"CERT_TS_A_AA"
)
runs
on
ItsPkiHttp
/* TITAN TODO: system ItsPkiHttpSystem */
{
if
(
LibItsPki_Pics
.
PICS_MULTIPLE_END_POINT
==
false
)
{
if
(
PICS_MULTIPLE_END_POINT
==
false
)
{
map
(
self
:
httpPort
,
system
:
httpPort
);
}
else
{
map
(
self
:
httpEcPort
,
system
:
httpEcPort
);
...
...
@@ -85,21 +99,20 @@ module LibItsPki_Functions {
// Setup EA certificate shared with PKI EA entity
f_readCertificate
(
p_ea_certificate_id
,
vc_eaCertificate
);
// f_readSigningKey(p_ea_certificate_id, vc_eaPrivateKey); // TODO To be removed
// f_readCertificate(p_aa_certificate_id, vc_ecCertificate); // TODO To be removed
// f_readSigningKey(p_aa_certificate_id, vc_ecPrivateKey); // TODO To be removed
// f_readEncryptingKey(p_ea_certificate_id, vc_eaPrivateEncKey); // TODO To be removed
f_readSigningKey
(
p_ea_certificate_id
,
vc_eaPrivateKey
);
// TODO To be removed
f_readEncryptingKey
(
p_ea_certificate_id
,
vc_eaPrivateEncKey
);
f_getCertificateDigest
(
p_ea_certificate_id
,
vc_eaHashedId8
);
f_getCertificateHash
(
p_ea_certificate_id
,
vc_eaWholeHash
);
log
(
"f_cfHttpUp: vc_eaPrivateKey= "
,
vc_eaPrivateKey
);
log
(
"f_cfHttpUp: vc_eaHashedId8= "
,
vc_eaHashedId8
);
log
(
"f_cfHttpUp: vc_eaWholeHash= "
,
vc_eaWholeHash
);
// Setup AA certificate shared with PKI AA entity
f_readCertificate
(
p_aa_certificate_id
,
vc_aaCertificate
);
f_getCertificateDigest
(
p_aa_certificate_id
,
vc_aaHashedId8
);
f_getCertificateHash
(
p_aa_certificate_id
,
vc_aaWholeHash
);
log
(
"vc_aaHashedId8= "
,
vc_aaHashedId8
);
log
(
"vc_aaWholeHash= "
,
vc_aaWholeHash
);
// f_readCertificate(p_peerCertificateId, vc_peerEaCertificate); // TODO To be removed
// f_getCertificateHash(p_peerCertificateId, vc_eaPeerWholeHash); // TODO To be removed
log
(
"f_cfHttpUp: vc_aaHashedId8= "
,
vc_aaHashedId8
);
log
(
"f_cfHttpUp: vc_aaWholeHash= "
,
vc_aaWholeHash
);
if
(
PICS_MULTIPLE_END_POINT
==
false
)
{
activate
(
a_default_pki_http
());
...
...
@@ -123,6 +136,24 @@ module LibItsPki_Functions {
// activate(a_default_pki()); TOTO Defualt from geoNet
}
// End of function f_cfUp_itss
/**
* @desc Deletes default configuration
*/
function
f_cfMtcDown
(
inout
ItsPkiItss
p_itss
,
inout
ItsPkiHttp
p_pki
)
runs
on
ItsMtc
{
p_itss
:=
ItsPkiItss
.
create
(
"IUT"
)
alive
;
p_pki
:=
ItsPkiHttp
.
create
(
"TS"
)
alive
;
disconnect
(
self
:
syncPort
,
mtc
:
syncPort
);
disconnect
(
p_itss
:
syncPort
,
self
:
syncPort
);
disconnect
(
p_pki
:
syncPort
,
self
:
syncPort
);
p_itss
.
done
;
p_pki
.
done
;
}
/**
* @desc Deletes default configuration
*/
...
...
@@ -285,7 +316,70 @@ module LibItsPki_Functions {
}
return
''
O
;
}
// End of function f_signWithEcdsa
function
f_verifyEcdsa
(
in
octetstring
p_tbs
,
in
octetstring
p_issuer
,
in
Signature
p_signature_
,
in
PublicVerificationKey
p_verification_key
)
return
boolean
{
var
boolean
v_ret
:=
false
;
log
(
" >>> f_verifyEcdsa"
);
if
(
ischosen
(
p_verification_key
.
ecdsaNistP256
))
{
if
(
ischosen
(
p_verification_key
.
ecdsaNistP256
.
compressed_y_0
))
{
v_ret
:=
f_verifyWithEcdsaNistp256WithSha256
(
p_tbs
,
p_issuer
,
p_signature_
.
ecdsaNistP256Signature
.
rSig
.
x_only
&
p_signature_
.
ecdsaNistP256Signature
.
sSig
,
p_verification_key
.
ecdsaNistP256
.
compressed_y_0
,
0
);
}
else
{
v_ret
:=
f_verifyWithEcdsaNistp256WithSha256
(
p_tbs
,
p_issuer
,
p_signature_
.
ecdsaNistP256Signature
.
rSig
.
x_only
&
p_signature_
.
ecdsaNistP256Signature
.
sSig
,
p_verification_key
.
ecdsaNistP256
.
compressed_y_1
,
1
);
}
}
else
if
(
ischosen
(
p_verification_key
.
ecdsaBrainpoolP256r1
))
{
if
(
ischosen
(
p_verification_key
.
ecdsaBrainpoolP256r1
.
compressed_y_0
))
{
v_ret
:=
f_verifyWithEcdsaBrainpoolp256WithSha256
(
p_tbs
,
p_issuer
,
p_signature_
.
ecdsaBrainpoolP256r1Signature
.
rSig
.
x_only
&
p_signature_
.
ecdsaBrainpoolP256r1Signature
.
sSig
,
p_verification_key
.
ecdsaBrainpoolP256r1
.
compressed_y_0
,
0
);
}
else
{
v_ret
:=
f_verifyWithEcdsaBrainpoolp256WithSha256
(
p_tbs
,
p_issuer
,
p_signature_
.
ecdsaBrainpoolP256r1Signature
.
rSig
.
x_only
&
p_signature_
.
ecdsaBrainpoolP256r1Signature
.
sSig
,
p_verification_key
.
ecdsaBrainpoolP256r1
.
compressed_y_1
,
1
);
}
}
else
if
(
ischosen
(
p_verification_key
.
ecdsaBrainpoolP384r1
))
{
if
(
ischosen
(
p_verification_key
.
ecdsaBrainpoolP384r1
.
compressed_y_0
))
{
v_ret
:=
f_verifyWithEcdsaBrainpoolp384WithSha384
(
p_tbs
,
p_issuer
,
p_signature_
.
ecdsaBrainpoolP384r1Signature
.
rSig
.
x_only
&
p_signature_
.
ecdsaBrainpoolP384r1Signature
.
sSig
,
p_verification_key
.
ecdsaBrainpoolP384r1
.
compressed_y_0
,
0
);
}
else
{
v_ret
:=
f_verifyWithEcdsaBrainpoolp384WithSha384
(
p_tbs
,
p_issuer
,
p_signature_
.
ecdsaBrainpoolP384r1Signature
.
rSig
.
x_only
&
p_signature_
.
ecdsaBrainpoolP384r1Signature
.
sSig
,
p_verification_key
.
ecdsaBrainpoolP384r1
.
compressed_y_1
,
1
);
}
}
return
v_ret
;
}
// End of function f_verifyEcdsa
}
// End of group helpers
...
...
@@ -414,6 +508,80 @@ module LibItsPki_Functions {
log
(
"*** f_http_build_invalid_enrolment_request: DEBUG: p_ieee1609dot2_signed_and_encrypted_data = "
,
p_ieee1609dot2_signed_and_encrypted_data
);
}
// End of function f_http_build_invalid_enrolment_request
function
f_http_build_inner_ec_response
(
in
InnerEcRequest
p_inner_ec_request
,
in
EnrolmentResponseCode
p_responseCode
:=
ok
,
in
Oct16
p_request_hash
,
in
Oct32
p_private_key
,
in
HashedId8
p_hashed_id8
,
in
Oct16
p_aes_sym_key
,
out
Ieee1609Dot2Data
p_ieee1609dot2_signed_and_encrypted_data
)
return
boolean
{
// Local variables
var
bitstring
v_msg_bit
;
var
octetstring
v_msg
;
var
Oct12
v_nonce
;
var
Ieee1609Dot2Data
v_ieee1609dot2_signed_data
;
var
InnerEcResponse
v_inner_ec_response
;
var
EtsiTs103097Certificate
v_ec_certificate
;
var
boolean
p_result
:=
false
;
log
(
">>> f_http_build_inner_ec_response"
);
// Check expectred response
if
(
p_responseCode
!=
ok
)
{
v_inner_ec_response
:=
valueof
(
m_innerEcResponse_ko
(
p_request_hash
,
p_responseCode
)
);
p_result
:=
true
;
}
else
{
// Generate the certificate
if
(
f_generate_ec_certificate_for_inner_ec_response
(
p_inner_ec_request
,
v_ec_certificate
)
==
false
)
{
log
(
"f_http_build_inner_ec_response: Failed to generate the certificate"
);
v_inner_ec_response
:=
valueof
(
m_innerEcResponse_ko
(
p_request_hash
,
incompleterequest
)
);
}
else
{
v_inner_ec_response
:=
valueof
(
m_innerEcResponse_ok
(
p_request_hash
,
v_ec_certificate
)
);
}
}
// Secure the response
log
(
"f_http_build_inner_ec_response: v_inner_ec_response= "
,
v_inner_ec_response
);
v_msg
:=
bit2oct
(
encvalue
(
v_inner_ec_response
));
v_nonce
:=
int2oct
(
f_getCurrentTime
(),
32
);
// Random value
if
(
f_build_pki_secured_response_message
(
p_private_key
,
valueof
(
m_signerIdentifier_digest
(
p_hashed_id8
)),
// in SignerIdentifier p_signer_identifier,
v_msg
,
p_aes_sym_key
,
v_nonce
,
p_ieee1609dot2_signed_and_encrypted_data
)
==
false
)
{
log
(
"f_http_build_inner_ec_response: Failed to generate the certificate"
);
v_inner_ec_response
:=
valueof
(
m_innerEcResponse_ko
(
p_request_hash
,
deniedrequest
)
);
}
else
{
p_result
:=
true
;
}
return
p_result
;
}
// End of function f_http_build_inner_ec_response
function
f_http_build_authorization_request
(
in
Certificate
p_ec_certificate
,
// Enrolment credentials certificate
in
octetstring
p_ec_private_key
,
...
...
@@ -641,6 +809,58 @@ module LibItsPki_Functions {
return
true
;
}
// End of function f_generate_ec_certificate
function
f_generate_ec_certificate_for_inner_ec_response
(
in
InnerEcRequest
p_inner_ec_request
,
out
EtsiTs103097Certificate
p_ec_certificate
)
return
boolean
{
/*v_cert := m_etsiTs103097Certificate(
m_issuerIdentifier_sha256AndDigest(f_HashedId8FromSha256(f_hashWithSha256('616263'O))),
m_toBeSignedCertificate_at(
v_appPermissions,
m_verificationKeyIndicator_verificationKey(
v_public_verification_key
),
m_validityPeriod(
f_getCurrentTime() / 1000,
m_duration_years(1)
),
m_geographicRegion_identifiedRegion(
{
m_identifiedRegion_country_only(12),
m_identifiedRegion_country_only(34)
}
)
)
);
// Encode it ==> Get octetstring
v_tbs := encvalue(v_cert.toBeSigned);
// Sign the certificate
v_sig := f_signWithEcdsa(bit2oct(v_tbs), int2oct(11, 32), p_private_key);
if ((PX_VE_ALG == e_nist_p256) or (PX_VE_ALG == e_brainpool_p256_r1)) {
v_cert.signature_ := m_signature_ecdsaNistP256(
m_ecdsaP256Signature(
m_eccP256CurvePoint_x_only(
substr(v_sig, 0, 32)
),
substr(v_sig, 32, 32)
)
);
} else if (PX_VE_ALG == e_brainpool_p384_r1) {
v_cert.signature_ := m_signature_ecdsaBrainpoolP384r1(
m_ecdsaP384Signature(
m_eccP384CurvePoint_x_only(
substr(v_sig, 0, 48)
),
substr(v_sig, 48, 48)
)
);
}
log("f_generate_ec_certificate_for_inner_ec_response: v_cert= ", v_cert);
p_ec_certificate := valueof(v_cert);*/
return
true
;
}
// End of function f_generate_ec_certificate_for_inner_ec_response
function
f_generate_at_certificate
(
in
octetstring
p_private_key
,
in
InnerEcRequest
p_inner_ec_request
,
...
...
@@ -855,6 +1075,29 @@ module LibItsPki_Functions {
return
true
;
}
// End of function f_generate_inner_ec_request_signed_for_pop
function
f_verify_inner_ec_request_signed_for_pop
(
in
EtsiTs102941Data
p_etsi_ts_102941_data
,
out
InnerEcRequest
p_inner_ec_request
)
return
boolean
{
var
bitstring
v_msg_bit
;
log
(
">>> f_verify_inner_ec_request_signed_for_pop: "
,
p_etsi_ts_102941_data
);
// 1. Decode content
v_msg_bit
:=
oct2bit
(
p_etsi_ts_102941_data
.
content
.
enrolmentRequest
.
content
.
signedData
.
tbsData
.
payload
.
data
.
content
.
unsecuredData
);
if
(
decvalue
(
v_msg_bit
,
p_inner_ec_request
)
!=
0
)
{
log
(
"f_verify_inner_ec_request_signed_for_pop: Failed to decode InnerEcRequest"
);
return
false
;
}
else
{
log
(
"f_verify_inner_ec_request_signed_for_pop: v_inner_ec_request= "
,
p_inner_ec_request
);
// 2. Verify the InnerEcRequestSignedForPop signature
}
return
true
;
}
// End of function f_verify_inner_ec_request_signed_for_pop
function
f_generate_inner_ec_response
(
in
octetstring
p_inner_ec_request_hash
,
in
EtsiTs103097Certificate
p_certificate
,
...
...
@@ -1287,7 +1530,7 @@ module LibItsPki_Functions {
)))))))
->
value
v_response
{
tc_ac
.
stop
;
if
(
f_verify_pki_message
(
p_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
)
{
if
(
f_verify_pki_
response_
message
(
p_private_key
,
v_aes_sym_key
,
v_authentication_vector
,
vc_eaWholeHash
,
v_response
.
response
.
body
.
binary_body
.
ieee1609dot2_data
,
false
,
v_etsi_ts_102941_data
)
==
false
)
{
log
(
"f_await_http_inner_ec_request_response: Failed to verify PKI message ***"
);
}
else
{
log
(
"f_await_http_inner_ec_request_response: Receive "
,
v_etsi_ts_102941_data
,
" ***"
);
...
...
@@ -1320,7 +1563,7 @@ module LibItsPki_Functions {
)))))))
->
value
v_response
{
tc_ac
.
stop
;
if
(
f_verify_pki_message
(
p_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
)
{
if
(
f_verify_pki_
response_
message
(
p_private_key
,
v_aes_sym_key
,
v_authentication_vector
,
vc_eaWholeHash
,
v_response
.
response
.
body
.
binary_body
.
ieee1609dot2_data
,
false
,
v_etsi_ts_102941_data
)
==
false
)
{
log
(
"f_await_http_inner_ec_request_response: Failed to verify PKI message ***"
);
}
else
{
log
(
"f_await_http_inner_ec_request_response: Receive "
,
v_etsi_ts_102941_data
,
" ***"
);
...
...
@@ -1746,6 +1989,101 @@ module LibItsPki_Functions {
return
true
;
}
// End of function f_build_pki_secured_response_message
/**
* @desc Verify the protocol element of the Pki message.
* If p_check_security is set to false, only decryption and decoding of the outer message are verified.
* @param p_private_enc_key Private key for decryption
* @param p_salt
* @param p_p_ieee1609dot2_encrypted_and_signed_data
* @param p_check_security Set to true to verify PKI protocol element such as signatures...
* @param p_request_hash The request hash for to be used to build the response
* @param p_etsi_ts_102941_data The EtsiTs102941Data message
* @param p_aes_enc_key The AES 128 encrytion key to be used to encrypt the response
* @return true on success, false otherwise
*/
function
f_verify_pki_request_message
(
in
Oct32
p_private_enc_key
,
in
Oct32
p_salt
,
in
octetstring
p_issuer
,
in
Ieee1609Dot2Data
p_ieee1609dot2_encrypted_and_signed_data
,
in
boolean
p_check_security
:=
true
,
out
Oct16
p_request_hash
,
out
EtsiTs102941Data
p_etsi_ts_102941_data
,
out
Oct16
p_aes_enc_key
)
return
boolean
{
// Local variables
var
bitstring
v_msg_bit
;
var
octetstring
v_msg
;
var
Ieee1609Dot2Data
v_ieee1609dot2_signed_data
;
var
Certificate
v_certificate
;
log
(
">>> f_verify_pki_request_message: p_private_enc_key= "
,
p_private_enc_key
);
log
(
">>> f_verify_pki_request_message: p_salt= "
,
p_salt
);
log
(
">>> f_verify_pki_request_message: p_issuer= "
,
p_issuer
);
// 1. Calculate the request Hash
v_msg
:=
bit2oct
(
encvalue
(
p_ieee1609dot2_encrypted_and_signed_data
));
log
(
"f_verify_pki_request_message: Encoded request: "
,
v_msg
);
p_request_hash
:=
substr
(
f_hashWithSha256
(
v_msg
),
0
,
16
);
log
(
"f_verify_pki_request_message: v_request_hash= "
,
p_request_hash
);
// 2. Decrypt the InnerEcRequest
log
(
"f_verify_pki_request_message: p_private_enc_key= "
,
p_private_enc_key
);
if
(
f_decrypt
(
p_private_enc_key
,
p_ieee1609dot2_encrypted_and_signed_data
,
p_salt
,
v_ieee1609dot2_signed_data
,
p_aes_enc_key
)
==
false
)
{
log
(
"f_verify_pki_request_message: Failed to decrypt message"
);
return
false
;
}
log
(
"f_verify_pki_request_message: v_ieee1609dot2_signed_data= "
,
v_ieee1609dot2_signed_data
);
log
(
"f_verify_pki_request_message: p_aes_enc_key= "
,
p_aes_enc_key
);
// 3. Check basics security
log
(
match
(
v_ieee1609dot2_signed_data
,
mw_etsiTs103097Data_signed
(
mw_signedData
(
-
,
mw_toBeSignedData
(
mw_signedDataPayload
,
mw_ieee1609Dot2_headerInfo
(
c_its_aid_SCR
)
)
)
)));
if
(
match
(
v_ieee1609dot2_signed_data
,
mw_etsiTs103097Data_signed
(
mw_signedData
(
-
,
mw_toBeSignedData
(
mw_signedDataPayload
))))
==
false
)
{
log
(
"f_verify_pki_request_message: Failed to check basic security"
);
if
(
p_check_security
==
true
)
{
return
false
;
}
}
// 4. Verifiy signature
log
(
"f_verify_pki_request_message: v_ieee1609dot2_signed_data.content.signedData.tbsData= "
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
tbsData
);
v_msg
:=
bit2oct
(
encvalue
(
v_ieee1609dot2_signed_data
.
content
.
signedData
.
tbsData
));
if
(
f_getCertificateFromDigest
(
f_HashedId8FromSha256
(
p_issuer
),
v_certificate
)
==
false
)
{
return
false
;
}
log
(
"f_verify_pki_request_message: v_certificate= "
,
v_certificate
);
if
(
f_verifyEcdsa
(
v_msg
,
p_issuer
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
,
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
)
==
false
)
{
if
(
p_check_security
==
true
)
{
return
false
;
}
}
// 4. Return the PKI message
log
(
"f_verify_pki_request_message: v_ieee1609dot2_signed_data.content.signedData.tbsData.payload.data.content.unsecuredData= "
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
tbsData
.
payload
.
data
.
content
.
unsecuredData
);
v_msg_bit
:=
oct2bit
(
v_ieee1609dot2_signed_data
.
content
.
signedData
.
tbsData
.
payload
.
data
.
content
.
unsecuredData
);
if
(
decvalue
(
v_msg_bit
,
p_etsi_ts_102941_data
)
!=
0
)
{
return
false
;
}
if
(
p_etsi_ts_102941_data
.
version
!=
PkiProtocolVersion
)
{
return
false
;
}
log
(
"<<< f_verify_pki_request_message: true"
);
return
true
;
}
// End of function f_verify_pki_request_message
/**
* @desc Verify the protocol element of the Pki message.
* If p_check_security is set to false, only decryption and decoding of the outer message are verified.
...
...
@@ -1759,12 +2097,11 @@ module LibItsPki_Functions {
* @param p_etsi_ts_102941_data The EtsiTs102941Data message
* @return true on success, false otherwise
*/
function
f_verify_pki_message
(
function
f_verify_pki_
response_
message
(
in
octetstring
p_private_enc_key
,
in
Oct16
p_aes_sym_key
,
in
Oct16
p_authentication_vector
,
// TODO Tobe removed
in
octetstring
p_issuer
,
in
Certificate
p_certificate
,
// TODO Tobe removed
in
Ieee1609Dot2Data
p_ieee1609dot2_encrypted_and_signed_data
,
in
boolean
p_check_security
:=
true
,
out
EtsiTs102941Data
p_etsi_ts_102941_data
...
...
@@ -1779,10 +2116,10 @@ module LibItsPki_Functions {
var
bitstring
v_tbs
;
var
boolean
v_ret
;
log
(
">>> f_verify_pki_message: p_private_enc_key= "
,
p_private_enc_key
);
log
(
">>> f_verify_pki_message: p_aes_sym_key= "
,
p_aes_sym_key
);
log
(
">>> f_verify_pki_message: p_authentication_vector= "
,
p_authentication_vector
);
log
(
">>> f_verify_pki_message: p_issuer= "
,
p_issuer
);
log
(
">>> f_verify_pki_
response_
message: p_private_enc_key= "
,
p_private_enc_key
);
log
(
">>> f_verify_pki_
response_
message: p_aes_sym_key= "
,
p_aes_sym_key
);
log
(
">>> f_verify_pki_
response_
message: p_authentication_vector= "
,
p_authentication_vector
);
log
(
">>> f_verify_pki_
response_
message: p_issuer= "
,
p_issuer
);
// TODO Check p_ieee1609dot2_encrypted_and_signed_data.content.encryptedData.recipients[0].pskRecipInfo. See IEEE Std 1609.2-2017 Clause 6.3.34 PreSharedKeyRecipientInfo
...
...
@@ -1791,95 +2128,42 @@ module LibItsPki_Functions {
if
(
isbound
(
v_plain_message
)
==
false
)
{
return
false
;
}
log
(
"f_verify_pki_message: v_plain_message= "
,
v_plain_message
);
log
(
"f_verify_pki_
response_
message: v_plain_message= "
,
v_plain_message
);
// 2. Decode it
v_tbs
:=
oct2bit
(
v_plain_message
);
if
(
decvalue
(
v_tbs
,
v_ieee1609dot2_signed_data
)
!=
0
)
{
return
false
;
}
log
(
"f_verify_pki_message: v_ieee1609dot2_signed_data= "
,
v_ieee1609dot2_signed_data
);
log
(
"f_verify_pki_
response_
message: v_ieee1609dot2_signed_data= "
,
v_ieee1609dot2_signed_data
);
// 3. Check the signature
log
(
"f_verify_pki_message: v_ieee1609dot2_signed_data.content.signedData.tbsData= "
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
tbsData
);
log
(
"f_verify_pki_
response_
message: v_ieee1609dot2_signed_data.content.signedData.tbsData= "
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
tbsData
);
v_tbs
:=
encvalue
(
v_ieee1609dot2_signed_data
.
content
.
signedData
.
tbsData
);
if
(
f_getCertificateFromDigest
(
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signer
.
digest
,
v_certificate
)
==
false
)
{
if
(
p_check_security
==
true
)
{
return
false
;
}
}
//log("f_verify_pki_message: v_certificate= ", v_certificate);
v_ret
:=
false
;
if
(
ischosen
(
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaNistP256
))
{
if
(
ischosen
(
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaNistP256
.
compressed_y_0
))
{
v_ret
:=
f_verifyWithEcdsaNistp256WithSha256
(
bit2oct
(
v_tbs
),
p_issuer
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaNistP256Signature
.
rSig
.
x_only
&
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaNistP256Signature
.
sSig
,
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaNistP256
.
compressed_y_0
,
0
);
}
else
{
v_ret
:=
f_verifyWithEcdsaNistp256WithSha256
(
bit2oct
(
v_tbs
),
p_issuer
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaNistP256Signature
.
rSig
.
x_only
&
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaNistP256Signature
.
sSig
,
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaNistP256
.
compressed_y_1
,
1
);
}
}
else
if
(
ischosen
(
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaBrainpoolP256r1
))
{
if
(
ischosen
(
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaBrainpoolP256r1
.
compressed_y_0
))
{
v_ret
:=
f_verifyWithEcdsaBrainpoolp256WithSha256
(
bit2oct
(
v_tbs
),
p_issuer
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaBrainpoolP256r1Signature
.
rSig
.
x_only
&
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaBrainpoolP256r1Signature
.
sSig
,
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaBrainpoolP256r1
.
compressed_y_0
,
0
);
}
else
{
v_ret
:=
f_verifyWithEcdsaBrainpoolp256WithSha256
(
bit2oct
(
v_tbs
),
p_issuer
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaBrainpoolP256r1Signature
.
rSig
.
x_only
&
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaBrainpoolP256r1Signature
.
sSig
,
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaBrainpoolP256r1
.
compressed_y_1
,
1
);
}
}
else
if
(
ischosen
(
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaBrainpoolP384r1
))
{
if
(
ischosen
(
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaBrainpoolP384r1
.
compressed_y_0
))
{
v_ret
:=
f_verifyWithEcdsaBrainpoolp384WithSha384
(
bit2oct
(
v_tbs
),
p_issuer
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaBrainpoolP384r1Signature
.
rSig
.
x_only
&
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaBrainpoolP384r1Signature
.
sSig
,
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaBrainpoolP384r1
.
compressed_y_0
,
0
);
}
else
{
v_ret
:=
f_verifyWithEcdsaBrainpoolp384WithSha384
(
bit2oct
(
v_tbs
),
p_issuer
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaBrainpoolP384r1Signature
.
rSig
.
x_only
&
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
.
ecdsaBrainpoolP384r1Signature
.
sSig
,
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
.
ecdsaBrainpoolP384r1
.
compressed_y_1
,
1
);
}
}
if
(
v_ret
==
false
)
{
if
(
f_verifyEcdsa
(
bit2oct
(
v_tbs
),
p_issuer
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
signature_
,
v_certificate
.
toBeSigned
.
verifyKeyIndicator
.
verificationKey
)
==
false
)
{
if
(
p_check_security
==
true
)
{
return
false
;
}
}
// 4. Return the PKI message
log
(
"v_ieee1609dot2_signed_data.content.signedData.tbsData.payload.data.content.unsecuredData= "
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
tbsData
.
payload
.
data
.
content
.
unsecuredData
);
log
(
"
f_verify_pki_response_message:
v_ieee1609dot2_signed_data.content.signedData.tbsData.payload.data.content.unsecuredData= "
,
v_ieee1609dot2_signed_data
.
content
.
signedData
.
tbsData
.
payload
.
data
.
content
.
unsecuredData
);
v_etsi_ts_102941_data_msg
:=
oct2bit
(
v_ieee1609dot2_signed_data
.
content
.
signedData
.
tbsData
.
payload
.
data
.
content
.
unsecuredData
);
if
(
decvalue
(
v_etsi_ts_102941_data_msg
,
p_etsi_ts_102941_data
)
!=
0
)
{
return
false
;
}
if
(
p_etsi_ts_102941_data
.
version
!=
PkiProtocolVersion
)
{
if
(
p_check_security
==
true
)
{
return
false
;
}
}
return
true
;
}
// End of function f_verify_pki_message
}
// End of function f_verify_pki_
response_
message
/**
* @desc Verify the EC certificate generated by the EA entity
...
...
@@ -2027,6 +2311,10 @@ module LibItsPki_Functions {
log
(
"*** a_default: ERROR: Unexpected HTTP message received ***"
);
f_selfOrClientSyncAndVerdict
(
"error"
,
e_error
);
}
[]
a_shutdown
()
{
log
(
"*** a_default: INFO: TEST COMPONENT NOW STOPPING ITSELF! ***"
);
stop
;
}
}
// End of altstep a_default_pki_http
altstep
a_default_pki_http_ec
()
runs
on
ItsPkiHttp
{
...
...
@@ -2054,6 +2342,10 @@ module LibItsPki_Functions {
log
(
"*** a_default: ERROR: Unexpected HTTP message received ***"
);
f_selfOrClientSyncAndVerdict
(
"error"
,
e_error
);
}
[]
a_shutdown
()
{
log
(
"*** a_default: INFO: TEST COMPONENT NOW STOPPING ITSELF! ***"
);
stop
;
}
}
// End of altstep a_default_pki_http_ec
altstep
a_default_pki_http_atv
()
runs
on
ItsPkiHttp
{
...
...
@@ -2081,6 +2373,10 @@ module LibItsPki_Functions {
log
(
"*** a_default: ERROR: Unexpected HTTP message received ***"
);
f_selfOrClientSyncAndVerdict
(
"error"
,
e_error
);
}