2
0

apr_ldap_option.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
  2. * applicable.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @file apr_ldap_option.h
  18. * @brief APR-UTIL LDAP ldap_*_option() functions
  19. */
  20. #ifndef APR_LDAP_OPTION_H
  21. #define APR_LDAP_OPTION_H
  22. /**
  23. * @defgroup APR_Util_LDAP LDAP
  24. * @ingroup APR_Util
  25. * @{
  26. */
  27. #include "apr_ldap.h"
  28. #if APR_HAS_LDAP
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif /* __cplusplus */
  32. /*
  33. * The following defines handle the different TLS certificate
  34. * options available. If these options are missing, APR will try and
  35. * emulate support for this using the deprecated ldap_start_tls_s()
  36. * function.
  37. */
  38. /**
  39. * Set SSL mode to one of APR_LDAP_NONE, APR_LDAP_SSL, APR_LDAP_STARTTLS
  40. * or APR_LDAP_STOPTLS.
  41. */
  42. #define APR_LDAP_OPT_TLS 0x6fff
  43. /**
  44. * Set zero or more CA certificates, client certificates or private
  45. * keys globally, or per connection (where supported).
  46. */
  47. #define APR_LDAP_OPT_TLS_CERT 0x6ffe
  48. /**
  49. * Set the LDAP library to no verify the server certificate. This means
  50. * all servers are considered trusted.
  51. */
  52. #define APR_LDAP_OPT_VERIFY_CERT 0x6ffd
  53. /**
  54. * Structures for the apr_set_option() cases
  55. */
  56. /**
  57. * APR_LDAP_OPT_TLS_CERT
  58. *
  59. * This structure includes possible options to set certificates on
  60. * system initialisation. Different SDKs have different certificate
  61. * requirements, and to achieve this multiple certificates must be
  62. * specified at once passed as an (apr_array_header_t *).
  63. *
  64. * Netscape:
  65. * Needs the CA cert database (cert7.db), the client cert database (key3.db)
  66. * and the security module file (secmod.db) set at the system initialisation
  67. * time. Three types are supported: APR_LDAP_CERT7_DB, APR_LDAP_KEY3_DB and
  68. * APR_LDAP_SECMOD.
  69. *
  70. * To specify a client cert connection, a certificate nickname needs to be
  71. * provided with a type of APR_LDAP_CERT.
  72. * int ldapssl_enable_clientauth( LDAP *ld, char *keynickname,
  73. * char *keypasswd, char *certnickname );
  74. * keynickname is currently not used, and should be set to ""
  75. *
  76. * Novell:
  77. * Needs CA certificates and client certificates set at system initialisation
  78. * time. Three types are supported: APR_LDAP_CA*, APR_LDAP_CERT* and
  79. * APR_LDAP_KEY*.
  80. *
  81. * Certificates cannot be specified per connection.
  82. *
  83. * The functions used are:
  84. * ldapssl_add_trusted_cert(serverTrustedRoot, serverTrustedRootEncoding);
  85. * Clients certs and keys are set at system initialisation time with
  86. * int ldapssl_set_client_cert (
  87. * void *cert,
  88. * int type
  89. * void *password);
  90. * type can be LDAPSSL_CERT_FILETYPE_B64 or LDAPSSL_CERT_FILETYPE_DER
  91. * ldapssl_set_client_private_key(clientPrivateKey,
  92. * clientPrivateKeyEncoding,
  93. * clientPrivateKeyPassword);
  94. *
  95. * OpenSSL:
  96. * Needs one or more CA certificates to be set at system initialisation time
  97. * with a type of APR_LDAP_CA*.
  98. *
  99. * May have one or more client certificates set per connection with a type of
  100. * APR_LDAP_CERT*, and keys with APR_LDAP_KEY*.
  101. */
  102. /** CA certificate type unknown */
  103. #define APR_LDAP_CA_TYPE_UNKNOWN 0
  104. /** binary DER encoded CA certificate */
  105. #define APR_LDAP_CA_TYPE_DER 1
  106. /** PEM encoded CA certificate */
  107. #define APR_LDAP_CA_TYPE_BASE64 2
  108. /** Netscape/Mozilla cert7.db CA certificate database */
  109. #define APR_LDAP_CA_TYPE_CERT7_DB 3
  110. /** Netscape/Mozilla secmod file */
  111. #define APR_LDAP_CA_TYPE_SECMOD 4
  112. /** Client certificate type unknown */
  113. #define APR_LDAP_CERT_TYPE_UNKNOWN 5
  114. /** binary DER encoded client certificate */
  115. #define APR_LDAP_CERT_TYPE_DER 6
  116. /** PEM encoded client certificate */
  117. #define APR_LDAP_CERT_TYPE_BASE64 7
  118. /** Netscape/Mozilla key3.db client certificate database */
  119. #define APR_LDAP_CERT_TYPE_KEY3_DB 8
  120. /** Netscape/Mozilla client certificate nickname */
  121. #define APR_LDAP_CERT_TYPE_NICKNAME 9
  122. /** Private key type unknown */
  123. #define APR_LDAP_KEY_TYPE_UNKNOWN 10
  124. /** binary DER encoded private key */
  125. #define APR_LDAP_KEY_TYPE_DER 11
  126. /** PEM encoded private key */
  127. #define APR_LDAP_KEY_TYPE_BASE64 12
  128. /** PKCS#12 encoded client certificate */
  129. #define APR_LDAP_CERT_TYPE_PFX 13
  130. /** PKCS#12 encoded private key */
  131. #define APR_LDAP_KEY_TYPE_PFX 14
  132. /**
  133. * Certificate structure.
  134. *
  135. * This structure is used to store certificate details. An array of
  136. * these structures is passed to apr_ldap_set_option() to set CA
  137. * and client certificates.
  138. * @param type Type of certificate APR_LDAP_*_TYPE_*
  139. * @param path Path, file or nickname of the certificate
  140. * @param password Optional password, can be NULL
  141. */
  142. typedef struct apr_ldap_opt_tls_cert_t apr_ldap_opt_tls_cert_t;
  143. struct apr_ldap_opt_tls_cert_t {
  144. int type;
  145. const char *path;
  146. const char *password;
  147. };
  148. /**
  149. * APR_LDAP_OPT_TLS
  150. *
  151. * This sets the SSL level on the LDAP handle.
  152. *
  153. * Netscape/Mozilla:
  154. * Supports SSL, but not STARTTLS
  155. * SSL is enabled by calling ldapssl_install_routines().
  156. *
  157. * Novell:
  158. * Supports SSL and STARTTLS.
  159. * SSL is enabled by calling ldapssl_install_routines(). Note that calling
  160. * other ldap functions before ldapssl_install_routines() may cause this
  161. * function to fail.
  162. * STARTTLS is enabled by calling ldapssl_start_tls_s() after calling
  163. * ldapssl_install_routines() (check this).
  164. *
  165. * OpenLDAP:
  166. * Supports SSL and supports STARTTLS, but none of this is documented:
  167. * http://www.openldap.org/lists/openldap-software/200409/msg00618.html
  168. * Documentation for both SSL support and STARTTLS has been deleted from
  169. * the OpenLDAP documentation and website.
  170. */
  171. /** No encryption */
  172. #define APR_LDAP_NONE 0
  173. /** SSL encryption (ldaps://) */
  174. #define APR_LDAP_SSL 1
  175. /** TLS encryption (STARTTLS) */
  176. #define APR_LDAP_STARTTLS 2
  177. /** end TLS encryption (STOPTLS) */
  178. #define APR_LDAP_STOPTLS 3
  179. /**
  180. * APR LDAP get option function
  181. *
  182. * This function gets option values from a given LDAP session if
  183. * one was specified. It maps to the native ldap_get_option() function.
  184. * @param pool The pool to use
  185. * @param ldap The LDAP handle
  186. * @param option The LDAP_OPT_* option to return
  187. * @param outvalue The value returned (if any)
  188. * @param result_err The apr_ldap_err_t structure contained detailed results
  189. * of the operation.
  190. */
  191. APU_DECLARE(int) apr_ldap_get_option(apr_pool_t *pool,
  192. LDAP *ldap,
  193. int option,
  194. void *outvalue,
  195. apr_ldap_err_t **result_err);
  196. /**
  197. * APR LDAP set option function
  198. *
  199. * This function sets option values to a given LDAP session if
  200. * one was specified. It maps to the native ldap_set_option() function.
  201. *
  202. * Where an option is not supported by an LDAP toolkit, this function
  203. * will try and apply legacy functions to achieve the same effect,
  204. * depending on the platform.
  205. * @param pool The pool to use
  206. * @param ldap The LDAP handle
  207. * @param option The LDAP_OPT_* option to set
  208. * @param invalue The value to set
  209. * @param result_err The apr_ldap_err_t structure contained detailed results
  210. * of the operation.
  211. */
  212. APU_DECLARE(int) apr_ldap_set_option(apr_pool_t *pool,
  213. LDAP *ldap,
  214. int option,
  215. const void *invalue,
  216. apr_ldap_err_t **result_err);
  217. #ifdef __cplusplus
  218. }
  219. #endif
  220. #endif /* APR_HAS_LDAP */
  221. /** @} */
  222. #endif /* APR_LDAP_OPTION_H */