diff options
| author | historia <[not public]> | 2026-10-05 19:20:17 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-05 19:20:17 -0400 |
| commit | 1091d0fae96d152c11aec1bb2dd949f51ed5aa1e (patch) | |
| tree | 0d867d42726cd3910c9851ec69e15b9a4b031001 /internal/net/server.go | |
| parent | 9d8c43cd68c960b9a6b8f781684f763e204a4498 (diff) | |
| download | thehouseoficarus-1091d0fae96d152c11aec1bb2dd949f51ed5aa1e.tar.gz | |
feat: shared tls cert, validation fixes
Diffstat (limited to 'internal/net/server.go')
| -rw-r--r-- | internal/net/server.go | 38 |
1 files changed, 2 insertions, 36 deletions
diff --git a/internal/net/server.go b/internal/net/server.go index 8e23a1f..0854426 100644 --- a/internal/net/server.go +++ b/internal/net/server.go @@ -2,14 +2,9 @@ package net import ( "context" - "crypto/rand" - "crypto/rsa" "crypto/tls" - "crypto/x509" - "crypto/x509/pkix" "fmt" "log" - "math/big" "net" "net/http" "sort" @@ -20,6 +15,7 @@ import ( "thehouseoficarus/internal/color" "thehouseoficarus/internal/config" "thehouseoficarus/internal/player" + "thehouseoficarus/internal/tlscert" ) type SessionState int @@ -691,37 +687,7 @@ func loadOrGenerateCert(cfg *config.Config, service string) (tls.Certificate, er } func generateSelfSignedCert() (tls.Certificate, error) { - key, err := rsa.GenerateKey(rand.Reader, 2048) - if err != nil { - return tls.Certificate{}, fmt.Errorf("rsa key generation: %w", err) - } - serial, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128)) - if err != nil { - return tls.Certificate{}, fmt.Errorf("serial number: %w", err) - } - now := time.Now() - template := &x509.Certificate{ - SerialNumber: serial, - Subject: pkix.Name{ - CommonName: "THOI Self-Signed Certificate", - }, - NotBefore: now.Add(-1 * time.Hour), - NotAfter: now.Add(365 * 24 * time.Hour), - KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, - BasicConstraintsValid: true, - IsCA: true, - DNSNames: []string{"localhost"}, - IPAddresses: []net.IP{net.ParseIP("127.0.0.1"), net.ParseIP("::1")}, - } - certDER, err := x509.CreateCertificate(rand.Reader, template, template, &key.PublicKey, key) - if err != nil { - return tls.Certificate{}, fmt.Errorf("x509 creation: %w", err) - } - return tls.Certificate{ - Certificate: [][]byte{certDER}, - PrivateKey: key, - }, nil + return tlscert.SelfSigned("THOI Self-Signed Certificate") } func (s *Server) Hub() *Hub { |
