Browse Source

AddRules enum to configure rule checking; Configure VerifyTimeStamps

The RuleHanding settings define how error cases that result from rules
in the OPC UA specification shall be handled. The rule handling can be
softened, e.g. to workaround misbehaving implementations or to mitigate
the impact of additional rules that are introduced in later versions
of the OPC UA specification.
Julius Pfrommer 5 years ago
parent
commit
488abc531b
3 changed files with 35 additions and 3 deletions
  1. 22 0
      include/open62541/constants.h
  2. 4 0
      include/open62541/server_config.h
  3. 9 3
      src/server/ua_server_binary.c

+ 22 - 0
include/open62541/constants.h

@@ -111,6 +111,28 @@ typedef enum {
 #define UA_VALUERANK_TWO_DIMENSIONS            2
 #define UA_VALUERANK_THREE_DIMENSIONS          3
 
+/**
+ * General Configuration Constants
+ * ===============================
+ *
+ * This section defines constants that are used for the configuration of both
+ * clients and servers.
+ *
+ * Rule Handling
+ * -------------
+ *
+ * The RuleHanding settings define how error cases that result from rules in the
+ * OPC UA specification shall be handled. The rule handling can be softened,
+ * e.g. to workaround misbehaving implementations or to mitigate the impact of
+ * additional rules that are introduced in later versions of the OPC UA
+ * specification. */
+typedef enum {
+    UA_RULEHANDLING_DEFAULT = 0,
+    UA_RULEHANDLING_ABORT,  /* Abort the operation and return an error code */
+    UA_RULEHANDLING_WARN,   /* Print a message in the logs and continue */
+    UA_RULEHANDLING_ACCEPT, /* Continue and disregard the broken rule */
+} UA_RuleHandling;
+
 _UA_END_DECLS
 
 #endif /* UA_CONSTANTS_H_ */

+ 4 - 0
include/open62541/server_config.h

@@ -69,6 +69,10 @@ struct UA_ServerConfig {
     UA_ApplicationDescription applicationDescription;
     UA_ByteString serverCertificate;
 
+    /* Rule Handling */
+    UA_RuleHandling verifyRequestTimestamp; /* Verify that the server sends a
+                                             * timestamp in the request header */
+
     /* MDNS Discovery */
 #ifdef UA_ENABLE_DISCOVERY
     UA_String mdnsServerName;

+ 9 - 3
src/server/ua_server_binary.c

@@ -562,9 +562,15 @@ processMSG(UA_Server *server, UA_SecureChannel *channel,
     ((UA_ResponseHeader*)response)->timestamp = UA_DateTime_now();
 
     /* Check timestamp in the request header */
-    if(!(requestHeader->timestamp)) {
-        return sendServiceFault(channel, msg, requestPos, responseType,
-                                requestId, UA_STATUSCODE_BADINVALIDTIMESTAMP);
+    if(requestHeader->timestamp == 0) {
+        if(server->config.verifyRequestTimestamp <= UA_RULEHANDLING_WARN) {
+            UA_LOG_WARNING_CHANNEL(&server->config.logger, channel,
+                                   "The server sends no timestamp in the request header. "
+                                   "See the 'verifyRequestTimestamp' setting.");
+            if(server->config.verifyRequestTimestamp <= UA_RULEHANDLING_ABORT)
+                return sendServiceFault(channel, msg, requestPos, responseType,
+                                        requestId, UA_STATUSCODE_BADINVALIDTIMESTAMP);
+        }
     }
 
     /* Process normal services before initializing the message context.