Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion apps/epp_proxy/include/epp_proxy.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
epp_verb % Epp verb that is targeted, plus 'error'
}).

-type epp_request() :: #epp_request{}.
-record(valid_frame, {command, cl_trid, raw_frame}).

-record(invalid_frame, {code, cl_trid, message}).

-record(state, {socket, session_id, headers}).

-type epp_request() :: #epp_request{}.

-define(XMLErrorCode, <<"2001">>).

Expand Down
4 changes: 3 additions & 1 deletion apps/epp_proxy/priv/test_backend_app/epp_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class EppServer < Roda

r.on "session" do
r.get "hello" do
render("session/hello")
if r.cookies['session']
render("session/hello")
end
end

r.post "login" do
Expand Down
21 changes: 15 additions & 6 deletions apps/epp_proxy/src/epp_http_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

%% Callback API
request(#epp_request{} = Request) ->
HackneyArgs = handle_args(Request),
case apply(hackney, request, HackneyArgs) of
[Method, URL, Headers, Payload, Options] =
handle_args(Request),
case hackney:request(Method, URL, Headers, Payload,
Options)
of
{error, Error} -> log_and_return_canned(Error, Request);
{Status, _StatusCode, _Headers, ClientRef} ->
{ok, Body} = hackney:body(ClientRef), {Status, Body}
Expand All @@ -28,7 +31,7 @@ request_builder(Map) -> request_from_map(Map).
handle_args(#epp_request{method = get, url = URL,
headers = Headers, cookies = Cookies,
epp_verb = ?helloCommand}) ->
[get, URL, Headers, "", [{cookie, Cookies}, insecure]];
[get, URL, Headers, "", hackney_options(Cookies)];
%% For error command, we convert the message and code into query parameters,
%% and append them to the original URL.
handle_args(#epp_request{method = get, url = URL,
Expand All @@ -37,13 +40,12 @@ handle_args(#epp_request{method = get, url = URL,
QueryString = hackney_url:qs(Payload),
CompleteURL = [URL, <<"?">>, QueryString],
[get, CompleteURL, Headers, "",
[{cookie, Cookies}, insecure]];
hackney_options(Cookies)];
%% For valid commands, we set the multipart body earlier, now we just pass it on.
handle_args(#epp_request{method = post, url = URL,
payload = Payload, headers = Headers,
cookies = Cookies}) ->
[post, URL, Headers, Payload,
[{cookie, Cookies}, insecure]].
[post, URL, Headers, Payload, hackney_options(Cookies)].

%% Map request and return values.
request_from_map(#{command := ?errorCommand,
Expand Down Expand Up @@ -79,6 +81,13 @@ request_from_map(#{command := Command,
lager:info("Request from map: [~p]~n", [Request]),
Request.

%% Get hackney options
hackney_options(Cookies) ->
case application:get_env(epp_proxy, insecure) of
false -> [{cookie, Cookies}, insecure];
_ -> [{cookie, Cookies}]
end.

%% Return form data or an empty list.
request_body(?helloCommand, _, _) -> "";
request_body(_Command, RawFrame, nomatch) ->
Expand Down
6 changes: 0 additions & 6 deletions apps/epp_proxy/src/epp_tcp_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@

-export([code_change/3]).

-record(valid_frame, {command, cl_trid, raw_frame}).

-record(invalid_frame, {code, cl_trid, message}).

-record(state, {socket, session_id, headers}).

%% Initialize process
%% Assign an unique session id that will be passed on to http server as a cookie
init(Socket) ->
Expand Down
9 changes: 2 additions & 7 deletions apps/epp_proxy/src/epp_tls_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@

-export([code_change/3]).

-record(valid_frame, {command, cl_trid, raw_frame}).

-record(invalid_frame, {code, cl_trid, message}).

-record(state, {socket, session_id, headers}).

%% Initialize process
%% Assign an unique session id that will be passed on to http server as a cookie
init(Socket) ->
Expand Down Expand Up @@ -171,7 +165,8 @@ log_on_invalid_handshake(Ip, Error) ->

log_opened_connection(Ip) ->
ReadableIp = epp_util:readable_ip(Ip),
lager:info("New client connection. IP: ~s, Process: ~p.~n",
lager:info("New client connection. IP: ~s, Process: "
"~p.~n",
[ReadableIp, self()]).

%% Extract state info from socket. Fail if you must.
Expand Down
1 change: 1 addition & 0 deletions config/docker.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{dev_mode, true},
{tcp_port, 3333},
{tls_port, 700},
{insecure, false},
{epp_session_url, "http://epp:3000/epp/session/"},
{epp_command_url, "http://epp:3000/epp/command/"},
{epp_error_url, "http://epp:3000/epp/error/"},
Expand Down
3 changes: 3 additions & 0 deletions config/sys.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
%% TLS port, specified in RFC to 700, but can be set to anything else
%% in case that is needed.
{tls_port, 700},
%% When set to true, you can connect to EPP over HTTPS endpoints without
%% verifying their TLS certificates.
{insecure, false}
%% URL of EPP endpoints. Can be pointed at a web server (Apache/NGINX)
%% Can contain port (https://some-host:3000/epp/session)
%% Honors the prepended protocol (http / https).
Expand Down
1 change: 1 addition & 0 deletions config/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{epp_proxy, [{dev_mode, true},
{tcp_port, 1180},
{tls_port, 1443},
{insecure, false},

{epp_session_url, "http://localhost:9292/session/"},
{epp_command_url, "http://localhost:9292/command/"},
Expand Down