Add Subject option in CertificateOptions

This commit is contained in:
Adnan Maolood 2020-11-02 23:11:46 -05:00
parent 5b3194695f
commit 01670647d2
3 changed files with 11 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"crypto/rand" "crypto/rand"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"crypto/x509/pkix"
"encoding/pem" "encoding/pem"
"log" "log"
"math/big" "math/big"
@ -91,6 +92,7 @@ func (c *CertificateStore) Load(path string) error {
type CertificateOptions struct { type CertificateOptions struct {
IPAddresses []net.IP IPAddresses []net.IP
DNSNames []string DNSNames []string
Subject pkix.Name
Duration time.Duration Duration time.Duration
} }
@ -138,6 +140,7 @@ func newX509KeyPair(options CertificateOptions) (*x509.Certificate, crypto.Priva
BasicConstraintsValid: true, BasicConstraintsValid: true,
IPAddresses: options.IPAddresses, IPAddresses: options.IPAddresses,
DNSNames: options.DNSNames, DNSNames: options.DNSNames,
Subject: options.Subject,
} }
crt, err := x509.CreateCertificate(rand.Reader, &template, &template, public, priv) crt, err := x509.CreateCertificate(rand.Reader, &template, &template, public, priv)

View File

@ -5,6 +5,7 @@ package main
import ( import (
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"crypto/x509/pkix"
"fmt" "fmt"
"log" "log"
"time" "time"
@ -48,6 +49,9 @@ func main() {
} }
server.CreateCertificate = func(hostname string) (tls.Certificate, error) { server.CreateCertificate = func(hostname string) (tls.Certificate, error) {
return gemini.CreateCertificate(gemini.CertificateOptions{ return gemini.CreateCertificate(gemini.CertificateOptions{
Subject: pkix.Name{
CommonName: hostname,
},
DNSNames: []string{hostname}, DNSNames: []string{hostname},
Duration: time.Hour, Duration: time.Hour,
}) })

View File

@ -4,6 +4,7 @@ package main
import ( import (
"crypto/tls" "crypto/tls"
"crypto/x509/pkix"
"log" "log"
"time" "time"
@ -19,6 +20,9 @@ func main() {
} }
server.CreateCertificate = func(hostname string) (tls.Certificate, error) { server.CreateCertificate = func(hostname string) (tls.Certificate, error) {
return gemini.CreateCertificate(gemini.CertificateOptions{ return gemini.CreateCertificate(gemini.CertificateOptions{
Subject: pkix.Name{
CommonName: hostname,
},
DNSNames: []string{hostname}, DNSNames: []string{hostname},
Duration: time.Minute, // for testing purposes Duration: time.Minute, // for testing purposes
}) })