Skip to content

Commit 1843dbf

Browse files
author
tsoganov
committed
Added optional client certs flag
1 parent 738c8a3 commit 1843dbf

6 files changed

Lines changed: 62 additions & 8 deletions

File tree

Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,21 @@ ENV KERL_DOC_TARGETS=""
4444
ENV KERL_INSTALL_HTMLDOCS="no"
4545
ENV KERL_INSTALL_MANPAGES="no"
4646

47-
RUN git clone https://github.com/asdf-vm/asdf.git --branch v0.6.3 "$HOME"/.asdf && \
48-
echo '. $HOME/.asdf/asdf.sh' >> "$HOME"/.bashrc && \
49-
echo '. $HOME/.asdf/asdf.sh' >> "$HOME"/.profile
47+
# Install asdf and add it to PATH
48+
RUN git clone https://github.com/asdf-vm/asdf.git --branch v0.6.3 /root/.asdf && \
49+
echo '. /root/.asdf/asdf.sh' >> /root/.bashrc && \
50+
echo '. /root/.asdf/asdf.sh' >> /root/.profile
5051

51-
ENV PATH="${PATH}:/root/.asdf/shims:/root/.asdf/bin"
52+
ENV PATH="/root/.asdf/shims:/root/.asdf/bin:${PATH}"
5253

5354
RUN mkdir -p /opt/erlang/epp_proxy
5455
WORKDIR /opt/erlang/epp_proxy
5556

5657
COPY .tool-versions ./
58+
59+
# Install plugins and tools with explicit sourcing of asdf.sh
5760
RUN asdf plugin-add erlang
58-
RUN . $HOME/.asdf/asdf.sh && asdf install
61+
RUN source /root/.asdf/asdf.sh && asdf install
5962
RUN asdf global erlang $(grep erlang .tool-versions | cut -d' ' -f2)
6063
RUN asdf plugin-add ruby
6164
RUN asdf plugin-add rebar

apps/epp_proxy/src/epp_tls_acceptor.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ start_link(Port) ->
2121
[]).
2222

2323
init(Port) ->
24+
RequireClientCerts = require_client_certs(),
2425
DefaultOptions = [binary, {packet, raw},
2526
{active, false}, {reuseaddr, true},
26-
{verify, verify_peer}, {depth, 1},
27+
{verify, verify_peer}, {fail_if_no_peer_cert, RequireClientCerts}, {depth, 1},
2728
{cacertfile, ca_cert_file()}, {certfile, cert_file()},
2829
{keyfile, key_file()}],
2930
Options = handle_crl_check_options(DefaultOptions),
@@ -82,6 +83,14 @@ key_file() ->
8283
{ok, KeyFile} -> epp_util:path_for_file(KeyFile)
8384
end.
8485

86+
%% Whether client certificates are required.
87+
%% If not configured, default to true to preserve existing behavior.
88+
require_client_certs() ->
89+
case application:get_env(epp_proxy, require_client_certs) of
90+
undefined -> true;
91+
{ok, Bool} -> Bool
92+
end.
93+
8594
crl_file() ->
8695
case application:get_env(epp_proxy, crlfile_path) of
8796
undefined -> undefined;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
-module(tls_client_optional_cert_SUITE).
2+
3+
-include_lib("common_test/include/ct.hrl").
4+
5+
-export([all/0, init_per_suite/1, end_per_suite/1,
6+
connect_without_client_cert_test/1, connect_with_client_cert_test/1]).
7+
8+
all() -> [connect_without_client_cert_test, connect_with_client_cert_test].
9+
10+
init_per_suite(Config) ->
11+
application:set_env(epp_proxy, require_client_certs, false),
12+
application:ensure_all_started(epp_proxy),
13+
application:ensure_all_started(hackney),
14+
CWD = code:priv_dir(epp_proxy),
15+
WithCert = [binary,
16+
{certfile, filename:join(CWD, "test_ca/certs/client.crt.pem")},
17+
{keyfile, filename:join(CWD, "test_ca/private/client.key.pem")},
18+
{active, false}],
19+
[{with_cert, WithCert} | Config].
20+
21+
end_per_suite(Config) ->
22+
application:unset_env(epp_proxy, require_client_certs),
23+
application:stop(epp_proxy),
24+
application:stop(hackney),
25+
Config.
26+
27+
connect_without_client_cert_test(_Config) ->
28+
{ok, Socket} = ssl:connect("localhost", 1443, [binary, {active, false}], 2000),
29+
{ok, _Data} = ssl:recv(Socket, 0, 1200),
30+
ok.
31+
32+
connect_with_client_cert_test(Config) ->
33+
Options = proplists:get_value(with_cert, Config),
34+
{ok, Socket} = ssl:connect("localhost", 1443, Options, 2000),
35+
{ok, _Data} = ssl:recv(Socket, 0, 1200),
36+
ok.

config/docker.config

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
{epp_session_url, "http://epp:3000/epp/session/"},
99
{epp_command_url, "http://epp:3000/epp/command/"},
1010
{epp_error_url, "http://epp:3000/epp/error/"},
11+
%% Allows client to connect to epp_proxy without client certificate using TLS
12+
{require_client_certs, true},
1113
{cacertfile_path, "/opt/ca/certs/ca.crt.pem"},
1214
{certfile_path, "/opt/ca/certs/apache.crt"},
13-
{keyfile_path, "/opt/ca/private/apache.key"},
14-
{crlfile_path, "/opt/ca/crl/crl.pem"}
15+
{keyfile_path, "/opt/ca/private/apache.key"}
16+
%% {crlfile_path, "/opt/ca/crl/crl.pem"}
1517
]},
1618
{lager, [
1719
{handlers, [

config/sys.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
{epp_session_url, "${EPP_SESSION_URL}"},
1818
{epp_command_url, "${EPP_COMMAND_URL}"},
1919
{epp_error_url, "${EPP_ERROR_URL}"},
20+
%% Allows client to connect to epp_proxy without client certificate using TLS
21+
{require_client_certs, true},
2022
%% Path to root CA that should check the client certificates.
2123
{cacertfile_path, "${CACERT_PATH}"},
2224
%% Path to server's certficate file.

config/test.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
{epp_session_url, "http://localhost:9292/session/"},
88
{epp_command_url, "http://localhost:9292/command/"},
99
{epp_error_url, "http://localhost:9292/error/"},
10+
%% Allows client to connect to epp_proxy without client certificate using TLS
11+
{require_client_certs, true},
1012
%% Path to root CA that should check the client certificates.
1113
{cacertfile_path, "test_ca/certs/ca.crt.pem"},
1214
{certfile_path, "test_ca/certs/apache.crt"},

0 commit comments

Comments
 (0)