diff options
Diffstat (limited to 'libtransport/includes/hicn/transport/auth/signer.h')
-rw-r--r-- | libtransport/includes/hicn/transport/auth/signer.h | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/libtransport/includes/hicn/transport/auth/signer.h b/libtransport/includes/hicn/transport/auth/signer.h index 405dd83cf..f9e07efae 100644 --- a/libtransport/includes/hicn/transport/auth/signer.h +++ b/libtransport/includes/hicn/transport/auth/signer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2021 Cisco and/or its affiliates. + * Copyright (c) 2021 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -21,18 +21,19 @@ #include <hicn/transport/errors/errors.h> #include <hicn/transport/utils/membuf.h> +#include <memory> extern "C" { #include <openssl/evp.h> #include <openssl/hmac.h> +#include <openssl/pkcs12.h> +#include <openssl/x509.h> } namespace transport { namespace auth { -class Identity; class Signer { // The base class from which all signer classes derive. - friend class Identity; public: Signer(); @@ -41,11 +42,15 @@ class Signer { // Sign a packet. virtual void signPacket(PacketPtr packet); + virtual void signBuffer(const uint8_t *buffer, std::size_t len); virtual void signBuffer(const std::vector<uint8_t> &buffer); virtual void signBuffer(const utils::MemBuf *buffer); // Return the signature. - std::vector<uint8_t> getSignature() const; + const utils::MemBuf::Ptr &getSignature() const; + + // Return the signature as a string. + std::string getStringSignature() const; // Return the signature size in bytes. virtual std::size_t getSignatureSize() const; @@ -61,9 +66,12 @@ class Signer { // Return the hash algorithm associated to the signer. CryptoHashType getHashType() const; + // Print signature to stdout. + void display(); + protected: CryptoSuite suite_; - std::vector<uint8_t> signature_; + utils::MemBuf::Ptr signature_; std::size_t signature_len_; std::shared_ptr<EVP_PKEY> key_; CryptoHash key_id_; @@ -75,6 +83,7 @@ class VoidSigner : public Signer { VoidSigner() = default; void signPacket(PacketPtr packet) override; + void signBuffer(const uint8_t *buffer, std::size_t len) override; void signBuffer(const std::vector<uint8_t> &buffer) override; void signBuffer(const utils::MemBuf *buffer) override; }; @@ -84,10 +93,17 @@ class AsymmetricSigner : public Signer { public: AsymmetricSigner() = default; - // Construct an AsymmetricSigner from a key store and a given crypto suite. + // Create an AsymmetricSigner from a keystore file (.p12). + AsymmetricSigner(std::string keystore_path, std::string password); + + // Construct an AsymmetricSigner from a key store and a given crypto + // suite. AsymmetricSigner(CryptoSuite suite, std::shared_ptr<EVP_PKEY> key, std::shared_ptr<EVP_PKEY> pub_key); + void setKey(CryptoSuite suite, std::shared_ptr<EVP_PKEY> key, + std::shared_ptr<EVP_PKEY> pub_key); + std::size_t getSignatureFieldSize() const override; }; |