|
@@ -31,8 +31,13 @@ void Service_CreateSession(UA_Server *server, UA_SecureChannel *channel,
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ /* Fill the session with more information */
|
|
|
newSession->maxResponseMessageSize = request->maxResponseMessageSize;
|
|
|
newSession->maxRequestMessageSize = channel->connection->localConf.maxMessageSize;
|
|
|
+ response->responseHeader.serviceResult |=
|
|
|
+ UA_ApplicationDescription_copy(&request->clientDescription, &newSession->clientDescription);
|
|
|
+
|
|
|
+ /* Prepare the response */
|
|
|
response->sessionId = newSession->sessionId;
|
|
|
response->revisedSessionTimeout = (UA_Double)newSession->timeout;
|
|
|
response->authenticationToken = newSession->authenticationToken;
|
|
@@ -41,10 +46,13 @@ void Service_CreateSession(UA_Server *server, UA_SecureChannel *channel,
|
|
|
response->responseHeader.serviceResult |=
|
|
|
UA_ByteString_copy(&server->endpointDescriptions->serverCertificate,
|
|
|
&response->serverCertificate);
|
|
|
+
|
|
|
+ /* Failure -> remove the session */
|
|
|
if(response->responseHeader.serviceResult != UA_STATUSCODE_GOOD) {
|
|
|
UA_SessionManager_removeSession(&server->sessionManager, &newSession->authenticationToken);
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
UA_LOG_DEBUG_CHANNEL(server->config.logger, channel, "Session " UA_PRINTF_GUID_FORMAT " created",
|
|
|
UA_PRINTF_GUID_DATA(newSession->sessionId.identifier.guid));
|
|
|
}
|
|
@@ -60,74 +68,12 @@ Service_ActivateSession(UA_Server *server, UA_SecureChannel *channel,
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if(request->userIdentityToken.encoding < UA_EXTENSIONOBJECT_DECODED ||
|
|
|
- (request->userIdentityToken.content.decoded.type != &UA_TYPES[UA_TYPES_ANONYMOUSIDENTITYTOKEN] &&
|
|
|
- request->userIdentityToken.content.decoded.type != &UA_TYPES[UA_TYPES_USERNAMEIDENTITYTOKEN])) {
|
|
|
- UA_LOG_INFO_SESSION(server->config.logger, session, "ActivateSession: SecureChannel %i wants "
|
|
|
- "to activate, but the UserIdentify token is invalid", channel->securityToken.channelId);
|
|
|
- response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- UA_String ap = UA_STRING(ANONYMOUS_POLICY);
|
|
|
- UA_String up = UA_STRING(USERNAME_POLICY);
|
|
|
-
|
|
|
- /* Compatibility notice: Siemens OPC Scout v10 provides an empty policyId,
|
|
|
- this is not okay For compatibility we will assume that empty policyId == ANONYMOUS_POLICY
|
|
|
- if(token.policyId->data == NULL)
|
|
|
- response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
|
|
|
- */
|
|
|
-
|
|
|
- if(server->config.enableAnonymousLogin &&
|
|
|
- request->userIdentityToken.content.decoded.type == &UA_TYPES[UA_TYPES_ANONYMOUSIDENTITYTOKEN]) {
|
|
|
- /* anonymous login */
|
|
|
- const UA_AnonymousIdentityToken *token = request->userIdentityToken.content.decoded.data;
|
|
|
- if(token->policyId.data && !UA_String_equal(&token->policyId, &ap)) {
|
|
|
- response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
|
|
|
- return;
|
|
|
- }
|
|
|
- } else if(server->config.enableUsernamePasswordLogin &&
|
|
|
- request->userIdentityToken.content.decoded.type == &UA_TYPES[UA_TYPES_USERNAMEIDENTITYTOKEN]) {
|
|
|
- /* username login */
|
|
|
- const UA_UserNameIdentityToken *token = request->userIdentityToken.content.decoded.data;
|
|
|
- if(!UA_String_equal(&token->policyId, &up)) {
|
|
|
- response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
|
|
|
- return;
|
|
|
- }
|
|
|
- if(token->encryptionAlgorithm.length > 0) {
|
|
|
- /* we don't support encryption */
|
|
|
- response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if(token->userName.length == 0 && token->password.length == 0) {
|
|
|
- /* empty username and password */
|
|
|
- response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- /* trying to match pw/username */
|
|
|
- UA_Boolean match = false;
|
|
|
- for(size_t i = 0; i < server->config.usernamePasswordLoginsSize; i++) {
|
|
|
- UA_String *user = &server->config.usernamePasswordLogins[i].username;
|
|
|
- UA_String *pw = &server->config.usernamePasswordLogins[i].password;
|
|
|
- if(UA_String_equal(&token->userName, user) && UA_String_equal(&token->password, pw)) {
|
|
|
- match = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if(!match) {
|
|
|
- UA_LOG_INFO_SESSION(server->config.logger, session,
|
|
|
- "ActivateSession: Did not find matching username/password");
|
|
|
- response->responseHeader.serviceResult = UA_STATUSCODE_BADUSERACCESSDENIED;
|
|
|
- return;
|
|
|
- }
|
|
|
- } else {
|
|
|
- /* Unsupported token type */
|
|
|
- response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
|
|
|
+ /* Callback into userland access control */
|
|
|
+ response->responseHeader.serviceResult =
|
|
|
+ server->config.accessControl.activateSession(&session->sessionId, &request->userIdentityToken,
|
|
|
+ &session->sessionHandle);
|
|
|
+ if(response->responseHeader.serviceResult != UA_STATUSCODE_GOOD)
|
|
|
return;
|
|
|
- }
|
|
|
|
|
|
/* Detach the old SecureChannel */
|
|
|
if(session->channel && session->channel != channel) {
|
|
@@ -146,6 +92,8 @@ void
|
|
|
Service_CloseSession(UA_Server *server, UA_Session *session, const UA_CloseSessionRequest *request,
|
|
|
UA_CloseSessionResponse *response) {
|
|
|
UA_LOG_INFO_SESSION(server->config.logger, session, "CloseSession");
|
|
|
+ /* Callback into userland access control */
|
|
|
+ server->config.accessControl.closeSession(&session->sessionId, session->sessionHandle);
|
|
|
response->responseHeader.serviceResult =
|
|
|
UA_SessionManager_removeSession(&server->sessionManager, &session->authenticationToken);
|
|
|
}
|