|
@@ -26,6 +26,10 @@ static void UA_Client_init(UA_Client* client, UA_ClientConfig config, UA_Logger
|
|
UA_String_init(&client->endpointUrl);
|
|
UA_String_init(&client->endpointUrl);
|
|
client->requestId = 0;
|
|
client->requestId = 0;
|
|
|
|
|
|
|
|
+ client->authenticationMethod = UA_CLIENTAUTHENTICATION_NONE;
|
|
|
|
+ UA_String_init(&client->username);
|
|
|
|
+ UA_String_init(&client->password);
|
|
|
|
+
|
|
UA_NodeId_init(&client->authenticationToken);
|
|
UA_NodeId_init(&client->authenticationToken);
|
|
client->requestHandle = 0;
|
|
client->requestHandle = 0;
|
|
|
|
|
|
@@ -56,6 +60,10 @@ static void UA_Client_deleteMembers(UA_Client* client) {
|
|
if(client->endpointUrl.data)
|
|
if(client->endpointUrl.data)
|
|
UA_String_deleteMembers(&client->endpointUrl);
|
|
UA_String_deleteMembers(&client->endpointUrl);
|
|
UA_UserTokenPolicy_deleteMembers(&client->token);
|
|
UA_UserTokenPolicy_deleteMembers(&client->token);
|
|
|
|
+ if(client->username.data)
|
|
|
|
+ UA_String_deleteMembers(&client->username);
|
|
|
|
+ if(client->password.data)
|
|
|
|
+ UA_String_deleteMembers(&client->password);
|
|
#ifdef UA_ENABLE_SUBSCRIPTIONS
|
|
#ifdef UA_ENABLE_SUBSCRIPTIONS
|
|
UA_Client_NotificationsAckNumber *n, *tmp;
|
|
UA_Client_NotificationsAckNumber *n, *tmp;
|
|
LIST_FOREACH_SAFE(n, &client->pendingNotificationsAcks, listEntry, tmp) {
|
|
LIST_FOREACH_SAFE(n, &client->pendingNotificationsAcks, listEntry, tmp) {
|
|
@@ -315,20 +323,29 @@ static UA_StatusCode ActivateSession(UA_Client *client) {
|
|
request.requestHeader.timestamp = UA_DateTime_now();
|
|
request.requestHeader.timestamp = UA_DateTime_now();
|
|
request.requestHeader.timeoutHint = 600000;
|
|
request.requestHeader.timeoutHint = 600000;
|
|
|
|
|
|
- UA_AnonymousIdentityToken identityToken;
|
|
|
|
- UA_AnonymousIdentityToken_init(&identityToken);
|
|
|
|
- UA_String_copy(&client->token.policyId, &identityToken.policyId);
|
|
|
|
-
|
|
|
|
//manual ExtensionObject encoding of the identityToken
|
|
//manual ExtensionObject encoding of the identityToken
|
|
- request.userIdentityToken.encoding = UA_EXTENSIONOBJECT_DECODED_NODELETE;
|
|
|
|
- request.userIdentityToken.content.decoded.type = &UA_TYPES[UA_TYPES_ANONYMOUSIDENTITYTOKEN];
|
|
|
|
- request.userIdentityToken.content.decoded.data = &identityToken;
|
|
|
|
|
|
+ if(client->authenticationMethod == UA_CLIENTAUTHENTICATION_NONE){
|
|
|
|
+ UA_AnonymousIdentityToken* identityToken = UA_malloc(sizeof(UA_AnonymousIdentityToken));
|
|
|
|
+ UA_AnonymousIdentityToken_init(identityToken);
|
|
|
|
+ UA_String_copy(&client->token.policyId, &identityToken->policyId);
|
|
|
|
+ request.userIdentityToken.encoding = UA_EXTENSIONOBJECT_DECODED;
|
|
|
|
+ request.userIdentityToken.content.decoded.type = &UA_TYPES[UA_TYPES_ANONYMOUSIDENTITYTOKEN];
|
|
|
|
+ request.userIdentityToken.content.decoded.data = identityToken;
|
|
|
|
+ }else{
|
|
|
|
+ UA_UserNameIdentityToken* identityToken = UA_malloc(sizeof(UA_UserNameIdentityToken));
|
|
|
|
+ UA_UserNameIdentityToken_init(identityToken);
|
|
|
|
+ UA_String_copy(&client->token.policyId, &identityToken->policyId);
|
|
|
|
+ UA_String_copy(&client->username, &identityToken->userName);
|
|
|
|
+ UA_String_copy(&client->password, &identityToken->password);
|
|
|
|
+ request.userIdentityToken.encoding = UA_EXTENSIONOBJECT_DECODED;
|
|
|
|
+ request.userIdentityToken.content.decoded.type = &UA_TYPES[UA_TYPES_USERNAMEIDENTITYTOKEN];
|
|
|
|
+ request.userIdentityToken.content.decoded.data = identityToken;
|
|
|
|
+ }
|
|
|
|
|
|
UA_ActivateSessionResponse response;
|
|
UA_ActivateSessionResponse response;
|
|
__UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_ACTIVATESESSIONREQUEST],
|
|
__UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_ACTIVATESESSIONREQUEST],
|
|
&response, &UA_TYPES[UA_TYPES_ACTIVATESESSIONRESPONSE]);
|
|
&response, &UA_TYPES[UA_TYPES_ACTIVATESESSIONRESPONSE]);
|
|
|
|
|
|
- UA_AnonymousIdentityToken_deleteMembers(&identityToken);
|
|
|
|
UA_ActivateSessionRequest_deleteMembers(&request);
|
|
UA_ActivateSessionRequest_deleteMembers(&request);
|
|
UA_ActivateSessionResponse_deleteMembers(&response);
|
|
UA_ActivateSessionResponse_deleteMembers(&response);
|
|
return response.responseHeader.serviceResult; // not deleted
|
|
return response.responseHeader.serviceResult; // not deleted
|
|
@@ -391,8 +408,15 @@ static UA_StatusCode EndpointsHandshake(UA_Client *client) {
|
|
/* look for a user token policy with an anonymous token */
|
|
/* look for a user token policy with an anonymous token */
|
|
for(size_t j = 0; j < endpoint->userIdentityTokensSize; ++j) {
|
|
for(size_t j = 0; j < endpoint->userIdentityTokensSize; ++j) {
|
|
UA_UserTokenPolicy* userToken = &endpoint->userIdentityTokens[j];
|
|
UA_UserTokenPolicy* userToken = &endpoint->userIdentityTokens[j];
|
|
- if(userToken->tokenType != UA_USERTOKENTYPE_ANONYMOUS)
|
|
|
|
- continue;
|
|
|
|
|
|
+ //anonymous authentication
|
|
|
|
+ if(client->authenticationMethod == UA_CLIENTAUTHENTICATION_NONE){
|
|
|
|
+ if(userToken->tokenType != UA_USERTOKENTYPE_ANONYMOUS)
|
|
|
|
+ continue;
|
|
|
|
+ }else{
|
|
|
|
+ //username authentication
|
|
|
|
+ if(userToken->tokenType != UA_USERTOKENTYPE_USERNAME)
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
tokenFound = true;
|
|
tokenFound = true;
|
|
UA_UserTokenPolicy_copy(userToken, &client->token);
|
|
UA_UserTokenPolicy_copy(userToken, &client->token);
|
|
break;
|
|
break;
|
|
@@ -537,6 +561,15 @@ UA_Client_getEndpoints(UA_Client *client, UA_ConnectClientConnection connectFunc
|
|
return retval;
|
|
return retval;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+UA_StatusCode UA_Client_connect_username(UA_Client *client, UA_ConnectClientConnection connFunc,
|
|
|
|
+ const char *endpointUrl, const char *username, const char *password){
|
|
|
|
+ client->authenticationMethod=UA_CLIENTAUTHENTICATION_USERNAME;
|
|
|
|
+ client->username = UA_STRING_ALLOC(username);
|
|
|
|
+ client->password = UA_STRING_ALLOC(password);
|
|
|
|
+ return UA_Client_connect(client, connFunc, endpointUrl);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
UA_StatusCode UA_Client_connect(UA_Client *client, UA_ConnectClientConnection connectFunc,
|
|
UA_StatusCode UA_Client_connect(UA_Client *client, UA_ConnectClientConnection connectFunc,
|
|
const char *endpointUrl) {
|
|
const char *endpointUrl) {
|
|
if(client->state == UA_CLIENTSTATE_CONNECTED)
|
|
if(client->state == UA_CLIENTSTATE_CONNECTED)
|