-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
82 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
FROM golang:1.23 | ||
|
||
WORKDIR /app | ||
|
||
# Copy all files | ||
COPY . ./ | ||
|
||
RUN go build -o server http-server.go | ||
ENV GO111MODULE=off | ||
|
||
# Build the server | ||
ARG BUILD_TARGET | ||
RUN go build -o $BUILD_TARGET http-server.go | ||
|
||
# Expose port 443 | ||
EXPOSE 443 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
FROM mcr.microsoft.com/windows/servercore:ltsc2022 | ||
FROM golang:1.23 | ||
|
||
COPY start-server.ps1 C:/app/start-server.ps1 | ||
COPY ca.* C:/app/ | ||
WORKDIR /app | ||
|
||
# Copy all files | ||
COPY . ./ | ||
|
||
ENV GO111MODULE=off | ||
|
||
# Build the server | ||
RUN go build -o http-server.exe http-server.go | ||
|
||
# Expose port 443 | ||
EXPOSE 443 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func main() { | ||
// Get the allowed cipher from command-line argument | ||
if len(os.Args) < 2 { | ||
log.Fatal("Usage: server <TLS_CIPHER>") | ||
} | ||
tlsCipher := os.Args[1] | ||
|
||
// Define allowed ciphers for TLS 1.2 | ||
cipherMap := map[string]uint16{ | ||
"ECDHE-RSA-CHACHA20-POLY1305": tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, | ||
"ECDHE-RSA-AES128-SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, | ||
} | ||
|
||
cipher, exists := cipherMap[tlsCipher] | ||
if !exists { | ||
log.Fatalf("Unsupported cipher: %s", tlsCipher) | ||
} | ||
|
||
// TLS Configuration | ||
tlsConfig := &tls.Config{ | ||
MinVersion: tls.VersionTLS12, | ||
MaxVersion: tls.VersionTLS12, // Force TLS 1.2 only | ||
CipherSuites: []uint16{cipher}, // Restrict to a single cipher | ||
PreferServerCipherSuites: true, | ||
|
||
} | ||
|
||
// Define a simple HTTP handler | ||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
w.Write([]byte("<html><body><h1>Secure Server</h1></body></html>")) | ||
}) | ||
|
||
// Create HTTPS server | ||
server := &http.Server{ | ||
Addr: ":443", | ||
Handler: handler, | ||
TLSConfig: tlsConfig, | ||
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)), | ||
} | ||
|
||
fmt.Printf("Serving on https://localhost:8443 using cipher %s with TLSv1.2 enforced\n", tlsCipher) | ||
log.Fatal(server.ListenAndServeTLS("./ca.crt", "./ca.key")) | ||
} |
This file was deleted.
Oops, something went wrong.