5454 */
5555abstract class CKeyStore extends KeyStoreSpi {
5656
57+ private static final int LOCATION_CURRENTUSER = 0 ;
58+ private static final int LOCATION_LOCALMACHINE = 1 ;
59+
5760 public static final class MY extends CKeyStore {
5861 public MY () {
59- super ("MY" );
62+ super ("MY" , LOCATION_CURRENTUSER );
6063 }
6164 }
6265
6366 public static final class ROOT extends CKeyStore {
6467 public ROOT () {
65- super ("ROOT" );
68+ super ("ROOT" , LOCATION_CURRENTUSER );
69+ }
70+ }
71+
72+ public static final class MYLocalMachine extends CKeyStore {
73+ public MYLocalMachine () {
74+ super ("MY" , LOCATION_LOCALMACHINE );
75+ }
76+ }
77+
78+ public static final class ROOTLocalMachine extends CKeyStore {
79+ public ROOTLocalMachine () {
80+ super ("ROOT" , LOCATION_LOCALMACHINE );
6681 }
6782 }
6883
@@ -220,7 +235,12 @@ public void delete() throws KeyStoreException {
220235 */
221236 private final String storeName ;
222237
223- CKeyStore (String storeName ) {
238+ /*
239+ * The keystore location.
240+ */
241+ private final int storeLocation ;
242+
243+ CKeyStore (String storeName , int storeLocation ) {
224244 // Get the compatibility mode
225245 @ SuppressWarnings ("removal" )
226246 String prop = AccessController .doPrivileged (
@@ -233,6 +253,7 @@ public void delete() throws KeyStoreException {
233253 }
234254
235255 this .storeName = storeName ;
256+ this .storeLocation = storeLocation ;
236257 }
237258
238259 /**
@@ -259,7 +280,7 @@ public void delete() throws KeyStoreException {
259280 * @exception UnrecoverableKeyException if the key cannot be recovered.
260281 */
261282 public java .security .Key engineGetKey (String alias , char [] password )
262- throws NoSuchAlgorithmException , UnrecoverableKeyException {
283+ throws NoSuchAlgorithmException , UnrecoverableKeyException {
263284 if (alias == null ) {
264285 return null ;
265286 }
@@ -705,7 +726,7 @@ public void engineLoad(InputStream stream, char[] password)
705726 try {
706727
707728 // Load keys and/or certificate chains
708- loadKeysOrCertificateChains (getName ());
729+ loadKeysOrCertificateChains (getName (), getLocation () );
709730
710731 } catch (KeyStoreException e ) {
711732 throw new IOException (e );
@@ -801,7 +822,7 @@ private void generateKeyAndCertificateChain(boolean isRSA, String alias,
801822 * @param certCollection Collection of certificates.
802823 */
803824 private void generateCertificate (byte [] data ,
804- Collection <Certificate > certCollection ) {
825+ Collection <Certificate > certCollection ) {
805826 try {
806827 ByteArrayInputStream bis = new ByteArrayInputStream (data );
807828
@@ -829,12 +850,20 @@ private String getName() {
829850 }
830851
831852 /**
832- * Load keys and/or certificates from keystore into Collection.
853+ * Returns the location of the keystore.
854+ */
855+ private int getLocation () {
856+ return storeLocation ;
857+ }
858+
859+ /**
860+ * Loads keys and/or certificates from keystore into Collection.
833861 *
834862 * @param name Name of keystore.
863+ * @param location Location of keystore.
835864 */
836- private native void loadKeysOrCertificateChains (String name )
837- throws KeyStoreException ;
865+ private native void loadKeysOrCertificateChains (String name ,
866+ int location ) throws KeyStoreException ;
838867
839868 /**
840869 * Stores a DER-encoded certificate into the certificate store
@@ -844,8 +873,8 @@ private native void loadKeysOrCertificateChains(String name)
844873 * @param encoding DER-encoded certificate.
845874 */
846875 private native void storeCertificate (String name , String alias ,
847- byte [] encoding , int encodingLength , long hCryptProvider ,
848- long hCryptKey ) throws CertificateException , KeyStoreException ;
876+ byte [] encoding , int encodingLength , long hCryptProvider ,
877+ long hCryptKey ) throws CertificateException , KeyStoreException ;
849878
850879 /**
851880 * Removes the certificate from the certificate store
@@ -855,7 +884,7 @@ private native void storeCertificate(String name, String alias,
855884 * @param encoding DER-encoded certificate.
856885 */
857886 private native void removeCertificate (String name , String alias ,
858- byte [] encoding , int encodingLength )
887+ byte [] encoding , int encodingLength )
859888 throws CertificateException , KeyStoreException ;
860889
861890 /**
@@ -864,7 +893,7 @@ private native void removeCertificate(String name, String alias,
864893 * @param keyContainerName The name of the key container.
865894 */
866895 private native void destroyKeyContainer (String keyContainerName )
867- throws KeyStoreException ;
896+ throws KeyStoreException ;
868897
869898 /**
870899 * Removes a CNG key.
@@ -877,16 +906,16 @@ private native void destroyKeyContainer(String keyContainerName)
877906 * Generates a private-key BLOB from a key's components.
878907 */
879908 private native byte [] generateRSAPrivateKeyBlob (
880- int keyBitLength ,
881- byte [] modulus ,
882- byte [] publicExponent ,
883- byte [] privateExponent ,
884- byte [] primeP ,
885- byte [] primeQ ,
886- byte [] exponentP ,
887- byte [] exponentQ ,
888- byte [] crtCoefficient ) throws InvalidKeyException ;
909+ int keyBitLength ,
910+ byte [] modulus ,
911+ byte [] publicExponent ,
912+ byte [] privateExponent ,
913+ byte [] primeP ,
914+ byte [] primeQ ,
915+ byte [] exponentP ,
916+ byte [] exponentQ ,
917+ byte [] crtCoefficient ) throws InvalidKeyException ;
889918
890919 private native CPrivateKey storePrivateKey (String alg , byte [] keyBlob ,
891- String keyContainerName , int keySize ) throws KeyStoreException ;
920+ String keyContainerName , int keySize ) throws KeyStoreException ;
892921}
0 commit comments