diff --git a/autobahn/build.gradle b/autobahn/build.gradle index 014e2fd8..ba425784 100644 --- a/autobahn/build.gradle +++ b/autobahn/build.gradle @@ -27,10 +27,7 @@ dependencies { implementation 'org.web3j:core:5.0.0' implementation 'org.web3j:abi:5.0.0' implementation 'org.web3j:utils:5.0.0' - if (IS_ANDROID) { - implementation 'com.github.joshjdevl.libsodiumjni:libsodium-jni-aar:2.0.2' - } else { - implementation 'com.github.joshjdevl.libsodiumjni:libsodium-jni:2.0.2' + if (!IS_ANDROID) { implementation 'org.json:json:20240205' implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.5' } @@ -188,7 +185,7 @@ afterEvaluate { artifactId ARTIFACT_ANDROID } else { from components.java - artifactId IS_NEXT ? ARTIFACT_NEXT: ARTIFACT_JAVA + artifactId IS_NEXT ? ARTIFACT_NEXT : ARTIFACT_JAVA } artifact sourcesJar diff --git a/autobahn/src/main/java/xbr/network/crypto/SealedBox.java b/autobahn/src/main/java/xbr/network/crypto/SealedBox.java index 0fcbba4e..c0c34665 100644 --- a/autobahn/src/main/java/xbr/network/crypto/SealedBox.java +++ b/autobahn/src/main/java/xbr/network/crypto/SealedBox.java @@ -7,11 +7,6 @@ import org.bouncycastle.crypto.params.ParametersWithIV; import org.bouncycastle.math.ec.rfc7748.X25519; import org.bouncycastle.util.Arrays; -import org.libsodium.jni.encoders.Encoder; - -import static org.libsodium.jni.SodiumConstants.NONCE_BYTES; -import static org.libsodium.jni.SodiumConstants.PUBLICKEY_BYTES; -import static org.libsodium.jni.SodiumConstants.SECRETKEY_BYTES; import io.crossbar.autobahn.utils.Pair; import xbr.network.Util; @@ -19,6 +14,7 @@ public class SealedBox { private static final int MAC_BYTES = 16; + private static int PUBLICKEY_BYTES = 32; private static final int SEAL_BYTES = PUBLICKEY_BYTES + MAC_BYTES; private byte[] publicKey; @@ -32,9 +28,6 @@ public SealedBox(byte[] publicKey) { this.privateKey = null; } - public SealedBox(String publicKey, Encoder encoder) { - this(encoder.decode(publicKey)); - } public SealedBox(byte[] publicKey, byte[] privateKey) { if (publicKey == null) { @@ -47,10 +40,6 @@ public SealedBox(byte[] publicKey, byte[] privateKey) { this.privateKey = privateKey; } - public SealedBox(String publicKey, String privateKey, Encoder encoder) { - this(encoder.decode(publicKey), encoder.decode(privateKey)); - } - public byte[] encrypt(byte[] message) { Pair keyPair = Util.generateX25519KeyPair(); byte[] nonce = createNonce(keyPair.first, publicKey); @@ -60,7 +49,7 @@ public byte[] encrypt(byte[] message) { ParametersWithIV params = new ParametersWithIV(new KeyParameter(sharedSecret), nonce); cipher.init(true, params); - byte[] sk = new byte[SECRETKEY_BYTES]; + byte[] sk = new byte[Util.SECRET_KEY_LEN]; cipher.processBytes(sk, 0, sk.length, sk, 0); // encrypt the message @@ -78,7 +67,7 @@ public byte[] encrypt(byte[] message) { } private byte[] createNonce(byte[] ephemeralPublicKey, byte[] recipientPublicKey) { - Blake2bDigest blake2b = new Blake2bDigest(NONCE_BYTES * 8); + Blake2bDigest blake2b = new Blake2bDigest(Util.NONCE_SIZE * 8); byte[] nonce = new byte[blake2b.getDigestSize()]; blake2b.update(ephemeralPublicKey, 0, ephemeralPublicKey.length);