mirror of
https://git.sr.ht/~adnano/go-gemini
synced 2024-11-23 08:32:02 +01:00
8811080005
This reverts commit f3481c3ff8815475a693c718e7de8dc7b90634b8.
44 lines
779 B
Go
44 lines
779 B
Go
// +build ignore
|
|
|
|
// This example illustrates a certificate generation tool.
|
|
|
|
package main
|
|
|
|
import (
|
|
"crypto/x509/pkix"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"time"
|
|
|
|
"git.sr.ht/~adnano/go-gemini/certificate"
|
|
)
|
|
|
|
func main() {
|
|
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)
|
|
}
|
|
options := certificate.CreateOptions{
|
|
Subject: pkix.Name{
|
|
CommonName: host,
|
|
},
|
|
DNSNames: []string{host},
|
|
Duration: duration,
|
|
}
|
|
cert, err := certificate.Create(options)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
certPath := host + ".crt"
|
|
keyPath := host + ".key"
|
|
if err := certificate.Write(cert, certPath, keyPath); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|