apr_ldap_option.h 8.7 KB

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