-
Notifications
You must be signed in to change notification settings - Fork 48
/
usercommands.go
66 lines (58 loc) · 1.34 KB
/
usercommands.go
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
59
60
61
62
63
64
65
66
// 25 september 2016
package main
import (
"fmt"
"io"
"github.com/andlabs/reallymine/command"
"github.com/andlabs/reallymine/disk"
"github.com/andlabs/reallymine/kek"
)
func runUntilDEK(d *disk.Disk, out io.Writer) (dec *Decrypter, err error) {
dec = &Decrypter{
Disk: d,
Out: out,
}
err = dec.FindKeySector()
if err != nil {
return nil, err
}
asker, err := kek.NewAsker(kek.AskReal)
if err != nil {
return nil, err
}
err = dec.ExtractDEK(asker)
if err != nil {
return nil, err
}
return dec, nil
}
func cGetDEK(d *disk.Disk) error {
dec, err := runUntilDEK(d, nil)
if err != nil {
return err
}
fmt.Printf("%s\n", formatBridge(dec.Bridge))
fmt.Printf("DEK: %s\n", formatKey(dec.DEK))
// TODO make this a format function?
fmt.Printf("decryption steps: %v\n", dec.Bridge.DecryptLoopSteps())
return nil
}
var getdek = &command.Command{
Name: "getdek",
Args: []command.Arg{command.ArgDisk},
Description: "Gets the DEK and decryption steps to use on %s and prints it on stdout.",
Do: cGetDEK,
}
func cDecrypt(d *disk.Disk, out io.Writer) error {
dec, err := runUntilDEK(d, out)
if err != nil {
return err
}
return dec.DecryptDisk()
}
var decrypt = &command.Command{
Name: "decrypt",
Args: []command.Arg{command.ArgDisk, command.ArgOutImage},
Description: "Decrypts the entire disk %s to %s.",
Do: cDecrypt,
}