我正在尝试基于SHA256withECDSA
算法验证证书的证书链。我正在使用 Java JDK 11。
运行该CertPathValidator.getInstance("PKIX").validate
方法时,我遇到了 crash Unrecognized algorithm for signature parameters SHA256withECDSA
。
根本原因似乎如下:
// null
providerSunEC.getService("AlgorithmParameters", "SHA256withECDSA");
但是,没有这样的签名参数:X509CertImpl
实例包含一个AlgorithmId
withalgid
1.2.840.10045.4.3.2
和 params OID.1.2.840.10045.3.1.7
(DER 编码,应该是prime256v1
),这应该是默认的,并且是唯一受支持的。
我的感觉可能是非常错误的,冗余prime256v1
可以而且应该被省略,但我不知道如何实现它,因为它在 Java 代码中。
这是堆栈跟踪:
Caused by: java.security.cert.CertPathValidatorException: signature check failed
at java.base/sun.security.provider.certpath.PKIXMasterCertPathValidator.validate(PKIXMasterCertPathValidator.java:135)
at java.base/sun.security.provider.certpath.PKIXCertPathValidator.validate(PKIXCertPathValidator.java:233)
at java.base/sun.security.provider.certpath.PKIXCertPathValidator.validate(PKIXCertPathValidator.java:141)
at java.base/sun.security.provider.certpath.PKIXCertPathValidator.engineValidate(PKIXCertPathValidator.java:80)
at java.base/java.security.cert.CertPathValidator.validate(CertPathValidator.java:309)
at net.corda.core.internal.InternalUtils.validate(InternalUtils.kt:469)
... 64 more
Caused by: java.security.cert.CertificateException: Unrecognized algorithm for signature parameters SHA256withECDSA
at java.base/sun.security.x509.X509CertImpl.verify(X509CertImpl.java:445)
at java.base/sun.security.provider.certpath.BasicChecker.verifySignature(BasicChecker.java:166)
at java.base/sun.security.provider.certpath.BasicChecker.check(BasicChecker.java:147)
at java.base/sun.security.provider.certpath.PKIXMasterCertPathValidator.validate(PKIXMasterCertPathValidator.java:125)
... 69 more
这是证书链:
-----BEGIN CERTIFICATE-----
MIICDjCCAaugAwIBAgIIL8JlejRD9+AwFAYIKoZIzj0EAwIGCCqGSM49AwEHMDcx
CzAJBgNVBAYTAkNIMQ8wDQYDVQQHDAZadXJpY2gxFzAVBgNVBAoMDk5vdGFyeSBT
ZXJ2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