1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 16:45:58 +01:00

Fail the connection if only one of cert.pem and key.pem exists.

This commit is contained in:
Juliusz Chroboczek 2021-02-24 22:23:38 +01:00
parent b1babf5b77
commit c19b356e54

View file

@ -5,6 +5,7 @@ import (
"crypto/rsa" "crypto/rsa"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"errors"
"log" "log"
"math/big" "math/big"
"os" "os"
@ -73,7 +74,11 @@ func getCertificate(dataDir string) (*tls.Certificate, error) {
if !ok || !info.certTime.Equal(certTime) || !info.keyTime.Equal(keyTime) { if !ok || !info.certTime.Equal(certTime) || !info.keyTime.Equal(keyTime) {
var cert tls.Certificate var cert tls.Certificate
if certTime.Equal(time.Time{}) || keyTime.Equal(time.Time{}) { nocert := certTime.Equal(time.Time{})
nokey := keyTime.Equal(time.Time{})
if nocert != nokey {
return nil, errors.New("only one of cert.pem and key.pem exists")
} else if nokey {
log.Printf("Generating self-signed certificate") log.Printf("Generating self-signed certificate")
var err error var err error
cert, err = generateCertificate(dataDir) cert, err = generateCertificate(dataDir)