Newer
Older
// 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;
// AtsGenCert
import from ItsGenCert_TypeAndValues all;
import from ItsGenCert_Functions all;
import from ItsGenCert_TestSystem all;
import from ItsGenCert_Pics all;
testcase TC_GEN_CERT() runs on TCType system TCType {
var certificate_details_list v_certificate_details_list;
var integer v_idx := 0;
for (var integer v_counter := 0; v_counter < lengthof(PICS_CERTFICATES); v_counter := v_counter + 1) {
var certificate_details v_details;
var template (value) EtsiTs103097Certificate v_certificate;
var certificate_params v_certificate_params;
// Setup
v_certificate_params := PICS_CERTFICATES[v_counter];
v_details := { v_certificate_params.certificate_id, {}, ''O, ''O, ''O, ''O, '0000000000000000'O, '0000000000000000'O };
// Generate Private/Public keys for the certificate
if (f_generate_signing_keys(v_certificate_params, v_details) == -1) {
setverdict(fail, "Unsupported curve");
stop;
}
// Build the certificate templates
if (f_fill_certificate(v_certificate_params, v_details) == -1) {
setverdict(fail, "Failed to build the certificate templates");
stop;
}
// Generate the certificate
if (f_generate_certificate(v_certificate_params, v_details) == -1) {
setverdict(fail, "Failed to generate the certificate");
stop;
}
// Fianlyse certificate
if (f_finalyse_certificate(v_certificate_params, v_certificate_details_list, v_details) == -1) {
setverdict(fail, "Failed to finalyse the certificate");
stop;
}
v_certificate_details_list[v_idx] := v_details;
log("v_certificate_details_list = ", v_certificate_details_list);
// Store them
if (f_store_certificates(v_certificate_details_list) == -1) {
setverdict(fail, "Failed to finalyse the certificate");
stop;
} else {
setverdict(pass);
}
} // End of testcase TC_GEN_CERT
testcase TC_VALIDATE_CERT() runs on TCType system TCType {
var SequenceOfCertificate v_certificate_list;
var integer v_idx := 0;
// 1. Load certificates
fx_loadCertificates(PX_CERTIFICATE_POOL_PATH, PX_IUT_SEC_CONFIG_NAME);
// 2. Create the list of certificates
for (var integer v_counter := 0; v_counter < lengthof(PICS_CERTFICATES); v_counter := v_counter + 1) {
var EtsiTs103097Certificate v_certificate;
if (f_readCertificate(PICS_CERTFICATES[v_counter].certificate_id, v_certificate) == false) {
setverdict(fail, "Failed to read certificate ", PICS_CERTFICATES[v_counter].certificate_id);
stop;
} else {
v_certificate_list[v_idx] := v_certificate;
v_idx := v_idx + 1;
log("v_certificate_list = ", v_certificate_list);
// 3. Check signature
for (var integer v_counter := 0; v_counter < lengthof(v_certificate_list); v_counter := v_counter + 1) {
var EtsiTs103097Certificate v_certificate;
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
131
132
133
134
if (ischosen(v_certificate.issuer.self_)) {
if (f_verifyCertificateSignatureWithIssuingCertificate(v_certificate, v_certificate) == false) {
setverdict(fail, "Failed to verify signature for CA certificate ", v_certificate.toBeSigned.id.name);
stop;
}
} else {
var EtsiTs103097Certificate v_issuing_certificate;
var HashedId8 v_issuer;
if (ischosen(v_issuing_certificate.issuer.sha256AndDigest)) {
v_issuer := v_issuing_certificate.issuer.sha256AndDigest;
} else if (ischosen(v_issuing_certificate.issuer.sha256AndDigest)) {
v_issuer := v_issuing_certificate.issuer.sha384AndDigest;
} else {
setverdict(fail, "Unsupported issuer");
stop;
}
if (f_getCertificateFromDigest(v_issuer, v_issuing_certificate) == false) {
setverdict(fail, "Failed to get certificate from digest ", v_issuer);
stop;
}
if (f_verifyCertificateSignatureWithIssuingCertificate(v_certificate, v_issuing_certificate) == false) {
setverdict(fail, "Failed to verify signature for CA certificate ", v_certificate.toBeSigned.id.name);
stop;
}
}
} // End of 'for' statement
setverdict(pass);
} // End of testcase TC_VALIDATE_CERT
control {
execute(TC_GEN_CERT(), 1.0);
execute(TC_VALIDATE_CERT(), 1.0);
} // End of 'control' statement
} // End of module ItsGencert_TestCases