Kaynağa Gözat

fixing client identification

Stasik0 10 yıl önce
ebeveyn
işleme
a70e39362c
3 değiştirilmiş dosya ile 17 ekleme ve 2 silme
  1. 15 0
      src/client/ua_client.c
  2. 1 1
      src/server/ua_server.c
  3. 1 1
      tools/generate_datatypes.py

+ 15 - 0
src/client/ua_client.c

@@ -4,6 +4,8 @@
 #include "ua_types_encoding_binary.h"
 #include "ua_transport_generated.h"
 
+#define ANONYMOUS_POLICY "open62541-anonymous-policy"
+
 struct UA_Client {
     /* Connection */
     UA_Connection connection;
@@ -330,6 +332,19 @@ static UA_StatusCode ActivateSession(UA_Client *client) {
     request.requestHeader.timestamp = UA_DateTime_now();
     request.requestHeader.timeoutHint = 10000;
 
+    UA_AnonymousIdentityToken identityToken;
+    UA_AnonymousIdentityToken_init(&identityToken);
+    identityToken.policyId = UA_STRING(ANONYMOUS_POLICY);
+
+    //manual ExtensionObject encoding of the identityToken
+    request.userIdentityToken.encoding = UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING;
+    request.userIdentityToken.typeId = UA_TYPES[UA_TYPES_ANONYMOUSIDENTITYTOKEN].typeId;
+    request.userIdentityToken.typeId.identifier.numeric+=UA_ENCODINGOFFSET_BINARY;
+
+    UA_ByteString_newMembers(&request.userIdentityToken.body, identityToken.policyId.length+4);
+    size_t offset = 0;
+    UA_ByteString_encodeBinary(&identityToken.policyId,&request.userIdentityToken.body,&offset);
+
     UA_ActivateSessionResponse response;
     synchronousRequest(&request, &UA_TYPES[UA_TYPES_ACTIVATESESSIONREQUEST],
                        &response, &UA_TYPES[UA_TYPES_ACTIVATESESSIONRESPONSE],

+ 1 - 1
src/server/ua_server.c

@@ -8,7 +8,7 @@
 
 
 const UA_ServerConfig UA_ServerConfig_standard = {
-        UA_FALSE,
+        UA_TRUE,
 
         UA_TRUE,
         (char *[]){"username"},

+ 1 - 1
tools/generate_datatypes.py

@@ -57,7 +57,7 @@ minimal_types = ["InvalidType", "Node", "NodeClass", "ReferenceNode", "Applicati
                  "NodeAttributes","ReferenceTypeAttributes", "ViewAttributes", "ObjectTypeAttributes",
                  "NodeAttributesMask","DeleteNodesItem", "DeleteNodesRequest", "DeleteNodesResponse",
                  "DeleteReferencesItem", "DeleteReferencesRequest", "DeleteReferencesResponse",
-                 "RegisterNodesRequest", "RegisterNodesResponse", "UnregisterNodesRequest", "UnregisterNodesResponse", "UserIdentityToken", "UserNameIdentityToken"]
+                 "RegisterNodesRequest", "RegisterNodesResponse", "UnregisterNodesRequest", "UnregisterNodesResponse", "UserIdentityToken", "UserNameIdentityToken", "AnonymousIdentityToken"]
 
 class TypeDescription(object):
     def __init__(self, name, nodeid, namespaceid):