3 * Copyright 2018 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #ifndef GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_CLIENT_H
20 #define GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_CLIENT_H
22 #include <grpc/support/port_platform.h>
24 #include <grpc/byte_buffer.h>
25 #include <grpc/byte_buffer_reader.h>
26 #include <grpc/grpc.h>
28 #include "src/core/tsi/alts/handshaker/alts_tsi_handshaker.h"
29 #include "src/core/tsi/transport_security_interface.h"
31 #include "src/core/lib/iomgr/closure.h"
32 #include "src/core/lib/iomgr/pollset_set.h"
34 #define ALTS_SERVICE_METHOD "/grpc.gcp.HandshakerService/DoHandshake"
35 #define ALTS_APPLICATION_PROTOCOL "grpc"
36 #define ALTS_RECORD_PROTOCOL "ALTSRP_GCM_AES128_REKEY"
37 #define ALTS_HANDSHAKER_SERVICE_URL_FOR_TESTING "lame"
39 const size_t kAltsAes128GcmRekeyKeyLength = 44;
41 typedef struct alts_tsi_handshaker alts_tsi_handshaker;
43 * A ALTS handshaker client interface. It is used to communicate with
44 * ALTS handshaker service by scheduling a handshaker request that could be one
45 * of client_start, server_start, and next handshaker requests. All APIs in the
46 * header are thread-compatible.
48 typedef struct alts_handshaker_client alts_handshaker_client;
50 /* A function that makes the grpc call to the handshaker service. */
51 typedef grpc_call_error (*alts_grpc_caller)(grpc_call* call, const grpc_op* ops,
52 size_t nops, grpc_closure* tag);
54 /* V-table for ALTS handshaker client operations. */
55 typedef struct alts_handshaker_client_vtable {
56 tsi_result (*client_start)(alts_handshaker_client* client);
57 tsi_result (*server_start)(alts_handshaker_client* client,
58 grpc_slice* bytes_received);
59 tsi_result (*next)(alts_handshaker_client* client,
60 grpc_slice* bytes_received);
61 void (*shutdown)(alts_handshaker_client* client);
62 void (*destruct)(alts_handshaker_client* client);
63 } alts_handshaker_client_vtable;
66 * This method schedules a client_start handshaker request to ALTS handshaker
69 * - client: ALTS handshaker client instance.
71 * It returns TSI_OK on success and an error status code on failure.
73 tsi_result alts_handshaker_client_start_client(alts_handshaker_client* client);
76 * This method schedules a server_start handshaker request to ALTS handshaker
79 * - client: ALTS handshaker client instance.
80 * - bytes_received: bytes in out_frames returned from the peer's handshaker
83 * It returns TSI_OK on success and an error status code on failure.
85 tsi_result alts_handshaker_client_start_server(alts_handshaker_client* client,
86 grpc_slice* bytes_received);
89 * This method schedules a next handshaker request to ALTS handshaker service.
91 * - client: ALTS handshaker client instance.
92 * - bytes_received: bytes in out_frames returned from the peer's handshaker
95 * It returns TSI_OK on success and an error status code on failure.
97 tsi_result alts_handshaker_client_next(alts_handshaker_client* client,
98 grpc_slice* bytes_received);
101 * This method cancels previously scheduled, but yet executed handshaker
102 * requests to ALTS handshaker service. After this operation, the handshake
103 * will be shutdown, and no more handshaker requests will get scheduled.
105 * - client: ALTS handshaker client instance.
107 void alts_handshaker_client_shutdown(alts_handshaker_client* client);
110 * This method destroys an ALTS handshaker client.
112 * - client: an ALTS handshaker client instance.
114 void alts_handshaker_client_destroy(alts_handshaker_client* client);
117 * This method creates an ALTS handshaker client.
119 * - handshaker: ALTS TSI handshaker to which the created handshaker client
121 * - channel: grpc channel to ALTS handshaker service.
122 * - handshaker_service_url: address of ALTS handshaker service in the format of
124 * - interested_parties: set of pollsets interested in this connection.
125 * - options: ALTS credentials options containing information passed from TSI
126 * caller (e.g., rpc protocol versions)
127 * - target_name: the name of the endpoint that the channel is connecting to,
128 * and will be used for secure naming check
129 * - grpc_cb: gRPC provided callbacks passed from TSI handshaker.
130 * - cb: callback to be executed when tsi_handshaker_next API compltes.
131 * - user_data: argument passed to cb.
132 * - vtable_for_testing: ALTS handshaker client vtable instance used for
134 * - is_client: a boolean value indicating if the created handshaker client is
135 * used at the client (is_client = true) or server (is_client = false) side. It
136 * returns the created ALTS handshaker client on success, and NULL on failure.
138 alts_handshaker_client* alts_grpc_handshaker_client_create(
139 alts_tsi_handshaker* handshaker, grpc_channel* channel,
140 const char* handshaker_service_url, grpc_pollset_set* interested_parties,
141 grpc_alts_credentials_options* options, const grpc_slice& target_name,
142 grpc_iomgr_cb_func grpc_cb, tsi_handshaker_on_next_done_cb cb,
143 void* user_data, alts_handshaker_client_vtable* vtable_for_testing,
147 * This method handles handshaker response returned from ALTS handshaker
148 * service. Note that the only reason the API is exposed is that it is used in
149 * alts_shared_resources.cc.
151 * - client: an ALTS handshaker client instance.
152 * - is_ok: a boolean value indicating if the handshaker response is ok to read.
154 void alts_handshaker_client_handle_response(alts_handshaker_client* client,
157 #endif /* GRPC_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_CLIENT_H */