/src/S2OPC/src/ClientServer/services/b2c/user_bs.c
Line | Count | Source |
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 | | #include "user_bs.h" |
21 | | #include "sopc_assert.h" |
22 | | #include "sopc_builtintypes.h" |
23 | | #include "sopc_enum_types.h" |
24 | | #include "sopc_macros.h" |
25 | | |
26 | | /*-------------- |
27 | | SEES Clause |
28 | | --------------*/ |
29 | | #include "constants.h" |
30 | | #include "sopc_service_call_context.h" |
31 | | #include "sopc_user.h" |
32 | | |
33 | | #include "app_cb_call_context_internal.h" |
34 | | |
35 | | /*------------------------ |
36 | | INITIALISATION Clause |
37 | | ------------------------*/ |
38 | | void user_bs__INITIALISATION(void) |
39 | 0 | { /*Translated from B but an initialization is not needed from this module.*/ |
40 | 0 | } |
41 | | |
42 | | /*-------------------- |
43 | | OPERATIONS Clause |
44 | | --------------------*/ |
45 | | |
46 | | void user_bs__are_application_uri_equal(const constants__t_user_i user_bs__p_user, |
47 | | const constants__t_Criteria_i user_bs__p_cli_app_uri, |
48 | | t_bool* const user_bs__p_bres) |
49 | 0 | { |
50 | | /* Spec: This criteria type is used if a Role should be granted to a Session |
51 | | for Application Authentication with Anonymous UserIdentityToken.*/ |
52 | 0 | SOPC_UNUSED_ARG(user_bs__p_user); // B model checks for anonymous constraint |
53 | 0 | *user_bs__p_bres = false; |
54 | 0 | const SOPC_CallContext* callCtx = SOPC_CallContext_GetCurrent(); |
55 | 0 | OpcUa_MessageSecurityMode secuMode = SOPC_CallContext_GetSecurityMode(callCtx); |
56 | | |
57 | | /* Spec: The Client Certificate shall be trusted by the Server and the Session shall |
58 | | use at least a signed communication channel. */ |
59 | 0 | if (OpcUa_MessageSecurityMode_Sign == secuMode || OpcUa_MessageSecurityMode_SignAndEncrypt == secuMode) |
60 | 0 | { |
61 | | /* Spec: The criteria is the ApplicationUri from the Client Certificate used for the Session. |
62 | | * Note: equality of ApplicationUri is checked server_create_session_req_do_crypto */ |
63 | 0 | const OpcUa_ApplicationDescription* cliDesc = SOPC_CallContext_GetClientApplicationDesc(callCtx); |
64 | 0 | SOPC_ASSERT(NULL != cliDesc); |
65 | 0 | int32_t comparison = -1; |
66 | 0 | SOPC_ReturnStatus status = |
67 | 0 | SOPC_String_Compare(&cliDesc->ApplicationUri, user_bs__p_cli_app_uri, false, &comparison); |
68 | 0 | *user_bs__p_bres = (0 == comparison && SOPC_STATUS_OK == status); |
69 | 0 | } |
70 | 0 | } |
71 | | |
72 | | void user_bs__are_username_equal(const constants__t_user_i user_bs__p_user, |
73 | | const constants__t_Criteria_i user_bs__p_username, |
74 | | t_bool* const user_bs__b_res) |
75 | 0 | { |
76 | 0 | const SOPC_User* user = SOPC_UserWithAuthorization_GetUser(user_bs__p_user); |
77 | 0 | SOPC_ASSERT(SOPC_User_IsUsername(user)); |
78 | 0 | const SOPC_String* username = SOPC_User_GetUsername(user); |
79 | 0 | int32_t comparison = -1; |
80 | 0 | SOPC_ReturnStatus status = SOPC_String_Compare(username, user_bs__p_username, false, &comparison); |
81 | 0 | *user_bs__b_res = (0 == comparison && SOPC_STATUS_OK == status); |
82 | 0 | } |
83 | | |
84 | | void user_bs__are_certificate_tb_equal(const constants__t_user_i user_bs__p_user, |
85 | | const constants__t_Criteria_i user_bs__p_thumbprint, |
86 | | t_bool* const user_bs__b_res) |
87 | 0 | { |
88 | 0 | const SOPC_User* user = SOPC_UserWithAuthorization_GetUser(user_bs__p_user); |
89 | 0 | SOPC_ASSERT(SOPC_User_IsCertificate(user)); |
90 | 0 | const SOPC_String* certTb = SOPC_User_GetCertificate_Thumbprint(user); |
91 | 0 | int32_t comparison = -1; |
92 | 0 | SOPC_ReturnStatus status = SOPC_String_Compare(certTb, user_bs__p_thumbprint, false, &comparison); |
93 | 0 | *user_bs__b_res = (0 == comparison && SOPC_STATUS_OK == status); |
94 | 0 | } |
95 | | |
96 | | void user_bs__is_anonymous(const constants__t_user_i user_bs__p_user, t_bool* const user_bs__b_res) |
97 | 0 | { |
98 | 0 | SOPC_ASSERT(NULL != user_bs__b_res); |
99 | 0 | const SOPC_User* user = SOPC_UserWithAuthorization_GetUser(user_bs__p_user); |
100 | 0 | *user_bs__b_res = SOPC_User_IsAnonymous(user); |
101 | 0 | } |
102 | | |
103 | | void user_bs__is_certificate(const constants__t_user_i user_bs__p_user, t_bool* const user_bs__b_res) |
104 | 0 | { |
105 | 0 | SOPC_ASSERT(NULL != user_bs__b_res); |
106 | 0 | const SOPC_User* user = SOPC_UserWithAuthorization_GetUser(user_bs__p_user); |
107 | 0 | *user_bs__b_res = SOPC_User_IsCertificate(user); |
108 | 0 | } |
109 | | |
110 | | void user_bs__is_username(const constants__t_user_i user_bs__p_user, t_bool* const user_bs__b_res) |
111 | 0 | { |
112 | 0 | SOPC_ASSERT(NULL != user_bs__b_res); |
113 | 0 | const SOPC_User* user = SOPC_UserWithAuthorization_GetUser(user_bs__p_user); |
114 | 0 | *user_bs__b_res = SOPC_User_IsUsername(user); |
115 | 0 | } |