Skip to content

Commit 6e1d110

Browse files
committed
add CA fields to self signed certificate
1 parent 1dd1fed commit 6e1d110

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

certificates.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,16 @@ func generateCertificates() {
106106
template := x509.Certificate{
107107
SerialNumber: serialNumber,
108108
Subject: pkix.Name{
109-
Organization: []string{"Arduino LLC US"},
109+
Organization: []string{"Arduino LLC US"},
110+
Country: []string{"US"},
111+
CommonName: "localhost",
112+
OrganizationalUnit: []string{"IT"},
110113
},
111114
NotBefore: notBefore,
112115
NotAfter: notAfter,
113116

114117
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
115-
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
118+
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
116119
BasicConstraintsValid: true,
117120
}
118121

@@ -135,6 +138,11 @@ func generateCertificates() {
135138
log.Fatalf("Failed to create certificate: %s", err)
136139
}
137140

141+
// remove old certificates
142+
os.Remove("cert.pem")
143+
os.Remove("key.pem")
144+
os.Remove("cert.cer")
145+
138146
certOut, err := os.Create("cert.pem")
139147
if err != nil {
140148
log.Fatalf("failed to open cert.pem for writing: %s", err)

main.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ package main
55

66
import (
77
"flag"
8+
log "github.com/Sirupsen/logrus"
9+
"github.com/carlescere/scheduler"
10+
"github.com/gin-gonic/gin"
11+
"github.com/itsjamie/gin-cors"
12+
"github.com/kardianos/osext"
13+
"github.com/vharitonsky/iniflags"
814
"os"
915
"os/user"
1016
"path/filepath"
1117
"runtime/debug"
1218
"strconv"
1319
"text/template"
1420
"time"
15-
16-
log "github.com/Sirupsen/logrus"
17-
"github.com/carlescere/scheduler"
18-
"github.com/gin-gonic/gin"
19-
"github.com/itsjamie/gin-cors"
20-
"github.com/kardianos/osext"
21-
"github.com/vharitonsky/iniflags"
2221
//"github.com/sanbornm/go-selfupdate/selfupdate" #included in update.go to change heavily
2322
)
2423

@@ -75,6 +74,11 @@ func launchSelfLater() {
7574
log.Println("Done waiting 2 secs. Now launching...")
7675
}
7776

77+
func certHandler(c *gin.Context) {
78+
c.Header("content-type", "application/x-x509-ca-cert")
79+
c.File("cert.cer")
80+
}
81+
7882
func main() {
7983

8084
flag.Parse()
@@ -232,6 +236,7 @@ func main() {
232236
}))
233237

234238
r.GET("/", homeHandler)
239+
r.GET("/certificate.crt", certHandler)
235240
r.POST("/upload", uploadHandler)
236241
r.GET("/socket.io/", socketHandler)
237242
r.POST("/socket.io/", socketHandler)
@@ -393,7 +398,9 @@ body {
393398
<form id="form">
394399
<input type="submit" value="Send" />
395400
<input type="text" id="msg" size="64"/>
396-
<input name="pause" type="checkbox" value="pause" id="myCheck"/> Pause <br>
401+
<input name="pause" type="checkbox" value="pause" id="myCheck"/> Pause
402+
<input type="button" value="Install Certificate" onclick="window.open('http://localhost:8991/certificate.crt')" />
403+
</form>
397404
</form>
398405
</body>
399406
</html>

0 commit comments

Comments
 (0)