Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
caddyhttp: New placeholder for PEM of client certificate (#3662)
* Fix-3585: added placeholder for a PEM encoded value of the certificate * Update modules/caddyhttp/replacer.go Change type of block and empty headers removed Co-authored-by: Matt Holt <mholt@users.noreply.github.com> * fixed tests Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Gaurav Dhameeja committed
Sep 17, 2020 at 02:36 UTC
b01bb275b395643542ceca4fbc82bedea8e43937
2 files changed
+8
modules/caddyhttp/replacer.go
+4
@@ -25,6 +25,7 @@ import (
25
"crypto/tls"
26
"crypto/x509"
27
"encoding/asn1"
28
+ "encoding/pem"
29
"fmt"
30
"io"
31
"io/ioutil"
@@ -343,6 +344,9 @@ func getReqTLSReplacement(req *http.Request, key string) (interface{}, bool) {
344
return cert.SerialNumber, true
345
case "client.subject":
346
return cert.Subject, true
347
+ case "client.certificate_pem":
348
+ block := pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw}
349
+ return pem.EncodeToMemory(&block), true
350
default:
351
return nil, false
352
}
modules/caddyhttp/replacer_test.go
+4
@@ -171,6 +171,10 @@ eqp31wM9il1n+guTNyxJd+FzVAH+hCZE5K+tCgVDdVFUlDEHHbS/wqb2PSIoouLV
171
input: "{http.request.tls.client.san.ips.0}",
172
expect: "127.0.0.1",
173
},
174
+ {
175
+ input: "{http.request.tls.client.certificate_pem}",
176
+ expect: string(clientCert) + "\n", // returned value comes with a newline appended to it
177
+ },
178
} {
179
actual := repl.ReplaceAll(tc.input, "<empty>")
180
if actual != tc.expect {