Search in sources :

Example 31 with SecureDirectory

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");
    }
}
Also used : SecureDirectory(net.i2p.util.SecureDirectory) File(java.io.File)

Example 32 with SecureDirectory

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);
    }
}
Also used : SecureDirectory(net.i2p.util.SecureDirectory) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) File(java.io.File)

Aggregations

SecureDirectory (net.i2p.util.SecureDirectory)32 File (java.io.File)31 IOException (java.io.IOException)16 HashMap (java.util.HashMap)5 Properties (java.util.Properties)4 GeneralSecurityException (java.security.GeneralSecurityException)3 ArrayList (java.util.ArrayList)3 OrderedProperties (net.i2p.util.OrderedProperties)3 SecureFile (net.i2p.util.SecureFile)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 PrivateKey (java.security.PrivateKey)2 Map (java.util.Map)2 StringTokenizer (java.util.StringTokenizer)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 SU3File (net.i2p.crypto.SU3File)2 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)2 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 InetSocketAddress (java.net.InetSocketAddress)1