on master help sign in
Add a function for reading PEM private keys
a35bbbeKirill Elagin
package.yaml+3−1
@@ -40,7 +40,7 @@ library:
40 dependencies:
40 dependencies:
41 - aeson
41 - aeson
42 - bytestring
42 - bytestring
43− - crypto-pubkey-types
43+ - cryptonite
44 - github
44 - github
45 - http-client
45 - http-client
46 - http-client-tls
46 - http-client-tls
@@ -50,3 +50,5 @@ library:
50 - safe-exceptions
50 - safe-exceptions
51 - text
51 - text
52 - time
52 - time
53+ - x509
54+ - x509-store
src/Crypto/PubKey/RSA/Read.hsnew file+27
@@ -0,0 +1,27 @@
1+{- This Source Code Form is subject to the terms of the Mozilla Public
2+ - License, v. 2.0. If a copy of the MPL was not distributed with this
3+ - file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+ -}
5+
6+module Crypto.PubKey.RSA.Read
7+ ( ReadRsaKeyError (..)
8+ , readRsaPem
9+ ) where
10+
11+import Crypto.PubKey.RSA (PrivateKey)
12+import Data.X509 (PrivKey (PrivKeyRSA))
13+import Data.ByteString (ByteString)
14+import Data.X509.Memory (readKeyFileFromMemory)
15+
16+
17+data ReadRsaKeyError
18+ = SingleKeyExpected { rrkeActualKeysCount :: Int }
19+ | NotRsaKey
20+
21+readRsaPem :: ByteString -> Either ReadRsaKeyError PrivateKey
22+readRsaPem bs =
23+ case readKeyFileFromMemory bs of
24+ [k] -> case k of
25+ PrivKeyRSA rsaKey -> Right rsaKey
26+ _ -> Left NotRsaKey
27+ l -> Left $ SingleKeyExpected (length l)
src/GitHub/App/Auth.hs+2−2
@@ -7,7 +7,7 @@
7{-# LANGUAGE DataKinds #-}
7{-# LANGUAGE DataKinds #-}
8
8
9module GitHub.App.Auth
9module GitHub.App.Auth
10− ( AppAuth
10+ ( AppAuth (..)
11
11
12 , InstallationAuth
12 , InstallationAuth
13 , mkInstallationAuth
13 , mkInstallationAuth
@@ -21,7 +21,7 @@ import Control.Concurrent (MVar, newMVar, putMVar, readMVar, takeMVar)
21import Control.Exception.Safe (bracketOnError, catch)
21import Control.Exception.Safe (bracketOnError, catch)
22import Control.Monad.Except (ExceptT, MonadError (throwError), runExceptT)
22import Control.Monad.Except (ExceptT, MonadError (throwError), runExceptT)
23import Control.Monad.Trans (lift)
23import Control.Monad.Trans (lift)
24−import Crypto.Types.PubKey.RSA (PrivateKey)
24+import Crypto.PubKey.RSA (PrivateKey)
25import Data.Aeson (FromJSON (..), withObject, (.:))
25import Data.Aeson (FromJSON (..), withObject, (.:))
26import qualified Data.ByteString.Lazy as LBS
26import qualified Data.ByteString.Lazy as LBS
27import Data.Functor (($>))
27import Data.Functor (($>))