From 88852672341997c0ccad04ee89d76971a97fd205 Mon Sep 17 00:00:00 2001 From: Jan Henning Date: Thu, 28 Nov 2024 19:15:54 +0100 Subject: [PATCH 1/2] Fix TestInterfaceSelector failing with InaccessibleObjectException --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 8dcfb76..1584c71 100755 --- a/pom.xml +++ b/pom.xml @@ -114,6 +114,7 @@ --add-opens com.javax0.license3j/javax0.license3j.io=ALL-UNNAMED --add-opens com.javax0.license3j/javax0.license3j.parsers=ALL-UNNAMED --add-opens com.javax0.license3j/javax0.license3j.hardware=ALL-UNNAMED + --add-opens java.base/java.lang=ALL-UNNAMED From ddde5b53a344587840257fa5c7af91090c96b6b9 Mon Sep 17 00:00:00 2001 From: Jan Henning Date: Wed, 27 Nov 2024 23:34:32 +0100 Subject: [PATCH 2/2] Pass exact serialised key algorithm string into isOK function When faced with a simple algorithm string like e.g. "RSA" (which is all what we get from querying PublicKey.getAlgorithm()), Android doesn't use the exact same default cipher mode that gets used on Desktop (where the license was probably originally created). To fix that, we need to extract the original full algorithm specification string stored in the serialised license key and pass that to the isOK function. --- src/main/java/javax0/license3j/License.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/javax0/license3j/License.java b/src/main/java/javax0/license3j/License.java index 3f963fb..d75deb5 100644 --- a/src/main/java/javax0/license3j/License.java +++ b/src/main/java/javax0/license3j/License.java @@ -139,7 +139,8 @@ public void sign(PrivateKey key, String digest) throws NoSuchAlgorithmException, */ public boolean isOK(byte[] key) { try { - return isOK(LicenseKeyPair.Create.from(key, Modifier.PUBLIC).getPair().getPublic()); + LicenseKeyPair lkp = LicenseKeyPair.Create.from(key, Modifier.PUBLIC); + return isOK(lkp.getPair().getPublic(), lkp.cipher()); } catch (Exception e) { return false; } @@ -154,11 +155,15 @@ public boolean isOK(byte[] key) { * false}. */ public boolean isOK(PublicKey key) { + return isOK(key, key.getAlgorithm()); + } + + private boolean isOK(PublicKey key, String algorithm) { try { final var digester = MessageDigest.getInstance(get(DIGEST_KEY).getString()); final var ser = unsigned(); final var digestValue = digester.digest(ser); - final var cipher = Cipher.getInstance(key.getAlgorithm()); + final var cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.DECRYPT_MODE, key); final var sigDigest = cipher.doFinal(getSignature()); return Arrays.equals(digestValue, sigDigest);