Re: Prime239v1 self-signed certificate cannot be verified
David Hook <dgh-rTAZ0PM/[email protected]> Thu, 12 Dec 2019 11:56:00 +1100
| Newsgroups | gmane.comp.encryption.bouncy-castle.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------8FC3A0CF51B3FBE38233036C
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit
It looks alright to me as well. How are you verifying it in openSSL
though? I've played around with the openssl verify command and it seems
I can get it to print OK in a number of situations where I would not
have expected it. Something clearly is not right here. Have you tried
using java to sign a short message and then verify it? That would at
least tell us if it's the signature or the certificate encoding that is
the issue.
Regards,
David
On 12/12/19 12:58 am, Eric Tournier wrote:
>
> Hi
>
>
>
> When I try to verify a ECDSA prime239v1 self-signed certificate with
> BC version 1.64, it fails with the error:
> java.security.SignatureException: certificate 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 =
> "MIIBljCCAUGgAwIBAgISESEodJHbPEvphL8WrOaYt+HXMAoGCCqGSM49BAMCMB0xGzAZBgNVBAMMEkhTU1Rlc3RUb0JlUmVtb3ZlZDAgFw0xOTA5MDEwMDAwMDFaGA8yMDU0MDkwMTAwMDAwMVowHTEbMBkGA1UEAwwSSFNTVGVzdFRvQmVSZW1vdmVkMFUwEwYHKoZIzj0CAQYIKoZIzj0DAQQDPgAEAqBdSfsPUcy2smBkKEY1EsMal+b/3V4FoUQE+ye/NjVR2Cr35YEzkfHjfmFnjxLYEWZkNsLF/UpEgqXlo2MwYTAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBNjAdBgNVHQ4EFgQUMx33HrlnhuffFTo+nUgszc70GhswHwYDVR0jBBgwFoAUMx33HrlnhuffFTo+nUgszc70GhswCgYIKoZIzj0EAwIDQwAwQAIeVUy/xhOy6CAbgMRLTnbYSCsK5d5F2dx8yZJl/EmRAh43u+lUn5/K366BQwLUv9w6YlZSL7h9cfuidtRJi2Q=";
>
> CertificateFactory certificateFactory =
> CertificateFactory.getInstance("X.509",
> BouncyCastleProvider.PROVIDER_NAME);
>
> final byte[] bytes = Base64.decode(certificateAsString);
>
> final ByteArrayInputStream inputStream = new
> ByteArrayInputStream(bytes);
>
> final X509Certificate certificate = (X509Certificate)
> certificateFactory.generateCertificate(inputStream);
>
> final PublicKey publicKey = 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 structure of the certificate doesn't seem to be invalid.
>
>
>
> Éric
>
--------------8FC3A0CF51B3FBE38233036C
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">It looks alright to me as well. How are
you verifying it in openSSL though? I've played around with the
openssl verify command and it seems I can get it to print OK in a
number of situations where I would not have expected it. Something
clearly is not right here. Have you tried using java to sign a
short message and then verify it? That would at least tell us if
it's the signature or the certificate encoding that is the issue.<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Regards,</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">David</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">On 12/12/19 12:58 am, Eric Tournier
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:cc7bd70a098c4a988711b00e92616b0e-LolL45/IeJoIy7AD+B/[email protected]">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="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="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoPlainText"><span lang="EN-US">Hi<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"> When I try to
verify a ECDSA prime239v1 self-signed certificate with BC
version 1.64, it fails with the error:
</span><span style="font-size:10.0pt;font-family:"Courier
New"" lang="EN-US">java.security.SignatureException:
certificate does not verify with supplied key</span><span
lang="EN-US"><o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"> Here are a piece of
code which can be used to reproduce:<o:p></o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US">@Test<o:p></o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US"> void verifyPublicKey() throws Exception {<o:p></o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US"> Security.addProvider( new
BouncyCastleProvider() );<o:p></o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US"> String certificateAsString =
"MIIBljCCAUGgAwIBAgISESEodJHbPEvphL8WrOaYt+HXMAoGCCqGSM49BAMCMB0xGzAZBgNVBAMMEkhTU1Rlc3RUb0JlUmVtb3ZlZDAgFw0xOTA5MDEwMDAwMDFaGA8yMDU0MDkwMTAwMDAwMVowHTEbMBkGA1UEAwwSSFNTVGVzdFRvQmVSZW1vdmVkMFUwEwYHKoZIzj0CAQYIKoZIzj0DAQQDPgAEAqBdSfsPUcy2smBkKEY1EsMal+b/3V4FoUQE+ye/NjVR2Cr35YEzkfHjfmFnjxLYEWZkNsLF/UpEgqXlo2MwYTAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBNjAdBgNVHQ4EFgQUMx33HrlnhuffFTo+nUgszc70GhswHwYDVR0jBBgwFoAUMx33HrlnhuffFTo+nUgszc70GhswCgYIKoZIzj0EAwIDQwAwQAIeVUy/xhOy6CAbgMRLTnbYSCsK5d5F2dx8yZJl/EmRAh43u+lUn5/K366BQwLUv9w6YlZSL7h9cfuidtRJi2Q=";<o:p></o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US"> CertificateFactory certificateFactory =
CertificateFactory.getInstance("X.509",
BouncyCastleProvider.PROVIDER_NAME);<o:p></o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US"> final byte[] bytes =
Base64.decode(certificateAsString);<o:p></o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US"> final ByteArrayInputStream inputStream = new
ByteArrayInputStream(bytes);<o:p></o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US"> final X509Certificate certificate =
(X509Certificate)
certificateFactory.generateCertificate(inputStream);<o:p></o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US"> final PublicKey publicKey =
certificate.getPublicKey();<o:p></o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US"> certificate.verify(publicKey,
BouncyCastleProvider.PROVIDER_NAME);<o:p></o:p></span></p>
<p class="MsoPlainText"><span
style="font-size:10.0pt;font-family:"Courier New""
lang="EN-US">}<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US">I debugged the code
and it fails in this fragment of verifySignature method in
ECDSASigner class, which retrun false:<o:p></o:p></span></p>
<p class="MsoPlainText"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">This verification fails
with SUN 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="MsoNormal"><span style="mso-fareast-language:FR"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:FR">Éric </span><o:p></o:p></p>
</div>
</blockquote>
<p><br>
</p>
</body>
</html>
--------------8FC3A0CF51B3FBE38233036C--