/src/S2OPC/src/ClientServer/services/bgenc/user_authentication.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Licensed to Systerel under one or more contributor license |
3 | | * agreements. See the NOTICE file distributed with this work |
4 | | * for additional information regarding copyright ownership. |
5 | | * Systerel licenses this file to you under the Apache |
6 | | * License, Version 2.0 (the "License"); you may not use this |
7 | | * file except in compliance with the License. You may obtain |
8 | | * a copy of the License at |
9 | | * |
10 | | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | | * |
12 | | * Unless required by applicable law or agreed to in writing, |
13 | | * software distributed under the License is distributed on an |
14 | | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | | * KIND, either express or implied. See the License for the |
16 | | * specific language governing permissions and limitations |
17 | | * under the License. |
18 | | */ |
19 | | |
20 | | /****************************************************************************** |
21 | | |
22 | | File Name : user_authentication.c |
23 | | |
24 | | Date : 12/01/2024 15:45:13 |
25 | | |
26 | | C Translator Version : tradc Java V1.2 (06/02/2022) |
27 | | |
28 | | ******************************************************************************/ |
29 | | |
30 | | /*------------------------ |
31 | | Exported Declarations |
32 | | ------------------------*/ |
33 | | #include "user_authentication.h" |
34 | | |
35 | | /*------------------------ |
36 | | INITIALISATION Clause |
37 | | ------------------------*/ |
38 | 0 | void user_authentication__INITIALISATION(void) { |
39 | 0 | } |
40 | | |
41 | | /*-------------------- |
42 | | OPERATIONS Clause |
43 | | --------------------*/ |
44 | | void user_authentication__allocate_user_if_authenticated( |
45 | | const constants__t_endpoint_config_idx_i user_authentication__p_endpoint_config_idx, |
46 | | const constants__t_user_token_i user_authentication__p_user_token, |
47 | | const constants_statuscodes_bs__t_StatusCode_i user_authentication__p_sc_valid_user, |
48 | | constants_statuscodes_bs__t_StatusCode_i * const user_authentication__p_sc_allocated_valid_user, |
49 | 0 | constants__t_user_i * const user_authentication__p_user) { |
50 | 0 | { |
51 | 0 | t_bool user_authentication__l_is_user_allocated; |
52 | | |
53 | 0 | if (user_authentication__p_sc_valid_user == constants_statuscodes_bs__e_sc_ok) { |
54 | 0 | user_authentication_bs__allocate_authenticated_user(user_authentication__p_endpoint_config_idx, |
55 | 0 | user_authentication__p_user_token, |
56 | 0 | &user_authentication__l_is_user_allocated, |
57 | 0 | user_authentication__p_user); |
58 | 0 | if (user_authentication__l_is_user_allocated == true) { |
59 | 0 | *user_authentication__p_sc_allocated_valid_user = user_authentication__p_sc_valid_user; |
60 | 0 | } |
61 | 0 | else { |
62 | 0 | *user_authentication__p_user = constants__c_user_indet; |
63 | 0 | *user_authentication__p_sc_allocated_valid_user = constants_statuscodes_bs__e_sc_bad_out_of_memory; |
64 | 0 | } |
65 | 0 | } |
66 | 0 | else { |
67 | 0 | *user_authentication__p_sc_allocated_valid_user = user_authentication__p_sc_valid_user; |
68 | 0 | *user_authentication__p_user = constants__c_user_indet; |
69 | 0 | } |
70 | 0 | } |
71 | 0 | } |
72 | | |
73 | | void user_authentication__may_encrypt_user_token( |
74 | | const constants__t_channel_config_idx_i user_authentication__p_channel_config_idx, |
75 | | const constants__t_byte_buffer_i user_authentication__p_user_server_cert, |
76 | | const constants__t_Nonce_i user_authentication__p_server_nonce, |
77 | | const constants__t_SecurityPolicy user_authentication__p_user_secu_policy, |
78 | | const constants__t_user_token_i user_authentication__p_user_token, |
79 | | t_bool * const user_authentication__p_valid, |
80 | 0 | constants__t_user_token_i * const user_authentication__p_user_token_encrypted) { |
81 | 0 | { |
82 | 0 | constants__t_user_token_type_i user_authentication__l_user_token_type; |
83 | | |
84 | 0 | user_authentication_bs__get_user_token_type_from_token(user_authentication__p_user_token, |
85 | 0 | &user_authentication__l_user_token_type); |
86 | 0 | if ((user_authentication__l_user_token_type == constants__e_userTokenType_anonymous) || |
87 | 0 | (user_authentication__l_user_token_type == constants__e_userTokenType_x509)) { |
88 | 0 | user_authentication_bs__shallow_copy_user_token(user_authentication__l_user_token_type, |
89 | 0 | user_authentication__p_user_token, |
90 | 0 | user_authentication__p_valid, |
91 | 0 | user_authentication__p_user_token_encrypted); |
92 | 0 | } |
93 | 0 | else if (user_authentication__l_user_token_type == constants__e_userTokenType_userName) { |
94 | 0 | user_authentication_bs__encrypt_user_token(user_authentication__p_channel_config_idx, |
95 | 0 | user_authentication__p_user_server_cert, |
96 | 0 | user_authentication__p_server_nonce, |
97 | 0 | user_authentication__p_user_secu_policy, |
98 | 0 | user_authentication__l_user_token_type, |
99 | 0 | user_authentication__p_user_token, |
100 | 0 | user_authentication__p_valid, |
101 | 0 | user_authentication__p_user_token_encrypted); |
102 | 0 | } |
103 | 0 | else { |
104 | 0 | *user_authentication__p_user_token_encrypted = constants__c_user_token_indet; |
105 | 0 | *user_authentication__p_valid = false; |
106 | 0 | } |
107 | 0 | } |
108 | 0 | } |
109 | | |
110 | | void user_authentication__allocate_valid_and_authenticated_user( |
111 | | const constants__t_user_token_i user_authentication__p_user_token, |
112 | | const constants__t_Nonce_i user_authentication__p_server_nonce, |
113 | | const constants__t_channel_config_idx_i user_authentication__p_channel_config_idx, |
114 | | const constants__t_endpoint_config_idx_i user_authentication__p_endpoint_config_idx, |
115 | | const constants__t_SignatureData_i user_authentication__p_user_token_signature, |
116 | | constants_statuscodes_bs__t_StatusCode_i * const user_authentication__p_sc_valid_user, |
117 | 0 | constants__t_user_i * const user_authentication__p_user) { |
118 | 0 | { |
119 | 0 | constants__t_user_token_type_i user_authentication__l_user_token_type; |
120 | 0 | t_bool user_authentication__l_is_supported_user_token_type; |
121 | 0 | constants_statuscodes_bs__t_StatusCode_i user_authentication__l_sc_user_authentication; |
122 | 0 | constants__t_SecurityPolicy user_authentication__l_used_security_policy; |
123 | 0 | t_bool user_authentication__l_is_valid_user_token; |
124 | 0 | constants__t_user_token_i user_authentication__l_decrypted_user_token; |
125 | | |
126 | 0 | user_authentication_bs__get_user_token_type_from_token(user_authentication__p_user_token, |
127 | 0 | &user_authentication__l_user_token_type); |
128 | 0 | user_authentication_bs__is_user_token_supported(user_authentication__l_user_token_type, |
129 | 0 | user_authentication__p_user_token, |
130 | 0 | user_authentication__p_channel_config_idx, |
131 | 0 | user_authentication__p_endpoint_config_idx, |
132 | 0 | &user_authentication__l_is_supported_user_token_type, |
133 | 0 | &user_authentication__l_used_security_policy); |
134 | 0 | if (user_authentication__l_is_supported_user_token_type == true) { |
135 | 0 | if (user_authentication__l_user_token_type == constants__e_userTokenType_userName) { |
136 | 0 | user_authentication_bs__decrypt_user_token(user_authentication__p_endpoint_config_idx, |
137 | 0 | user_authentication__p_server_nonce, |
138 | 0 | user_authentication__l_used_security_policy, |
139 | 0 | user_authentication__l_user_token_type, |
140 | 0 | user_authentication__p_user_token, |
141 | 0 | &user_authentication__l_is_valid_user_token, |
142 | 0 | &user_authentication__l_decrypted_user_token); |
143 | 0 | if (user_authentication__l_is_valid_user_token == true) { |
144 | 0 | user_authentication_bs__is_valid_username_pwd_authentication(user_authentication__p_endpoint_config_idx, |
145 | 0 | user_authentication__l_user_token_type, |
146 | 0 | user_authentication__l_decrypted_user_token, |
147 | 0 | &user_authentication__l_sc_user_authentication); |
148 | 0 | } |
149 | 0 | else { |
150 | 0 | user_authentication__l_sc_user_authentication = constants_statuscodes_bs__e_sc_bad_identity_token_invalid; |
151 | 0 | } |
152 | 0 | } |
153 | 0 | else if (user_authentication__l_user_token_type == constants__e_userTokenType_x509) { |
154 | 0 | user_authentication_bs__is_valid_user_token_signature(user_authentication__p_endpoint_config_idx, |
155 | 0 | user_authentication__l_user_token_type, |
156 | 0 | user_authentication__p_user_token, |
157 | 0 | user_authentication__p_user_token_signature, |
158 | 0 | user_authentication__p_server_nonce, |
159 | 0 | user_authentication__l_used_security_policy, |
160 | 0 | &user_authentication__l_sc_user_authentication); |
161 | 0 | if (user_authentication__l_sc_user_authentication == constants_statuscodes_bs__e_sc_ok) { |
162 | 0 | user_authentication_bs__is_cert_comply_with_security_policy(user_authentication__p_endpoint_config_idx, |
163 | 0 | user_authentication__l_user_token_type, |
164 | 0 | user_authentication__p_user_token, |
165 | 0 | user_authentication__l_used_security_policy, |
166 | 0 | &user_authentication__l_sc_user_authentication); |
167 | 0 | } |
168 | 0 | if (user_authentication__l_sc_user_authentication == constants_statuscodes_bs__e_sc_ok) { |
169 | 0 | user_authentication_bs__is_valid_user_x509_authentication(user_authentication__p_endpoint_config_idx, |
170 | 0 | user_authentication__l_user_token_type, |
171 | 0 | user_authentication__p_user_token, |
172 | 0 | &user_authentication__l_sc_user_authentication); |
173 | 0 | } |
174 | 0 | } |
175 | 0 | else if (user_authentication__l_user_token_type == constants__e_userTokenType_anonymous) { |
176 | 0 | user_authentication__l_sc_user_authentication = constants_statuscodes_bs__e_sc_ok; |
177 | 0 | } |
178 | 0 | else { |
179 | 0 | user_authentication__l_sc_user_authentication = constants_statuscodes_bs__e_sc_bad_identity_token_invalid; |
180 | 0 | } |
181 | 0 | user_authentication__allocate_user_if_authenticated(user_authentication__p_endpoint_config_idx, |
182 | 0 | user_authentication__p_user_token, |
183 | 0 | user_authentication__l_sc_user_authentication, |
184 | 0 | user_authentication__p_sc_valid_user, |
185 | 0 | user_authentication__p_user); |
186 | 0 | } |
187 | 0 | else { |
188 | 0 | *user_authentication__p_user = constants__c_user_indet; |
189 | 0 | *user_authentication__p_sc_valid_user = constants_statuscodes_bs__e_sc_bad_identity_token_invalid; |
190 | 0 | } |
191 | 0 | } |
192 | 0 | } |
193 | | |