2016-04-15 08:54:02 +00:00
|
|
|
// +build ignore
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-04-18 08:09:18 +00:00
|
|
|
"crypto/rand"
|
2016-04-15 08:54:02 +00:00
|
|
|
"encoding/base64"
|
2016-04-18 08:09:18 +00:00
|
|
|
"fmt"
|
2016-04-15 08:54:02 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-04-18 08:09:18 +00:00
|
|
|
|
|
|
|
"github.com/jfrazelle/binctr/cryptar"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
nonceSize = 24
|
2016-04-15 08:54:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-04-18 08:09:18 +00:00
|
|
|
// prompt for key
|
2016-04-15 08:54:02 +00:00
|
|
|
wd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
out, err := os.Create(filepath.Join(wd, "rootfs.go"))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
tarPath := filepath.Join(wd, "image.tar")
|
|
|
|
|
|
|
|
out.Write([]byte("// This file is autogenerated; DO NOT EDIT DIRECTLY\n// See generate.go for more info\npackage main\n\nconst (\n"))
|
2016-04-18 08:09:18 +00:00
|
|
|
out.Write([]byte("\t// DATA is the encrypted tarball data\n"))
|
2016-04-15 08:54:02 +00:00
|
|
|
out.Write([]byte("\tDATA = `"))
|
|
|
|
f, err := ioutil.ReadFile(tarPath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2016-04-18 08:09:18 +00:00
|
|
|
key := make([]byte, 32)
|
|
|
|
if _, err := rand.Read(key); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
gcmOut, err := cryptar.Encrypt(f, key)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
out.Write([]byte(gcmOut))
|
2016-04-15 08:54:02 +00:00
|
|
|
|
|
|
|
out.Write([]byte("`\n"))
|
|
|
|
out.Write([]byte(")\n"))
|
2016-04-18 08:09:18 +00:00
|
|
|
|
|
|
|
fmt.Println("key is: ", base64.StdEncoding.EncodeToString(key))
|
2016-04-15 08:54:02 +00:00
|
|
|
}
|