Print this page
9642 PKCS#11 softtoken should use explicit_bzero
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Alex Wilson <alex.wilson@joyent.com>

*** 20,29 **** --- 20,30 ---- */ /* * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2012 Milan Jurik. All rights reserved. + * Copyright (c) 2018, Joyent. Inc. */ #include <stdlib.h> #include <string.h> #include <strings.h>
*** 85,95 **** /* * Realloc() may free() or shrink previous memory location, so * clear out potentially sensitive data before that happens. */ if (dst->big_value != NULL) ! (void) memset(dst->big_value, 0x0, dst->big_value_len); padding = (src->big_value[0] < 0x80) ? 0 : 1; dst->big_value_len = src->big_value_len + padding; dst->big_value = realloc(dst->big_value, dst->big_value_len); --- 86,96 ---- /* * Realloc() may free() or shrink previous memory location, so * clear out potentially sensitive data before that happens. */ if (dst->big_value != NULL) ! explicit_bzero(dst->big_value, dst->big_value_len); padding = (src->big_value[0] < 0x80) ? 0 : 1; dst->big_value_len = src->big_value_len + padding; dst->big_value = realloc(dst->big_value, dst->big_value_len);
*** 336,349 **** *buf_len = p8obj_octs->bv_len; (void) memcpy(buf, p8obj_octs->bv_val, *buf_len); cleanup_rsapri2asn: ! if (tmp_pad.big_value != NULL) { ! (void) memset(tmp_pad.big_value, 0x0, tmp_pad.big_value_len); ! free(tmp_pad.big_value); ! } if (key_asn != NULLBER) ber_free(key_asn, 1); if (key_octs != NULL) --- 337,347 ---- *buf_len = p8obj_octs->bv_len; (void) memcpy(buf, p8obj_octs->bv_val, *buf_len); cleanup_rsapri2asn: ! freezero(tmp_pad.big_value, tmp_pad.big_value_len); if (key_asn != NULLBER) ber_free(key_asn, 1); if (key_octs != NULL)
*** 525,538 **** *buf_len = p8obj_octs->bv_len; (void) memcpy(buf, p8obj_octs->bv_val, *buf_len); cleanup_dsapri2asn: ! if (tmp_pad.big_value != NULL) { ! (void) memset(tmp_pad.big_value, 0x0, tmp_pad.big_value_len); ! free(tmp_pad.big_value); ! } if (key_asn != NULLBER) ber_free(key_asn, 1); if (key_octs != NULL) --- 523,533 ---- *buf_len = p8obj_octs->bv_len; (void) memcpy(buf, p8obj_octs->bv_val, *buf_len); cleanup_dsapri2asn: ! freezero(tmp_pad.big_value, tmp_pad.big_value_len); if (key_asn != NULLBER) ber_free(key_asn, 1); if (key_octs != NULL)
*** 699,712 **** *buf_len = p8obj_octs->bv_len; (void) memcpy(buf, p8obj_octs->bv_val, *buf_len); cleanup_dhpri2asn: ! if (tmp_pad.big_value != NULL) { ! (void) memset(tmp_pad.big_value, 0x0, tmp_pad.big_value_len); ! free(tmp_pad.big_value); ! } if (key_asn != NULLBER) ber_free(key_asn, 1); if (key_octs != NULL) --- 694,704 ---- *buf_len = p8obj_octs->bv_len; (void) memcpy(buf, p8obj_octs->bv_val, *buf_len); cleanup_dhpri2asn: ! freezero(tmp_pad.big_value, tmp_pad.big_value_len); if (key_asn != NULLBER) ber_free(key_asn, 1); if (key_octs != NULL)
*** 891,904 **** *buf_len = p8obj_octs->bv_len; (void) memcpy(buf, p8obj_octs->bv_val, *buf_len); cleanup_x942dhpri2asn: ! if (tmp_pad.big_value != NULL) { ! (void) memset(tmp_pad.big_value, 0x0, tmp_pad.big_value_len); ! free(tmp_pad.big_value); ! } if (key_asn != NULLBER) ber_free(key_asn, 1); if (key_octs != NULL) --- 883,893 ---- *buf_len = p8obj_octs->bv_len; (void) memcpy(buf, p8obj_octs->bv_val, *buf_len); cleanup_x942dhpri2asn: ! freezero(tmp_pad.big_value, tmp_pad.big_value_len); if (key_asn != NULLBER) ber_free(key_asn, 1); if (key_octs != NULL)
*** 1238,1252 **** bigint_attr_cleanup(KEY_PRI_RSA_EXPO2(keyp)); bigint_attr_cleanup(KEY_PRI_RSA_COEF(keyp)); cleanup_asn2rsapri: ! if (tmp_nopad.big_value != NULL) { ! (void) memset(tmp_nopad.big_value, 0x0, ! tmp_nopad.big_value_len); ! free(tmp_nopad.big_value); ! } if (p8obj_asn != NULLBER) ber_free(p8obj_asn, 1); if (key_octs.bv_val != NULL) --- 1227,1237 ---- bigint_attr_cleanup(KEY_PRI_RSA_EXPO2(keyp)); bigint_attr_cleanup(KEY_PRI_RSA_COEF(keyp)); cleanup_asn2rsapri: ! freezero(tmp_nopad.big_value, tmp_nopad.big_value_len); if (p8obj_asn != NULLBER) ber_free(p8obj_asn, 1); if (key_octs.bv_val != NULL)
*** 1446,1460 **** bigint_attr_cleanup(KEY_PRI_DSA_BASE(keyp)); bigint_attr_cleanup(KEY_PRI_DSA_VALUE(keyp)); cleanup_asn2dsapri: ! if (tmp_nopad.big_value != NULL) { ! (void) memset(tmp_nopad.big_value, 0x0, ! tmp_nopad.big_value_len); ! free(tmp_nopad.big_value); ! } if (p8obj_asn != NULLBER) ber_free(p8obj_asn, 1); if (key_octs.bv_val != NULL) --- 1431,1441 ---- bigint_attr_cleanup(KEY_PRI_DSA_BASE(keyp)); bigint_attr_cleanup(KEY_PRI_DSA_VALUE(keyp)); cleanup_asn2dsapri: ! freezero(tmp_nopad.big_value, tmp_nopad.big_value_len); if (p8obj_asn != NULLBER) ber_free(p8obj_asn, 1); if (key_octs.bv_val != NULL)
*** 1630,1644 **** bigint_attr_cleanup(KEY_PRI_DH_BASE(keyp)); bigint_attr_cleanup(KEY_PRI_DH_VALUE(keyp)); cleanup_asn2dhpri: ! if (tmp_nopad.big_value != NULL) { ! (void) memset(tmp_nopad.big_value, 0x0, ! tmp_nopad.big_value_len); ! free(tmp_nopad.big_value); ! } if (p8obj_asn != NULLBER) ber_free(p8obj_asn, 1); if (key_octs.bv_val != NULL) --- 1611,1621 ---- bigint_attr_cleanup(KEY_PRI_DH_BASE(keyp)); bigint_attr_cleanup(KEY_PRI_DH_VALUE(keyp)); cleanup_asn2dhpri: ! freezero(tmp_nopad.big_value, tmp_nopad.big_value_len); if (p8obj_asn != NULLBER) ber_free(p8obj_asn, 1); if (key_octs.bv_val != NULL)
*** 1838,1852 **** bigint_attr_cleanup(KEY_PRI_DH942_SUBPRIME(keyp)); bigint_attr_cleanup(KEY_PRI_DH942_VALUE(keyp)); cleanup_asn2x942dhpri: ! if (tmp_nopad.big_value != NULL) { ! (void) memset(tmp_nopad.big_value, 0x0, ! tmp_nopad.big_value_len); ! free(tmp_nopad.big_value); ! } if (p8obj_asn != NULLBER) ber_free(p8obj_asn, 1); if (key_octs.bv_val != NULL) --- 1815,1825 ---- bigint_attr_cleanup(KEY_PRI_DH942_SUBPRIME(keyp)); bigint_attr_cleanup(KEY_PRI_DH942_VALUE(keyp)); cleanup_asn2x942dhpri: ! freezero(tmp_nopad.big_value, tmp_nopad.big_value_len); if (p8obj_asn != NULLBER) ber_free(p8obj_asn, 1); if (key_octs.bv_val != NULL)