1 // Copyright 2024 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 #ifndef NET_DEVICE_BOUND_SESSIONS_SESSION_BINDING_UTILS_H_ 6 #define NET_DEVICE_BOUND_SESSIONS_SESSION_BINDING_UTILS_H_ 7 8 #include <optional> 9 #include <string> 10 #include <string_view> 11 12 #include "base/containers/span.h" 13 #include "crypto/signature_verifier.h" 14 #include "net/base/net_export.h" 15 16 class GURL; 17 18 namespace base { 19 class Time; 20 } 21 22 namespace net::device_bound_sessions { 23 24 // Creates header and payload parts of a registration JWT. 25 std::optional<std::string> NET_EXPORT CreateKeyRegistrationHeaderAndPayload( 26 std::string_view challenge, 27 const GURL& registration_url, 28 crypto::SignatureVerifier::SignatureAlgorithm algorithm, 29 base::span<const uint8_t> pubkey_spki, 30 base::Time timestamp, 31 std::optional<std::string> authorization); 32 33 // Appends `signature` generated by `algorithm` to provided `header_and_payload` 34 // to form a complete JWT. 35 std::optional<std::string> NET_EXPORT AppendSignatureToHeaderAndPayload( 36 std::string_view header_and_payload, 37 crypto::SignatureVerifier::SignatureAlgorithm algorithm, 38 base::span<const uint8_t> signature); 39 40 } // namespace net::device_bound_sessions 41 42 #endif // NET_DEVICE_BOUND_SESSIONS_SESSION_BINDING_UTILS_H_ 43