components/openssl/openssl-1.0.0/engines/pkcs11/hw_pk11.c
changeset 669 8046d7c55991
parent 588 a72cfdd57701
child 684 f76b6e9a83b8
equal deleted inserted replaced
668:49f7eecdeb8f 669:8046d7c55991
     1 /*
     1 /*
     2  * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
     3  */
     3  */
     4 
     4 
     5 /* crypto/engine/hw_pk11.c */
     5 /* crypto/engine/hw_pk11.c */
     6 /*
     6 /*
     7  * This product includes software developed by the OpenSSL Project for
     7  * This product includes software developed by the OpenSSL Project for
   146 /*
   146 /*
   147  * We use this lock to prevent multiple C_Login()s, guard getpassphrase(),
   147  * We use this lock to prevent multiple C_Login()s, guard getpassphrase(),
   148  * uri_struct manipulation, and static token info. All of that is used by the
   148  * uri_struct manipulation, and static token info. All of that is used by the
   149  * RSA keys by reference feature.
   149  * RSA keys by reference feature.
   150  */
   150  */
   151 pthread_mutex_t *uri_lock;
   151 pthread_mutex_t *uri_lock = NULL;
   152 
   152 
   153 #ifdef	SOLARIS_HW_SLOT_SELECTION
   153 #ifdef	SOLARIS_HW_SLOT_SELECTION
   154 /*
   154 /*
   155  * Tables for symmetric ciphers and digest mechs found in the pkcs11_kernel
   155  * Tables for symmetric ciphers and digest mechs found in the pkcs11_kernel
   156  * library. See comment at check_hw_mechanisms() for more information.
   156  * library. See comment at check_hw_mechanisms() for more information.
   904 			(void) pthread_mutex_destroy(session_cache[type].lock);
   904 			(void) pthread_mutex_destroy(session_cache[type].lock);
   905 			OPENSSL_free(session_cache[type].lock);
   905 			OPENSSL_free(session_cache[type].lock);
   906 			session_cache[type].lock = NULL;
   906 			session_cache[type].lock = NULL;
   907 			}
   907 			}
   908 		}
   908 		}
       
   909 	/* Free uri_lock */
       
   910 	(void) pthread_mutex_destroy(uri_lock);
       
   911 	OPENSSL_free(uri_lock);
       
   912 	uri_lock = NULL;
   909 	}
   913 	}
   910 
   914 
   911 /*
   915 /*
   912  * This internal function is used by ENGINE_pk11() and "dynamic" ENGINE support.
   916  * This internal function is used by ENGINE_pk11() and "dynamic" ENGINE support.
   913  */
   917  */
  1212 			 */
  1216 			 */
  1213 			pk11_free_all_locks();
  1217 			pk11_free_all_locks();
  1214 			}
  1218 			}
  1215 		}
  1219 		}
  1216 
  1220 
  1217 	if (pk11_dso == NULL)
  1221 
  1218 		{
  1222 	/* Attempt to load PKCS#11 library */
  1219 		PK11err(PK11_F_LIBRARY_INIT, PK11_R_DSO_FAILURE);
  1223 	if (!pk11_dso)
  1220 		goto err;
  1224 		{
       
  1225 		pk11_dso = DSO_load(NULL, get_PK11_LIBNAME(), NULL, 0);
       
  1226 		if (pk11_dso == NULL)
       
  1227 			{
       
  1228 			PK11err(PK11_F_LOAD, PK11_R_DSO_FAILURE);
       
  1229 			goto err;
       
  1230 			}
  1221 		}
  1231 		}
  1222 
  1232 
  1223 #ifdef	SOLARIS_AES_CTR
  1233 #ifdef	SOLARIS_AES_CTR
  1224 	/*
  1234 	/*
  1225 	 * We must do this before we start working with slots since we need all
  1235 	 * We must do this before we start working with slots since we need all
  1340 
  1350 
  1341 /* Destructor (complements the "ENGINE_pk11()" constructor) */
  1351 /* Destructor (complements the "ENGINE_pk11()" constructor) */
  1342 /* ARGSUSED */
  1352 /* ARGSUSED */
  1343 static int pk11_destroy(ENGINE *e)
  1353 static int pk11_destroy(ENGINE *e)
  1344 	{
  1354 	{
       
  1355 	int rtn = 1;
       
  1356 
  1345 	free_PK11_LIBNAME();
  1357 	free_PK11_LIBNAME();
  1346 	ERR_unload_pk11_strings();
  1358 	ERR_unload_pk11_strings();
  1347 	return (1);
  1359 	if (pk11_library_initialized == CK_TRUE)
       
  1360 		rtn = pk11_finish(e);
       
  1361 
       
  1362 	return (rtn);
  1348 	}
  1363 	}
  1349 
  1364 
  1350 /*
  1365 /*
  1351  * Termination function to clean up the session, the token, and the pk11
  1366  * Termination function to clean up the session, the token, and the pk11
  1352  * library.
  1367  * library.