Re: Difficulty reading DSA/El Gamal key pair from public key ring collection
David Hook <dgh-rTAZ0PM/[email protected]> Wed, 25 Sep 2019 18:39:33 +1000
| Newsgroups | gmane.comp.encryption.bouncy-castle.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --------------050B82F6BE4A9AB9E0AFD118 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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, > > 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. > > 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. > > 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). > > 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. > > [1] 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 > [2] https://gist.github.com/alopresto/b91c731b347584316fa4d3ca37ba256c > [3] http://cephas.net/blog/2004/04/01/pgp-encryption-using-bouncy-castle/ > > > Andy LoPresto > [email protected] <mailto:[email protected]> > /[email protected] <mailto:[email protected]>/ > PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4 BACE 3C6E F65B 2F7D EF69 > --------------050B82F6BE4A9AB9E0AFD118 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">Can you send me a copy of the public key ring file that is causing the problem?</div> <div class="moz-cite-prefix"><br> </div> <div class="moz-cite-prefix">Thanks,</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 25/9/19 1:57 pm, Andy LoPresto wrote:<br> </div> <blockquote type="cite" cite="mid:0B7816FA-3113-4E6F-94BB-268E5A80F8EC-1oDqGaOF3Lkdnm+yROfE0A@public.gmane.org"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <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); 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;" 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><br> </p> </body> </html> --------------050B82F6BE4A9AB9E0AFD118--