server_config_default.h 8.3 KB

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