● Notice //GitHub (@shehzade) is temporarily suspended pending an automated false-positive review. All tools are hosted on this Code Mirror and available on request (contact); GitHub links will return once reinstated.
PUBLIC MIRRORGo v1.0

Multi-protocol network egress assessment and DLP verification framework featuring automated L4 sweeps, corporate proxy traversal, and covert protocol smuggling across 20+ channels.

$ git clone https://shehzade.io/repos/contraband.git Copy
Source ZIP (1.93 MB)
Code 174 Commits 1
contraband / pkg / server / certgen / tls.go
← Back to directory
64 lines · 1.8 KB
Raw
1package certgen
2
3import (
4 "crypto/tls"
5 "fmt"
6 "time"
7)
8
9// GenerateTLSCert generates an ephemeral in-memory TLS certificate. If a CA is provided,
10// it signs the certificate using the CA; otherwise, it creates an ephemeral Root CA and signs the leaf.
11func GenerateTLSCert(hosts []string, ca *CertificateAuthority) (*tls.Certificate, error) {
12 if ca == nil {
13 var err error
14 ca, err = NewCA("Contraband Ephemeral CA")
15 if err != nil {
16 return nil, fmt.Errorf("failed to generate ephemeral CA: %w", err)
17 }
18 }
19
20 certPEM, keyPEM, err := ca.SignServerCert(hosts, 30*24*time.Hour)
21 if err != nil {
22 return nil, err
23 }
24
25 cert, err := tls.X509KeyPair(certPEM, keyPEM)
26 if err != nil {
27 return nil, fmt.Errorf("failed to load x509 key pair: %w", err)
28 }
29 return &cert, nil
30}
31
32// NewServerTLSConfig creates a hardened TLS server configuration pre-loaded with an ephemeral cert.
33func NewServerTLSConfig(hosts []string, ca *CertificateAuthority) (*tls.Config, error) {
34 cert, err := GenerateTLSCert(hosts, ca)
35 if err != nil {
36 return nil, err
37 }
38
39 return &tls.Config{
40 Certificates: []tls.Certificate{*cert},
41 MinVersion: tls.VersionTLS12,
42 NextProtos: []string{"h2", "http/1.1"},
43 CipherSuites: []uint16{
44 tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
45 tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
46 tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
47 tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
48 tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
49 tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
50 },
51 }, nil
52}
53
54// NewClientTLSConfig creates a TLS client configuration trusting the provided CA CertPool.
55func NewClientTLSConfig(ca *CertificateAuthority, serverName string) *tls.Config {
56 cfg := &tls.Config{
57 MinVersion: tls.VersionTLS12,
58 ServerName: serverName,
59 }
60 if ca != nil {
61 cfg.RootCAs = ca.CertPool()
62 }
63 return cfg
64}