Selaa lähdekoodia

client basic 256sha256 / server sample / tests / various fixes (#1691)

* client basic 256sha256 / tests / various fixes

* fix server basic256sha256

* remove duplicated loadFile

* Fix fuzzing by making backup of message buffer

* Disable sonarcloud on PRs
StalderT 6 vuotta sitten
vanhempi
commit
da64add5c0

+ 2 - 0
examples/CMakeLists.txt

@@ -76,8 +76,10 @@ add_example(server_inheritance server_inheritance.c)
 
 if(UA_ENABLE_ENCRYPTION)
     add_example(server_basic128rsa15 encryption/server_basic128rsa15.c)
+    add_example(server_basic256sha256 encryption/server_basic256sha256.c)
     # Add secure client example application
     add_example(client_basic128rsa15 encryption/client_basic128rsa15.c)
+    add_example(client_basic256sha256 encryption/client_basic256sha256.c)
 endif()
 
 add_example(custom_datatype_client custom_datatype/client_types_custom.c)

+ 34 - 0
examples/common.h

@@ -0,0 +1,34 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
+
+/* loadFile parses the certificate file.
+ *
+ * @param  path               specifies the file name given in argv[]
+ * @return Returns the file content after parsing */
+static UA_INLINE UA_ByteString
+loadFile(const char *const path) {
+    UA_ByteString fileContents = UA_STRING_NULL;
+
+    /* Open the file */
+    FILE *fp = fopen(path, "rb");
+    if(!fp) {
+        errno = 0; /* We read errno also from the tcp layer... */
+        return fileContents;
+    }
+
+    /* Get the file length, allocate the data and read */
+    fseek(fp, 0, SEEK_END);
+    fileContents.length = (size_t)ftell(fp);
+    fileContents.data = (UA_Byte *)UA_malloc(fileContents.length * sizeof(UA_Byte));
+    if(fileContents.data) {
+        fseek(fp, 0, SEEK_SET);
+        size_t read = fread(fileContents.data, sizeof(UA_Byte), fileContents.length, fp);
+        if(read != fileContents.length)
+            UA_ByteString_deleteMembers(&fileContents);
+    } else {
+        fileContents.length = 0;
+    }
+    fclose(fp);
+
+    return fileContents;
+}

+ 2 - 1
examples/discovery/server_multicast.c

@@ -250,7 +250,8 @@ UA_Client *getRegisterClient(UA_EndpointDescription *endpointRegister, int argc,
                                           certificate, privateKey,
                                           &endpointRegister->serverCertificate,
                                           trustList, trustListSize,
-                                          revocationList, revocationListSize);
+                                          revocationList, revocationListSize,
+                                          UA_SecurityPolicy_Basic128Rsa15);
     UA_ByteString_deleteMembers(&certificate);
     UA_ByteString_deleteMembers(&privateKey);
     for (size_t deleteCount = 0; deleteCount < trustListSize; deleteCount++) {

+ 7 - 47
examples/encryption/client_basic128rsa15.c

@@ -1,52 +1,16 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- *     Copyright 2018 (c) Kalycito Infotech Private Limited
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #include <stdio.h>
 #include <errno.h>
 
 #include "open62541.h"
+#include "../common.h"
 
 #define MIN_ARGS           3
 #define FAILURE            1
 #define CONNECTION_STRING  "opc.tcp://localhost:4840"
 
-/* loadFile parses the certificate file.
- *
- * @param  path               specifies the file name given in argv[]
- * @return Returns the file content after parsing */
-static UA_ByteString loadFile(const char *const path) {
-    UA_ByteString fileContents = UA_BYTESTRING_NULL;
-    if(path == NULL)
-        return fileContents;
-
-    /* Open the file */
-    FILE *fp = fopen(path, "rb");
-    if(!fp) {
-        errno = 0; /* We read errno also from the tcp layer */
-        return fileContents;
-    }
-
-    /* Get the file length, allocate the data and read */
-    fseek(fp, 0, SEEK_END);
-    fileContents.length = (size_t)ftell(fp);
-    fileContents.data = (UA_Byte*)UA_malloc(fileContents.length * sizeof(UA_Byte));
-    if(fileContents.data) {
-        fseek(fp, 0, SEEK_SET);
-        size_t read = fread(fileContents.data, sizeof(UA_Byte), fileContents.length, fp);
-        if(read != fileContents.length)
-            UA_ByteString_deleteMembers(&fileContents);
-    } else {
-        fileContents.length = 0;
-    }
-
-    fclose(fp);
-    return fileContents;
-}
-
 /* cleanupClient deletes the memory allocated for client configuration.
  *
  * @param  client             client configuration that need to be deleted
@@ -123,6 +87,8 @@ int main(int argc, char* argv[]) {
     UA_Array_delete(endpointArray, endpointArraySize,
                     &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
 
+    UA_Client_delete(client); /* Disconnects the client internally */
+
     /* Load the trustList. Load revocationList is not supported now */
     if(argc > MIN_ARGS) {
         trustListSize = (size_t)argc-MIN_ARGS;
@@ -142,7 +108,8 @@ int main(int argc, char* argv[]) {
                                   certificate, privateKey,
                                   remoteCertificate,
                                   trustList, trustListSize,
-                                  revocationList, revocationListSize);
+                                  revocationList, revocationListSize,
+                                  UA_SecurityPolicy_Basic128Rsa15);
     if(client == NULL) {
         UA_ByteString_delete(remoteCertificate); /* Dereference the memory */
         return FAILURE;
@@ -154,13 +121,6 @@ int main(int argc, char* argv[]) {
         UA_ByteString_deleteMembers(&trustList[deleteCount]);
     }
 
-    if(!client) {
-        UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
-                     "Could not create the server config");
-        cleanupClient(client, remoteCertificate);
-        return FAILURE;
-    }
-
     /* Secure client connect */
     retval = UA_Client_connect(client, CONNECTION_STRING);
     if(retval != UA_STATUSCODE_GOOD) {

+ 150 - 0
examples/encryption/client_basic256sha256.c

@@ -0,0 +1,150 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
+
+#include <stdio.h>
+#include <errno.h>
+
+#include "open62541.h"
+#include "../common.h"
+
+#define MIN_ARGS           3
+#define FAILURE            1
+#define CONNECTION_STRING  "opc.tcp://localhost:4840"
+
+/* cleanupClient deletes the memory allocated for client configuration.
+ *
+ * @param  client             client configuration that need to be deleted
+ * @param  remoteCertificate  server certificate */
+static void cleanupClient(UA_Client* client, UA_ByteString* remoteCertificate) {
+    UA_ByteString_delete(remoteCertificate); /* Dereference the memory */
+    UA_Client_delete(client); /* Disconnects the client internally */
+}
+
+/* main function for secure client implementation.
+ *
+ * @param  argc               count of command line variable provided
+ * @param  argv[]             array of strings include certificate, private key,
+ *                            trust list and revocation list
+ * @return Return an integer representing success or failure of application */
+int main(int argc, char* argv[]) {
+    UA_Client*              client             = NULL;
+    UA_ByteString*          remoteCertificate  = NULL;
+    UA_StatusCode           retval             = UA_STATUSCODE_GOOD;
+    UA_ByteString*          trustList          = NULL;
+    size_t                  trustListSize      = 0;
+    UA_ByteString*          revocationList     = NULL;
+    size_t                  revocationListSize = 0;
+
+    /* endpointArray is used to hold the available endpoints in the server
+     * endpointArraySize is used to hold the number of endpoints available */
+    UA_EndpointDescription* endpointArray      = NULL;
+    size_t                  endpointArraySize  = 0;
+
+    /* Load certificate and private key */
+    UA_ByteString           certificate        = loadFile(argv[1]);
+    UA_ByteString           privateKey         = loadFile(argv[2]);
+
+    if(argc < MIN_ARGS) {
+        UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
+                     "The Certificate and key is missing."
+                     "The required arguments are "
+                     "<client-certificate.der> <client-private-key.der> "
+                     "[<trustlist1.crl>, ...]");
+        return FAILURE;
+    }
+
+    /* The Get endpoint (discovery service) is done with
+     * security mode as none to see the server's capability
+     * and certificate */
+    client = UA_Client_new(UA_ClientConfig_default);
+    remoteCertificate = UA_ByteString_new();
+    retval = UA_Client_getEndpoints(client, CONNECTION_STRING,
+                                    &endpointArraySize, &endpointArray);
+    if(retval != UA_STATUSCODE_GOOD) {
+        UA_Array_delete(endpointArray, endpointArraySize,
+                        &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
+        cleanupClient(client, remoteCertificate);
+        return (int)retval;
+    }
+
+    printf("%i endpoints found\n", (int)endpointArraySize);
+    for(size_t endPointCount = 0; endPointCount < endpointArraySize; endPointCount++) {
+        printf("URL of endpoint %i is %.*s\n", (int)endPointCount,
+               (int)endpointArray[endPointCount].endpointUrl.length,
+               endpointArray[endPointCount].endpointUrl.data);
+        if(endpointArray[endPointCount].securityMode == UA_MESSAGESECURITYMODE_SIGNANDENCRYPT)
+            UA_ByteString_copy(&endpointArray[endPointCount].serverCertificate, remoteCertificate);
+    }
+
+    if(UA_ByteString_equal(remoteCertificate, &UA_BYTESTRING_NULL)) {
+        UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
+                     "Server does not support Security Mode of"
+                     " UA_MESSAGESECURITYMODE_SIGNANDENCRYPT");
+        cleanupClient(client, remoteCertificate);
+        return FAILURE;
+    }
+
+    UA_Array_delete(endpointArray, endpointArraySize,
+                    &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
+
+    UA_Client_delete(client); /* Disconnects the client internally */
+
+    /* Load the trustList. Load revocationList is not supported now */
+    if(argc > MIN_ARGS) {
+        trustListSize = (size_t)argc-MIN_ARGS;
+        retval = UA_ByteString_allocBuffer(trustList, trustListSize);
+        if(retval != UA_STATUSCODE_GOOD) {
+            cleanupClient(client, remoteCertificate);
+            return (int)retval;
+        }
+
+        for(size_t trustListCount = 0; trustListCount < trustListSize; trustListCount++) {
+            trustList[trustListCount] = loadFile(argv[trustListCount+3]);
+        }
+    }
+
+    /* Secure client initialization */
+    client = UA_Client_secure_new(UA_ClientConfig_default,
+                                  certificate, privateKey,
+                                  remoteCertificate,
+                                  trustList, trustListSize,
+                                  revocationList, revocationListSize,
+                                  UA_SecurityPolicy_Basic256Sha256);
+    if(client == NULL) {
+        UA_ByteString_delete(remoteCertificate); /* Dereference the memory */
+        return FAILURE;
+    }
+
+    UA_ByteString_deleteMembers(&certificate);
+    UA_ByteString_deleteMembers(&privateKey);
+    for(size_t deleteCount = 0; deleteCount < trustListSize; deleteCount++) {
+        UA_ByteString_deleteMembers(&trustList[deleteCount]);
+    }
+
+    /* Secure client connect */
+    retval = UA_Client_connect(client, CONNECTION_STRING);
+    if(retval != UA_STATUSCODE_GOOD) {
+        cleanupClient(client, remoteCertificate);
+        return (int)retval;
+    }
+
+    UA_Variant value;
+    UA_Variant_init(&value);
+
+    /* NodeId of the variable holding the current time */
+    const UA_NodeId nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
+    retval = UA_Client_readValueAttribute(client, nodeId, &value);
+
+    if(retval == UA_STATUSCODE_GOOD &&
+       UA_Variant_hasScalarType(&value, &UA_TYPES[UA_TYPES_DATETIME])) {
+        UA_DateTime raw_date  = *(UA_DateTime *) value.data;
+        UA_DateTimeStruct dts = UA_DateTime_toStruct(raw_date);
+        UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "date is: %u-%u-%u %u:%u:%u.%03u\n",
+                    dts.day, dts.month, dts.year, dts.hour, dts.min, dts.sec, dts.milliSec);
+    }
+
+    /* Clean up */
+    UA_Variant_deleteMembers(&value);
+    cleanupClient(client, remoteCertificate);
+    return (int)retval;
+}

+ 2 - 28
examples/encryption/server_basic128rsa15.c

@@ -5,33 +5,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include "open62541.h"
-
-static UA_ByteString loadFile(const char *const path) {
-    UA_ByteString fileContents = UA_STRING_NULL;
-
-    /* Open the file */
-    FILE *fp = fopen(path, "rb");
-    if(!fp) {
-        errno = 0; /* We read errno also from the tcp layer... */
-        return fileContents;
-    }
-
-    /* Get the file length, allocate the data and read */
-    fseek(fp, 0, SEEK_END);
-    fileContents.length = (size_t)ftell(fp);
-    fileContents.data = (UA_Byte*)UA_malloc(fileContents.length * sizeof(UA_Byte));
-    if(fileContents.data) {
-        fseek(fp, 0, SEEK_SET);
-        size_t read = fread(fileContents.data, sizeof(UA_Byte), fileContents.length, fp);
-        if(read != fileContents.length)
-            UA_ByteString_deleteMembers(&fileContents);
-    } else {
-        fileContents.length = 0;
-    }
-    fclose(fp);
-
-    return fileContents;
-}
+#include "../common.h"
 
 UA_Boolean running = true;
 static void stopHandler(int sig) {
@@ -63,7 +37,7 @@ int main(int argc, char* argv[]) {
     for(size_t i = 0; i < trustListSize; i++)
         trustList[i] = loadFile(argv[i+3]);
 
-    /* Loading of a revocation list currentlu unsupported */
+    /* Loading of a revocation list currently unsupported */
     UA_ByteString *revocationList = NULL;
     size_t revocationListSize = 0;
 

+ 64 - 0
examples/encryption/server_basic256sha256.c

@@ -0,0 +1,64 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
+
+#include <signal.h>
+#include <stdio.h>
+#include <errno.h>
+#include "open62541.h"
+#include "../common.h"
+
+UA_Boolean running = true;
+static void stopHandler(int sig) {
+    UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "received ctrl-c");
+    running = false;
+}
+
+int main(int argc, char* argv[]) {
+    signal(SIGINT, stopHandler);
+    signal(SIGTERM, stopHandler);
+
+    if(argc < 3) {
+        UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
+                     "Missing arguments. Arguments are "
+                     "<server-certificate.der> <private-key.der> "
+                     "[<trustlist1.crl>, ...]");
+        return 1;
+    }
+
+    /* Load certificate and private key */
+    UA_ByteString certificate = loadFile(argv[1]);
+    UA_ByteString privateKey = loadFile(argv[2]);
+
+    /* Load the trustlist */
+    size_t trustListSize = 0;
+    if(argc > 3)
+        trustListSize = (size_t)argc-3;
+    UA_STACKARRAY(UA_ByteString, trustList, trustListSize);
+    for(size_t i = 0; i < trustListSize; i++)
+        trustList[i] = loadFile(argv[i+3]);
+
+    /* Loading of a revocation list currently unsupported */
+    UA_ByteString *revocationList = NULL;
+    size_t revocationListSize = 0;
+
+    UA_ServerConfig *config =
+        UA_ServerConfig_new_basic256sha256(4840, &certificate, &privateKey,
+                                          trustList, trustListSize,
+                                          revocationList, revocationListSize);
+    UA_ByteString_deleteMembers(&certificate);
+    UA_ByteString_deleteMembers(&privateKey);
+    for(size_t i = 0; i < trustListSize; i++)
+        UA_ByteString_deleteMembers(&trustList[i]);
+
+    if(!config) {
+        UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
+                     "Could not create the server config");
+        return 1;
+    }
+
+    UA_Server *server = UA_Server_new(config);
+    UA_StatusCode retval = UA_Server_run(server, &running);
+    UA_Server_delete(server);
+    UA_ServerConfig_delete(config);
+    return (int)retval;
+}

