Re: Difficulty reading DSA/El Gamal key pair from public key ring collection
David Hook <dgh-rTAZ0PM/[email protected]> Sat, 5 Oct 2019 14:36:58 +1000
| Newsgroups | gmane.comp.encryption.bouncy-castle.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --------------B84F656C33BF34E21B9B2D0D Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Andy, Sorry, have been a bit distracted... the two DSA files are in key box format - they're not keyring files. You'll need to use JcaKeyBoxBuilder to parse these. They are a very different beast from the RFC 4880 key rings. If it's any help I've added a couple of methods to PGPUtil which will have a look at a byte array and try and guess whether the bytes represent a key box or a key ring, they should appear on github shortly. And in 1.64 when it roles out in the next couple of days. Regards, David On 5/10/19 3:48 am, Andy LoPresto wrote: > Hi David,=C2=A0 > > Following up on this to see if you need any additional information > from me or you have any suggestions for where to continue > investigating this issue. Thanks.=C2=A0 > > Andy LoPresto > [email protected] <mailto:[email protected]> > /[email protected]/ > PGP Fingerprint: 70EC B3E5 98A6 5A3F=C2=A0D3C4 =C2=A0BACE 3C6E F65B 2F7= D EF69 > >> On Sep 25, 2019, at 11:36 AM, Andy LoPresto <[email protected] >> <mailto:[email protected]>> wrote: >> >> Hi David,=C2=A0 >> >> Thanks for your quick reply. There are three sample public keyring >> collection files here [1][2][3]. The first (pubring.gpg) contains an >> RSA key pair. The second (dsa-pubring.gpg) contains a 2048 bit DSA/El >> Gamal key pair. The third (dsa-small-pubring.gpg) contains a 1024 bit >> DSA/El Gamal key pair. The third is the same one referenced during >> the CLI output I linked to in my previous message. All three work >> using the gpg command line tool, but neither of the DSA rings work >> with the Java code I posted. The two DSA keyrings actually contain >> the secret keys as well.=C2=A0 >> >> [1]=C2=A0https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45= f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-pr= ocessors/src/test/resources/TestEncryptContent/pubring.gpg >> [2]=C2=A0https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45= f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-pr= ocessors/src/test/resources/TestEncryptContent/dsa-pubring.gpg >> [3]=C2=A0https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45= f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-pr= ocessors/src/test/resources/TestEncryptContent/dsa-small-pubring.gpg >> >> >> Andy LoPresto >> [email protected] <mailto:[email protected]> >> /[email protected] <mailto:[email protected]>/ >> PGP Fingerprint: 70EC B3E5 98A6 5A3F=C2=A0D3C4 =C2=A0BACE 3C6E F65B 2F= 7D EF69 >> >>> On Sep 25, 2019, at 1:39 AM, David Hook <dgh-rTAZ0PM/[email protected] >>> <mailto:dgh-rTAZ0PM/[email protected]>> wrote: >>> >>> >>> Can you send me a copy of the public key ring file that is causing >>> the problem? >>> >>> Thanks, >>> >>> David >>> >>> On 25/9/19 1:57 pm, Andy LoPresto wrote: >>>> Hi,=C2=A0 >>>> >>>> I am encountering a surprising issue when attempting to read a DSA >>>> & El Gamal key pair from a public key ring file. I generated the >>>> keys as per the usual process on the command-line using gpg (GnuPG >>>> 2.2.17 on Mac OS X 10.14.2). I have verified that I can encrypt and >>>> decrypt arbitrary data using those keys and gpg. However, when >>>> trying to read the keys via BC OpenPGP (Java), I either get an >>>> IOException (=E2=80=9CUnexpected object encountered in stream: 0=E2=80= =9D) if not >>>> using PGPUtil.getDecoderStream(InputStream), or simply an empty >>>> PGPPublicKeyRingCollection object if using >>>> PGPUtil.getDecoderStream() in the constructor.=C2=A0 >>>> >>>> I have verified that the same code works successfully against a >>>> public keyring file containing RSA keys, and that if I generate a >>>> public key ring collection with a single DSA/El Gamal key pair in >>>> Java code and pass those bytes as an InputStream into the same >>>> code, it successfully parses and returns the key ring collection.=C2= =A0 >>>> >>>> I have tried with 2048 bit keys (default), but saw there was a >>>> potential compatibility warning with some OpenPGP implementations >>>> so tried with 1024 bits as well (same result).=C2=A0 >>>> >>>> I have posted the exploratory test code here [1] and selected >>>> output from the command-line demonstrating successful operation >>>> with the key pair here [2]. I did not see any mention of this issue >>>> on BC release notes or the examples, but there is this external >>>> post [3] (15 years old) noting there may be a bug here. Thanks in >>>> advance for your assistance.=C2=A0 >>>> >>>> [1]=C2=A0https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa= 45f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-= processors/src/test/groovy/org/apache/nifi/security/util/crypto/OpenPGPKe= yBasedEncryptorGroovyTest.groovy#L141 >>>> [2]=C2=A0https://gist.github.com/alopresto/b91c731b347584316fa4d3ca3= 7ba256c >>>> [3]=C2=A0http://cephas.net/blog/2004/04/01/pgp-encryption-using-boun= cy-castle/ >>>> >>>> >>>> Andy LoPresto >>>> [email protected] <mailto:[email protected]> >>>> /[email protected] <mailto:[email protected]>/ >>>> PGP Fingerprint: 70EC B3E5 98A6 5A3F=C2=A0D3C4 =C2=A0BACE 3C6E F65B = 2F7D EF69 >>>> >>> >> > --------------B84F656C33BF34E21B9B2D0D Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body text="#000000" bgcolor="#FFFFFF"> <div class="moz-cite-prefix"><br> </div> <div class="moz-cite-prefix">Hi Andy,</div> <div class="moz-cite-prefix"><br> </div> <div class="moz-cite-prefix">Sorry, have been a bit distracted... the two DSA files are in key box format - they're not keyring files.</div> <div class="moz-cite-prefix"><br> </div> <div class="moz-cite-prefix">You'll need to use JcaKeyBoxBuilder to parse these. They are a very different beast from the RFC 4880 key rings.</div> <div class="moz-cite-prefix"><br> </div> <div class="moz-cite-prefix">If it's any help I've added a couple of methods to PGPUtil which will have a look at a byte array and try and guess whether the bytes represent a key box or a key ring, they should appear on github shortly. And in 1.64 when it roles out in the next couple of days.</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 5/10/19 3:48 am, Andy LoPresto wrote:<br> </div> <blockquote type="cite" cite="mid:715880BC-D53F-444B-B67E-5B7B904AAE0E-1oDqGaOF3Lkdnm+yROfE0A@public.gmane.org"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> Hi David, <div class=""><br class=""> </div> <div class="">Following up on this to see if you need any additional information from me or you have any suggestions for where to continue investigating this issue. Thanks. </div> <div class=""><br class=""> <div class=""> <div style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;">Andy LoPresto<br class=""> <a href="mailto:[email protected]" class="" moz-do-not-send="true">[email protected]</a><br class=""> <i class=""><a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a></i><br class=""> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4 BACE 3C6E F65B 2F7D EF69</div> </div> <div><br class=""> <blockquote type="cite" class=""> <div class="">On Sep 25, 2019, at 11:36 AM, Andy LoPresto <<a href="mailto:[email protected]" class="" moz-do-not-send="true">[email protected]</a>> wrote:</div> <br class="Apple-interchange-newline"> <div class=""> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class=""> <div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi David, <div class=""><br class=""> </div> <div class="">Thanks for your quick reply. There are three sample public keyring collection files here [1][2][3]. The first (pubring.gpg) contains an RSA key pair. The second (dsa-pubring.gpg) contains a 2048 bit DSA/El Gamal key pair. The third (dsa-small-pubring.gpg) contains a 1024 bit DSA/El Gamal key pair. The third is the same one referenced during the CLI output I linked to in my previous message. All three work using the gpg command line tool, but neither of the DSA rings work with the Java code I posted. The two DSA keyrings actually contain the secret keys as well. </div> <div class=""><br class=""> </div> <div class="">[1] <a href="https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/pubring.gpg" class="" moz-do-not-send="true">https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/pubring.gpg</a></div> <div class="">[2] <a href="https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/dsa-pubring.gpg" class="" moz-do-not-send="true">https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/dsa-pubring.gpg</a></div> <div class="">[3] <a href="https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/dsa-small-pubring.gpg" class="" moz-do-not-send="true">https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/resources/TestEncryptContent/dsa-small-pubring.gpg</a></div> <div class=""><br class=""> </div> <div class=""><br class=""> <div class=""> <div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">Andy LoPresto<br class=""> <a href="mailto:[email protected]" class="" moz-do-not-send="true">[email protected]</a><br class=""> <i class=""><a href="mailto:[email protected]" class="" moz-do-not-send="true">[email protected]</a></i><br class=""> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4 BACE 3C6E F65B 2F7D EF69</div> </div> <div class=""><br class=""> <blockquote type="cite" class=""> <div class="">On Sep 25, 2019, at 1:39 AM, David Hook <<a href="mailto:dgh-rTAZ0PM/[email protected]" class="" moz-do-not-send="true">dgh-rTAZ0PM/[email protected]</a>> wrote:</div> <br class="Apple-interchange-newline"> <div class=""> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class=""> <div text="#000000" bgcolor="#FFFFFF" class=""> <div class="moz-cite-prefix"><br class=""> </div> <div class="moz-cite-prefix">Can you send me a copy of the public key ring file that is causing the problem?</div> <div class="moz-cite-prefix"><br class=""> </div> <div class="moz-cite-prefix">Thanks,</div> <div class="moz-cite-prefix"><br class=""> </div> <div class="moz-cite-prefix">David</div> <div class="moz-cite-prefix"><br class=""> </div> <div class="moz-cite-prefix">On 25/9/19 1:57 pm, Andy LoPresto wrote:<br class=""> </div> <blockquote type="cite" cite="mid:0B7816FA-3113-4E6F-94BB-268E5A80F8EC-1oDqGaOF3Lkdnm+yROfE0A@public.gmane.org" class=""> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class=""> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class=""> <div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi, <div class=""><br class=""> </div> <div class="">I am encountering a surprising issue when attempting to read a DSA & El Gamal key pair from a public key ring file. I generated the keys as per the usual process on the command-line using gpg (GnuPG 2.2.17 on Mac OS X 10.14.2). I have verified that I can encrypt and decrypt arbitrary data using those keys and gpg. However, when trying to read the keys via BC OpenPGP (Java), I either get an IOException (“Unexpected object encountered in stream: 0”) if not using PGPUtil.getDecoderStream(InputStream), or simply an empty PGPPublicKeyRingCollection object if using PGPUtil.getDecoderStream() in the constructor. </div> <div class=""><br class=""> </div> <div class="">I have verified that the same code works successfully against a public keyring file containing RSA keys, and that if I generate a public key ring collection with a single DSA/El Gamal key pair in Java code and pass those bytes as an InputStream into the same code, it successfully parses and returns the key ring collection. </div> <div class=""><br class=""> </div> <div class="">I have tried with 2048 bit keys (default), but saw there was a potential compatibility warning with some OpenPGP implementations so tried with 1024 bits as well (same result). </div> <div class=""><br class=""> </div> <div class="">I have posted the exploratory test code here [1] and selected output from the command-line demonstrating successful operation with the key pair here [2]. I did not see any mention of this issue on BC release notes or the examples, but there is this external post [3] (15 years old) noting there may be a bug here. Thanks in advance for your assistance. </div> <div class=""><br class=""> </div> <div class="">[1] <a href="https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/security/util/crypto/OpenPGPKeyBasedEncryptorGroovyTest.groovy#L141" class="" moz-do-not-send="true">https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f483bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/security/util/crypto/OpenPGPKeyBasedEncryptorGroovyTest.groovy#L141</a></div> <div class="">[2] <a href="https://gist.github.com/alopresto/b91c731b347584316fa4d3ca37ba256c" class="" moz-do-not-send="true">https://gist.github.com/alopresto/b91c731b347584316fa4d3ca37ba256c</a></div> <div class="">[3] <a href="http://cephas.net/blog/2004/04/01/pgp-encryption-using-bouncy-castle/" class="" moz-do-not-send="true">http://cephas.net/blog/2004/04/01/pgp-encryption-using-bouncy-castle/</a></div> <div class=""><br class=""> </div> <div class=""><br class=""> <div class=""> <div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">Andy LoPresto<br class=""> <a href="mailto:[email protected]" class="" moz-do-not-send="true">[email protected]</a><br class=""> <i class=""><a href="mailto:[email protected]" class="" moz-do-not-send="true">[email protected]</a></i><br class=""> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4 BACE 3C6E F65B 2F7D EF69</div> </div> <br class=""> </div> </div> </blockquote> <p class=""><br class=""> </p> </div> </div> </blockquote> </div> <br class=""> </div> </div> </div> </blockquote> </div> <br class=""> </div> </blockquote> <p><br> </p> </body> </html> --------------B84F656C33BF34E21B9B2D0D--