1 // Copyright (c) 2023 The Chromium Authors. All rights reserved. 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 QUICHE_BLIND_SIGN_AUTH_BLIND_SIGN_MESSAGE_INTERFACE_H_ 6 #define QUICHE_BLIND_SIGN_AUTH_BLIND_SIGN_MESSAGE_INTERFACE_H_ 7 8 #include <optional> 9 #include <string> 10 11 #include "absl/status/statusor.h" 12 #include "absl/strings/string_view.h" 13 #include "quiche/blind_sign_auth/blind_sign_http_response.h" 14 #include "quiche/common/platform/api/quiche_export.h" 15 #include "quiche/common/quiche_callbacks.h" 16 17 namespace quiche { 18 19 using BlindSignHttpCallback = 20 quiche::SingleUseCallback<void(absl::StatusOr<BlindSignHttpResponse>)>; 21 22 enum class BlindSignHttpRequestType { 23 kUnknown = 0, 24 kGetInitialData, 25 kAuthAndSign, 26 }; 27 28 // Interface for async HTTP POST requests in BlindSignAuth. 29 // Implementers must send a request to a signer server's URL 30 // and call the provided callback when the request is complete. 31 class QUICHE_EXPORT BlindSignMessageInterface { 32 public: 33 virtual ~BlindSignMessageInterface() = default; 34 // Non-HTTP errors (like failing to create a socket) must return an 35 // absl::Status. 36 // HTTP errors must set status_code and body in BlindSignHttpResponse. 37 // DoRequest must be a HTTP POST request. 38 // Requests do not need cookies and must follow redirects. 39 // The implementer must set Content-Type and Accept headers to 40 // "application/x-protobuf". 41 // DoRequest is async. When the request completes, the implementer must call 42 // the provided callback. 43 virtual void DoRequest(BlindSignHttpRequestType request_type, 44 std::optional<absl::string_view> authorization_header, 45 const std::string& body, 46 BlindSignHttpCallback callback) = 0; 47 }; 48 49 } // namespace quiche 50 51 #endif // QUICHE_BLIND_SIGN_AUTH_BLIND_SIGN_MESSAGE_INTERFACE_H_ 52