[PD1] Added certificates and fixed a few things

This commit is contained in:
Afonso Franco 2024-04-18 20:15:29 +01:00
parent b7023329de
commit 1cb81d2279
Signed by: afonso
SSH key fingerprint: SHA256:aiLbdlPwXKJS5wMnghdtod0SPy8imZjlVvCyUX9DJNk
28 changed files with 596 additions and 54 deletions

View file

@ -8,7 +8,7 @@ import (
)
type ServerTLSConfigProvider interface {
GetTLSConfigServer() *tls.Config
GetTLSConfig() *tls.Config
}
type Server[T any] struct {
@ -18,7 +18,7 @@ type Server[T any] struct {
func NewServer[T any](serverTLSConfigProvider ServerTLSConfigProvider, port int) Server[T] {
listener, err := tls.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port), serverTLSConfigProvider.GetTLSConfigServer())
listener, err := tls.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port), serverTLSConfigProvider.GetTLSConfig())
if err != nil {
panic("Server could not bind to address")
}
@ -39,9 +39,11 @@ func (s *Server[T]) ListenLoop() {
if !ok {
panic("Connection is not a TLS connection")
}
fmt.Println(tlsConn)
state := tlsConn.ConnectionState()
if len(state.PeerCertificates) == 0 {
fmt.Println(state.PeerCertificates)
log.Panicln("Client did not provide a certificate")
}
conn := NewConnection[T](tlsConn)