diff options
author | Joe Crayne <joe@jerkface.net> | 2020-05-16 08:17:38 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-05-19 11:59:23 -0400 |
commit | a901da5942b29e0a3f1ce358b6c14f56984934e7 (patch) | |
tree | 56465946e4119ac2513200952748e6514c4314c3 /Data | |
parent | 52973c2c26fc2d3c529f0a11329c9784f87b3c72 (diff) |
Encode v5 signatures (draft-ietf-openpgp-rfc4880bis-09).
Diffstat (limited to 'Data')
-rw-r--r-- | Data/OpenPGP.hs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs index cc97cd6..dc6fb78 100644 --- a/Data/OpenPGP.hs +++ b/Data/OpenPGP.hs | |||
@@ -383,14 +383,14 @@ secret_key_fields alg = fromMaybe (error $ "Unknown secret fields for "++show a | |||
383 | -- Need this seperate for trailer calculation | 383 | -- Need this seperate for trailer calculation |
384 | signature_packet_start :: Packet -> B.ByteString | 384 | signature_packet_start :: Packet -> B.ByteString |
385 | signature_packet_start (SignaturePacket { | 385 | signature_packet_start (SignaturePacket { |
386 | version = 4, | 386 | version = v, |
387 | signature_type = signature_type, | 387 | signature_type = signature_type, |
388 | key_algorithm = key_algorithm, | 388 | key_algorithm = key_algorithm, |
389 | hash_algorithm = hash_algorithm, | 389 | hash_algorithm = hash_algorithm, |
390 | hashed_subpackets = hashed_subpackets | 390 | hashed_subpackets = hashed_subpackets |
391 | }) = | 391 | }) | v==4 || v==5 = |
392 | B.concat [ | 392 | B.concat [ |
393 | encode (0x04 :: Word8), | 393 | encode (v :: Word8), |
394 | encode signature_type, | 394 | encode signature_type, |
395 | encode key_algorithm, | 395 | encode key_algorithm, |
396 | encode hash_algorithm, | 396 | encode hash_algorithm, |
@@ -416,12 +416,16 @@ calculate_signature_trailer (SignaturePacket { version = v, | |||
416 | Just (SignatureCreationTimePacket creation_time) = find isCreation unhashed_subpackets | 416 | Just (SignatureCreationTimePacket creation_time) = find isCreation unhashed_subpackets |
417 | isCreation (SignatureCreationTimePacket {}) = True | 417 | isCreation (SignatureCreationTimePacket {}) = True |
418 | isCreation _ = False | 418 | isCreation _ = False |
419 | calculate_signature_trailer p@(SignaturePacket {version = 4}) = | 419 | calculate_signature_trailer p@(SignaturePacket {version = v}) | v==4 || v==5 = |
420 | B.concat [ | 420 | B.concat [ |
421 | signature_packet_start p, | 421 | signature_packet_start p, |
422 | encode (0x04 :: Word8), | 422 | -- TODO: v5 document signatures (type 0x00 or 0x01) hash more fields here. |
423 | encode (v :: Word8), | ||
423 | encode (0xff :: Word8), | 424 | encode (0xff :: Word8), |
424 | encode (fromIntegral (B.length $ signature_packet_start p) :: Word32) | 425 | if v==4 |
426 | then encode (fromIntegral (B.length $ signature_packet_start p) :: Word32) | ||
427 | else encode (fromIntegral (B.length $ signature_packet_start p) :: Word64) | ||
428 | |||
425 | ] | 429 | ] |
426 | calculate_signature_trailer x = | 430 | calculate_signature_trailer x = |
427 | error ("Trying to calculate signature trailer for: " ++ show x) | 431 | error ("Trying to calculate signature trailer for: " ++ show x) |
@@ -544,21 +548,23 @@ put_packet (SignaturePacket { version = v, | |||
544 | Just (IssuerPacket keyidS) = find isIssuer unhashed_subpackets | 548 | Just (IssuerPacket keyidS) = find isIssuer unhashed_subpackets |
545 | isIssuer (IssuerPacket {}) = True | 549 | isIssuer (IssuerPacket {}) = True |
546 | isIssuer _ = False | 550 | isIssuer _ = False |
547 | put_packet (SymmetricSessionKeyPacket version salgo s2k encd) = | 551 | put_packet (SignaturePacket { version = v, |
548 | (B.concat [encode version, encode salgo, encode s2k, encd], 3) | ||
549 | put_packet (SignaturePacket { version = 4, | ||
550 | unhashed_subpackets = unhashed_subpackets, | 552 | unhashed_subpackets = unhashed_subpackets, |
551 | hash_head = hash_head, | 553 | hash_head = hash_head, |
552 | signature = signature, | 554 | signature = signature, |
553 | trailer = trailer }) = | 555 | trailer = trailer }) = |
554 | (B.concat $ [ | 556 | (B.concat $ [ |
555 | trailer_top, | 557 | B.take n trailer, |
556 | encode (fromIntegral $ B.length unhashed :: Word16), | 558 | encode (fromIntegral $ B.length unhashed :: Word16), |
557 | unhashed, encode hash_head | 559 | unhashed, encode hash_head |
558 | ] ++ map encode signature, 2) | 560 | ] ++ map encode signature, 2) |
559 | where | 561 | where |
560 | trailer_top = B.reverse $ B.drop 6 $ B.reverse trailer | 562 | n = case B.length trailer - (if v==5 then 10 else 6) of |
563 | x | x >=0 -> x | ||
564 | | otherwise -> 0 -- Should never happen. | ||
561 | unhashed = B.concat $ map encode unhashed_subpackets | 565 | unhashed = B.concat $ map encode unhashed_subpackets |
566 | put_packet (SymmetricSessionKeyPacket version salgo s2k encd) = | ||
567 | (B.concat [encode version, encode salgo, encode s2k, encd], 3) | ||
562 | put_packet (OnePassSignaturePacket { version = version, | 568 | put_packet (OnePassSignaturePacket { version = version, |
563 | signature_type = signature_type, | 569 | signature_type = signature_type, |
564 | hash_algorithm = hash_algorithm, | 570 | hash_algorithm = hash_algorithm, |