server_config_default.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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) Stefan Profanter, fortiss GmbH
  6. * Copyright 2018 (c) Mark Giraud, Fraunhofer IOSB
  7. * Copyright 2019 (c) Kalycito Infotech Private Limited
  8. */
  9. #ifndef UA_SERVER_CONFIG_DEFAULT_H_
  10. #define UA_SERVER_CONFIG_DEFAULT_H_
  11. #include <open62541/server_config.h>
  12. _UA_BEGIN_DECLS
  13. /* Create a new server with default plugins for logging etc. used during
  14. * initialization. No network layer and SecurityPolicies are set so far. */
  15. UA_Server UA_EXPORT * UA_Server_new(void);
  16. /**********************/
  17. /* Default Connection */
  18. /**********************/
  19. extern const UA_EXPORT
  20. UA_ConnectionConfig UA_ConnectionConfig_default;
  21. /*************************/
  22. /* Default Server Config */
  23. /*************************/
  24. /* Creates a new server config with one endpoint and custom buffer size.
  25. *
  26. * The config will set the tcp network layer to the given port and adds a single
  27. * endpoint with the security policy ``SecurityPolicy#None`` to the server. A
  28. * server certificate may be supplied but is optional.
  29. * Additionally you can define a custom buffer size for send and receive buffer.
  30. *
  31. * @param portNumber The port number for the tcp network layer
  32. * @param certificate Optional certificate for the server endpoint. Can be
  33. * ``NULL``.
  34. * @param sendBufferSize The size in bytes for the network send buffer
  35. * @param recvBufferSize The size in bytes for the network receive buffer
  36. *
  37. */
  38. UA_EXPORT UA_StatusCode
  39. UA_ServerConfig_setMinimalCustomBuffer(UA_ServerConfig *config,
  40. UA_UInt16 portNumber,
  41. const UA_ByteString *certificate,
  42. UA_UInt32 sendBufferSize,
  43. UA_UInt32 recvBufferSize);
  44. /* Creates a new server config with one endpoint.
  45. *
  46. * The config will set the tcp network layer to the given port and adds a single
  47. * endpoint with the security policy ``SecurityPolicy#None`` to the server. A
  48. * server certificate may be supplied but is optional. */
  49. static UA_INLINE UA_StatusCode
  50. UA_ServerConfig_setMinimal(UA_ServerConfig *config, UA_UInt16 portNumber,
  51. const UA_ByteString *certificate) {
  52. return UA_ServerConfig_setMinimalCustomBuffer(config, portNumber,
  53. certificate, 0, 0);
  54. }
  55. #ifdef UA_ENABLE_ENCRYPTION
  56. UA_EXPORT UA_StatusCode
  57. UA_ServerConfig_setDefaultWithSecurityPolicies(UA_ServerConfig *conf,
  58. UA_UInt16 portNumber,
  59. const UA_ByteString *certificate,
  60. const UA_ByteString *privateKey,
  61. const UA_ByteString *trustList,
  62. size_t trustListSize,
  63. const UA_ByteString *issuerList,
  64. size_t issuerListSize,
  65. const UA_ByteString *revocationList,
  66. size_t revocationListSize);
  67. #endif
  68. /* Creates a server config on the default port 4840 with no server
  69. * certificate. */
  70. static UA_INLINE UA_StatusCode
  71. UA_ServerConfig_setDefault(UA_ServerConfig *config) {
  72. return UA_ServerConfig_setMinimal(config, 4840, NULL);
  73. }
  74. /* Creates a new server config with no network layer and no endpoints.
  75. *
  76. * It initializes reasonable defaults for many things, but does not
  77. * add any network layer, security policies and endpoints.
  78. * Use the various UA_ServerConfig_addXxx functions to add them.
  79. *
  80. * @param conf The configuration to manipulate
  81. */
  82. UA_EXPORT UA_StatusCode
  83. UA_ServerConfig_setBasics(UA_ServerConfig *conf);
  84. /* Adds a TCP network layer with custom buffer sizes
  85. *
  86. * @param conf The configuration to manipulate
  87. * @param portNumber The port number for the tcp network layer
  88. * @param sendBufferSize The size in bytes for the network send buffer. Pass 0
  89. * to use defaults.
  90. * @param recvBufferSize The size in bytes for the network receive buffer.
  91. * Pass 0 to use defaults.
  92. */
  93. UA_EXPORT UA_StatusCode
  94. UA_ServerConfig_addNetworkLayerTCP(UA_ServerConfig *conf, UA_UInt16 portNumber,
  95. UA_UInt32 sendBufferSize, UA_UInt32 recvBufferSize);
  96. #ifdef UA_ENABLE_WEBSOCKET_SERVER
  97. /* Adds a Websocket network layer with custom buffer sizes
  98. *
  99. * @param conf The configuration to manipulate
  100. * @param portNumber The port number for the tcp network layer
  101. * @param sendBufferSize The size in bytes for the network send buffer. Pass 0
  102. * to use defaults.
  103. * @param recvBufferSize The size in bytes for the network receive buffer.
  104. * Pass 0 to use defaults.
  105. */
  106. UA_EXPORT UA_StatusCode
  107. UA_ServerConfig_addNetworkLayerWS(UA_ServerConfig *conf, UA_UInt16 portNumber,
  108. UA_UInt32 sendBufferSize, UA_UInt32 recvBufferSize);
  109. #endif
  110. /* Adds the security policy ``SecurityPolicy#None`` to the server. A
  111. * server certificate may be supplied but is optional.
  112. *
  113. * @param config The configuration to manipulate
  114. * @param certificate The optional server certificate.
  115. */
  116. UA_EXPORT UA_StatusCode
  117. UA_ServerConfig_addSecurityPolicyNone(UA_ServerConfig *config,
  118. const UA_ByteString *certificate);
  119. #ifdef UA_ENABLE_ENCRYPTION
  120. /* Adds the security policy ``SecurityPolicy#Basic128Rsa15`` to the server. A
  121. * server certificate may be supplied but is optional.
  122. *
  123. * Certificate verification should be configured before calling this
  124. * function. See PKI plugin.
  125. *
  126. * @param config The configuration to manipulate
  127. * @param certificate The server certificate.
  128. * @param privateKey The private key that corresponds to the certificate.
  129. */
  130. UA_EXPORT UA_StatusCode
  131. UA_ServerConfig_addSecurityPolicyBasic128Rsa15(UA_ServerConfig *config,
  132. const UA_ByteString *certificate,
  133. const UA_ByteString *privateKey);
  134. /* Adds the security policy ``SecurityPolicy#Basic256`` to the server. A
  135. * server certificate may be supplied but is optional.
  136. *
  137. * Certificate verification should be configured before calling this
  138. * function. See PKI plugin.
  139. *
  140. * @param config The configuration to manipulate
  141. * @param certificate The server certificate.
  142. * @param privateKey The private key that corresponds to the certificate.
  143. */
  144. UA_EXPORT UA_StatusCode
  145. UA_ServerConfig_addSecurityPolicyBasic256(UA_ServerConfig *config,
  146. const UA_ByteString *certificate,
  147. const UA_ByteString *privateKey);
  148. /* Adds the security policy ``SecurityPolicy#Basic256Sha256`` to the server. A
  149. * server certificate may be supplied but is optional.
  150. *
  151. * Certificate verification should be configured before calling this
  152. * function. See PKI plugin.
  153. *
  154. * @param config The configuration to manipulate
  155. * @param certificate The server certificate.
  156. * @param privateKey The private key that corresponds to the certificate.
  157. */
  158. UA_EXPORT UA_StatusCode
  159. UA_ServerConfig_addSecurityPolicyBasic256Sha256(UA_ServerConfig *config,
  160. const UA_ByteString *certificate,
  161. const UA_ByteString *privateKey);
  162. /* Adds all supported security policies and sets up certificate
  163. * validation procedures.
  164. *
  165. * Certificate verification should be configured before calling this
  166. * function. See PKI plugin.
  167. *
  168. * @param config The configuration to manipulate
  169. * @param certificate The server certificate.
  170. * @param privateKey The private key that corresponds to the certificate.
  171. * @param trustList The trustList for client certificate validation.
  172. * @param trustListSize The trustList size.
  173. * @param revocationList The revocationList for client certificate validation.
  174. * @param revocationListSize The revocationList size.
  175. */
  176. UA_EXPORT UA_StatusCode
  177. UA_ServerConfig_addAllSecurityPolicies(UA_ServerConfig *config,
  178. const UA_ByteString *certificate,
  179. const UA_ByteString *privateKey);
  180. #endif
  181. /* Adds an endpoint for the given security policy and mode. The security
  182. * policy has to be added already. See UA_ServerConfig_addXxx functions.
  183. *
  184. * @param config The configuration to manipulate
  185. * @param securityPolicyUri The security policy for which to add the endpoint.
  186. * @param securityMode The security mode for which to add the endpoint.
  187. */
  188. UA_EXPORT UA_StatusCode
  189. UA_ServerConfig_addEndpoint(UA_ServerConfig *config, const UA_String securityPolicyUri,
  190. UA_MessageSecurityMode securityMode);
  191. /* Adds endpoints for all configured security policies in each mode.
  192. *
  193. * @param config The configuration to manipulate
  194. */
  195. UA_EXPORT UA_StatusCode
  196. UA_ServerConfig_addAllEndpoints(UA_ServerConfig *config);
  197. _UA_END_DECLS
  198. #endif /* UA_SERVER_CONFIG_DEFAULT_H_ */