Selaa lähdekoodia

feature(server): Don't start server with mismatching ApplicationUri

Also, upgrade to an error warning
Julius Pfrommer 5 vuotta sitten
vanhempi
commit
645b29277f

+ 10 - 8
src/server/ua_server.c

@@ -468,9 +468,8 @@ UA_SecurityPolicy_getSecurityPolicyByUri(const UA_Server *server,
 #ifdef UA_ENABLE_ENCRYPTION
 /* The local ApplicationURI has to match the certificates of the
  * SecurityPolicies */
-static void
+static UA_StatusCode
 verifyServerApplicationURI(const UA_Server *server) {
-#if UA_LOGLEVEL <= 400
     for(size_t i = 0; i < server->config.securityPoliciesSize; i++) {
         UA_SecurityPolicy *sp = &server->config.securityPolicies[i];
         if(!sp->certificateVerification)
@@ -481,13 +480,14 @@ verifyServerApplicationURI(const UA_Server *server) {
                                  &sp->localCertificate,
                                  &server->config.applicationDescription.applicationUri);
         if(retval != UA_STATUSCODE_GOOD) {
-            UA_LOG_WARNING(&server->config.logger, UA_LOGCATEGORY_SERVER,
-                           "The configured ApplicationURI does not match the URI "
-                           "specified in the certificate for the SecurityPolicy %.*s",
-                           (int)sp->policyUri.length, sp->policyUri.data);
+            UA_LOG_ERROR(&server->config.logger, UA_LOGCATEGORY_SERVER,
+                         "The configured ApplicationURI does not match the URI "
+                         "specified in the certificate for the SecurityPolicy %.*s",
+                         (int)sp->policyUri.length, sp->policyUri.data);
+            return retval;
         }
     }
-#endif
+    return UA_STATUSCODE_GOOD;
 }
 #endif
 
@@ -532,7 +532,9 @@ UA_Server_run_startup(UA_Server *server) {
 
     /* Does the ApplicationURI match the local certificates? */
 #ifdef UA_ENABLE_ENCRYPTION
-    verifyServerApplicationURI(server);
+    retVal = verifyServerApplicationURI(server);
+    if(retVal != UA_STATUSCODE_GOOD)
+        return retVal;
 #endif
 
     /* Sample the start time and set it to the Server object */

+ 7 - 2
tests/encryption/check_encryption_basic128rsa15.c

@@ -66,12 +66,17 @@ static void setup(void) {
     size_t revocationListSize = 0;
 
     server = UA_Server_new();
-    UA_ServerConfig_setDefaultWithSecurityPolicies(UA_Server_getConfig(server),
-                                                   4840, &certificate, &privateKey,
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefaultWithSecurityPolicies(config, 4840, &certificate, &privateKey,
                                                    trustList, trustListSize,
                                                    issuerList, issuerListSize,
                                                    revocationList, revocationListSize);
 
+    /* Set the ApplicationUri used in the certificate */
+    UA_String_clear(&config->applicationDescription.applicationUri);
+    config->applicationDescription.applicationUri =
+        UA_STRING_ALLOC("urn:unconfigured:application");
+
     for(size_t i = 0; i < trustListSize; i++)
         UA_ByteString_deleteMembers(&trustList[i]);
 

+ 7 - 2
tests/encryption/check_encryption_basic256sha256.c

@@ -69,12 +69,17 @@ static void setup(void) {
     size_t revocationListSize = 0;
 
     server = UA_Server_new();
-    UA_ServerConfig_setDefaultWithSecurityPolicies(UA_Server_getConfig(server),
-                                                   4840, &certificate, &privateKey,
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefaultWithSecurityPolicies(config, 4840, &certificate, &privateKey,
                                                    trustList, trustListSize,
                                                    issuerList, issuerListSize,
                                                    revocationList, revocationListSize);
 
+    /* Set the ApplicationUri used in the certificate */
+    UA_String_clear(&config->applicationDescription.applicationUri);
+    config->applicationDescription.applicationUri =
+        UA_STRING_ALLOC("urn:unconfigured:application");
+
     for(size_t i = 0; i < trustListSize; i++)
         UA_ByteString_deleteMembers(&trustList[i]);