use of net.i2p.util.SecureDirectory in project i2p.i2p by i2p.
the class FamilyKeyCrypto method exportCert.
/**
* Save the public key certificate
* so the clients can get to it.
*/
private void exportCert(X509Certificate cert) {
File sdir = new SecureDirectory(_context.getConfigDir(), CERT_DIR);
if (sdir.exists() || sdir.mkdirs()) {
String name = _fname.replace("@", "_at_") + CERT_SUFFIX;
File out = new File(sdir, name);
boolean success = CertUtil.saveCert(cert, out);
if (success) {
_log.logAlways(Log.INFO, "Created new public key certificate for netdb family \"" + _fname + "\" in file: " + out.getAbsolutePath() + "\n" + "The certificate will be associated with your router identity.\n" + "Copy the certificate to the directory $I2P/" + CERT_DIR + " for each of the other routers in the family.\n" + "Give this certificate to an I2P developer for inclusion in the next I2P release.");
} else {
_log.error("Error saving family key certificate");
}
} else {
_log.error("Error saving family key certificate");
}
}
use of net.i2p.util.SecureDirectory in project i2p.i2p by i2p.
the class FamilyKeyCrypto method verifyKeyStore.
/**
* @return success if it exists and we have a password, or it was created successfully.
* @throws GeneralSecurityException on keystore error
*/
private void verifyKeyStore(File ks) throws GeneralSecurityException {
if (ks.exists()) {
if (_context.getProperty(PROP_KEY_PASSWORD) == null) {
String s = "Family key error, must set " + PROP_KEY_PASSWORD + " in " + (new File(_context.getConfigDir(), "router.config")).getAbsolutePath();
_log.error(s);
throw new GeneralSecurityException(s);
}
return;
}
File dir = ks.getParentFile();
if (!dir.exists()) {
File sdir = new SecureDirectory(dir.getAbsolutePath());
if (!sdir.mkdirs()) {
String s = "Family key error, must set " + PROP_KEY_PASSWORD + " in " + (new File(_context.getConfigDir(), "router.config")).getAbsolutePath();
_log.error(s);
throw new GeneralSecurityException(s);
}
}
try {
createKeyStore(ks);
} catch (IOException ioe) {
throw new GeneralSecurityException("Failed to create NetDb family keystore", ioe);
}
}
Aggregations