1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 18:25: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/tls"
"crypto/x509"
"errors"
"log"
"math/big"
"os"
@ -73,7 +74,11 @@ func getCertificate(dataDir string) (*tls.Certificate, error) {
if !ok || !info.certTime.Equal(certTime) || !info.keyTime.Equal(keyTime) {
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")
var err error
cert, err = generateCertificate(dataDir)