fixed update openssl version

This commit is contained in:
Termina1
2022-10-13 15:42:11 +03:00
parent 01c5f53d4d
commit 198db59818
9 changed files with 20 additions and 49 deletions

View File

@@ -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"

View File

@@ -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
*/

View File

@@ -37,7 +37,7 @@ open class ResponseSignerFactory(
private fun readKey(algorithm: SignatureConfig.Algorithm, pem: PemObject): Pair<ECPrivateKey, Long> {
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")
}

View File

@@ -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"
}
}
}

View File

@@ -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"() {

View File

@@ -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())

View File

@@ -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-----

View File

@@ -1,4 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE3zetdMdyTO/sTFCLeOrI5moiZt2RjfUV
davhorgqd+gxAqM01cf5Q4QZ8INne9RykcQsbLYXQfDXJbGMm5+gdg==
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEe89tQHsIg3oGlf+MwZAWzVhjkoNW
aLROhxgizDLij9F5joNo1aCL5xydTmQiCm9t+h8J6IBeBvqP6pQk4vdD9Q==
-----END PUBLIC KEY-----