Skip to content

Commit 1172225

Browse files
committed
Add tls_prefer_rsa as promised a while back
1 parent f9f1944 commit 1172225

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

dnscrypt-proxy/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type Config struct {
9292
LogMaxBackups int `toml:"log_files_max_backups"`
9393
TLSDisableSessionTickets bool `toml:"tls_disable_session_tickets"`
9494
TLSCipherSuite []uint16 `toml:"tls_cipher_suite"`
95+
TLSPreferRSA bool `toml:"tls_prefer_rsa"`
9596
TLSKeyLogFile string `toml:"tls_key_log_file"`
9697
NetprobeAddress string `toml:"netprobe_address"`
9798
NetprobeTimeout int `toml:"netprobe_timeout"`
@@ -156,6 +157,7 @@ func newConfig() Config {
156157
LogMaxBackups: 1,
157158
TLSDisableSessionTickets: false,
158159
TLSCipherSuite: nil,
160+
TLSPreferRSA: false,
159161
TLSKeyLogFile: "",
160162
NetprobeTimeout: 60,
161163
OfflineMode: false,

dnscrypt-proxy/config_loader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func configureLogging(proxy *Proxy, flags *ConfigFlags, config *Config) {
6565
// configureXTransport - Configures the XTransport
6666
func configureXTransport(proxy *Proxy, config *Config) error {
6767
proxy.xTransport.tlsDisableSessionTickets = config.TLSDisableSessionTickets
68+
proxy.xTransport.tlsPreferRSA = config.TLSPreferRSA
6869
proxy.xTransport.http3 = config.HTTP3
6970
proxy.xTransport.http3Probe = config.HTTP3Probe
7071

dnscrypt-proxy/example-dnscrypt-proxy.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,15 @@ cert_refresh_delay = 240
287287
# tls_disable_session_tickets = false
288288

289289

290+
## Prefer RSA certificates over ECDSA for TLS connections.
291+
## When this is enabled, some servers may become impossible to use,
292+
## or may stop to work later as they upgrade their configuratione.
293+
## Changing this setting is generally not recommended, but it may
294+
## reduce CPU usage on small routers with slow CPUs.
295+
296+
# tls_prefer_rsa = false
297+
298+
290299
## Log TLS key material to a file, for debugging purposes only.
291300
## This file will contain the TLS master key, which can be used to decrypt
292301
## all TLS traffic to/from DoH servers.

dnscrypt-proxy/xtransport.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ import (
2828
"github.com/quic-go/quic-go/http3"
2929
"golang.org/x/net/http2"
3030
netproxy "golang.org/x/net/proxy"
31+
"golang.org/x/sys/cpu"
3132
)
3233

34+
var hasAESGCMHardwareSupport = cpu.X86.HasAES && cpu.X86.HasPCLMULQDQ ||
35+
cpu.ARM64.HasAES && cpu.ARM64.HasPMULL ||
36+
cpu.S390X.HasAES && cpu.S390X.HasAESGCM
37+
3338
const (
3439
DefaultBootstrapResolver = "9.9.9.9:53"
3540
DefaultKeepAlive = 5 * time.Second
@@ -77,6 +82,7 @@ type XTransport struct {
7782
http3 bool
7883
http3Probe bool
7984
tlsDisableSessionTickets bool
85+
tlsPreferRSA bool
8086
proxyDialer *netproxy.Dialer
8187
httpProxyFunction func(*http.Request) (*url.URL, error)
8288
tlsClientCreds DOHClientCreds
@@ -99,6 +105,7 @@ func NewXTransport() *XTransport {
99105
useIPv6: false,
100106
http3Probe: false,
101107
tlsDisableSessionTickets: false,
108+
tlsPreferRSA: false,
102109
keyLogWriter: nil,
103110
}
104111
return &xTransport
@@ -328,6 +335,28 @@ func (xTransport *XTransport) rebuildTransport() {
328335
if xTransport.tlsDisableSessionTickets {
329336
tlsClientConfig.SessionTicketsDisabled = true
330337
}
338+
if xTransport.tlsPreferRSA {
339+
tlsClientConfig.MaxVersion = tls.VersionTLS12
340+
if hasAESGCMHardwareSupport {
341+
tlsClientConfig.CipherSuites = []uint16{
342+
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
343+
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
344+
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
345+
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
346+
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
347+
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
348+
}
349+
} else {
350+
tlsClientConfig.CipherSuites = []uint16{
351+
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
352+
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
353+
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
354+
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
355+
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
356+
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
357+
}
358+
}
359+
}
331360
transport.TLSClientConfig = &tlsClientConfig
332361
if http2Transport, _ := http2.ConfigureTransports(transport); http2Transport != nil {
333362
http2Transport.ReadIdleTimeout = timeout

0 commit comments

Comments
 (0)