proxygen
TokenBindingConstructorTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #include <gmock/gmock.h>
10 #include <gtest/gtest.h>
11 
14 
15 using namespace folly;
16 using namespace folly::ssl;
17 
18 using namespace testing;
19 
20 namespace fizz {
21 namespace extensions {
22 namespace test {
23 
25  "1234567890012345689012345678901234567890123456789012345678901234"};
26 
28  public:
29  void SetUp() override {
30  OpenSSL_add_all_algorithms();
31  EcKeyUniquePtr ecKey(EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
32  key_ = EvpPkeyUniquePtr(EVP_PKEY_new());
33  if (!ecKey || !key_) {
34  throw std::runtime_error("Unable to initialize key");
35  }
36  if (EC_KEY_generate_key(ecKey.get()) != 1) {
37  throw std::runtime_error("Unable to generate EC Key");
38  }
39  if (EVP_PKEY_set1_EC_KEY(key_.get(), ecKey.get()) != 1) {
40  throw std::runtime_error("Unable to set EC key");
41  }
42  }
43 
45  auto data = unhexlify(hex);
46  return folly::IOBuf::copyBuffer(data.data(), data.size());
47  }
48 
50 };
51 
52 TEST_F(TokenBindingConstructorTest, TestSignAndValidate) {
53  auto ekmBuf = getBuf(ekm);
54  auto binding = TokenBindingConstructor::createTokenBinding(
55  *key_.get(),
56  ekmBuf,
57  TokenBindingKeyParameters::ecdsap256,
58  TokenBindingType::provided_token_binding);
60  Validator::validateTokenBinding(
61  std::move(binding), ekmBuf, TokenBindingKeyParameters::ecdsap256)
62  .hasValue());
63 }
64 
66  auto badKey = EvpPkeyUniquePtr(EVP_PKEY_new());
67  auto ekmBuf = getBuf(ekm);
69  TokenBindingConstructor::createTokenBinding(
70  *badKey.get(),
71  ekmBuf,
72  TokenBindingKeyParameters::ecdsap256,
73  TokenBindingType::provided_token_binding),
74  std::runtime_error);
75 }
76 } // namespace test
77 } // namespace extensions
78 } // namespace fizz
bool unhexlify(const InputString &input, OutputString &output)
Definition: String-inl.h:616
#define EXPECT_THROW(statement, expected_exception)
Definition: gtest.h:1843
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< EVP_PKEY, EvpPkeyDeleter > EvpPkeyUniquePtr
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
std::unique_ptr< EC_KEY, EcKeyDeleter > EcKeyUniquePtr
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
Definition: Actions.h:16
TEST_F(AsyncSSLSocketWriteTest, write_coalescing1)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587