Prime239v1 self-signed certificate cannot be verified
Eric Tournier <[email protected]> Wed, 11 Dec 2019 13:58:45 +0000
| Newsgroups | gmane.comp.encryption.bouncy-castle.devel |
|---|---|
| Message-ID | <[email protected]> |
--_000_cc7bd70a098c4a988711b00e92616b0eSRVMAILkeynectissalocal_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi
When I try to verify a ECDSA prime239v1 self-signed certificate with BC v=
ersion 1.64, it fails with the error: java.security.SignatureException: cer=
tificate does not verify with supplied key
Here are a piece of code which can be used to reproduce:
@Test
void verifyPublicKey() throws Exception {
Security.addProvider( new BouncyCastleProvider() );
String certificateAsString =3D "MIIBljCCAUGgAwIBAgISESEodJHbPEvphL8WrOaYt=
+HXMAoGCCqGSM49BAMCMB0xGzAZBgNVBAMMEkhTU1Rlc3RUb0JlUmVtb3ZlZDAgFw0xOTA5MDEw=
MDAwMDFaGA8yMDU0MDkwMTAwMDAwMVowHTEbMBkGA1UEAwwSSFNTVGVzdFRvQmVSZW1vdmVkMFU=
wEwYHKoZIzj0CAQYIKoZIzj0DAQQDPgAEAqBdSfsPUcy2smBkKEY1EsMal+b/3V4FoUQE+ye/Nj=
VR2Cr35YEzkfHjfmFnjxLYEWZkNsLF/UpEgqXlo2MwYTAPBgNVHRMBAf8EBTADAQH/MA4GA1UdD=
wEB/wQEAwIBNjAdBgNVHQ4EFgQUMx33HrlnhuffFTo+nUgszc70GhswHwYDVR0jBBgwFoAUMx33=
HrlnhuffFTo+nUgszc70GhswCgYIKoZIzj0EAwIDQwAwQAIeVUy/xhOy6CAbgMRLTnbYSCsK5d5=
F2dx8yZJl/EmRAh43u+lUn5/K366BQwLUv9w6YlZSL7h9cfuidtRJi2Q=3D";
CertificateFactory certificateFactory =3D CertificateFactory.getInstance(=
"X.509", BouncyCastleProvider.PROVIDER_NAME);
final byte[] bytes =3D Base64.decode(certificateAsString);
final ByteArrayInputStream inputStream =3D new ByteArrayInputStream(bytes=
);
final X509Certificate certificate =3D (X509Certificate) certificateFactor=
y.generateCertificate(inputStream);
final PublicKey publicKey =3D certificate.getPublicKey();
certificate.verify(publicKey, BouncyCastleProvider.PROVIDER_NAME);
}
I debugged the code and it fails in this fragment of verifySignature method=
in ECDSASigner class, which retrun false:
This verification fails with SUN but succeeds with OpenSSL and the ASN1 str=
ucture of the certificate doesn't seem to be invalid.
=C9ric
--_000_cc7bd70a098c4a988711b00e92616b0eSRVMAILkeynectissalocal_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<meta name=3D"Generator" content=3D"Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{mso-style-priority:99;
mso-style-link:"Texte brut Car";
margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.TextebrutCar
{mso-style-name:"Texte brut Car";
mso-style-priority:99;
mso-style-link:"Texte brut";
font-family:"Calibri",sans-serif;
mso-fareast-language:FR;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=3D"FR" link=3D"#0563C1" vlink=3D"#954F72">
<div class=3D"WordSection1">
<p class=3D"MsoPlainText"><span lang=3D"EN-US">Hi<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US"><o:p> </o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US"> When I try to verify =
a ECDSA prime239v1 self-signed certificate with BC version 1.64, it fails w=
ith the error:
</span><span lang=3D"EN-US" style=3D"font-size:10.0pt;font-family:"Cou=
rier New"">java.security.SignatureException: certificate does not veri=
fy with supplied key</span><span lang=3D"EN-US"><o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US"><o:p> </o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US"> Here are a piece of c=
ode which can be used to reproduce:<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New"">@Test<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New""> void verifyPublicKey() throws Exc=
eption {<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New""> Security.addProvider( new BouncyC=
astleProvider() );<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New""><o:p> </o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New""> String certificateAsString =3D &q=
uot;MIIBljCCAUGgAwIBAgISESEodJHbPEvphL8WrOaYt+HXMAoGCCqGSM49BAMCMB0xGzA=
ZBgNVBAMMEkhTU1Rlc3RUb0JlUmVtb3ZlZDAgFw0xOTA5MDEwMDAwMDFaGA8yMDU0MDkwMTAwMD=
AwMVowHTEbMBkGA1UEAwwSSFNTVGVzdFRvQmVSZW1vdmVkMFUwEwYHKoZIzj0CAQYIKoZIzj0DA=
QQDPgAEAqBdSfsPUcy2smBkKEY1EsMal+b/3V4FoUQE+ye/NjVR2Cr35YEzkfHjfmFn=
jxLYEWZkNsLF/UpEgqXlo2MwYTAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBNjAdBgN=
VHQ4EFgQUMx33HrlnhuffFTo+nUgszc70GhswHwYDVR0jBBgwFoAUMx33HrlnhuffFTo=
3;nUgszc70GhswCgYIKoZIzj0EAwIDQwAwQAIeVUy/xhOy6CAbgMRLTnbYSCsK5d5F2dx8yZJl/=
EmRAh43u+lUn5/K366BQwLUv9w6YlZSL7h9cfuidtRJi2Q=3D";<o:p></o:p></sp=
an></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New""> CertificateFactory certificateFac=
tory =3D CertificateFactory.getInstance("X.509", BouncyCastleProv=
ider.PROVIDER_NAME);<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New""> final byte[] bytes =3D Base64.dec=
ode(certificateAsString);<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New""> final ByteArrayInputStream inputS=
tream =3D new ByteArrayInputStream(bytes);<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New""> final X509Certificate certificate=
=3D (X509Certificate) certificateFactory.generateCertificate(inputStream);=
<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New""> final PublicKey publicKey =3D cer=
tificate.getPublicKey();<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New""> certificate.verify(publicKey, Bou=
ncyCastleProvider.PROVIDER_NAME);<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US" style=3D"font-size:10.0pt;fo=
nt-family:"Courier New"">}<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US"><o:p> </o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US">I debugged the code and it f=
ails in this fragment of verifySignature method in ECDSASigner class, which=
retrun false:<o:p></o:p></span></p>
<p class=3D"MsoPlainText"><span lang=3D"EN-US"><o:p> </o:p></span></p>
<p class=3D"MsoNormal"><span lang=3D"EN-US">This verification fails with SU=
N but succeeds with OpenSSL and the ASN1 structure of the certificate doesn=
't seem to be invalid.<o:p></o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"mso-fareast-language:FR"><o:p> <=
/o:p></span></p>
<p class=3D"MsoNormal"><span style=3D"mso-fareast-language:FR">=C9ric =
</span><o:p></o:p></p>
</div>
</body>
</html>
--_000_cc7bd70a098c4a988711b00e92616b0eSRVMAILkeynectissalocal_--