Esempio n. 1
0
 public static KeyStore buildKeyStore() {
   if (keystore == null) {
     File keyStoreFile = new File(KEY_STORE_FILENAME);
     if (keyStoreFile.exists()) {
       loadKeyStore(keyStoreFile);
     } else {
       dynamicallyCreateKeyStore();
       saveKeyStore();
     }
   }
   return keystore;
 }
Esempio n. 2
0
 private static void saveKeyStore() {
   try {
     ByteArrayOutputStream bout = new ByteArrayOutputStream();
     keystore.store(bout, KEY_STORE_PASSWORD.toCharArray());
     File keyStoreFile = new File(KEY_STORE_FILENAME);
     logger.trace("Saving key store to file [" + keyStoreFile + "]");
     FileOutputStream fileOutputStream = null;
     try {
       fileOutputStream = new FileOutputStream(keyStoreFile);
       fileOutputStream.write(bout.toByteArray());
     } finally {
       if (fileOutputStream != null) {
         fileOutputStream.close();
       }
     }
     keyStoreFile.deleteOnExit();
   } catch (Exception e) {
     throw new RuntimeException("Exception while saving KeyStore", e);
   }
 }
Esempio n. 3
0
 private static void loadKeyStore(File keyStoreFile) {
   try {
     FileInputStream fileInputStream = null;
     try {
       fileInputStream = new FileInputStream(KEY_STORE_FILENAME);
       logger.trace("Loading key store from file [" + keyStoreFile + "]");
       keystore = KeyStore.getInstance(KeyStore.getDefaultType());
       keystore.load(fileInputStream, KEY_STORE_PASSWORD.toCharArray());
     } finally {
       if (fileInputStream != null) {
         fileInputStream.close();
       }
     }
   } catch (Exception e) {
     throw new RuntimeException(
         "Exception while loading KeyStore from " + keyStoreFile.getAbsolutePath(), e);
   }
 }