Search in sources :

Example 26 with SecureDirectory

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

Example 27 with SecureDirectory

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

Example 28 with SecureDirectory

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

Example 29 with SecureDirectory

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

Example 30 with SecureDirectory

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