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>


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.

  24  */
  25 
  26 #include <stdio.h>
  27 #include <stdlib.h>
  28 #include <strings.h>
  29 #include <errno.h>
  30 #include <security/cryptoki.h>
  31 #include <cryptoutil.h>
  32 #include "kernelGlobal.h"
  33 #include "kernelObject.h"
  34 #include "kernelSession.h"
  35 #include "kernelSlot.h"
  36 
  37 /*
  38  * Add an object to the session's object list.
  39  *
  40  * This function will acquire the lock on the session, and release
  41  * that lock after adding the object to the session's object list.
  42  */
  43 void


  60 
  61         /* Release the session lock. */
  62         (void) pthread_mutex_unlock(&sp->session_mutex);
  63 }
  64 
  65 /*
  66  * Clean up and release the storage allocated to the object.
  67  *
  68  * The function is called either with the object lock being held
  69  * (by caller kernel_delete_object()), or there is no object lock
  70  * yet (by kernel_build_XXX_object() during creating an object).
  71  */
  72 void
  73 kernel_cleanup_object(kernel_object_t *objp)
  74 {
  75         /*
  76          * Free the storage allocated to a secret key object.
  77          */
  78         if (objp->class == CKO_SECRET_KEY) {
  79                 if (OBJ_SEC(objp) != NULL && OBJ_SEC_VALUE(objp) != NULL) {
  80                         bzero(OBJ_SEC_VALUE(objp), OBJ_SEC_VALUE_LEN(objp));
  81                         free(OBJ_SEC_VALUE(objp));
  82                         OBJ_SEC_VALUE(objp) = NULL;
  83                         OBJ_SEC_VALUE_LEN(objp) = 0;
  84                 }
  85                 free(OBJ_SEC(objp));
  86                 OBJ_SEC(objp) = NULL;
  87         } else {
  88                 kernel_cleanup_object_bigint_attrs(objp);
  89         }
  90 
  91         /*
  92          * Free the storage allocated to the extra attribute list.
  93          */
  94         kernel_cleanup_extra_attr(objp);
  95 }
  96 
  97 /*
  98  * Create a new object. Copy the attributes that can be modified
  99  * (in the boolean attribute mask field and extra attribute list)
 100  * from the old object to the new object.
 101  *




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  * Copyright (c) 2018, Joyent, Inc.
  25  */
  26 
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <strings.h>
  30 #include <errno.h>
  31 #include <security/cryptoki.h>
  32 #include <cryptoutil.h>
  33 #include "kernelGlobal.h"
  34 #include "kernelObject.h"
  35 #include "kernelSession.h"
  36 #include "kernelSlot.h"
  37 
  38 /*
  39  * Add an object to the session's object list.
  40  *
  41  * This function will acquire the lock on the session, and release
  42  * that lock after adding the object to the session's object list.
  43  */
  44 void


  61 
  62         /* Release the session lock. */
  63         (void) pthread_mutex_unlock(&sp->session_mutex);
  64 }
  65 
  66 /*
  67  * Clean up and release the storage allocated to the object.
  68  *
  69  * The function is called either with the object lock being held
  70  * (by caller kernel_delete_object()), or there is no object lock
  71  * yet (by kernel_build_XXX_object() during creating an object).
  72  */
  73 void
  74 kernel_cleanup_object(kernel_object_t *objp)
  75 {
  76         /*
  77          * Free the storage allocated to a secret key object.
  78          */
  79         if (objp->class == CKO_SECRET_KEY) {
  80                 if (OBJ_SEC(objp) != NULL && OBJ_SEC_VALUE(objp) != NULL) {
  81                         freezero(OBJ_SEC_VALUE(objp), OBJ_SEC_VALUE_LEN(objp));

  82                         OBJ_SEC_VALUE(objp) = NULL;
  83                         OBJ_SEC_VALUE_LEN(objp) = 0;
  84                 }
  85                 free(OBJ_SEC(objp));
  86                 OBJ_SEC(objp) = NULL;
  87         } else {
  88                 kernel_cleanup_object_bigint_attrs(objp);
  89         }
  90 
  91         /*
  92          * Free the storage allocated to the extra attribute list.
  93          */
  94         kernel_cleanup_extra_attr(objp);
  95 }
  96 
  97 /*
  98  * Create a new object. Copy the attributes that can be modified
  99  * (in the boolean attribute mask field and extra attribute list)
 100  * from the old object to the new object.
 101  *