+ 2 - 27
examples/server_certificate.c

@@ -10,36 +10,11 @@
 #include <errno.h> // errno, EINTR
 #include <stdlib.h>
 #include "open62541.h"
+#include "common.h"
 
 UA_Boolean running = true;
 UA_Logger logger = UA_Log_Stdout;
 
-static UA_ByteString loadCertificate(void) {
-    UA_ByteString certificate = UA_STRING_NULL;
-    //FIXME: a potiential bug of locating the certificate, we need to get the path from the server's config
-    FILE *fp = fopen("server_cert.der", "rb");
-    if(!fp) {
-        errno = 0; // we read errno also from the tcp layer...
-        UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, "Could not open certificate file");
-        return certificate;
-    }
-
-    fseek(fp, 0, SEEK_END);
-    certificate.length = (size_t)ftell(fp);
-    certificate.data = (UA_Byte *)UA_malloc(certificate.length*sizeof(UA_Byte));
-    if(!certificate.data) {
-        fclose(fp);
-        return UA_STRING_NULL;
-    }
-
-    fseek(fp, 0, SEEK_SET);
-    if(fread(certificate.data, sizeof(UA_Byte), certificate.length, fp) < (size_t)certificate.length)
-        UA_ByteString_deleteMembers(&certificate); // error reading the cert
-    fclose(fp);
-
-    return certificate;
-}
-
 static void stopHandler(int sign) {
     UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c");
     running = false;
@@ -51,7 +26,7 @@ int main(int argc, char** argv) {
     UA_ServerConfig *config = UA_ServerConfig_new_default();
 
     /* load certificate */
-    config->serverCertificate = loadCertificate();
+    config->serverCertificate = loadFile("server_cert.der");
     if(config->serverCertificate.length > 0)
         UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "Certificate loaded");
 

+ 1 - 28
examples/server_ctt.c

@@ -12,6 +12,7 @@
 #include <string.h>
 #include <open62541.h>
 #include "open62541.h"
+#include "common.h"
 
 /* This server is configured to the Compliance Testing Tools (CTT) against. The
  * corresponding CTT configuration is available at
@@ -22,34 +23,6 @@ UA_Logger logger = UA_Log_Stdout;
 
 static const UA_NodeId baseDataVariableType = {0, UA_NODEIDTYPE_NUMERIC, {UA_NS0ID_BASEDATAVARIABLETYPE}};
 
-static UA_ByteString
-loadFile(const char *const path) {
-    UA_ByteString fileContents = UA_STRING_NULL;
-
-    /* Open the file */
-    FILE *fp = fopen(path, "rb");
-    if(!fp) {
-        errno = 0; /* We read errno also from the tcp layer... */
-        return fileContents;
-    }
-
-    /* Get the file length, allocate the data and read */
-    fseek(fp, 0, SEEK_END);
-    fileContents.length = (size_t)ftell(fp);
-    fileContents.data = (UA_Byte *)UA_malloc(fileContents.length * sizeof(UA_Byte));
-    if(fileContents.data) {
-        fseek(fp, 0, SEEK_SET);
-        size_t read = fread(fileContents.data, sizeof(UA_Byte), fileContents.length, fp);
-        if(read != fileContents.length)
-            UA_ByteString_deleteMembers(&fileContents);
-    } else {
-        fileContents.length = 0;
-    }
-    fclose(fp);
-
-    return fileContents;
-}
-
 static void
 stopHandler(int sign) {
     UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "Received Ctrl-C");

