Create bogus certificate if none passed

This commit is contained in:
DataHoarder 2022-01-16 15:25:17 +01:00
parent 66f705879a
commit 5f9a8a9f4f
2 changed files with 25 additions and 7 deletions

View file

@ -378,7 +378,6 @@ func handle(w http.ResponseWriter, r *http.Request) {
setCORSHeaders(w)
pathElements := strings.Split(r.URL.Path, "/")
if len(pathElements) < 3 {
log.Printf("1")
w.WriteHeader(http.StatusBadRequest)
return
}
@ -452,8 +451,8 @@ func checkContentServers() {
func main() {
//TODO: OCSP
certificatePath := flag.String("certificate", "ssl.crt", "Path to SSL certificate file.")
keypairPath := flag.String("keypair", "ssl.key", "Path to SSL key file.")
certificatePath := flag.String("certificate", "", "Path to SSL certificate file.")
keypairPath := flag.String("keypair", "", "Path to SSL key file.")
listenAddress := flag.String("listen", ":7777", "Address/port to lisent on.")
@ -523,9 +522,16 @@ func main() {
if err != nil {
log.Fatal(err)
}
serverCertificate, err := tls.LoadX509KeyPair(*certificatePath, *keypairPath)
if err != nil {
log.Fatal(err)
var serverCertificate tls.Certificate
if *certificatePath != "" && *keypairPath != "" {
serverCertificate, err = tls.LoadX509KeyPair(*certificatePath, *keypairPath)
if err != nil {
log.Fatal(err)
}
} else {
serverCertificate = bogusCertificate
}
server := &http.Server{

View file

@ -7,4 +7,16 @@ Content-addressable storage redirector.
`$ go run .`
Build via `$ go build -o fcmm`
Build via `$ go build -o fcmm`
### Certbot notes
* Use pip certbot
* Edit .env to add paths to certificates
```
$ certbot certonly \
--standalone \
--key-type=ecdsa --elliptic-curve=secp256r1 \
--domain <domain> \
--post-hook "docker restart <docker name>"
```