From 185668c3c67f2c234c7dd20ec97eec826cadbd80 Mon Sep 17 00:00:00 2001 From: Termina1 Date: Thu, 13 Oct 2022 10:54:35 +0300 Subject: [PATCH 1/5] update grpc --- gradle/libs.versions.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 02076f63..16330ee3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,7 +2,7 @@ detekt = "1.18.1" etherjar = "0.11.1" groovy = "2.5.14" -protoc = "3.9.0" +protoc = "3.21.7" slf4j = "1.7.32" jackson = "2.11.0" grpc = "1.38.0" @@ -11,7 +11,7 @@ spring-boot = "2.5.6" spring-security = "5.5.3" reactor = "3.4.10" netty = "4.1.70.Final" -netty-tcnative = "2.0.45.Final" +netty-tcnative = "2.0.54.Final" kotlin = "1.5.31" httpcomponents = "4.5.8" From b6eaca8edd03d401d99e6f11923fd453d69871f4 Mon Sep 17 00:00:00 2001 From: Termina1 Date: Thu, 13 Oct 2022 12:34:43 +0300 Subject: [PATCH 2/5] update client ref --- emerald-java-client | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emerald-java-client b/emerald-java-client index 39765fd0..b746b3e0 160000 --- a/emerald-java-client +++ b/emerald-java-client @@ -1 +1 @@ -Subproject commit 39765fd040f6cb417ad7e4fe7c05b508a2e6ee1a +Subproject commit b746b3e015941ff656125c390ab6ecd02cabfc9e From 50f8e13b43454ca507b1d3bc80e3289faf09f004 Mon Sep 17 00:00:00 2001 From: Termina1 Date: Thu, 13 Oct 2022 12:49:36 +0300 Subject: [PATCH 3/5] update boring ssl --- emerald-java-client | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emerald-java-client b/emerald-java-client index b746b3e0..78022772 160000 --- a/emerald-java-client +++ b/emerald-java-client @@ -1 +1 @@ -Subproject commit b746b3e015941ff656125c390ab6ecd02cabfc9e +Subproject commit 780227723b50aaba7cccdf82e551554c9c3cbb9f From 01c5f53d4dfe9a24704dc2c9a7b87d719dc40975 Mon Sep 17 00:00:00 2001 From: Termina1 Date: Thu, 13 Oct 2022 13:37:33 +0300 Subject: [PATCH 4/5] update deps --- gradle/libs.versions.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 16330ee3..d510b672 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -10,7 +10,7 @@ reactive-grpc = "1.2.0" spring-boot = "2.5.6" spring-security = "5.5.3" reactor = "3.4.10" -netty = "4.1.70.Final" +netty = "4.1.84.Final" netty-tcnative = "2.0.54.Final" kotlin = "1.5.31" httpcomponents = "4.5.8" @@ -33,7 +33,7 @@ detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", emerald-api = "io.emeraldpay:emerald-api:0.12-alpha.3" -equals-verifier = "nl.jqno.equalsverifier:equalsverifier:3.3" +equals-verifier = "nl.jqno.equalsverifier:equalsverifier:3.10.1" etherjar-domain = { module = "io.emeraldpay.etherjar:etherjar-domain", version.ref = "etherjar" } etherjar-hex = { module = "io.emeraldpay.etherjar:etherjar-hex", version.ref = "etherjar" } From 198db598186feeec6099142738fddbc01aa19894 Mon Sep 17 00:00:00 2001 From: Termina1 Date: Thu, 13 Oct 2022 15:42:11 +0300 Subject: [PATCH 5/5] fixed update openssl version --- emerald-java-client | 2 +- gradle/libs.versions.toml | 2 +- .../dshackle/config/SignatureConfig.kt | 8 ++---- .../signature/ResponseSignerFactory.kt | 6 +--- .../emeraldpay/dshackle/TlsSetupSpec.groovy | 9 +++--- .../config/SignatureConfigReaderSpec.groovy | 4 +-- .../upstream/signature/EcdsaSignerSpec.groovy | 28 ++----------------- testing/dshackle/test_key | 6 ++-- testing/dshackle/test_key.pub | 4 +-- 9 files changed, 20 insertions(+), 49 deletions(-) diff --git a/emerald-java-client b/emerald-java-client index 78022772..99c7f330 160000 --- a/emerald-java-client +++ b/emerald-java-client @@ -1 +1 @@ -Subproject commit 780227723b50aaba7cccdf82e551554c9c3cbb9f +Subproject commit 99c7f3306081ca3631d3b449973b613b8d682595 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d510b672..93c48428 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,7 +11,7 @@ spring-boot = "2.5.6" spring-security = "5.5.3" reactor = "3.4.10" netty = "4.1.84.Final" -netty-tcnative = "2.0.54.Final" +netty-tcnative = "2.0.48.Final" kotlin = "1.5.31" httpcomponents = "4.5.8" diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/SignatureConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/SignatureConfig.kt index 6b1d8e85..57ab0796 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/SignatureConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/SignatureConfig.kt @@ -5,13 +5,10 @@ import java.util.Locale class SignatureConfig { enum class Algorithm { - SECP256K1, NIST_P256; fun getCurveName(): String { - return if (this == SECP256K1) { - "secp256k1" - } else if (this == NIST_P256) { + return if (this == NIST_P256) { "secp256r1" } else { throw IllegalStateException() @@ -22,7 +19,6 @@ class SignatureConfig { companion object { fun algorithmOfString(algo: String): Algorithm { val algorithm = when (algo.uppercase(Locale.getDefault())) { - "SECP256K1" -> Algorithm.SECP256K1 "NIST_P256", "NIST-P256", "NISTP256", "SECP256R1" -> Algorithm.NIST_P256 else -> throw IllegalArgumentException("Unknown algorithm or not allowed") } @@ -33,7 +29,7 @@ class SignatureConfig { /** * Signature scheme that we should use */ - var algorithm: Algorithm = Algorithm.SECP256K1 + var algorithm: Algorithm = Algorithm.NIST_P256 /** * Should we generate signature on this instance if it's not already present */ diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/signature/ResponseSignerFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/signature/ResponseSignerFactory.kt index 980bcda3..12a2876a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/signature/ResponseSignerFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/signature/ResponseSignerFactory.kt @@ -37,7 +37,7 @@ open class ResponseSignerFactory( private fun readKey(algorithm: SignatureConfig.Algorithm, pem: PemObject): Pair { val keyFactory = KeyFactory.getInstance("EC") val key = when (algorithm) { - SignatureConfig.Algorithm.SECP256K1, SignatureConfig.Algorithm.NIST_P256 -> { + SignatureConfig.Algorithm.NIST_P256 -> { val keySpec = PKCS8EncodedKeySpec(pem.content) keyFactory.generatePrivate(keySpec) } @@ -47,10 +47,6 @@ open class ResponseSignerFactory( throw IllegalStateException("Only EC keys are allowed") } - if (algorithm == SignatureConfig.Algorithm.SECP256K1 && key.params.toString().indexOf(SignatureConfig.Algorithm.SECP256K1.getCurveName()) < 0) { - throw IllegalStateException("Key is not SECP256K1, generate SECP256K1 or use another algorithm") - } - if (algorithm == SignatureConfig.Algorithm.NIST_P256 && key.params.toString().indexOf(SignatureConfig.Algorithm.NIST_P256.getCurveName()) < 0) { throw IllegalStateException("Key is not NIST P256, generate NIST P256 or use another algorithm") } diff --git a/src/test/groovy/io/emeraldpay/dshackle/TlsSetupSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/TlsSetupSpec.groovy index 4ef30c38..582c3a58 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/TlsSetupSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/TlsSetupSpec.groovy @@ -26,6 +26,7 @@ import spock.lang.Specification import sun.security.x509.X509CertImpl import java.security.Security +import java.security.cert.X509Certificate class TlsSetupSpec extends Specification { @@ -66,8 +67,8 @@ class TlsSetupSpec extends Specification { !act.client with((OpenSslServerContext) act) { clientAuth == ClientAuth.NONE - with((X509CertImpl) keyCertChain[0]) { - getIssuerDN().name == "CN=ca.myhost.dev, OU=Blockchain CA, O=My Company" + with((X509Certificate) keyCertChain[0]) { + getIssuerX500Principal().name == "CN=ca.myhost.dev,OU=Blockchain CA,O=My Company" } } } @@ -90,8 +91,8 @@ class TlsSetupSpec extends Specification { with((OpenSslServerContext) act) { clientAuth == ClientAuth.REQUIRE - with((X509CertImpl) keyCertChain[0]) { - getIssuerDN().name == "CN=ca.myhost.dev, OU=Blockchain CA, O=My Company" + with((X509Certificate) keyCertChain[0]) { + getIssuerX500Principal().name == "CN=ca.myhost.dev,OU=Blockchain CA,O=My Company" } } } diff --git a/src/test/groovy/io/emeraldpay/dshackle/config/SignatureConfigReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/config/SignatureConfigReaderSpec.groovy index 3383af39..b8e5f5c5 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/config/SignatureConfigReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/config/SignatureConfigReaderSpec.groovy @@ -16,7 +16,7 @@ class SignatureConfigReaderSpec extends Specification { setup: def config = "signed-response:\n" + " enabled: true\n" + - " algorithm: SECP256K1\n" + + " algorithm: NIST_P256\n" + " private-key: /root/key.pem\n" when: @@ -26,7 +26,7 @@ class SignatureConfigReaderSpec extends Specification { then: act.enabled act.privateKey == "/root/key.pem" - act.algorithm == SignatureConfig.Algorithm.SECP256K1 + act.algorithm == SignatureConfig.Algorithm.NIST_P256 } def "No path when disabled"() { diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/signature/EcdsaSignerSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/signature/EcdsaSignerSpec.groovy index 408488b7..668b5abc 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/signature/EcdsaSignerSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/signature/EcdsaSignerSpec.groovy @@ -23,28 +23,6 @@ class EcdsaSignerSpec extends Specification { Security.addProvider(new BouncyCastleProvider()) } - def "Reads private key"() { - setup: - def file = File.createTempFile("test", ".pem") - def keygen = KeyPairGenerator.getInstance("EC") - keygen.initialize(new ECGenParameterSpec("secp256k1")) - def key = keygen.generateKeyPair() - def keyBuilder = new PKCS8EncodedKeySpec(key.getPrivate().getEncoded()) - def writer = new PemWriter(new FileWriter(file.path)) - writer.writeObject(new PemObject("PRIVATE KEY", keyBuilder.getEncoded())) - writer.close() - - when: - def signer = new ResponseSignerFactory(new SignatureConfig()) - def act = signer.readKey(SignatureConfig.Algorithm.SECP256K1, file.absolutePath).first - - then: - act == key.getPrivate() - - cleanup: - file.delete() - } - def "Reads private key NIST P256"() { setup: def file = File.createTempFile("test", ".pem") @@ -84,7 +62,7 @@ class EcdsaSignerSpec extends Specification { def id = signer.keyId then: - id == 0xd25f1ff2c1a57235L + id == 0xed397068b172b393L } def "Wrap message"() { @@ -109,7 +87,7 @@ class EcdsaSignerSpec extends Specification { } def keyPairGen = KeyPairGenerator.getInstance("EC") - keyPairGen.initialize(new ECGenParameterSpec("secp256k1")) + keyPairGen.initialize(new ECGenParameterSpec("secp256r1")) def pair = keyPairGen.generateKeyPair() def verifier = Signature.getInstance("SHA256withECDSA") verifier.initVerify(pair.getPublic()) @@ -140,7 +118,7 @@ class EcdsaSignerSpec extends Specification { def factory = new ResponseSignerFactory(conf) def sk = factory.readKey(conf.algorithm, conf.privateKey).first - def pk = factory.extractPublicKey(KeyFactory.getInstance("EC"), sk, SignatureConfig.Algorithm.SECP256K1) + def pk = factory.extractPublicKey(KeyFactory.getInstance("EC"), sk, SignatureConfig.Algorithm.NIST_P256) def verifier = Signature.getInstance("SHA256withECDSA") verifier.initVerify(pk) verifier.update("DSHACKLESIG/10/infura/${Hex.encodeHexString(sha256.digest(result))}".getBytes()) diff --git a/testing/dshackle/test_key b/testing/dshackle/test_key index dedd7587..fdb38126 100644 --- a/testing/dshackle/test_key +++ b/testing/dshackle/test_key @@ -1,5 +1,5 @@ -----BEGIN PRIVATE KEY----- -MIGEAgEAMBAGByqGSM49AgEGBSuBBAAKBG0wawIBAQQglWZBwGvH/I/TqQb3uPGq -d/6MB2tgFXUfQCYj5RmaXV2hRANCAATfN610x3JM7+xMUIt46sjmaiJm3ZGN9RV1 -q+GiuCp36DECozTVx/lDhBnwg2d71HKRxCxsthdB8NclsYybn6B2 +MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgWz2Pxo+O3UAWFLqJ +BMLoT8VtWNXn4FHb+VMiyrn0sfehRANCAAR7z21AewiDegaV/4zBkBbNWGOSg1Zo +tE6HGCLMMuKP0XmOg2jVoIvnHJ1OZCIKb236HwnogF4G+o/qlCTi90P1 -----END PRIVATE KEY----- diff --git a/testing/dshackle/test_key.pub b/testing/dshackle/test_key.pub index b99ed61c..fd762264 100644 --- a/testing/dshackle/test_key.pub +++ b/testing/dshackle/test_key.pub @@ -1,4 +1,4 @@ -----BEGIN PUBLIC KEY----- -MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE3zetdMdyTO/sTFCLeOrI5moiZt2RjfUV -davhorgqd+gxAqM01cf5Q4QZ8INne9RykcQsbLYXQfDXJbGMm5+gdg== +MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEe89tQHsIg3oGlf+MwZAWzVhjkoNW +aLROhxgizDLij9F5joNo1aCL5xydTmQiCm9t+h8J6IBeBvqP6pQk4vdD9Q== -----END PUBLIC KEY-----