diff options
author | joe <joe@jerkface.net> | 2016-04-23 21:13:40 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2016-04-23 21:13:40 -0400 |
commit | 5000de4f1079004fa398e4b129896f5e59e9c9df (patch) | |
tree | 94f55eb7d19bc4e06f35bbf801b6d443f10e9eb6 /KeyRing.hs | |
parent | ec89ad06f3388b7c35f939f30011bea8f2304c6b (diff) |
Added --keypairs support to export-public.
Diffstat (limited to 'KeyRing.hs')
-rw-r--r-- | KeyRing.hs | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -2158,7 +2158,9 @@ rsaPrivateKeyFromPacket pkt@(SecretKeyPacket {}) = do | |||
2158 | , rsaCoefficient = coefficient } | 2158 | , rsaCoefficient = coefficient } |
2159 | rsaPrivateKeyFromPacket _ = Nothing | 2159 | rsaPrivateKeyFromPacket _ = Nothing |
2160 | 2160 | ||
2161 | secretPemFromPacket packet = | 2161 | secretPemFromPacket packet = pemFromPacket Sec packet |
2162 | |||
2163 | pemFromPacket 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 |
2173 | pemFromPacket 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 | ||
2183 | pemFromPacket AutoAccess p@(PublicKeyPacket {}) = pemFromPacket Pub p | ||
2184 | pemFromPacket AutoAccess p@(SecretKeyPacket {}) = pemFromPacket Sec p | ||
2185 | pemFromPacket AutoAccess _ = Nothing | ||
2171 | 2186 | ||
2172 | writeKeyToFile :: | 2187 | writeKeyToFile :: |
2173 | Bool -> FileType -> InputFile -> Packet -> IO [(InputFile, KikiReportAction)] | 2188 | Bool -> StreamInfo -> InputFile -> Packet -> IO [(InputFile, KikiReportAction)] |
2174 | writeKeyToFile False PEMFile fname packet = do | 2189 | writeKeyToFile 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 | ||
2187 | writeKeyToFile False DNSPresentation fname packet = do | 2202 | writeKeyToFile 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 |