Skip to content

Commit d2a1b61

Browse files
feat: expose SSL_CIPHER env var (#1693)
1 parent 9e3b47c commit d2a1b61

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

caddy/module.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ func needReplacement(s string) bool {
136136
}
137137

138138
// ServeHTTP implements caddyhttp.MiddlewareHandler.
139-
// TODO: Expose TLS versions as env vars, as Apache's mod_ssl: https://github.com/caddyserver/caddy/blob/master/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go#L298
140139
func (f *FrankenPHPModule) ServeHTTP(w http.ResponseWriter, r *http.Request, _ caddyhttp.Handler) error {
141140
origReq := r.Context().Value(caddyhttp.OriginalRequestCtxKey).(http.Request)
142141
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)

cgi.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var knownServerKeys = []string{
4141
"SERVER_PROTOCOL",
4242
"SERVER_SOFTWARE",
4343
"SSL_PROTOCOL",
44+
"SSL_CIPHER",
4445
"AUTH_TYPE",
4546
"REMOTE_IDENT",
4647
"CONTENT_TYPE",
@@ -73,11 +74,13 @@ func addKnownVariablesToServer(thread *phpThread, fc *frankenPHPContext, trackVa
7374

7475
var https string
7576
var sslProtocol string
77+
var sslCipher string
7678
var rs string
7779
if request.TLS == nil {
7880
rs = "http"
7981
https = ""
8082
sslProtocol = ""
83+
sslCipher = ""
8184
} else {
8285
rs = "https"
8386
https = "on"
@@ -89,6 +92,10 @@ func addKnownVariablesToServer(thread *phpThread, fc *frankenPHPContext, trackVa
8992
} else {
9093
sslProtocol = ""
9194
}
95+
96+
if request.TLS.CipherSuite != 0 {
97+
sslCipher = tls.CipherSuiteName(request.TLS.CipherSuite)
98+
}
9299
}
93100

94101
reqHost, reqPort, _ := net.SplitHostPort(request.Host)
@@ -151,6 +158,7 @@ func addKnownVariablesToServer(thread *phpThread, fc *frankenPHPContext, trackVa
151158
packCgiVariable(keys["REMOTE_IDENT"], ""),
152159
// Request uri of the original request
153160
packCgiVariable(keys["REQUEST_URI"], requestURI),
161+
packCgiVariable(keys["SSL_CIPHER"], sslCipher),
154162
)
155163

156164
// These values are already present in the SG(request_info), so we'll register them from there

frankenphp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ void frankenphp_register_bulk(
641641
ht_key_value_pair gateway_interface, ht_key_value_pair server_protocol,
642642
ht_key_value_pair server_software, ht_key_value_pair http_host,
643643
ht_key_value_pair auth_type, ht_key_value_pair remote_ident,
644-
ht_key_value_pair request_uri) {
644+
ht_key_value_pair request_uri, ht_key_value_pair ssl_cipher) {
645645
HashTable *ht = Z_ARRVAL_P(track_vars_array);
646646
frankenphp_register_trusted_var(remote_addr.key, remote_addr.val,
647647
remote_addr.val_len, ht);
@@ -664,6 +664,8 @@ void frankenphp_register_bulk(
664664
frankenphp_register_trusted_var(https.key, https.val, https.val_len, ht);
665665
frankenphp_register_trusted_var(ssl_protocol.key, ssl_protocol.val,
666666
ssl_protocol.val_len, ht);
667+
frankenphp_register_trusted_var(ssl_cipher.key, ssl_cipher.val,
668+
ssl_cipher.val_len, ht);
667669
frankenphp_register_trusted_var(request_scheme.key, request_scheme.val,
668670
request_scheme.val_len, ht);
669671
frankenphp_register_trusted_var(server_name.key, server_name.val,

frankenphp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void frankenphp_register_bulk(
9191
ht_key_value_pair gateway_interface, ht_key_value_pair server_protocol,
9292
ht_key_value_pair server_software, ht_key_value_pair http_host,
9393
ht_key_value_pair auth_type, ht_key_value_pair remote_ident,
94-
ht_key_value_pair request_uri);
94+
ht_key_value_pair request_uri, ht_key_value_pair ssl_cipher);
9595

9696
void register_extensions(zend_module_entry *m, int len);
9797

0 commit comments

Comments
 (0)