Skip to content
Snippets Groups Projects
Commit 97528038 authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

Add a tool for extracting the public key from a signing key

parent e080beb1
No related branches found
No related tags found
1 merge request!105Add a tool for extracting the public key from a signing key
......@@ -67,6 +67,15 @@ executable PaymentServer-generate-key
, PaymentServer
default-language: Haskell2010
executable PaymentServer-get-public-key
hs-source-dirs: get-public-key
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wmissing-import-lists -Wunused-imports
build-depends: base
, text
, PaymentServer
default-language: Haskell2010
test-suite PaymentServer-tests
type: exitcode-stdio-1.0
hs-source-dirs: test
......
-- | Extract a public key from Ristretto-flavored PrivacyPass signing key read from stdin.
module Main
( main
) where
import Prelude hiding
( putStrLn
, getLine
)
import Data.Text.IO
( putStrLn
, getLine
)
import PaymentServer.Ristretto
( getPublicKey
)
main :: IO ()
main = getLine >>= getPublicKey >>= putStrLn
......@@ -93,6 +93,16 @@
hsSourceDirs = [ "generate-key" ];
mainPath = [ "Main.hs" ];
};
"PaymentServer-get-public-key" = {
depends = [
(hsPkgs."base" or (errorHandler.buildDepError "base"))
(hsPkgs."text" or (errorHandler.buildDepError "text"))
(hsPkgs."PaymentServer" or (errorHandler.buildDepError "PaymentServer"))
];
buildable = true;
hsSourceDirs = [ "get-public-key" ];
mainPath = [ "Main.hs" ];
};
};
tests = {
"PaymentServer-tests" = {
......
......@@ -4,6 +4,7 @@
module PaymentServer.Ristretto
( Issuance(Issuance)
, randomSigningKey
, getPublicKey
, ristretto
) where
......@@ -159,3 +160,14 @@ randomSigningKey = do
result <- peekCString cString
free cString
return $ pack result
-- | getPublicKey returns the base64 encoded public key corresponding to the
-- base64 encoded signing key passed to it.
getPublicKey :: Text -> IO Text
getPublicKey enc_skey = do
enc_cstr_skey <- newCString . unpack $ enc_skey
skey <- signing_key_decode_base64 $ enc_cstr_skey
pkey <- signing_key_get_public_key skey
enc_cstr_pkey <- public_key_encode_base64 pkey
enc_pkey <- peekCString enc_cstr_pkey
return $ pack enc_pkey
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment