Changeset 9eec357 for core/java


Ignore:
Timestamp:
May 11, 2019 1:37:18 PM (14 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
adb1c6f
Parents:
f6efdcea
Message:

Utils: Allow absolute path to certs in I2PSSLSocketFactory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/I2PSSLSocketFactory.java

    rf6efdcea r9eec357  
    238238
    239239    /**
    240      * @param relativeCertPath e.g. "certificates/i2cp"
     240     * @param relativeCertPath e.g. "certificates/i2cp"; as of 0.9.41, may be absolute
    241241     * @since 0.9.9 was static
    242242     */
     
    469469    /**
    470470     *  Loads certs from
    471      *  the ~/.i2p/certificates/ and $I2P/certificates/ directories.
     471     *  the ~/.i2p/certificates/ and $I2P/certificates/ directories,
     472     *  or from the absolute path given.
     473     *
     474     *  @param relativeCertPath e.g. "certificates/i2cp"; as of 0.9.41, may be absolute
    472475     */
    473476    private static SSLSocketFactory initSSLContext(I2PAppContext context, boolean loadSystemCerts, String relativeCertPath)
     
    488491        }
    489492
    490         File dir = new File(context.getConfigDir(), relativeCertPath);
     493        File dir = new File(relativeCertPath);
     494        boolean wasAbsolute = dir.isAbsolute();
     495        if (!wasAbsolute)
     496            dir = new File(context.getConfigDir(), relativeCertPath);
    491497        int adds = KeyStoreUtil.addCerts(dir, ks);
    492498        int totalAdds = adds;
     
    496502        }
    497503
    498         File dir2 = new File(context.getBaseDir(), relativeCertPath);
    499         if (!dir.getAbsolutePath().equals(dir2.getAbsolutePath())) {
    500             adds = KeyStoreUtil.addCerts(dir2, ks);
    501             totalAdds += adds;
    502             if (adds > 0) {
    503                 if (log.shouldLog(Log.INFO))
    504                     log.info("Loaded " + adds + " trusted certificates from " + dir.getAbsolutePath());
     504        File dir2;
     505        if (!wasAbsolute) {
     506            dir2 = new File(context.getBaseDir(), relativeCertPath);
     507            if (!dir.getAbsolutePath().equals(dir2.getAbsolutePath())) {
     508                adds = KeyStoreUtil.addCerts(dir2, ks);
     509                totalAdds += adds;
     510                if (adds > 0) {
     511                    if (log.shouldLog(Log.INFO))
     512                        log.info("Loaded " + adds + " trusted certificates from " + dir.getAbsolutePath());
     513                }
    505514            }
     515        } else {
     516            // for logging below
     517            dir2 = dir;
    506518        }
    507519        if (totalAdds > 0 || loadSystemCerts) {
Note: See TracChangeset for help on using the changeset viewer.