proxygen
fizz::OpenSSLSignature< T > Class Template Reference

#include <Signature.h>

Public Member Functions

void setKey (folly::ssl::EvpPkeyUniquePtr pkey)
 
template<SignatureScheme Scheme>
std::unique_ptr< folly::IOBufsign (folly::ByteRange data) const
 
template<SignatureScheme Scheme>
void verify (folly::ByteRange data, folly::ByteRange signature) const
 
template<>
void setKey (folly::ssl::EvpPkeyUniquePtr pkey)
 
template<>
void setKey (folly::ssl::EvpPkeyUniquePtr pkey)
 
template<>
void setKey (folly::ssl::EvpPkeyUniquePtr pkey)
 
template<>
void setKey (folly::ssl::EvpPkeyUniquePtr pkey)
 

Private Attributes

folly::ssl::EvpPkeyUniquePtr pkey_
 

Detailed Description

template<KeyType T>
class fizz::OpenSSLSignature< T >

Signature implementation using OpenSSL.

Definition at line 23 of file Signature.h.

Member Function Documentation

template<KeyType T>
void fizz::OpenSSLSignature< T >::setKey ( folly::ssl::EvpPkeyUniquePtr  pkey)
template<>
void fizz::OpenSSLSignature< KeyType::P256 >::setKey ( folly::ssl::EvpPkeyUniquePtr  pkey)
inline

Definition at line 102 of file Signature-inl.h.

References folly::gen::move, and fizz::detail::validateECKey().

103  {
104  detail::validateECKey(pkey, NID_X9_62_prime256v1);
105  pkey_ = std::move(pkey);
106 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void validateECKey(const folly::ssl::EvpPkeyUniquePtr &key, int curveNid)
folly::ssl::EvpPkeyUniquePtr pkey_
Definition: Signature.h:48
template<>
void fizz::OpenSSLSignature< KeyType::P384 >::setKey ( folly::ssl::EvpPkeyUniquePtr  pkey)
inline

Definition at line 109 of file Signature-inl.h.

References folly::gen::move, and fizz::detail::validateECKey().

110  {
111  detail::validateECKey(pkey, NID_secp384r1);
112  pkey_ = std::move(pkey);
113 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void validateECKey(const folly::ssl::EvpPkeyUniquePtr &key, int curveNid)
folly::ssl::EvpPkeyUniquePtr pkey_
Definition: Signature.h:48
template<>
void fizz::OpenSSLSignature< KeyType::P521 >::setKey ( folly::ssl::EvpPkeyUniquePtr  pkey)
inline

Definition at line 116 of file Signature-inl.h.

References folly::gen::move, and fizz::detail::validateECKey().

117  {
118  detail::validateECKey(pkey, NID_secp521r1);
119  pkey_ = std::move(pkey);
120 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void validateECKey(const folly::ssl::EvpPkeyUniquePtr &key, int curveNid)
folly::ssl::EvpPkeyUniquePtr pkey_
Definition: Signature.h:48
template<>
void fizz::OpenSSLSignature< KeyType::RSA >::setKey ( folly::ssl::EvpPkeyUniquePtr  pkey)
inline

Definition at line 123 of file Signature-inl.h.

References folly::gen::move.

124  {
125  if (EVP_PKEY_id(pkey.get()) != EVP_PKEY_RSA) {
126  throw std::runtime_error("key not rsa");
127  }
128  pkey_ = std::move(pkey);
129 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::ssl::EvpPkeyUniquePtr pkey_
Definition: Signature.h:48
template<KeyType Type>
template<SignatureScheme Scheme>
std::unique_ptr< folly::IOBuf > fizz::OpenSSLSignature< Type >::sign ( folly::ByteRange  data) const
inline

Returns a signature of data.

Only valid for SignatureSchemes that are compatible with KeyType.

setKey() must be called before with a private key.

Definition at line 69 of file Signature-inl.h.

References folly::assume_unreachable(), fizz::detail::ecSign(), fizz::P256, fizz::P384, fizz::P521, fizz::RSA, and fizz::detail::rsaPssSign().

Referenced by fizz::test::TEST_F(), and fizz::testing::TEST_P().

70  {
71  static_assert(
72  SigAlg<Scheme>::type == Type, "Called with mismatched type and scheme");
73  switch (Type) {
74  case KeyType::P256:
75  case KeyType::P384:
76  case KeyType::P521:
77  return detail::ecSign(data, pkey_, SigAlg<Scheme>::HashNid);
78  case KeyType::RSA:
79  return detail::rsaPssSign(data, pkey_, SigAlg<Scheme>::HashNid);
80  }
82 }
PskType type
FOLLY_ALWAYS_INLINE void assume_unreachable()
Definition: Assume.h:59
std::unique_ptr< folly::IOBuf > ecSign(folly::ByteRange data, const folly::ssl::EvpPkeyUniquePtr &pkey, int hashNid)
Definition: Signature.cpp:30
folly::ssl::EvpPkeyUniquePtr pkey_
Definition: Signature.h:48
std::unique_ptr< folly::IOBuf > rsaPssSign(folly::ByteRange data, const folly::ssl::EvpPkeyUniquePtr &pkey, int hashNid)
Definition: Signature.cpp:85
template<KeyType Type>
template<SignatureScheme Scheme>
void fizz::OpenSSLSignature< Type >::verify ( folly::ByteRange  data,
folly::ByteRange  signature 
) const
inline

Verifies that signature is a valid signature over data. Throws if it's not.

Only valid for SignatureSchemes that are compatible with KeyType.

setKey() must be called before.

Definition at line 86 of file Signature-inl.h.

References folly::assume_unreachable(), fizz::detail::ecVerify(), fizz::P256, fizz::P384, fizz::P521, fizz::RSA, and fizz::detail::rsaPssVerify().

Referenced by fizz::test::TEST_F(), and fizz::testing::TEST_P().

88  {
89  switch (Type) {
90  case KeyType::P256:
91  case KeyType::P384:
92  case KeyType::P521:
93  return detail::ecVerify(data, signature, pkey_, SigAlg<Scheme>::HashNid);
94  case KeyType::RSA:
95  return detail::rsaPssVerify(
96  data, signature, pkey_, SigAlg<Scheme>::HashNid);
97  }
99 }
void rsaPssVerify(folly::ByteRange data, folly::ByteRange signature, const folly::ssl::EvpPkeyUniquePtr &pkey, int hashNid)
Definition: Signature.cpp:123
FOLLY_ALWAYS_INLINE void assume_unreachable()
Definition: Assume.h:59
folly::ssl::EvpPkeyUniquePtr pkey_
Definition: Signature.h:48
void ecVerify(folly::ByteRange data, folly::ByteRange signature, const folly::ssl::EvpPkeyUniquePtr &pkey, int hashNid)
Definition: Signature.cpp:59

Member Data Documentation

template<KeyType T>
folly::ssl::EvpPkeyUniquePtr fizz::OpenSSLSignature< T >::pkey_
private

Definition at line 48 of file Signature.h.


The documentation for this class was generated from the following files: