ssl.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* SSL-related stuff for slapd */
  42. #if defined( _WINDOWS )
  43. #include <windows.h>
  44. #include <winsock.h>
  45. #include <sys/types.h>
  46. #include <sys/stat.h>
  47. #include "proto-ntutil.h"
  48. #include <string.h>
  49. #include <stdlib.h>
  50. #include <direct.h>
  51. #include <io.h>
  52. #endif
  53. #include <sys/param.h>
  54. #include <ssl.h>
  55. #include <nss.h>
  56. #include <key.h>
  57. #include <sslproto.h>
  58. #include "secmod.h"
  59. #include <string.h>
  60. #include <errno.h>
  61. #define NEED_TOK_DES /* defines tokDes and ptokDes - see slap.h */
  62. #include "slap.h"
  63. #include "svrcore.h"
  64. #include "fe.h"
  65. #include "certdb.h"
  66. #if !defined(USE_OPENLDAP)
  67. #include "ldap_ssl.h"
  68. #endif
  69. /* For IRIX... */
  70. #ifndef MAXPATHLEN
  71. #define MAXPATHLEN 1024
  72. #endif
  73. extern char* slapd_SSL3ciphers;
  74. extern symbol_t supported_ciphers[];
  75. /* dongle_file_name is set in slapd_nss_init when we set the path for the
  76. key, cert, and secmod files - the dongle file must be in the same directory
  77. and use the same naming scheme
  78. */
  79. static char* dongle_file_name = NULL;
  80. static int _security_library_initialized = 0;
  81. static int _ssl_listener_initialized = 0;
  82. static int _nss_initialized = 0;
  83. /* Our name for the internal token, must match PKCS-11 config data below */
  84. static char *internalTokenName = "Internal (Software) Token";
  85. static int stimeout;
  86. static char *ciphers = NULL;
  87. static char * configDN = "cn=encryption,cn=config";
  88. /* Copied from libadmin/libadmin.h public/nsapi.h */
  89. #define SERVER_KEY_NAME "Server-Key"
  90. #define MAGNUS_ERROR_LEN 1024
  91. #define LOG_WARN 0
  92. #define LOG_FAILURE 3
  93. #define FILE_PATHSEP '/'
  94. /* ----------------------- Multiple cipher support ------------------------ */
  95. static char **cipher_names = NULL;
  96. typedef struct {
  97. char *version;
  98. char *name;
  99. int num;
  100. } cipherstruct;
  101. static cipherstruct _conf_ciphers[] = {
  102. {"SSL3","rc4", SSL_EN_RC4_128_WITH_MD5},
  103. {"SSL3","rc4export", SSL_EN_RC4_128_EXPORT40_WITH_MD5},
  104. {"SSL3","rc2", SSL_EN_RC2_128_CBC_WITH_MD5},
  105. {"SSL3","rc2export", SSL_EN_RC2_128_CBC_EXPORT40_WITH_MD5},
  106. /*{"idea", SSL_EN_IDEA_128_CBC_WITH_MD5}, */
  107. {"SSL3","des", SSL_EN_DES_64_CBC_WITH_MD5},
  108. {"SSL3","desede3", SSL_EN_DES_192_EDE3_CBC_WITH_MD5},
  109. {"SSL3","rsa_rc4_128_md5", SSL_RSA_WITH_RC4_128_MD5},
  110. {"SSL3","rsa_rc4_128_sha", SSL_RSA_WITH_RC4_128_SHA},
  111. {"SSL3","rsa_3des_sha", SSL_RSA_WITH_3DES_EDE_CBC_SHA},
  112. {"SSL3","rsa_des_sha", SSL_RSA_WITH_DES_CBC_SHA},
  113. {"SSL3","rsa_fips_3des_sha", SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA},
  114. {"SSL3","fips_3des_sha", SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA}, /* ditto */
  115. {"SSL3","rsa_fips_des_sha", SSL_RSA_FIPS_WITH_DES_CBC_SHA},
  116. {"SSL3","fips_des_sha", SSL_RSA_FIPS_WITH_DES_CBC_SHA}, /* ditto */
  117. {"SSL3","rsa_rc4_40_md5", SSL_RSA_EXPORT_WITH_RC4_40_MD5},
  118. {"SSL3","rsa_rc2_40_md5", SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5},
  119. {"SSL3","rsa_null_md5", SSL_RSA_WITH_NULL_MD5},
  120. {"SSL3","rsa_null_sha", SSL_RSA_WITH_NULL_SHA},
  121. {"TLS","tls_rsa_export1024_with_rc4_56_sha", TLS_RSA_EXPORT1024_WITH_RC4_56_SHA},
  122. {"TLS","rsa_rc4_56_sha", TLS_RSA_EXPORT1024_WITH_RC4_56_SHA}, /* ditto */
  123. {"TLS","tls_rsa_export1024_with_des_cbc_sha", TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA},
  124. {"TLS","rsa_des_56_sha", TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA}, /* ditto */
  125. {"SSL3","fortezza", SSL_FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA},
  126. {"SSL3","fortezza_rc4_128_sha", SSL_FORTEZZA_DMS_WITH_RC4_128_SHA},
  127. {"SSL3","fortezza_null", SSL_FORTEZZA_DMS_WITH_NULL_SHA},
  128. /*{"SSL3","dhe_dss_40_sha", SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA}, */
  129. {"SSL3","dhe_dss_des_sha", SSL_DHE_DSS_WITH_DES_CBC_SHA},
  130. {"SSL3","dhe_dss_3des_sha", SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA},
  131. /*{"SSL3","dhe_rsa_40_sha", SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA}, */
  132. {"SSL3","dhe_rsa_des_sha", SSL_DHE_RSA_WITH_DES_CBC_SHA},
  133. {"SSL3","dhe_rsa_3des_sha", SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA},
  134. {"TLS","tls_rsa_aes_128_sha", TLS_RSA_WITH_AES_128_CBC_SHA},
  135. {"TLS","rsa_aes_128_sha", TLS_RSA_WITH_AES_128_CBC_SHA}, /* ditto */
  136. {"TLS","tls_dhe_dss_aes_128_sha", TLS_DHE_DSS_WITH_AES_128_CBC_SHA},
  137. {"TLS","tls_dhe_rsa_aes_128_sha", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
  138. {"TLS","tls_rsa_aes_256_sha", TLS_RSA_WITH_AES_256_CBC_SHA},
  139. {"TLS","rsa_aes_256_sha", TLS_RSA_WITH_AES_256_CBC_SHA}, /* ditto */
  140. {"TLS","tls_dhe_dss_aes_256_sha", TLS_DHE_DSS_WITH_AES_256_CBC_SHA},
  141. {"TLS","tls_dhe_rsa_aes_256_sha", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
  142. /*{"TLS","tls_dhe_dss_1024_des_sha", TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA}, */
  143. {"TLS","tls_dhe_dss_1024_rc4_sha", TLS_RSA_EXPORT1024_WITH_RC4_56_SHA},
  144. {"TLS","tls_dhe_dss_rc4_128_sha", TLS_DHE_DSS_WITH_RC4_128_SHA},
  145. {NULL, NULL, 0}
  146. };
  147. static void
  148. slapd_SSL_report(int degree, char *fmt, va_list args)
  149. {
  150. char buf[2048];
  151. PR_vsnprintf( buf, sizeof(buf), fmt, args );
  152. LDAPDebug( LDAP_DEBUG_ANY, "SSL %s: %s\n",
  153. (degree == LOG_FAILURE) ? "failure" : "alert",
  154. buf, 0 );
  155. }
  156. void
  157. slapd_SSL_error(char *fmt, ...)
  158. {
  159. va_list args;
  160. va_start(args, fmt);
  161. slapd_SSL_report(LOG_FAILURE, fmt, args);
  162. va_end(args);
  163. }
  164. void
  165. slapd_SSL_warn(char *fmt, ...)
  166. {
  167. va_list args;
  168. va_start(args, fmt);
  169. slapd_SSL_report(LOG_WARN, fmt, args);
  170. va_end(args);
  171. }
  172. char ** getSupportedCiphers()
  173. {
  174. SSLCipherSuiteInfo info;
  175. char *sep = "::";
  176. int number_of_ciphers = sizeof (_conf_ciphers) /sizeof(cipherstruct);
  177. int i;
  178. int idx = 0;
  179. PRBool isFIPS = slapd_pk11_isFIPS();
  180. if (cipher_names == NULL ) {
  181. cipher_names = (char **) slapi_ch_calloc ((number_of_ciphers +1 ) , sizeof(char *));
  182. for (i = 0 ; _conf_ciphers[i].name != NULL; i++ ) {
  183. SSL_GetCipherSuiteInfo((PRUint16)_conf_ciphers[i].num,&info,sizeof(info));
  184. /* only support FIPS approved ciphers in FIPS mode */
  185. if (!isFIPS || info.isFIPS) {
  186. cipher_names[idx++] = PR_smprintf("%s%s%s%s%s%s%s%s%d",_conf_ciphers[i].version,sep,_conf_ciphers[i].name,sep,info.symCipherName,sep,info.macAlgorithmName,sep,info.symKeyBits);
  187. }
  188. }
  189. cipher_names[idx] = NULL;
  190. }
  191. return cipher_names;
  192. }
  193. static PRBool
  194. cipher_check_fips(int idx, char ***suplist, char ***unsuplist)
  195. {
  196. PRBool rc = PR_TRUE;
  197. if (slapd_pk11_isFIPS()) {
  198. SSLCipherSuiteInfo info;
  199. if (SECFailure == SSL_GetCipherSuiteInfo((PRUint16)_conf_ciphers[idx].num,
  200. &info, sizeof info)) {
  201. PRErrorCode errorCode = PR_GetError();
  202. if (slapi_is_loglevel_set(SLAPI_LOG_CONFIG)) {
  203. slapd_SSL_warn("Security Initialization: no information for cipher suite [%s] "
  204. "error %d - %s", _conf_ciphers[idx].name,
  205. errorCode, slapd_pr_strerror(errorCode));
  206. }
  207. rc = PR_FALSE;
  208. }
  209. if (rc && !info.isFIPS) {
  210. if (slapi_is_loglevel_set(SLAPI_LOG_CONFIG)) {
  211. slapd_SSL_warn("Security Initialization: FIPS mode is enabled but "
  212. "cipher suite [%s] is not approved for FIPS - "
  213. "the cipher suite will be disabled - if "
  214. "you want to use this cipher suite, you must use modutil to "
  215. "disable FIPS in the internal token.",
  216. _conf_ciphers[idx].name);
  217. }
  218. rc = PR_FALSE;
  219. }
  220. if (!rc && unsuplist && !charray_inlist(*unsuplist, _conf_ciphers[idx].name)) {
  221. charray_add(unsuplist, _conf_ciphers[idx].name);
  222. }
  223. if (rc && suplist && !charray_inlist(*suplist, _conf_ciphers[idx].name)) {
  224. charray_add(suplist, _conf_ciphers[idx].name);
  225. }
  226. }
  227. return rc;
  228. }
  229. void
  230. _conf_setallciphers(int active, char ***suplist, char ***unsuplist)
  231. {
  232. int x;
  233. /* MLM - change: Because null_md5 is NOT encrypted at all, force
  234. * them to activate it by name. */
  235. for(x = 0; _conf_ciphers[x].name; x++) {
  236. PRBool enabled = active ? PR_TRUE : PR_FALSE;
  237. if(active && !strcmp(_conf_ciphers[x].name, "rsa_null_md5")) {
  238. continue;
  239. }
  240. if (enabled) {
  241. enabled = cipher_check_fips(x, suplist, unsuplist);
  242. }
  243. SSL_CipherPrefSetDefault(_conf_ciphers[x].num, enabled);
  244. }
  245. }
  246. static char *
  247. charray2str(char **ary, const char *delim)
  248. {
  249. char *str = NULL;
  250. while (ary && *ary) {
  251. if (str) {
  252. str = PR_sprintf_append(str, "%s%s", delim, *ary++);
  253. } else {
  254. str = PR_smprintf("%s", *ary++);
  255. }
  256. }
  257. return str;
  258. }
  259. char *
  260. _conf_setciphers(char *ciphers)
  261. {
  262. char *t, err[MAGNUS_ERROR_LEN];
  263. int x, active;
  264. char *raw = ciphers;
  265. char **suplist = NULL;
  266. char **unsuplist = NULL;
  267. /* Default is to activate all of them */
  268. if(!ciphers || ciphers[0] == '\0') {
  269. _conf_setallciphers(1, &suplist, NULL);
  270. if (suplist && *suplist) {
  271. if (slapi_is_loglevel_set(SLAPI_LOG_CONFIG)) {
  272. char *str = charray2str(suplist, ",");
  273. slapd_SSL_warn("Security Initialization: FIPS mode is enabled - only the following "
  274. "cipher suites are approved for FIPS: [%s] - "
  275. "all other cipher suites are disabled - if "
  276. "you want to use other cipher suites, you must use modutil to "
  277. "disable FIPS in the internal token.",
  278. str ? str : "(none)");
  279. slapi_ch_free_string(&str);
  280. }
  281. }
  282. slapi_ch_free((void **)&suplist); /* strings inside are static */
  283. return NULL;
  284. }
  285. /* Enable all the ciphers by default and the following while loop would disable the user disabled ones This is needed becuase we added a new set of ciphers in the table . Right now there is no support for this from the console */
  286. _conf_setallciphers(1, &suplist, NULL);
  287. t = ciphers;
  288. while(t) {
  289. while((*ciphers) && (isspace(*ciphers))) ++ciphers;
  290. switch(*ciphers++) {
  291. case '+':
  292. active = 1; break;
  293. case '-':
  294. active = 0; break;
  295. default:
  296. PR_snprintf(err, sizeof(err), "invalid ciphers <%s>: format is "
  297. "+cipher1,-cipher2...", raw);
  298. return slapi_ch_strdup(err);
  299. }
  300. if( (t = strchr(ciphers, ',')) )
  301. *t++ = '\0';
  302. if(!strcasecmp(ciphers, "all"))
  303. _conf_setallciphers(active, NULL, NULL);
  304. else {
  305. for(x = 0; _conf_ciphers[x].name; x++) {
  306. if(!strcasecmp(ciphers, _conf_ciphers[x].name)) {
  307. PRBool enabled = active ? PR_TRUE : PR_FALSE;
  308. if (enabled) {
  309. enabled = cipher_check_fips(x, NULL, &unsuplist);
  310. }
  311. SSL_CipherPrefSetDefault(_conf_ciphers[x].num, enabled);
  312. break;
  313. }
  314. }
  315. if(!_conf_ciphers[x].name) {
  316. PR_snprintf(err, sizeof(err), "unknown cipher %s", ciphers);
  317. slapi_ch_free((void **)&suplist); /* strings inside are static */
  318. slapi_ch_free((void **)&unsuplist); /* strings inside are static */
  319. return slapi_ch_strdup(err);
  320. }
  321. }
  322. if(t)
  323. ciphers = t;
  324. }
  325. if (unsuplist && *unsuplist) {
  326. char *strsup = charray2str(suplist, ",");
  327. char *strunsup = charray2str(unsuplist, ",");
  328. slapd_SSL_warn("Security Initialization: FIPS mode is enabled - only the following "
  329. "cipher suites are approved for FIPS: [%s] - "
  330. "the specified cipher suites [%s] are disabled - if "
  331. "you want to use these unsupported cipher suites, you must use modutil to "
  332. "disable FIPS in the internal token.",
  333. strsup ? strsup : "(none)", strunsup ? strunsup : "(none)");
  334. slapi_ch_free_string(&strsup);
  335. slapi_ch_free_string(&strunsup);
  336. }
  337. slapi_ch_free((void **)&suplist); /* strings inside are static */
  338. slapi_ch_free((void **)&unsuplist); /* strings inside are static */
  339. return NULL;
  340. }
  341. /* SSL Policy stuff */
  342. /*
  343. * SSLPLCY_Install
  344. *
  345. * Call the SSL_CipherPolicySet function for each ciphersuite.
  346. */
  347. PRStatus
  348. SSLPLCY_Install(void)
  349. {
  350. SECStatus s = 0;
  351. s = NSS_SetDomesticPolicy();
  352. return s?PR_FAILURE:PR_SUCCESS;
  353. }
  354. /**
  355. * Get a particular entry
  356. */
  357. static Slapi_Entry *
  358. getConfigEntry( const char *dn, Slapi_Entry **e2 ) {
  359. Slapi_DN sdn;
  360. slapi_sdn_init_dn_byref( &sdn, dn );
  361. slapi_search_internal_get_entry( &sdn, NULL, e2,
  362. plugin_get_default_component_id());
  363. slapi_sdn_done( &sdn );
  364. return *e2;
  365. }
  366. /**
  367. * Free an entry
  368. */
  369. static void
  370. freeConfigEntry( Slapi_Entry ** e ) {
  371. if ( (e != NULL) && (*e != NULL) ) {
  372. slapi_entry_free( *e );
  373. *e = NULL;
  374. }
  375. }
  376. /**
  377. * Get a list of child DNs
  378. */
  379. static char **
  380. getChildren( char *dn ) {
  381. Slapi_PBlock *new_pb = NULL;
  382. Slapi_Entry **e;
  383. int search_result = 1;
  384. int nEntries = 0;
  385. char **list = NULL;
  386. new_pb = slapi_search_internal ( dn, LDAP_SCOPE_ONELEVEL,
  387. "(objectclass=nsEncryptionModule)",
  388. NULL, NULL, 0);
  389. slapi_pblock_get( new_pb, SLAPI_NENTRIES, &nEntries);
  390. if ( nEntries > 0 ) {
  391. slapi_pblock_get( new_pb, SLAPI_PLUGIN_INTOP_RESULT, &search_result);
  392. slapi_pblock_get( new_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &e);
  393. if ( e != NULL ) {
  394. int i;
  395. list = (char **)slapi_ch_malloc( sizeof(*list) * (nEntries + 1));
  396. for ( i = 0; e[i] != NULL; i++ ) {
  397. list[i] = slapi_ch_strdup(slapi_entry_get_dn(e[i]));
  398. }
  399. list[nEntries] = NULL;
  400. }
  401. }
  402. slapi_free_search_results_internal(new_pb);
  403. slapi_pblock_destroy(new_pb );
  404. return list;
  405. }
  406. /**
  407. * Free a list of child DNs
  408. */
  409. static void
  410. freeChildren( char **list ) {
  411. if ( list != NULL ) {
  412. int i;
  413. for ( i = 0; list[i] != NULL; i++ ) {
  414. slapi_ch_free( (void **)(&list[i]) );
  415. }
  416. slapi_ch_free( (void **)(&list) );
  417. }
  418. }
  419. /* Logs a warning and returns 1 if cert file doesn't exist. You
  420. * can skip the warning log message by setting no_log to 1.*/
  421. static int
  422. warn_if_no_cert_file(const char *dir, int no_log)
  423. {
  424. int ret = 0;
  425. char *filename = slapi_ch_smprintf("%s/cert8.db", dir);
  426. PRStatus status = PR_Access(filename, PR_ACCESS_READ_OK);
  427. if (PR_SUCCESS != status) {
  428. slapi_ch_free_string(&filename);
  429. filename = slapi_ch_smprintf("%s/cert7.db", dir);
  430. status = PR_Access(filename, PR_ACCESS_READ_OK);
  431. if (PR_SUCCESS != status) {
  432. ret = 1;
  433. if (!no_log) {
  434. slapi_log_error(SLAPI_LOG_FATAL, "SSL Initialization",
  435. "Warning: certificate DB file cert8.db nor cert7.db exists in [%s] - "
  436. "SSL initialization will likely fail\n", dir);
  437. }
  438. }
  439. }
  440. slapi_ch_free_string(&filename);
  441. return ret;
  442. }
  443. /* Logs a warning and returns 1 if key file doesn't exist. You
  444. * can skip the warning log message by setting no_log to 1.*/
  445. static int
  446. warn_if_no_key_file(const char *dir, int no_log)
  447. {
  448. int ret = 0;
  449. char *filename = slapi_ch_smprintf("%s/key3.db", dir);
  450. PRStatus status = PR_Access(filename, PR_ACCESS_READ_OK);
  451. if (PR_SUCCESS != status) {
  452. ret = 1;
  453. if (!no_log) {
  454. slapi_log_error(SLAPI_LOG_FATAL, "SSL Initialization",
  455. "Warning: key DB file %s does not exist - SSL initialization will "
  456. "likely fail\n", filename);
  457. }
  458. }
  459. slapi_ch_free_string(&filename);
  460. return ret;
  461. }
  462. /*
  463. * slapd_nss_init() is always called from main(), even if we do not
  464. * plan to listen on a secure port. If config_available is 0, the
  465. * config. entries from dse.ldif are NOT available (used only when
  466. * running in referral mode).
  467. * As of DS6.1, the init_ssl flag passed is ignored.
  468. *
  469. * richm 20070126 - By default now we put the key/cert db files
  470. * in an instance specific directory (the certdir directory) so
  471. * we do not need a prefix any more.
  472. */
  473. int
  474. slapd_nss_init(int init_ssl, int config_available)
  475. {
  476. SECStatus secStatus;
  477. PRErrorCode errorCode;
  478. int rv = 0;
  479. int len = 0;
  480. int create_certdb = 0;
  481. PRUint32 nssFlags = 0;
  482. char *certdir;
  483. char *certdb_file_name = NULL;
  484. char *keydb_file_name = NULL;
  485. char *secmoddb_file_name = NULL;
  486. /* set in slapd_bootstrap_config,
  487. thus certdir is available even if config_available is false */
  488. certdir = config_get_certdir();
  489. /* make sure path does not end in the path separator character */
  490. len = strlen(certdir);
  491. if (certdir[len-1] == '/' || certdir[len-1] == '\\') {
  492. certdir[len-1] = '\0';
  493. }
  494. /* If the server is configured to use SSL, we must have a key and cert db */
  495. if (config_get_security()) {
  496. warn_if_no_cert_file(certdir, 0);
  497. warn_if_no_key_file(certdir, 0);
  498. } else { /* otherwise, NSS will create empty databases */
  499. /* we open the key/cert db in rw mode, so make sure the directory
  500. is writable */
  501. if (PR_SUCCESS != PR_Access(certdir, PR_ACCESS_WRITE_OK)) {
  502. char *serveruser = "unknown";
  503. #ifndef _WIN32
  504. serveruser = config_get_localuser();
  505. #endif
  506. slapi_log_error(SLAPI_LOG_FATAL, "SSL Initialization",
  507. "Warning: The key/cert database directory [%s] is not writable by "
  508. "the server uid [%s]: initialization likely to fail.\n",
  509. certdir, serveruser);
  510. #ifndef _WIN32
  511. slapi_ch_free_string(&serveruser);
  512. #endif
  513. }
  514. }
  515. /* Check if we have a certdb already. If not, set a flag that we are
  516. * going to create one so we can set the appropriate permissions on it. */
  517. if (warn_if_no_cert_file(certdir, 1) || warn_if_no_key_file(certdir, 1)) {
  518. create_certdb = 1;
  519. }
  520. /******** Initialise NSS *********/
  521. nssFlags &= (~NSS_INIT_READONLY);
  522. slapd_pk11_configurePKCS11(NULL, NULL, tokDes, ptokDes, NULL, NULL, NULL, NULL, 0, 0 );
  523. secStatus = NSS_Initialize(certdir, NULL, NULL, "secmod.db", nssFlags);
  524. dongle_file_name = PR_smprintf("%s/pin.txt", certdir);
  525. if (secStatus != SECSuccess) {
  526. errorCode = PR_GetError();
  527. slapd_SSL_warn("Security Initialization: NSS initialization failed ("
  528. SLAPI_COMPONENT_NAME_NSPR " error %d - %s): "
  529. "certdir: %s",
  530. errorCode, slapd_pr_strerror(errorCode), certdir);
  531. rv = -1;
  532. }
  533. if(SSLPLCY_Install() != PR_SUCCESS) {
  534. errorCode = PR_GetError();
  535. slapd_SSL_warn("Security Initialization: Unable to set SSL export policy ("
  536. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  537. errorCode, slapd_pr_strerror(errorCode));
  538. return -1;
  539. }
  540. /* NSS creates the certificate db files with a mode of 600. There
  541. * is no way to pass in a mode to use for creation to NSS, so we
  542. * need to modify it after creation. We need to allow read and
  543. * write permission to the group so the certs can be managed via
  544. * the console/adminserver. */
  545. if (create_certdb) {
  546. certdb_file_name = slapi_ch_smprintf("%s/cert8.db", certdir);
  547. keydb_file_name = slapi_ch_smprintf("%s/key3.db", certdir);
  548. secmoddb_file_name = slapi_ch_smprintf("%s/secmod.db", certdir);
  549. if(chmod(certdb_file_name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP )){
  550. LDAPDebug(LDAP_DEBUG_ANY, "slapd_nss_init: chmod failed for file %s error (%d) %s.\n",
  551. certdb_file_name, errno, slapd_system_strerror(errno));
  552. }
  553. if(chmod(keydb_file_name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP )){
  554. LDAPDebug(LDAP_DEBUG_ANY, "slapd_nss_init: chmod failed for file %s error (%d) %s.\n",
  555. keydb_file_name, errno, slapd_system_strerror(errno));
  556. }
  557. if(chmod(secmoddb_file_name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP )){
  558. LDAPDebug(LDAP_DEBUG_ANY, "slapd_nss_init: chmod failed for file %s error (%d) %s.\n",
  559. secmoddb_file_name, errno, slapd_system_strerror(errno));
  560. }
  561. }
  562. /****** end of NSS Initialization ******/
  563. _nss_initialized = 1;
  564. slapi_ch_free_string(&certdb_file_name);
  565. slapi_ch_free_string(&keydb_file_name);
  566. slapi_ch_free_string(&secmoddb_file_name);
  567. slapi_ch_free_string(&certdir);
  568. return rv;
  569. }
  570. static int
  571. svrcore_setup()
  572. {
  573. PRErrorCode errorCode;
  574. int rv = 0;
  575. #ifndef _WIN32
  576. SVRCOREStdPinObj *StdPinObj;
  577. #else
  578. SVRCOREFilePinObj *FilePinObj;
  579. SVRCOREAltPinObj *AltPinObj;
  580. SVRCORENTUserPinObj *NTUserPinObj;
  581. #endif
  582. #ifndef _WIN32
  583. StdPinObj = (SVRCOREStdPinObj *)SVRCORE_GetRegisteredPinObj();
  584. if (StdPinObj) {
  585. return 0; /* already registered */
  586. }
  587. if ( SVRCORE_CreateStdPinObj(&StdPinObj, dongle_file_name, PR_TRUE) !=
  588. SVRCORE_Success) {
  589. errorCode = PR_GetError();
  590. slapd_SSL_warn("Security Initialization: Unable to create PinObj ("
  591. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  592. errorCode, slapd_pr_strerror(errorCode));
  593. return -1;
  594. }
  595. SVRCORE_RegisterPinObj((SVRCOREPinObj *)StdPinObj);
  596. #else
  597. AltPinObj = (SVRCOREAltPinObj *)SVRCORE_GetRegisteredPinObj();
  598. if (AltPinObj) {
  599. return 0; /* already registered */
  600. }
  601. if (SVRCORE_CreateFilePinObj(&FilePinObj, dongle_file_name) !=
  602. SVRCORE_Success) {
  603. errorCode = PR_GetError();
  604. slapd_SSL_warn("Security Initialization: Unable to create FilePinObj ("
  605. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  606. errorCode, slapd_pr_strerror(errorCode));
  607. return -1;
  608. }
  609. if (SVRCORE_CreateNTUserPinObj(&NTUserPinObj) != SVRCORE_Success){
  610. errorCode = PR_GetError();
  611. slapd_SSL_warn("Security Initialization: Unable to create NTUserPinObj ("
  612. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  613. errorCode, slapd_pr_strerror(errorCode));
  614. return -1;
  615. }
  616. if (SVRCORE_CreateAltPinObj(&AltPinObj, (SVRCOREPinObj *)FilePinObj,
  617. (SVRCOREPinObj *)NTUserPinObj) != SVRCORE_Success) {
  618. errorCode = PR_GetError();
  619. slapd_SSL_warn("Security Initialization: Unable to create AltPinObj ("
  620. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  621. errorCode, slapd_pr_strerror(errorCode));
  622. return -1;
  623. }
  624. SVRCORE_RegisterPinObj((SVRCOREPinObj *)AltPinObj);
  625. #endif /* _WIN32 */
  626. return rv;
  627. }
  628. /*
  629. * slapd_ssl_init() is called from main() if we plan to listen
  630. * on a secure port.
  631. */
  632. int
  633. slapd_ssl_init() {
  634. PRErrorCode errorCode;
  635. char ** family_list;
  636. char *val = NULL;
  637. char cipher_string[1024];
  638. int rv = 0;
  639. PK11SlotInfo *slot;
  640. Slapi_Entry *entry = NULL;
  641. /* Get general information */
  642. getConfigEntry( configDN, &entry );
  643. val = slapi_entry_attr_get_charptr( entry, "nssslSessionTimeout" );
  644. ciphers = slapi_entry_attr_get_charptr( entry, "nsssl3ciphers" );
  645. /* We are currently using the value of sslSessionTimeout
  646. for ssl3SessionTimeout, see SSL_ConfigServerSessionIDCache() */
  647. /* Note from Tom Weinstein on the meaning of the timeout:
  648. Timeouts are in seconds. '0' means use the default, which is
  649. 24hrs for SSL3 and 100 seconds for SSL2.
  650. */
  651. if(!val) {
  652. errorCode = PR_GetError();
  653. slapd_SSL_warn("Security Initialization: Failed to retrieve SSL "
  654. "configuration information ("
  655. SLAPI_COMPONENT_NAME_NSPR " error %d - %s): "
  656. "nssslSessionTimeout: %s ",
  657. errorCode, slapd_pr_strerror(errorCode),
  658. (val ? "found" : "not found"));
  659. slapi_ch_free((void **) &val);
  660. slapi_ch_free((void **) &ciphers);
  661. freeConfigEntry( &entry );
  662. return -1;
  663. }
  664. stimeout = atoi(val);
  665. slapi_ch_free((void **) &val);
  666. if (svrcore_setup()) {
  667. freeConfigEntry( &entry );
  668. return -1;
  669. }
  670. if((family_list = getChildren(configDN))) {
  671. char **family;
  672. char *token;
  673. char *activation;
  674. for (family = family_list; *family; family++) {
  675. token = NULL;
  676. activation = NULL;
  677. freeConfigEntry( &entry );
  678. getConfigEntry( *family, &entry );
  679. if ( entry == NULL ) {
  680. continue;
  681. }
  682. activation = slapi_entry_attr_get_charptr( entry, "nssslactivation" );
  683. if((!activation) || (!strcasecmp(activation, "off"))) {
  684. /* this family was turned off, goto next */
  685. slapi_ch_free((void **) &activation);
  686. continue;
  687. }
  688. slapi_ch_free((void **) &activation);
  689. token = slapi_entry_attr_get_charptr( entry, "nsssltoken" );
  690. if( token ) {
  691. if( !strcasecmp(token, "internal") ||
  692. !strcasecmp(token, "internal (software)"))
  693. slot = slapd_pk11_getInternalKeySlot();
  694. else
  695. slot = slapd_pk11_findSlotByName(token);
  696. } else {
  697. errorCode = PR_GetError();
  698. slapd_SSL_warn("Security Initialization: Unable to get token ("
  699. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  700. errorCode, slapd_pr_strerror(errorCode));
  701. freeChildren(family_list);
  702. freeConfigEntry( &entry );
  703. return -1;
  704. }
  705. slapi_ch_free((void **) &token);
  706. if (!slot) {
  707. errorCode = PR_GetError();
  708. slapd_SSL_warn("Security Initialization: Unable to find slot ("
  709. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  710. errorCode, slapd_pr_strerror(errorCode));
  711. freeChildren(family_list);
  712. freeConfigEntry( &entry );
  713. return -1;
  714. }
  715. /* authenticate */
  716. if(slapd_pk11_authenticate(slot, PR_TRUE, NULL) != SECSuccess)
  717. {
  718. errorCode = PR_GetError();
  719. slapd_SSL_warn("Security Initialization: Unable to authenticate ("
  720. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  721. errorCode, slapd_pr_strerror(errorCode));
  722. freeChildren(family_list);
  723. freeConfigEntry( &entry );
  724. return -1;
  725. }
  726. }
  727. freeChildren( family_list );
  728. }
  729. freeConfigEntry( &entry );
  730. /* ugaston- Cipher preferences must be set before any sslSocket is created
  731. * for such sockets to take preferences into account.
  732. */
  733. /* Step Three.5: Set SSL cipher preferences */
  734. *cipher_string = 0;
  735. if(ciphers && (*ciphers) && strcmp(ciphers, "blank"))
  736. PL_strncpyz(cipher_string, ciphers, sizeof(cipher_string));
  737. slapi_ch_free((void **) &ciphers);
  738. if( NULL != (val = _conf_setciphers(cipher_string)) ) {
  739. errorCode = PR_GetError();
  740. slapd_SSL_warn("Security Initialization: Failed to set SSL cipher "
  741. "preference information: %s (" SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  742. val, errorCode, slapd_pr_strerror(errorCode));
  743. rv = 3;
  744. slapi_ch_free((void **) &val);
  745. }
  746. freeConfigEntry( &entry );
  747. /* Introduce a way of knowing whether slapd_ssl_init has
  748. * already been executed. */
  749. _security_library_initialized = 1;
  750. if ( rv != 0 )
  751. return rv;
  752. return 0;
  753. }
  754. int slapd_ssl_init2(PRFileDesc **fd, int startTLS)
  755. {
  756. PRFileDesc *pr_sock, *sock = (*fd);
  757. PRErrorCode errorCode;
  758. SECStatus rv = SECFailure;
  759. char ** family_list;
  760. CERTCertificate *cert = NULL;
  761. SECKEYPrivateKey *key = NULL;
  762. char errorbuf[BUFSIZ];
  763. char *val = NULL;
  764. char *default_val = NULL;
  765. int nFamilies = 0;
  766. SECStatus sslStatus;
  767. int slapd_SSLclientAuth;
  768. char* tmpDir;
  769. Slapi_Entry *e = NULL;
  770. PRBool enableSSL2 = PR_FALSE;
  771. PRBool enableSSL3 = PR_TRUE;
  772. PRBool enableTLS1 = PR_TRUE;
  773. PRBool fipsMode = PR_FALSE;
  774. /* turn off the PKCS11 pin interactive mode */
  775. #ifndef _WIN32
  776. SVRCOREStdPinObj *StdPinObj;
  777. if (svrcore_setup()) {
  778. return 1;
  779. }
  780. StdPinObj = (SVRCOREStdPinObj *)SVRCORE_GetRegisteredPinObj();
  781. SVRCORE_SetStdPinInteractive(StdPinObj, PR_FALSE);
  782. #endif
  783. errorbuf[0] = '\0';
  784. /* Import pr fd into SSL */
  785. pr_sock = SSL_ImportFD( NULL, sock );
  786. if( pr_sock == (PRFileDesc *)NULL ) {
  787. errorCode = PR_GetError();
  788. slapd_SSL_warn("Security Initialization: Failed to import NSPR "
  789. "fd into SSL (" SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  790. errorCode, slapd_pr_strerror(errorCode));
  791. return 1;
  792. }
  793. (*fd) = pr_sock;
  794. /* Step / Three.6 /
  795. * - If in FIPS mode, authenticate to the token before
  796. * doing anything else
  797. */
  798. {
  799. PK11SlotInfo *slot = slapd_pk11_getInternalSlot();
  800. if (!slot) {
  801. errorCode = PR_GetError();
  802. slapd_SSL_warn("Security Initialization: Unable to get internal slot ("
  803. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  804. errorCode, slapd_pr_strerror(errorCode));
  805. return -1;
  806. }
  807. if(slapd_pk11_isFIPS()) {
  808. if(slapd_pk11_authenticate(slot, PR_TRUE, NULL) != SECSuccess) {
  809. errorCode = PR_GetError();
  810. slapd_SSL_warn("Security Initialization: Unable to authenticate ("
  811. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  812. errorCode, slapd_pr_strerror(errorCode));
  813. return -1;
  814. }
  815. fipsMode = PR_TRUE;
  816. /* FIPS does not like to use SSLv3 */
  817. enableSSL3 = PR_FALSE;
  818. }
  819. slapd_pk11_setSlotPWValues(slot, 0, 0);
  820. }
  821. /*
  822. * Now, get the complete list of cipher families. Each family
  823. * has a token name and personality name which we'll use to find
  824. * appropriate keys and certs, and call SSL_ConfigSecureServer
  825. * with.
  826. */
  827. if((family_list = getChildren(configDN))) {
  828. char **family;
  829. char cert_name[1024];
  830. char *token;
  831. char *personality;
  832. char *activation;
  833. for (family = family_list; *family; family++) {
  834. token = NULL;
  835. personality = NULL;
  836. activation = NULL;
  837. getConfigEntry( *family, &e );
  838. if ( e == NULL ) {
  839. continue;
  840. }
  841. activation = slapi_entry_attr_get_charptr( e, "nssslactivation" );
  842. if((!activation) || (!strcasecmp(activation, "off"))) {
  843. /* this family was turned off, goto next */
  844. slapi_ch_free((void **) &activation);
  845. freeConfigEntry( &e );
  846. continue;
  847. }
  848. slapi_ch_free((void **) &activation);
  849. token = slapi_entry_attr_get_charptr( e, "nsssltoken" );
  850. personality = slapi_entry_attr_get_charptr( e, "nssslpersonalityssl" );
  851. if( token && personality ) {
  852. if( !strcasecmp(token, "internal") ||
  853. !strcasecmp(token, "internal (software)") )
  854. PL_strncpyz(cert_name, personality, sizeof(cert_name));
  855. else
  856. /* external PKCS #11 token - attach token name */
  857. PR_snprintf(cert_name, sizeof(cert_name), "%s:%s", token, personality);
  858. }
  859. else {
  860. errorCode = PR_GetError();
  861. slapd_SSL_warn("Security Initialization: Failed to get cipher "
  862. "family information. Missing nsssltoken or"
  863. "nssslpersonalityssl in %s ("
  864. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  865. *family, errorCode, slapd_pr_strerror(errorCode));
  866. slapi_ch_free((void **) &token);
  867. slapi_ch_free((void **) &personality);
  868. freeConfigEntry( &e );
  869. continue;
  870. }
  871. slapi_ch_free((void **) &token);
  872. /* Step Four -- Locate the server certificate */
  873. cert = slapd_pk11_findCertFromNickname(cert_name, NULL);
  874. if (cert == NULL) {
  875. errorCode = PR_GetError();
  876. slapd_SSL_warn("Security Initialization: Can't find "
  877. "certificate (%s) for family %s ("
  878. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  879. cert_name, *family,
  880. errorCode, slapd_pr_strerror(errorCode));
  881. }
  882. /* Step Five -- Get the private key from cert */
  883. if( cert != NULL )
  884. key = slapd_pk11_findKeyByAnyCert(cert, NULL);
  885. if (key == NULL) {
  886. errorCode = PR_GetError();
  887. slapd_SSL_warn("Security Initialization: Unable to retrieve "
  888. "private key for cert %s of family %s ("
  889. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  890. cert_name, *family,
  891. errorCode, slapd_pr_strerror(errorCode));
  892. slapi_ch_free((void **) &personality);
  893. CERT_DestroyCertificate(cert);
  894. cert = NULL;
  895. freeConfigEntry( &e );
  896. continue;
  897. }
  898. /* Step Six -- Configure Secure Server Mode */
  899. if(pr_sock) {
  900. SECCertificateUsage returnedUsages;
  901. if (config_get_validate_cert_switch() == SLAPD_VALIDATE_CERT_OFF) {
  902. /* If we're set to ignore certificate verification issues,
  903. * just skip performing verification. */
  904. rv = SECSuccess;
  905. } else {
  906. /* Check if the certificate is valid. */
  907. rv = CERT_VerifyCertificateNow(
  908. CERT_GetDefaultCertDB(), cert, PR_TRUE,
  909. certificateUsageSSLServer,
  910. SSL_RevealPinArg(pr_sock),
  911. &returnedUsages);
  912. if (rv != SECSuccess) {
  913. /* Log warning */
  914. errorCode = PR_GetError();
  915. slapd_SSL_warn("CERT_VerifyCertificateNow: "
  916. "verify certificate failed "
  917. "for cert %s of family %s ("
  918. SLAPI_COMPONENT_NAME_NSPR
  919. " error %d - %s)",
  920. cert_name, *family, errorCode,
  921. slapd_pr_strerror(errorCode));
  922. /* If we're set to only warn, go ahead and
  923. * override rv to allow us to start up. */
  924. if (config_get_validate_cert_switch() == SLAPD_VALIDATE_CERT_WARN) {
  925. rv = SECSuccess;
  926. }
  927. }
  928. }
  929. if (SECSuccess == rv) {
  930. if( slapd_pk11_fortezzaHasKEA(cert) == PR_TRUE ) {
  931. rv = SSL_ConfigSecureServer(*fd, cert, key, kt_fortezza);
  932. }
  933. else {
  934. rv = SSL_ConfigSecureServer(*fd, cert, key, kt_rsa);
  935. }
  936. if (SECSuccess != rv) {
  937. errorCode = PR_GetError();
  938. slapd_SSL_warn("ConfigSecureServer: "
  939. "Server key/certificate is "
  940. "bad for cert %s of family %s ("
  941. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  942. cert_name, *family, errorCode,
  943. slapd_pr_strerror(errorCode));
  944. }
  945. }
  946. }
  947. if (cert) {
  948. CERT_DestroyCertificate(cert);
  949. cert = NULL;
  950. }
  951. if (key) {
  952. slapd_pk11_DestroyPrivateKey(key);
  953. key = NULL;
  954. }
  955. slapi_ch_free((void **) &personality);
  956. if (SECSuccess != rv) {
  957. freeConfigEntry( &e );
  958. continue;
  959. }
  960. nFamilies++;
  961. freeConfigEntry( &e );
  962. }
  963. freeChildren( family_list );
  964. }
  965. if ( !nFamilies ) {
  966. slapd_SSL_error("None of the cipher are valid");
  967. return -1;
  968. }
  969. /* Step Seven -- Configure Server Session ID Cache */
  970. tmpDir = slapd_get_tmp_dir();
  971. slapi_log_error(SLAPI_LOG_TRACE,
  972. "slapd_ssl_init2", "tmp dir = %s\n", tmpDir);
  973. rv = SSL_ConfigServerSessionIDCache(0, stimeout, stimeout, tmpDir);
  974. slapi_ch_free_string(&tmpDir);
  975. if (rv) {
  976. errorCode = PR_GetError();
  977. if (errorCode == ENOSPC) {
  978. slapd_SSL_error("Config of server nonce cache failed, "
  979. "out of disk space! Make more room in /tmp "
  980. "and try again. (" SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  981. errorCode, slapd_pr_strerror(errorCode));
  982. }
  983. else {
  984. slapd_SSL_error("Config of server nonce cache failed (error %d - %s)",
  985. errorCode, slapd_pr_strerror(errorCode));
  986. }
  987. return rv;
  988. }
  989. sslStatus = SSL_OptionSet(pr_sock, SSL_SECURITY, PR_TRUE);
  990. if (sslStatus != SECSuccess) {
  991. errorCode = PR_GetError();
  992. slapd_SSL_warn("Security Initialization: Failed to enable security "
  993. "on the imported socket (" SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  994. errorCode, slapd_pr_strerror(errorCode));
  995. return -1;
  996. }
  997. /* Explicitly disabling SSL2 - NGK */
  998. sslStatus = SSL_OptionSet(pr_sock, SSL_ENABLE_SSL2, enableSSL2);
  999. if (sslStatus != SECSuccess) {
  1000. errorCode = PR_GetError();
  1001. slapd_SSL_warn("Security Initialization: Failed to %s SSLv2 "
  1002. "on the imported socket (" SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  1003. enableSSL2 ? "enable" : "disable",
  1004. errorCode, slapd_pr_strerror(errorCode));
  1005. return -1;
  1006. }
  1007. /* Retrieve the SSL Client Authentication status from cn=config */
  1008. /* Set a default value if no value found */
  1009. getConfigEntry( configDN, &e );
  1010. val = NULL;
  1011. if ( e != NULL ) {
  1012. val = slapi_entry_attr_get_charptr( e, "nssslclientauth" );
  1013. }
  1014. if( !val ) {
  1015. errorCode = PR_GetError();
  1016. slapd_SSL_warn("Security Initialization: Cannot get SSL Client "
  1017. "Authentication status. No nsslclientauth in %s ("
  1018. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  1019. configDN, errorCode, slapd_pr_strerror(errorCode));
  1020. switch( SLAPD_SSLCLIENTAUTH_DEFAULT ) {
  1021. case SLAPD_SSLCLIENTAUTH_OFF:
  1022. default_val = "off";
  1023. break;
  1024. case SLAPD_SSLCLIENTAUTH_ALLOWED:
  1025. default_val = "allowed";
  1026. break;
  1027. case SLAPD_SSLCLIENTAUTH_REQUIRED:
  1028. default_val = "required";
  1029. break;
  1030. default:
  1031. default_val = "allowed";
  1032. break;
  1033. }
  1034. val = default_val;
  1035. }
  1036. if( config_set_SSLclientAuth( "nssslclientauth", val, errorbuf,
  1037. CONFIG_APPLY ) != LDAP_SUCCESS ) {
  1038. errorCode = PR_GetError();
  1039. slapd_SSL_warn("Security Initialization: Cannot set SSL Client "
  1040. "Authentication status to \"%s\", error (%s). "
  1041. "Supported values are \"off\", \"allowed\" "
  1042. "and \"required\". (" SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  1043. val, errorbuf, errorCode, slapd_pr_strerror(errorCode));
  1044. }
  1045. if (val != default_val) {
  1046. slapi_ch_free_string(&val);
  1047. }
  1048. if ( e != NULL ) {
  1049. val = slapi_entry_attr_get_charptr( e, "nsSSL3" );
  1050. if ( val ) {
  1051. if ( !strcasecmp( val, "off" ) ) {
  1052. enableSSL3 = PR_FALSE;
  1053. } else if ( !strcasecmp( val, "on" ) ) {
  1054. enableSSL3 = PR_TRUE;
  1055. } else {
  1056. enableSSL3 = slapi_entry_attr_get_bool( e, "nsSSL3" );
  1057. }
  1058. if ( fipsMode && enableSSL3 ) {
  1059. slapd_SSL_warn("Security Initialization: FIPS mode is enabled and "
  1060. "nsSSL3 explicitly set to on - SSLv3 is not approved "
  1061. "for use in FIPS mode - SSLv3 will be disabled - if "
  1062. "you want to use SSLv3, you must use modutil to "
  1063. "disable FIPS in the internal token.");
  1064. enableSSL3 = PR_FALSE;
  1065. }
  1066. }
  1067. slapi_ch_free_string( &val );
  1068. val = slapi_entry_attr_get_charptr( e, "nsTLS1" );
  1069. if ( val ) {
  1070. if ( !strcasecmp( val, "off" ) ) {
  1071. enableTLS1 = PR_FALSE;
  1072. } else if ( !strcasecmp( val, "on" ) ) {
  1073. enableTLS1 = PR_TRUE;
  1074. } else {
  1075. enableTLS1 = slapi_entry_attr_get_bool( e, "nsTLS1" );
  1076. }
  1077. }
  1078. slapi_ch_free_string( &val );
  1079. }
  1080. sslStatus = SSL_OptionSet(pr_sock, SSL_ENABLE_SSL3, enableSSL3);
  1081. if (sslStatus != SECSuccess) {
  1082. errorCode = PR_GetError();
  1083. slapd_SSL_warn("Security Initialization: Failed to %s SSLv3 "
  1084. "on the imported socket (" SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  1085. enableSSL3 ? "enable" : "disable",
  1086. errorCode, slapd_pr_strerror(errorCode));
  1087. }
  1088. sslStatus = SSL_OptionSet(pr_sock, SSL_ENABLE_TLS, enableTLS1);
  1089. if (sslStatus != SECSuccess) {
  1090. errorCode = PR_GetError();
  1091. slapd_SSL_warn("Security Initialization: Failed to %s TLSv1 "
  1092. "on the imported socket (" SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  1093. enableTLS1 ? "enable" : "disable",
  1094. errorCode, slapd_pr_strerror(errorCode));
  1095. }
  1096. freeConfigEntry( &e );
  1097. if(( slapd_SSLclientAuth = config_get_SSLclientAuth()) != SLAPD_SSLCLIENTAUTH_OFF ) {
  1098. int err;
  1099. switch (slapd_SSLclientAuth) {
  1100. case SLAPD_SSLCLIENTAUTH_ALLOWED:
  1101. #ifdef SSL_REQUIRE_CERTIFICATE /* new feature */
  1102. if ((err = SSL_OptionSet (pr_sock, SSL_REQUIRE_CERTIFICATE, PR_FALSE)) < 0) {
  1103. PRErrorCode prerr = PR_GetError();
  1104. LDAPDebug (LDAP_DEBUG_ANY,
  1105. "SSL_OptionSet(SSL_REQUIRE_CERTIFICATE,PR_FALSE) %d "
  1106. SLAPI_COMPONENT_NAME_NSPR " error %d (%s)\n",
  1107. err, prerr, slapd_pr_strerror(prerr));
  1108. }
  1109. #endif
  1110. /* Give the client a clear opportunity to send her certificate: */
  1111. case SLAPD_SSLCLIENTAUTH_REQUIRED:
  1112. if ((err = SSL_OptionSet (pr_sock, SSL_REQUEST_CERTIFICATE, PR_TRUE)) < 0) {
  1113. PRErrorCode prerr = PR_GetError();
  1114. LDAPDebug (LDAP_DEBUG_ANY,
  1115. "SSL_OptionSet(SSL_REQUEST_CERTIFICATE,PR_TRUE) %d "
  1116. SLAPI_COMPONENT_NAME_NSPR " error %d (%s)\n",
  1117. err, prerr, slapd_pr_strerror(prerr));
  1118. }
  1119. default: break;
  1120. }
  1121. }
  1122. /* Introduce a way of knowing whether slapd_ssl_init2 has
  1123. * already been executed.
  1124. * The cases in which slapd_ssl_init2 is executed during an
  1125. * Start TLS operation are not taken into account, for it is
  1126. * the fact of being executed by the server's SSL listener socket
  1127. * that matters. */
  1128. if (!startTLS)
  1129. _ssl_listener_initialized = 1; /* --ugaston */
  1130. return 0;
  1131. }
  1132. /* richm 20020227
  1133. To do LDAP client SSL init, we need to do
  1134. static void
  1135. ldapssl_basic_init( void )
  1136. {
  1137. PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
  1138. PR_SetConcurrency( 4 );
  1139. }
  1140. NSS_Init(certdbpath);
  1141. SSL_OptionSetDefault(SSL_ENABLE_SSL2, PR_FALSE);
  1142. SSL_OptionSetDefault(SSL_ENABLE_SSL3, PR_TRUE);
  1143. s = NSS_SetDomesticPolicy();
  1144. We already do pr_init, we don't need pr_setconcurrency, we already do nss_init and the rest
  1145. */
  1146. int
  1147. slapd_SSL_client_auth (LDAP* ld)
  1148. {
  1149. int rc = 0;
  1150. PRErrorCode errorCode;
  1151. char* pw = NULL;
  1152. char ** family_list;
  1153. Slapi_Entry *entry = NULL;
  1154. char cert_name[1024];
  1155. char *token = NULL;
  1156. #ifndef _WIN32
  1157. SVRCOREStdPinObj *StdPinObj;
  1158. #else
  1159. SVRCOREAltPinObj *AltPinObj;
  1160. #endif
  1161. SVRCOREError err = SVRCORE_Success;
  1162. if((family_list = getChildren(configDN))) {
  1163. char **family;
  1164. char *personality = NULL;
  1165. char *activation = NULL;
  1166. char *cipher = NULL;
  1167. for (family = family_list; *family; family++) {
  1168. getConfigEntry( *family, &entry );
  1169. if ( entry == NULL ) {
  1170. continue;
  1171. }
  1172. activation = slapi_entry_attr_get_charptr( entry, "nssslactivation" );
  1173. if((!activation) || (!strcasecmp(activation, "off"))) {
  1174. /* this family was turned off, goto next */
  1175. slapi_ch_free((void **) &activation);
  1176. freeConfigEntry( &entry );
  1177. continue;
  1178. }
  1179. slapi_ch_free((void **) &activation);
  1180. personality = slapi_entry_attr_get_charptr( entry, "nssslpersonalityssl" );
  1181. cipher = slapi_entry_attr_get_charptr( entry, "cn" );
  1182. if ( cipher && !strcasecmp(cipher, "RSA" )) {
  1183. char *ssltoken;
  1184. /* If there already is a token name, use it */
  1185. if (token) {
  1186. slapi_ch_free((void **) &personality);
  1187. slapi_ch_free((void **) &cipher);
  1188. freeConfigEntry( &entry );
  1189. continue;
  1190. }
  1191. ssltoken = slapi_entry_attr_get_charptr( entry, "nsssltoken" );
  1192. if( ssltoken && personality ) {
  1193. if( !strcasecmp(ssltoken, "internal") ||
  1194. !strcasecmp(ssltoken, "internal (software)") ) {
  1195. /* Translate config internal name to more
  1196. * readable form. Certificate name is just
  1197. * the personality for internal tokens.
  1198. */
  1199. token = slapi_ch_strdup(internalTokenName);
  1200. #if defined(USE_OPENLDAP)
  1201. /* openldap needs tokenname:certnick */
  1202. PR_snprintf(cert_name, sizeof(cert_name), "%s:%s", token, personality);
  1203. #else
  1204. PL_strncpyz(cert_name, personality, sizeof(cert_name));
  1205. #endif
  1206. slapi_ch_free((void **) &ssltoken);
  1207. } else {
  1208. /* external PKCS #11 token - attach token name */
  1209. /*ssltoken was already dupped and we don't need it anymore*/
  1210. token = ssltoken;
  1211. PR_snprintf(cert_name, sizeof(cert_name), "%s:%s", token, personality);
  1212. }
  1213. } else {
  1214. errorCode = PR_GetError();
  1215. slapd_SSL_warn("Security Initialization: Failed to get cipher "
  1216. "family information. Missing nsssltoken or"
  1217. "nssslpersonalityssl in %s ("
  1218. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  1219. *family, errorCode, slapd_pr_strerror(errorCode));
  1220. slapi_ch_free((void **) &ssltoken);
  1221. slapi_ch_free((void **) &personality);
  1222. slapi_ch_free((void **) &cipher);
  1223. freeConfigEntry( &entry );
  1224. continue;
  1225. }
  1226. } else { /* external PKCS #11 cipher */
  1227. char *ssltoken;
  1228. ssltoken = slapi_entry_attr_get_charptr( entry, "nsssltoken" );
  1229. if( token && personality ) {
  1230. /* free the old token and remember the new one */
  1231. if (token) slapi_ch_free((void **)&token);
  1232. token = ssltoken; /*ssltoken was already dupped and we don't need it anymore*/
  1233. /* external PKCS #11 token - attach token name */
  1234. PR_snprintf(cert_name, sizeof(cert_name), "%s:%s", token, personality);
  1235. } else {
  1236. errorCode = PR_GetError();
  1237. slapd_SSL_warn("Security Initialization: Failed to get cipher "
  1238. "family information. Missing nsssltoken or"
  1239. "nssslpersonalityssl in %s ("
  1240. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  1241. *family, errorCode, slapd_pr_strerror(errorCode));
  1242. slapi_ch_free((void **) &ssltoken);
  1243. slapi_ch_free((void **) &personality);
  1244. slapi_ch_free((void **) &cipher);
  1245. freeConfigEntry( &entry );
  1246. continue;
  1247. }
  1248. }
  1249. slapi_ch_free((void **) &personality);
  1250. slapi_ch_free((void **) &cipher);
  1251. freeConfigEntry( &entry );
  1252. } /* end of for */
  1253. freeChildren( family_list );
  1254. }
  1255. /* Free config data */
  1256. if (!svrcore_setup()) {
  1257. #ifndef _WIN32
  1258. StdPinObj = (SVRCOREStdPinObj *)SVRCORE_GetRegisteredPinObj();
  1259. err = SVRCORE_StdPinGetPin( &pw, StdPinObj, token );
  1260. #else
  1261. AltPinObj = (SVRCOREAltPinObj *)SVRCORE_GetRegisteredPinObj();
  1262. pw = SVRCORE_GetPin( (SVRCOREPinObj *)AltPinObj, token, PR_FALSE);
  1263. #endif
  1264. if ( err != SVRCORE_Success || pw == NULL) {
  1265. errorCode = PR_GetError();
  1266. slapd_SSL_warn("SSL client authentication cannot be used "
  1267. "(no password). (" SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  1268. errorCode, slapd_pr_strerror(errorCode));
  1269. } else {
  1270. #if defined(USE_OPENLDAP)
  1271. rc = ldap_set_option(ld, LDAP_OPT_X_TLS_KEYFILE, SERVER_KEY_NAME);
  1272. if (rc) {
  1273. slapd_SSL_warn("SSL client authentication cannot be used "
  1274. "unable to set the key to use to %s", SERVER_KEY_NAME);
  1275. }
  1276. rc = ldap_set_option(ld, LDAP_OPT_X_TLS_CERTFILE, cert_name);
  1277. if (rc) {
  1278. slapd_SSL_warn("SSL client authentication cannot be used "
  1279. "unable to set the cert to use to %s", cert_name);
  1280. }
  1281. /* not sure what else needs to be done for client auth - don't
  1282. currently have a way to pass in the password to use to unlock
  1283. the keydb - nor a way to disable caching */
  1284. #else /* !USE_OPENLDAP */
  1285. rc = ldapssl_enable_clientauth (ld, SERVER_KEY_NAME, pw, cert_name);
  1286. if (rc != 0) {
  1287. errorCode = PR_GetError();
  1288. slapd_SSL_warn("ldapssl_enable_clientauth(%s, %s) %i ("
  1289. SLAPI_COMPONENT_NAME_NSPR " error %d - %s)",
  1290. SERVER_KEY_NAME, cert_name, rc,
  1291. errorCode, slapd_pr_strerror(errorCode));
  1292. } else {
  1293. /* We cannot allow NSS to cache outgoing client auth connections -
  1294. each client auth connection must have it's own non-shared SSL
  1295. connection to the peer so that it will go through the
  1296. entire handshake protocol every time including the use of its
  1297. own unique client cert - see bug 605457
  1298. */
  1299. ldapssl_set_option(ld, SSL_NO_CACHE, PR_TRUE);
  1300. }
  1301. #endif
  1302. }
  1303. }
  1304. if (token) slapi_ch_free((void**)&token);
  1305. slapi_ch_free((void**)&pw);
  1306. LDAPDebug (LDAP_DEBUG_TRACE, "slapd_SSL_client_auth() %i\n", rc, 0, 0);
  1307. return rc;
  1308. }
  1309. /* Function for keeping track of the SSL initialization status:
  1310. * - returns 1: when slapd_ssl_init has been executed
  1311. */
  1312. int
  1313. slapd_security_library_is_initialized()
  1314. {
  1315. return _security_library_initialized;
  1316. }
  1317. /* Function for keeping track of the SSL listener socket initialization status:
  1318. * - returns 1: when slapd_ssl_init2 has been executed
  1319. */
  1320. int
  1321. slapd_ssl_listener_is_initialized()
  1322. {
  1323. return _ssl_listener_initialized;
  1324. }
  1325. int
  1326. slapd_nss_is_initialized()
  1327. {
  1328. return _nss_initialized;
  1329. }
  1330. /* memory to store tmpdir is allocated and returned; caller should free it. */
  1331. char* slapd_get_tmp_dir()
  1332. {
  1333. static char tmp[MAXPATHLEN];
  1334. char* tmpdir = NULL;;
  1335. #if defined( XP_WIN32 )
  1336. unsigned ilen;
  1337. char pch;
  1338. #endif
  1339. tmp[0] = '\0';
  1340. if((tmpdir = config_get_tmpdir()) == NULL)
  1341. {
  1342. slapi_log_error(
  1343. SLAPI_LOG_FATAL,
  1344. "slapd_get_tmp_dir",
  1345. "config_get_tmpdir returns NULL Setting tmp dir to default\n");
  1346. #if defined( XP_WIN32 )
  1347. ilen = sizeof(tmp);
  1348. GetTempPath( ilen, tmp );
  1349. tmp[ilen-1] = (char)0;
  1350. ilen = strlen(tmp);
  1351. /* Remove trailing slash. */
  1352. pch = tmp[ilen-1];
  1353. if( pch == '\\' || pch == '/' )
  1354. tmp[ilen-1] = '\0';
  1355. #else
  1356. strcpy(tmp, "/tmp");
  1357. #endif
  1358. return slapi_ch_strdup(tmp);
  1359. }
  1360. #if defined( XP_WIN32 )
  1361. {
  1362. char *ptr = NULL;
  1363. char *endptr = tmpdir + strlen(tmpdir);
  1364. for(ptr = tmpdir; ptr < endptr; ptr++)
  1365. {
  1366. if('/' == *ptr)
  1367. *ptr = '\\';
  1368. }
  1369. }
  1370. #endif
  1371. #if defined( XP_WIN32 )
  1372. if(CreateDirectory(tmpdir, NULL) == 0)
  1373. {
  1374. slapi_log_error(
  1375. SLAPI_LOG_FATAL,
  1376. "slapd_get_tmp_dir",
  1377. "CreateDirectory(%s, NULL) Error: %s\n",
  1378. tmpdir, strerror(errno));
  1379. }
  1380. #else
  1381. if(mkdir(tmpdir, 00770) == -1)
  1382. {
  1383. if (errno == EEXIST) {
  1384. slapi_log_error(
  1385. SLAPI_LOG_TRACE,
  1386. "slapd_get_tmp_dir",
  1387. "mkdir(%s, 00770) - already exists\n",
  1388. tmpdir);
  1389. } else {
  1390. slapi_log_error(
  1391. SLAPI_LOG_FATAL,
  1392. "slapd_get_tmp_dir",
  1393. "mkdir(%s, 00770) Error: %s\n",
  1394. tmpdir, strerror(errno));
  1395. }
  1396. }
  1397. #endif
  1398. return ( tmpdir );
  1399. }
  1400. SECKEYPrivateKey *
  1401. slapd_get_unlocked_key_for_cert(CERTCertificate *cert, void *pin_arg)
  1402. {
  1403. SECKEYPrivateKey *key = NULL;
  1404. PK11SlotListElement *sle;
  1405. PK11SlotList *slotlist = PK11_GetAllSlotsForCert(cert, NULL);
  1406. const char *certsubject = cert->subjectName ? cert->subjectName : "unknown cert";
  1407. if (!slotlist) {
  1408. PRErrorCode errcode = PR_GetError();
  1409. slapi_log_error(SLAPI_LOG_FATAL, "slapd_get_unlocked_key_for_cert",
  1410. "Error: cannot get slot list for certificate [%s] (%d: %s)\n",
  1411. certsubject, errcode, slapd_pr_strerror(errcode));
  1412. return key;
  1413. }
  1414. for (sle = slotlist->head; sle; sle = sle->next) {
  1415. PK11SlotInfo *slot = sle->slot;
  1416. const char *slotname = (slot && PK11_GetSlotName(slot)) ? PK11_GetSlotName(slot) : "unknown slot";
  1417. const char *tokenname = (slot && PK11_GetTokenName(slot)) ? PK11_GetTokenName(slot) : "unknown token";
  1418. if (!slot) {
  1419. slapi_log_error(SLAPI_LOG_TRACE, "slapd_get_unlocked_key_for_cert",
  1420. "Missing slot for slot list element for certificate [%s]\n",
  1421. certsubject);
  1422. } else if (PK11_IsLoggedIn(slot, pin_arg)) {
  1423. key = PK11_FindKeyByDERCert(slot, cert, pin_arg);
  1424. slapi_log_error(SLAPI_LOG_TRACE, "slapd_get_unlocked_key_for_cert",
  1425. "Found unlocked slot [%s] token [%s] for certificate [%s]\n",
  1426. slotname, tokenname, certsubject);
  1427. break;
  1428. } else {
  1429. slapi_log_error(SLAPI_LOG_TRACE, "slapd_get_unlocked_key_for_cert",
  1430. "Skipping locked slot [%s] token [%s] for certificate [%s]\n",
  1431. slotname, tokenname, certsubject);
  1432. }
  1433. }
  1434. if (!key) {
  1435. slapi_log_error(SLAPI_LOG_FATAL, "slapd_get_unlocked_key_for_cert",
  1436. "Error: could not find any unlocked slots for certificate [%s]. "
  1437. "Please review your TLS/SSL configuration. The following slots were found:\n",
  1438. certsubject);
  1439. for (sle = slotlist->head; sle; sle = sle->next) {
  1440. PK11SlotInfo *slot = sle->slot;
  1441. const char *slotname = (slot && PK11_GetSlotName(slot)) ? PK11_GetSlotName(slot) : "unknown slot";
  1442. const char *tokenname = (slot && PK11_GetTokenName(slot)) ? PK11_GetTokenName(slot) : "unknown token";
  1443. slapi_log_error(SLAPI_LOG_FATAL, "slapd_get_unlocked_key_for_cert",
  1444. "Slot [%s] token [%s] was locked.\n",
  1445. slotname, tokenname);
  1446. }
  1447. }
  1448. PK11_FreeSlotList(slotlist);
  1449. return key;
  1450. }