-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-form.go
131 lines (107 loc) · 3.5 KB
/
server-form.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
package main
import (
"bufio"
"fmt"
"strconv"
"strings"
"github.com/therecipe/qt/widgets"
)
func showServerForm(app *widgets.QApplication, window *widgets.QMainWindow) *widgets.QFormLayout {
config := ConfigParser()
formLayout := widgets.NewQFormLayout(nil)
formLayout.SetFieldGrowthPolicy(widgets.QFormLayout__ExpandingFieldsGrow)
label := widgets.NewQLabel2("Create New Server or Client Certificate", nil, 0)
formLayout.AddWidget(label)
selector := widgets.NewQComboBox(nil)
selector.AddItems(getCas())
formLayout.AddRow3("Select Certificate Authority: ", selector)
C := widgets.NewQLineEdit(nil)
C.SetPlaceholderText("US")
formLayout.AddRow3("Country (two letter): ", C)
S := widgets.NewQLineEdit(nil)
S.SetPlaceholderText("CA")
formLayout.AddRow3("Province/State (two letter): ", S)
L := widgets.NewQLineEdit(nil)
L.SetPlaceholderText("Los Angeles")
formLayout.AddRow3("Locality: ", L)
O := widgets.NewQLineEdit(nil)
O.SetPlaceholderText("Widgets INTL")
formLayout.AddRow3("Organization: ", O)
OU := widgets.NewQLineEdit(nil)
OU.SetPlaceholderText("Widgets Web Services")
formLayout.AddRow3("Organizational Unit: ", OU)
// CN := widgets.NewQLineEdit(nil)
// CN.SetPlaceholderText("Widgets International")
// formLayout.AddRow3("Common Name: ", CN)
CName := widgets.NewQLineEdit(nil)
CName.SetPlaceholderText("root.wigets.com")
formLayout.AddRow3("Certificate Name: ", CName)
age := widgets.NewQComboBox(nil)
age.AddItems([]string{"2", "1"})
formLayout.AddRow3("Age (years): ", age)
domains := widgets.NewQTextEdit(nil)
domains.SetMaximumHeight(100)
formLayout.AddRow3("Domains: ", domains)
ips := widgets.NewQTextEdit(nil)
ips.SetMaximumHeight(100)
formLayout.AddRow3("IPs: ", ips)
optionGroup := widgets.NewQHBoxLayout()
//add button
addButton := widgets.NewQPushButton(nil)
addButton.SetText("Add")
optionGroup.AddWidget(addButton, 0, 0)
//cancel button
cancelButton := widgets.NewQPushButton(nil)
cancelButton.SetText("Cancel")
optionGroup.AddWidget(cancelButton, 0, 0)
formLayout.InsertRow6(11, optionGroup)
cancelButton.ConnectClicked(func(checked bool) {
window.Close()
GlobalForm = ""
mkgui(app, window)
})
addButton.ConnectClicked(func(checked bool) {
//check if file exists
caKey := config.RootDIR + "/" + selector.CurrentText() + "-key.pem"
caCert := config.RootDIR + "/" + selector.CurrentText() + ".pem"
issuer, err := getIssuer(caKey, caCert)
if err != nil {
fmt.Println(err)
}
c := []string{}
c = append(c, C.Text())
s := []string{}
s = append(s, S.Text())
l := []string{}
l = append(l, L.Text())
o := []string{}
o = append(o, O.Text())
ou := []string{}
ou = append(ou, OU.Text())
i, _ := strconv.Atoi(age.CurrentText())
domainSlice := []string{}
scanner := bufio.NewScanner(strings.NewReader(domains.ToPlainText()))
for scanner.Scan() {
domainSlice = append(domainSlice, scanner.Text())
}
ipSlice := []string{}
scanner2 := bufio.NewScanner(strings.NewReader(ips.ToPlainText()))
for scanner.Scan() {
ipSlice = append(ipSlice, scanner2.Text())
}
//sign(iss *issuer, cn string, y int, domains, ipAddresses []string)
_, err = sign(issuer, CName.Text(), i, domainSlice, ipSlice, c, s, l, o, ou, config)
// _, err = makeRootCert(key, caCert, CN.Text(), c, s, l, o, ou, i)
if err != nil {
fmt.Println("Error creating Cert", err)
} else {
GlobalForm = ""
window.Close()
vlayout2 := mkgui(app, window)
vlayout2.AddLayout(listCerts(app, window), 0)
GlobalForm = "LC"
}
// }
})
return formLayout
}