Search in sources :

Example 76 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class HostCheckHandler method handle.

/**
 *  Block by Host header,
 *  redirect HTTP to HTTPS,
 *  pass everything else to the delegate.
 */
public void handle(String pathInContext, Request baseRequest, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
    String host = httpRequest.getHeader("Host");
    if (!allowHost(host)) {
        Log log = _context.logManager().getLog(HostCheckHandler.class);
        host = getHost(host);
        String s = "Console request denied.\n" + "    To allow access using the hostname \"" + host + "\", add the line \"" + PROP_ALLOWED_HOSTS + '=' + host + "\" in the file " + RunStandalone.APP_CONFIG_FILE.getAbsolutePath() + " and restart.";
        log.logAlways(Log.WARN, s);
        httpResponse.sendError(403, s);
        baseRequest.setHandled(true);
        return;
    }
}
Also used : Log(net.i2p.util.Log)

Example 77 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class SessionConfig method verifySignature.

/**
 * Verify that the signature matches the destination's signing public key.
 *
 * Note that this also returns false if the creation date is too far in the
 * past or future. See tooOld() and getCreationDate().
 *
 * @return true only if the signature matches
 */
public boolean verifySignature() {
    if (getSignature() == null) {
        // if (_log.shouldLog(Log.WARN)) _log.warn("Signature is null!");
        return false;
    }
    if (getDestination() == null) {
        // if (_log.shouldLog(Log.WARN)) _log.warn("Destination is null!");
        return false;
    }
    if (getCreationDate() == null) {
        // if (_log.shouldLog(Log.WARN)) _log.warn("Date is null!");
        return false;
    }
    if (tooOld()) {
        // if (_log.shouldLog(Log.WARN)) _log.warn("Too old!");
        return false;
    }
    byte[] data = getBytes();
    if (data == null) {
        // if (_log.shouldLog(Log.WARN)) _log.warn("Bytes could not be found");
        return false;
    }
    boolean ok = DSAEngine.getInstance().verifySignature(getSignature(), data, getDestination().getSigningPublicKey());
    if (!ok) {
        Log log = I2PAppContext.getGlobalContext().logManager().getLog(SessionConfig.class);
        if (log.shouldLog(Log.WARN))
            log.warn("DSA signature failed!");
    }
    return ok;
}
Also used : Log(net.i2p.util.Log)

Example 78 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class GeoIPv6 method main.

/**
 *  Merge and compress CSV files to I2P compressed format
 *
 *  GeoIPv6 infile1.csv[.gz] [infile2.csv[.gz]...] outfile.dat.gz
 *
 *  Used to create the file for distribution, do not comment out
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.err.println("Usage: GeoIPv6 infile1.csv [infile2.csv...] outfile.dat.gz");
        System.exit(1);
    }
    List<File> infiles = new ArrayList<File>();
    for (int i = 0; i < args.length - 1; i++) {
        infiles.add(new File(args[i]));
    }
    File outfile = new File(args[args.length - 1]);
    boolean success = compressGeoIPv6CSVFiles(infiles, outfile);
    if (!success) {
        System.err.println("Failed");
        System.exit(1);
    }
    // readback for testing
    readGeoIPFile(outfile, new Long[] { Long.MAX_VALUE }, Collections.<String, String>emptyMap(), new Log(GeoIPv6.class));
}
Also used : Log(net.i2p.util.Log) ArrayList(java.util.ArrayList) File(java.io.File)

Example 79 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class GeoIPv6 method readGeoIPFile.

/**
 * Lookup search items in the geoip file.
 * See below for format.
 *
 * @param search a sorted array of IPs to search
 * @return an array of country codes, same order as the search param,
 *         or a zero-length array on failure
 */
public static String[] readGeoIPFile(I2PAppContext context, Long[] search, Map<String, String> codeCache) {
    Log log = context.logManager().getLog(GeoIPv6.class);
    File geoFile = new File(context.getBaseDir(), GEOIP_DIR_DEFAULT);
    geoFile = new File(geoFile, GEOIP_FILE_DEFAULT);
    if (!geoFile.exists()) {
        if (log.shouldLog(Log.WARN))
            log.warn("GeoIP file not found: " + geoFile.getAbsolutePath());
        return new String[0];
    }
    return readGeoIPFile(geoFile, search, codeCache, log);
}
Also used : Log(net.i2p.util.Log) File(java.io.File)

Example 80 with Log

use of net.i2p.util.Log in project i2p.i2p by i2p.

the class MarkLiveliness method ping.

private void ping() {
    FileOutputStream fos = null;
    try {
        fos = new SecureFileOutputStream(_pingFile);
        fos.write(DataHelper.getASCII(Long.toString(System.currentTimeMillis())));
    } catch (IOException ioe) {
        if (!_errorLogged) {
            Log log = _router.getContext().logManager().getLog(MarkLiveliness.class);
            log.logAlways(Log.WARN, "Error writing to ping file " + _pingFile + ": " + ioe);
            _errorLogged = true;
        }
    } finally {
        if (fos != null)
            try {
                fos.close();
            } catch (IOException ioe) {
            }
    }
}
Also used : Log(net.i2p.util.Log) FileOutputStream(java.io.FileOutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) IOException(java.io.IOException)

Aggregations

Log (net.i2p.util.Log)94 IOException (java.io.IOException)30 File (java.io.File)13 Properties (java.util.Properties)11 DataFormatException (net.i2p.data.DataFormatException)11 FileInputStream (java.io.FileInputStream)7 GeneralSecurityException (java.security.GeneralSecurityException)7 ArrayList (java.util.ArrayList)7 Hash (net.i2p.data.Hash)6 HashMap (java.util.HashMap)5 InputStream (java.io.InputStream)4 EventLog (net.i2p.router.util.EventLog)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 I2PAppContext (net.i2p.I2PAppContext)3 I2PSession (net.i2p.client.I2PSession)3 I2PSessionException (net.i2p.client.I2PSessionException)3 SigType (net.i2p.crypto.SigType)3 RouterInfo (net.i2p.data.router.RouterInfo)3