fixed update openssl version
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"() {
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user