• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifdef UNSAFE_BUFFERS_BUILD
6 // TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
7 #pragma allow_unsafe_buffers
8 #endif
9 
10 #include "net/test/ssl_test_util.h"
11 
12 #include <string>
13 #include <string_view>
14 
15 #include "third_party/boringssl/src/include/openssl/hpke.h"
16 
17 namespace net {
18 
MakeTestEchKeys(std::string_view public_name,size_t max_name_len,std::vector<uint8_t> * ech_config_list)19 bssl::UniquePtr<SSL_ECH_KEYS> MakeTestEchKeys(
20     std::string_view public_name,
21     size_t max_name_len,
22     std::vector<uint8_t>* ech_config_list) {
23   bssl::ScopedEVP_HPKE_KEY key;
24   if (!EVP_HPKE_KEY_generate(key.get(), EVP_hpke_x25519_hkdf_sha256())) {
25     return nullptr;
26   }
27 
28   uint8_t* ech_config;
29   size_t ech_config_len;
30   if (!SSL_marshal_ech_config(&ech_config, &ech_config_len,
31                               /*config_id=*/1, key.get(),
32                               std::string(public_name).c_str(), max_name_len)) {
33     return nullptr;
34   }
35   bssl::UniquePtr<uint8_t> scoped_ech_config(ech_config);
36 
37   uint8_t* ech_config_list_raw;
38   size_t ech_config_list_len;
39   bssl::UniquePtr<SSL_ECH_KEYS> keys(SSL_ECH_KEYS_new());
40   if (!keys ||
41       !SSL_ECH_KEYS_add(keys.get(), /*is_retry_config=*/1, ech_config,
42                         ech_config_len, key.get()) ||
43       !SSL_ECH_KEYS_marshal_retry_configs(keys.get(), &ech_config_list_raw,
44                                           &ech_config_list_len)) {
45     return nullptr;
46   }
47   bssl::UniquePtr<uint8_t> scoped_ech_config_list(ech_config_list_raw);
48 
49   ech_config_list->assign(ech_config_list_raw,
50                           ech_config_list_raw + ech_config_list_len);
51   return keys;
52 }
53 
54 }  // namespace net
55