-
Notifications
You must be signed in to change notification settings - Fork 14
/
cert.go
148 lines (129 loc) · 4.31 KB
/
cert.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
147
148
package main
import (
"crypto/x509"
"github.com/jpki/myna/libmyna"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/widgets"
)
type SelectCertDialog struct {
*widgets.QDialog
}
func NewSelectCertDialog() *SelectCertDialog {
windowFlag := core.Qt__Window | core.Qt__WindowCloseButtonHint
dialog := widgets.NewQDialog(nil, windowFlag)
dialog.SetModal(true)
dialog.SetMinimumSize2(300, 300)
dialog.SetWindowTitle("証明書選択")
radio1 := widgets.NewQRadioButton2("認証用証明書", nil)
radio2 := widgets.NewQRadioButton2("署名用証明書", nil)
radio3 := widgets.NewQRadioButton2("認証用CA証明書", nil)
radio4 := widgets.NewQRadioButton2("署名用CA証明書", nil)
radio1.SetChecked(true)
layout := widgets.NewQVBoxLayout()
layout.AddWidget(radio1, 0, 0)
layout.AddWidget(radio2, 0, 0)
layout.AddWidget(radio3, 0, 0)
layout.AddWidget(radio4, 0, 0)
group := widgets.NewQButtonGroup(nil)
group.AddButton(radio1, 1)
group.AddButton(radio2, 2)
group.AddButton(radio3, 3)
group.AddButton(radio4, 4)
buttons := widgets.NewQDialogButtonBox(nil)
closeButton := widgets.NewQPushButton2("閉じる", nil)
closeButton.ConnectClicked(func(bool) { dialog.Close() })
showButton := widgets.NewQPushButton2("表示", nil)
showButton.ConnectClicked(func(bool) {
id := group.CheckedId()
var name string
var ef string
var password string
if id == 1 {
name = "認証用証明書"
ef = "00 0A"
} else if id == 2 {
name = "署名用証明書"
ef = "00 01"
prompt := NewPasswordPromptDialog()
rc := prompt.Exec()
if rc != int(widgets.QDialog__Accepted) {
return
}
password = prompt.GetPin()
} else if id == 3 {
name = "認証用CA証明書"
ef = "00 0B"
} else if id == 4 {
name = "署名用CA証明書"
ef = "00 02"
} else {
return
}
cert, err := libmyna.GetCert(ctx, ef, password)
if err != nil {
widgets.QMessageBox_Warning(nil, "エラー", err.Error(),
widgets.QMessageBox__Ok, 0)
return
}
certDialog := NewShowCertDialog(name, cert)
certDialog.Show()
})
buttons.AddButton(closeButton, widgets.QDialogButtonBox__RejectRole)
buttons.AddButton(showButton, widgets.QDialogButtonBox__AcceptRole)
layout.AddWidget(buttons, 0, 0)
dialog.SetLayout(layout)
return &SelectCertDialog{dialog}
}
type ShowCertDialog struct {
*widgets.QDialog
}
func NewShowCertDialog(name string, cert *x509.Certificate) *ShowCertDialog {
if cert == nil {
widgets.QMessageBox_Warning(nil, "エラー", "証明書がみつかりません",
widgets.QMessageBox__Ok, 0)
return nil
/*
data, _ := ioutil.ReadFile("../test.pem")
block, _ := pem.Decode(data)
cert, _ = x509.ParseCertificate(block.Bytes)
*/
}
windowFlag := core.Qt__Window | core.Qt__WindowCloseButtonHint
dialog := widgets.NewQDialog(nil, windowFlag)
dialog.SetModal(true)
dialog.SetWindowTitle("証明書ビューア: " + name)
dialog.SetMinimumSize2(600, 400)
layout := widgets.NewQVBoxLayout()
labelSubject := widgets.NewQLabel2("発行先", nil, 0)
layout.AddWidget(labelSubject, 0, 0)
textSubject := widgets.NewQLineEdit(dialog)
textSubject.SetReadOnly(true)
textSubject.SetText(libmyna.Name2String(cert.Subject))
textSubject.AdjustSize()
layout.AddWidget(textSubject, 0, 0)
labelIssuer := widgets.NewQLabel2("発行元", nil, 0)
layout.AddWidget(labelIssuer, 0, 0)
textIssuer := widgets.NewQLineEdit(nil)
textIssuer.SetReadOnly(true)
textIssuer.SetText(libmyna.Name2String(cert.Issuer))
layout.AddWidget(textIssuer, 0, 0)
labelNotBefore := widgets.NewQLabel2("発行日", nil, 0)
layout.AddWidget(labelNotBefore, 0, 0)
textNotBefore := widgets.NewQLineEdit(nil)
textNotBefore.SetReadOnly(true)
textNotBefore.SetText(cert.NotBefore.Local().String())
layout.AddWidget(textNotBefore, 0, 0)
labelNotAfter := widgets.NewQLabel2("有効期限", nil, 0)
layout.AddWidget(labelNotAfter, 0, 0)
textNotAfter := widgets.NewQLineEdit(nil)
textNotAfter.SetReadOnly(true)
textNotAfter.SetText(cert.NotAfter.Local().String())
layout.AddWidget(textNotAfter, 0, 0)
buttons := widgets.NewQDialogButtonBox(nil)
closeButton := widgets.NewQPushButton2("閉じる", nil)
closeButton.ConnectClicked(func(bool) { dialog.Close() })
buttons.AddButton(closeButton, widgets.QDialogButtonBox__RejectRole)
layout.AddWidget(buttons, 0, 0)
dialog.SetLayout(layout)
return &ShowCertDialog{dialog}
}