Browse Source

Client: Make encryption and signing routines conditional on build flags

Julius Pfrommer 6 years ago
parent
commit
a94c499321
2 changed files with 18 additions and 16 deletions
  1. 10 8
      src/client/ua_client_connect.c
  2. 8 8
      src/client/ua_client_connect_async.c

+ 10 - 8
src/client/ua_client_connect.c

@@ -289,6 +289,7 @@ checkClientSignature(const UA_SecureChannel *channel,
 }
 
 /* Function to create a signature using remote certificate and nonce */
+#ifdef UA_ENABLE_ENCRYPTION
 UA_StatusCode
 signActivateSessionRequest(UA_SecureChannel *channel,
                            UA_ActivateSessionRequest *request) {
@@ -433,6 +434,7 @@ encryptUserIdentityToken(UA_Client *client, const UA_String *userTokenSecurityPo
 
     return retval;
 }
+#endif
 
 static UA_StatusCode
 activateSession(UA_Client *client) {
@@ -460,25 +462,25 @@ activateSession(UA_Client *client) {
 
     /* Set the policy-Id from the endpoint. Every IdentityToken starts with a
      * string. */
-    retval |= UA_String_copy(&client->config.userTokenPolicy.policyId,
-                             (UA_String*)request.userIdentityToken.content.decoded.data);
+    retval = UA_String_copy(&client->config.userTokenPolicy.policyId,
+                            (UA_String*)request.userIdentityToken.content.decoded.data);
 
+#ifdef UA_ENABLE_ENCRYPTION
     /* Encrypt the UserIdentityToken */
     const UA_String *userTokenPolicy = &client->channel.securityPolicy->policyUri;
     if(client->config.userTokenPolicy.securityPolicyUri.length > 0)
         userTokenPolicy = &client->config.userTokenPolicy.securityPolicyUri;
     retval |= encryptUserIdentityToken(client, userTokenPolicy, &request.userIdentityToken);
+
+    /* This function call is to prepare a client signature */
+    retval |= signActivateSessionRequest(&client->channel, &request);
+#endif
+
     if(retval != UA_STATUSCODE_GOOD) {
         UA_ActivateSessionRequest_deleteMembers(&request);
         return retval;
     }
 
-    /* This function call is to prepare a client signature */
-    if(client->channel.securityMode == UA_MESSAGESECURITYMODE_SIGN ||
-       client->channel.securityMode == UA_MESSAGESECURITYMODE_SIGNANDENCRYPT) {
-        signActivateSessionRequest(&client->channel, &request);
-    }
-
     UA_ActivateSessionResponse response;
     __UA_Client_Service(client, &request, &UA_TYPES[UA_TYPES_ACTIVATESESSIONREQUEST],
                         &response, &UA_TYPES[UA_TYPES_ACTIVATESESSIONRESPONSE]);

+ 8 - 8
src/client/ua_client_connect_async.c

@@ -352,26 +352,26 @@ requestActivateSession (UA_Client *client, UA_UInt32 *requestId) {
 
     /* Set the policy-Id from the endpoint. Every IdentityToken starts with a
      * string. */
-    retval |= UA_String_copy(&client->config.userTokenPolicy.policyId,
-                             (UA_String*)request.userIdentityToken.content.decoded.data);
+    retval = UA_String_copy(&client->config.userTokenPolicy.policyId,
+                            (UA_String*)request.userIdentityToken.content.decoded.data);
 
+#ifdef UA_ENABLE_ENCRYPTION
     /* Encrypt the UserIdentityToken */
     const UA_String *userTokenPolicy = &client->channel.securityPolicy->policyUri;
     if(client->config.userTokenPolicy.securityPolicyUri.length > 0)
         userTokenPolicy = &client->config.userTokenPolicy.securityPolicyUri;
     retval |= encryptUserIdentityToken(client, userTokenPolicy, &request.userIdentityToken);
+
+    /* This function call is to prepare a client signature */
+    retval |= signActivateSessionRequest(&client->channel, &request);
+#endif
+
     if(retval != UA_STATUSCODE_GOOD) {
         UA_ActivateSessionRequest_deleteMembers(&request);
         client->connectStatus = retval;
         return retval;
     }
 
-    /* This function call is to prepare a client signature */
-    if(client->channel.securityMode == UA_MESSAGESECURITYMODE_SIGN ||
-       client->channel.securityMode == UA_MESSAGESECURITYMODE_SIGNANDENCRYPT) {
-        signActivateSessionRequest(&client->channel, &request);
-    }
-
     retval = UA_Client_sendAsyncRequest (
             client, &request, &UA_TYPES[UA_TYPES_ACTIVATESESSIONREQUEST],
             (UA_ClientAsyncServiceCallback) responseActivateSession,