From b9da9c313e8b7362f347a4ff050fcf468ba26a08 Mon Sep 17 00:00:00 2001 From: Reece Date: Thu, 1 Jul 2021 10:32:52 +0100 Subject: [PATCH] [*] Amend crypto headers and type usage --- Include/Aurora/Crypto/CA/CA.hpp | 9 +++++++-- Include/Aurora/Crypto/Crypto.hpp | 8 +++++++- Include/Aurora/Crypto/ECC/25519/25519.hpp | 2 +- Include/Aurora/Crypto/ECC/NIST/NIST.hpp | 2 +- Include/Aurora/Crypto/PEM/PEM.hpp | 8 ++++---- Source/Crypto/PEM/PEM.cpp | 16 ++++++++-------- Source/Crypto/RSA/RSAPrivate.cpp | 2 +- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Include/Aurora/Crypto/CA/CA.hpp b/Include/Aurora/Crypto/CA/CA.hpp index 76b2963a..3a7a2fab 100644 --- a/Include/Aurora/Crypto/CA/CA.hpp +++ b/Include/Aurora/Crypto/CA/CA.hpp @@ -7,19 +7,24 @@ ***/ #pragma once +namespace Aurora::Crypto::RSA +{ + class IRSAPublic; +} + namespace Aurora::Crypto::CA { class ICertificateStore { public: - virtual void AddSignature(const PublicRSAKey& CA, const AuList& sig, + virtual void AddSignature(const AuSPtr& CA, const AuList& sig, EHashType method, EPaddingType type) = 0; virtual void AddPublicCert(const X509::Certificate& cert) = 0; /// For future support of http gets of the CA list virtual bool& AllowHTTPTree() = 0; - virtual bool CheckKey(const PublicKey& pub) = 0; + virtual bool CheckKey(const AuSPtr& pub) = 0; virtual bool CheckCert(const X509::Certificate& cert) = 0; }; diff --git a/Include/Aurora/Crypto/Crypto.hpp b/Include/Aurora/Crypto/Crypto.hpp index 9c786b61..48ee29d9 100644 --- a/Include/Aurora/Crypto/Crypto.hpp +++ b/Include/Aurora/Crypto/Crypto.hpp @@ -15,6 +15,12 @@ namespace Aurora::Crypto { using Certificate = AuList; } + + struct RSAPair + { + AuString certificate; + AuString privKey; + }; } #include "EHashType.hpp" @@ -25,4 +31,4 @@ namespace Aurora::Crypto #include "CA/CA.hpp" #include "ECC/ECC.hpp" #include "PEM/PEM.hpp" -#include "RSA/RSA.hpp" +#include "RSA/RSA.hpp" \ No newline at end of file diff --git a/Include/Aurora/Crypto/ECC/25519/25519.hpp b/Include/Aurora/Crypto/ECC/25519/25519.hpp index bffafa5e..4fdf5984 100644 --- a/Include/Aurora/Crypto/ECC/25519/25519.hpp +++ b/Include/Aurora/Crypto/ECC/25519/25519.hpp @@ -7,7 +7,7 @@ ***/ #pragma once -namespace Aurora::Crypto::ECC25519 +namespace Aurora::Crypto::ECC::C25519 { } \ No newline at end of file diff --git a/Include/Aurora/Crypto/ECC/NIST/NIST.hpp b/Include/Aurora/Crypto/ECC/NIST/NIST.hpp index 9fba724f..0943ed7b 100644 --- a/Include/Aurora/Crypto/ECC/NIST/NIST.hpp +++ b/Include/Aurora/Crypto/ECC/NIST/NIST.hpp @@ -7,7 +7,7 @@ ***/ #pragma once -namespace Aurora::Crypto::ECCNIST +namespace Aurora::Crypto::ECC::NIST { } \ No newline at end of file diff --git a/Include/Aurora/Crypto/PEM/PEM.hpp b/Include/Aurora/Crypto/PEM/PEM.hpp index f245b06f..9632c212 100644 --- a/Include/Aurora/Crypto/PEM/PEM.hpp +++ b/Include/Aurora/Crypto/PEM/PEM.hpp @@ -16,8 +16,8 @@ namespace Aurora::Crypto::PEM AUKN_SYM AuString PrivateRSAToString(const DerBuffer &in); AUKN_SYM bool FromString(const AuString &in, Aurora::Crypto::X509::Certificate &out); - AUKN_SYM bool PublicFromString(const AuString &in, PublicKey &out); - AUKN_SYM bool PrivateFromString(const AuString &in, PrivateKey &out); - AUKN_SYM bool PublicRSAFromString(const AuString &in, PrivateRSAKey &out); - AUKN_SYM bool PrivateRSAFromString(const AuString &in, PublicRSAKey &out); + AUKN_SYM bool PublicFromString(const AuString &in, DerBuffer &out); + AUKN_SYM bool PrivateFromString(const AuString &in, DerBuffer &out); + AUKN_SYM bool PublicRSAFromString(const AuString &in, DerBuffer &out); + AUKN_SYM bool PrivateRSAFromString(const AuString &in, DerBuffer &out); } \ No newline at end of file diff --git a/Source/Crypto/PEM/PEM.cpp b/Source/Crypto/PEM/PEM.cpp index 9a223f71..1f83f8a0 100644 --- a/Source/Crypto/PEM/PEM.cpp +++ b/Source/Crypto/PEM/PEM.cpp @@ -62,22 +62,22 @@ namespace Aurora::Crypto::PEM return SerializePEM("-----BEGIN CERTIFICATE-----", "-----END CERTIFICATE-----", in); } - AUKN_SYM AuString PrivateToString(const PrivateKey &in) + AUKN_SYM AuString PrivateToString(const DerBuffer &in) { return SerializePEM("-----BEGIN PRIVATE KEY-----", "-----END PRIVATE KEY-----", in); } - AUKN_SYM AuString PublicToString(const PublicKey &in) + AUKN_SYM AuString PublicToString(const DerBuffer &in) { return SerializePEM("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----", in); } - AUKN_SYM AuString PublicRSAToString(const PrivateRSAKey &in) + AUKN_SYM AuString PublicRSAToString(const DerBuffer &in) { return SerializePEM("-----BEGIN RSA PUBLIC KEY-----", "-----END RSA PUBLIC KEY-----", in); } - AUKN_SYM AuString PrivateRSAToString(const PublicRSAKey &in) + AUKN_SYM AuString PrivateRSAToString(const DerBuffer &in) { return SerializePEM("-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----", in); } @@ -87,22 +87,22 @@ namespace Aurora::Crypto::PEM return ParsePEM("-----BEGIN CERTIFICATE-----", "-----END CERTIFICATE-----", in, out); } - AUKN_SYM bool PrivateFromString(const AuString &in, PrivateKey &out) + AUKN_SYM bool PrivateFromString(const AuString &in, DerBuffer &out) { return ParsePEM("-----BEGIN PRIVATE KEY-----", "-----END PRIVATE KEY-----", in, out); } - AUKN_SYM bool PublicRSAFromString(const AuString &in, PrivateRSAKey &out) + AUKN_SYM bool PublicRSAFromString(const AuString &in, DerBuffer &out) { return ParsePEM("-----BEGIN RSA PUBLIC KEY-----", "-----END RSA PUBLIC KEY-----", in, out); } - AUKN_SYM bool PrivateRSAFromString(const AuString &in, PublicRSAKey &out) + AUKN_SYM bool PrivateRSAFromString(const AuString &in, DerBuffer &out) { return ParsePEM("-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----", in, out); } - AUKN_SYM bool PublicFromString(const AuString &in, PublicKey &out) + AUKN_SYM bool PublicFromString(const AuString &in, DerBuffer &out) { return ParsePEM("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----", in, out); } diff --git a/Source/Crypto/RSA/RSAPrivate.cpp b/Source/Crypto/RSA/RSAPrivate.cpp index 3b8a15d2..cbe4e985 100644 --- a/Source/Crypto/RSA/RSAPrivate.cpp +++ b/Source/Crypto/RSA/RSAPrivate.cpp @@ -158,7 +158,7 @@ namespace Aurora::Crypto::RSA if (key.meta.side == EKeyType::eKeyPublic) { SysPushErrorArg("Attempted to import a public key as a private key."); - return false; + return nullptr; } if (!ImportRSAKey(in, key))