1 /*
2 * Copyright (c) 2020 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef __STS_CLIENT_H__
17 #define __STS_CLIENT_H__
18
19 #include <stdint.h>
20 #include "key_agreement_server.h"
21 #include "base.h"
22 #include "hichain.h"
23 #include "sts_server.h"
24 #include "parsedata.h"
25 #include "key_agreement_client.h"
26
27 #if !(defined(_CUT_STS_) || defined(_CUT_STS_CLIENT_))
28
29 struct sts_client {
30 struct key_agreement_client client_info;
31 const struct session_identity *identity;
32 int32_t operation_code;
33 struct stsk self_private_key;
34 struct stpk self_public_key;
35 struct stpk peer_public_key;
36 struct hc_session_key session_key;
37 struct hc_session_key service_key;
38 uint32_t key_length;
39 struct challenge peer_challenge;
40 struct challenge my_challenge;
41 struct hc_auth_id peer_id;
42 struct hc_auth_id self_id;
43 enum hc_user_type peer_user_type;
44 struct auth_data my_auth_data;
45 struct auth_data peer_auth_data;
46 struct hc_salt salt;
47 hc_handle hichain_handle;
48 };
49
sts_client_sn(struct sts_client * client)50 static inline uint32_t sts_client_sn(struct sts_client *client)
51 {
52 return client->client_info.protocol_base_info.sn;
53 }
54
55 int32_t send_sts_start_request(struct sts_client *sts_client, struct message *send);
56 int32_t send_sts_end_request(struct sts_client *sts_client, const struct message *receive, struct message *send);
57 int32_t receive_sts_end_response(struct sts_client *sts_client, struct message *receive);
58
59 #else /* _CUT_XXX_ */
60
61 struct sts_client {
62 char rsv;
63 };
64
65 #endif /* _CUT_XXX_ */
66
67 struct sts_client *build_sts_client(const hc_handle hichain_handle, uint32_t key_length,
68 const struct hc_auth_id *client, const struct hc_auth_id *server);
69 void destroy_sts_client(struct sts_client *handle);
70
71 #endif /* __STS_CLIENT_H__ */
72