diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-17 03:23:19 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-17 03:23:19 +0100 |
| commit | 1bbf7e6c2ff571b2e26b643a7e86e35790b91875 (patch) | |
| tree | f455073490071b96cc45f7db4898fcd8e6431a8e /src/server_lds.c | |
| parent | c35eb35bb63a97b7c46e879819757a9cb48165b5 (diff) | |
| download | BobinkCOpcUa-1bbf7e6c2ff571b2e26b643a7e86e35790b91875.tar.gz BobinkCOpcUa-1bbf7e6c2ff571b2e26b643a7e86e35790b91875.zip | |
Add username/password authentication to servers and client
Disallow anonymous sessions on both the LDS and registering server by
configuring UA_AccessControl_default with a hardcoded user/password
credential pair. Set UA_ClientConfig_setAuthenticationUsername on the
client configs used for register, re-register, and deregister calls.
Use UA_Client_connectUsername in the FindServers client when reading
server time.
Diffstat (limited to 'src/server_lds.c')
| -rw-r--r-- | src/server_lds.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/server_lds.c b/src/server_lds.c index a7794aa..12dfe59 100644 --- a/src/server_lds.c +++ b/src/server_lds.c @@ -10,6 +10,7 @@ #include "common.h" +#include <open62541/plugin/accesscontrol_default.h> #include <open62541/plugin/log_stdout.h> #include <open62541/server.h> #include <open62541/server_config_default.h> @@ -66,6 +67,19 @@ main (int argc, char *argv[]) UA_ServerConfig *serverConfig = UA_Server_getConfig (server); + /* Disallow anonymous sessions. + UA_ServerConfig_setDefaultWithSecurityPolicies (called by + createSecureServer) resets access control, so this must come after server + creation. The static credential list is deep-copied. */ + UA_UsernamePasswordLogin logins[] + = { { UA_STRING_STATIC ("user"), UA_STRING_STATIC ("password") } }; + retval = UA_AccessControl_default (serverConfig, false, NULL, 1, logins); + if (retval != UA_STATUSCODE_GOOD) + { + UA_Server_delete (server); + return EXIT_FAILURE; + } + /* Mark this server as a Discovery Server so clients can identify it. */ serverConfig->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER; |
