Вопрос

Our application decrypt pgp-encrypted file using something adapted from KeyBasedFileProcessor.cs , similar to this one. Normally, this works okay, but we encountered issue with certain files. The problematic code is below:

if (message is PgpLiteralData)
{
   PgpLiteralData ld = (PgpLiteralData)message;
    Stream fOut = File.Create(ld.FileName);
                        Stream unc = ld.GetInputStream();
                        Streams.PipeAll(unc, fOut);
                        fOut.Close();
}
else if (message is PgpOnePassSignatureList)
{
    throw new PgpException("encrypted message contains a signed message - not literal data.");
}
else
{ 
    // the code goes here and throw this exception, when I debug, message is of type PgpMarker
    throw new PgpException("message is not a simple encrypted file - type unknown.");
}

At this part, I believe the code is expecting PgpLiteralData. But instead we got PgpMarker, which causes exception to be thrown. Why is there a PgpMarker? How to find the PgpLiteralData instead?

Это было полезно?

Решение

The solution is simply to disregard the PgpMarker object and continue reading the next ones. The OpenPGP specification has this to say about marker packages:

An experimental version of PGP used this packet as the Literal packet, but no released version of PGP generated Literal packets with this tag. With PGP 5.x, this packet has been reassigned and is reserved for use as the Marker packet.

The body of this packet consists of:

 - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8).

Such a packet MUST be ignored when received. It may be placed at the beginning of a message that uses features not available in PGP 2.6.x in order to cause that version to report that newer software is necessary to process the message.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top