summaryrefslogtreecommitdiff
path: root/KeyRing.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-05-12 20:51:50 -0400
committerjoe <joe@jerkface.net>2014-05-12 20:51:50 -0400
commit83c9390271cfcb9cd64d0ffab0a2713f204c2ccc (patch)
tree0b5c4a8aa69a109050d6aaedc12c452b469c6049 /KeyRing.hs
parent91dd66f6478ec87aaf184daab7c44b17f9796fce (diff)
parse email-style Date: headers when importing PEM files.
Diffstat (limited to 'KeyRing.hs')
-rw-r--r--KeyRing.hs17
1 files changed, 12 insertions, 5 deletions
diff --git a/KeyRing.hs b/KeyRing.hs
index e0c3b77..94039f6 100644
--- a/KeyRing.hs
+++ b/KeyRing.hs
@@ -113,7 +113,7 @@ import Data.ASN1.Types ( toASN1, ASN1Object, fromASN1
113import Data.ASN1.BitArray ( BitArray(..), toBitArray ) 113import Data.ASN1.BitArray ( BitArray(..), toBitArray )
114import Data.ASN1.Encoding ( encodeASN1, encodeASN1', decodeASN1, decodeASN1' ) 114import Data.ASN1.Encoding ( encodeASN1, encodeASN1', decodeASN1, decodeASN1' )
115import Data.ASN1.BinaryEncoding ( DER(..) ) 115import Data.ASN1.BinaryEncoding ( DER(..) )
116import Data.Time.Clock.POSIX ( POSIXTime, utcTimeToPOSIXSeconds ) 116import Data.Time.Clock.POSIX ( POSIXTime, utcTimeToPOSIXSeconds, posixSecondsToUTCTime )
117import Data.Time.Clock ( UTCTime ) 117import Data.Time.Clock ( UTCTime )
118import Data.Bits ( Bits ) 118import Data.Bits ( Bits )
119import Data.Text.Encoding ( encodeUtf8 ) 119import Data.Text.Encoding ( encodeUtf8 )
@@ -1500,9 +1500,9 @@ readSecretPEMFile fname = do
1500 let ctx = InputFileContext "" "" 1500 let ctx = InputFileContext "" ""
1501 -- Note: The key's timestamp is included in it's fingerprint. 1501 -- Note: The key's timestamp is included in it's fingerprint.
1502 -- Therefore, we should attempt to preserve it. 1502 -- Therefore, we should attempt to preserve it.
1503 timestamp <- getInputFileTime ctx fname 1503 stamp <- getInputFileTime ctx fname
1504 input <- readInputFileL ctx fname 1504 input <- readInputFileL ctx fname
1505 let dta = catMaybes $ scanAndParse (pkcs1 <> cert) $ Char8.lines input 1505 let edta = scanAndParse (fmap Left dateParser <> fmap Right (pkcs1 <> cert)) $ Char8.lines input
1506 pkcs1 = fmap (parseRSAPrivateKey . pemBlob) 1506 pkcs1 = fmap (parseRSAPrivateKey . pemBlob)
1507 $ pemParser $ Just "RSA PRIVATE KEY" 1507 $ pemParser $ Just "RSA PRIVATE KEY"
1508 cert = fmap (fmap PEMCertificate . parseCertBlob False . pemBlob) 1508 cert = fmap (fmap PEMCertificate . parseCertBlob False . pemBlob)
@@ -1514,7 +1514,7 @@ readSecretPEMFile fname = do
1514 let _ = rsa :: RSAPrivateKey 1514 let _ = rsa :: RSAPrivateKey
1515 return $ PEMPacket $ SecretKeyPacket 1515 return $ PEMPacket $ SecretKeyPacket
1516 { version = 4 1516 { version = 4
1517 , timestamp = toEnum (fromEnum timestamp) 1517 , timestamp = fromTime stamp -- toEnum (fromEnum stamp)
1518 , key_algorithm = RSA 1518 , key_algorithm = RSA
1519 , key = [ -- public fields... 1519 , key = [ -- public fields...
1520 ('n',rsaN rsa) 1520 ('n',rsaN rsa)
@@ -1532,7 +1532,14 @@ readSecretPEMFile fname = do
1532 , encrypted_data = "" 1532 , encrypted_data = ""
1533 , is_subkey = True 1533 , is_subkey = True
1534 } 1534 }
1535 return dta 1535 dta = catMaybes $ map snd $ scanl mergeDate (stamp,Nothing) edta
1536 mergeDate (_,obj) (Left tm) = (fromTime tm,obj)
1537 mergeDate (tm,_) (Right (Just (PEMPacket key))) = (tm,Just $ PEMPacket key')
1538 where key' = if tm < fromTime (timestamp key)
1539 then key { timestamp = fromTime tm }
1540 else key
1541 mergeDate (tm,_) (Right mb) = (tm,mb)
1542 return $ dta
1536 1543
1537doImport 1544doImport
1538 :: Ord k => 1545 :: Ord k =>