From 177326221f23543772ba47e4fa38b4a8a61d2772 Mon Sep 17 00:00:00 2001 From: Graham Date: Thu, 2 Apr 2020 19:26:41 +0100 Subject: [PATCH] Move cryptographic code to a separate module Signed-off-by: Graham --- asm/build.gradle.kts | 1 + .../java/dev/openrs2/asm/classpath/Library.kt | 2 +- bundler/build.gradle.kts | 1 + .../main/java/dev/openrs2/bundler/Bundler.kt | 2 +- .../java/dev/openrs2/bundler/BundlerModule.kt | 4 +-- common/build.gradle.kts | 9 ------ crypto/build.gradle.kts | 30 +++++++++++++++++++ .../java/dev/openrs2/crypto/CryptoModule.kt | 5 ++-- .../dev/openrs2}/crypto/Pkcs12KeyStore.kt | 2 +- .../src/main/java/dev/openrs2}/crypto/Rsa.kt | 2 +- .../dev/openrs2}/crypto/RsaKeyProvider.kt | 2 +- .../crypto/ThreadLocalSecureRandom.kt | 2 +- .../test/java/dev/openrs2}/crypto/RsaTest.kt | 2 +- game/build.gradle.kts | 2 +- .../main/java/dev/openrs2/game/GameModule.kt | 3 +- settings.gradle.kts | 1 + 16 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 crypto/build.gradle.kts rename common/src/main/java/dev/openrs2/common/CommonModule.kt => crypto/src/main/java/dev/openrs2/crypto/CryptoModule.kt (73%) rename {common/src/main/java/dev/openrs2/common => crypto/src/main/java/dev/openrs2}/crypto/Pkcs12KeyStore.kt (99%) rename {common/src/main/java/dev/openrs2/common => crypto/src/main/java/dev/openrs2}/crypto/Rsa.kt (99%) rename {common/src/main/java/dev/openrs2/common => crypto/src/main/java/dev/openrs2}/crypto/RsaKeyProvider.kt (95%) rename {common/src/main/java/dev/openrs2/common => crypto/src/main/java/dev/openrs2}/crypto/ThreadLocalSecureRandom.kt (83%) rename {common/src/test/java/dev/openrs2/common => crypto/src/test/java/dev/openrs2}/crypto/RsaTest.kt (99%) diff --git a/asm/build.gradle.kts b/asm/build.gradle.kts index 0848c863..0ec767a3 100644 --- a/asm/build.gradle.kts +++ b/asm/build.gradle.kts @@ -11,6 +11,7 @@ dependencies { api("org.ow2.asm:asm-util:${Versions.asm}") implementation(project(":compress")) + implementation(project(":crypto")) } publishing { diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt b/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt index 7ce6c764..9653f3bd 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/Library.kt @@ -3,7 +3,7 @@ package dev.openrs2.asm.classpath import com.github.michaelbull.logging.InlineLogger import dev.openrs2.asm.NopClassVisitor import dev.openrs2.asm.remap -import dev.openrs2.common.crypto.Pkcs12KeyStore +import dev.openrs2.crypto.Pkcs12KeyStore import dev.openrs2.common.io.DeterministicJarOutputStream import dev.openrs2.compress.gzip.Gzip import org.objectweb.asm.ClassReader diff --git a/bundler/build.gradle.kts b/bundler/build.gradle.kts index ca371859..27afd876 100644 --- a/bundler/build.gradle.kts +++ b/bundler/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { api(project(":asm")) api("com.github.ajalt:clikt:${Versions.clikt}") + implementation(project(":crypto")) implementation("dev.openrs2:openrs2-natives-all:${Versions.openrs2Natives}") } diff --git a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt index c7c40864..7a664f15 100644 --- a/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt +++ b/bundler/src/main/java/dev/openrs2/bundler/Bundler.kt @@ -13,7 +13,7 @@ import dev.openrs2.bundler.transform.PublicKeyTransformer import dev.openrs2.bundler.transform.ResourceTransformer import dev.openrs2.bundler.transform.RightClickTransformer import dev.openrs2.bundler.transform.TypoTransformer -import dev.openrs2.common.crypto.Pkcs12KeyStore +import dev.openrs2.crypto.Pkcs12KeyStore import java.nio.file.Path import java.util.jar.Attributes import java.util.jar.Attributes.Name.MANIFEST_VERSION diff --git a/bundler/src/main/java/dev/openrs2/bundler/BundlerModule.kt b/bundler/src/main/java/dev/openrs2/bundler/BundlerModule.kt index 9cd77590..c08d9f51 100644 --- a/bundler/src/main/java/dev/openrs2/bundler/BundlerModule.kt +++ b/bundler/src/main/java/dev/openrs2/bundler/BundlerModule.kt @@ -1,10 +1,10 @@ package dev.openrs2.bundler import com.google.inject.AbstractModule -import dev.openrs2.common.CommonModule +import dev.openrs2.crypto.CryptoModule class BundlerModule : AbstractModule() { override fun configure() { - install(CommonModule()) + install(CryptoModule()) } } diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 07194d19..c9bbb3fa 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -3,15 +3,6 @@ plugins { kotlin("jvm") } -dependencies { - api("com.google.inject:guice:${Versions.guice}") - api("io.netty:netty-buffer:${Versions.netty}") - api("org.bouncycastle:bcpkix-jdk15on:${Versions.bouncyCastle}") - api("org.bouncycastle:bcprov-jdk15on:${Versions.bouncyCastle}") - - testImplementation("com.google.jimfs:jimfs:${Versions.jimfs}") -} - publishing { publications.create("maven") { from(components["java"]) diff --git a/crypto/build.gradle.kts b/crypto/build.gradle.kts new file mode 100644 index 00000000..fcfe1267 --- /dev/null +++ b/crypto/build.gradle.kts @@ -0,0 +1,30 @@ +plugins { + `maven-publish` + kotlin("jvm") +} + +dependencies { + api("com.google.inject:guice:${Versions.guice}") + api("io.netty:netty-buffer:${Versions.netty}") + api("org.bouncycastle:bcpkix-jdk15on:${Versions.bouncyCastle}") + api("org.bouncycastle:bcprov-jdk15on:${Versions.bouncyCastle}") + + testImplementation("com.google.jimfs:jimfs:${Versions.jimfs}") +} + +publishing { + publications.create("maven") { + from(components["java"]) + + pom { + packaging = "jar" + name.set("OpenRS2 Cryptography") + description.set( + """ + Provides implementations of cryptographic algorithms used by + the client, including RSA, ISAAC, XTEA and JAR signing. + """.trimIndent() + ) + } + } +} diff --git a/common/src/main/java/dev/openrs2/common/CommonModule.kt b/crypto/src/main/java/dev/openrs2/crypto/CryptoModule.kt similarity index 73% rename from common/src/main/java/dev/openrs2/common/CommonModule.kt rename to crypto/src/main/java/dev/openrs2/crypto/CryptoModule.kt index bda823be..2d904342 100644 --- a/common/src/main/java/dev/openrs2/common/CommonModule.kt +++ b/crypto/src/main/java/dev/openrs2/crypto/CryptoModule.kt @@ -1,11 +1,10 @@ -package dev.openrs2.common +package dev.openrs2.crypto import com.google.inject.AbstractModule import com.google.inject.Scopes -import dev.openrs2.common.crypto.RsaKeyProvider import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters -class CommonModule : AbstractModule() { +class CryptoModule : AbstractModule() { override fun configure() { bind(RSAPrivateCrtKeyParameters::class.java) .toProvider(RsaKeyProvider::class.java) diff --git a/common/src/main/java/dev/openrs2/common/crypto/Pkcs12KeyStore.kt b/crypto/src/main/java/dev/openrs2/crypto/Pkcs12KeyStore.kt similarity index 99% rename from common/src/main/java/dev/openrs2/common/crypto/Pkcs12KeyStore.kt rename to crypto/src/main/java/dev/openrs2/crypto/Pkcs12KeyStore.kt index ac7474c4..90915f9f 100644 --- a/common/src/main/java/dev/openrs2/common/crypto/Pkcs12KeyStore.kt +++ b/crypto/src/main/java/dev/openrs2/crypto/Pkcs12KeyStore.kt @@ -1,4 +1,4 @@ -package dev.openrs2.common.crypto +package dev.openrs2.crypto import jdk.security.jarsigner.JarSigner import org.bouncycastle.asn1.nist.NISTObjectIdentifiers diff --git a/common/src/main/java/dev/openrs2/common/crypto/Rsa.kt b/crypto/src/main/java/dev/openrs2/crypto/Rsa.kt similarity index 99% rename from common/src/main/java/dev/openrs2/common/crypto/Rsa.kt rename to crypto/src/main/java/dev/openrs2/crypto/Rsa.kt index 67835756..5e07e73d 100644 --- a/common/src/main/java/dev/openrs2/common/crypto/Rsa.kt +++ b/crypto/src/main/java/dev/openrs2/crypto/Rsa.kt @@ -1,4 +1,4 @@ -package dev.openrs2.common.crypto +package dev.openrs2.crypto import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBufUtil diff --git a/common/src/main/java/dev/openrs2/common/crypto/RsaKeyProvider.kt b/crypto/src/main/java/dev/openrs2/crypto/RsaKeyProvider.kt similarity index 95% rename from common/src/main/java/dev/openrs2/common/crypto/RsaKeyProvider.kt rename to crypto/src/main/java/dev/openrs2/crypto/RsaKeyProvider.kt index 1bf2d7aa..e8594d75 100644 --- a/common/src/main/java/dev/openrs2/common/crypto/RsaKeyProvider.kt +++ b/crypto/src/main/java/dev/openrs2/crypto/RsaKeyProvider.kt @@ -1,4 +1,4 @@ -package dev.openrs2.common.crypto +package dev.openrs2.crypto import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters import java.nio.file.Files diff --git a/common/src/main/java/dev/openrs2/common/crypto/ThreadLocalSecureRandom.kt b/crypto/src/main/java/dev/openrs2/crypto/ThreadLocalSecureRandom.kt similarity index 83% rename from common/src/main/java/dev/openrs2/common/crypto/ThreadLocalSecureRandom.kt rename to crypto/src/main/java/dev/openrs2/crypto/ThreadLocalSecureRandom.kt index 09fce084..57a90d62 100644 --- a/common/src/main/java/dev/openrs2/common/crypto/ThreadLocalSecureRandom.kt +++ b/crypto/src/main/java/dev/openrs2/crypto/ThreadLocalSecureRandom.kt @@ -1,4 +1,4 @@ -package dev.openrs2.common.crypto +package dev.openrs2.crypto import java.security.SecureRandom diff --git a/common/src/test/java/dev/openrs2/common/crypto/RsaTest.kt b/crypto/src/test/java/dev/openrs2/crypto/RsaTest.kt similarity index 99% rename from common/src/test/java/dev/openrs2/common/crypto/RsaTest.kt rename to crypto/src/test/java/dev/openrs2/crypto/RsaTest.kt index cafa18fa..d013c6bd 100644 --- a/common/src/test/java/dev/openrs2/common/crypto/RsaTest.kt +++ b/crypto/src/test/java/dev/openrs2/crypto/RsaTest.kt @@ -1,4 +1,4 @@ -package dev.openrs2.common.crypto +package dev.openrs2.crypto import com.google.common.jimfs.Configuration import com.google.common.jimfs.Jimfs diff --git a/game/build.gradle.kts b/game/build.gradle.kts index 8956db23..118a79e7 100644 --- a/game/build.gradle.kts +++ b/game/build.gradle.kts @@ -11,7 +11,7 @@ application { dependencies { api("com.github.ajalt:clikt:${Versions.clikt}") - implementation(project(":common")) + implementation("com.google.inject:guice:${Versions.guice}") } publishing { diff --git a/game/src/main/java/dev/openrs2/game/GameModule.kt b/game/src/main/java/dev/openrs2/game/GameModule.kt index 2df0a138..bd1324ce 100644 --- a/game/src/main/java/dev/openrs2/game/GameModule.kt +++ b/game/src/main/java/dev/openrs2/game/GameModule.kt @@ -1,10 +1,9 @@ package dev.openrs2.game import com.google.inject.AbstractModule -import dev.openrs2.common.CommonModule class GameModule : AbstractModule() { override fun configure() { - install(CommonModule()) + // empty } } diff --git a/settings.gradle.kts b/settings.gradle.kts index bec30dee..0773cabe 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,6 +11,7 @@ include( "compress", "compress-cli", "crc32", + "crypto", "decompiler", "deob", "deob-annotations",