1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18 
19 #ifndef GRPC_TEST_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_TEST_LIB_H
20 #define GRPC_TEST_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_TEST_LIB_H
21 
22 #include "src/core/tsi/alts/handshaker/alts_handshaker_service_api.h"
23 #include "src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h"
24 #include "src/core/tsi/alts/handshaker/transport_security_common_api.h"
25 
26 /**
27  * The first part of this file contains function signatures for de-serializing
28  * ALTS handshake requests and setting/serializing ALTS handshake responses,
29  * which simulate the behaviour of grpc server that runs ALTS handshaker
30  * service.
31  */
32 
33 /**
34  * This method creates a ALTS handshaker request that is used to hold
35  * de-serialized result.
36  */
37 grpc_gcp_handshaker_req* grpc_gcp_handshaker_decoded_req_create(
38     grpc_gcp_handshaker_req_type type);
39 
40 /* This method de-serializes a ALTS handshaker request. */
41 bool grpc_gcp_handshaker_req_decode(grpc_slice slice,
42                                     grpc_gcp_handshaker_req* req);
43 
44 /* This method serializes a ALTS handshaker response. */
45 bool grpc_gcp_handshaker_resp_encode(grpc_gcp_handshaker_resp* resp,
46                                      grpc_slice* slice);
47 
48 /* This method sets application protocol of ALTS handshaker response. */
49 bool grpc_gcp_handshaker_resp_set_application_protocol(
50     grpc_gcp_handshaker_resp* resp, const char* application_protocol);
51 
52 /* This method sets record protocol of ALTS handshaker response. */
53 bool grpc_gcp_handshaker_resp_set_record_protocol(
54     grpc_gcp_handshaker_resp* resp, const char* record_protocol);
55 
56 /* This method sets key_data of ALTS handshaker response. */
57 bool grpc_gcp_handshaker_resp_set_key_data(grpc_gcp_handshaker_resp* resp,
58                                            const char* key_data, size_t size);
59 
60 /* This method sets local identity's hostname for ALTS handshaker response. */
61 bool grpc_gcp_handshaker_resp_set_local_identity_hostname(
62     grpc_gcp_handshaker_resp* resp, const char* hostname);
63 
64 /**
65  * This method sets local identity's service account for ALTS handshaker
66  * response.
67  */
68 bool grpc_gcp_handshaker_resp_set_local_identity_service_account(
69     grpc_gcp_handshaker_resp* resp, const char* service_account);
70 
71 /* This method sets peer identity's hostname for ALTS handshaker response. */
72 bool grpc_gcp_handshaker_resp_set_peer_identity_hostname(
73     grpc_gcp_handshaker_resp* resp, const char* hostname);
74 
75 /**
76  * This method sets peer identity's service account for ALTS handshaker
77  * response.
78  */
79 bool grpc_gcp_handshaker_resp_set_peer_identity_service_account(
80     grpc_gcp_handshaker_resp* resp, const char* service_account);
81 
82 /* This method sets keep_channel_open for ALTS handshaker response. */
83 bool grpc_gcp_handshaker_resp_set_channel_open(grpc_gcp_handshaker_resp* resp,
84                                                bool keep_channel_open);
85 
86 /* This method sets code for ALTS handshaker response. */
87 bool grpc_gcp_handshaker_resp_set_code(grpc_gcp_handshaker_resp* resp,
88                                        uint32_t code);
89 
90 /* This method sets details for ALTS handshaker response. */
91 bool grpc_gcp_handshaker_resp_set_details(grpc_gcp_handshaker_resp* resp,
92                                           const char* details);
93 
94 /* This method sets out_frames for ALTS handshaker response. */
95 bool grpc_gcp_handshaker_resp_set_out_frames(grpc_gcp_handshaker_resp* resp,
96                                              const char* out_frames,
97                                              size_t size);
98 
99 /* This method sets peer_rpc_versions for ALTS handshaker response. */
100 bool grpc_gcp_handshaker_resp_set_peer_rpc_versions(
101     grpc_gcp_handshaker_resp* resp, uint32_t max_major, uint32_t max_minor,
102     uint32_t min_major, uint32_t min_minor);
103 
104 /* This method sets bytes_consumed for ALTS handshaker response. */
105 bool grpc_gcp_handshaker_resp_set_bytes_consumed(grpc_gcp_handshaker_resp* resp,
106                                                  int32_t bytes_consumed);
107 
108 /* This method serializes ALTS handshaker response. */
109 bool grpc_gcp_handshaker_resp_encode(grpc_gcp_handshaker_resp* resp,
110                                      grpc_slice* slice);
111 
112 /* This method de-serializes ALTS handshaker request. */
113 bool grpc_gcp_handshaker_req_decode(grpc_slice slice,
114                                     grpc_gcp_handshaker_req* req);
115 
116 /**
117  * The second part contains function signatures for checking equality of a pair
118  * of ALTS handshake requests/responses.
119  */
120 
121 /* This method checks equality of two client_start handshaker requests. */
122 bool grpc_gcp_handshaker_client_start_req_equals(
123     grpc_gcp_start_client_handshake_req* l_req,
124     grpc_gcp_start_client_handshake_req* r_req);
125 
126 /* This method checks equality of two server_start handshaker requests. */
127 bool grpc_gcp_handshaker_server_start_req_equals(
128     grpc_gcp_start_server_handshake_req* l_req,
129     grpc_gcp_start_server_handshake_req* r_req);
130 
131 /* This method checks equality of two ALTS handshaker requests. */
132 bool grpc_gcp_handshaker_req_equals(grpc_gcp_handshaker_req* l_req,
133                                     grpc_gcp_handshaker_req* r_req);
134 
135 /* This method checks equality of two handshaker response results. */
136 bool grpc_gcp_handshaker_resp_result_equals(
137     grpc_gcp_handshaker_result* l_result, grpc_gcp_handshaker_result* r_result);
138 
139 /* This method checks equality of two ALTS handshaker responses. */
140 bool grpc_gcp_handshaker_resp_equals(grpc_gcp_handshaker_resp* l_resp,
141                                      grpc_gcp_handshaker_resp* r_resp);
142 
143 #endif  // GRPC_TEST_CORE_TSI_ALTS_HANDSHAKER_ALTS_HANDSHAKER_SERVICE_API_TEST_LIB_H
144