-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
126 lines (96 loc) · 2.31 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) WithSecure Corporation
// https://foundry.withsecure.com
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.
package main
import (
"fmt"
"log"
"runtime"
"time"
"github.com/usbarmory/armory-drive/internal/ble"
"github.com/usbarmory/armory-drive/internal/crypto"
"github.com/usbarmory/armory-drive/internal/hab"
"github.com/usbarmory/armory-drive/internal/ums"
"github.com/usbarmory/tamago/soc/nxp/imx6ul"
usbarmory "github.com/usbarmory/tamago/board/usbarmory/mk2"
)
func init() {
if err := imx6ul.SetARMFreq(900); err != nil {
panic(fmt.Sprintf("WARNING: error setting ARM frequency: %v\n", err))
}
log.SetFlags(0)
}
func main() {
usbarmory.LED("blue", false)
usbarmory.LED("white", false)
if err := usbarmory.MMC.Detect(); err != nil {
log.Fatal(err)
}
keyring := &crypto.Keyring{}
if err := keyring.Init(false); err != nil {
log.Fatal(err)
}
drive := &ums.Drive{
Cipher: true,
Keyring: keyring,
Mult: ums.BLOCK_SIZE_MULTIPLIER,
}
ble := &ble.BLE{
Drive: drive,
Keyring: keyring,
}
ble.Init()
if drive.Init(usbarmory.SD) != nil {
var code []byte
var err error
// provision Secure Boot as required
hab.Init()
// Do not offer pairing code on first time installs (or
// recovery) as that pairing might become invalid at reboot if
// Secure Boot has been just activated, rather offer pairing
// only by firmware booted internally.
if !imx6ul.SDP {
code, err = ble.PairingMode()
if err != nil {
log.Fatal(err)
}
}
drive.Cipher = false
drive.Mult = 1
drive.Ready = true
drive.Init(ums.Pairing(code, keyring))
go pairingFeedback(drive.PairingComplete)
}
device := drive.ConfigureUSB()
imx6ul.USB1.Init()
imx6ul.USB1.DeviceMode()
// To further reduce the attack surface, start the USB stack only when
// the card is unlocked (or in pairing mode).
if !drive.Ready {
imx6ul.USB1.Stop()
for !drive.Ready {
runtime.Gosched()
time.Sleep(10 * time.Millisecond)
}
imx6ul.USB1.Run()
}
imx6ul.USB1.Reset()
imx6ul.USB1.Start(device)
}
func pairingFeedback(done chan bool) {
var on bool
for {
select {
case <-done:
usbarmory.LED("blue", false)
return
default:
}
on = !on
usbarmory.LED("blue", on)
runtime.Gosched()
time.Sleep(1 * time.Second)
}
}