summaryrefslogtreecommitdiff
path: root/KeyRing.hs
diff options
context:
space:
mode:
Diffstat (limited to 'KeyRing.hs')
-rw-r--r--KeyRing.hs29
1 files changed, 23 insertions, 6 deletions
diff --git a/KeyRing.hs b/KeyRing.hs
index b164527..53a1a34 100644
--- a/KeyRing.hs
+++ b/KeyRing.hs
@@ -2158,7 +2158,9 @@ rsaPrivateKeyFromPacket pkt@(SecretKeyPacket {}) = do
2158 , rsaCoefficient = coefficient } 2158 , rsaCoefficient = coefficient }
2159rsaPrivateKeyFromPacket _ = Nothing 2159rsaPrivateKeyFromPacket _ = Nothing
2160 2160
2161secretPemFromPacket packet = 2161secretPemFromPacket packet = pemFromPacket Sec packet
2162
2163pemFromPacket Sec packet =
2162 case key_algorithm packet of 2164 case key_algorithm packet of
2163 RSA -> do 2165 RSA -> do
2164 rsa <- rsaPrivateKeyFromPacket packet -- RSAPrivateKey 2166 rsa <- rsaPrivateKeyFromPacket packet -- RSAPrivateKey
@@ -2168,11 +2170,24 @@ secretPemFromPacket packet =
2168 output = writePEM "RSA PRIVATE KEY" dta 2170 output = writePEM "RSA PRIVATE KEY" dta
2169 Just output 2171 Just output
2170 algo -> Nothing 2172 algo -> Nothing
2173pemFromPacket Pub packet =
2174 case key_algorithm packet of
2175 RSA -> do
2176 rsa <- rsaKeyFromPacket packet
2177 let asn1 = toASN1 (pkcs8 rsa) []
2178 bs = encodeASN1 DER asn1
2179 dta = Base64.encode (L.unpack bs)
2180 output = writePEM "PUBLIC KEY" dta
2181 Just output
2182 algo -> Nothing
2183pemFromPacket AutoAccess p@(PublicKeyPacket {}) = pemFromPacket Pub p
2184pemFromPacket AutoAccess p@(SecretKeyPacket {}) = pemFromPacket Sec p
2185pemFromPacket AutoAccess _ = Nothing
2171 2186
2172writeKeyToFile :: 2187writeKeyToFile ::
2173 Bool -> FileType -> InputFile -> Packet -> IO [(InputFile, KikiReportAction)] 2188 Bool -> StreamInfo -> InputFile -> Packet -> IO [(InputFile, KikiReportAction)]
2174writeKeyToFile False PEMFile fname packet = do 2189writeKeyToFile False stream@(StreamInfo { typ = PEMFile }) fname packet = do
2175 case secretPemFromPacket packet of 2190 case pemFromPacket (access stream) packet of
2176 Just output -> do 2191 Just output -> do
2177 let stamp = toEnum . fromEnum $ timestamp packet 2192 let stamp = toEnum . fromEnum $ timestamp packet
2178 handleIO_ (return [(fname, FailedFileWrite)]) $ do 2193 handleIO_ (return [(fname, FailedFileWrite)]) $ do
@@ -2184,7 +2199,7 @@ writeKeyToFile False PEMFile fname packet = do
2184 return [(fname, ExportedSubkey)] 2199 return [(fname, ExportedSubkey)]
2185 Nothing -> return [(fname, UnableToExport (key_algorithm packet) $ fingerprint packet)] 2200 Nothing -> return [(fname, UnableToExport (key_algorithm packet) $ fingerprint packet)]
2186 2201
2187writeKeyToFile False DNSPresentation fname packet = do 2202writeKeyToFile False StreamInfo { typ = DNSPresentation } fname packet = do
2188 case key_algorithm packet of 2203 case key_algorithm packet of
2189 RSA -> do 2204 RSA -> do
2190 flip (maybe (return [])) 2205 flip (maybe (return []))
@@ -2232,12 +2247,14 @@ writePEMKeys doDecrypt db exports = do
2232 let ds' = map functorToEither ds 2247 let ds' = map functorToEither ds
2233 if null (lefts ds') 2248 if null (lefts ds')
2234 then do 2249 then do
2235 rs <- mapM (\(f,stream,p) -> writeKeyToFile False (typ stream) (ArgFile f) p) 2250 rs <- mapM (\(f,stream,p) -> writeKeyToFile False stream (ArgFile f) p)
2236 (rights ds') 2251 (rights ds')
2237 return $ KikiSuccess (map (first $ resolveForReport Nothing) $ concat rs) 2252 return $ KikiSuccess (map (first $ resolveForReport Nothing) $ concat rs)
2238 else do 2253 else do
2239 return (head $ lefts ds') 2254 return (head $ lefts ds')
2240 where 2255 where
2256 decryptKeys (fname,subspec,[p],stream@(StreamInfo { access=Pub }))
2257 = return $ KikiSuccess (fname,stream,packet p) -- public keys are never encrypted.
2241 decryptKeys (fname,subspec,[p],stream) = do 2258 decryptKeys (fname,subspec,[p],stream) = do
2242 pun <- doDecrypt p 2259 pun <- doDecrypt p
2243 try pun $ \pun -> do 2260 try pun $ \pun -> do