summaryrefslogtreecommitdiffhomepage
path: root/keysafe.hs
blob: f1d87fafc19f8ee7c5240ed27b9af5c03faabd1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# LANGUAGE OverloadedStrings #-}

{- Copyright 2016 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU AGPL version 3 or higher.
 -}

module Main where

import Types
import Tunables
import Encryption
import Shard
import Raaz.Core.Encode
import System.IO
import System.Posix.ByteString
import qualified Data.ByteString as B

main :: IO ()
main = do
	kek <- genKeyEncryptionKey tunables name password
	let esk = encrypt kek secretkey
	let sis = shardIdents tunables name keyid
	shards <- genShards esk tunables
	mapM_ (uncurry store) (zip (getIdents sis) shards)
  where
	password = Password "foo"
	name = Name "bar"
	tunables = testModeTunables -- defaultTunables
	keyid = KeyId gpgKey "foobar"
	secretkey = SecretKey "this is a gpg private key"

store :: StorableObjectIdent -> StorableObject -> IO ()
store i o = do
	print $ toByteString i
	fd <- openFd (toByteString i) WriteOnly (Just 0o666)
		(defaultFileFlags { exclusive = True } )
	h <- fdToHandle fd
	B.hPut h (fromStorableObject o)
	hClose h