server_config_default.h 8.1 KB

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