Difficulty reading DSA/El Gamal key pair from public key ring collection

Andy LoPresto <[email protected]> Tue, 24 Sep 2019 20:57:12 -0700
Newsgroups gmane.comp.encryption.bouncy-castle.devel
Message-ID <[email protected]>
--Apple-Mail=_3AFF1F42-8FB4-4C4E-A662-6A4806F88DD3
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

Hi,=20

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.=20

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.=20

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).=20

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.=20

[1] =
https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f483bcac77347=
b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/t=
est/groovy/org/apache/nifi/security/util/crypto/OpenPGPKeyBasedEncryptorGr=
oovyTest.groovy#L141 =
<https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f483bcac7734=
7b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/=
test/groovy/org/apache/nifi/security/util/crypto/OpenPGPKeyBasedEncryptorG=
roovyTest.groovy#L141>
[2] https://gist.github.com/alopresto/b91c731b347584316fa4d3ca37ba256c =
<https://gist.github.com/alopresto/b91c731b347584316fa4d3ca37ba256c>
[3] =
http://cephas.net/blog/2004/04/01/pgp-encryption-using-bouncy-castle/ =
<http://cephas.net/blog/2004/04/01/pgp-encryption-using-bouncy-castle/>


Andy LoPresto
[email protected] <mailto:[email protected]>
[email protected]
PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69


--Apple-Mail=_3AFF1F42-8FB4-4C4E-A662-6A4806F88DD3
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dutf-8"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;" class=3D""><meta=
 http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8" =
class=3D""><div style=3D"word-wrap: break-word; -webkit-nbsp-mode: =
space; line-break: after-white-space;" class=3D"">Hi,&nbsp;<div =
class=3D""><br class=3D""></div><div class=3D"">I am encountering a =
surprising issue when attempting to read a DSA &amp; 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.&nbsp;</div><div class=3D""><br class=3D""></div><div =
class=3D"">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.&nbsp;</div><div =
class=3D""><br class=3D""></div><div class=3D"">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).&nbsp;</div><div class=3D""><br class=3D""></div><div class=3D"">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.&nbsp;</div><div class=3D""><br class=3D""></div><div =
class=3D"">[1]&nbsp;<a =
href=3D"https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f483b=
cac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processo=
rs/src/test/groovy/org/apache/nifi/security/util/crypto/OpenPGPKeyBasedEnc=
ryptorGroovyTest.groovy#L141" =
class=3D"">https://github.com/alopresto/nifi/blob/45375f8cd798750ef9aa45f4=
83bcac77347b465c/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-proce=
ssors/src/test/groovy/org/apache/nifi/security/util/crypto/OpenPGPKeyBased=
EncryptorGroovyTest.groovy#L141</a></div><div class=3D"">[2]&nbsp;<a =
href=3D"https://gist.github.com/alopresto/b91c731b347584316fa4d3ca37ba256c=
" =
class=3D"">https://gist.github.com/alopresto/b91c731b347584316fa4d3ca37ba2=
56c</a></div><div class=3D"">[3]&nbsp;<a =
href=3D"http://cephas.net/blog/2004/04/01/pgp-encryption-using-bouncy-cast=
le/" =
class=3D"">http://cephas.net/blog/2004/04/01/pgp-encryption-using-bouncy-c=
astle/</a></div><div class=3D""><br class=3D""></div><div class=3D""><br =
class=3D""><div class=3D"">
<div style=3D"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=3D"">Andy LoPresto<br class=3D""><a =
href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a><br class=3D""><i class=3D""><a =
href=3D"mailto:[email protected]" =
class=3D"">[email protected]</a></i><br class=3D"">PGP =
Fingerprint: 70EC B3E5 98A6 5A3F&nbsp;D3C4 &nbsp;BACE 3C6E F65B 2F7D =
EF69</div>

</div>
<br class=3D""></div></div></body></html>=

--Apple-Mail=_3AFF1F42-8FB4-4C4E-A662-6A4806F88DD3--