totemcrypto.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. * Copyright (c) 2006-2012 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@redhat.com)
  7. * Christine Caulfield (ccaulfie@redhat.com)
  8. * Jan Friesse (jfriesse@redhat.com)
  9. *
  10. * This software licensed under BSD license, the text of which follows:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * - Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  21. * contributors may be used to endorse or promote products derived from this
  22. * software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  34. * THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include <config.h>
  37. #include <assert.h>
  38. #include <pthread.h>
  39. #include <sys/mman.h>
  40. #include <sys/types.h>
  41. #include <sys/stat.h>
  42. #include <sys/socket.h>
  43. #include <netdb.h>
  44. #include <sys/un.h>
  45. #include <sys/ioctl.h>
  46. #include <sys/param.h>
  47. #include <netinet/in.h>
  48. #include <arpa/inet.h>
  49. #include <unistd.h>
  50. #include <fcntl.h>
  51. #include <stdlib.h>
  52. #include <stdio.h>
  53. #include <errno.h>
  54. #include <sched.h>
  55. #include <time.h>
  56. #include <sys/time.h>
  57. #include <sys/poll.h>
  58. #include <limits.h>
  59. #include <corosync/sq.h>
  60. #include <corosync/swab.h>
  61. #include <corosync/list.h>
  62. #include <qb/qbdefs.h>
  63. #include <qb/qbloop.h>
  64. #define LOGSYS_UTILS_ONLY 1
  65. #include <corosync/logsys.h>
  66. #include <corosync/totem/totem.h>
  67. #include "totemcrypto.h"
  68. #include "util.h"
  69. #include <nss.h>
  70. #include <pk11pub.h>
  71. #include <pkcs11.h>
  72. #include <prerror.h>
  73. #define CRYPTO_HMAC_HASH_SIZE 20
  74. #define SALT_SIZE 16
  75. struct crypto_security_header {
  76. unsigned char hash_digest[CRYPTO_HMAC_HASH_SIZE]; /* The hash *MUST* be first in the data structure */
  77. unsigned char salt[SALT_SIZE]; /* random number */
  78. char msg[0];
  79. } __attribute__((packed));
  80. struct crypto_instance {
  81. PK11SymKey *nss_sym_key;
  82. PK11SymKey *nss_sym_key_sign;
  83. unsigned char private_key[1024];
  84. unsigned int private_key_len;
  85. enum crypto_crypt_t crypto_cipher_type;
  86. enum crypto_hash_t crypto_hash_type;
  87. void (*log_printf_func) (
  88. int level,
  89. int subsys,
  90. const char *function,
  91. const char *file,
  92. int line,
  93. const char *format,
  94. ...)__attribute__((format(printf, 6, 7)));
  95. int log_level_security;
  96. int log_level_notice;
  97. int log_level_error;
  98. int log_subsys_id;
  99. };
  100. CK_MECHANISM_TYPE cipher_to_nss[] = {
  101. 0, /* CRYPTO_CIPHER_TYPE_NONE */
  102. CKM_AES_CBC_PAD /* CRYPTO_CIPHER_TYPE_AES256 */
  103. };
  104. size_t cipher_key_len[] = {
  105. 0, /* CRYPTO_CIPHER_TYPE_NONE */
  106. 32, /* CRYPTO_CIPHER_TYPE_AES256 */
  107. };
  108. CK_MECHANISM_TYPE hash_to_nss[] = {
  109. 0, /* CRYPTO_HASH_TYPE_NONE */
  110. CKM_SHA_1_HMAC /* CRYPTO_HASH_TYPE_SHA1 */
  111. };
  112. #define log_printf(level, format, args...) \
  113. do { \
  114. instance->log_printf_func ( \
  115. level, instance->log_subsys_id, \
  116. __FUNCTION__, __FILE__, __LINE__, \
  117. (const char *)format, ##args); \
  118. } while (0);
  119. #define LOGSYS_PERROR(err_num, level, fmt, args...) \
  120. do { \
  121. char _error_str[LOGSYS_MAX_PERROR_MSG_LEN]; \
  122. const char *_error_ptr = qb_strerror_r(err_num, _error_str, sizeof(_error_str)); \
  123. instance->totemudp_log_printf ( \
  124. level, instance->log_subsys_id, \
  125. __FUNCTION__, __FILE__, __LINE__, \
  126. fmt ": %s (%d)", ##args, _error_ptr, err_num); \
  127. } while(0)
  128. static int init_nss_crypto(struct crypto_instance *instance,
  129. const char *crypto_cipher_type,
  130. const char *crypto_hash_type)
  131. {
  132. PK11SlotInfo* crypt_slot = NULL;
  133. PK11SlotInfo* hash_slot = NULL;
  134. SECItem crypt_param;
  135. SECItem hash_param;
  136. if ((!cipher_to_nss[instance->crypto_cipher_type]) &&
  137. (!hash_to_nss[instance->crypto_hash_type])) {
  138. log_printf(instance->log_level_notice,
  139. "Initializing transmit/receive security: NONE");
  140. return 0;
  141. }
  142. log_printf(instance->log_level_notice,
  143. "Initializing transmit/receive security: NSS crypto: %s hash: %s",
  144. crypto_cipher_type, crypto_hash_type);
  145. if (NSS_NoDB_Init(".") != SECSuccess) {
  146. log_printf(instance->log_level_security, "NSS initialization failed (err %d)",
  147. PR_GetError());
  148. goto out;
  149. }
  150. if (cipher_to_nss[instance->crypto_cipher_type]) {
  151. crypt_param.type = siBuffer;
  152. crypt_param.data = instance->private_key;
  153. crypt_param.len = cipher_key_len[instance->crypto_cipher_type];
  154. crypt_slot = PK11_GetBestSlot(cipher_to_nss[instance->crypto_cipher_type], NULL);
  155. if (crypt_slot == NULL) {
  156. log_printf(instance->log_level_security, "Unable to find security slot (err %d)",
  157. PR_GetError());
  158. goto out;
  159. }
  160. instance->nss_sym_key = PK11_ImportSymKey(crypt_slot,
  161. cipher_to_nss[instance->crypto_cipher_type],
  162. PK11_OriginUnwrap, CKA_ENCRYPT|CKA_DECRYPT,
  163. &crypt_param, NULL);
  164. if (instance->nss_sym_key == NULL) {
  165. log_printf(instance->log_level_security, "Failure to import key into NSS (err %d)",
  166. PR_GetError());
  167. goto out;
  168. }
  169. }
  170. if (hash_to_nss[instance->crypto_hash_type]) {
  171. hash_param.type = siBuffer;
  172. hash_param.data = 0;
  173. hash_param.len = 0;
  174. hash_slot = PK11_GetBestSlot(hash_to_nss[instance->crypto_hash_type], NULL);
  175. if (hash_slot == NULL) {
  176. log_printf(instance->log_level_security, "Unable to find security slot (err %d)",
  177. PR_GetError());
  178. goto out;
  179. }
  180. instance->nss_sym_key_sign = PK11_ImportSymKey(hash_slot,
  181. hash_to_nss[instance->crypto_hash_type],
  182. PK11_OriginUnwrap, CKA_SIGN,
  183. &hash_param, NULL);
  184. if (instance->nss_sym_key_sign == NULL) {
  185. log_printf(instance->log_level_security, "Failure to import key into NSS (err %d)",
  186. PR_GetError());
  187. goto out;
  188. }
  189. }
  190. return 0;
  191. out:
  192. return -1;
  193. }
  194. static int encrypt_and_sign_nss (
  195. struct crypto_instance *instance,
  196. const unsigned char *buf_in,
  197. const size_t buf_in_len,
  198. unsigned char *buf_out,
  199. size_t *buf_out_len)
  200. {
  201. PK11Context* enc_context = NULL;
  202. SECItem crypt_param;
  203. SECItem hash_param;
  204. SECItem *nss_sec_param = NULL;
  205. struct crypto_security_header *header;
  206. unsigned char *outdata;
  207. int tmp1_outlen = 0;
  208. unsigned int tmp2_outlen = 0;
  209. outdata = buf_out + sizeof (struct crypto_security_header);
  210. header = (struct crypto_security_header *)buf_out;
  211. memset(header->salt, 0, SALT_SIZE);
  212. if (!cipher_to_nss[instance->crypto_cipher_type]) {
  213. memcpy(outdata, buf_in, buf_in_len);
  214. *buf_out_len = buf_in_len;
  215. goto only_hash;
  216. }
  217. if (PK11_GenerateRandom (header->salt, SALT_SIZE) != SECSuccess) {
  218. log_printf(instance->log_level_security,
  219. "Failure to generate a random number %d",
  220. PR_GetError());
  221. goto out;
  222. }
  223. crypt_param.type = siBuffer;
  224. crypt_param.data = header->salt;
  225. crypt_param.len = SALT_SIZE;
  226. nss_sec_param = PK11_ParamFromIV (cipher_to_nss[instance->crypto_cipher_type],
  227. &crypt_param);
  228. if (nss_sec_param == NULL) {
  229. log_printf(instance->log_level_security,
  230. "Failure to set up PKCS11 param (err %d)",
  231. PR_GetError());
  232. goto out;
  233. }
  234. /*
  235. * Create cipher context for encryption
  236. */
  237. enc_context = PK11_CreateContextBySymKey (cipher_to_nss[instance->crypto_cipher_type],
  238. CKA_ENCRYPT,
  239. instance->nss_sym_key,
  240. nss_sec_param);
  241. if (!enc_context) {
  242. log_printf(instance->log_level_security,
  243. "PK11_CreateContext failed (encrypt) crypt_type=%d (err %d)",
  244. (int)cipher_to_nss[instance->crypto_cipher_type],
  245. PR_GetError());
  246. goto out;
  247. }
  248. if (PK11_CipherOp(enc_context, outdata,
  249. &tmp1_outlen, FRAME_SIZE_MAX - sizeof(struct crypto_security_header),
  250. (unsigned char *)buf_in, buf_in_len) != SECSuccess) {
  251. log_printf(instance->log_level_security,
  252. "PK11_CipherOp failed (encrypt) crypt_type=%d (err %d)",
  253. (int)cipher_to_nss[instance->crypto_cipher_type],
  254. PR_GetError());
  255. goto out;
  256. }
  257. if (PK11_DigestFinal(enc_context, outdata + tmp1_outlen,
  258. &tmp2_outlen, FRAME_SIZE_MAX - tmp1_outlen) != SECSuccess) {
  259. log_printf(instance->log_level_security,
  260. "PK11_DigestFinal failed (encrypt) crypt_type=%d (err %d)",
  261. (int)cipher_to_nss[instance->crypto_cipher_type],
  262. PR_GetError());
  263. goto out;
  264. }
  265. PK11_DestroyContext(enc_context, PR_TRUE);
  266. *buf_out_len = tmp1_outlen + tmp2_outlen;
  267. only_hash:
  268. if (!hash_to_nss[instance->crypto_hash_type]) {
  269. goto no_hash;
  270. }
  271. /* Now do the digest */
  272. hash_param.type = siBuffer;
  273. hash_param.data = 0;
  274. hash_param.len = 0;
  275. enc_context = PK11_CreateContextBySymKey(hash_to_nss[instance->crypto_hash_type],
  276. CKA_SIGN,
  277. instance->nss_sym_key_sign,
  278. &hash_param);
  279. if (!enc_context) {
  280. log_printf(instance->log_level_security,
  281. "PK11_CreateContext failed (hash) hash_type=%d (err %d)",
  282. (int)hash_to_nss[instance->crypto_hash_type],
  283. PR_GetError());
  284. goto out;
  285. }
  286. if (PK11_DigestBegin(enc_context) != SECSuccess) {
  287. log_printf(instance->log_level_security,
  288. "PK11_DigestBegin failed (hash) hash_type=%d (err %d)",
  289. (int)hash_to_nss[instance->crypto_hash_type],
  290. PR_GetError());
  291. goto out;
  292. }
  293. if (PK11_DigestOp(enc_context,
  294. outdata - SALT_SIZE,
  295. *buf_out_len + SALT_SIZE) != SECSuccess) {
  296. log_printf(instance->log_level_security,
  297. "PK11_DigestOp failed (hash) hash_type=%d (err %d)",
  298. (int)hash_to_nss[instance->crypto_hash_type],
  299. PR_GetError());
  300. goto out;
  301. }
  302. if (PK11_DigestFinal(enc_context,
  303. header->hash_digest,
  304. &tmp2_outlen,
  305. sizeof(header->hash_digest)) != SECSuccess) {
  306. log_printf(instance->log_level_security,
  307. "PK11_DigestFinale failed (hash) hash_type=%d (err %d)",
  308. (int)hash_to_nss[instance->crypto_hash_type],
  309. PR_GetError());
  310. goto out;
  311. }
  312. PK11_DestroyContext(enc_context, PR_TRUE);
  313. no_hash:
  314. SECITEM_FreeItem(nss_sec_param, PR_TRUE);
  315. *buf_out_len = *buf_out_len + sizeof(struct crypto_security_header);
  316. return 0;
  317. out:
  318. if (enc_context) {
  319. PK11_DestroyContext(enc_context, PR_TRUE);
  320. }
  321. if (nss_sec_param) {
  322. SECITEM_FreeItem(nss_sec_param, PR_TRUE);
  323. }
  324. return -1;
  325. }
  326. static int authenticate_and_decrypt_nss (
  327. struct crypto_instance *instance,
  328. unsigned char *buf,
  329. int *buf_len)
  330. {
  331. PK11Context* enc_context = NULL;
  332. int tmp1_outlen = 0;
  333. unsigned int tmp2_outlen = 0;
  334. unsigned char outbuf[FRAME_SIZE_MAX];
  335. unsigned char digest[CRYPTO_HMAC_HASH_SIZE];
  336. unsigned char *outdata;
  337. int result_len;
  338. unsigned char *data;
  339. size_t datalen;
  340. struct crypto_security_header *header = (struct crypto_security_header *)buf;
  341. SECItem crypt_param;
  342. SECItem hash_param;
  343. datalen = *buf_len;
  344. data = buf + sizeof (struct crypto_security_header) - SALT_SIZE;
  345. datalen = datalen - sizeof (struct crypto_security_header) + SALT_SIZE;
  346. outdata = outbuf + sizeof (struct crypto_security_header);
  347. if (!hash_to_nss[instance->crypto_hash_type]) {
  348. goto only_decrypt;
  349. }
  350. hash_param.type = siBuffer;
  351. hash_param.data = 0;
  352. hash_param.len = 0;
  353. /* Check the digest */
  354. enc_context = PK11_CreateContextBySymKey (hash_to_nss[instance->crypto_hash_type],
  355. CKA_SIGN,
  356. instance->nss_sym_key_sign,
  357. &hash_param);
  358. if (!enc_context) {
  359. log_printf(instance->log_level_security,
  360. "PK11_CreateContext failed (check digest) err %d",
  361. PR_GetError());
  362. goto out;
  363. }
  364. if (PK11_DigestBegin(enc_context) != SECSuccess) {
  365. log_printf(instance->log_level_security,
  366. "PK11_DigestBegin failed (check digest) err %d",
  367. PR_GetError());
  368. goto out;
  369. }
  370. if (PK11_DigestOp(enc_context, data, datalen) != SECSuccess) {
  371. log_printf(instance->log_level_security,
  372. "PK11_DigestOp failed (check digest) err %d",
  373. PR_GetError());
  374. goto out;
  375. }
  376. if (PK11_DigestFinal(enc_context, digest,
  377. &tmp2_outlen, sizeof(digest)) != SECSuccess) {
  378. log_printf(instance->log_level_security,
  379. "PK11_DigestFinal failed (check digest) err %d",
  380. PR_GetError());
  381. goto out;
  382. }
  383. PK11_DestroyContext(enc_context, PR_TRUE);
  384. if (memcmp(digest, header->hash_digest, tmp2_outlen) != 0) {
  385. log_printf(instance->log_level_error, "Digest does not match");
  386. goto out;
  387. }
  388. only_decrypt:
  389. if (!cipher_to_nss[instance->crypto_cipher_type]) {
  390. memcpy(outbuf, buf + sizeof (struct crypto_security_header), *buf_len - sizeof (struct crypto_security_header));
  391. outdata = outbuf;
  392. result_len = *buf_len - sizeof (struct crypto_security_header);
  393. goto no_decrypt;
  394. }
  395. /*
  396. * Get rid of salt
  397. */
  398. data += SALT_SIZE;
  399. datalen -= SALT_SIZE;
  400. /* Create cipher context for decryption */
  401. crypt_param.type = siBuffer;
  402. crypt_param.data = header->salt;
  403. crypt_param.len = SALT_SIZE;
  404. enc_context = PK11_CreateContextBySymKey(cipher_to_nss[instance->crypto_cipher_type],
  405. CKA_DECRYPT,
  406. instance->nss_sym_key, &crypt_param);
  407. if (!enc_context) {
  408. log_printf(instance->log_level_security,
  409. "PK11_CreateContext (decrypt) failed (err %d)",
  410. PR_GetError());
  411. goto out;
  412. }
  413. if (PK11_CipherOp(enc_context, outdata, &tmp1_outlen,
  414. sizeof(outbuf) - sizeof (struct crypto_security_header),
  415. data, datalen) != SECSuccess) {
  416. log_printf(instance->log_level_security,
  417. "PK11_CipherOp (decrypt) failed (err %d)",
  418. PR_GetError());
  419. goto out;
  420. }
  421. if (PK11_DigestFinal(enc_context, outdata + tmp1_outlen, &tmp2_outlen,
  422. sizeof(outbuf) - tmp1_outlen) != SECSuccess) {
  423. log_printf(instance->log_level_security,
  424. "PK11_DigestFinal (decrypt) failed (err %d)",
  425. PR_GetError());
  426. goto out;
  427. }
  428. PK11_DestroyContext(enc_context, PR_TRUE);
  429. result_len = tmp1_outlen + tmp2_outlen + sizeof (struct crypto_security_header);
  430. no_decrypt:
  431. memset(buf, 0, *buf_len);
  432. memcpy(buf, outdata, result_len);
  433. *buf_len = result_len;
  434. return 0;
  435. out:
  436. if (enc_context) {
  437. PK11_DestroyContext(enc_context, PR_TRUE);
  438. }
  439. return -1;
  440. }
  441. size_t crypto_sec_header_size(
  442. const char *crypto_cipher_type,
  443. const char *crypto_hash_type)
  444. {
  445. /*
  446. * TODO: crypto_cipher_type determines the crypto BLOCK size
  447. * crypto_hash_type determines the HASH_SIZE
  448. */
  449. return sizeof(struct crypto_security_header);
  450. }
  451. int crypto_encrypt_and_sign (
  452. struct crypto_instance *instance,
  453. const unsigned char *buf_in,
  454. const size_t buf_in_len,
  455. unsigned char *buf_out,
  456. size_t *buf_out_len)
  457. {
  458. /*
  459. * if crypto is totally disabled, let's skip complex parsing
  460. */
  461. if ((!cipher_to_nss[instance->crypto_cipher_type]) &&
  462. (!hash_to_nss[instance->crypto_hash_type])) {
  463. memcpy(buf_out, buf_in, buf_in_len);
  464. *buf_out_len = buf_in_len;
  465. return 0;
  466. }
  467. return (encrypt_and_sign_nss(instance, buf_in, buf_in_len, buf_out, buf_out_len));
  468. }
  469. int crypto_authenticate_and_decrypt (struct crypto_instance *instance,
  470. unsigned char *buf,
  471. int *buf_len)
  472. {
  473. /*
  474. * if crypto is totally disabled, there is no work for us
  475. */
  476. if ((!cipher_to_nss[instance->crypto_cipher_type]) &&
  477. (!hash_to_nss[instance->crypto_hash_type])) {
  478. return 0;
  479. }
  480. return (authenticate_and_decrypt_nss(instance, buf, buf_len));
  481. }
  482. struct crypto_instance *crypto_init(
  483. const unsigned char *private_key,
  484. unsigned int private_key_len,
  485. const char *crypto_cipher_type,
  486. const char *crypto_hash_type,
  487. void (*log_printf_func) (
  488. int level,
  489. int subsys,
  490. const char *function,
  491. const char *file,
  492. int line,
  493. const char *format,
  494. ...)__attribute__((format(printf, 6, 7))),
  495. int log_level_security,
  496. int log_level_notice,
  497. int log_level_error,
  498. int log_subsys_id)
  499. {
  500. struct crypto_instance *instance;
  501. instance = malloc(sizeof(*instance));
  502. if (instance == NULL) {
  503. return (NULL);
  504. }
  505. memset(instance, 0, sizeof(struct crypto_instance));
  506. memcpy(instance->private_key, private_key, private_key_len);
  507. instance->private_key_len = private_key_len;
  508. if (strcmp(crypto_cipher_type, "none") == 0) {
  509. instance->crypto_cipher_type = CRYPTO_CIPHER_TYPE_NONE;
  510. } else if (strcmp(crypto_cipher_type, "aes256") == 0) {
  511. instance->crypto_cipher_type = CRYPTO_CIPHER_TYPE_AES256;
  512. }
  513. if (strcmp(crypto_hash_type, "none") == 0) {
  514. instance->crypto_hash_type = CRYPTO_HASH_TYPE_NONE;
  515. } else if (strcmp(crypto_hash_type, "sha1") == 0) {
  516. instance->crypto_hash_type = CRYPTO_HASH_TYPE_SHA1;
  517. }
  518. instance->log_printf_func = log_printf_func;
  519. instance->log_level_security = log_level_security;
  520. instance->log_level_notice = log_level_notice;
  521. instance->log_level_error = log_level_error;
  522. instance->log_subsys_id = log_subsys_id;
  523. if (init_nss_crypto(instance, crypto_cipher_type, crypto_hash_type) < 0) {
  524. free(instance);
  525. return(NULL);
  526. }
  527. return (instance);
  528. }