summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2020-05-06 06:37:26 -0400
committerJoe Crayne <joe@jerkface.net>2020-05-06 09:33:33 -0400
commit99ee915c0fdbf5bc718dbd59e9f5bbe9f5f7690c (patch)
treed376f6405deeb640aed44ef5995b08fc9a3099a4
parent02680b1ed3b37c0cc16e04e51e613d53ff9dbab8 (diff)
Implemented v5 fingerprints (draft-ietf-openpgp-rfc4880bis-09).
-rw-r--r--Data/OpenPGP.hs10
-rw-r--r--Data/OpenPGP/Util/Fingerprint.hs3
2 files changed, 13 insertions, 0 deletions
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
845 845
846-- | Helper method for fingerprints and such 846-- | Helper method for fingerprints and such
847fingerprint_material :: Packet -> [B.ByteString] 847fingerprint_material :: Packet -> [B.ByteString]
848fingerprint_material p | version p == 5 =
849 [
850 B.singleton 0x9A,
851 encode (10 + fromIntegral (B.length material) :: Word32),
852 B.singleton 5, encode (timestamp p), encode (key_algorithm p),
853 encode (fromIntegral (B.length material) :: Word32),
854 material
855 ]
856 where
857 material = B.concat $ encode_public_key_material p
848fingerprint_material p | version p == 4 = 858fingerprint_material p | version p == 4 =
849 [ 859 [
850 B.singleton 0x99, 860 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
41-- <http://tools.ietf.org/html/rfc4880#section-12.2> 41-- <http://tools.ietf.org/html/rfc4880#section-12.2>
42fingerprint :: OpenPGP.Packet -> Fingerprint 42fingerprint :: OpenPGP.Packet -> Fingerprint
43fingerprint p 43fingerprint p
44 | OpenPGP.version p == 5 = Fingerprint $ sha256 material
44 | OpenPGP.version p == 4 = Fingerprint $ sha1 material 45 | OpenPGP.version p == 4 = Fingerprint $ sha1 material
45 | OpenPGP.version p `elem` [2, 3] = Fingerprint $ md5 material 46 | OpenPGP.version p `elem` [2, 3] = Fingerprint $ md5 material
46 | otherwise = error "Unsupported Packet version or type in fingerprint" 47 | otherwise = error "Unsupported Packet version or type in fingerprint"
47 where 48 where
48 49
49#if defined(VERSION_cryptonite) 50#if defined(VERSION_cryptonite)
51 sha256 x = Bytes.convert (hashlazy x :: Digest SHA256)
50 sha1 x = Bytes.convert (hashlazy x :: Digest SHA1) 52 sha1 x = Bytes.convert (hashlazy x :: Digest SHA1)
51 md5 x = Bytes.convert (hashlazy x :: Digest MD5) 53 md5 x = Bytes.convert (hashlazy x :: Digest MD5)
52#else 54#else
55 -- TODO: SHA256 (or drop support for non-cryptonite)
53 sha1 = SHA1.hashlazy 56 sha1 = SHA1.hashlazy
54 md5 = MD5.hashlazy 57 md5 = MD5.hashlazy
55#endif 58#endif