From 99ee915c0fdbf5bc718dbd59e9f5bbe9f5f7690c Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Wed, 6 May 2020 06:37:26 -0400 Subject: Implemented v5 fingerprints (draft-ietf-openpgp-rfc4880bis-09). --- Data/OpenPGP.hs | 10 ++++++++++ Data/OpenPGP/Util/Fingerprint.hs | 3 +++ 2 files changed, 13 insertions(+) diff --git a/Data/OpenPGP.hs b/Data/OpenPGP.hs index 17a6927..3064dc5 100644 --- a/Data/OpenPGP.hs +++ b/Data/OpenPGP.hs @@ -845,6 +845,16 @@ parse_packet tag = fmap (UnsupportedPacket tag) getRemainingByteString -- | Helper method for fingerprints and such fingerprint_material :: Packet -> [B.ByteString] +fingerprint_material p | version p == 5 = + [ + B.singleton 0x9A, + encode (10 + fromIntegral (B.length material) :: Word32), + B.singleton 5, encode (timestamp p), encode (key_algorithm p), + encode (fromIntegral (B.length material) :: Word32), + material + ] + where + material = B.concat $ encode_public_key_material p fingerprint_material p | version p == 4 = [ B.singleton 0x99, diff --git a/Data/OpenPGP/Util/Fingerprint.hs b/Data/OpenPGP/Util/Fingerprint.hs index c1d8fef..d88661b 100644 --- a/Data/OpenPGP/Util/Fingerprint.hs +++ b/Data/OpenPGP/Util/Fingerprint.hs @@ -41,15 +41,18 @@ hex (Fingerprint bs) = hexify bs -- fingerprint :: OpenPGP.Packet -> Fingerprint fingerprint p + | OpenPGP.version p == 5 = Fingerprint $ sha256 material | OpenPGP.version p == 4 = Fingerprint $ sha1 material | OpenPGP.version p `elem` [2, 3] = Fingerprint $ md5 material | otherwise = error "Unsupported Packet version or type in fingerprint" where #if defined(VERSION_cryptonite) + sha256 x = Bytes.convert (hashlazy x :: Digest SHA256) sha1 x = Bytes.convert (hashlazy x :: Digest SHA1) md5 x = Bytes.convert (hashlazy x :: Digest MD5) #else + -- TODO: SHA256 (or drop support for non-cryptonite) sha1 = SHA1.hashlazy md5 = MD5.hashlazy #endif -- cgit v1.2.3