ua_config_default.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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
  116. /* conf->mdnsServerName = UA_STRING_NULL; */
  117. /* conf->serverCapabilitiesSize = 0; */
  118. /* conf->serverCapabilities = NULL; */
  119. #endif
  120. /* Custom DataTypes */
  121. /* conf->customDataTypesSize = 0; */
  122. /* conf->customDataTypes = NULL; */
  123. /* Networking */
  124. /* conf->networkLayersSize = 0; */
  125. /* conf->networkLayers = NULL; */
  126. /* conf->customHostname = UA_STRING_NULL; */
  127. /* Endpoints */
  128. /* conf->endpoints = {0, NULL}; */
  129. /* Certificate Verification that accepts every certificate. Can be
  130. * overwritten when the policy is specialized. */
  131. UA_CertificateVerification_AcceptAll(&conf->certificateVerification);
  132. /* Global Node Lifecycle */
  133. conf->nodeLifecycle.constructor = NULL;
  134. conf->nodeLifecycle.destructor = NULL;
  135. UA_StatusCode retval = UA_AccessControl_default(&conf->accessControl, true,
  136. usernamePasswordsSize,
  137. usernamePasswords);
  138. if(retval != UA_STATUSCODE_GOOD) {
  139. UA_ServerConfig_clean(conf);
  140. return retval;
  141. }
  142. /* Relax constraints for the InformationModel */
  143. conf->relaxEmptyValueConstraint = true; /* Allow empty values */
  144. /* Limits for SecureChannels */
  145. conf->maxSecureChannels = 40;
  146. conf->maxSecurityTokenLifetime = 10 * 60 * 1000; /* 10 minutes */
  147. /* Limits for Sessions */
  148. conf->maxSessions = 100;
  149. conf->maxSessionTimeout = 60.0 * 60.0 * 1000.0; /* 1h */
  150. /* Limits for Subscriptions */
  151. conf->publishingIntervalLimits = UA_DURATIONRANGE(100.0, 3600.0 * 1000.0);
  152. conf->lifeTimeCountLimits = UA_UINT32RANGE(3, 15000);
  153. conf->keepAliveCountLimits = UA_UINT32RANGE(1, 100);
  154. conf->maxNotificationsPerPublish = 1000;
  155. conf->enableRetransmissionQueue = true;
  156. conf->maxRetransmissionQueueSize = 0; /* unlimited */
  157. #ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS
  158. conf->maxEventsPerNode = 0; /* unlimited */
  159. #endif
  160. /* Limits for MonitoredItems */
  161. conf->samplingIntervalLimits = UA_DURATIONRANGE(50.0, 24.0 * 3600.0 * 1000.0);
  162. conf->queueSizeLimits = UA_UINT32RANGE(1, 100);
  163. #ifdef UA_ENABLE_DISCOVERY
  164. conf->discoveryCleanupTimeout = 60 * 60;
  165. #endif
  166. #ifdef UA_ENABLE_HISTORIZING
  167. /* conf->accessHistoryDataCapability = UA_FALSE; */
  168. /* conf->maxReturnDataValues = 0; */
  169. /* conf->accessHistoryEventsCapability = UA_FALSE; */
  170. /* conf->maxReturnEventValues = 0; */
  171. /* conf->insertDataCapability = UA_FALSE; */
  172. /* conf->insertEventCapability = UA_FALSE; */
  173. /* conf->insertAnnotationsCapability = UA_FALSE; */
  174. /* conf->replaceDataCapability = UA_FALSE; */
  175. /* conf->replaceEventCapability = UA_FALSE; */
  176. /* conf->updateDataCapability = UA_FALSE; */
  177. /* conf->updateEventCapability = UA_FALSE; */
  178. /* conf->deleteRawCapability = UA_FALSE; */
  179. /* conf->deleteEventCapability = UA_FALSE; */
  180. /* conf->deleteAtTimeDataCapability = UA_FALSE; */
  181. #endif
  182. /* --> Finish setting the default static config <-- */
  183. return UA_STATUSCODE_GOOD;
  184. }
  185. static UA_StatusCode
  186. addDefaultNetworkLayers(UA_ServerConfig *conf, UA_UInt16 portNumber,
  187. UA_UInt32 sendBufferSize, UA_UInt32 recvBufferSize) {
  188. /* Add a network layer */
  189. conf->networkLayers = (UA_ServerNetworkLayer *)
  190. UA_malloc(sizeof(UA_ServerNetworkLayer));
  191. if(!conf->networkLayers)
  192. return UA_STATUSCODE_BADOUTOFMEMORY;
  193. UA_ConnectionConfig config = UA_ConnectionConfig_default;
  194. if (sendBufferSize > 0)
  195. config.sendBufferSize = sendBufferSize;
  196. if (recvBufferSize > 0)
  197. config.recvBufferSize = recvBufferSize;
  198. conf->networkLayers[0] =
  199. UA_ServerNetworkLayerTCP(config, portNumber, &conf->logger);
  200. if (!conf->networkLayers[0].handle)
  201. return UA_STATUSCODE_BADOUTOFMEMORY;
  202. conf->networkLayersSize = 1;
  203. return UA_STATUSCODE_GOOD;
  204. }
  205. UA_EXPORT UA_StatusCode
  206. UA_ServerConfig_setMinimalCustomBuffer(UA_ServerConfig *config, UA_UInt16 portNumber,
  207. const UA_ByteString *certificate,
  208. UA_UInt32 sendBufferSize,
  209. UA_UInt32 recvBufferSize) {
  210. UA_StatusCode retval = setDefaultConfig(config);
  211. if(retval != UA_STATUSCODE_GOOD) {
  212. UA_ServerConfig_clean(config);
  213. return retval;
  214. }
  215. retval = addDefaultNetworkLayers(config, portNumber, sendBufferSize, recvBufferSize);
  216. if(retval != UA_STATUSCODE_GOOD) {
  217. UA_ServerConfig_clean(config);
  218. return retval;
  219. }
  220. /* Allocate the SecurityPolicies */
  221. config->securityPolicies = (UA_SecurityPolicy *)UA_malloc(sizeof(UA_SecurityPolicy));
  222. if(!config->securityPolicies) {
  223. UA_ServerConfig_clean(config);
  224. return retval;
  225. }
  226. config->securityPoliciesSize = 1;
  227. /* Populate the SecurityPolicies */
  228. UA_ByteString localCertificate = UA_BYTESTRING_NULL;
  229. if(certificate)
  230. localCertificate = *certificate;
  231. retval = UA_SecurityPolicy_None(&config->securityPolicies[0], NULL,
  232. localCertificate, &config->logger);
  233. if(retval != UA_STATUSCODE_GOOD) {
  234. UA_ServerConfig_clean(config);
  235. return retval;
  236. }
  237. /* Allocate the endpoint */
  238. config->endpoints = (UA_EndpointDescription *)
  239. UA_malloc(sizeof(UA_EndpointDescription));
  240. if(!config->endpoints) {
  241. UA_ServerConfig_clean(config);
  242. return retval;
  243. }
  244. config->endpointsSize = 1;
  245. /* Populate the endpoint */
  246. retval = createEndpoint(config, &config->endpoints[0],
  247. &config->securityPolicies[0],
  248. UA_MESSAGESECURITYMODE_NONE);
  249. if(retval != UA_STATUSCODE_GOOD) {
  250. UA_ServerConfig_clean(config);
  251. return retval;
  252. }
  253. return UA_STATUSCODE_GOOD;
  254. }
  255. #ifdef UA_ENABLE_ENCRYPTION
  256. UA_EXPORT UA_StatusCode
  257. UA_ServerConfig_setDefaultWithSecurityPolicies(UA_ServerConfig *conf,
  258. UA_UInt16 portNumber,
  259. const UA_ByteString *certificate,
  260. const UA_ByteString *privateKey,
  261. const UA_ByteString *trustList,
  262. size_t trustListSize,
  263. const UA_ByteString *revocationList,
  264. size_t revocationListSize) {
  265. UA_StatusCode retval = setDefaultConfig(conf);
  266. if(retval != UA_STATUSCODE_GOOD) {
  267. UA_ServerConfig_clean(conf);
  268. return retval;
  269. }
  270. retval = UA_CertificateVerification_Trustlist(&conf->certificateVerification,
  271. trustList, trustListSize,
  272. revocationList, revocationListSize);
  273. if(retval != UA_STATUSCODE_GOOD) {
  274. UA_ServerConfig_clean(conf);
  275. return retval;
  276. }
  277. retval = addDefaultNetworkLayers(conf, portNumber, 0, 0);
  278. if(retval != UA_STATUSCODE_GOOD) {
  279. UA_ServerConfig_clean(conf);
  280. return retval;
  281. }
  282. if(trustListSize == 0)
  283. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
  284. "No CA trust-list provided. "
  285. "Any remote certificate will be accepted.");
  286. /* Allocate the SecurityPolicies */
  287. conf->securityPoliciesSize = 0;
  288. conf->securityPolicies = (UA_SecurityPolicy *)
  289. UA_malloc(sizeof(UA_SecurityPolicy) * 4);
  290. if(!conf->securityPolicies) {
  291. UA_ServerConfig_clean(conf);
  292. return retval;
  293. }
  294. /* Populate the SecurityPolicies */
  295. UA_ByteString localCertificate = UA_BYTESTRING_NULL;
  296. UA_ByteString localPrivateKey = UA_BYTESTRING_NULL;
  297. if(certificate)
  298. localCertificate = *certificate;
  299. if(privateKey)
  300. localPrivateKey = *privateKey;
  301. retval = UA_SecurityPolicy_None(&conf->securityPolicies[0], NULL,
  302. localCertificate, &conf->logger);
  303. if(retval != UA_STATUSCODE_GOOD) {
  304. UA_ServerConfig_clean(conf);
  305. return retval;
  306. }
  307. ++conf->securityPoliciesSize;
  308. retval = UA_SecurityPolicy_Basic128Rsa15(&conf->securityPolicies[1],
  309. &conf->certificateVerification,
  310. localCertificate, localPrivateKey,
  311. &conf->logger);
  312. if(retval != UA_STATUSCODE_GOOD) {
  313. UA_ServerConfig_clean(conf);
  314. return retval;
  315. }
  316. ++conf->securityPoliciesSize;
  317. retval = UA_SecurityPolicy_Basic256(&conf->securityPolicies[2],
  318. &conf->certificateVerification,
  319. localCertificate, localPrivateKey,
  320. &conf->logger);
  321. if(retval != UA_STATUSCODE_GOOD) {
  322. UA_ServerConfig_clean(conf);
  323. return retval;
  324. }
  325. ++conf->securityPoliciesSize;
  326. retval = UA_SecurityPolicy_Basic256Sha256(&conf->securityPolicies[3],
  327. &conf->certificateVerification,
  328. localCertificate, localPrivateKey,
  329. &conf->logger);
  330. if(retval != UA_STATUSCODE_GOOD) {
  331. UA_ServerConfig_clean(conf);
  332. return retval;
  333. }
  334. ++conf->securityPoliciesSize;
  335. /* Allocate the endpoints */
  336. conf->endpointsSize = 0;
  337. conf->endpoints = (UA_EndpointDescription *)
  338. UA_malloc(sizeof(UA_EndpointDescription) * 7);
  339. if(!conf->endpoints) {
  340. UA_ServerConfig_clean(conf);
  341. return retval;
  342. }
  343. /* Populate the endpoints */
  344. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  345. &conf->securityPolicies[0], UA_MESSAGESECURITYMODE_NONE);
  346. if(retval != UA_STATUSCODE_GOOD) {
  347. UA_ServerConfig_clean(conf);
  348. return retval;
  349. }
  350. ++conf->endpointsSize;
  351. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  352. &conf->securityPolicies[1], UA_MESSAGESECURITYMODE_SIGN);
  353. if(retval != UA_STATUSCODE_GOOD) {
  354. UA_ServerConfig_clean(conf);
  355. return retval;
  356. }
  357. ++conf->endpointsSize;
  358. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  359. &conf->securityPolicies[1], UA_MESSAGESECURITYMODE_SIGNANDENCRYPT);
  360. if(retval != UA_STATUSCODE_GOOD) {
  361. UA_ServerConfig_clean(conf);
  362. return retval;
  363. }
  364. ++conf->endpointsSize;
  365. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  366. &conf->securityPolicies[2], UA_MESSAGESECURITYMODE_SIGN);
  367. if(retval != UA_STATUSCODE_GOOD) {
  368. UA_ServerConfig_clean(conf);
  369. return retval;
  370. }
  371. ++conf->endpointsSize;
  372. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  373. &conf->securityPolicies[2], UA_MESSAGESECURITYMODE_SIGNANDENCRYPT);
  374. if(retval != UA_STATUSCODE_GOOD) {
  375. UA_ServerConfig_clean(conf);
  376. return retval;
  377. }
  378. ++conf->endpointsSize;
  379. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  380. &conf->securityPolicies[3], UA_MESSAGESECURITYMODE_SIGN);
  381. if(retval != UA_STATUSCODE_GOOD) {
  382. UA_ServerConfig_clean(conf);
  383. return retval;
  384. }
  385. ++conf->endpointsSize;
  386. retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
  387. &conf->securityPolicies[3], UA_MESSAGESECURITYMODE_SIGNANDENCRYPT);
  388. if(retval != UA_STATUSCODE_GOOD) {
  389. UA_ServerConfig_clean(conf);
  390. return retval;
  391. }
  392. ++conf->endpointsSize;
  393. return UA_STATUSCODE_GOOD;
  394. }
  395. #endif
  396. /***************************/
  397. /* Default Client Settings */
  398. /***************************/
  399. static UA_INLINE void
  400. UA_ClientConnectionTCP_poll_callback(UA_Client *client, void *data) {
  401. UA_ClientConnectionTCP_poll(client, data);
  402. }
  403. UA_StatusCode
  404. UA_ClientConfig_setDefault(UA_ClientConfig *config) {
  405. config->timeout = 5000;
  406. config->secureChannelLifeTime = 10 * 60 * 1000; /* 10 minutes */
  407. config->logger.log = UA_Log_Stdout_log;
  408. config->logger.context = NULL;
  409. config->logger.clear = UA_Log_Stdout_clear;
  410. config->localConnectionConfig = UA_ConnectionConfig_default;
  411. /* Certificate Verification that accepts every certificate. Can be
  412. * overwritten when the policy is specialized. */
  413. UA_CertificateVerification_AcceptAll(&config->certificateVerification);
  414. /* With encryption enabled, the applicationUri needs to match the URI from
  415. * the certificate */
  416. config->clientDescription.applicationUri = UA_STRING_ALLOC(APPLICATION_URI);
  417. config->clientDescription.applicationType = UA_APPLICATIONTYPE_CLIENT;
  418. if(config->securityPoliciesSize > 0) {
  419. UA_LOG_ERROR(&config->logger, UA_LOGCATEGORY_NETWORK,
  420. "Could not initialize a config that already has SecurityPolicies");
  421. return UA_STATUSCODE_BADINTERNALERROR;
  422. }
  423. config->securityPolicies = (UA_SecurityPolicy*)UA_malloc(sizeof(UA_SecurityPolicy));
  424. if(!config->securityPolicies)
  425. return UA_STATUSCODE_BADOUTOFMEMORY;
  426. UA_StatusCode retval = UA_SecurityPolicy_None(config->securityPolicies, NULL,
  427. UA_BYTESTRING_NULL, &config->logger);
  428. if(retval != UA_STATUSCODE_GOOD) {
  429. UA_free(config->securityPolicies);
  430. config->securityPolicies = NULL;
  431. return retval;
  432. }
  433. config->securityPoliciesSize = 1;
  434. config->connectionFunc = UA_ClientConnectionTCP;
  435. config->initConnectionFunc = UA_ClientConnectionTCP_init; /* for async client */
  436. config->pollConnectionFunc = UA_ClientConnectionTCP_poll_callback; /* for async connection */
  437. config->customDataTypes = NULL;
  438. config->stateCallback = NULL;
  439. config->connectivityCheckInterval = 0;
  440. config->requestedSessionTimeout = 1200000; /* requestedSessionTimeout */
  441. config->inactivityCallback = NULL;
  442. config->clientContext = NULL;
  443. #ifdef UA_ENABLE_SUBSCRIPTIONS
  444. config->outStandingPublishRequests = 10;
  445. config->subscriptionInactivityCallback = NULL;
  446. #endif
  447. return UA_STATUSCODE_GOOD;
  448. }
  449. #ifdef UA_ENABLE_ENCRYPTION
  450. UA_StatusCode
  451. UA_ClientConfig_setDefaultEncryption(UA_ClientConfig *config,
  452. UA_ByteString localCertificate, UA_ByteString privateKey,
  453. const UA_ByteString *trustList, size_t trustListSize,
  454. const UA_ByteString *revocationList, size_t revocationListSize) {
  455. UA_StatusCode retval = UA_ClientConfig_setDefault(config);
  456. if(retval != UA_STATUSCODE_GOOD)
  457. return retval;
  458. retval = UA_CertificateVerification_Trustlist(&config->certificateVerification,
  459. trustList, trustListSize,
  460. revocationList, revocationListSize);
  461. if(retval != UA_STATUSCODE_GOOD)
  462. return retval;
  463. /* Populate SecurityPolicies */
  464. UA_SecurityPolicy *sp = (UA_SecurityPolicy*)
  465. UA_realloc(config->securityPolicies, sizeof(UA_SecurityPolicy) * 4);
  466. if(!sp)
  467. return UA_STATUSCODE_BADOUTOFMEMORY;
  468. config->securityPolicies = sp;
  469. retval = UA_SecurityPolicy_Basic128Rsa15(&config->securityPolicies[1],
  470. &config->certificateVerification,
  471. localCertificate, privateKey, &config->logger);
  472. if(retval != UA_STATUSCODE_GOOD)
  473. return retval;
  474. ++config->securityPoliciesSize;
  475. retval = UA_SecurityPolicy_Basic256(&config->securityPolicies[2],
  476. &config->certificateVerification,
  477. localCertificate, privateKey, &config->logger);
  478. if(retval != UA_STATUSCODE_GOOD)
  479. return retval;
  480. ++config->securityPoliciesSize;
  481. retval = UA_SecurityPolicy_Basic256Sha256(&config->securityPolicies[3],
  482. &config->certificateVerification,
  483. localCertificate, privateKey, &config->logger);
  484. if(retval != UA_STATUSCODE_GOOD)
  485. return retval;
  486. ++config->securityPoliciesSize;
  487. return UA_STATUSCODE_GOOD;
  488. }
  489. #endif