Skip to content

Commit

Permalink
Add node() method
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Jan 20, 2025
1 parent 30eca86 commit 4849cf4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion jpos/src/main/java/org/jpos/util/PGPHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.bouncycastle.openpgp.operator.bc.*;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
import org.jpos.core.Environment;
import org.jpos.iso.ISOUtil;
import org.jpos.log.evt.License;
import org.jpos.q2.Q2;
Expand All @@ -45,9 +46,19 @@ public class PGPHelper {
private static KeyFingerPrintCalculator fingerPrintCalculator = new BcKeyFingerprintCalculator();
private static final String PUBRING = "META-INF/.pgp/pubring.asc";
private static final String SIGNER = "[email protected]";
private static int node;
static {
if(Security.getProvider("BC") == null)
Security.addProvider(new BouncyCastleProvider());

String nodeString = Environment.get("${q2.node:1}");
Pattern pattern = Pattern.compile("\\d+");

node = (nodeString == null || nodeString.isEmpty())
? 1
: (pattern.matcher(nodeString).find()
? Integer.parseInt(pattern.matcher(nodeString).group())
: 1);
}

private static boolean verifySignature(InputStream in, PGPPublicKey pk) throws IOException, PGPException {
Expand Down Expand Up @@ -205,7 +216,9 @@ public static int checkLicense() {
}
matcher = p2.matcher(s);
if (matcher.find() && matcher.groupCount() == 2) {
rc |= Integer.parseInt(matcher.group(2));
int n = Integer.parseInt(matcher.group(2));
node = n >= node ? node : 0;
rc |= n;
}
if (s.contains(h)) {
rc &= 0xEFFFF;
Expand Down Expand Up @@ -248,6 +261,10 @@ public static String getLicenseeHash() throws IOException, NoSuchAlgorithmExcept
return ISOUtil.hexString(hash(getLicensee()));
}

public static int node () {
return node;
}

/**
* Simple PGP encryptor between byte[].
*
Expand Down

0 comments on commit 4849cf4

Please sign in to comment.