This repository has been archived by the owner on Apr 5, 2024. It is now read-only.
/
enclavemain.go
132 lines (106 loc) · 3.49 KB
/
enclavemain.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
127
128
129
130
131
132
// +build enclave
/* Copyright (c) Edgeless Systems GmbH
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
package main
import (
"flag"
"os"
"path"
"path/filepath"
"syscall"
"github.com/edgelesssys/edgelessdb/edb/core"
"github.com/edgelesssys/edgelessdb/edb/rt"
"github.com/edgelesssys/ego/enclave"
"github.com/edgelesssys/marblerun/marble/premain"
)
// Don't touch! Automatically injected at build-time.
var version = "0.0.0"
var gitCommit = "0000000000000000000000000000000000000000"
const internalPath = "/tmp/edb" // supposed to be mounted in emain.cpp
func main() {
rt.Log.Printf("EdgelessDB v%v (%v)\n", version, gitCommit)
runAsMarble := flag.Bool("marble", false, "Run edb with Marblerun")
flag.Parse()
if *runAsMarble {
// Contact Marblerun to provision edb
if err := premain.PreMainEgo(); err != nil {
panic(err)
}
}
config := core.Config{
DataPath: "data",
APIAddress: ":8080",
CertificateDNSName: "localhost",
Debug: false,
LogDir: "",
}
// Load config parameters from environment variables
config = core.FillConfigFromEnvironment(config)
if err := os.Mkdir(internalPath, 0); err != nil {
panic(err)
}
// mount logDir from hostfs if set
if len(config.LogDir) > 0 {
absLogPath := enclaveAbsPath(config.LogDir)
if err := os.MkdirAll(hostPath(absLogPath), 0700); err != nil {
panic(err)
}
if err := syscall.Mount(absLogPath, "/log", "oe_host_file_system", 0, ""); err != nil {
panic(err)
}
config.LogDir = "/log"
}
// mount rocksdb dir from hostfs
absDataPath := enclaveAbsPath(config.DataPath)
if err := os.MkdirAll(hostPath(absDataPath), 0700); err != nil {
panic(err)
}
if err := syscall.Mount(filepath.Join(absDataPath, "#rocksdb"), "/data/#rocksdb", "oe_host_file_system", 0, ""); err != nil {
panic(err)
}
// Create to store sealing key
if !*runAsMarble {
if err := syscall.Mount(filepath.Join(absDataPath, core.PersistenceDir), filepath.Join("/data", core.PersistenceDir), "oe_host_file_system", 0, ""); err != nil {
panic(err)
}
if err := os.Mkdir(path.Join(hostPath(absDataPath), core.PersistenceDir), 0700); err != nil && !os.IsExist(err) {
panic(err)
}
}
config.DataPath = "/data"
run(config, *runAsMarble, internalPath, "255.0.0.1")
}
func enclaveAbsPath(path string) string {
if !filepath.IsAbs(path) {
cwd := os.Getenv("EDG_CWD")
if cwd == "" {
panic("cwd")
}
path = filepath.Join(cwd, path)
}
return path
}
func hostPath(path string) string {
path = enclaveAbsPath(path)
return filepath.Join(filepath.FromSlash("/edg"), "hostfs", filepath.Clean(path))
}
type runtime struct{}
func (runtime) GetRemoteReport(reportData []byte) ([]byte, error) {
return enclave.GetRemoteReport(reportData)
}
func (runtime) GetProductSealKey() ([]byte, error) {
key, _, err := enclave.GetProductSealKey()
return key, err
}
func (runtime) IsEnclave() bool {
return true
}