aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/test_cvc.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-05 06:23:21 +0000
committerlloyd <[email protected]>2014-01-05 06:23:21 +0000
commitc431fb65b883a0a5fa060ea7caace0aca3628ec6 (patch)
tree09898d2307801bffa7e1aeee9251d57ed4837870 /src/tests/test_cvc.cpp
parent052345203b67eb5cacacd5659ec9837eeb59af35 (diff)
Split up public key tests and data, use new test framework
Diffstat (limited to 'src/tests/test_cvc.cpp')
-rw-r--r--src/tests/test_cvc.cpp68
1 files changed, 34 insertions, 34 deletions
diff --git a/src/tests/test_cvc.cpp b/src/tests/test_cvc.cpp
index 205b74ec8..9519f0926 100644
--- a/src/tests/test_cvc.cpp
+++ b/src/tests/test_cvc.cpp
@@ -28,7 +28,7 @@
#include <botan/cvc_cert.h>
#include <botan/cvc_ado.h>
-#define TEST_DATA_DIR CHECKS_DIR "/ecc_testdata"
+#define CVC_TEST_DATA_DIR TEST_DATA_DIR "/ecc"
using namespace Botan;
@@ -94,21 +94,21 @@ void test_enc_gen_selfsigned(RandomNumberGenerator& rng)
std::vector<byte> der(cert.BER_encode());
std::ofstream cert_file;
- cert_file.open(TEST_DATA_DIR "/my_cv_cert.ber", std::ios::binary);
+ cert_file.open(CVC_TEST_DATA_DIR "/my_cv_cert.ber", std::ios::binary);
//cert_file << der; // this is bad !!!
cert_file.write((char*)&der[0], der.size());
cert_file.close();
- EAC1_1_CVC cert_in(TEST_DATA_DIR "/my_cv_cert.ber");
+ EAC1_1_CVC cert_in(CVC_TEST_DATA_DIR "/my_cv_cert.ber");
CHECK(cert == cert_in);
// encoding it again while it has no dp
std::vector<byte> der2(cert_in.BER_encode());
- std::ofstream cert_file2(TEST_DATA_DIR "/my_cv_cert2.ber", std::ios::binary);
+ std::ofstream cert_file2(CVC_TEST_DATA_DIR "/my_cv_cert2.ber", std::ios::binary);
cert_file2.write((char*)&der2[0], der2.size());
cert_file2.close();
// read both and compare them
- std::ifstream cert_1_in(TEST_DATA_DIR "/my_cv_cert.ber");
- std::ifstream cert_2_in(TEST_DATA_DIR "/my_cv_cert2.ber");
+ std::ifstream cert_1_in(CVC_TEST_DATA_DIR "/my_cv_cert.ber");
+ std::ifstream cert_2_in(CVC_TEST_DATA_DIR "/my_cv_cert2.ber");
std::vector<byte> sv1;
std::vector<byte> sv2;
if (!cert_1_in || !cert_2_in)
@@ -200,12 +200,12 @@ void test_enc_gen_req(RandomNumberGenerator& rng)
key.set_parameter_encoding(EC_DOMPAR_ENC_IMPLICITCA);
EAC1_1_Req req = CVC_EAC::create_cvc_req(key, opts.chr, opts.hash_alg, rng);
std::vector<byte> der(req.BER_encode());
- std::ofstream req_file(TEST_DATA_DIR "/my_cv_req.ber", std::ios::binary);
+ std::ofstream req_file(CVC_TEST_DATA_DIR "/my_cv_req.ber", std::ios::binary);
req_file.write((char*)&der[0], der.size());
req_file.close();
// read and check signature...
- EAC1_1_Req req_in(TEST_DATA_DIR "/my_cv_req.ber");
+ EAC1_1_Req req_in(CVC_TEST_DATA_DIR "/my_cv_req.ber");
//req_in.set_domain_parameters(dom_pars);
std::unique_ptr<Public_Key> p_pk(req_in.subject_public_key());
ECDSA_PublicKey* p_ecdsa_pk = dynamic_cast<ECDSA_PublicKey*>(p_pk.get());
@@ -217,7 +217,7 @@ void test_enc_gen_req(RandomNumberGenerator& rng)
void test_cvc_req_ext(RandomNumberGenerator&)
{
- EAC1_1_Req req_in(TEST_DATA_DIR "/DE1_flen_chars_cvcRequest_ECDSA.der");
+ EAC1_1_Req req_in(CVC_TEST_DATA_DIR "/DE1_flen_chars_cvcRequest_ECDSA.der");
EC_Group dom_pars(OID("1.3.36.3.3.2.8.1.1.5")); // "german curve"
//req_in.set_domain_parameters(dom_pars);
std::unique_ptr<Public_Key> p_pk(req_in.subject_public_key());
@@ -230,7 +230,7 @@ void test_cvc_req_ext(RandomNumberGenerator&)
void test_cvc_ado_ext(RandomNumberGenerator&)
{
- EAC1_1_ADO req_in(TEST_DATA_DIR "/ado.cvcreq");
+ EAC1_1_ADO req_in(CVC_TEST_DATA_DIR "/ado.cvcreq");
EC_Group dom_pars(OID("1.3.36.3.3.2.8.1.1.5")); // "german curve"
//cout << "car = " << req_in.get_car().value() << std::endl;
//req_in.set_domain_parameters(dom_pars);
@@ -251,7 +251,7 @@ void test_cvc_ado_creation(RandomNumberGenerator& rng)
//EAC1_1_Req req = CVC_EAC::create_cvc_req(req_key, opts);
EAC1_1_Req req = CVC_EAC::create_cvc_req(req_key, opts.chr, opts.hash_alg, rng);
std::vector<byte> der(req.BER_encode());
- std::ofstream req_file(TEST_DATA_DIR "/my_cv_req.ber", std::ios::binary);
+ std::ofstream req_file(CVC_TEST_DATA_DIR "/my_cv_req.ber", std::ios::binary);
req_file.write((char*)&der[0], der.size());
req_file.close();
@@ -265,12 +265,12 @@ void test_cvc_ado_creation(RandomNumberGenerator& rng)
EAC1_1_ADO ado = CVC_EAC::create_ado_req(ado_key, req, ado_opts.car, rng);
CHECK_MESSAGE(ado.check_signature(ado_key), "failure of ado verification after creation");
- std::ofstream ado_file(TEST_DATA_DIR "/ado", std::ios::binary);
+ std::ofstream ado_file(CVC_TEST_DATA_DIR "/ado", std::ios::binary);
std::vector<byte> ado_der(ado.BER_encode());
ado_file.write((char*)&ado_der[0], ado_der.size());
ado_file.close();
// read it again and check the signature
- EAC1_1_ADO ado2(TEST_DATA_DIR "/ado");
+ EAC1_1_ADO ado2(CVC_TEST_DATA_DIR "/ado");
CHECK(ado == ado2);
//ECDSA_PublicKey* p_ado_pk = dynamic_cast<ECDSA_PublicKey*>(&ado_key);
//bool ver = ado2.check_signature(*p_ado_pk);
@@ -319,13 +319,13 @@ void test_cvc_ado_comparison(RandomNumberGenerator& rng)
CHECK_MESSAGE(ado2.check_signature(ado_key2), "failure of ado verification after creation");
CHECK_MESSAGE(ado != ado2, "ado's found to be equal where they are not");
- // std::ofstream ado_file(TEST_DATA_DIR "/ado");
+ // std::ofstream ado_file(CVC_TEST_DATA_DIR "/ado");
// std::vector<byte> ado_der(ado.BER_encode());
// ado_file.write((char*)&ado_der[0], ado_der.size());
// ado_file.close();
// read it again and check the signature
- // EAC1_1_ADO ado2(TEST_DATA_DIR "/ado");
+ // EAC1_1_ADO ado2(CVC_TEST_DATA_DIR "/ado");
// ECDSA_PublicKey* p_ado_pk = dynamic_cast<ECDSA_PublicKey*>(&ado_key);
// //bool ver = ado2.check_signature(*p_ado_pk);
// bool ver = ado2.check_signature(ado_key);
@@ -369,7 +369,7 @@ void test_eac_time(RandomNumberGenerator&)
void test_ver_cvca(RandomNumberGenerator&)
{
- EAC1_1_CVC req_in(TEST_DATA_DIR "/cvca01.cv.crt");
+ EAC1_1_CVC req_in(CVC_TEST_DATA_DIR "/cvca01.cv.crt");
bool exc = false;
@@ -391,20 +391,20 @@ void test_ver_cvca(RandomNumberGenerator&)
void test_copy_and_assignment(RandomNumberGenerator&)
{
- EAC1_1_CVC cert_in(TEST_DATA_DIR "/cvca01.cv.crt");
+ EAC1_1_CVC cert_in(CVC_TEST_DATA_DIR "/cvca01.cv.crt");
EAC1_1_CVC cert_cp(cert_in);
EAC1_1_CVC cert_ass = cert_in;
CHECK(cert_in == cert_cp);
CHECK(cert_in == cert_ass);
- EAC1_1_ADO ado_in(TEST_DATA_DIR "/ado.cvcreq");
+ EAC1_1_ADO ado_in(CVC_TEST_DATA_DIR "/ado.cvcreq");
//EC_Group dom_pars(OID("1.3.36.3.3.2.8.1.1.5")); // "german curve"
EAC1_1_ADO ado_cp(ado_in);
EAC1_1_ADO ado_ass = ado_in;
CHECK(ado_in == ado_cp);
CHECK(ado_in == ado_ass);
- EAC1_1_Req req_in(TEST_DATA_DIR "/DE1_flen_chars_cvcRequest_ECDSA.der");
+ EAC1_1_Req req_in(CVC_TEST_DATA_DIR "/DE1_flen_chars_cvcRequest_ECDSA.der");
//EC_Group dom_pars(OID("1.3.36.3.3.2.8.1.1.5")); // "german curve"
EAC1_1_Req req_cp(req_in);
EAC1_1_Req req_ass = req_in;
@@ -417,7 +417,7 @@ void test_eac_str_illegal_values(RandomNumberGenerator&)
bool exc = false;
try
{
- EAC1_1_CVC(TEST_DATA_DIR "/cvca_illegal_chars.cv.crt");
+ EAC1_1_CVC(CVC_TEST_DATA_DIR "/cvca_illegal_chars.cv.crt");
}
catch (Decoding_Error)
@@ -429,7 +429,7 @@ void test_eac_str_illegal_values(RandomNumberGenerator&)
bool exc2 = false;
try
{
- EAC1_1_CVC(TEST_DATA_DIR "/cvca_illegal_chars2.cv.crt");
+ EAC1_1_CVC(CVC_TEST_DATA_DIR "/cvca_illegal_chars2.cv.crt");
}
catch (Decoding_Error)
@@ -465,7 +465,7 @@ void test_cvc_chain(RandomNumberGenerator& rng)
std::string hash("SHA-224");
ASN1_Car car("DECVCA00001");
EAC1_1_CVC cvca_cert = DE_EAC::create_cvca(cvca_privk, hash, car, true, true, 12, rng);
- std::ofstream cvca_file(TEST_DATA_DIR "/cvc_chain_cvca.cer", std::ios::binary);
+ std::ofstream cvca_file(CVC_TEST_DATA_DIR "/cvc_chain_cvca.cer", std::ios::binary);
std::vector<byte> cvca_sv = cvca_cert.BER_encode();
cvca_file.write((char*)&cvca_sv[0], cvca_sv.size());
cvca_file.close();
@@ -475,21 +475,21 @@ void test_cvc_chain(RandomNumberGenerator& rng)
EAC1_1_CVC cvca_cert2 = DE_EAC::create_cvca(cvca_privk2, hash, car2, true, true, 12, rng);
EAC1_1_CVC link12 = DE_EAC::link_cvca(cvca_cert, cvca_privk, cvca_cert2, rng);
std::vector<byte> link12_sv = link12.BER_encode();
- std::ofstream link12_file(TEST_DATA_DIR "/cvc_chain_link12.cer", std::ios::binary);
+ std::ofstream link12_file(CVC_TEST_DATA_DIR "/cvc_chain_link12.cer", std::ios::binary);
link12_file.write((char*)&link12_sv[0], link12_sv.size());
link12_file.close();
// verify the link
CHECK(link12.check_signature(cvca_privk));
- EAC1_1_CVC link12_reloaded(TEST_DATA_DIR "/cvc_chain_link12.cer");
- EAC1_1_CVC cvca1_reloaded(TEST_DATA_DIR "/cvc_chain_cvca.cer");
+ EAC1_1_CVC link12_reloaded(CVC_TEST_DATA_DIR "/cvc_chain_link12.cer");
+ EAC1_1_CVC cvca1_reloaded(CVC_TEST_DATA_DIR "/cvc_chain_cvca.cer");
std::unique_ptr<Public_Key> cvca1_rel_pk(cvca1_reloaded.subject_public_key());
CHECK(link12_reloaded.check_signature(*cvca1_rel_pk));
// create first round dvca-req
ECDSA_PrivateKey dvca_priv_key(rng, dom_pars);
EAC1_1_Req dvca_req = DE_EAC::create_cvc_req(dvca_priv_key, ASN1_Chr("DEDVCAEPASS"), hash, rng);
- std::ofstream dvca_file(TEST_DATA_DIR "/cvc_chain_dvca_req.cer", std::ios::binary);
+ std::ofstream dvca_file(CVC_TEST_DATA_DIR "/cvc_chain_dvca_req.cer", std::ios::binary);
std::vector<byte> dvca_sv = dvca_req.BER_encode();
dvca_file.write((char*)&dvca_sv[0], dvca_sv.size());
dvca_file.close();
@@ -498,18 +498,18 @@ void test_cvc_chain(RandomNumberGenerator& rng)
EAC1_1_CVC dvca_cert1 = DE_EAC::sign_request(cvca_cert, cvca_privk, dvca_req, 1, 5, true, 3, 1, rng);
CHECK(dvca_cert1.get_car().iso_8859() == "DECVCA00001");
CHECK(dvca_cert1.get_chr().iso_8859() == "DEDVCAEPASS00001");
- helper_write_file(dvca_cert1, TEST_DATA_DIR "/cvc_chain_dvca_cert1.cer");
+ helper_write_file(dvca_cert1, CVC_TEST_DATA_DIR "/cvc_chain_dvca_cert1.cer");
// make a second round dvca ado request
ECDSA_PrivateKey dvca_priv_key2(rng, dom_pars);
EAC1_1_Req dvca_req2 = DE_EAC::create_cvc_req(dvca_priv_key2, ASN1_Chr("DEDVCAEPASS"), hash, rng);
- std::ofstream dvca_file2(TEST_DATA_DIR "/cvc_chain_dvca_req2.cer", std::ios::binary);
+ std::ofstream dvca_file2(CVC_TEST_DATA_DIR "/cvc_chain_dvca_req2.cer", std::ios::binary);
std::vector<byte> dvca_sv2 = dvca_req2.BER_encode();
dvca_file2.write((char*)&dvca_sv2[0], dvca_sv2.size());
dvca_file2.close();
EAC1_1_ADO dvca_ado2 = CVC_EAC::create_ado_req(dvca_priv_key, dvca_req2,
ASN1_Car(dvca_cert1.get_chr().iso_8859()), rng);
- helper_write_file(dvca_ado2, TEST_DATA_DIR "/cvc_chain_dvca_ado2.cer");
+ helper_write_file(dvca_ado2, CVC_TEST_DATA_DIR "/cvc_chain_dvca_ado2.cer");
// verify the ado and sign the request too
@@ -518,14 +518,14 @@ void test_cvc_chain(RandomNumberGenerator& rng)
//cert_pk->set_domain_parameters(dom_pars);
//std::cout << "dvca_cert.public_point.size() = " << ec::EC2OSP(cert_pk->get_public_point(), ec::PointGFp::COMPRESSED).size() << std::endl;
- EAC1_1_CVC dvca_cert1_reread(TEST_DATA_DIR "/cvc_chain_cvca.cer");
+ EAC1_1_CVC dvca_cert1_reread(CVC_TEST_DATA_DIR "/cvc_chain_cvca.cer");
CHECK(dvca_ado2.check_signature(*cert_pk));
CHECK(dvca_ado2.check_signature(dvca_priv_key)); // must also work
EAC1_1_Req dvca_req2b = dvca_ado2.get_request();
- helper_write_file(dvca_req2b, TEST_DATA_DIR "/cvc_chain_dvca_req2b.cer");
- CHECK(helper_files_equal(TEST_DATA_DIR "/cvc_chain_dvca_req2b.cer", TEST_DATA_DIR "/cvc_chain_dvca_req2.cer"));
+ helper_write_file(dvca_req2b, CVC_TEST_DATA_DIR "/cvc_chain_dvca_req2b.cer");
+ CHECK(helper_files_equal(CVC_TEST_DATA_DIR "/cvc_chain_dvca_req2b.cer", CVC_TEST_DATA_DIR "/cvc_chain_dvca_req2.cer"));
EAC1_1_CVC dvca_cert2 = DE_EAC::sign_request(cvca_cert, cvca_privk, dvca_req2b, 2, 5, true, 3, 1, rng);
CHECK(dvca_cert2.get_car().iso_8859() == "DECVCA00001");
CHECK_MESSAGE(dvca_cert2.get_chr().iso_8859() == "DEDVCAEPASS00002",
@@ -534,14 +534,14 @@ void test_cvc_chain(RandomNumberGenerator& rng)
// make a first round IS request
ECDSA_PrivateKey is_priv_key(rng, dom_pars);
EAC1_1_Req is_req = DE_EAC::create_cvc_req(is_priv_key, ASN1_Chr("DEIS"), hash, rng);
- helper_write_file(is_req, TEST_DATA_DIR "/cvc_chain_is_req.cer");
+ helper_write_file(is_req, CVC_TEST_DATA_DIR "/cvc_chain_is_req.cer");
// sign the IS request
//dvca_cert1.set_domain_parameters(dom_pars);
EAC1_1_CVC is_cert1 = DE_EAC::sign_request(dvca_cert1, dvca_priv_key, is_req, 1, 5, true, 3, 1, rng);
CHECK_MESSAGE(is_cert1.get_car().iso_8859() == "DEDVCAEPASS00001", "car = " << is_cert1.get_car().iso_8859());
CHECK(is_cert1.get_chr().iso_8859() == "DEIS00001");
- helper_write_file(is_cert1, TEST_DATA_DIR "/cvc_chain_is_cert.cer");
+ helper_write_file(is_cert1, CVC_TEST_DATA_DIR "/cvc_chain_is_cert.cer");
// verify the signature of the certificate
CHECK(is_cert1.check_signature(dvca_priv_key));