1
0
Fork 0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-06-02 06:26:06 +02:00
go-gemini/examples/cert.go

44 lines
779 B
Go
Raw Normal View History

2020-10-12 22:34:52 +02:00
// +build ignore
2020-09-27 19:50:48 +02:00
2020-12-18 06:47:30 +01:00
// This example illustrates a certificate generation tool.
2020-09-27 19:50:48 +02:00
package main
import (
"crypto/x509/pkix"
2020-10-28 18:47:52 +01:00
"fmt"
2020-09-27 19:50:48 +02:00
"log"
2020-10-13 22:50:59 +02:00
"os"
2020-09-28 05:49:41 +02:00
"time"
2020-09-27 19:50:48 +02:00
2021-01-15 03:23:13 +01:00
"git.sr.ht/~adnano/go-gemini/certificate"
2020-09-27 19:50:48 +02:00
)
func main() {
2020-10-28 18:47:52 +01:00
if len(os.Args) < 3 {
fmt.Printf("usage: %s [hostname] [duration]\n", os.Args[0])
os.Exit(1)
}
host := os.Args[1]
duration, err := time.ParseDuration(os.Args[2])
if err != nil {
log.Fatal(err)
}
2021-01-15 03:23:13 +01:00
options := certificate.CreateOptions{
Subject: pkix.Name{
CommonName: host,
},
2020-10-28 18:47:52 +01:00
DNSNames: []string{host},
Duration: duration,
}
2021-01-15 03:23:13 +01:00
cert, err := certificate.Create(options)
2020-09-27 19:50:48 +02:00
if err != nil {
log.Fatal(err)
}
2020-11-01 20:19:18 +01:00
certPath := host + ".crt"
keyPath := host + ".key"
2021-01-15 03:23:13 +01:00
if err := certificate.Write(cert, certPath, keyPath); err != nil {
2020-09-27 19:50:48 +02:00
log.Fatal(err)
}
}