ua_config_default.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  3. *
  4. * Copyright 2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  5. * Copyright 2017 (c) Julian Grothoff
  6. * Copyright 2017-2018 (c) Mark Giraud, Fraunhofer IOSB
  7. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  8. * Copyright 2017 (c) Thomas Stalder, Blue Time Concept SA
  9. * Copyright 2018 (c) Daniel Feist, Precitec GmbH & Co. KG
  10. * Copyright 2018 (c) Fabian Arndt, Root-Core
  11. * Copyright 2019 (c) Kalycito Infotech Private Limited
  12. */
  13. #include <open62541/client_config_default.h>
  14. #include <open62541/network_tcp.h>
  15. #include <open62541/plugin/accesscontrol_default.h>
  16. #include <open62541/plugin/log_stdout.h>
  17. #include <open62541/plugin/pki_default.h>
  18. #include <open62541/plugin/securitypolicy_default.h>
  19. #include <open62541/server_config_default.h>
  20. /* Struct initialization works across ANSI C/C99/C++ if it is done when the
  21. * variable is first declared. Assigning values to existing structs is
  22. * heterogeneous across the three. */
  23. static UA_INLINE UA_UInt32Range
  24. UA_UINT32RANGE(UA_UInt32 min, UA_UInt32 max) {
  25. UA_UInt32Range range = {min, max};
  26. return range;
  27. }
  28. static UA_INLINE UA_DurationRange
  29. UA_DURATIONRANGE(UA_Duration min, UA_Duration max) {
  30. UA_DurationRange range = {min, max};
  31. return range;
  32. }
  33. /*******************************/
  34. /* Default Connection Settings */
  35. /*******************************/
  36. const UA_ConnectionConfig UA_ConnectionConfig_default = {
  37. 0, /* .protocolVersion */
  38. 65535, /* .sendBufferSize, 64k per chunk */
  39. 65535, /* .recvBufferSize, 64k per chunk */
  40. 0, /* .maxMessageSize, 0 -> unlimited */
  41. 0 /* .maxChunkCount, 0 -> unlimited */
  42. };
  43. /***************************/
  44. /* Default Server Settings */
  45. /***************************/
  46. #define MANUFACTURER_NAME "open62541"
  47. #define PRODUCT_NAME "open62541 OPC UA Server"
  48. #define PRODUCT_URI "http://open62541.org"
  49. #define APPLICATION_NAME "open62541-based OPC UA Application"
  50. #define APPLICATION_URI "urn:unconfigured:application"
  51. #define STRINGIFY(arg) #arg
  52. #define VERSION(MAJOR, MINOR, PATCH, LABEL) \
  53. STRINGIFY(MAJOR) "." STRINGIFY(MINOR) "." STRINGIFY(PATCH) LABEL
  54. static UA_StatusCode
  55. createEndpoint(UA_ServerConfig *conf, UA_EndpointDescription *endpoint,
  56. const UA_SecurityPolicy *securityPolicy,
  57. UA_MessageSecurityMode securityMode) {
  58. UA_EndpointDescription_init(endpoint);
  59. endpoint->securityMode = securityMode;
  60. UA_String_copy(&securityPolicy->policyUri, &endpoint->securityPolicyUri);
  61. endpoint->transportProfileUri =
  62. UA_STRING_ALLOC("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary");
  63. /* Add security level value for the corresponding message security mode */
  64. endpoint->securityLevel = (UA_Byte) securityMode;
  65. /* Enable all login mechanisms from the access control plugin */
  66. UA_StatusCode retval = UA_Array_copy(conf->accessControl.userTokenPolicies,
  67. conf->accessControl.userTokenPoliciesSize,
  68. (void **)&endpoint->userIdentityTokens,
  69. &UA_TYPES[UA_TYPES_USERTOKENPOLICY]);
  70. if(retval != UA_STATUSCODE_GOOD)
  71. return retval;
  72. endpoint->userIdentityTokensSize =
  73. conf->accessControl.userTokenPoliciesSize;
  74. UA_String_copy(&securityPolicy->localCertificate, &endpoint->serverCertificate);
  75. UA_ApplicationDescription_copy(&conf->applicationDescription,
  76. &endpoint->server);
  77. return UA_STATUSCODE_GOOD;
  78. }
  79. static const size_t usernamePasswordsSize = 2;
  80. static UA_UsernamePasswordLogin usernamePasswords[2] = {
  81. {UA_STRING_STATIC("user1"), UA_STRING_STATIC("password")},
  82. {UA_STRING_STATIC("user2"), UA_STRING_STATIC("password1")}};
  83. static UA_StatusCode
  84. setDefaultConfig(UA_ServerConfig *conf) {
  85. if (!conf)
  86. return UA_STATUSCODE_BADINVALIDARGUMENT;
  87. /* Zero out.. All members have a valid initial value */
  88. UA_ServerConfig_clean(conf);
  89. memset(conf, 0, sizeof(UA_ServerConfig));
  90. /* --> Start setting the default static config <-- */
  91. conf->nThreads = 1;
  92. conf->logger = UA_Log_Stdout_;
  93. /* Server Description */
  94. conf->buildInfo.productUri = UA_STRING_ALLOC(PRODUCT_URI);
  95. conf->buildInfo.manufacturerName = UA_STRING_ALLOC(MANUFACTURER_NAME);
  96. conf->buildInfo.productName = UA_STRING_ALLOC(PRODUCT_NAME);
  97. conf->buildInfo.softwareVersion =
  98. UA_STRING_ALLOC(VERSION(UA_OPEN62541_VER_MAJOR, UA_OPEN62541_VER_MINOR,
  99. UA_OPEN62541_VER_PATCH, UA_OPEN62541_VER_LABEL));
  100. #ifdef UA_PACK_DEBIAN
  101. conf->buildInfo.buildNumber = UA_STRING_ALLOC("deb");
  102. #else
  103. conf->buildInfo.buildNumber = UA_STRING_ALLOC(__DATE__ " " __TIME__);
  104. #endif
  105. conf->buildInfo.buildDate = 0;
  106. conf->applicationDescription.applicationUri = UA_STRING_ALLOC(APPLICATION_URI);
  107. conf->applicationDescription.productUri = UA_STRING_ALLOC(PRODUCT_URI);
  108. conf->applicationDescription.applicationName =
  109. UA_LOCALIZEDTEXT_ALLOC("en", APPLICATION_NAME);
  110. conf->applicationDescription.applicationType = UA_APPLICATIONTYPE_SERVER;
  111. /* conf->applicationDescription.gatewayServerUri = UA_STRING_NULL; */
  112. /* conf->applicationDescription.discoveryProfileUri = UA_STRING_NULL; */
  113. /* conf->applicationDescription.discoveryUrlsSize = 0; */
  114. /* conf->applicationDescription.discoveryUrls = NULL; */
  115. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  116. UA_MdnsDiscoveryConfiguration_init(&conf->discovery.mdns);
  117. #endif
  118. /* Custom DataTypes */
  119. /* conf->customDataTypesSize = 0; */
  120. /* conf->customDataTypes = NULL; */
  121. /* Networking */
  122. /* conf->networkLayersSize = 0; */
  123. /* conf->networkLayers = NULL; */
  124. /* conf->customHostname = UA_STRING_NULL; */
  125. /* Endpoints */
  126. /* conf->endpoints = {0, NULL}; */
  127. /* Certificate Verification that accepts every certificate. Can be
  128. * overwritten when the policy is specialized. */
  129. UA_CertificateVerification_AcceptAll(&conf->certificateVerification);
  130. /* Global Node Lifecycle */
  131. conf->nodeLifecycle.constructor = NULL;
  132. conf->nodeLifecycle.destructor = NULL;
  133. UA_StatusCode retval = UA_AccessControl_default(&conf->accessControl, true,
  134. usernamePasswordsSize,
  135. usernamePasswords);
  136. if(retval != UA_STATUSCODE_GOOD) {
  137. UA_ServerConfig_clean(conf);
  138. return retval;
  139. }
  140. /* Relax constraints for the InformationModel */
  141. conf->relaxEmptyValueConstraint = true; /* Allow empty values */
  142. /* Limits for SecureChannels */
  143. conf->maxSecureChannels = 40;
  144. conf->maxSecurityTokenLifetime = 10 * 60 * 1000; /* 10 minutes */
  145. /* Limits for Sessions */
  146. conf->maxSessions = 100;
  147. conf->maxSessionTimeout = 60.0 * 60.0 * 1000.0; /* 1h */
  148. /* Limits for Subscriptions */
  149. conf->publishingIntervalLimits = UA_DURATIONRANGE(100.0, 3600.0 * 1000.0);
  150. conf->lifeTimeCountLimits = UA_UINT32RANGE(3, 15000);
  151. conf->keepAliveCountLimits = UA_UINT32RANGE(1, 100);
  152. conf->maxNotificationsPerPublish = 1000;
  153. conf->enableRetransmissionQueue = true;
  154. conf->maxRetransmissionQueueSize = 0; /* unlimited */
  155. #ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS
  156. conf->maxEventsPerNode = 0; /* unlimited */
  157. #endif
  158. /* Limits for MonitoredItems */
  159. conf->samplingIntervalLimits = UA_DURATIONRANGE(50.0, 24.0 * 3600.0 * 1000.0);
  160. conf->queueSizeLimits = UA_UINT32RANGE(1, 100);
  161. #ifdef UA_ENABLE_DISCOVERY
  162. conf->discovery.cleanupTimeout = 60 * 60;
  163. #endif
  164. #ifdef UA_ENABLE_HISTORIZING
  165. /* conf->accessHistoryDataCapability = UA_FALSE; */
  166. /* conf->maxReturnDataValues = 0; */
  167. /* conf->accessHistoryEventsCapability = UA_FALSE; */
  168. /* conf->maxReturnEventValues = 0; */
  169. /* conf->insertDataCapability = UA_FALSE; */
  170. /* conf->insertEventCapability = UA_FALSE; */
  171. /* conf->insertAnnotationsCapability = UA_FALSE; */
  172. /* conf->replaceDataCapability = UA_FALSE; */
  173. /* conf->replaceEventCapability = UA_FALSE; */
  174. /* conf->updateDataCapability = UA_FALSE; */
  175. /* conf->updateEventCapability = UA_FALSE; */
  176. /* conf->deleteRawCapability = UA_FALSE; */
  177. /* conf->deleteEventCapability = UA_FALSE; */
  178. /* conf->deleteAtTimeDataCapability = UA_FALSE; */
  179. #endif
  180. /* --> Finish setting the default static config <-- */
  181. return UA_STATUSCODE_GOOD;
  182. }
  183. static UA_StatusCode
  184. addDefaultNetworkLayers(UA_ServerConfig *conf, UA_UInt16 portNumber,
  185. UA_UInt32 sendBufferSize, UA_UInt32 recvBufferSize) {
  186. /* Add a network layer */
  187. conf->networkLayers = (UA_ServerNetworkLayer *)
  188. UA_malloc(sizeof(UA_ServerNetworkLayer));
  189. if(!conf->networkLayers)
  190. return UA_STATUSCODE_BADOUTOFMEMORY;
  191. UA_ConnectionConfig config = UA_ConnectionConfig_default;
  192. if (sendBufferSize > 0)
  193. config.sendBufferSize = sendBufferSize;
  194. if (recvBufferSize > 0)
  195. config.recvBufferSize = recvBufferSize;
  196. conf->networkLayers[0] =
  197. UA_ServerNetworkLayerTCP(config, portNumber, &conf->logger);
  198. if (!conf->networkLayers[0].handle)
  199. return UA_STATUSCODE_BADOUTOFMEMORY;
  200. conf->networkLayersSize = 1;
  201. return UA_STATUSCODE_GOOD;
  202. }
  203. UA_EXPORT UA_StatusCode
  204. UA_ServerConfig_setMinimalCustomBuffer(UA_ServerConfig *config, UA_UInt16 portNumber,
  205. const UA_ByteString *certificate,
  206. UA_UInt32 sendBufferSize,
  207. UA_UInt32 recvBufferSize) {
  208. UA_StatusCode retval = setDefaultConfig(config);
  209. if(retval != UA_STATUSCODE_GOOD) {
  210. UA_ServerConfig_clean(config);
  211. return retval;
  212. }
  213. retval = addDefaultNetworkLayers(config, portNumber, sendBufferSize, recvBufferSize);
  214. if(retval != UA_STATUSCODE_GOOD) {
  215. UA_ServerConfig_clean(config);
  216. return retval;
  217. }
  218. /* Allocate the SecurityPolicies */
  219. config->securityPolicies = (UA_SecurityPolicy *)UA_malloc(sizeof(UA_SecurityPolicy));
  220. if(!config->securityPolicies) {
  221. UA_ServerConfig_clean(config);
  222. return retval;
  223. }
  224. config->securityPoliciesSize = 1;
  225. /* Populate the SecurityPolicies */
  226. UA_ByteString localCertificate = UA_BYTESTRING_NULL;
  227. if(certificate)
  228. localCertificate = *certificate;
  229. retval = UA_SecurityPolicy_None(&config->securityPolicies[0], NULL,
  230. localCertificate, &config->logger);
  231. if(retval != UA_STATUSCODE_GOOD) {
  232. UA_ServerConfig_clean(config);
  233. return retval;
  234. }
  235. /* Allocate the endpoint */
  236. config->endpoints = (UA_EndpointDescription *)
  237. UA_malloc(sizeof(UA_EndpointDescription));
  238. if(!config->endpoints) {
  239. UA_ServerConfig_clean(config);
  240. return retval;
  241. }
  242. config->endpointsSize = 1;
  243. /* Populate the endpoint */
  244. retval = createEndpoint(config, &config->endpoints[0],
  245. &config->securityPolicies[0],
  246. UA_MESSAGESECURITYMODE_NONE);
  247. if(retval != UA_STATUSCODE_GOOD) {
  248. UA_ServerConfig_clean(config);
  249. return retval;
  250. }
  251. return UA_STATUSCODE_GOOD;
  252. }
  253. #ifdef UA_ENABLE_ENCRYPTION
  254. UA_EXPORT UA_StatusCode
  255. UA_ServerConfig_setDefaultWithSecurityPolicies(UA_ServerConfig *conf,
  256. UA_UInt16 portNumber,
  257. const UA_ByteString *certificate,
  258. const UA_ByteString *privateKey,
  259. const UA_ByteString *trustList,
  260. size_t trustListSize,
  261. const UA_ByteString *revocationList,
  262. size_t revocationListSize) {
  263. UA_StatusCode retval = setDefaultConfig(conf);
  264. if(retval != UA_STATUSCODE_GOOD) {
  265. UA_ServerConfig_clean(conf);
  266. return retval;
  267. }
  268. retval = UA_CertificateVerification_Trustlist(&conf->certificateVerification,
  269. trustList, trustListSize,
  270. revocationList, revocationListSize);
  271. if(retval != UA_STATUSCODE_GOOD) {
  272. UA_ServerConfig_clean(conf);
  273. return retval;
  274. }
  275. retval = addDefaultNetworkLayers(conf, portNumber, 0, 0);
  276. if(retval != UA_STATUSCODE_GOOD) {
  277. UA_ServerConfig_clean(conf);
  278. return retval;
  279. }
  280. if(trustListSize == 0)
  281. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
  282. "No CA trust-list provided. "
  283. "Any remote certificate will be accepted.");
  284. /* Allocate the SecurityPolicies */
  285. conf->securityPoliciesSize = 0;
  286. conf->securityPolicies = (UA_SecurityPolicy *)
  287. UA_malloc(sizeof(UA_SecurityPolicy) * 4);
  288. if(!conf->securityPolicies) {
  289. UA_ServerConfig_clean(conf);
  290. return retval;
  291. }
  292. /* Populate the SecurityPolicies */
  293. UA_ByteString localCertificate = UA_BYTESTRING_NULL;
  294. UA_ByteString localPrivateKey = UA_BYTESTRING_NULL;
  295. if(certificate)
  296. localCertificate = *certificate;
  297. if(privateKey)
  298. localPrivateKey = *privateKey;
  299. retval = UA_SecurityPolicy_None(&conf->securityPolicies[0], NULL,
  300. localCertificate, &conf->logger);
  301. if(retval != UA_STATUSCODE_GOOD) {
  302. UA_ServerConfig_clean(conf);
  303. return retval;
  304. }
  305. ++conf->securityPoliciesSize;
  306. retval = UA_SecurityPolicy_Basic128Rsa15(&conf->securityPolicies[1],
  307. &conf->certificateVerification,
  308. localCertificate, localPrivateKey,
  309. &conf->logger);
  310. if(retval != UA_STATUSCODE_GOOD) {
  311. UA_ServerConfig_clean(conf);
  312. return retval;
  313. }
  314. ++conf->securityPoliciesSize;
  315. retval = UA_SecurityPolicy_Basic256(&conf->securityPolicies[2],
  316. &conf->certificateVerification,
  317. localCertificate, localPrivateKey,
  318. &conf->logger);
  319. if(retval != UA_STATUSCODE_GOOD) {
  320. UA_ServerConfig_clean(conf);
  321. return retval;
  322. }
  323. ++conf->securityPoliciesSize;
  324. retval = UA_SecurityPolicy_Basic256Sha256(&conf->securityPolicies[3],
  325. &conf->certificateVerification,
  326. localCertificate, localPrivateKey,
  327. &conf->logger);
  328. if(retval != UA_STATUSCODE_GOOD) {
  329. UA_ServerConfig_clean(conf);
  330. return retval;
  331. }
  332. ++conf->securityPoliciesSize;
  333. /* Allocate the endpoints */
  334. conf->endpointsSize = 0;
  335. conf->endpoints = (UA_EndpointDescription *)
  336. UA_malloc(sizeof(UA_EndpointDescription) * 7);
  337. if(!conf->endpoints) {
  338. UA_ServerConfig_clean(conf);
  339. return retval;
  340. }
  341. /* Populate the endpoints */
  342. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  343. &conf->securityPolicies[0], UA_MESSAGESECURITYMODE_NONE);
  344. if(retval != UA_STATUSCODE_GOOD) {
  345. UA_ServerConfig_clean(conf);
  346. return retval;
  347. }
  348. ++conf->endpointsSize;
  349. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  350. &conf->securityPolicies[1], UA_MESSAGESECURITYMODE_SIGN);
  351. if(retval != UA_STATUSCODE_GOOD) {
  352. UA_ServerConfig_clean(conf);
  353. return retval;
  354. }
  355. ++conf->endpointsSize;
  356. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  357. &conf->securityPolicies[1], UA_MESSAGESECURITYMODE_SIGNANDENCRYPT);
  358. if(retval != UA_STATUSCODE_GOOD) {
  359. UA_ServerConfig_clean(conf);
  360. return retval;
  361. }
  362. ++conf->endpointsSize;
  363. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  364. &conf->securityPolicies[2], UA_MESSAGESECURITYMODE_SIGN);
  365. if(retval != UA_STATUSCODE_GOOD) {
  366. UA_ServerConfig_clean(conf);
  367. return retval;
  368. }
  369. ++conf->endpointsSize;
  370. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  371. &conf->securityPolicies[2], UA_MESSAGESECURITYMODE_SIGNANDENCRYPT);
  372. if(retval != UA_STATUSCODE_GOOD) {
  373. UA_ServerConfig_clean(conf);
  374. return retval;
  375. }
  376. ++conf->endpointsSize;
  377. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  378. &conf->securityPolicies[3], UA_MESSAGESECURITYMODE_SIGN);
  379. if(retval != UA_STATUSCODE_GOOD) {
  380. UA_ServerConfig_clean(conf);
  381. return retval;
  382. }
  383. ++conf->endpointsSize;
  384. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  385. &conf->securityPolicies[3], UA_MESSAGESECURITYMODE_SIGNANDENCRYPT);
  386. if(retval != UA_STATUSCODE_GOOD) {
  387. UA_ServerConfig_clean(conf);
  388. return retval;
  389. }
  390. ++conf->endpointsSize;
  391. return UA_STATUSCODE_GOOD;
  392. }
  393. #endif
  394. /***************************/
  395. /* Default Client Settings */
  396. /***************************/
  397. static UA_INLINE void
  398. UA_ClientConnectionTCP_poll_callback(UA_Client *client, void *data) {
  399. UA_ClientConnectionTCP_poll(client, data);
  400. }
  401. UA_StatusCode
  402. UA_ClientConfig_setDefault(UA_ClientConfig *config) {
  403. config->timeout = 5000;
  404. config->secureChannelLifeTime = 10 * 60 * 1000; /* 10 minutes */
  405. config->logger.log = UA_Log_Stdout_log;
  406. config->logger.context = NULL;
  407. config->logger.clear = UA_Log_Stdout_clear;
  408. config->localConnectionConfig = UA_ConnectionConfig_default;
  409. /* Certificate Verification that accepts every certificate. Can be
  410. * overwritten when the policy is specialized. */
  411. UA_CertificateVerification_AcceptAll(&config->certificateVerification);
  412. /* With encryption enabled, the applicationUri needs to match the URI from
  413. * the certificate */
  414. config->clientDescription.applicationUri = UA_STRING_ALLOC(APPLICATION_URI);
  415. config->clientDescription.applicationType = UA_APPLICATIONTYPE_CLIENT;
  416. if(config->securityPoliciesSize > 0) {
  417. UA_LOG_ERROR(&config->logger, UA_LOGCATEGORY_NETWORK,
  418. "Could not initialize a config that already has SecurityPolicies");
  419. return UA_STATUSCODE_BADINTERNALERROR;
  420. }
  421. config->securityPolicies = (UA_SecurityPolicy*)UA_malloc(sizeof(UA_SecurityPolicy));
  422. if(!config->securityPolicies)
  423. return UA_STATUSCODE_BADOUTOFMEMORY;
  424. UA_StatusCode retval = UA_SecurityPolicy_None(config->securityPolicies, NULL,
  425. UA_BYTESTRING_NULL, &config->logger);
  426. if(retval != UA_STATUSCODE_GOOD) {
  427. UA_free(config->securityPolicies);
  428. config->securityPolicies = NULL;
  429. return retval;
  430. }
  431. config->securityPoliciesSize = 1;
  432. config->connectionFunc = UA_ClientConnectionTCP;
  433. config->initConnectionFunc = UA_ClientConnectionTCP_init; /* for async client */
  434. config->pollConnectionFunc = UA_ClientConnectionTCP_poll_callback; /* for async connection */
  435. config->customDataTypes = NULL;
  436. config->stateCallback = NULL;
  437. config->connectivityCheckInterval = 0;
  438. config->requestedSessionTimeout = 1200000; /* requestedSessionTimeout */
  439. config->inactivityCallback = NULL;
  440. config->clientContext = NULL;
  441. #ifdef UA_ENABLE_SUBSCRIPTIONS
  442. config->outStandingPublishRequests = 10;
  443. config->subscriptionInactivityCallback = NULL;
  444. #endif
  445. return UA_STATUSCODE_GOOD;
  446. }
  447. #ifdef UA_ENABLE_ENCRYPTION
  448. UA_StatusCode
  449. UA_ClientConfig_setDefaultEncryption(UA_ClientConfig *config,
  450. UA_ByteString localCertificate, UA_ByteString privateKey,
  451. const UA_ByteString *trustList, size_t trustListSize,
  452. const UA_ByteString *revocationList, size_t revocationListSize) {
  453. UA_StatusCode retval = UA_ClientConfig_setDefault(config);
  454. if(retval != UA_STATUSCODE_GOOD)
  455. return retval;
  456. retval = UA_CertificateVerification_Trustlist(&config->certificateVerification,
  457. trustList, trustListSize,
  458. revocationList, revocationListSize);
  459. if(retval != UA_STATUSCODE_GOOD)
  460. return retval;
  461. /* Populate SecurityPolicies */
  462. UA_SecurityPolicy *sp = (UA_SecurityPolicy*)
  463. UA_realloc(config->securityPolicies, sizeof(UA_SecurityPolicy) * 4);
  464. if(!sp)
  465. return UA_STATUSCODE_BADOUTOFMEMORY;
  466. config->securityPolicies = sp;
  467. retval = UA_SecurityPolicy_Basic128Rsa15(&config->securityPolicies[1],
  468. &config->certificateVerification,
  469. localCertificate, privateKey, &config->logger);
  470. if(retval != UA_STATUSCODE_GOOD)
  471. return retval;
  472. ++config->securityPoliciesSize;
  473. retval = UA_SecurityPolicy_Basic256(&config->securityPolicies[2],
  474. &config->certificateVerification,
  475. localCertificate, privateKey, &config->logger);
  476. if(retval != UA_STATUSCODE_GOOD)
  477. return retval;
  478. ++config->securityPoliciesSize;
  479. retval = UA_SecurityPolicy_Basic256Sha256(&config->securityPolicies[3],
  480. &config->certificateVerification,
  481. localCertificate, privateKey, &config->logger);
  482. if(retval != UA_STATUSCODE_GOOD)
  483. return retval;
  484. ++config->securityPoliciesSize;
  485. return UA_STATUSCODE_GOOD;
  486. }
  487. #endif