on master help sign in
Add a function for reading PEM private keys

This depends on a change to `jwt` which makes it use `cryptonite` for RSA signatures. The PR is pending.

commita35bbbe40f333bb6db6c941d54caa695e6f92351 authorKirill Elagin <kirelagin@gmail.com> dateFri 10 Aug 2018, 22:04 (8 years ago) parentaf636e7
3 files changed+32−3
package.yaml+3−1 src/Crypto/PubKey/RSA/Read.hs+27 src/GitHub/App/Auth.hs+2−2
package.yaml+3−1
@@ -40,7 +40,7 @@ library:
4040 dependencies:
4141 - aeson
4242 - bytestring
43− - crypto-pubkey-types
43+ - cryptonite
4444 - github
4545 - http-client
4646 - http-client-tls
@@ -50,3 +50,5 @@ library:
5050 - safe-exceptions
5151 - text
5252 - 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 @@
77{-# LANGUAGE DataKinds #-}
88
99module GitHub.App.Auth
10− ( AppAuth
10+ ( AppAuth (..)
1111
1212 , InstallationAuth
1313 , mkInstallationAuth
@@ -21,7 +21,7 @@ import Control.Concurrent (MVar, newMVar, putMVar, readMVar, takeMVar)
2121import Control.Exception.Safe (bracketOnError, catch)
2222import Control.Monad.Except (ExceptT, MonadError (throwError), runExceptT)
2323import Control.Monad.Trans (lift)
24−import Crypto.Types.PubKey.RSA (PrivateKey)
24+import Crypto.PubKey.RSA (PrivateKey)
2525import Data.Aeson (FromJSON (..), withObject, (.:))
2626import qualified Data.ByteString.Lazy as LBS
2727import Data.Functor (($>))