ua_config_default.c 21 KB

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