Util: Fix EepGet allowCaching parameter

Add SSLEepGet method to force DoH on/off
This commit is contained in:
zzz
2020-10-26 12:22:54 +00:00
parent 7823001594
commit af97eedcbb
2 changed files with 19 additions and 3 deletions

View File

@ -34,7 +34,6 @@ import net.i2p.data.Base32;
import net.i2p.data.Base64;
import net.i2p.data.ByteArray;
import net.i2p.data.DataHelper;
import net.i2p.util.InternalSocket;
/**
* EepGet [-p 127.0.0.1:4444]
@ -174,6 +173,7 @@ public class EepGet {
_bytesRemaining = -1;
_fetchHeaderTimeout = CONNECT_TIMEOUT;
_listeners = new ArrayList<StatusListener>(1);
_allowCaching = allowCaching;
_etag = etag;
_lastModified = lastModified;
_etagOrig = etag;

View File

@ -99,6 +99,7 @@ public class SSLEepGet extends EepGet {
/** may be null if init failed */
private SavingTrustManager _stm;
private final ProxyType _proxyType;
private int _forceDoH;
private static final String CERT_DIR = "certificates/ssl";
private static final String PROP_USE_DNS_OVER_HTTPS = "eepget.useDNSOverHTTPS";
@ -547,6 +548,15 @@ public class SSLEepGet extends EepGet {
return new SSLState(_sslContext);
}
/**
* Override the config setting, force DNSoverHTTPS on or off
* Call before the fetch.
* @since 0.9.49
*/
public void forceDNSOverHTTPS(boolean on) {
_forceDoH = on ? 2 : 1;
}
///// end of all the SSL stuff
///// start of overrides
@ -732,10 +742,16 @@ public class SSLEepGet extends EepGet {
port = 443;
String originalHost = host;
boolean useDNSOverHTTPS = _context.getProperty(PROP_USE_DNS_OVER_HTTPS, DEFAULT_USE_DNS_OVER_HTTPS);
boolean useDNSOverHTTPS;
if (_forceDoH == 2)
useDNSOverHTTPS = true;
else if (_forceDoH == 1)
useDNSOverHTTPS = false;
else
useDNSOverHTTPS = _context.getProperty(PROP_USE_DNS_OVER_HTTPS, DEFAULT_USE_DNS_OVER_HTTPS);
// This duplicates checks in DNSOverHTTPS.lookup() but do it here too so
// we don't even construct it if we don't need it
if (useDNSOverHTTPS && !host.equals("dns.google.com") && !Addresses.isIPAddress(host)) {
if (useDNSOverHTTPS && !host.equals("dns.google") && !Addresses.isIPAddress(host)) {
DNSOverHTTPS doh = new DNSOverHTTPS(_context, getSSLState());
String ip = doh.lookup(host);
if (ip != null)