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
Compare Revisions
b1729a03676613e0233209066db2209f1cfdf853...467ea0b72dbef25dc1a8ce0c938f77442a7fdf4d
Commits (1)
Validate Authorization/AuthorizationValidation
· 467ea0b7
Yann Garcia
authored
Feb 13, 2019
467ea0b7
Hide whitespace changes
Inline
Side-by-side
ttcn/Pki/LibItsPki_Functions.ttcn
View file @
467ea0b7
...
...
@@ -104,6 +104,7 @@ module LibItsPki_Functions {
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_eaPrivateEncKey= "
,
vc_eaPrivateEncKey
);
log
(
"f_cfHttpUp: vc_eaHashedId8= "
,
vc_eaHashedId8
);
log
(
"f_cfHttpUp: vc_eaWholeHash= "
,
vc_eaWholeHash
);
...
...
@@ -512,8 +513,8 @@ module LibItsPki_Functions {
in
InnerEcRequest
p_inner_ec_request
,
in
EnrolmentResponseCode
p_responseCode
:=
ok
,
in
Oct16
p_request_hash
,
in
O
ct
32
p_private_key
,
in
HashedId8
p_hashed_id8
,
in
o
ct
etstring
p_private_key
:=
''
O
,
in
octetstring
p_digest
:=
''
O
,
in
Oct16
p_aes_sym_key
,
out
Ieee1609Dot2Data
p_ieee1609dot2_signed_and_encrypted_data
)
return
boolean
{
...
...
@@ -526,7 +527,12 @@ module LibItsPki_Functions {
var
EtsiTs103097Certificate
v_ec_certificate
;
var
boolean
p_result
:=
false
;
log
(
">>> f_http_build_inner_ec_response"
);
log
(
">>> f_http_build_inner_ec_response: p_inner_ec_request= "
,
p_inner_ec_request
);
log
(
">>> f_http_build_inner_ec_response: p_responseCode= "
,
p_responseCode
);
log
(
">>> f_http_build_inner_ec_response: p_request_hash= "
,
p_request_hash
);
log
(
">>> f_http_build_inner_ec_response: p_private_key= "
,
p_private_key
);
log
(
">>> f_http_build_inner_ec_response: p_digest= "
,
p_digest
);
log
(
">>> f_http_build_inner_ec_response: p_aes_sym_key= "
,
p_aes_sym_key
);
// Check expectred response
if
(
p_responseCode
!=
ok
)
{
...
...
@@ -539,7 +545,7 @@ module LibItsPki_Functions {
p_result
:=
true
;
}
else
{
// Generate the certificate
if
(
f_generate_ec_certificate_for_inner_ec_response
(
p_inner_ec_request
,
v_ec_certificate
)
==
false
)
{
if
(
f_generate_ec_certificate_for_inner_ec_response
(
p_inner_ec_request
,
p_private_key
,
p_digest
,
v_ec_certificate
)
==
false
)
{
log
(
"f_http_build_inner_ec_response: Failed to generate the certificate"
);
v_inner_ec_response
:=
valueof
(
m_innerEcResponse_ko
(
...
...
@@ -561,8 +567,9 @@ module LibItsPki_Functions {
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
// TODO Consider Sha384: m_signerIdentifier_digest(f_HashedId8FromSha384(p_digest))
if
(
f_build_pki_secured_response_message
(
p_private_key
,
valueof
(
m_signerIdentifier_digest
(
p_h
ashed
_id8
)),
// in SignerIdentifier p_signer_identifier,
valueof
(
m_signerIdentifier_digest
(
f_H
ashed
Id8FromSha256
(
p_digest
)
)),
// in SignerIdentifier p_signer_identifier,
v_msg
,
p_aes_sym_key
,
v_nonce
,
...
...
@@ -639,7 +646,7 @@ module LibItsPki_Functions {
}
}
else
{
// Only encryption of EtsiTs102941Data/InnerAtRequest
log
(
"*** f_http_build_authorization_request: POP signature not applied"
);
if
(
f_build_pki_secured_request_message
(
vc_aaHashedId8
/*recipientId*/
,
v_public_enc_key
,
v_compressed_enc_key_mode
,
p_salt
,
bit2oct
(
encvalue
(
m_etsiTs102941Data_authorization_request
(
v_inner_at_request
))),
p_ieee1609dot2_signed_and_encrypted_data
,
p_aes_sym_key
,
p_encrypted_sym_key
,
p_authentication_vector
,
p_nonce
,
p_request_hash
)
==
false
)
{
if
(
f_build_pki_secured_request_message
_for_authorization
(
vc_aaHashedId8
/*recipientId*/
,
v_public_enc_key
,
v_compressed_enc_key_mode
,
p_salt
,
bit2oct
(
encvalue
(
m_etsiTs102941Data_authorization_request
(
v_inner_at_request
))),
p_ieee1609dot2_signed_and_encrypted_data
,
p_aes_sym_key
,
p_encrypted_sym_key
,
p_authentication_vector
,
p_nonce
,
p_request_hash
)
==
false
)
{
log
(
"*** f_http_build_authorization_request: ERROR: Failed to generate Authorization Request ***"
);
f_selfOrClientSyncAndVerdict
(
"error"
,
e_error
);
}
...
...
@@ -695,17 +702,9 @@ module LibItsPki_Functions {
log
(
"*** f_http_build_authorization_validation_request: Public encryption key comp: "
,
v_compressed_enc_key_mode
);
p_salt
:=
vc_eaWholeHash
;
log
(
"*** f_http_build_authorization_validation_request: p_salt: "
,
p_salt
);
if
(
PX_AUTHORIZATION_REQUEST_WITH_POP
)
{
if
(
f_build_pki_secured_request_message_signed_with_pop
(
PICS_ITS_S_SIGN_NITSP256_PRIVATE_KEY
,
valueof
(
m_signerIdentifier_self
),
vc_eaHashedId8
/*recipientId*/
,
v_public_enc_key
,
v_compressed_enc_key_mode
,
p_salt
,
bit2oct
(
encvalue
(
m_etsiTs102941Data_authorization_validation_request
(
v_authorization_validation_request
))),
p_ieee1609dot2_signed_and_encrypted_data
,
p_aes_sym_key
,
p_encrypted_sym_key
,
p_authentication_vector
,
p_nonce
,
p_request_hash
)
==
false
)
{
log
(
"*** f_http_build_authorization_validation_request: ERROR: Failed to generate Authorization Request ***"
);
f_selfOrClientSyncAndVerdict
(
"error"
,
e_error
);
}
}
else
{
// Only encryption of EtsiTs102941Data/InnerAtRequest
log
(
"*** f_http_build_authorization_validation_request: POP signature not applied"
);
if
(
f_build_pki_secured_request_message
(
vc_eaHashedId8
/*recipientId*/
,
v_public_enc_key
,
v_compressed_enc_key_mode
,
p_salt
,
bit2oct
(
encvalue
(
m_etsiTs102941Data_authorization_validation_request
(
v_authorization_validation_request
))),
p_ieee1609dot2_signed_and_encrypted_data
,
p_aes_sym_key
,
p_encrypted_sym_key
,
p_authentication_vector
,
p_nonce
,
p_request_hash
)
==
false
)
{
log
(
"*** f_http_build_authorization_validation_request: ERROR: Failed to generate Authorization Request ***"
);
f_selfOrClientSyncAndVerdict
(
"error"
,
e_error
);
}
if
(
f_build_pki_secured_request_message_signed_with_pop
(
PICS_ITS_S_SIGN_NITSP256_PRIVATE_KEY
,
valueof
(
m_signerIdentifier_self
),
vc_eaHashedId8
/*recipientId*/
,
v_public_enc_key
,
v_compressed_enc_key_mode
,
p_salt
,
bit2oct
(
encvalue
(
m_etsiTs102941Data_authorization_validation_request
(
v_authorization_validation_request
))),
p_ieee1609dot2_signed_and_encrypted_data
,
p_aes_sym_key
,
p_encrypted_sym_key
,
p_authentication_vector
,
p_nonce
,
p_request_hash
)
==
false
)
{
log
(
"*** f_http_build_authorization_validation_request: ERROR: Failed to generate Authorization Request ***"
);
f_selfOrClientSyncAndVerdict
(
"error"
,
e_error
);
}
log
(
"*** f_http_build_authorization_validation_request: DEBUG: p_ieee1609dot2_signed_and_encrypted_data= "
,
p_ieee1609dot2_signed_and_encrypted_data
);
log
(
"*** f_http_build_authorization_validation_request: DEBUG: p_request_hash= "
,
p_request_hash
);
...
...
@@ -811,53 +810,75 @@ module LibItsPki_Functions {
function
f_generate_ec_certificate_for_inner_ec_response
(
in
InnerEcRequest
p_inner_ec_request
,
in
octetstring
p_private_key
,
in
octetstring
p_digest
,
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)
}
)
)
);
var
EtsiTs103097Certificate
v_cert
;
var
IssuerIdentifier
v_issuer
;
var
bitstring
v_tbs
;
var
octetstring
v_sig
;
log
(
">>> f_generate_ec_certificate_for_inner_ec_response"
);
v_issuer
:=
valueof
(
m_issuerIdentifier_sha256AndDigest
(
f_HashedId8FromSha256
(
p_digest
)));
// TODO Check sha256/384 f_HashedId8FromSha384
v_cert
:=
valueof
(
m_etsiTs103097Certificate
(
v_issuer
,
m_toBeSignedCertificate_ec
(
p_inner_ec_request
.
requestedSubjectAttributes
.
id
,
p_inner_ec_request
.
requestedSubjectAttributes
.
appPermissions
,
m_verificationKeyIndicator_verificationKey
(
p_inner_ec_request
.
publicKeys
.
verificationKey
),
p_inner_ec_request
.
requestedSubjectAttributes
.
validityPeriod
,
p_inner_ec_request
.
requestedSubjectAttributes
.
region
,
p_inner_ec_request
.
requestedSubjectAttributes
.
assuranceLevel
,
p_inner_ec_request
.
publicKeys
.
encryptionKey
)
)
);
// 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)
)
);
v_sig
:=
f_signWithEcdsa
(
bit2oct
(
v_tbs
),
p_digest
,
p_private_key
);
if
(
PX_VE_ALG
==
e_nist_p256
)
{
v_cert
.
signature_
:=
valueof
(
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_p256_r1
)
{
v_cert
.
signature_
:=
valueof
(
m_signature_ecdsaBrainpoolP256r1
(
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)
)
);
v_cert
.
signature_
:=
valueof
(
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
);
log
(
"f_generate_ec_certificate_for_inner_ec_response: p_ec_certificate= "
,
p_ec_certificate
);
p_ec_certificate := valueof(v_cert);*/
return
true
;
}
// End of function f_generate_ec_certificate_for_inner_ec_response
...
...
@@ -1149,7 +1170,7 @@ module LibItsPki_Functions {
var
octetstring
v_hash_shared_at_request
;
var
template
(
value
)
ToBeSignedData
v_tbs
;
var
octetstring
v_tbs_signed
;
var
Ieee1609Dot2Data
v_signed_
ec
_signature
;
var
Ieee1609Dot2Data
v_signed_
at
_signature
;
var
template
(
value
)
EccP256CurvePoint
v_eccP256_curve_point
;
var
template
(
value
)
EccP256CurvePoint
v_enc_eccP256_curve_point
;
var
HashAlgorithm
v_hashId
;
...
...
@@ -1204,7 +1225,7 @@ module LibItsPki_Functions {
valueof
(
m_certificate_subject_attributes
(
// FIXME Review subjectPermissions
p_ec_certificate
.
toBeSigned
.
appPermissions
,
{
{
subjectPermissions
:=
{
all_
:=
NULL
},
minChainLength
:=
1
,
chainLengthRange
:=
0
,
eeType
:=
'00000000'B
}
}
,
p_ec_certificate
.
toBeSigned
.
certRequestPermissions
,
p_ec_certificate
.
toBeSigned
.
id
,
p_ec_certificate
.
toBeSigned
.
validityPeriod
,
p_ec_certificate
.
toBeSigned
.
region
,
...
...
@@ -1224,7 +1245,7 @@ module LibItsPki_Functions {
);
log
(
"f_generate_inner_at_request: v_tbs= "
,
v_tbs
);
// Signed ToBeSigned payload using the private key of EC certificate obtained from Enrolment request
// In case of ITS-S privacy, v_signed_
ec
_signature contained the data to be encrypted
// In case of ITS-S privacy, v_signed_
at
_signature contained the data to be encrypted
if
(
ischosen
(
p_ec_certificate
.
signature_
.
ecdsaBrainpoolP384r1Signature
))
{
v_hashId
:=
sha384
;
v_tbs_signed
:=
f_signWithEcdsaBrainpoolp384WithSha384
(
bit2oct
(
encvalue
(
v_tbs
)),
v_ec_hash
,
p_ec_private_key
);
...
...
@@ -1270,7 +1291,7 @@ module LibItsPki_Functions {
return
false
;
}
}
v_signed_
ec
_signature
:=
valueof
(
v_signed_
at
_signature
:=
valueof
(
m_etsiTs103097Data_signed
(
m_signedData
(
v_hashId
,
...
...
@@ -1280,7 +1301,7 @@ module LibItsPki_Functions {
)
)
);
log
(
"f_generate_inner_at_request: v_signed_
ec
_signature= "
,
v_signed_
ec
_signature
);
log
(
"f_generate_inner_at_request: v_signed_
at
_signature= "
,
v_signed_
at
_signature
);
if
(
PICS_ITS_S_WITH_PRIVACY
)
{
// Build EtsiTs102097Data-Encrypted structure
var
octetstring
v_public_enc_key
;
...
...
@@ -1294,7 +1315,7 @@ module LibItsPki_Functions {
var
integer
v_public_compressed_ephemeral_mode
;
var
octetstring
v_enc_signed_ec_signature
;
var
EncryptedDataEncryptionKey
v_encrypted_data_encryption_key
;
// Use EA certificate for the encryption
if
(
PX_EC_ALG
==
e_nist_p256
)
{
if
(
ischosen
(
p_ea_certificate
.
toBeSigned
.
encryptionKey
.
publicKey
.
eciesNistP256
.
compressed_y_0
))
{
...
...
@@ -1308,13 +1329,21 @@ module LibItsPki_Functions {
return
false
;
}
if
(
PX_EC_ALG
==
e_nist_p256
)
{
v_enc_signed_ec_signature
:=
f_encryptWithEciesNistp256WithSha256
(
bit2oct
(
encvalue
(
v_signed_
ec
_signature
)),
v_public_enc_key
,
v_compressed_mode
,
''
O
,
v_public_compressed_ephemeral_key
,
v_public_compressed_ephemeral_mode
,
v_aes_sym_key
,
v_encrypted_sym_key
,
v_authentication_vector
,
v_nonce
,
PICS_SEC_FIXED_KEYS
);
v_enc_signed_ec_signature
:=
f_encryptWithEciesNistp256WithSha256
(
bit2oct
(
encvalue
(
v_signed_
at
_signature
)),
v_public_enc_key
,
v_compressed_mode
,
''
O
,
v_public_compressed_ephemeral_key
,
v_public_compressed_ephemeral_mode
,
v_aes_sym_key
,
v_encrypted_sym_key
,
v_authentication_vector
,
v_nonce
,
PICS_SEC_FIXED_KEYS
);
}
else
if
(
PX_EC_ALG
==
e_brainpool_p256_r1
)
{
v_enc_signed_ec_signature
:=
f_encryptWithEciesBrainpoolp256WithSha256
(
bit2oct
(
encvalue
(
v_signed_
ec
_signature
)),
v_public_enc_key
,
v_compressed_mode
,
''
O
,
v_public_compressed_ephemeral_key
,
v_public_compressed_ephemeral_mode
,
v_aes_sym_key
,
v_encrypted_sym_key
,
v_authentication_vector
,
v_nonce
,
PICS_SEC_FIXED_KEYS
);
v_enc_signed_ec_signature
:=
f_encryptWithEciesBrainpoolp256WithSha256
(
bit2oct
(
encvalue
(
v_signed_
at
_signature
)),
v_public_enc_key
,
v_compressed_mode
,
''
O
,
v_public_compressed_ephemeral_key
,
v_public_compressed_ephemeral_mode
,
v_aes_sym_key
,
v_encrypted_sym_key
,
v_authentication_vector
,
v_nonce
,
PICS_SEC_FIXED_KEYS
);
}
else
{
log
(
"f_generate_inner_at_request: Wrong encryption variant"
);
return
false
;
}
if
(
v_compressed_mode
==
0
)
{
v_eccP256_curve_point
:=
valueof
(
m_eccP256CurvePoint_compressed_y_0
(
v_public_enc_key
));
}
else
{
v_eccP256_curve_point
:=
valueof
(
m_eccP256CurvePoint_compressed_y_1
(
v_public_enc_key
));
}
log
(
"f_generate_inner_at_request: v_eccP256_curve_point= "
,
v_eccP256_curve_point
);
log
(
"f_generate_inner_at_request: v_encrypted_sym_key= "
,
v_encrypted_sym_key
);
log
(
"f_generate_inner_at_request: v_authentication_vector= "
,
v_authentication_vector
);
v_encrypted_data_encryption_key
:=
valueof
(
m_encryptedDataEncryptionKey_eciesNistP256
(
m_evciesP256EncryptedKey
(
...
...
@@ -1334,9 +1363,9 @@ module LibItsPki_Functions {
return
false
;
}
if
(
PX_EC_ALG
==
e_nist_p256
)
{
v_enc_signed_ec_signature
:=
f_encryptWithEciesNistp256WithSha256
(
bit2oct
(
encvalue
(
v_signed_
ec
_signature
)),
v_public_enc_key
,
v_compressed_mode
,
''
O
,
v_public_compressed_ephemeral_key
,
v_public_compressed_ephemeral_mode
,
v_aes_sym_key
,
v_encrypted_sym_key
,
v_authentication_vector
,
v_nonce
,
PICS_SEC_FIXED_KEYS
);
v_enc_signed_ec_signature
:=
f_encryptWithEciesNistp256WithSha256
(
bit2oct
(
encvalue
(
v_signed_
at
_signature
)),
v_public_enc_key
,
v_compressed_mode
,
''
O
,
v_public_compressed_ephemeral_key
,
v_public_compressed_ephemeral_mode
,
v_aes_sym_key
,
v_encrypted_sym_key
,
v_authentication_vector
,
v_nonce
,
PICS_SEC_FIXED_KEYS
);
}
else
if
(
PX_EC_ALG
==
e_brainpool_p256_r1
)
{
v_enc_signed_ec_signature
:=
f_encryptWithEciesBrainpoolp256WithSha256
(
bit2oct
(
encvalue
(
v_signed_
ec
_signature
)),
v_public_enc_key
,
v_compressed_mode
,
''
O
,
v_public_compressed_ephemeral_key
,
v_public_compressed_ephemeral_mode
,
v_aes_sym_key
,
v_encrypted_sym_key
,
v_authentication_vector
,
v_nonce
,
PICS_SEC_FIXED_KEYS
);
v_enc_signed_ec_signature
:=
f_encryptWithEciesBrainpoolp256WithSha256
(
bit2oct
(
encvalue
(
v_signed_
at
_signature
)),
v_public_enc_key
,
v_compressed_mode
,
''
O
,
v_public_compressed_ephemeral_key
,
v_public_compressed_ephemeral_mode
,
v_aes_sym_key
,
v_encrypted_sym_key
,
v_authentication_vector
,
v_nonce
,
PICS_SEC_FIXED_KEYS
);
}
else
{
log
(
"f_generate_inner_at_request: Wrong encryption variant"
);
return
false
;
...
...
@@ -1382,7 +1411,7 @@ module LibItsPki_Functions {
)
);
}
else
{
// Skip the encryption, alowed to be re-identified by the AA
p_inner_at_request
.
ecSignature
:=
valueof
(
m_ec_signature_ext_payload
(
v_signed_
ec
_signature
));
p_inner_at_request
.
ecSignature
:=
valueof
(
m_ec_signature_ext_payload
(
v_signed_
at
_signature
));
}
// Build the InnerAtRequest, EcSignature field is already set
if
(
p_compressed_key_mode
==
0
)
{
...
...
@@ -1872,11 +1901,11 @@ module LibItsPki_Functions {
m_etsiTs103097Data_encrypted
(
m_encryptedData
(
{
m_recipientInfo_
signedData
RecipInfo
(
m_pKRecipientInfo
(
v_recipientId
,
v_encrypted_data_encryption_key
))
m_recipientInfo_
cert
RecipInfo
(
m_pKRecipientInfo
(
v_recipientId
,
v_encrypted_data_encryption_key
))
},
m_SymmetricCiphertext_aes128ccm
(
m_aesCcmCiphertext
(
...
...
@@ -1901,6 +1930,116 @@ module LibItsPki_Functions {
return
true
;
}
// End of function f_build_pki_secured_request_message
function
f_build_pki_secured_request_message_for_authorization
(
in
HashedId8
p_recipientId
,
in
octetstring
p_public_key_compressed
,
in
integer
p_compressed_mode
,
in
octetstring
p_salt
,
in
octetstring
p_pki_message
,
out
Ieee1609Dot2Data
p_ieee1609dot2_signed_and_encrypted_data
,
out
Oct16
p_aes_sym_key
,
out
Oct16
p_encrypted_sym_key
,
out
Oct16
p_authentication_vector
,
out
Oct12
p_nonce
,
out
Oct32
p_request_hash
)
return
boolean
{
// Local variables
var
Ieee1609Dot2Data
v_unsecured_data
;
var
octetstring
v_pki_message
;
var
template
(
value
)
EccP256CurvePoint
v_eccP256_curve_point
;
var
HashedId8
v_recipientId
;
var
octetstring
v_public_compressed_ephemeral_key
;
var
integer
v_public_compressed_ephemeral_mode
;
var
octetstring
v_encrypted_request
;
var
EncryptedDataEncryptionKey
v_encrypted_data_encryption_key
;
var
bitstring
v_enc_value
;
log
(
">>> f_build_pki_secured_request_message"
);
// Add Ieee1609Dot2Data layer
v_unsecured_data
:=
valueof
(
m_etsiTs103097Data_unsecured
(
p_pki_message
));
v_pki_message
:=
bit2oct
(
encvalue
(
v_unsecured_data
));
// Encrypt encode EtsiTs103097Data-Signed data structure
if
(
PICS_SEC_FIXED_KEYS
)
{
p_salt
:=
'
77
C0637C3558B3238FDE1EEC376DA080BE4076FB8491CA0F8C19FD34DF298CEB
'
O
;
}
if
(
PX_EC_ALG
==
e_nist_p256
)
{
v_encrypted_request
:=
f_encryptWithEciesNistp256WithSha256
(
v_pki_message
,
p_public_key_compressed
,
p_compressed_mode
,
p_salt
,
v_public_compressed_ephemeral_key
,
v_public_compressed_ephemeral_mode
,
p_aes_sym_key
,
p_encrypted_sym_key
,
p_authentication_vector
,
p_nonce
,
PICS_SEC_FIXED_KEYS
);
}
else
if
(
PX_EC_ALG
==
e_brainpool_p256_r1
)
{
v_encrypted_request
:=
f_encryptWithEciesBrainpoolp256WithSha256
(
v_pki_message
,
p_public_key_compressed
,
p_compressed_mode
,
p_salt
,
v_public_compressed_ephemeral_key
,
v_public_compressed_ephemeral_mode
,
p_aes_sym_key
,
p_encrypted_sym_key
,
p_authentication_vector
,
p_nonce
,
PICS_SEC_FIXED_KEYS
);
}
else
{
log
(
"f_build_pki_secured_request_message: Wrong encryption variant"
);
return
false
;
}
log
(
"f_build_pki_secured_request_message: p_aes_sym_key= "
,
p_aes_sym_key
);
log
(
"f_build_pki_secured_request_message: p_encrypted_sym_key= "
,
p_encrypted_sym_key
);
log
(
"f_build_pki_secured_request_message: p_authentication_vector= "
,
p_authentication_vector
);
log
(
"f_build_pki_secured_request_message: p_nonce= "
,
p_nonce
);
log
(
"f_build_pki_secured_request_message: p_recipientId= "
,
p_recipientId
);
if
(
p_recipientId
==
int2oct
(
0
,
8
))
{
log
(
"f_build_pki_secured_request_message: f_hashWithSha256(v_encrypted_sym_key)= "
,
f_hashWithSha256
(
p_encrypted_sym_key
));
v_recipientId
:=
f_HashedId8FromSha256
(
f_hashWithSha256
(
p_encrypted_sym_key
));
}
else
{
v_recipientId
:=
p_recipientId
;
}
log
(
"f_build_pki_secured_request_message: v_recipientId= "
,
v_recipientId
);
// Fill Certificate template with the public compressed keys (canonical form)
if
(
v_public_compressed_ephemeral_mode
==
0
)
{
v_eccP256_curve_point
:=
valueof
(
m_eccP256CurvePoint_compressed_y_0
(
v_public_compressed_ephemeral_key
));
}
else
{
v_eccP256_curve_point
:=
valueof
(
m_eccP256CurvePoint_compressed_y_1
(
v_public_compressed_ephemeral_key
));
}
if
(
PX_EC_ALG
==
e_nist_p256
)
{
v_encrypted_data_encryption_key
:=
valueof
(
m_encryptedDataEncryptionKey_eciesNistP256
(
m_evciesP256EncryptedKey
(
v_eccP256_curve_point
,
p_encrypted_sym_key
,
p_authentication_vector
)));
}
else
if
(
PX_EC_ALG
==
e_brainpool_p256_r1
)
{
v_encrypted_data_encryption_key
:=
valueof
(
m_encryptedDataEncryptionKey_eciesBrainpoolP256r1
(
m_evciesP256EncryptedKey
(
v_eccP256_curve_point
,
p_encrypted_sym_key
,
p_authentication_vector
)));
}
p_ieee1609dot2_signed_and_encrypted_data
:=
valueof
(
m_etsiTs103097Data_encrypted
(
m_encryptedData
(
{
m_recipientInfo_certRecipInfo
(
m_pKRecipientInfo
(
v_recipientId
,
v_encrypted_data_encryption_key
))
},
m_SymmetricCiphertext_aes128ccm
(
m_aesCcmCiphertext
(
p_nonce
,
v_encrypted_request
)
)
)
)
);
// The 'p_request_hash' shall be the SHA256 digest of the OER representation of the topmost EtsiTs103097Data-Encoded structure
v_enc_value
:=
encvalue
(
p_ieee1609dot2_signed_and_encrypted_data
);
if
(
PICS_SEC_FIXED_KEYS
)
{
p_request_hash
:=
'
10
ED97A2F2933DD3AC55F47022D125E18F5E1AA024613E616A75BA4979EFE318
'
O
;
}
else
{
p_request_hash
:=
f_hashWithSha256
(
bit2oct
(
v_enc_value
));
}
log
(
"f_build_pki_secured_request_message: p_request_hash= "
,
p_request_hash
);
log
(
"<<< f_build_pki_secured_request_message: "
,
p_ieee1609dot2_signed_and_encrypted_data
);
return
true
;
}
// End of function f_build_pki_secured_request_message_for_authorization
/**
* @desc Build a signed and encrypted PKI response message
* @param p_private_key Private key for signature
...
...
ttcn/Security/LibItsSecurity_Templates.ttcn
View file @
467ea0b7
...
...
@@ -1259,7 +1259,7 @@ module LibItsSecurity_Templates {
group
issuerIdentifier
{
template
(
value
)
IssuerIdentifier
m_issuerIdentifier_self
(
in
template
(
value
)
HashAlgorithm
p_self
in
template
(
value
)
HashAlgorithm
p_self
:=
sha256
)
:=
{
self_
:=
p_self
}
// End of template m_issuerIdentifier_self
...
...
@@ -1409,6 +1409,29 @@ module LibItsSecurity_Templates {
verifyKeyIndicator
:=
p_verifyKeyIndicator
}
// End of template mw_toBeSignedCertificate_ea
template
(
omit
)
ToBeSignedCertificate
m_toBeSignedCertificate_ec
(
in
template
(
value
)
CertificateId
p_id
,
in
template
(
value
)
SequenceOfPsidSsp
p_appPermissions
,
in
template
(
value
)
VerificationKeyIndicator
p_verifyKeyIndicator
,
in
template
(
value
)
ValidityPeriod
p_validityPeriod
,
in
template
(
omit
)
GeographicRegion
p_region
:=
omit
,
in
template
(
omit
)
SubjectAssurance
p_assuranceLevel
:=
omit
,
in
template
(
omit
)
PublicEncryptionKey
p_encryptionKey
:=
omit
)
:=
{
id
:=
p_id
,
cracaId
:=
'000000'O
,
// ETSI TS 103 097 V1.3.1 Clause 6 Bullet 2
crlSeries
:=
0
,
// ETSI TS 103 097 V1.3.1 Clause 6 Bullet 3
validityPeriod
:=
p_validityPeriod
,
region
:=
p_region
,
assuranceLevel
:=
p_assuranceLevel
,
appPermissions
:=
p_appPermissions
,
certIssuePermissions
:=
omit
,
certRequestPermissions
:=
omit
,
canRequestRollover
:=
omit
,
encryptionKey
:=
p_encryptionKey
,
verifyKeyIndicator
:=
p_verifyKeyIndicator
}
// End of template m_toBeSignedCertificate_ec
/**
* @desc Send template for ToBeSignedCertificate with Enrolment credential restrictions
* @see ETSI TS 103 097 V1.3.1 Clause 7.2.2 Enrolment credential
...
...
@@ -1419,7 +1442,8 @@ module LibItsSecurity_Templates {
template
(
present
)
VerificationKeyIndicator
p_verifyKeyIndicator
:=
?
,
template
(
present
)
ValidityPeriod
p_validityPeriod
:=
?
,
template
GeographicRegion
p_region
:=
*
,
template
SubjectAssurance
p_assuranceLevel
:=
*
template
SubjectAssurance
p_assuranceLevel
:=
*
,
template
PublicEncryptionKey
p_encryptionKey
:=
*
)
:=
{
id
:=
p_id
,
cracaId
:=
'000000'O
,
// ETSI TS 103 097 V1.3.1 Clause 6 Bullet 2
...
...
@@ -1431,7 +1455,7 @@ module LibItsSecurity_Templates {
certIssuePermissions
:=
omit
,
certRequestPermissions
:=
omit
,
canRequestRollover
:=
omit
,
encryptionKey
:=
omit
,
encryptionKey
:=
p_encryptionKey
,
verifyKeyIndicator
:=
p_verifyKeyIndicator
}
// End of template mw_toBeSignedCertificate_ec
...
...