-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
146 lines (125 loc) · 3.08 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//go:build go1.17
// +build go1.17
/*
*
* BSD 3-Clause License
*
* Copyright (c) 2020 Ermites.IO
* All rights reserved.
*
*/
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"ermites.io/pkisauce/config"
)
func jsonErrorLineChar(input string, offset int) {
}
func Usage(cmd string) {
fmt.Printf("usage: %s [options] <pkidesc1.json pkidesc2.json ...>\n", cmd)
fmt.Printf("where [options]:\n")
fmt.Printf(" -userdata <data>\n")
fmt.Printf(" -pkidebug <name>\n")
fmt.Printf(" -version\n")
}
// args:
// -pkidebug <name>: output to <name> stdin using test templates.
// -test : output pkscd & pkscc code to debug the policy.
func main() {
var err error
//fmt.Printf("Flavors: %d %d %d %d %d\n", FlavorNone, FlavorGoTLS, FlavorGoGRPC, FlavorPEM, FlavorJavaGRPC)
debugFlag := flag.String("pkidebug", "", "display the defined pki node to stdout")
userFlag := flag.String("userdata", "", "add the following user data to the certificate in 'Locality'")
verFlag := flag.Bool("version", false, "output version")
//json2cfFlag := flag.Bool("j2c", false, "read a json conf stdin and stdout a conf")
//cf2jsonFlag := flag.Bool("c2j", false, "read a conf stdin and stdout a json conf")
flag.Parse()
argv := flag.Args()
if *verFlag {
fmt.Printf("PKI sauce version %s (c) 2020 ERMITES.io\nwe're saucing TLS1.3+ on your GRPC services\n", PkiSauceVersion)
os.Exit(0)
}
if len(argv) == 0 {
fmt.Printf("no pkisauce conf given\n")
Usage(os.Args[0])
os.Exit(1)
}
// let's test our shit...
ca, err := NewCA(182)
if err != nil {
panic(err)
}
// create the ephmeral PKI.
// the pki will include some userdata
// maybe later at node level inside the config directly..
pki, err := NewPKI(ca, *userFlag)
if err != nil {
panic(err)
}
// if multiple files are given they represent ONE pki.
// we build that one view.
for _, fileArgv := range argv {
configFile, err := filepath.Abs(fileArgv)
if err != nil {
panic(err)
}
fmt.Printf("parsing '%s'\n", configFile)
//cfg, err := config.NewJSON(configFile)
cfg, err := config.New(configFile)
if err != nil {
panic(err)
}
// we parse and verify nothing is missing to build a policy
err = pki.IncludeConfig(cfg)
if err != nil {
panic(err)
}
}
/*
if len(*debugFlag) > 0 {
fmt.Printf("debug mode\n")
err = pki.Debug(*debugFlag)
if err != nil {
panic(err)
}
os.Exit(0)
}
*/
// now let's generate a file for each
// templating.
for _, node := range pki.Nodes() {
if len(*debugFlag) > 0 {
if node.Name != *debugFlag {
continue
}
}
// create a node local list of all pki servers
fmt.Printf("generating '%s' (srv:%s clt:%s) in '%s'\n", node.Name, node.ServerUUID, node.ClientUUID, node.Path)
if pki.IsClient(node.Name) {
node.Client = true
}
err = node.Export()
if err != nil {
return
}
err := pki.BuildNodePolicy(node)
if err != nil {
panic(err)
}
switch {
case len(*debugFlag) > 0:
err = node.generateDebug()
os.Exit(0)
default:
err = node.generateFiles()
if err != nil {
panic(err)
}
}
}
fmt.Printf("done\n")
os.Exit(0)
}