fipsinstall.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. /*
  2. * Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <openssl/evp.h>
  10. #include <openssl/err.h>
  11. #include <openssl/provider.h>
  12. #include <openssl/params.h>
  13. #include <openssl/fips_names.h>
  14. #include <openssl/core_names.h>
  15. #include <openssl/self_test.h>
  16. #include <openssl/fipskey.h>
  17. #include "apps.h"
  18. #include "progs.h"
  19. #define BUFSIZE 4096
  20. /* Configuration file values */
  21. #define VERSION_KEY "version"
  22. #define VERSION_VAL "1"
  23. #define INSTALL_STATUS_VAL "INSTALL_SELF_TEST_KATS_RUN"
  24. static OSSL_CALLBACK self_test_events;
  25. static char *self_test_corrupt_desc = NULL;
  26. static char *self_test_corrupt_type = NULL;
  27. static int self_test_log = 1;
  28. static int quiet = 0;
  29. typedef enum OPTION_choice {
  30. OPT_COMMON,
  31. OPT_IN, OPT_OUT, OPT_MODULE, OPT_PEDANTIC,
  32. OPT_PROV_NAME, OPT_SECTION_NAME, OPT_MAC_NAME, OPT_MACOPT, OPT_VERIFY,
  33. OPT_NO_LOG, OPT_CORRUPT_DESC, OPT_CORRUPT_TYPE, OPT_QUIET, OPT_CONFIG,
  34. OPT_NO_CONDITIONAL_ERRORS,
  35. OPT_NO_SECURITY_CHECKS,
  36. OPT_TLS_PRF_EMS_CHECK, OPT_NO_SHORT_MAC,
  37. OPT_DISALLOW_PKCS15_PADDING, OPT_RSA_PSS_SALTLEN_CHECK,
  38. OPT_DISALLOW_SIGNATURE_X931_PADDING,
  39. OPT_HMAC_KEY_CHECK, OPT_KMAC_KEY_CHECK,
  40. OPT_DISALLOW_DRGB_TRUNC_DIGEST,
  41. OPT_SIGNATURE_DIGEST_CHECK,
  42. OPT_HKDF_DIGEST_CHECK,
  43. OPT_TLS13_KDF_DIGEST_CHECK,
  44. OPT_TLS1_PRF_DIGEST_CHECK,
  45. OPT_SSHKDF_DIGEST_CHECK,
  46. OPT_SSKDF_DIGEST_CHECK,
  47. OPT_X963KDF_DIGEST_CHECK,
  48. OPT_DISALLOW_DSA_SIGN,
  49. OPT_DISALLOW_TDES_ENCRYPT,
  50. OPT_HKDF_KEY_CHECK,
  51. OPT_KBKDF_KEY_CHECK,
  52. OPT_TLS13_KDF_KEY_CHECK,
  53. OPT_TLS1_PRF_KEY_CHECK,
  54. OPT_SSHKDF_KEY_CHECK,
  55. OPT_SSKDF_KEY_CHECK,
  56. OPT_X963KDF_KEY_CHECK,
  57. OPT_X942KDF_KEY_CHECK,
  58. OPT_NO_PBKDF2_LOWER_BOUND_CHECK,
  59. OPT_ECDH_COFACTOR_CHECK,
  60. OPT_SELF_TEST_ONLOAD, OPT_SELF_TEST_ONINSTALL
  61. } OPTION_CHOICE;
  62. const OPTIONS fipsinstall_options[] = {
  63. OPT_SECTION("General"),
  64. {"help", OPT_HELP, '-', "Display this summary"},
  65. {"pedantic", OPT_PEDANTIC, '-', "Set options for strict FIPS compliance"},
  66. {"verify", OPT_VERIFY, '-',
  67. "Verify a config file instead of generating one"},
  68. {"module", OPT_MODULE, '<', "File name of the provider module"},
  69. {"provider_name", OPT_PROV_NAME, 's', "FIPS provider name"},
  70. {"section_name", OPT_SECTION_NAME, 's',
  71. "FIPS Provider config section name (optional)"},
  72. {"no_conditional_errors", OPT_NO_CONDITIONAL_ERRORS, '-',
  73. "Disable the ability of the fips module to enter an error state if"
  74. " any conditional self tests fail"},
  75. {"no_security_checks", OPT_NO_SECURITY_CHECKS, '-',
  76. "Disable the run-time FIPS security checks in the module"},
  77. {"self_test_onload", OPT_SELF_TEST_ONLOAD, '-',
  78. "Forces self tests to always run on module load"},
  79. {"self_test_oninstall", OPT_SELF_TEST_ONINSTALL, '-',
  80. "Forces self tests to run once on module installation"},
  81. {"ems_check", OPT_TLS_PRF_EMS_CHECK, '-',
  82. "Enable the run-time FIPS check for EMS during TLS1_PRF"},
  83. {"no_short_mac", OPT_NO_SHORT_MAC, '-', "Disallow short MAC output"},
  84. {"no_drbg_truncated_digests", OPT_DISALLOW_DRGB_TRUNC_DIGEST, '-',
  85. "Disallow truncated digests with Hash and HMAC DRBGs"},
  86. {"signature_digest_check", OPT_SIGNATURE_DIGEST_CHECK, '-',
  87. "Enable checking for approved digests for signatures"},
  88. {"hmac_key_check", OPT_HMAC_KEY_CHECK, '-', "Enable key check for HMAC"},
  89. {"kmac_key_check", OPT_KMAC_KEY_CHECK, '-', "Enable key check for KMAC"},
  90. {"hkdf_digest_check", OPT_HKDF_DIGEST_CHECK, '-',
  91. "Enable digest check for HKDF"},
  92. {"tls13_kdf_digest_check", OPT_TLS13_KDF_DIGEST_CHECK, '-',
  93. "Enable digest check for TLS13-KDF"},
  94. {"tls1_prf_digest_check", OPT_TLS1_PRF_DIGEST_CHECK, '-',
  95. "Enable digest check for TLS1-PRF"},
  96. {"sshkdf_digest_check", OPT_SSHKDF_DIGEST_CHECK, '-',
  97. "Enable digest check for SSHKDF"},
  98. {"sskdf_digest_check", OPT_SSKDF_DIGEST_CHECK, '-',
  99. "Enable digest check for SSKDF"},
  100. {"x963kdf_digest_check", OPT_X963KDF_DIGEST_CHECK, '-',
  101. "Enable digest check for X963KDF"},
  102. {"dsa_sign_disabled", OPT_DISALLOW_DSA_SIGN, '-',
  103. "Disallow DSA signing"},
  104. {"tdes_encrypt_disabled", OPT_DISALLOW_TDES_ENCRYPT, '-',
  105. "Disallow Triple-DES encryption"},
  106. {"rsa_pkcs15_padding_disabled", OPT_DISALLOW_PKCS15_PADDING, '-',
  107. "Disallow PKCS#1 version 1.5 padding for RSA encryption"},
  108. {"rsa_pss_saltlen_check", OPT_RSA_PSS_SALTLEN_CHECK, '-',
  109. "Enable salt length check for RSA-PSS signature operations"},
  110. {"rsa_sign_x931_disabled", OPT_DISALLOW_SIGNATURE_X931_PADDING, '-',
  111. "Disallow X931 Padding for RSA signing"},
  112. {"hkdf_key_check", OPT_HKDF_KEY_CHECK, '-',
  113. "Enable key check for HKDF"},
  114. {"kbkdf_key_check", OPT_KBKDF_KEY_CHECK, '-',
  115. "Enable key check for KBKDF"},
  116. {"tls13_kdf_key_check", OPT_TLS13_KDF_KEY_CHECK, '-',
  117. "Enable key check for TLS13-KDF"},
  118. {"tls1_prf_key_check", OPT_TLS1_PRF_KEY_CHECK, '-',
  119. "Enable key check for TLS1-PRF"},
  120. {"sshkdf_key_check", OPT_SSHKDF_KEY_CHECK, '-',
  121. "Enable key check for SSHKDF"},
  122. {"sskdf_key_check", OPT_SSKDF_KEY_CHECK, '-',
  123. "Enable key check for SSKDF"},
  124. {"x963kdf_key_check", OPT_X963KDF_KEY_CHECK, '-',
  125. "Enable key check for X963KDF"},
  126. {"x942kdf_key_check", OPT_X942KDF_KEY_CHECK, '-',
  127. "Enable key check for X942KDF"},
  128. {"no_pbkdf2_lower_bound_check", OPT_NO_PBKDF2_LOWER_BOUND_CHECK, '-',
  129. "Disable lower bound check for PBKDF2"},
  130. {"ecdh_cofactor_check", OPT_ECDH_COFACTOR_CHECK, '-',
  131. "Enable Cofactor check for ECDH"},
  132. OPT_SECTION("Input"),
  133. {"in", OPT_IN, '<', "Input config file, used when verifying"},
  134. OPT_SECTION("Output"),
  135. {"out", OPT_OUT, '>', "Output config file, used when generating"},
  136. {"mac_name", OPT_MAC_NAME, 's', "MAC name"},
  137. {"macopt", OPT_MACOPT, 's', "MAC algorithm parameters in n:v form."},
  138. {OPT_MORE_STR, 0, 0, "See 'PARAMETER NAMES' in the EVP_MAC_ docs"},
  139. {"noout", OPT_NO_LOG, '-', "Disable logging of self test events"},
  140. {"corrupt_desc", OPT_CORRUPT_DESC, 's', "Corrupt a self test by description"},
  141. {"corrupt_type", OPT_CORRUPT_TYPE, 's', "Corrupt a self test by type"},
  142. {"config", OPT_CONFIG, '<', "The parent config to verify"},
  143. {"quiet", OPT_QUIET, '-', "No messages, just exit status"},
  144. {NULL}
  145. };
  146. typedef struct {
  147. unsigned int self_test_onload : 1;
  148. unsigned int conditional_errors : 1;
  149. unsigned int security_checks : 1;
  150. unsigned int hmac_key_check : 1;
  151. unsigned int kmac_key_check : 1;
  152. unsigned int tls_prf_ems_check : 1;
  153. unsigned int no_short_mac : 1;
  154. unsigned int drgb_no_trunc_dgst : 1;
  155. unsigned int signature_digest_check : 1;
  156. unsigned int hkdf_digest_check : 1;
  157. unsigned int tls13_kdf_digest_check : 1;
  158. unsigned int tls1_prf_digest_check : 1;
  159. unsigned int sshkdf_digest_check : 1;
  160. unsigned int sskdf_digest_check : 1;
  161. unsigned int x963kdf_digest_check : 1;
  162. unsigned int dsa_sign_disabled : 1;
  163. unsigned int tdes_encrypt_disabled : 1;
  164. unsigned int rsa_pkcs15_padding_disabled : 1;
  165. unsigned int rsa_pss_saltlen_check : 1;
  166. unsigned int sign_x931_padding_disabled : 1;
  167. unsigned int hkdf_key_check : 1;
  168. unsigned int kbkdf_key_check : 1;
  169. unsigned int tls13_kdf_key_check : 1;
  170. unsigned int tls1_prf_key_check : 1;
  171. unsigned int sshkdf_key_check : 1;
  172. unsigned int sskdf_key_check : 1;
  173. unsigned int x963kdf_key_check : 1;
  174. unsigned int x942kdf_key_check : 1;
  175. unsigned int pbkdf2_lower_bound_check : 1;
  176. unsigned int ecdh_cofactor_check : 1;
  177. } FIPS_OPTS;
  178. /* Pedantic FIPS compliance */
  179. static const FIPS_OPTS pedantic_opts = {
  180. 1, /* self_test_onload */
  181. 1, /* conditional_errors */
  182. 1, /* security_checks */
  183. 1, /* hmac_key_check */
  184. 1, /* kmac_key_check */
  185. 1, /* tls_prf_ems_check */
  186. 1, /* no_short_mac */
  187. 1, /* drgb_no_trunc_dgst */
  188. 1, /* signature_digest_check */
  189. 1, /* hkdf_digest_check */
  190. 1, /* tls13_kdf_digest_check */
  191. 1, /* tls1_prf_digest_check */
  192. 1, /* sshkdf_digest_check */
  193. 1, /* sskdf_digest_check */
  194. 1, /* x963kdf_digest_check */
  195. 1, /* dsa_sign_disabled */
  196. 1, /* tdes_encrypt_disabled */
  197. 1, /* rsa_pkcs15_padding_disabled */
  198. 1, /* rsa_pss_saltlen_check */
  199. 1, /* sign_x931_padding_disabled */
  200. 1, /* hkdf_key_check */
  201. 1, /* kbkdf_key_check */
  202. 1, /* tls13_kdf_key_check */
  203. 1, /* tls1_prf_key_check */
  204. 1, /* sshkdf_key_check */
  205. 1, /* sskdf_key_check */
  206. 1, /* x963kdf_key_check */
  207. 1, /* x942kdf_key_check */
  208. 1, /* pbkdf2_lower_bound_check */
  209. 1, /* ecdh_cofactor_check */
  210. };
  211. /* Default FIPS settings for backward compatibility */
  212. static FIPS_OPTS fips_opts = {
  213. 1, /* self_test_onload */
  214. 1, /* conditional_errors */
  215. 1, /* security_checks */
  216. 0, /* hmac_key_check */
  217. 0, /* kmac_key_check */
  218. 0, /* tls_prf_ems_check */
  219. 0, /* no_short_mac */
  220. 0, /* drgb_no_trunc_dgst */
  221. 0, /* signature_digest_check */
  222. 0, /* hkdf_digest_check */
  223. 0, /* tls13_kdf_digest_check */
  224. 0, /* tls1_prf_digest_check */
  225. 0, /* sshkdf_digest_check */
  226. 0, /* sskdf_digest_check */
  227. 0, /* x963kdf_digest_check */
  228. 0, /* dsa_sign_disabled */
  229. 0, /* tdes_encrypt_disabled */
  230. 0, /* rsa_pkcs15_padding_disabled */
  231. 0, /* rsa_pss_saltlen_check */
  232. 0, /* sign_x931_padding_disabled */
  233. 0, /* hkdf_key_check */
  234. 0, /* kbkdf_key_check */
  235. 0, /* tls13_kdf_key_check */
  236. 0, /* tls1_prf_key_check */
  237. 0, /* sshkdf_key_check */
  238. 0, /* sskdf_key_check */
  239. 0, /* x963kdf_key_check */
  240. 0, /* x942kdf_key_check */
  241. 1, /* pbkdf2_lower_bound_check */
  242. 0, /* ecdh_cofactor_check */
  243. };
  244. static int check_non_pedantic_fips(int pedantic, const char *name)
  245. {
  246. if (pedantic) {
  247. BIO_printf(bio_err, "Cannot specify -%s after -pedantic\n", name);
  248. return 0;
  249. }
  250. return 1;
  251. }
  252. static int do_mac(EVP_MAC_CTX *ctx, unsigned char *tmp, BIO *in,
  253. unsigned char *out, size_t *out_len)
  254. {
  255. int ret = 0;
  256. int i;
  257. size_t outsz = *out_len;
  258. if (!EVP_MAC_init(ctx, NULL, 0, NULL))
  259. goto err;
  260. if (EVP_MAC_CTX_get_mac_size(ctx) > outsz)
  261. goto end;
  262. while ((i = BIO_read(in, (char *)tmp, BUFSIZE)) != 0) {
  263. if (i < 0 || !EVP_MAC_update(ctx, tmp, i))
  264. goto err;
  265. }
  266. end:
  267. if (!EVP_MAC_final(ctx, out, out_len, outsz))
  268. goto err;
  269. ret = 1;
  270. err:
  271. return ret;
  272. }
  273. static int load_fips_prov_and_run_self_test(const char *prov_name,
  274. int *is_fips_140_2_prov)
  275. {
  276. int ret = 0;
  277. OSSL_PROVIDER *prov = NULL;
  278. OSSL_PARAM params[4], *p = params;
  279. char *name = "", *vers = "", *build = "";
  280. prov = OSSL_PROVIDER_load(NULL, prov_name);
  281. if (prov == NULL) {
  282. BIO_printf(bio_err, "Failed to load FIPS module\n");
  283. goto end;
  284. }
  285. if (!quiet) {
  286. *p++ = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_NAME,
  287. &name, sizeof(name));
  288. *p++ = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_VERSION,
  289. &vers, sizeof(vers));
  290. *p++ = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_BUILDINFO,
  291. &build, sizeof(build));
  292. *p = OSSL_PARAM_construct_end();
  293. if (!OSSL_PROVIDER_get_params(prov, params)) {
  294. BIO_printf(bio_err, "Failed to query FIPS module parameters\n");
  295. goto end;
  296. }
  297. if (OSSL_PARAM_modified(params))
  298. BIO_printf(bio_err, "\t%-10s\t%s\n", "name:", name);
  299. if (OSSL_PARAM_modified(params + 1))
  300. BIO_printf(bio_err, "\t%-10s\t%s\n", "version:", vers);
  301. if (OSSL_PARAM_modified(params + 2))
  302. BIO_printf(bio_err, "\t%-10s\t%s\n", "build:", build);
  303. } else {
  304. *p++ = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_VERSION,
  305. &vers, sizeof(vers));
  306. *p = OSSL_PARAM_construct_end();
  307. if (!OSSL_PROVIDER_get_params(prov, params)) {
  308. BIO_printf(bio_err, "Failed to query FIPS module parameters\n");
  309. goto end;
  310. }
  311. }
  312. *is_fips_140_2_prov = (strncmp("3.0.", vers, 4) == 0);
  313. ret = 1;
  314. end:
  315. OSSL_PROVIDER_unload(prov);
  316. return ret;
  317. }
  318. static int print_mac(BIO *bio, const char *label, const unsigned char *mac,
  319. size_t len)
  320. {
  321. int ret;
  322. char *hexstr = NULL;
  323. hexstr = OPENSSL_buf2hexstr(mac, (long)len);
  324. if (hexstr == NULL)
  325. return 0;
  326. ret = BIO_printf(bio, "%s = %s\n", label, hexstr);
  327. OPENSSL_free(hexstr);
  328. return ret;
  329. }
  330. static int write_config_header(BIO *out, const char *prov_name,
  331. const char *section)
  332. {
  333. return BIO_printf(out, "openssl_conf = openssl_init\n\n")
  334. && BIO_printf(out, "[openssl_init]\n")
  335. && BIO_printf(out, "providers = provider_section\n\n")
  336. && BIO_printf(out, "[provider_section]\n")
  337. && BIO_printf(out, "%s = %s\n\n", prov_name, section);
  338. }
  339. /*
  340. * Outputs a fips related config file that contains entries for the fips
  341. * module checksum, installation indicator checksum and the options
  342. * conditional_errors and security_checks.
  343. *
  344. * Returns 1 if the config file is written otherwise it returns 0 on error.
  345. */
  346. static int write_config_fips_section(BIO *out, const char *section,
  347. unsigned char *module_mac,
  348. size_t module_mac_len,
  349. const FIPS_OPTS *opts,
  350. unsigned char *install_mac,
  351. size_t install_mac_len)
  352. {
  353. int ret = 0;
  354. if (BIO_printf(out, "[%s]\n", section) <= 0
  355. || BIO_printf(out, "activate = 1\n") <= 0
  356. || BIO_printf(out, "%s = %s\n", OSSL_PROV_FIPS_PARAM_INSTALL_VERSION,
  357. VERSION_VAL) <= 0
  358. || BIO_printf(out, "%s = %s\n", OSSL_PROV_FIPS_PARAM_CONDITIONAL_ERRORS,
  359. opts->conditional_errors ? "1" : "0") <= 0
  360. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_SECURITY_CHECKS,
  361. opts->security_checks ? "1" : "0") <= 0
  362. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_HMAC_KEY_CHECK,
  363. opts->hmac_key_check ? "1": "0") <= 0
  364. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_KMAC_KEY_CHECK,
  365. opts->kmac_key_check ? "1": "0") <= 0
  366. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_TLS1_PRF_EMS_CHECK,
  367. opts->tls_prf_ems_check ? "1" : "0") <= 0
  368. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_NO_SHORT_MAC,
  369. opts->no_short_mac ? "1" : "0") <= 0
  370. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_DRBG_TRUNC_DIGEST,
  371. opts->drgb_no_trunc_dgst ? "1" : "0") <= 0
  372. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_SIGNATURE_DIGEST_CHECK,
  373. opts->signature_digest_check ? "1" : "0") <= 0
  374. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_HKDF_DIGEST_CHECK,
  375. opts->hkdf_digest_check ? "1": "0") <= 0
  376. || BIO_printf(out, "%s = %s\n",
  377. OSSL_PROV_PARAM_TLS13_KDF_DIGEST_CHECK,
  378. opts->tls13_kdf_digest_check ? "1": "0") <= 0
  379. || BIO_printf(out, "%s = %s\n",
  380. OSSL_PROV_PARAM_TLS1_PRF_DIGEST_CHECK,
  381. opts->tls1_prf_digest_check ? "1": "0") <= 0
  382. || BIO_printf(out, "%s = %s\n",
  383. OSSL_PROV_PARAM_SSHKDF_DIGEST_CHECK,
  384. opts->sshkdf_digest_check ? "1": "0") <= 0
  385. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_SSKDF_DIGEST_CHECK,
  386. opts->sskdf_digest_check ? "1": "0") <= 0
  387. || BIO_printf(out, "%s = %s\n",
  388. OSSL_PROV_PARAM_X963KDF_DIGEST_CHECK,
  389. opts->x963kdf_digest_check ? "1": "0") <= 0
  390. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_DSA_SIGN_DISABLED,
  391. opts->dsa_sign_disabled ? "1" : "0") <= 0
  392. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_TDES_ENCRYPT_DISABLED,
  393. opts->tdes_encrypt_disabled ? "1" : "0") <= 0
  394. || BIO_printf(out, "%s = %s\n",
  395. OSSL_PROV_PARAM_RSA_PKCS15_PAD_DISABLED,
  396. opts->rsa_pkcs15_padding_disabled ? "1" : "0") <= 0
  397. || BIO_printf(out, "%s = %s\n",
  398. OSSL_PROV_PARAM_RSA_PSS_SALTLEN_CHECK,
  399. opts->rsa_pss_saltlen_check ? "1" : "0") <= 0
  400. || BIO_printf(out, "%s = %s\n",
  401. OSSL_PROV_PARAM_RSA_SIGN_X931_PAD_DISABLED,
  402. opts->sign_x931_padding_disabled ? "1" : "0") <= 0
  403. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_HKDF_KEY_CHECK,
  404. opts->hkdf_key_check ? "1": "0") <= 0
  405. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_KBKDF_KEY_CHECK,
  406. opts->kbkdf_key_check ? "1": "0") <= 0
  407. || BIO_printf(out, "%s = %s\n",
  408. OSSL_PROV_PARAM_TLS13_KDF_KEY_CHECK,
  409. opts->tls13_kdf_key_check ? "1": "0") <= 0
  410. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_TLS1_PRF_KEY_CHECK,
  411. opts->tls1_prf_key_check ? "1": "0") <= 0
  412. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_SSHKDF_KEY_CHECK,
  413. opts->sshkdf_key_check ? "1": "0") <= 0
  414. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_SSKDF_KEY_CHECK,
  415. opts->sskdf_key_check ? "1": "0") <= 0
  416. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_X963KDF_KEY_CHECK,
  417. opts->x963kdf_key_check ? "1": "0") <= 0
  418. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_X942KDF_KEY_CHECK,
  419. opts->x942kdf_key_check ? "1": "0") <= 0
  420. || BIO_printf(out, "%s = %s\n",
  421. OSSL_PROV_PARAM_PBKDF2_LOWER_BOUND_CHECK,
  422. opts->pbkdf2_lower_bound_check ? "1" : "0") <= 0
  423. || BIO_printf(out, "%s = %s\n", OSSL_PROV_PARAM_ECDH_COFACTOR_CHECK,
  424. opts->ecdh_cofactor_check ? "1": "0") <= 0
  425. || !print_mac(out, OSSL_PROV_FIPS_PARAM_MODULE_MAC, module_mac,
  426. module_mac_len))
  427. goto end;
  428. if (install_mac != NULL
  429. && install_mac_len > 0
  430. && opts->self_test_onload == 0) {
  431. if (!print_mac(out, OSSL_PROV_FIPS_PARAM_INSTALL_MAC, install_mac,
  432. install_mac_len)
  433. || BIO_printf(out, "%s = %s\n", OSSL_PROV_FIPS_PARAM_INSTALL_STATUS,
  434. INSTALL_STATUS_VAL) <= 0)
  435. goto end;
  436. }
  437. ret = 1;
  438. end:
  439. return ret;
  440. }
  441. static CONF *generate_config_and_load(const char *prov_name,
  442. const char *section,
  443. unsigned char *module_mac,
  444. size_t module_mac_len,
  445. const FIPS_OPTS *opts)
  446. {
  447. BIO *mem_bio = NULL;
  448. CONF *conf = NULL;
  449. mem_bio = BIO_new(BIO_s_mem());
  450. if (mem_bio == NULL)
  451. return 0;
  452. if (!write_config_header(mem_bio, prov_name, section)
  453. || !write_config_fips_section(mem_bio, section,
  454. module_mac, module_mac_len,
  455. opts, NULL, 0))
  456. goto end;
  457. conf = app_load_config_bio(mem_bio, NULL);
  458. if (conf == NULL)
  459. goto end;
  460. if (CONF_modules_load(conf, NULL, 0) <= 0)
  461. goto end;
  462. BIO_free(mem_bio);
  463. return conf;
  464. end:
  465. NCONF_free(conf);
  466. BIO_free(mem_bio);
  467. return NULL;
  468. }
  469. static void free_config_and_unload(CONF *conf)
  470. {
  471. if (conf != NULL) {
  472. NCONF_free(conf);
  473. CONF_modules_unload(1);
  474. }
  475. }
  476. static int verify_module_load(const char *parent_config_file)
  477. {
  478. return OSSL_LIB_CTX_load_config(NULL, parent_config_file);
  479. }
  480. /*
  481. * Returns 1 if the config file entries match the passed in module_mac and
  482. * install_mac values, otherwise it returns 0.
  483. */
  484. static int verify_config(const char *infile, const char *section,
  485. unsigned char *module_mac, size_t module_mac_len,
  486. unsigned char *install_mac, size_t install_mac_len)
  487. {
  488. int ret = 0;
  489. char *s = NULL;
  490. unsigned char *buf1 = NULL, *buf2 = NULL;
  491. long len;
  492. CONF *conf = NULL;
  493. /* read in the existing values and check they match the saved values */
  494. conf = app_load_config(infile);
  495. if (conf == NULL)
  496. goto end;
  497. s = NCONF_get_string(conf, section, OSSL_PROV_FIPS_PARAM_INSTALL_VERSION);
  498. if (s == NULL || strcmp(s, VERSION_VAL) != 0) {
  499. BIO_printf(bio_err, "version not found\n");
  500. goto end;
  501. }
  502. s = NCONF_get_string(conf, section, OSSL_PROV_FIPS_PARAM_MODULE_MAC);
  503. if (s == NULL) {
  504. BIO_printf(bio_err, "Module integrity MAC not found\n");
  505. goto end;
  506. }
  507. buf1 = OPENSSL_hexstr2buf(s, &len);
  508. if (buf1 == NULL
  509. || (size_t)len != module_mac_len
  510. || memcmp(module_mac, buf1, module_mac_len) != 0) {
  511. BIO_printf(bio_err, "Module integrity mismatch\n");
  512. goto end;
  513. }
  514. if (install_mac != NULL && install_mac_len > 0) {
  515. s = NCONF_get_string(conf, section, OSSL_PROV_FIPS_PARAM_INSTALL_STATUS);
  516. if (s == NULL || strcmp(s, INSTALL_STATUS_VAL) != 0) {
  517. BIO_printf(bio_err, "install status not found\n");
  518. goto end;
  519. }
  520. s = NCONF_get_string(conf, section, OSSL_PROV_FIPS_PARAM_INSTALL_MAC);
  521. if (s == NULL) {
  522. BIO_printf(bio_err, "Install indicator MAC not found\n");
  523. goto end;
  524. }
  525. buf2 = OPENSSL_hexstr2buf(s, &len);
  526. if (buf2 == NULL
  527. || (size_t)len != install_mac_len
  528. || memcmp(install_mac, buf2, install_mac_len) != 0) {
  529. BIO_printf(bio_err, "Install indicator status mismatch\n");
  530. goto end;
  531. }
  532. }
  533. ret = 1;
  534. end:
  535. OPENSSL_free(buf1);
  536. OPENSSL_free(buf2);
  537. NCONF_free(conf);
  538. return ret;
  539. }
  540. int fipsinstall_main(int argc, char **argv)
  541. {
  542. int ret = 1, verify = 0, gotkey = 0, gotdigest = 0, pedantic = 0;
  543. int is_fips_140_2_prov = 0, set_selftest_onload_option = 0;
  544. const char *section_name = "fips_sect";
  545. const char *mac_name = "HMAC";
  546. const char *prov_name = "fips";
  547. BIO *module_bio = NULL, *mem_bio = NULL, *fout = NULL;
  548. char *in_fname = NULL, *out_fname = NULL, *prog;
  549. char *module_fname = NULL, *parent_config = NULL, *module_path = NULL;
  550. const char *tail;
  551. EVP_MAC_CTX *ctx = NULL, *ctx2 = NULL;
  552. STACK_OF(OPENSSL_STRING) *opts = NULL;
  553. OPTION_CHOICE o;
  554. unsigned char *read_buffer = NULL;
  555. unsigned char module_mac[EVP_MAX_MD_SIZE];
  556. size_t module_mac_len = EVP_MAX_MD_SIZE;
  557. unsigned char install_mac[EVP_MAX_MD_SIZE];
  558. size_t install_mac_len = EVP_MAX_MD_SIZE;
  559. EVP_MAC *mac = NULL;
  560. CONF *conf = NULL;
  561. if ((opts = sk_OPENSSL_STRING_new_null()) == NULL)
  562. goto end;
  563. prog = opt_init(argc, argv, fipsinstall_options);
  564. while ((o = opt_next()) != OPT_EOF) {
  565. switch (o) {
  566. case OPT_EOF:
  567. case OPT_ERR:
  568. opthelp:
  569. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  570. goto cleanup;
  571. case OPT_HELP:
  572. opt_help(fipsinstall_options);
  573. ret = 0;
  574. goto end;
  575. case OPT_IN:
  576. in_fname = opt_arg();
  577. break;
  578. case OPT_OUT:
  579. out_fname = opt_arg();
  580. break;
  581. case OPT_PEDANTIC:
  582. fips_opts = pedantic_opts;
  583. pedantic = 1;
  584. break;
  585. case OPT_NO_CONDITIONAL_ERRORS:
  586. if (!check_non_pedantic_fips(pedantic, "no_conditional_errors"))
  587. goto end;
  588. fips_opts.conditional_errors = 0;
  589. break;
  590. case OPT_NO_SECURITY_CHECKS:
  591. if (!check_non_pedantic_fips(pedantic, "no_security_checks"))
  592. goto end;
  593. fips_opts.security_checks = 0;
  594. break;
  595. case OPT_HMAC_KEY_CHECK:
  596. fips_opts.hmac_key_check = 1;
  597. break;
  598. case OPT_KMAC_KEY_CHECK:
  599. fips_opts.kmac_key_check = 1;
  600. break;
  601. case OPT_TLS_PRF_EMS_CHECK:
  602. fips_opts.tls_prf_ems_check = 1;
  603. break;
  604. case OPT_NO_SHORT_MAC:
  605. fips_opts.no_short_mac = 1;
  606. break;
  607. case OPT_DISALLOW_DRGB_TRUNC_DIGEST:
  608. fips_opts.drgb_no_trunc_dgst = 1;
  609. break;
  610. case OPT_SIGNATURE_DIGEST_CHECK:
  611. fips_opts.signature_digest_check = 1;
  612. break;
  613. case OPT_HKDF_DIGEST_CHECK:
  614. fips_opts.hkdf_digest_check = 1;
  615. break;
  616. case OPT_TLS13_KDF_DIGEST_CHECK:
  617. fips_opts.tls13_kdf_digest_check = 1;
  618. break;
  619. case OPT_TLS1_PRF_DIGEST_CHECK:
  620. fips_opts.tls1_prf_digest_check = 1;
  621. break;
  622. case OPT_SSHKDF_DIGEST_CHECK:
  623. fips_opts.sshkdf_digest_check = 1;
  624. break;
  625. case OPT_SSKDF_DIGEST_CHECK:
  626. fips_opts.sskdf_digest_check = 1;
  627. break;
  628. case OPT_X963KDF_DIGEST_CHECK:
  629. fips_opts.x963kdf_digest_check = 1;
  630. break;
  631. case OPT_DISALLOW_DSA_SIGN:
  632. fips_opts.dsa_sign_disabled = 1;
  633. break;
  634. case OPT_DISALLOW_TDES_ENCRYPT:
  635. fips_opts.tdes_encrypt_disabled = 1;
  636. break;
  637. case OPT_RSA_PSS_SALTLEN_CHECK:
  638. fips_opts.rsa_pss_saltlen_check = 1;
  639. break;
  640. case OPT_DISALLOW_SIGNATURE_X931_PADDING:
  641. fips_opts.sign_x931_padding_disabled = 1;
  642. break;
  643. case OPT_DISALLOW_PKCS15_PADDING:
  644. fips_opts.rsa_pkcs15_padding_disabled = 1;
  645. break;
  646. case OPT_HKDF_KEY_CHECK:
  647. fips_opts.hkdf_key_check = 1;
  648. break;
  649. case OPT_KBKDF_KEY_CHECK:
  650. fips_opts.kbkdf_key_check = 1;
  651. break;
  652. case OPT_TLS13_KDF_KEY_CHECK:
  653. fips_opts.tls13_kdf_key_check = 1;
  654. break;
  655. case OPT_TLS1_PRF_KEY_CHECK:
  656. fips_opts.tls1_prf_key_check = 1;
  657. break;
  658. case OPT_SSHKDF_KEY_CHECK:
  659. fips_opts.sshkdf_key_check = 1;
  660. break;
  661. case OPT_SSKDF_KEY_CHECK:
  662. fips_opts.sskdf_key_check = 1;
  663. break;
  664. case OPT_X963KDF_KEY_CHECK:
  665. fips_opts.x963kdf_key_check = 1;
  666. break;
  667. case OPT_X942KDF_KEY_CHECK:
  668. fips_opts.x942kdf_key_check = 1;
  669. break;
  670. case OPT_NO_PBKDF2_LOWER_BOUND_CHECK:
  671. if (!check_non_pedantic_fips(pedantic, "no_pbkdf2_lower_bound_check"))
  672. goto end;
  673. fips_opts.pbkdf2_lower_bound_check = 0;
  674. break;
  675. case OPT_ECDH_COFACTOR_CHECK:
  676. fips_opts.ecdh_cofactor_check = 1;
  677. break;
  678. case OPT_QUIET:
  679. quiet = 1;
  680. /* FALLTHROUGH */
  681. case OPT_NO_LOG:
  682. self_test_log = 0;
  683. break;
  684. case OPT_CORRUPT_DESC:
  685. self_test_corrupt_desc = opt_arg();
  686. break;
  687. case OPT_CORRUPT_TYPE:
  688. self_test_corrupt_type = opt_arg();
  689. break;
  690. case OPT_PROV_NAME:
  691. prov_name = opt_arg();
  692. break;
  693. case OPT_MODULE:
  694. module_fname = opt_arg();
  695. break;
  696. case OPT_SECTION_NAME:
  697. section_name = opt_arg();
  698. break;
  699. case OPT_MAC_NAME:
  700. mac_name = opt_arg();
  701. break;
  702. case OPT_CONFIG:
  703. parent_config = opt_arg();
  704. break;
  705. case OPT_MACOPT:
  706. if (!sk_OPENSSL_STRING_push(opts, opt_arg()))
  707. goto opthelp;
  708. if (HAS_PREFIX(opt_arg(), "hexkey:"))
  709. gotkey = 1;
  710. else if (HAS_PREFIX(opt_arg(), "digest:"))
  711. gotdigest = 1;
  712. break;
  713. case OPT_VERIFY:
  714. verify = 1;
  715. break;
  716. case OPT_SELF_TEST_ONLOAD:
  717. set_selftest_onload_option = 1;
  718. fips_opts.self_test_onload = 1;
  719. break;
  720. case OPT_SELF_TEST_ONINSTALL:
  721. if (!check_non_pedantic_fips(pedantic, "self_test_oninstall"))
  722. goto end;
  723. set_selftest_onload_option = 1;
  724. fips_opts.self_test_onload = 0;
  725. break;
  726. }
  727. }
  728. /* No extra arguments. */
  729. if (!opt_check_rest_arg(NULL))
  730. goto opthelp;
  731. if (verify && in_fname == NULL) {
  732. BIO_printf(bio_err, "Missing -in option for -verify\n");
  733. goto opthelp;
  734. }
  735. if (parent_config != NULL) {
  736. /* Test that a parent config can load the module */
  737. if (verify_module_load(parent_config)) {
  738. ret = OSSL_PROVIDER_available(NULL, prov_name) ? 0 : 1;
  739. if (!quiet) {
  740. BIO_printf(bio_err, "FIPS provider is %s\n",
  741. ret == 0 ? "available" : "not available");
  742. }
  743. }
  744. goto end;
  745. }
  746. if (module_fname == NULL)
  747. goto opthelp;
  748. tail = opt_path_end(module_fname);
  749. if (tail != NULL) {
  750. module_path = OPENSSL_strdup(module_fname);
  751. if (module_path == NULL)
  752. goto end;
  753. module_path[tail - module_fname] = '\0';
  754. if (!OSSL_PROVIDER_set_default_search_path(NULL, module_path))
  755. goto end;
  756. }
  757. if (self_test_log
  758. || self_test_corrupt_desc != NULL
  759. || self_test_corrupt_type != NULL)
  760. OSSL_SELF_TEST_set_callback(NULL, self_test_events, NULL);
  761. /* Use the default FIPS HMAC digest and key if not specified. */
  762. if (!gotdigest && !sk_OPENSSL_STRING_push(opts, "digest:SHA256"))
  763. goto end;
  764. if (!gotkey && !sk_OPENSSL_STRING_push(opts, "hexkey:" FIPS_KEY_STRING))
  765. goto end;
  766. module_bio = bio_open_default(module_fname, 'r', FORMAT_BINARY);
  767. if (module_bio == NULL) {
  768. BIO_printf(bio_err, "Failed to open module file\n");
  769. goto end;
  770. }
  771. read_buffer = app_malloc(BUFSIZE, "I/O buffer");
  772. if (read_buffer == NULL)
  773. goto end;
  774. mac = EVP_MAC_fetch(app_get0_libctx(), mac_name, app_get0_propq());
  775. if (mac == NULL) {
  776. BIO_printf(bio_err, "Unable to get MAC of type %s\n", mac_name);
  777. goto end;
  778. }
  779. ctx = EVP_MAC_CTX_new(mac);
  780. if (ctx == NULL) {
  781. BIO_printf(bio_err, "Unable to create MAC CTX for module check\n");
  782. goto end;
  783. }
  784. if (opts != NULL) {
  785. int ok = 1;
  786. OSSL_PARAM *params =
  787. app_params_new_from_opts(opts, EVP_MAC_settable_ctx_params(mac));
  788. if (params == NULL)
  789. goto end;
  790. if (!EVP_MAC_CTX_set_params(ctx, params)) {
  791. BIO_printf(bio_err, "MAC parameter error\n");
  792. ERR_print_errors(bio_err);
  793. ok = 0;
  794. }
  795. app_params_free(params);
  796. if (!ok)
  797. goto end;
  798. }
  799. ctx2 = EVP_MAC_CTX_dup(ctx);
  800. if (ctx2 == NULL) {
  801. BIO_printf(bio_err, "Unable to create MAC CTX for install indicator\n");
  802. goto end;
  803. }
  804. if (!do_mac(ctx, read_buffer, module_bio, module_mac, &module_mac_len))
  805. goto end;
  806. /* Calculate the MAC for the indicator status - it may not be used */
  807. mem_bio = BIO_new_mem_buf((const void *)INSTALL_STATUS_VAL,
  808. strlen(INSTALL_STATUS_VAL));
  809. if (mem_bio == NULL) {
  810. BIO_printf(bio_err, "Unable to create memory BIO\n");
  811. goto end;
  812. }
  813. if (!do_mac(ctx2, read_buffer, mem_bio, install_mac, &install_mac_len))
  814. goto end;
  815. if (verify) {
  816. if (fips_opts.self_test_onload == 1)
  817. install_mac_len = 0;
  818. if (!verify_config(in_fname, section_name, module_mac, module_mac_len,
  819. install_mac, install_mac_len))
  820. goto end;
  821. if (!quiet)
  822. BIO_printf(bio_err, "VERIFY PASSED\n");
  823. } else {
  824. conf = generate_config_and_load(prov_name, section_name, module_mac,
  825. module_mac_len, &fips_opts);
  826. if (conf == NULL)
  827. goto end;
  828. if (!load_fips_prov_and_run_self_test(prov_name, &is_fips_140_2_prov))
  829. goto end;
  830. /*
  831. * In OpenSSL 3.1 the code was changed so that the status indicator is
  832. * not written out by default since this is a FIPS 140-3 requirement.
  833. * For backwards compatibility - if the detected FIPS provider is 3.0.X
  834. * (Which was a FIPS 140-2 validation), then the indicator status will
  835. * be written to the config file unless 'self_test_onload' is set on the
  836. * command line.
  837. */
  838. if (set_selftest_onload_option == 0 && is_fips_140_2_prov)
  839. fips_opts.self_test_onload = 0;
  840. fout =
  841. out_fname == NULL ? dup_bio_out(FORMAT_TEXT)
  842. : bio_open_default(out_fname, 'w', FORMAT_TEXT);
  843. if (fout == NULL) {
  844. BIO_printf(bio_err, "Failed to open file\n");
  845. goto end;
  846. }
  847. if (!write_config_fips_section(fout, section_name,
  848. module_mac, module_mac_len, &fips_opts,
  849. install_mac, install_mac_len))
  850. goto end;
  851. if (!quiet)
  852. BIO_printf(bio_err, "INSTALL PASSED\n");
  853. }
  854. ret = 0;
  855. end:
  856. if (ret == 1) {
  857. if (!quiet)
  858. BIO_printf(bio_err, "%s FAILED\n", verify ? "VERIFY" : "INSTALL");
  859. ERR_print_errors(bio_err);
  860. }
  861. cleanup:
  862. OPENSSL_free(module_path);
  863. BIO_free(fout);
  864. BIO_free(mem_bio);
  865. BIO_free(module_bio);
  866. sk_OPENSSL_STRING_free(opts);
  867. EVP_MAC_free(mac);
  868. EVP_MAC_CTX_free(ctx2);
  869. EVP_MAC_CTX_free(ctx);
  870. OPENSSL_free(read_buffer);
  871. free_config_and_unload(conf);
  872. return ret;
  873. }
  874. static int self_test_events(const OSSL_PARAM params[], void *arg)
  875. {
  876. const OSSL_PARAM *p = NULL;
  877. const char *phase = NULL, *type = NULL, *desc = NULL;
  878. int ret = 0;
  879. p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_PHASE);
  880. if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
  881. goto err;
  882. phase = (const char *)p->data;
  883. p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_DESC);
  884. if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
  885. goto err;
  886. desc = (const char *)p->data;
  887. p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_TYPE);
  888. if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
  889. goto err;
  890. type = (const char *)p->data;
  891. if (self_test_log) {
  892. if (strcmp(phase, OSSL_SELF_TEST_PHASE_START) == 0)
  893. BIO_printf(bio_err, "%s : (%s) : ", desc, type);
  894. else if (strcmp(phase, OSSL_SELF_TEST_PHASE_PASS) == 0
  895. || strcmp(phase, OSSL_SELF_TEST_PHASE_FAIL) == 0)
  896. BIO_printf(bio_err, "%s\n", phase);
  897. }
  898. /*
  899. * The self test code will internally corrupt the KAT test result if an
  900. * error is returned during the corrupt phase.
  901. */
  902. if (strcmp(phase, OSSL_SELF_TEST_PHASE_CORRUPT) == 0
  903. && (self_test_corrupt_desc != NULL
  904. || self_test_corrupt_type != NULL)) {
  905. if (self_test_corrupt_desc != NULL
  906. && strcmp(self_test_corrupt_desc, desc) != 0)
  907. goto end;
  908. if (self_test_corrupt_type != NULL
  909. && strcmp(self_test_corrupt_type, type) != 0)
  910. goto end;
  911. BIO_printf(bio_err, "%s ", phase);
  912. goto err;
  913. }
  914. end:
  915. ret = 1;
  916. err:
  917. return ret;
  918. }