client: pin the server certificate by SHA-256, not by file

-server-cert-sha256 <hex> replaces -server-cert <file>: the connection is
accepted only if the SHA-256 of the server's certificate (DER) matches,
colons optional, case-insensitive. No certificate or key file to handle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Git Sagar 2026-10-28 15:36:01 -03:00
parent bb92a9b954
commit 94716ac989
4 changed files with 26 additions and 28 deletions

View file

@ -40,7 +40,7 @@ type Config struct {
Password string // Password (hashed or sent plain depending on PlainPassword)
PlainPassword bool // If true, send password as plaintext (AuthType 2)
InsecureSkipVerify bool // Skip TLS certificate verification
ServerCert []byte // Pinned server certificate (DER); nil = CA and hostname verification
ServerCertSHA256 []byte // Pinned SHA-256 of the server certificate (DER); nil = CA and hostname verification
}
// Session represents an established SoftEther VPN session.
@ -61,7 +61,7 @@ func Connect(cfg Config) (*Session, error) {
}
// Step 1: TLS connection
conn, err := protocol.DialTLS(cfg.Host, cfg.Port, cfg.InsecureSkipVerify, cfg.ServerCert)
conn, err := protocol.DialTLS(cfg.Host, cfg.Port, cfg.InsecureSkipVerify, cfg.ServerCertSHA256)
if err != nil {
return nil, fmt.Errorf("connect: %w", err)
}