Remove WriteX509KeyPair function
This commit is contained in:
parent
3d1e9e5519
commit
292fa7ee4f
26
cert.go
26
cert.go
@ -9,7 +9,6 @@ import (
|
|||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -152,28 +151,3 @@ func NewRawCertificate(host string, duration time.Duration) (crt, key []byte, er
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteX509KeyPair writes the provided certificate and private key
|
|
||||||
// to path.crt and path.key respectively.
|
|
||||||
func WriteX509KeyPair(path string, crt, key []byte) error {
|
|
||||||
// Write the certificate
|
|
||||||
crtPath := path + ".crt"
|
|
||||||
crtOut, err := os.OpenFile(crtPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := crtOut.Write(crt); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the private key
|
|
||||||
keyPath := path + ".key"
|
|
||||||
keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := keyOut.Write(key); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -4,6 +4,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.sr.ht/~adnano/gmi"
|
"git.sr.ht/~adnano/gmi"
|
||||||
@ -11,14 +12,38 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
host := "localhost"
|
host := "localhost"
|
||||||
|
duration := 365 * 24 * time.Hour
|
||||||
duration := 2 * time.Minute
|
|
||||||
crt, key, err := gmi.NewRawCertificate(host, duration)
|
crt, key, err := gmi.NewRawCertificate(host, duration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gmi.WriteX509KeyPair(host, crt, key); err != nil {
|
if err := writeX509KeyPair(host, crt, key); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// writeX509KeyPair writes the provided certificate and private key
|
||||||
|
// to path.crt and path.key respectively.
|
||||||
|
func writeX509KeyPair(path string, crt, key []byte) error {
|
||||||
|
// Write the certificate
|
||||||
|
crtPath := path + ".crt"
|
||||||
|
crtOut, err := os.OpenFile(crtPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := crtOut.Write(crt); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the private key
|
||||||
|
keyPath := path + ".key"
|
||||||
|
keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := keyOut.Write(key); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -28,7 +28,7 @@ func main() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Store and return the new certificate
|
// Store and return the new certificate
|
||||||
err = gmi.WriteX509KeyPair("/var/lib/gemini/certs/"+hostname, crt, key)
|
err = writeX509KeyPair("/var/lib/gemini/certs/"+hostname, crt, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -51,3 +51,28 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// writeX509KeyPair writes the provided certificate and private key
|
||||||
|
// to path.crt and path.key respectively.
|
||||||
|
func writeX509KeyPair(path string, crt, key []byte) error {
|
||||||
|
// Write the certificate
|
||||||
|
crtPath := path + ".crt"
|
||||||
|
crtOut, err := os.OpenFile(crtPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := crtOut.Write(crt); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the private key
|
||||||
|
keyPath := path + ".key"
|
||||||
|
keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := keyOut.Write(key); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user