fixed update openssl version
This commit is contained in:
Submodule emerald-java-client updated: 780227723b...99c7f33060
@@ -11,7 +11,7 @@ spring-boot = "2.5.6"
|
|||||||
spring-security = "5.5.3"
|
spring-security = "5.5.3"
|
||||||
reactor = "3.4.10"
|
reactor = "3.4.10"
|
||||||
netty = "4.1.84.Final"
|
netty = "4.1.84.Final"
|
||||||
netty-tcnative = "2.0.54.Final"
|
netty-tcnative = "2.0.48.Final"
|
||||||
kotlin = "1.5.31"
|
kotlin = "1.5.31"
|
||||||
httpcomponents = "4.5.8"
|
httpcomponents = "4.5.8"
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,10 @@ import java.util.Locale
|
|||||||
class SignatureConfig {
|
class SignatureConfig {
|
||||||
|
|
||||||
enum class Algorithm {
|
enum class Algorithm {
|
||||||
SECP256K1,
|
|
||||||
NIST_P256;
|
NIST_P256;
|
||||||
|
|
||||||
fun getCurveName(): String {
|
fun getCurveName(): String {
|
||||||
return if (this == SECP256K1) {
|
return if (this == NIST_P256) {
|
||||||
"secp256k1"
|
|
||||||
} else if (this == NIST_P256) {
|
|
||||||
"secp256r1"
|
"secp256r1"
|
||||||
} else {
|
} else {
|
||||||
throw IllegalStateException()
|
throw IllegalStateException()
|
||||||
@@ -22,7 +19,6 @@ class SignatureConfig {
|
|||||||
companion object {
|
companion object {
|
||||||
fun algorithmOfString(algo: String): Algorithm {
|
fun algorithmOfString(algo: String): Algorithm {
|
||||||
val algorithm = when (algo.uppercase(Locale.getDefault())) {
|
val algorithm = when (algo.uppercase(Locale.getDefault())) {
|
||||||
"SECP256K1" -> Algorithm.SECP256K1
|
|
||||||
"NIST_P256", "NIST-P256", "NISTP256", "SECP256R1" -> Algorithm.NIST_P256
|
"NIST_P256", "NIST-P256", "NISTP256", "SECP256R1" -> Algorithm.NIST_P256
|
||||||
else -> throw IllegalArgumentException("Unknown algorithm or not allowed")
|
else -> throw IllegalArgumentException("Unknown algorithm or not allowed")
|
||||||
}
|
}
|
||||||
@@ -33,7 +29,7 @@ class SignatureConfig {
|
|||||||
/**
|
/**
|
||||||
* Signature scheme that we should use
|
* 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
|
* Should we generate signature on this instance if it's not already present
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ open class ResponseSignerFactory(
|
|||||||
private fun readKey(algorithm: SignatureConfig.Algorithm, pem: PemObject): Pair<ECPrivateKey, Long> {
|
private fun readKey(algorithm: SignatureConfig.Algorithm, pem: PemObject): Pair<ECPrivateKey, Long> {
|
||||||
val keyFactory = KeyFactory.getInstance("EC")
|
val keyFactory = KeyFactory.getInstance("EC")
|
||||||
val key = when (algorithm) {
|
val key = when (algorithm) {
|
||||||
SignatureConfig.Algorithm.SECP256K1, SignatureConfig.Algorithm.NIST_P256 -> {
|
SignatureConfig.Algorithm.NIST_P256 -> {
|
||||||
val keySpec = PKCS8EncodedKeySpec(pem.content)
|
val keySpec = PKCS8EncodedKeySpec(pem.content)
|
||||||
keyFactory.generatePrivate(keySpec)
|
keyFactory.generatePrivate(keySpec)
|
||||||
}
|
}
|
||||||
@@ -47,10 +47,6 @@ open class ResponseSignerFactory(
|
|||||||
throw IllegalStateException("Only EC keys are allowed")
|
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) {
|
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")
|
throw IllegalStateException("Key is not NIST P256, generate NIST P256 or use another algorithm")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import spock.lang.Specification
|
|||||||
import sun.security.x509.X509CertImpl
|
import sun.security.x509.X509CertImpl
|
||||||
|
|
||||||
import java.security.Security
|
import java.security.Security
|
||||||
|
import java.security.cert.X509Certificate
|
||||||
|
|
||||||
class TlsSetupSpec extends Specification {
|
class TlsSetupSpec extends Specification {
|
||||||
|
|
||||||
@@ -66,8 +67,8 @@ class TlsSetupSpec extends Specification {
|
|||||||
!act.client
|
!act.client
|
||||||
with((OpenSslServerContext) act) {
|
with((OpenSslServerContext) act) {
|
||||||
clientAuth == ClientAuth.NONE
|
clientAuth == ClientAuth.NONE
|
||||||
with((X509CertImpl) keyCertChain[0]) {
|
with((X509Certificate) keyCertChain[0]) {
|
||||||
getIssuerDN().name == "CN=ca.myhost.dev, OU=Blockchain CA, O=My Company"
|
getIssuerX500Principal().name == "CN=ca.myhost.dev,OU=Blockchain CA,O=My Company"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,8 +91,8 @@ class TlsSetupSpec extends Specification {
|
|||||||
|
|
||||||
with((OpenSslServerContext) act) {
|
with((OpenSslServerContext) act) {
|
||||||
clientAuth == ClientAuth.REQUIRE
|
clientAuth == ClientAuth.REQUIRE
|
||||||
with((X509CertImpl) keyCertChain[0]) {
|
with((X509Certificate) keyCertChain[0]) {
|
||||||
getIssuerDN().name == "CN=ca.myhost.dev, OU=Blockchain CA, O=My Company"
|
getIssuerX500Principal().name == "CN=ca.myhost.dev,OU=Blockchain CA,O=My Company"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class SignatureConfigReaderSpec extends Specification {
|
|||||||
setup:
|
setup:
|
||||||
def config = "signed-response:\n" +
|
def config = "signed-response:\n" +
|
||||||
" enabled: true\n" +
|
" enabled: true\n" +
|
||||||
" algorithm: SECP256K1\n" +
|
" algorithm: NIST_P256\n" +
|
||||||
" private-key: /root/key.pem\n"
|
" private-key: /root/key.pem\n"
|
||||||
|
|
||||||
when:
|
when:
|
||||||
@@ -26,7 +26,7 @@ class SignatureConfigReaderSpec extends Specification {
|
|||||||
then:
|
then:
|
||||||
act.enabled
|
act.enabled
|
||||||
act.privateKey == "/root/key.pem"
|
act.privateKey == "/root/key.pem"
|
||||||
act.algorithm == SignatureConfig.Algorithm.SECP256K1
|
act.algorithm == SignatureConfig.Algorithm.NIST_P256
|
||||||
}
|
}
|
||||||
|
|
||||||
def "No path when disabled"() {
|
def "No path when disabled"() {
|
||||||
|
|||||||
@@ -23,28 +23,6 @@ class EcdsaSignerSpec extends Specification {
|
|||||||
Security.addProvider(new BouncyCastleProvider())
|
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"() {
|
def "Reads private key NIST P256"() {
|
||||||
setup:
|
setup:
|
||||||
def file = File.createTempFile("test", ".pem")
|
def file = File.createTempFile("test", ".pem")
|
||||||
@@ -84,7 +62,7 @@ class EcdsaSignerSpec extends Specification {
|
|||||||
def id = signer.keyId
|
def id = signer.keyId
|
||||||
|
|
||||||
then:
|
then:
|
||||||
id == 0xd25f1ff2c1a57235L
|
id == 0xed397068b172b393L
|
||||||
}
|
}
|
||||||
|
|
||||||
def "Wrap message"() {
|
def "Wrap message"() {
|
||||||
@@ -109,7 +87,7 @@ class EcdsaSignerSpec extends Specification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def keyPairGen = KeyPairGenerator.getInstance("EC")
|
def keyPairGen = KeyPairGenerator.getInstance("EC")
|
||||||
keyPairGen.initialize(new ECGenParameterSpec("secp256k1"))
|
keyPairGen.initialize(new ECGenParameterSpec("secp256r1"))
|
||||||
def pair = keyPairGen.generateKeyPair()
|
def pair = keyPairGen.generateKeyPair()
|
||||||
def verifier = Signature.getInstance("SHA256withECDSA")
|
def verifier = Signature.getInstance("SHA256withECDSA")
|
||||||
verifier.initVerify(pair.getPublic())
|
verifier.initVerify(pair.getPublic())
|
||||||
@@ -140,7 +118,7 @@ class EcdsaSignerSpec extends Specification {
|
|||||||
def factory = new ResponseSignerFactory(conf)
|
def factory = new ResponseSignerFactory(conf)
|
||||||
|
|
||||||
def sk = factory.readKey(conf.algorithm, conf.privateKey).first
|
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")
|
def verifier = Signature.getInstance("SHA256withECDSA")
|
||||||
verifier.initVerify(pk)
|
verifier.initVerify(pk)
|
||||||
verifier.update("DSHACKLESIG/10/infura/${Hex.encodeHexString(sha256.digest(result))}".getBytes())
|
verifier.update("DSHACKLESIG/10/infura/${Hex.encodeHexString(sha256.digest(result))}".getBytes())
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
-----BEGIN PRIVATE KEY-----
|
-----BEGIN PRIVATE KEY-----
|
||||||
MIGEAgEAMBAGByqGSM49AgEGBSuBBAAKBG0wawIBAQQglWZBwGvH/I/TqQb3uPGq
|
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgWz2Pxo+O3UAWFLqJ
|
||||||
d/6MB2tgFXUfQCYj5RmaXV2hRANCAATfN610x3JM7+xMUIt46sjmaiJm3ZGN9RV1
|
BMLoT8VtWNXn4FHb+VMiyrn0sfehRANCAAR7z21AewiDegaV/4zBkBbNWGOSg1Zo
|
||||||
q+GiuCp36DECozTVx/lDhBnwg2d71HKRxCxsthdB8NclsYybn6B2
|
tE6HGCLMMuKP0XmOg2jVoIvnHJ1OZCIKb236HwnogF4G+o/qlCTi90P1
|
||||||
-----END PRIVATE KEY-----
|
-----END PRIVATE KEY-----
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-----BEGIN PUBLIC KEY-----
|
-----BEGIN PUBLIC KEY-----
|
||||||
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE3zetdMdyTO/sTFCLeOrI5moiZt2RjfUV
|
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEe89tQHsIg3oGlf+MwZAWzVhjkoNW
|
||||||
davhorgqd+gxAqM01cf5Q4QZ8INne9RykcQsbLYXQfDXJbGMm5+gdg==
|
aLROhxgizDLij9F5joNo1aCL5xydTmQiCm9t+h8J6IBeBvqP6pQk4vdD9Q==
|
||||||
-----END PUBLIC KEY-----
|
-----END PUBLIC KEY-----
|
||||||
|
|||||||
Reference in New Issue
Block a user