+ 12 - 9
include/ua_client.h

@@ -24,6 +24,7 @@ extern "C" {
 #include "ua_types.h"
 #include "ua_types_generated.h"
 #include "ua_types_generated_handling.h"
+#include "ua_plugin_securitypolicy.h"
 #include "ua_plugin_network.h"
 #include "ua_plugin_log.h"
 #include "ua_client_config.h"
@@ -58,20 +59,22 @@ UA_Client_new(UA_ClientConfig config);
 /* Creates a new secure client with the required configuration, certificate
  * privatekey, trustlist and revocation list.
  *
- * @param  config               new secure configuration for client
- * @param  certificate          client certificate
- * @param  privateKey           client's private key
- * @param  remoteCertificate    server certificate form the endpoints
- * @param  trustList            list of trustable certificate
- * @param  trustListSize        count of trustList
- * @param  revocationList       list of revoked digital certificate
- * @param  revocationListSize   count of revocationList
+ * @param  config                   new secure configuration for client
+ * @param  certificate              client certificate
+ * @param  privateKey               client's private key
+ * @param  remoteCertificate        server certificate form the endpoints
+ * @param  trustList                list of trustable certificate
+ * @param  trustListSize            count of trustList
+ * @param  revocationList           list of revoked digital certificate
+ * @param  revocationListSize       count of revocationList
+ * @param  securityPolicyFunction   securityPolicy function
  * @return Returns a client configuration for secure channel */
 UA_Client UA_EXPORT *
 UA_Client_secure_new(UA_ClientConfig config, UA_ByteString certificate,
                      UA_ByteString privateKey, const UA_ByteString *remoteCertificate,
                      const UA_ByteString *trustList, size_t trustListSize,
-                     const UA_ByteString *revocationList, size_t revocationListSize);
+                     const UA_ByteString *revocationList, size_t revocationListSize,
+                     UA_SecurityPolicy_Func securityPolicyFunction);
 
 /* Get the client connection status */
 UA_ClientState UA_EXPORT

