blob: 02dc18a0b3dc8adbf581c38ab6f222689acb7869 (
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
{-# 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 Cost
import Shard
import Storage
import Storage.LocalFiles
main :: IO ()
main = do
storedemo
retrievedemo
storedemo :: IO ()
storedemo = do
kek <- genKeyEncryptionKey tunables name password
putStrLn "Very rough estimate of cost to brute-force the password:"
print $ estimateAttack spotAWS $ estimateBruteforceOf kek
(passwordEntropy password)
let esk = encrypt kek secretkey
let sis = shardIdents tunables name keyid
shards <- genShards esk tunables
print =<< mapM (uncurry (storeShard localFiles)) (zip (getIdents sis) shards)
print =<< obscureShards localFiles
where
password = Password "correct horse battery staple"
name = Name "bar"
tunables = testModeTunables -- defaultTunables
keyid = KeyId gpgKey "foobar"
secretkey = SecretKey "this is a gpg private key"
retrievedemo :: IO ()
retrievedemo = do
let sis = shardIdents tunables name keyid
-- we drop 1 to simulate not getting all shards from the servers
let l = drop 1 $ zip [1..] (getIdents sis)
shards <- map (\(RetrieveSuccess s) -> s)
<$> mapM (uncurry (retrieveShard localFiles)) l
let esk = combineShards tunables shards
kek <- genKeyEncryptionKey tunables name password
-- TODO: need to solve the encryption puzzle
case decrypt kek esk of
Just (SecretKey sk) -> print sk
Nothing -> print ("Failed" :: String, esk)
where
password = Password "foo"
name = Name "bar"
tunables = testModeTunables -- defaultTunables
keyid = KeyId gpgKey "foobar"
|