From 08233d44a6cfde878d7e10bca38ae935ed1c8fd5 Mon Sep 17 00:00:00 2001 From: Mauro Date: Wed, 30 Jun 2021 07:57:22 +0000 Subject: [HICN-713] Transport Library Major Refactoring 2 Co-authored-by: Luca Muscariello Co-authored-by: Michele Papalini Co-authored-by: Olivier Roques Co-authored-by: Giulio Grassi Signed-off-by: Mauro Sardara Change-Id: I5b2c667bad66feb45abdb5effe22ed0f6c85d1c2 --- libtransport/includes/hicn/transport/auth/signer.h | 69 +++++++++++++--------- 1 file changed, 41 insertions(+), 28 deletions(-) (limited to 'libtransport/includes/hicn/transport/auth/signer.h') diff --git a/libtransport/includes/hicn/transport/auth/signer.h b/libtransport/includes/hicn/transport/auth/signer.h index fd5c4e6c6..405dd83cf 100644 --- a/libtransport/includes/hicn/transport/auth/signer.h +++ b/libtransport/includes/hicn/transport/auth/signer.h @@ -16,62 +16,79 @@ #pragma once #include +#include +#include #include +#include extern "C" { -#include -#include -#include -#include +#include +#include } namespace transport { namespace auth { +class Identity; class Signer { // The base class from which all signer classes derive. + friend class Identity; + public: Signer(); - Signer(PARCSigner *signer); - virtual ~Signer(); // Sign a packet. virtual void signPacket(PacketPtr packet); + virtual void signBuffer(const std::vector &buffer); + virtual void signBuffer(const utils::MemBuf *buffer); + + // Return the signature. + std::vector getSignature() const; - // Set the signer object used to sign packets. - void setSigner(PARCSigner *signer); + // Return the signature size in bytes. + virtual std::size_t getSignatureSize() const; - // Return the signature size. - size_t getSignatureSize() const; + // Return the field size necessary to hold the signature. The field size is + // always a multiple of 4. Use this function when allocating the signature + // packet header. + virtual std::size_t getSignatureFieldSize() const; // Return the crypto suite associated to the signer. - CryptoSuite getCryptoSuite() const; + CryptoSuite getSuite() const; // Return the hash algorithm associated to the signer. - CryptoHashType getCryptoHashType() const; + CryptoHashType getHashType() const; - // Return the PARC signer. - PARCSigner *getParcSigner() const; + protected: + CryptoSuite suite_; + std::vector signature_; + std::size_t signature_len_; + std::shared_ptr key_; + CryptoHash key_id_; +}; - // Return the PARC key store containing the signer key. - PARCKeyStore *getParcKeyStore() const; +class VoidSigner : public Signer { + // This class is the default socket signer. It does not sign packet. + public: + VoidSigner() = default; - protected: - PARCSigner *signer_; - PARCKeyId *key_id_; + void signPacket(PacketPtr packet) override; + void signBuffer(const std::vector &buffer) override; + void signBuffer(const utils::MemBuf *buffer) override; }; class AsymmetricSigner : public Signer { - // This class uses asymmetric verification to sign packets. The public key - // must be given from a PARCKeyStore. + // This class uses asymmetric verification to sign packets. public: AsymmetricSigner() = default; - AsymmetricSigner(PARCSigner *signer) : Signer(signer){}; // Construct an AsymmetricSigner from a key store and a given crypto suite. - AsymmetricSigner(CryptoSuite suite, PARCKeyStore *key_store); + AsymmetricSigner(CryptoSuite suite, std::shared_ptr key, + std::shared_ptr pub_key); + + std::size_t getSignatureFieldSize() const override; }; class SymmetricSigner : public Signer { @@ -79,12 +96,8 @@ class SymmetricSigner : public Signer { // key is derived from a passphrase. public: SymmetricSigner() = default; - SymmetricSigner(PARCSigner *signer) : Signer(signer){}; - - // Construct an SymmetricSigner from a key store and a given crypto suite. - SymmetricSigner(CryptoSuite suite, PARCKeyStore *key_store); - // Construct an AsymmetricSigner from a passphrase and a given crypto suite. + // Construct a SymmetricSigner from a passphrase and a given crypto suite. SymmetricSigner(CryptoSuite suite, const std::string &passphrase); }; -- cgit 1.2.3-korg