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

add a command-line tool for encoding data to SDMF shares

parent 86b76488
No related branches found
No related tags found
1 merge request!10expose random IV generation in the public interface
module Main where
import qualified Crypto.PubKey.RSA as RSA
import Data.Binary (encode)
import Data.ByteString.Base32 (encodeBase32Unpadded)
import qualified Data.ByteString.Lazy as LB
import qualified Data.Text as T
import qualified Data.Text.IO as T
import System.IO (stdin)
import qualified Tahoe.SDMF as SDMF
import qualified Tahoe.SDMF.Keys as SDMF.Keys
main :: IO ()
main = do
plaintext <- LB.hGetContents stdin
keypair <- SDMF.Keys.KeyPair . snd <$> RSA.generate (2048 `div` 8) e
Just iv <- SDMF.randomIV
let ciphertext = SDMF.encrypt keypair iv plaintext
(shares, writeCap) <- SDMF.encode keypair iv 1 3 5 ciphertext
let shareBytes = encode <$> shares
let si = SDMF.Keys.unStorageIndex . SDMF.verifierStorageIndex . SDMF.readerVerifier . SDMF.writerReader $ writeCap
mapM_ (uncurry (writeShare si)) (zip [0 :: Int ..] shareBytes)
T.putStrLn (SDMF.dangerRealShow (SDMF.SDMFWriter writeCap))
where
e = 0x10001
writeShare si shnum = LB.writeFile $ (T.unpack . T.toLower . encodeBase32Unpadded $ si) <> "." <> show shnum
......@@ -164,3 +164,19 @@ executable make-keypairs
, cryptonite
, tahoe-ssk
, x509
executable encode-ssk
import:
warnings
, language
main-is: Main.hs
hs-source-dirs: encode-ssk
build-depends:
, base
, base32
, binary
, bytestring
, cryptonite
, tahoe-ssk
, text
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment