diff options
author | Joe Crayne <joe@jerkface.net> | 2020-05-10 20:03:30 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-05-10 20:03:30 -0400 |
commit | 47fdd273f68e0af73595daa1f3a9cdff2c8a9320 (patch) | |
tree | 0c08b57b5788a813d0dee875ff8ad67d62fc69c5 /Data/OpenPGP | |
parent | 99ee915c0fdbf5bc718dbd59e9f5bbe9f5f7690c (diff) |
Compute v5 fingerprints for v4 keys.
Diffstat (limited to 'Data/OpenPGP')
-rw-r--r-- | Data/OpenPGP/Util.hs | 1 | ||||
-rw-r--r-- | Data/OpenPGP/Util/Fingerprint.hs | 20 |
2 files changed, 13 insertions, 8 deletions
diff --git a/Data/OpenPGP/Util.hs b/Data/OpenPGP/Util.hs index 1781d6d..889ff10 100644 --- a/Data/OpenPGP/Util.hs +++ b/Data/OpenPGP/Util.hs | |||
@@ -1,5 +1,6 @@ | |||
1 | module Data.OpenPGP.Util | 1 | module Data.OpenPGP.Util |
2 | ( fingerprint | 2 | ( fingerprint |
3 | , fingerprintv | ||
3 | , Fingerprint(..) | 4 | , Fingerprint(..) |
4 | , hex | 5 | , hex |
5 | , decryptSecretKey | 6 | , decryptSecretKey |
diff --git a/Data/OpenPGP/Util/Fingerprint.hs b/Data/OpenPGP/Util/Fingerprint.hs index d88661b..cda25f6 100644 --- a/Data/OpenPGP/Util/Fingerprint.hs +++ b/Data/OpenPGP/Util/Fingerprint.hs | |||
@@ -1,11 +1,12 @@ | |||
1 | {-# LANGUAGE CPP #-} | 1 | {-# LANGUAGE CPP #-} |
2 | module Data.OpenPGP.Util.Fingerprint (fingerprint,Fingerprint(..),hex) where | 2 | module Data.OpenPGP.Util.Fingerprint (fingerprint,fingerprintv,Fingerprint(..),hex) where |
3 | 3 | ||
4 | import qualified Data.OpenPGP as OpenPGP | 4 | import qualified Data.OpenPGP as OpenPGP |
5 | import qualified Data.ByteString as BS | 5 | import qualified Data.ByteString as BS |
6 | import qualified Data.ByteString.Lazy as LZ | 6 | import qualified Data.ByteString.Lazy as LZ |
7 | import Data.Char (toUpper) | 7 | import Data.Char (toUpper) |
8 | import Data.Word (Word8) | 8 | import Data.Word (Word8) |
9 | import GHC.Stack | ||
9 | import Numeric (showHex) | 10 | import Numeric (showHex) |
10 | 11 | ||
11 | #if defined(VERSION_cryptonite) | 12 | #if defined(VERSION_cryptonite) |
@@ -39,12 +40,15 @@ hex (Fingerprint bs) = hexify bs | |||
39 | 40 | ||
40 | -- | Generate a key fingerprint from a PublicKeyPacket or SecretKeyPacket | 41 | -- | Generate a key fingerprint from a PublicKeyPacket or SecretKeyPacket |
41 | -- <http://tools.ietf.org/html/rfc4880#section-12.2> | 42 | -- <http://tools.ietf.org/html/rfc4880#section-12.2> |
42 | fingerprint :: OpenPGP.Packet -> Fingerprint | 43 | fingerprint :: HasCallStack => OpenPGP.Packet -> Fingerprint |
43 | fingerprint p | 44 | fingerprint p = fingerprintv (OpenPGP.auto_fp_version p) p |
44 | | OpenPGP.version p == 5 = Fingerprint $ sha256 material | 45 | |
45 | | OpenPGP.version p == 4 = Fingerprint $ sha1 material | 46 | fingerprintv :: HasCallStack => Word8 -> OpenPGP.Packet -> Fingerprint |
46 | | OpenPGP.version p `elem` [2, 3] = Fingerprint $ md5 material | 47 | fingerprintv v p = case v of |
47 | | otherwise = error "Unsupported Packet version or type in fingerprint" | 48 | 5 -> Fingerprint $ sha256 material |
49 | 4 -> Fingerprint $ sha1 material | ||
50 | 3 -> Fingerprint $ md5 material | ||
51 | _ -> error "Unsupported Packet version or type in fingerprint" | ||
48 | where | 52 | where |
49 | 53 | ||
50 | #if defined(VERSION_cryptonite) | 54 | #if defined(VERSION_cryptonite) |
@@ -57,4 +61,4 @@ fingerprint p | |||
57 | md5 = MD5.hashlazy | 61 | md5 = MD5.hashlazy |
58 | #endif | 62 | #endif |
59 | 63 | ||
60 | material = LZ.concat $ OpenPGP.fingerprint_material p | 64 | material = LZ.concat $ OpenPGP.fingerprint_materialv v p |