File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ (executable
2+ (name test)
3+ (libraries ocsigenserver))
Original file line number Diff line number Diff line change 1+ (lang dune 3 .18)
Original file line number Diff line number Diff line change 1+ F5: the HTTPS server must require TLS 1.2 at minimum (TLS 1.0 / 1.1 deprecated).
2+ Self-contained POSIX sh.
3+
4+ $ mkdir -p log data
5+ $ openssl req -x509 -newkey rsa: 2048 -nodes -keyout privkey. pem \
6+ > -out cert. pem -days 2 -subj / CN= localhost > /dev /null 2 > &1
7+ $ dune build ./ test. exe 2 > &1
8+ $ dune exec -- ./ test. exe > server. log 2 > &1 &
9+ $ trap ' echo shutdown > local.cmd 2>/dev/null; wait' EXIT
10+ $ i= 0 ; while [ ! -e local. cmd ]; do
11+ > i= $ ((i+ 1)); [ $ i -gt 200 ] && break ; sleep 0.05 ; done
12+ $ i= 0 ; while ! curl -sk -- tls-max 1.2 https: // 127.0 . 0. 1: 8453 / > /dev /null 2 > &1; do
13+ > i= $ ((i+ 1)); [ $ i -gt 200 ] && break ; sleep 0.05 ; done
14+
15+ A TLS 1.2 client succeeds:
16+
17+ $ curl -sk -- tlsv1. 2 -- tls-max 1.2 -o / dev/ null -w ' %{http_code}\n' https: // 127.0 . 0. 1: 8453 /
18+ 200
19+
20+ A TLS 1.1 client is refused (curl returns a non-zero exit code):
21+
22+ $ curl -sk -- tls-max 1.1 https: // 127.0 . 0. 1: 8453 / > /dev /null 2 > &1 && echo accepted || echo rejected
23+ rejected
Original file line number Diff line number Diff line change 1+ (* F5: the HTTPS server must require TLS 1.2 at minimum. This starts an HTTPS
2+ listener with a self-signed certificate (generated by the cram test). The
3+ handler is irrelevant: the test only checks the TLS handshake. *)
4+
5+ let respond _vh _config_info _path _request_state =
6+ Lwt. return
7+ (Ocsigen.Extensions. Ext_found
8+ (fun () ->
9+ Lwt. return
10+ (Ocsigen.Response. make
11+ (Cohttp.Response. make ~status: `OK () ))))
12+
13+ let () =
14+ Ocsigen.Server. start ~ports: []
15+ ~ssl_ports: [ (`All , 8453 ) ]
16+ ~ssl_info:
17+ (Some
18+ { Ocsigen.Config. ssl_certificate = Some " cert.pem"
19+ ; ssl_privatekey = Some " privkey.pem"
20+ ; ssl_ciphers = None
21+ ; ssl_dhfile = None
22+ ; ssl_curve = None })
23+ ~logdir: " log" ~datadir: " data" ~uploaddir: None ~usedefaulthostname: true
24+ ~command_pipe: " local.cmd" ~default_charset: (Some " utf-8" )
25+ [ Ocsigen.Server. host [ respond ] ]
Original file line number Diff line number Diff line change 1+ (executable
2+ (name test)
3+ (libraries ocsigenserver))
Original file line number Diff line number Diff line change 1+ (lang dune 3 .18)
Original file line number Diff line number Diff line change 1+ Security hardening checks: command pipe permissions (F8) and error-body
2+ sanitisation (F4). Self-contained (POSIX sh, no bash helper) so it runs
3+ regardless of the cram shell.
4+
5+ $ mkdir -p log data
6+ $ dune build ./test.exe 2>&1
7+ $ dune exec -- ./test.exe >server.log 2>&1 &
8+ $ trap ' echo shutdown > local.cmd 2>/dev/null; wait' EXIT
9+ $ i=0; while [ ! -e local .sock ] || [ ! -e local .cmd ]; do
10+ > i=$( (i+1)); [ $i -gt 200 ] && break; sleep 0.05; done
11+
12+ F8: the command pipe is created with mode 0o600, so that only the server' s own
13+ user can send it control commands.
14+
15+ $ stat -c ' %a ' local.cmd
16+ 600
17+
18+ F4: a handler error returns the generic HTTP status reason phrase, never the
19+ OCaml exception (the word "secret" from the exception must not appear).
20+
21+ $ curl --unix-socket local.sock -s -o /dev/null -w ' %{http_code }\n' http://x/anything
22+ 500
23+ $ curl --unix-socket local.sock -s http://x/anything
24+ Error: Internal Server Error
25+ $ curl --unix-socket local.sock -s http://x/anything | grep -c secret || true
26+ 0
Original file line number Diff line number Diff line change 1+ (* End-to-end checks for the security hardening:
2+ - F4: a handler error must not leak the OCaml exception in the response
3+ body; the client gets the generic HTTP status reason phrase.
4+ - F8: the command pipe must be created with mode 0o600.
5+
6+ The [boom] instruction intercepts every request and fails with an
7+ exception carrying a "secret" message that must never reach the client. *)
8+
9+ let boom _vh _config_info _path _request_state =
10+ Lwt. fail (Failure " secret internal detail that must not leak to the client" )
11+
12+ let () =
13+ Ocsigen.Server. start
14+ ~ports: [ (`Unix " ./local.sock" , 0 ) ]
15+ ~logdir: " log" ~datadir: " data" ~uploaddir: None ~usedefaulthostname: true
16+ ~command_pipe: " local.cmd" ~default_charset: (Some " utf-8" )
17+ [ Ocsigen.Server. host [ boom ] ]
You can’t perform that action at this time.
0 commit comments