+ 7 - 0
include/ua_plugin_securitypolicy.h

@@ -378,6 +378,13 @@ UA_SecurityPolicy_getRemoteAsymEncryptionBufferLengthOverhead(const UA_SecurityP
                                                               const void *channelContext,
                                                               size_t maxEncryptionLength);
 
+
+typedef UA_StatusCode (*UA_SecurityPolicy_Func)(UA_SecurityPolicy *policy,
+                                                UA_CertificateVerification *certificateVerification,
+                                                const UA_ByteString localCertificate,
+                                                const UA_ByteString localPrivateKey,
+                                                UA_Logger logger);
+
 #ifdef __cplusplus
 }
 #endif

+ 1 - 3
plugins/ua_securitypolicy_basic256sha256.c

@@ -200,7 +200,6 @@ asym_encrypt_sp_basic256sha256(const UA_SecurityPolicy *securityPolicy,
     size_t lenDataToEncrypt = data->length;
     size_t inOffset = 0;
     size_t offset = 0;
-    size_t outLength = 0;
     const unsigned char *label = NULL;
     Basic256Sha256_PolicyContext *pc = cc->policyContext;
     while(lenDataToEncrypt >= plainTextBlockSize) {
@@ -215,9 +214,8 @@ asym_encrypt_sp_basic256sha256(const UA_SecurityPolicy *securityPolicy,
             return retval;
         }
 
-        outLength += remoteRsaContext->len;
         inOffset += plainTextBlockSize;
-        offset += outLength;
+        offset += remoteRsaContext->len;
         lenDataToEncrypt -= plainTextBlockSize;
     }
 

+ 31 - 24
src/client/ua_client.c

@@ -58,15 +58,16 @@ UA_Client_new(UA_ClientConfig config) {
 /* Initializes a secure client with the required configuration, certificate
  * privatekey, trustlist and revocation list.
  *
- * @param  client               client to store configuration
- * @param  config               new secure configuration for client
- * @param  certificate          client certificate
- * @param  privateKey           client's private key
- * @param  remoteCertificate    server certificate form the endpoints
- * @param  trustList            list of trustable certificate
- * @param  trustListSize        count of trustList
- * @param  revocationList       list of revoked digital certificate
- * @param  revocationListSize   count of revocationList
+ * @param  client                   client to store configuration
+ * @param  config                   new secure configuration for client
+ * @param  certificate              client certificate
+ * @param  privateKey               client's private key
+ * @param  remoteCertificate        server certificate form the endpoints
+ * @param  trustList                list of trustable certificate
+ * @param  trustListSize            count of trustList
+ * @param  revocationList           list of revoked digital certificate
+ * @param  revocationListSize       count of revocationList
+ * @param  securityPolicyFunction   securityPolicy function
  * @return Returns a client configuration for secure channel */
 static UA_StatusCode
 UA_Client_secure_init(UA_Client* client, UA_ClientConfig config,
@@ -75,7 +76,8 @@ UA_Client_secure_init(UA_Client* client, UA_ClientConfig config,
                       const UA_ByteString *remoteCertificate,
                       const UA_ByteString *trustList, size_t trustListSize,
                       const UA_ByteString *revocationList,
-                      size_t revocationListSize) {
+                      size_t revocationListSize,
+                      UA_SecurityPolicy_Func securityPolicyFunction) {
     if(client == NULL || remoteCertificate == NULL)
         return STATUS_CODE_BAD_POINTER;
 
@@ -93,10 +95,10 @@ UA_Client_secure_init(UA_Client* client, UA_ClientConfig config,
     if(retval != UA_STATUSCODE_GOOD)
          return retval;
 
-    /* Initiate client security policy as Basic128Rsa15 */
-    UA_SecurityPolicy_Basic128Rsa15(&client->securityPolicy,
-                                    client->securityPolicy.certificateVerification,
-                                    certificate, privateKey, config.logger);
+    /* Initiate client security policy */
+    (*securityPolicyFunction)(&client->securityPolicy,
+                              client->securityPolicy.certificateVerification,
+                              certificate, privateKey, config.logger);
     client->channel.securityPolicy = &client->securityPolicy;
     client->channel.securityMode = UA_MESSAGESECURITYMODE_SIGNANDENCRYPT;
     client->config = config;
@@ -135,20 +137,22 @@ UA_Client_secure_init(UA_Client* client, UA_ClientConfig config,
 
 /* Creates a new secure client.
  *
- * @param  config               new secure configuration for client
- * @param  certificate          client certificate
- * @param  privateKey           client's private key
- * @param  remoteCertificate    server certificate form the endpoints
- * @param  trustList            list of trustable certificate
- * @param  trustListSize        count of trustList
- * @param  revocationList       list of revoked digital certificate
- * @param  revocationListSize   count of revocationList
+ * @param  config                   new secure configuration for client
+ * @param  certificate              client certificate
+ * @param  privateKey               client's private key
+ * @param  remoteCertificate        server certificate form the endpoints
+ * @param  trustList                list of trustable certificate
+ * @param  trustListSize            count of trustList
+ * @param  revocationList           list of revoked digital certificate
+ * @param  revocationListSize       count of revocationList
+ * @param  securityPolicyFunction   securityPolicy function
  * @return Returns a client with secure configuration */
 UA_Client *
 UA_Client_secure_new(UA_ClientConfig config, UA_ByteString certificate,
                      UA_ByteString privateKey, const UA_ByteString *remoteCertificate,
                      const UA_ByteString *trustList, size_t trustListSize,
-                     const UA_ByteString *revocationList, size_t revocationListSize) {
+                     const UA_ByteString *revocationList, size_t revocationListSize,
+                     UA_SecurityPolicy_Func securityPolicyFunction) {
     if(remoteCertificate == NULL)
         return NULL;
 
@@ -158,7 +162,8 @@ UA_Client_secure_new(UA_ClientConfig config, UA_ByteString certificate,
 
     UA_StatusCode retval = UA_Client_secure_init(client, config, certificate, privateKey,
                                                  remoteCertificate, trustList, trustListSize,
-                                                 revocationList, revocationListSize);
+                                                 revocationList, revocationListSize,
+                                                 securityPolicyFunction);
     if(retval != UA_STATUSCODE_GOOD){
         return NULL;
     }
@@ -205,6 +210,8 @@ UA_Client_delete(UA_Client* client) {
      * which is deallocated */
     if(client->channel.securityMode == UA_MESSAGESECURITYMODE_SIGN ||
        client->channel.securityMode == UA_MESSAGESECURITYMODE_SIGNANDENCRYPT) {
+        if (client->securityPolicy.certificateVerification->deleteMembers)
+            client->securityPolicy.certificateVerification->deleteMembers(client->securityPolicy.certificateVerification);
         UA_free(client->securityPolicy.certificateVerification);
     }
 

+ 1 - 0
src/client/ua_client_connect.c

@@ -506,6 +506,7 @@ createSession(UA_Client *client) {
     if(response.responseHeader.serviceResult == UA_STATUSCODE_GOOD &&
         (client->channel.securityMode == UA_MESSAGESECURITYMODE_SIGN ||
          client->channel.securityMode == UA_MESSAGESECURITYMODE_SIGNANDENCRYPT)) {
+        UA_ByteString_deleteMembers(&client->channel.remoteNonce);
         UA_ByteString_copy(&response.serverNonce, &client->channel.remoteNonce);
 
         if(!UA_ByteString_equal(&response.serverCertificate,

+ 12 - 0
tests/CMakeLists.txt

@@ -203,6 +203,18 @@ add_executable(check_client_highlevel client/check_client_highlevel.c $<TARGET_O
 target_link_libraries(check_client_highlevel ${LIBS})
 add_test_valgrind(client_highlevel ${TESTS_BINARY_DIR}/check_client_highlevel)
 
+# Test Encryption
+
+if(UA_ENABLE_ENCRYPTION)
+    add_executable(check_encryption_basic128rsa15 encryption/check_encryption_basic128rsa15.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
+    target_link_libraries(check_encryption_basic128rsa15 ${LIBS})
+    add_test_valgrind(encryption_basic128rsa15 ${TESTS_BINARY_DIR}/check_encryption_basic128rsa15)
+
+    add_executable(check_encryption_basic256sha256 encryption/check_encryption_basic256sha256.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
+    target_link_libraries(check_encryption_basic256sha256 ${LIBS})
+    add_test_valgrind(encryption_basic256sha256 ${TESTS_BINARY_DIR}/check_encryption_basic256sha256)
+endif()
+
 #############################
 #                           #
 # Test for Nodeset Compiler #

+ 158 - 0
tests/encryption/certificates.h

@@ -0,0 +1,158 @@
+#ifndef CERTIFICATES_H_
+#define CERTIFICATES_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "ua_types.h"
+
+#define KEY_DER_LENGTH 1193
+UA_Byte KEY_DER_DATA[1193] = {
+	0x30, 0x82, 0x04, 0x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0x62, 0xfa, 0x68, 0x03, 0x09, 0xf1, 0xa6, 0x14, 0xf0, 0xbe, 0xf7, 0x71, 0x3a, 0x01, 0x85, 
+	0x1f, 0x2c, 0x86, 0xde, 0x4a, 0xfb, 0x35, 0x16, 0xc4, 0x84, 0x22, 0x83, 0x49, 0xeb, 0x0d, 0xf7, 
+	0x33, 0x47, 0x8f, 0x96, 0x37, 0x32, 0xd3, 0xd2, 0xec, 0xea, 0x0f, 0xd0, 0xde, 0x0d, 0x27, 0x9e, 
+	0xc1, 0xf1, 0xe0, 0x39, 0xa6, 0x3e, 0x6c, 0xd4, 0x39, 0xdf, 0xde, 0xbd, 0x4c, 0xb8, 0xe7, 0xb7, 
+	0x4e, 0x2a, 0x32, 0x92, 0x83, 0xd3, 0x12, 0xb9, 0xa1, 0x91, 0x52, 0x46, 0x24, 0x58, 0x05, 0x35, 
+	0x22, 0x5f, 0x10, 0x3c, 0x13, 0x5b, 0xbe, 0x47, 0x5e, 0xbf, 0x85, 0xd6, 0xac, 0xfc, 0xbb, 0xd9, 
+	0x91, 0xf9, 0x50, 0x8f, 0xfc, 0xc2, 0x2c, 0x81, 0x5c, 0xa5, 0xc3, 0xc2, 0x15, 0xbe, 0xf4, 0x72, 
+	0xfd, 0x4d, 0xf0, 0x10, 0x6f, 0xe5, 0xbf, 0x8c, 0xb1  
+	};
+
+#define CERT_DER_LENGTH 968
+UA_Byte CERT_DER_DATA[968] = {
+	0x30, 0x82, 0x03, 0xc4, 0x30, 0x82, 0x02, 0xac, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00, 
+	0xa7, 0x17, 0x44, 0x2f, 0x8e, 0x6b, 0x74, 0xba, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 
+	0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x39, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 
+	0x04, 0x06, 0x13, 0x02, 0x44, 0x45, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 
+	0x09, 0x6f, 0x70, 0x65, 0x6e, 0x36, 0x32, 0x35, 0x34, 0x31, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 
+	0x55, 0x04, 0x03, 0x0c, 0x0d, 0x6f, 0x70, 0x65, 0x6e, 0x36, 0x32, 0x35, 0x34, 0x31, 0x2e, 0x6f, 
+	0x72, 0x67, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x38, 0x30, 0x33, 0x32, 0x38, 0x30, 0x38, 0x33, 0x33, 
+	0x35, 0x37, 0x5a, 0x17, 0x0d, 0x32, 0x38, 0x30, 0x33, 0x32, 0x35, 0x30, 0x38, 0x33, 0x33, 0x35, 
+	0x37, 0x5a, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x44, 
+	0x45, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x09, 0x6f, 0x70, 0x65, 0x6e, 
+	0x36, 0x32, 0x35, 0x34, 0x31, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x19, 
+	0x6f, 0x70, 0x65, 0x6e, 0x36, 0x32, 0x35, 0x34, 0x31, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x40, 
+	0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 
+	0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 
+	0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xe0, 0xc9, 0x91, 0x62, 0xcd, 0x91, 
+	0x68, 0x75, 0x2c, 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 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 
+	0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x46, 0x06, 0x03, 
+	0x55, 0x1d, 0x11, 0x04, 0x3f, 0x30, 0x3d, 0x82, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 
+	0x73, 0x74, 0x82, 0x06, 0x64, 0x65, 0x62, 0x69, 0x61, 0x6e, 0x87, 0x04, 0x7f, 0x00, 0x00, 0x01, 
+	0x87, 0x04, 0x00, 0x00, 0x00, 0x00, 0x86, 0x1c, 0x75, 0x72, 0x6e, 0x3a, 0x75, 0x6e, 0x63, 0x6f, 
+	0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x64, 0x3a, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 
+	0x74, 0x69, 0x6f, 0x6e, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 
+	0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0xa4, 0xc1, 0x4f, 0x0e, 0xfe, 0xce, 0x2d, 0x91, 
+	0x8a, 0x51, 0x25, 0xd2, 0x6c, 0x07, 0x86, 0x95, 0xba, 0xc5, 0xe0, 0xad, 0x9b, 0x09, 0x3e, 0x7f, 
+	0x36, 0xc4, 0xa8, 0x10, 0x5b, 0x33, 0x77, 0xe5, 0xb5, 0x3b, 0xd8, 0x98, 0x7c, 0x42, 0x05, 0xcb, 
+	0xb7, 0x91, 0x07, 0x3f, 0x47, 0xff, 0x13, 0x15, 0x45, 0xff, 0x05, 0x03, 0x3d, 0xed, 0x63, 0x96, 
+	0x3a, 0x5c, 0xf8, 0x59, 0xd0, 0xbc, 0x68, 0x8c, 0xfb, 0xf8, 0x29, 0x07, 0x76, 0x63, 0xa7, 0x39, 
+	0xc1, 0x82, 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, 0xd2, 0x8c, 0xfe, 0xd7, 0x51  
+	};
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif /* CERTIFICATES_H_ */

+ 195 - 0
tests/encryption/check_encryption_basic128rsa15.c

@@ -0,0 +1,195 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "ua_types.h"
+#include "ua_server.h"
+#include "ua_server_internal.h"
+#include "ua_client.h"
+#include "client/ua_client_internal.h"
+#include "ua_securitypolicy_basic128rsa15.h"
+#include "ua_config_default.h"
+#include "ua_client_highlevel.h"
+#include "ua_network_tcp.h"
+#include "testing_clock.h"
+#include "testing_networklayers.h"
+#include "check.h"
+#include "thread_wrapper.h"
+#include "certificates.h"
+
+UA_Server *server;
+UA_ServerConfig *config;
+UA_Boolean *running;
+UA_ServerNetworkLayer nl;
+THREAD_HANDLE server_thread;
+
+THREAD_CALLBACK(serverloop) {
+    while(*running)
+        UA_Server_run_iterate(server, true);
+    return 0;
+}
+
+static void setup(void) {
+    running = UA_Boolean_new();
+    *running = true;
+
+    /* Load certificate and private key */
+    UA_ByteString certificate;
+    certificate.length = CERT_DER_LENGTH;
+    certificate.data = CERT_DER_DATA;
+
+    UA_ByteString privateKey;
+    privateKey.length = KEY_DER_LENGTH;
+    privateKey.data = KEY_DER_DATA;
+
+    /* Load the trustlist */
+    size_t trustListSize = 0;
+    UA_ByteString *trustList = NULL;
+
+    /* TODO test trustList
+    if(argc > 3)
+        trustListSize = (size_t)argc-3;
+    UA_STACKARRAY(UA_ByteString, trustList, trustListSize);
+    for(size_t i = 0; i < trustListSize; i++)
+        trustList[i] = loadFile(argv[i+3]);
+    */
+
+    /* Loading of a revocation list currently unsupported */
+    UA_ByteString *revocationList = NULL;
+    size_t revocationListSize = 0;
+
+    config = UA_ServerConfig_new_basic128rsa15(4840, &certificate, &privateKey,
+                                               trustList, trustListSize,
+                                               revocationList, revocationListSize);
+
+    for(size_t i = 0; i < trustListSize; i++)
+        UA_ByteString_deleteMembers(&trustList[i]);
+
+    server = UA_Server_new(config);
+    UA_Server_run_startup(server);
+    THREAD_CREATE(server_thread, serverloop);
+}
+
+static void teardown(void) {
+    *running = false;
+    THREAD_JOIN(server_thread);
+    UA_Server_run_shutdown(server);
+    UA_Boolean_delete(running);
+    UA_Server_delete(server);
+    UA_ServerConfig_delete(config);
+}
+
+START_TEST(encryption_connect) {
+    UA_Client *client = NULL;
+    UA_EndpointDescription* endpointArray = NULL;
+    size_t endpointArraySize = 0;
+    UA_ByteString *trustList = NULL;
+    size_t trustListSize = 0;
+    UA_ByteString *revocationList = NULL;
+    size_t revocationListSize = 0;
+    UA_ByteString *remoteCertificate = NULL;
+
+    /* Load certificate and private key */
+    UA_ByteString certificate;
+    certificate.length = CERT_DER_LENGTH;
+    certificate.data = CERT_DER_DATA;
+    ck_assert_int_ne(certificate.length, 0);
+
+    UA_ByteString privateKey;
+    privateKey.length = KEY_DER_LENGTH;
+    privateKey.data = KEY_DER_DATA;
+    ck_assert_int_ne(privateKey.length, 0);
+
+    /* The Get endpoint (discovery service) is done with
+     * security mode as none to see the server's capability
+     * and certificate */
+    client = UA_Client_new(UA_ClientConfig_default);
+    ck_assert_msg(client != NULL);
+    remoteCertificate = UA_ByteString_new();
+    UA_StatusCode retval = UA_Client_getEndpoints(client, "opc.tcp://localhost:4840",
+                                                  &endpointArraySize, &endpointArray);
+    ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
+
+    for(size_t endPointCount = 0; endPointCount < endpointArraySize; endPointCount++) {
+        if(endpointArray[endPointCount].securityMode == UA_MESSAGESECURITYMODE_SIGNANDENCRYPT)
+            UA_ByteString_copy(&endpointArray[endPointCount].serverCertificate, remoteCertificate);
+    }
+
+    if(UA_ByteString_equal(remoteCertificate, &UA_BYTESTRING_NULL)) {
+        ck_abort_msg("Server does not support Security Mode of UA_MESSAGESECURITYMODE_SIGNANDENCRYPT");
+    }
+
+    UA_Array_delete(endpointArray, endpointArraySize,
+                    &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
+
+    /* TODO test trustList Load revocationList is not supported now
+    if(argc > MIN_ARGS) {
+        trustListSize = (size_t)argc-MIN_ARGS;
+        retval = UA_ByteString_allocBuffer(trustList, trustListSize);
+        if(retval != UA_STATUSCODE_GOOD) {
+            cleanupClient(client, remoteCertificate);
+            return (int)retval;
+        }
+
+        for(size_t trustListCount = 0; trustListCount < trustListSize; trustListCount++) {
+            trustList[trustListCount] = loadFile(argv[trustListCount+3]);
+        }
+    }
+    */
+
+    UA_Client_delete(client);
+
+    /* Secure client initialization */
+    client = UA_Client_secure_new(UA_ClientConfig_default,
+                                  certificate, privateKey,
+                                  remoteCertificate,
+                                  trustList, trustListSize,
+                                  revocationList, revocationListSize,
+                                  UA_SecurityPolicy_Basic128Rsa15);
+    ck_assert_msg(client != NULL);
+
+    for(size_t deleteCount = 0; deleteCount < trustListSize; deleteCount++) {
+        UA_ByteString_deleteMembers(&trustList[deleteCount]);
+    }
+
+    /* Secure client connect */
+    retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
+    ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
+
+    UA_Variant val;
+    UA_Variant_init(&val);
+    UA_NodeId nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE);
+    retval = UA_Client_readValueAttribute(client, nodeId, &val);
+    ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
+    UA_Variant_deleteMembers(&val);
+
+    UA_ByteString_delete(remoteCertificate);
+
+    UA_Client_disconnect(client);
+    UA_Client_delete(client);
+}
+END_TEST
+
+static Suite* testSuite_encryption(void) {
+    Suite *s = suite_create("Encryption");
+    TCase *tc_encryption = tcase_create("Encryption basic128rsa15");
+    tcase_add_checked_fixture(tc_encryption, setup, teardown);
+#ifdef UA_ENABLE_ENCRYPTION
+    tcase_add_test(tc_encryption, encryption_connect);
+#endif /* UA_ENABLE_ENCRYPTION */
+    suite_add_tcase(s,tc_encryption);
+    return s;
+}
+
+int main(void) {
+    Suite *s = testSuite_encryption();
+    SRunner *sr = srunner_create(s);
+    srunner_set_fork_status(sr, CK_NOFORK);
+    srunner_run_all(sr,CK_NORMAL);
+    int number_failed = srunner_ntests_failed(sr);
+    srunner_free(sr);
+    return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}

+ 195 - 0
tests/encryption/check_encryption_basic256sha256.c

@@ -0,0 +1,195 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "ua_types.h"
+#include "ua_server.h"
+#include "ua_server_internal.h"
+#include "ua_client.h"
+#include "client/ua_client_internal.h"
+#include "ua_securitypolicy_basic256sha256.h"
+#include "ua_config_default.h"
+#include "ua_client_highlevel.h"
+#include "ua_network_tcp.h"
+#include "testing_clock.h"
+#include "testing_networklayers.h"
+#include "check.h"
+#include "thread_wrapper.h"
+#include "certificates.h"
+
+UA_Server *server;
+UA_ServerConfig *config;
+UA_Boolean *running;
+UA_ServerNetworkLayer nl;
+THREAD_HANDLE server_thread;
+
+THREAD_CALLBACK(serverloop) {
+    while(*running)
+        UA_Server_run_iterate(server, true);
+    return 0;
+}
+
+static void setup(void) {
+    running = UA_Boolean_new();
+    *running = true;
+
+    /* Load certificate and private key */
+    UA_ByteString certificate;
+    certificate.length = CERT_DER_LENGTH;
+    certificate.data = CERT_DER_DATA;
+
+    UA_ByteString privateKey;
+    privateKey.length = KEY_DER_LENGTH;
+    privateKey.data = KEY_DER_DATA;
+
+    /* Load the trustlist */
+    size_t trustListSize = 0;
+    UA_ByteString *trustList = NULL;
+
+    /* TODO test trustList
+    if(argc > 3)
+        trustListSize = (size_t)argc-3;
+    UA_STACKARRAY(UA_ByteString, trustList, trustListSize);
+    for(size_t i = 0; i < trustListSize; i++)
+        trustList[i] = loadFile(argv[i+3]);
+    */
+
+    /* Loading of a revocation list currently unsupported */
+    UA_ByteString *revocationList = NULL;
+    size_t revocationListSize = 0;
+
+    config = UA_ServerConfig_new_basic256sha256(4840, &certificate, &privateKey,
+                                                trustList, trustListSize,
+                                                revocationList, revocationListSize);
+
+    for(size_t i = 0; i < trustListSize; i++)
+        UA_ByteString_deleteMembers(&trustList[i]);
+
+    server = UA_Server_new(config);
+    UA_Server_run_startup(server);
+    THREAD_CREATE(server_thread, serverloop);
+}
+
+static void teardown(void) {
+    *running = false;
+    THREAD_JOIN(server_thread);
+    UA_Server_run_shutdown(server);
+    UA_Boolean_delete(running);
+    UA_Server_delete(server);
+    UA_ServerConfig_delete(config);
+}
+
+START_TEST(encryption_connect) {
+    UA_Client *client = NULL;
+    UA_EndpointDescription* endpointArray = NULL;
+    size_t endpointArraySize = 0;
+    UA_ByteString *trustList = NULL;
+    size_t trustListSize = 0;
+    UA_ByteString *revocationList = NULL;
+    size_t revocationListSize = 0;
+    UA_ByteString *remoteCertificate = NULL;
+
+    /* Load certificate and private key */
+    UA_ByteString certificate;
+    certificate.length = CERT_DER_LENGTH;
+    certificate.data = CERT_DER_DATA;
+    ck_assert_int_ne(certificate.length, 0);
+
+    UA_ByteString privateKey;
+    privateKey.length = KEY_DER_LENGTH;
+    privateKey.data = KEY_DER_DATA;
+    ck_assert_int_ne(privateKey.length, 0);
+
+    /* The Get endpoint (discovery service) is done with
+     * security mode as none to see the server's capability
+     * and certificate */
+    client = UA_Client_new(UA_ClientConfig_default);
+    ck_assert_msg(client != NULL);
+    remoteCertificate = UA_ByteString_new();
+    UA_StatusCode retval = UA_Client_getEndpoints(client, "opc.tcp://localhost:4840",
+                                                  &endpointArraySize, &endpointArray);
+    ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
+
+    for(size_t endPointCount = 0; endPointCount < endpointArraySize; endPointCount++) {
+        if(endpointArray[endPointCount].securityMode == UA_MESSAGESECURITYMODE_SIGNANDENCRYPT)
+            UA_ByteString_copy(&endpointArray[endPointCount].serverCertificate, remoteCertificate);
+    }
+
+    if(UA_ByteString_equal(remoteCertificate, &UA_BYTESTRING_NULL)) {
+        ck_abort_msg("Server does not support Security Mode of UA_MESSAGESECURITYMODE_SIGNANDENCRYPT");
+    }
+
+    UA_Array_delete(endpointArray, endpointArraySize,
+                    &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
+
+    /* TODO test trustList Load revocationList is not supported now
+    if(argc > MIN_ARGS) {
+        trustListSize = (size_t)argc-MIN_ARGS;
+        retval = UA_ByteString_allocBuffer(trustList, trustListSize);
+        if(retval != UA_STATUSCODE_GOOD) {
+            cleanupClient(client, remoteCertificate);
+            return (int)retval;
+        }
+
+        for(size_t trustListCount = 0; trustListCount < trustListSize; trustListCount++) {
+            trustList[trustListCount] = loadFile(argv[trustListCount+3]);
+        }
+    }
+    */
+
+    UA_Client_delete(client);
+
+    /* Secure client initialization */
+    client = UA_Client_secure_new(UA_ClientConfig_default,
+                                  certificate, privateKey,
+                                  remoteCertificate,
+                                  trustList, trustListSize,
+                                  revocationList, revocationListSize,
+                                  UA_SecurityPolicy_Basic256Sha256);
+    ck_assert_msg(client != NULL);
+
+    for(size_t deleteCount = 0; deleteCount < trustListSize; deleteCount++) {
+        UA_ByteString_deleteMembers(&trustList[deleteCount]);
+    }
+
+    /* Secure client connect */
+    retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
+    ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
+
+    UA_Variant val;
+    UA_Variant_init(&val);
+    UA_NodeId nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE);
+    retval = UA_Client_readValueAttribute(client, nodeId, &val);
+    ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
+    UA_Variant_deleteMembers(&val);
+
+    UA_ByteString_delete(remoteCertificate);
+
+    UA_Client_disconnect(client);
+    UA_Client_delete(client);
+}
+END_TEST
+
+static Suite* testSuite_encryption(void) {
+    Suite *s = suite_create("Encryption");
+    TCase *tc_encryption = tcase_create("Encryption basic256sha256");
+    tcase_add_checked_fixture(tc_encryption, setup, teardown);
+#ifdef UA_ENABLE_ENCRYPTION
+    tcase_add_test(tc_encryption, encryption_connect);
+#endif /* UA_ENABLE_ENCRYPTION */
+    suite_add_tcase(s,tc_encryption);
+    return s;
+}
+
+int main(void) {
+    Suite *s = testSuite_encryption();
+    SRunner *sr = srunner_create(s);
+    srunner_set_fork_status(sr, CK_NOFORK);
+    srunner_run_all(sr,CK_NORMAL);
+    int number_failed = srunner_ntests_failed(sr);
+    srunner_free(sr);
+    return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}

+ 4 - 1
tests/fuzz/ua_debug_dump_pkgs_file.c

@@ -158,8 +158,11 @@ UA_debug_dumpCompleteChunk(UA_Server *const server, UA_Connection *const connect
     } else {
         // make a backup of the sequence number and reset it, because processChunk increases it
         UA_UInt32 seqBackup = connection->channel->receiveSequenceNumber;
-        UA_SecureChannel_processChunk(connection->channel, messageBuffer,
+        UA_ByteString messageBufferCopy;
+        UA_ByteString_copy(messageBuffer, &messageBufferCopy);
+        UA_SecureChannel_processChunk(connection->channel, &messageBufferCopy,
                                       UA_debug_dump_setName_withChannel, &dump_filename);
+        UA_ByteString_deleteMembers(&messageBufferCopy);
         connection->channel->receiveSequenceNumber = seqBackup;
     }
 

+ 4 - 1
tools/travis/travis_linux_script.sh

@@ -4,7 +4,10 @@ set -e
 
 # Sonar code quality
 if ! [ -z ${SONAR+x} ]; then
-    if ! [ "${TRAVIS_REPO_SLUG}" = "open62541/open62541" ]; then
+    if ([ "${TRAVIS_REPO_SLUG}" != "open62541/open62541" ] ||
+        [ "${TRAVIS_PULL_REQUEST}" != "false" ] ||
+        [ "${TRAVIS_BRANCH}" != "master" ]); then
+        echo "Skipping Sonarcloud on forks"
         # Skip on forks
         exit 0;
     fi