diff --git a/certificates.go b/certificates.go index 23354972e..bfa4d11ac 100644 --- a/certificates.go +++ b/certificates.go @@ -21,9 +21,11 @@ import ( "net" "os" "strings" + "text/template" "time" log "github.com/Sirupsen/logrus" + "github.com/gin-gonic/gin" ) var ( @@ -215,3 +217,116 @@ func generateCertificates() { log.Print("written cert.cer") } + +func certHandler(c *gin.Context) { + if strings.Contains(c.Request.UserAgent(), "Firefox") { + c.Header("content-type", "application/x-x509-ca-cert") + c.File("ca.cert.cer") + return + } + noFirefoxTemplate.Execute(c.Writer, gin.H{ + "url": "http://" + c.Request.Host + c.Request.URL.String(), + }) +} + +const noFirefoxTemplateHTML = ` + +
+ + + + +You need to open this link in Firefox to trust this certificate: {{.host}}{{.url}}
+