/** * The conmment file for a torrent * @param confDir the config directory * @param ih 20-byte infohash * @since 0.9.31 */ private static File commentFile(File confDir, byte[] ih) { String hex = I2PSnarkUtil.toHex(ih); File subdir = new SecureDirectory(confDir, SUBDIR_PREFIX + B64.charAt((ih[0] >> 2) & 0x3f)); return new File(subdir, hex + COMMENT_FILE_SUFFIX); }
/** * Sets file to mode 600 if the file is created */ @Override public boolean createNewFile() throws IOException { boolean rv = super.createNewFile(); if (rv) setPerms(); return rv; }
/** * Tries to set the permissions to 700, * ignores errors */ protected void setPerms() { if (!SecureFileOutputStream.canSetPerms()) return; try { setReadable(false, false); setReadable(true, true); setWritable(false, false); setWritable(true, true); if (isNotWindows) { setExecutable(false, false); setExecutable(true, true); } } catch (Throwable t) { // NoSuchMethodException or NoSuchMethodError if we somehow got the // version detection wrong or the JVM doesn't support it } } }
String gentooWarning = null; if (dir != null) { dirf = new SecureDirectory(dir); } else { String home = System.getProperty("user.home"); if (appdata != null) home = appdata; dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT_WINDOWS); } else if (SystemVersion.isMac()) { String appdata = "/Library/Application Support/"; File old = new File(home,WORKING_DIR_DEFAULT); if (old.exists() && old.isDirectory()) dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT); else { home = home+appdata; dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT_MAC); File d1 = new SecureDirectory(home, WORKING_DIR_DEFAULT); File d2 = new SecureDirectory(home, WORKING_DIR_DEFAULT_DAEMON); boolean e1 = isSetup(d1); boolean e2 = isSetup(d2); dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT_DAEMON); dirf = new SecureDirectory(home, WORKING_DIR_DEFAULT); success &= (new SecureDirectory(dirf, "docs")).mkdir();
/** * Sets directory to mode 700 if the directory is created */ @Override public boolean mkdir() { boolean rv = super.mkdir(); if (rv) setPerms(); return rv; }
/** * Sets directory to mode 700 if the directory is created * Does NOT change the mode of other created directories */ @Override public boolean mkdirs() { boolean rv = super.mkdirs(); if (rv) setPerms(); return rv; }
/** * The config file for a torrent * @param confDir the config directory * @param ih 20-byte infohash * @since 0.9.15 */ private static File configFile(File confDir, byte[] ih) { String hex = I2PSnarkUtil.toHex(ih); File subdir = new SecureDirectory(confDir, SUBDIR_PREFIX + B64.charAt((ih[0] >> 2) & 0x3f)); return new File(subdir, hex + CONFIG_FILE_SUFFIX); }
public ProfilePersistenceHelper(RouterContext ctx) { _context = ctx; _log = ctx.logManager().getLog(ProfilePersistenceHelper.class); String dir = _context.getProperty(PROP_PEER_PROFILE_DIR, DEFAULT_PEER_PROFILE_DIR); _profileDir = new SecureDirectory(_context.getRouterDir(), dir); if (!_profileDir.exists()) _profileDir.mkdirs(); for (int j = 0; j < B64.length(); j++) { File subdir = new SecureDirectory(_profileDir, DIR_PREFIX + B64.charAt(j)); if (!subdir.exists()) subdir.mkdir(); } }
public File getDataDir() { String dir = _config.getProperty(PROP_DIR, _contextName); File f; if (areFilesPublic()) f = new File(dir); else f = new SecureDirectory(dir); if (!f.isAbsolute()) { if (areFilesPublic()) f = new File(_context.getAppDir(), dir); else f = new SecureDirectory(_context.getAppDir(), dir); } return f; }
_tmpDirRand.nextBytes(rand); String f = "i2p-" + Base64.encode(rand) + ".tmp"; _tmpDir = new SecureDirectory(d, f); if (_tmpDir.exists()) { } else { System.err.println("WARNING: Could not create temp dir " + _tmpDir.getAbsolutePath()); _tmpDir = new SecureDirectory(_routerDir, "tmp"); _tmpDir.mkdirs(); if (!_tmpDir.exists())
private File getDbDir(String dbDir) throws IOException { File f = new SecureDirectory(_context.getRouterDir(), dbDir); if (!f.exists()) { boolean created = f.mkdirs(); if (!created) throw new IOException("Unable to create the DB directory [" + f.getAbsolutePath() + "]"); } if (!f.isDirectory()) throw new IOException("DB directory [" + f.getAbsolutePath() + "] is not a directory!"); if (!f.canRead()) throw new IOException("DB directory [" + f.getAbsolutePath() + "] is not readable!"); if (!f.canWrite()) throw new IOException("DB directory [" + f.getAbsolutePath() + "] is not writable!"); if (_flat) { unmigrate(f); } else { for (int j = 0; j < B64.length(); j++) { File subdir = new SecureDirectory(f, DIR_PREFIX + B64.charAt(j)); if (!subdir.exists()) subdir.mkdir(); } File routerInfoFiles[] = f.listFiles(RI_FILTER); if (routerInfoFiles != null) migrate(f, routerInfoFiles); } return f; }
File targetFile = new SecureDirectory(targetDir, src.getName()); if (!src.isDirectory()) return copyFile(src, targetFile);
/** * 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); }
public void runJob() { String keyDir = getContext().getProperty(PROP_KEYDIR, DEFAULT_KEYDIR); File dir = new SecureDirectory(getContext().getRouterDir(), keyDir); if (!dir.exists()) dir.mkdirs(); if (dir.exists() && dir.isDirectory() && dir.canRead() && dir.canWrite()) { synchronized(KeyManager.this) { syncKeys(dir); } } else { _log.log(Log.CRIT, "Unable to synchronize keys in " + keyDir + " - permissions problem?"); } }
/** * Save the CRL just in case. * @param ksdir parent of directory to save in * @since 0.9.25 */ private void exportCRL(File ksdir, X509CRL crl) { File sdir = new SecureDirectory(ksdir, CRL_DIR); if (sdir.exists() || sdir.mkdirs()) { String name = KEYSTORE_PREFIX + _fname.replace("@", "_at_") + '-' + System.currentTimeMillis() + CRL_SUFFIX; File out = new File(sdir, name); boolean success = CertUtil.saveCRL(crl, out); if (success) { _log.logAlways(Log.INFO, "Created certificate revocation list (CRL) for netdb family \"" + _fname + "\" in file: " + out.getAbsolutePath() + "\n" + "Back up the keystore and CRL files and keep them secure.\n" + "If your private key is ever compromised, give the CRL to an I2P developer for publication."); } else { _log.error("Error saving family key CRL"); } } else { _log.error("Error saving family key CRL"); } }
if (parent != null) { if (!parent.exists()) { File sd = new SecureDirectory(parent.getAbsolutePath()); boolean ok = sd.mkdirs(); if (!ok) {
File dirf = new SecureDirectory(dir);
File dir = ks.getParentFile(); if (dir != null && !dir.exists()) { File sdir = new SecureDirectory(dir.getAbsolutePath()); if (!sdir.mkdirs()) throw new IOException("Can't create directory " + dir);
File dir = ks.getParentFile(); if (!dir.exists()) { File sdir = new SecureDirectory(dir.getAbsolutePath()); if (!sdir.mkdirs()) throw new IOException("Unable to create keystore " + ks);
/** * 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"); } }