Unknown object in stream and building debug artifacts

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Unknown object in stream and building debug artifacts

Stephen Durfey
I keep having this issue where if I take a file encrypted with gpg that I immediately receive if the file contents are binary (this doesn't happen with ASCII armored files):

java.io.IOException: unknown object in stream: 47
    at org.bouncycastle.openpgp.PGPObjectFactory.nextObject(Unknown Source)

When trying to take the first packet off the stream using the JcaPGPObjectFactory. An example would be:

gpg:

gpg --output plain_signed_recipient.txt.gpg --encrypt --sign --local-user 374ABFC6 --recipient B3E4E0A5 plain.txt

code:

        URL encryptedBinaryStream = this.getClass().getClassLoader()
                .getResource("plain_signed_recipient.txt.gpg");

        InputStream decoderStream = PGPUtil.getDecoderStream(encryptedBinaryStream.openStream());

        JcaPGPObjectFactory jcaPGPObjectFactory = new JcaPGPObjectFactory(decoderStream); // also have tried PGPObjectFactory & BcPGPObjectFactory

        Object o = jcaPGPObjectFactory.nextObject();

I've tried with or without using PGPUtil without success. I have no problems with the code I have if I encrypt some data using bouncy castle in unit tests and decrypt that encrypted stream. This only happens when trying to decrypt a message encrypted with gpg. Inspecting the packets of the encrypted file doesn't show anything out of the ordinary:

⇒  gpg --list-packets plain_signed_recipient.txt.gpg
:pubkey enc packet: version 3, algo 1, keyid 4E78F8C0660E9775
           data: [4095 bits]
:encrypted data packet:
           length: unknown
           mdc_method: 2
gpg: encrypted with 4096-bit RSA key, ID 660E9775, created 2016-08-04
      "Recipient Tests <[hidden email]>"
:compressed packet: algo=2
:onepass_sig packet: keyid 8BDE1D40374ABFC6
           version 3, sigclass 0x00, digest 8, pubkey 1, last=1
:literal data packet:
           mode b (62), created 1472508916, name="plain.txt",
           raw data: 828 bytes
:signature packet: algo 1, keyid 8BDE1D40374ABFC6
           version 4, created 1472508916, md5len 0, sigclass 0x00
           digest algo 8, begin of digest 85 ef
           hashed subpkt 2 len 4 (sig created 2016-08-29)
           subpkt 16 len 8 (issuer key ID 8BDE1D40374ABFC6)
           data: [4095 bits]

I was wanting to debug through the bouncy castle code (bcpg-jdk15on), but I haven't figured out how to build the artifacts to include debug information and to generate a sources jar. Are there instructions somewhere on how to do this?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unknown object in stream and building debug artifacts

David Hook

"sh build15+" with release.debug in bc-build.properties will build debug versions of the jars. You'll need ant and you made to set JDKPATH to point to your JDK. The issue does sound a bit strange.

Regards,

David

On 30/08/16 09:32, Stephen Durfey wrote:
I keep having this issue where if I take a file encrypted with gpg that I immediately receive if the file contents are binary (this doesn't happen with ASCII armored files):

java.io.IOException: unknown object in stream: 47
    at org.bouncycastle.openpgp.PGPObjectFactory.nextObject(Unknown Source)

When trying to take the first packet off the stream using the JcaPGPObjectFactory. An example would be:

gpg:

gpg --output plain_signed_recipient.txt.gpg --encrypt --sign --local-user 374ABFC6 --recipient B3E4E0A5 plain.txt

code:

        URL encryptedBinaryStream = this.getClass().getClassLoader()
                .getResource("plain_signed_recipient.txt.gpg");

        InputStream decoderStream = PGPUtil.getDecoderStream(encryptedBinaryStream.openStream());

        JcaPGPObjectFactory jcaPGPObjectFactory = new JcaPGPObjectFactory(decoderStream); // also have tried PGPObjectFactory & BcPGPObjectFactory

        Object o = jcaPGPObjectFactory.nextObject();

I've tried with or without using PGPUtil without success. I have no problems with the code I have if I encrypt some data using bouncy castle in unit tests and decrypt that encrypted stream. This only happens when trying to decrypt a message encrypted with gpg. Inspecting the packets of the encrypted file doesn't show anything out of the ordinary:

⇒  gpg --list-packets plain_signed_recipient.txt.gpg
:pubkey enc packet: version 3, algo 1, keyid 4E78F8C0660E9775
           data: [4095 bits]
:encrypted data packet:
           length: unknown
           mdc_method: 2
gpg: encrypted with 4096-bit RSA key, ID 660E9775, created 2016-08-04
      "Recipient Tests <[hidden email]>"
:compressed packet: algo=2
:onepass_sig packet: keyid 8BDE1D40374ABFC6
           version 3, sigclass 0x00, digest 8, pubkey 1, last=1
:literal data packet:
           mode b (62), created 1472508916, name="plain.txt",
           raw data: 828 bytes
:signature packet: algo 1, keyid 8BDE1D40374ABFC6
           version 4, created 1472508916, md5len 0, sigclass 0x00
           digest algo 8, begin of digest 85 ef
           hashed subpkt 2 len 4 (sig created 2016-08-29)
           subpkt 16 len 8 (issuer key ID 8BDE1D40374ABFC6)
           data: [4095 bits]

I was wanting to debug through the bouncy castle code (bcpg-jdk15on), but I haven't figured out how to build the artifacts to include debug information and to generate a sources jar. Are there instructions somewhere on how to do this?


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unknown object in stream and building debug artifacts

Stephen Durfey
To add bit more context to the issue. The file resides in src/test/resources. I can see the classloader using an absolute path to the file in target/test-classes, where I can see it exists. The classloader is using a FileInputStream wrapped by a BufferedInputStream, and it isn't returning null, so it must have found the file. I tried the same thing, but pointed it at the file in src/test/resources, and that works just fine. So, I'm kind of at a loss as to what the issue is. I switched my tests to load the file from src/test/resources instead and moved on.

In regards to building debug artifacts, I was able to generate it and debug through some code, but had to jump through some hoops to get it working in intellij as well as my integration tests. Would it be possible to have the additional artifacts released to maven central with the debug information present, like what is done for bc-prov?

On Thu, Sep 1, 2016 at 9:17 PM, David Hook <[hidden email]> wrote:

"sh build15+" with release.debug in bc-build.properties will build debug versions of the jars. You'll need ant and you made to set JDKPATH to point to your JDK. The issue does sound a bit strange.

Regards,

David


On 30/08/16 09:32, Stephen Durfey wrote:
I keep having this issue where if I take a file encrypted with gpg that I immediately receive if the file contents are binary (this doesn't happen with ASCII armored files):

java.io.IOException: unknown object in stream: 47
    at org.bouncycastle.openpgp.PGPObjectFactory.nextObject(Unknown Source)

When trying to take the first packet off the stream using the JcaPGPObjectFactory. An example would be:

gpg:

gpg --output plain_signed_recipient.txt.gpg --encrypt --sign --local-user 374ABFC6 --recipient B3E4E0A5 plain.txt

code:

        URL encryptedBinaryStream = this.getClass().getClassLoader()
                .getResource("plain_signed_recipient.txt.gpg");

        InputStream decoderStream = PGPUtil.getDecoderStream(encryptedBinaryStream.openStream());

        JcaPGPObjectFactory jcaPGPObjectFactory = new JcaPGPObjectFactory(decoderStream); // also have tried PGPObjectFactory & BcPGPObjectFactory

        Object o = jcaPGPObjectFactory.nextObject();

I've tried with or without using PGPUtil without success. I have no problems with the code I have if I encrypt some data using bouncy castle in unit tests and decrypt that encrypted stream. This only happens when trying to decrypt a message encrypted with gpg. Inspecting the packets of the encrypted file doesn't show anything out of the ordinary:

⇒  gpg --list-packets plain_signed_recipient.txt.gpg
:pubkey enc packet: version 3, algo 1, keyid 4E78F8C0660E9775
           data: [4095 bits]
:encrypted data packet:
           length: unknown
           mdc_method: 2
gpg: encrypted with 4096-bit RSA key, ID 660E9775, created 2016-08-04
      "Recipient Tests <[hidden email]>"
:compressed packet: algo=2
:onepass_sig packet: keyid 8BDE1D40374ABFC6
           version 3, sigclass 0x00, digest 8, pubkey 1, last=1
:literal data packet:
           mode b (62), created 1472508916, name="plain.txt",
           raw data: 828 bytes
:signature packet: algo 1, keyid 8BDE1D40374ABFC6
           version 4, created 1472508916, md5len 0, sigclass 0x00
           digest algo 8, begin of digest 85 ef
           hashed subpkt 2 len 4 (sig created 2016-08-29)
           subpkt 16 len 8 (issuer key ID 8BDE1D40374ABFC6)
           data: [4095 bits]

I was wanting to debug through the bouncy castle code (bcpg-jdk15on), but I haven't figured out how to build the artifacts to include debug information and to generate a sources jar. Are there instructions somewhere on how to do this?



Loading...