use of net.i2p.util.SecureDirectory in project i2p.i2p by i2p.
the class SSLUtil method exportCert.
/**
* Pull the cert back OUT of the keystore and save it as ascii
* so the clients can get to it.
*
* @param name used to generate output file name
* @param opts must contain PROP_KEY_ALIAS
*/
private static void exportCert(File ks, String name, Properties opts) {
File sdir = new SecureDirectory(I2PAppContext.getGlobalContext().getConfigDir(), CERT_DIR);
if (sdir.exists() || sdir.mkdirs()) {
String keyAlias = opts.getProperty(PROP_KEY_ALIAS);
String ksPass = opts.getProperty(PROP_KEYSTORE_PASSWORD, KeyStoreUtil.DEFAULT_KEYSTORE_PASSWORD);
File out = new File(sdir, PREFIX + name + ASCII_KEYFILE_SUFFIX);
boolean success = KeyStoreUtil.exportCert(ks, ksPass, keyAlias, out);
if (!success)
error("Error getting SSL cert to save as ASCII");
} else {
error("Error saving ASCII SSL keys");
}
}
use of net.i2p.util.SecureDirectory in project i2p.i2p by i2p.
the class I2PAppContext method getTempDir.
/**
* Where anybody may store temporary data.
* This is a directory created in the system temp dir on the
* first call in this context, and is deleted on JVM exit.
* Applications should create their own directory inside this directory
* to avoid collisions with other apps.
* @since 0.7.6
* @return dir constant for the life of the context
*/
public File getTempDir() {
// fixme don't synchronize every time
synchronized (_lock1) {
if (_tmpDir == null) {
String d = getProperty("i2p.dir.temp", System.getProperty("java.io.tmpdir"));
// our random() probably isn't warmed up yet
byte[] rand = new byte[6];
_tmpDirRand.nextBytes(rand);
String f = "i2p-" + Base64.encode(rand) + ".tmp";
_tmpDir = new SecureDirectory(d, f);
if (_tmpDir.exists()) {
// good or bad ? loop and try again?
} else if (_tmpDir.mkdir()) {
_tmpDir.deleteOnExit();
} else {
System.err.println("WARNING: Could not create temp dir " + _tmpDir.getAbsolutePath());
_tmpDir = new SecureDirectory(_routerDir, "tmp");
_tmpDir.mkdirs();
if (!_tmpDir.exists())
System.err.println("ERROR: Could not create temp dir " + _tmpDir.getAbsolutePath());
}
}
}
return _tmpDir;
}
use of net.i2p.util.SecureDirectory in project i2p.i2p by i2p.
the class SSLClientListenerRunner method verifyKeyStore.
/**
* @return success if it exists and we have a password, or it was created successfully.
*/
private boolean verifyKeyStore(File ks) {
if (ks.exists()) {
boolean rv = _context.getProperty(PROP_KEY_PASSWORD) != null;
if (!rv)
_log.error("I2CP SSL error, must set " + PROP_KEY_PASSWORD + " in " + (new File(_context.getConfigDir(), "router.config")).getAbsolutePath());
return rv;
}
File dir = ks.getParentFile();
if (!dir.exists()) {
File sdir = new SecureDirectory(dir.getAbsolutePath());
if (!sdir.mkdir())
return false;
}
boolean rv = createKeyStore(ks);
// Failure of this part is not fatal.
if (rv)
exportCert(ks);
return rv;
}
use of net.i2p.util.SecureDirectory in project i2p.i2p by i2p.
the class SSLClientListenerRunner method exportCert.
/**
* Pull the cert back OUT of the keystore and save it as ascii
* so the clients can get to it.
*/
private void exportCert(File ks) {
File sdir = new SecureDirectory(_context.getConfigDir(), "certificates/i2cp");
if (sdir.exists() || sdir.mkdirs()) {
String ksPass = _context.getProperty(PROP_KEYSTORE_PASSWORD, KeyStoreUtil.DEFAULT_KEYSTORE_PASSWORD);
File out = new File(sdir, ASCII_KEYFILE);
boolean success = KeyStoreUtil.exportCert(ks, ksPass, KEY_ALIAS, out);
if (!success)
_log.error("Error getting SSL cert to save as ASCII");
} else {
_log.error("Error saving ASCII SSL keys");
}
}
use of net.i2p.util.SecureDirectory in project i2p.i2p by i2p.
the class FamilyKeyCrypto method initialize.
/**
* Create (if necessary) and load the key store, then run.
*/
private SigningPrivateKey initialize() throws GeneralSecurityException {
File dir = new SecureDirectory(_context.getConfigDir(), KS_DIR);
File keyStore = new File(dir, KEYSTORE_PREFIX + _fname + KEYSTORE_SUFFIX);
verifyKeyStore(keyStore);
return getPrivKey(keyStore);
}
Aggregations