Skip to content

Commit

Permalink
Added back missing CSR test
Browse files Browse the repository at this point in the history
Signed-off-by: AssemblyJohn <[email protected]>
  • Loading branch information
AssemblyJohn committed May 27, 2024
1 parent c5f049c commit 937f4fa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/evse_security/crypto/interface/crypto_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace evse_security {
enum class CryptoKeyType {
EC_prime256v1, // Default EC. P-256, ~equiv to rsa 3072
EC_secp384r1, // P-384, ~equiv to rsa 7680
RSA_TPM20, // Default TPM RSA, only option allowed for TPM (universal support), 2048 bits
RSA_2048,
RSA_TPM20 = RSA_2048, // Default TPM RSA, only option allowed for TPM (universal support), 2048 bits
RSA_3072, // Default RSA. Protection lifetime: ~2030
RSA_7680, // Protection lifetime: >2031. Very long generation time 8-40s on 16 core PC
};
Expand Down
33 changes: 33 additions & 0 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,39 @@ TEST_F(EvseSecurityTests, verify_normal_keygen) {
ASSERT_TRUE(gen);
}

TEST_F(EvseSecurityTests, verify_keygen_csr) {
KeyGenerationInfo info;
KeyHandle_ptr key;

info.key_type = CryptoKeyType::EC_prime256v1;
info.generate_on_tpm = false;

info.public_key_file = fs::path("key/pubkey.key");
info.private_key_file = fs::path("key/privkey.key");

bool gen = CryptoSupplier::generate_key(info, key);
ASSERT_TRUE(gen);

CertificateSigningRequestInfo csr_info;
csr_info.n_version = 0;
csr_info.commonName = "pionix_01";
csr_info.organization = "PionixDE";
csr_info.country = "DE";

info.public_key_file = fs::path("key/csr_pubkey.tkey");
info.private_key_file = fs::path("key/csr_privkey.tkey");
info.key_type = CryptoKeyType::RSA_2048;

csr_info.key_info = info;

std::string csr;

auto csr_gen = CryptoSupplier::x509_generate_csr(csr_info, csr);
ASSERT_EQ(csr_gen, CertificateSignRequestResult::Valid);

std::cout << "Csr: " << std::endl << csr << std::endl;
}

/// \brief get_certificate_hash_data() throws exception if called with no issuer and a non-self-signed cert
TEST_F(EvseSecurityTests, get_certificate_hash_data_non_self_signed_requires_issuer) {
const auto non_self_signed_cert_str =
Expand Down

0 comments on commit 937f4fa

Please sign in to comment.