Как создать одну подпись GnuPG, которая работает как с LF, так и с CR / LF версиями файла?

666
Bill Evans at Mariposa

Я создал текстовый файл, используя только LF (перевод строки) в конце каждой строки. Затем я сделал его версию, которая была идентична, за исключением того, что в конце каждой строки был CR / LF (возврат каретки / перевод строки).

Затем, используя gpg2версию 2.0.19, я сделал отдельную подпись для каждого файла. Каждый файл проверен правильно с правильной подписью, но не смог сделать это, когда я использовал неправильную подпись для каждого файла данных.

Пока что это то, что я ожидал.

Но у меня есть текстовый файл и отдельная подпись. Теперь у меня есть две версии текстового файла: одна в стиле LF, другая в стиле CR / LF. Одна и та же отдельная подпись работает правильно на обоих.

Как оригинальному подписчику удалось это сделать? Я хотел бы быть в состоянии сделать это.

2

1 ответ на вопрос

2
Jens Erat

tl;dr: set the --textmode option.

From RFC 4880, 5.2.4. Computing Signatures:

5.2.4. Computing Signatures

All signatures are formed by producing a hash over the signature data, and then using the resulting hash in the signature algorithm.

For binary document signatures (type 0x00), the document data is hashed directly. For text document signatures (type 0x01), the document is canonicalized by converting line endings to <CR><LF>, and the resulting data is hashed.

In other words, you need to make sure GnuPG treats the document as a text document while signing, which needs to be enabled using the --textmode option:

gpg --textmode --detach --sign file 

By running gpg --list-packets signature-file, you will observe the different signature types from RFC 4880, the second line containing sigclass 0x01 with --textmode set instead of sigclass 0x00 without.

From man gpg (it is the same for GnuPG 2):

-t, --textmode
--no-textmode

Treat input files as text and store them in the OpenPGP canonical text form with standard "CRLF" line endings. This also sets the necessary flags to inform the recipient that the encrypted or signed data is text and may need its line endings converted back to whatever the local system uses. This option is useful when communicating between two platforms that have different line ending conventions (UNIX-like to Mac, Mac to Windows, etc). --no-textmode disables this option, and is the default.

If -t (but not --textmode) is used together with armoring and signing, this enables clearsigned messages. This kludge is needed for command-line compati‐bility with command-line versions of PGP; normally you would use --sign or --clearsign to select the type of the signature.