mattosaurus / PgpCore

.NET Core class library for using PGP
MIT License
245 stars 98 forks source link

Possible issue when using only public key for description #131

Closed rogerhival closed 3 years ago

rogerhival commented 3 years ago

Hi,

This does not look right: Line 4314 on PGP.cs

if (message is PgpCompressedData cData) { PgpObjectFactory of = null;

            using (Stream compDataIn = cData.GetDataStream())
            {
                of = new PgpObjectFactory(compDataIn);
            }

            message = Utilities.SkipSignatureList(of);

            PgpLiteralData Ld = null;
            Ld = (PgpLiteralData)message;
            Stream unc = Ld.GetInputStream();
            await Streams.PipeAllAsync(unc, outputStream);

        }

when getting the message = Utilities.SkipSignatureList(of) the stream is closed..

mattosaurus commented 3 years ago

Hi, thanks for raising. Yeah, looks like that ine should be within the using statement.

Do you have an example of when you're hitting this error? It didn't show up on any of the tests so might need to adjust them.

rogerhival commented 3 years ago

The scenario I have is I download a file from here (any file): http://distr.tullverket.se/tulltaxan/xml/dif/ And I'm using a public key they provide on : http://distr.tullverket.se/tulltaxan/Tulltaxan_Fildistribution.asc

Running the following code: static async Task Main(string[] args) { var SEFilePath = @"D:\PGPDecryptTesting\PGPDecryptTesting\SEFile.xml.gz.pgp"; var SEKeyFilePath = new FileInfo(@"D:\PGPDecryptTesting\PGPDecryptTesting\key.asc"); var SEOutputFilePath = @"D:\PGPDecryptTesting\PGPDecryptTesting\SEFile.xml.gz";

var encriptionKeys = new EncryptionKeys(SEKeyFilePath);
using (PGP pgp = new PGP())
{
    await pgp.DecryptFileAsync(SEFilePath, SEOutputFilePath, encriptionKeys);
}

}

Gives me: System.ObjectDisposedException: 'Cannot access a closed file.'

mattosaurus commented 3 years ago

I've published v5.3.1 which has fixed this now. Thanks for pointing it out.