Skip to content

Commit

Permalink
Merge branch 'master' into feature/jakarta
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-kumar authored Oct 26, 2024
2 parents d68a23e + d290014 commit 1b79d6f
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import network.oxalis.vefa.peppol.lookup.util.DynamicHostnameGenerator;
import network.oxalis.vefa.peppol.lookup.util.EncodingUtils;
import network.oxalis.vefa.peppol.mode.Mode;
import org.apache.commons.lang3.StringUtils;
import org.xbill.DNS.*;

import java.net.InetAddress;
Expand All @@ -44,8 +45,9 @@
*/
public class BdxlLocator extends AbstractLocator {

private long timeout = 30L;
private int maxRetries = 3;
private final long timeout;
private final int maxRetries;
private final boolean enablePublicDNS;

private static final List<InetAddress> customDNSServers = new ArrayList<>();
//Google DNS: faster, supported by multiple data centers all around the world
Expand All @@ -62,10 +64,11 @@ public BdxlLocator(Mode mode) {
mode.getString("lookup.locator.bdxl.prefix"),
mode.getString("lookup.locator.hostname"),
mode.getString("lookup.locator.bdxl.algorithm"),
EncodingUtils.get(mode.getString("lookup.locator.bdxl.encoding"))
EncodingUtils.get(mode.getString("lookup.locator.bdxl.encoding")),
Long.parseLong(mode.getString("lookup.locator.bdxl.timeout")),
Integer.parseInt(mode.getString("lookup.locator.bdxl.maxRetries")),
Boolean.parseBoolean(mode.getString("lookup.locator.bdxl.enablePublicDNS"))
);
maxRetries = Integer.parseInt(mode.getString("lookup.locator.bdxl.maxRetries"));
timeout = Long.parseLong(mode.getString("lookup.locator.bdxl.timeout"));

try {
GOOGLE_PRIMARY_DNS = InetAddress.getByAddress((new byte[]{(byte) (8 & 0xff), (byte) (8 & 0xff), (byte) (8 & 0xff), (byte) (8 & 0xff)}));
Expand All @@ -77,10 +80,12 @@ public BdxlLocator(Mode mode) {
//Unable to initialize Custom DNS server
}

customDNSServers.add(GOOGLE_PRIMARY_DNS);
customDNSServers.add(GOOGLE_SECONDARY_DNS);
customDNSServers.add(CLOUDFLARE_PRIMARY_DNS);
customDNSServers.add(CLOUDFLARE_SECONDARY_DNS);
if (enablePublicDNS) {
customDNSServers.add(GOOGLE_PRIMARY_DNS);
customDNSServers.add(GOOGLE_SECONDARY_DNS);
customDNSServers.add(CLOUDFLARE_PRIMARY_DNS);
customDNSServers.add(CLOUDFLARE_SECONDARY_DNS);
}
}

/**
Expand All @@ -90,7 +95,7 @@ public BdxlLocator(Mode mode) {
*/
@SuppressWarnings("unused")
public BdxlLocator(String hostname) {
this(hostname, "SHA-256");
this("", hostname, "SHA-256", 30L, 3, false);
}

/**
Expand All @@ -100,7 +105,7 @@ public BdxlLocator(String hostname) {
* @param digestAlgorithm Algorithm used for generation of hostname.
*/
public BdxlLocator(String hostname, String digestAlgorithm) {
this("", hostname, digestAlgorithm);
this("", hostname, digestAlgorithm, 30L, 3, false);
}

/**
Expand All @@ -109,9 +114,12 @@ public BdxlLocator(String hostname, String digestAlgorithm) {
* @param prefix Value attached in front of calculated hash.
* @param hostname Hostname used as base for lookup.
* @param digestAlgorithm Algorithm used for generation of hostname.
* @param timeout Lookup timeout
* @param maxRetries Maximum number of retries
* @param enablePublicDNS Enable custom DNS lookup
*/
public BdxlLocator(String prefix, String hostname, String digestAlgorithm) {
this(prefix, hostname, digestAlgorithm, BaseEncoding.base32());
public BdxlLocator(String prefix, String hostname, String digestAlgorithm, long timeout, int maxRetries, boolean enablePublicDNS) {
this(prefix, hostname, digestAlgorithm, BaseEncoding.base32(), timeout, maxRetries, enablePublicDNS);
}

/**
Expand All @@ -121,8 +129,14 @@ public BdxlLocator(String prefix, String hostname, String digestAlgorithm) {
* @param hostname Hostname used as base for lookup.
* @param digestAlgorithm Algorithm used for generation of hostname.
* @param encoding Encoding of hash for hostname.
* @param timeout Lookup timeout
* @param maxRetries Maximum number of retries
* @param enablePublicDNS Enable custom DNS lookup
*/
public BdxlLocator(String prefix, String hostname, String digestAlgorithm, BaseEncoding encoding) {
public BdxlLocator(String prefix, String hostname, String digestAlgorithm, BaseEncoding encoding, long timeout, int maxRetries, boolean enablePublicDNS) {
this.timeout = timeout;
this.maxRetries = maxRetries;
this.enablePublicDNS = enablePublicDNS;
hostnameGenerator = new DynamicHostnameGenerator(prefix, hostname, digestAlgorithm, encoding);
}

Expand All @@ -131,8 +145,21 @@ public URI lookup(ParticipantIdentifier participantIdentifier) throws LookupExce
// Create hostname for participant identifier.
String hostname = hostnameGenerator.generate(participantIdentifier).replaceAll("=*", "");

ExtendedResolver extendedResolver;
try {
ExtendedResolver extendedResolver = CustomExtendedDNSResolver.createExtendedResolver(customDNSServers, timeout, maxRetries);
if(enablePublicDNS) {
extendedResolver = CustomExtendedDNSResolver.createExtendedResolver(customDNSServers, timeout, maxRetries);
} else {
extendedResolver = new ExtendedResolver();
try {
if (StringUtils.isNotBlank(hostname)) {
extendedResolver.addResolver(new SimpleResolver(hostname));
}
} catch (final UnknownHostException ex) {
//Primary DNS lookup fail, now try with default resolver
}
extendedResolver.addResolver (Lookup.getDefaultResolver ());
}
extendedResolver.setRetries(maxRetries);
extendedResolver.setTimeout(Duration.ofSeconds(timeout));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import network.oxalis.vefa.peppol.lookup.api.NotFoundException;
import network.oxalis.vefa.peppol.lookup.util.DynamicHostnameGenerator;
import network.oxalis.vefa.peppol.mode.Mode;
import org.apache.commons.lang3.StringUtils;
import org.xbill.DNS.ExtendedResolver;
import org.xbill.DNS.Lookup;
import org.xbill.DNS.SimpleResolver;
import org.xbill.DNS.TextParseException;

import java.net.InetAddress;
Expand All @@ -37,8 +39,9 @@

public class BusdoxLocator extends AbstractLocator {

private long timeout = 30L;
private int maxRetries = 3;
private final long timeout;
private final int maxRetries;
private final boolean enablePublicDNS;

private static final List<InetAddress> customDNSServers = new ArrayList<>();
//Google DNS: faster, supported by multiple data centers all around the world
Expand All @@ -54,10 +57,11 @@ public BusdoxLocator(Mode mode) {
this(
mode.getString("lookup.locator.busdox.prefix"),
mode.getString("lookup.locator.hostname"),
mode.getString("lookup.locator.busdox.algorithm")
mode.getString("lookup.locator.busdox.algorithm"),
Long.parseLong(mode.getString("lookup.locator.busdox.timeout")),
Integer.parseInt(mode.getString("lookup.locator.busdox.maxRetries")),
Boolean.parseBoolean(mode.getString("lookup.locator.busdox.enablePublicDNS"))
);
maxRetries = Integer.parseInt(mode.getString("lookup.locator.busdox.maxRetries"));
timeout = Long.parseLong(mode.getString("lookup.locator.busdox.timeout"));

try {
GOOGLE_PRIMARY_DNS = InetAddress.getByAddress((new byte[]{(byte) (8 & 0xff), (byte) (8 & 0xff), (byte) (8 & 0xff), (byte) (8 & 0xff)}));
Expand All @@ -69,18 +73,23 @@ public BusdoxLocator(Mode mode) {
//Unable to initialize Custom DNS server
}

customDNSServers.add(GOOGLE_PRIMARY_DNS);
customDNSServers.add(GOOGLE_SECONDARY_DNS);
customDNSServers.add(CLOUDFLARE_PRIMARY_DNS);
customDNSServers.add(CLOUDFLARE_SECONDARY_DNS);
if (enablePublicDNS) {
customDNSServers.add(GOOGLE_PRIMARY_DNS);
customDNSServers.add(GOOGLE_SECONDARY_DNS);
customDNSServers.add(CLOUDFLARE_PRIMARY_DNS);
customDNSServers.add(CLOUDFLARE_SECONDARY_DNS);
}
}

@SuppressWarnings("unused")
public BusdoxLocator(String hostname) {
this("B-", hostname, "MD5");
this("B-", hostname, "MD5", 30L, 3, false);
}

public BusdoxLocator(String prefix, String hostname, String algorithm) {
public BusdoxLocator(String prefix, String hostname, String algorithm, long timeout, int maxRetries, boolean enablePublicDNS) {
this.timeout = timeout;
this.maxRetries = maxRetries;
this.enablePublicDNS = enablePublicDNS;
hostnameGenerator = new DynamicHostnameGenerator(prefix, hostname, algorithm);
}

Expand All @@ -89,8 +98,21 @@ public URI lookup(ParticipantIdentifier participantIdentifier) throws LookupExce
// Create hostname for participant identifier.
String hostname = hostnameGenerator.generate(participantIdentifier);

ExtendedResolver extendedResolver;
try {
ExtendedResolver extendedResolver = CustomExtendedDNSResolver.createExtendedResolver(customDNSServers, timeout, maxRetries);
if(enablePublicDNS) {
extendedResolver = CustomExtendedDNSResolver.createExtendedResolver(customDNSServers, timeout, maxRetries);
} else {
extendedResolver = new ExtendedResolver();
try {
if (StringUtils.isNotBlank(hostname)) {
extendedResolver.addResolver(new SimpleResolver(hostname));
}
} catch (final UnknownHostException ex) {
//Primary DNS lookup fail, now try with default resolver
}
extendedResolver.addResolver (Lookup.getDefaultResolver ());
}
extendedResolver.setRetries(maxRetries);
extendedResolver.setTimeout(Duration.ofSeconds(timeout));

Expand Down
6 changes: 4 additions & 2 deletions peppol-lookup/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ mode.default.lookup.locator = {
prefix: ""
algorithm: SHA-256
encoding: base32
maxRetries: 3
timeout: 30
maxRetries: 3
enablePublicDNS: false
}

busdox: {
prefix: "B-"
algorithm: MD5
maxRetries: 3
timeout: 30
maxRetries: 3
enablePublicDNS: false
}
}

Expand Down
59 changes: 29 additions & 30 deletions peppol-security/src/test/resources/ap-test.cer
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
-----BEGIN CERTIFICATE-----
MIIFvzCCA6egAwIBAgIQWd+YpUNgpRbU0EW3hC/uETANBgkqhkiG9w0BAQsFADBr
MIIFwTCCA6mgAwIBAgIQZ1Cu7re4rmdelnaYimpAsDANBgkqhkiG9w0BAQsFADBr
MQswCQYDVQQGEwJCRTEZMBcGA1UEChMQT3BlblBFUFBPTCBBSVNCTDEWMBQGA1UE
CxMNRk9SIFRFU1QgT05MWTEpMCcGA1UEAxMgUEVQUE9MIEFDQ0VTUyBQT0lOVCBU
RVNUIENBIC0gRzIwHhcNMjQwMjE3MDAwMDAwWhcNMjYwMjA2MjM1OTU5WjBMMQsw
CQYDVQQGEwJGSTEQMA4GA1UECgwHQmFzd2FyZTEXMBUGA1UECwwOUEVQUE9MIFRF
U1QgQVAxEjAQBgNVBAMMCVBPUDAwMDAxM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D8RbQhUAk1AsmfFc6+2v5EeBLTa2VznnH3PGQ7ZLmx9PWBcpzTkYn
1WmHiza81qzyNrQUKpq0w6fBFZudJ1qE10LU+5IEiAYilDxKvxbfACPBQ835/i1E
SeGG0FDFxuy4f/lQHXIfK31h3VdyD2llNTMBQ/kVsT9asSxz3m7Kn5IVA4uK8oWK
gxoOc7clPjodEtac4cNdTZToHblQL4ZzGQq0U1o9TCydjKe0Xg==
-----END CERTIFICATE-----

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
<commons-certvalidator.version>4.2.1-SNAPSHOT</commons-certvalidator.version>
<peppol-lib.version>2.2.1-SNAPSHOT</peppol-lib.version>
<httpclient.version>4.5.13</httpclient.version>
<dnsjava.version>3.6.2</dnsjava.version>
<guava.version>32.0.1-jre</guava.version>
<dnsjava.version>3.6.0</dnsjava.version>
<guava.version>33.3.1-jre</guava.version>
<typesafe-config.version>1.4.2</typesafe-config.version>
<javax-mail.version>1.4.7</javax-mail.version>
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
Expand Down

0 comments on commit 1b79d6f

Please sign in to comment.