proxygen
TokenBindingServerExtension.h
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 #pragma once
10 
13 #include <fizz/server/Negotiator.h>
15 
16 namespace fizz {
17 namespace extensions {
18 
20  public:
22  const std::shared_ptr<TokenBindingContext>& tokenBindingContext)
23  : tokenBindingContext_(tokenBindingContext) {}
24 
25  std::vector<Extension> getExtensions(const ClientHello& chlo) override {
26  std::vector<Extension> serverExtensions;
27  auto params = getExtension<TokenBindingParameters>(chlo.extensions);
28  if (params) {
29  auto negotiatedVersion = negotiateVersion(params->version);
30  auto negotiatedKeyParam = server::negotiate(
31  tokenBindingContext_->getKeyParams(), params->key_parameters_list);
32  if (negotiatedKeyParam && negotiatedVersion) {
33  TokenBindingParameters negotiatedParams;
34  negotiatedParams.version = *negotiatedVersion;
35  negotiatedParams.key_parameters_list.push_back(*negotiatedKeyParam);
36  serverExtensions.push_back(encodeExtension(negotiatedParams));
37  negotiatedKeyParam_ = std::move(negotiatedKeyParam);
38  }
39  }
40  return serverExtensions;
41  }
42  const auto& getNegotiatedKeyParam() {
43  return negotiatedKeyParam_;
44  }
45 
46  private:
47  std::shared_ptr<TokenBindingContext> tokenBindingContext_;
49 
55  const TokenBindingProtocolVersion& clientPref) {
56  for (const auto& pref : tokenBindingContext_->getSupportedVersions()) {
57  if (pref <= clientPref) {
58  return pref;
59  }
60  }
61  return folly::none;
62  }
63 };
64 } // namespace extensions
65 } // namespace fizz
std::vector< Extension > getExtensions(const ClientHello &chlo) override
static const std::string chlo
folly::Optional< T > negotiate(const std::vector< std::vector< T >> &serverPref, const std::vector< T > &clientPref)
Definition: Negotiator.h:22
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::Optional< TokenBindingProtocolVersion > negotiateVersion(const TokenBindingProtocolVersion &clientPref)
std::shared_ptr< TokenBindingContext > tokenBindingContext_
TokenBindingProtocolVersion version
Definition: Types.h:42
constexpr Params params[]
Definition: Actions.h:16
std::vector< Extension > extensions
Definition: Types.h:193
folly::Optional< TokenBindingKeyParameters > negotiatedKeyParam_
std::vector< TokenBindingKeyParameters > key_parameters_list
Definition: Types.h:43
TokenBindingProtocolVersion
Definition: Types.h:22
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
TokenBindingServerExtension(const std::shared_ptr< TokenBindingContext > &tokenBindingContext)
constexpr None none
Definition: Optional.h:87