Skip to content

Commit

Permalink
Clean up the parsing of the ssl configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Faulet committed Feb 26, 2014
1 parent 2dcb7a5 commit 15a171f
Showing 1 changed file with 20 additions and 56 deletions.
76 changes: 20 additions & 56 deletions src/yaws_config.erl
Expand Up @@ -1726,105 +1726,72 @@ fload(FD, ssl, GC, C, Cs, Lno, Chars) ->

["keyfile", '=', Val] ->
case is_file(Val) of
true when is_record(C#sconf.ssl, ssl) ->
true ->
C2 = C#sconf{ssl = (C#sconf.ssl)#ssl{keyfile = Val}},
fload(FD, ssl, GC, C2, Cs, Lno+1, Next);
true ->
{error, ?F("Need to set option ssl to true before line ~w",
[Lno])};
_ ->
{error, ?F("Expect existing file at line ~w", [Lno])}
end;
["certfile", '=', Val] ->
case is_file(Val) of
true when is_record(C#sconf.ssl, ssl) ->
true ->
C2 = C#sconf{ssl = (C#sconf.ssl)#ssl{certfile = Val}},
fload(FD, ssl, GC, C2, Cs, Lno+1, Next);
true ->
{error, ?F("Need to set option ssl to true before line ~w",
[Lno])};
_ ->
{error, ?F("Expect existing file at line ~w", [Lno])}
end;
["cacertfile", '=', Val] ->
case is_file(Val) of
true when is_record(C#sconf.ssl, ssl) ->
true ->
C2 = C#sconf{ssl = (C#sconf.ssl)#ssl{cacertfile = Val}},
fload(FD, ssl, GC, C2, Cs, Lno+1, Next);
true ->
{error, ?F("Need to set option ssl to true before line ~w",
[Lno])};
_ ->
{error, ?F("Expect existing file at line ~w", [Lno])}
end;
["verify", '=', Val0] ->
Val =
try
list_to_integer(Val0)
catch error:badarg ->
list_to_atom(Val0)
end,
Val = try
list_to_integer(Val0)
catch error:badarg ->
list_to_atom(Val0)
end,
case lists:member(Val, [0,1,2,verify_peer,verify_none]) of
true when is_record(C#sconf.ssl, ssl) ->
true ->
C2 = C#sconf{ssl = (C#sconf.ssl)#ssl{verify = Val}},
fload(FD, ssl, GC, C2, Cs, Lno+1, Next);
true ->
{error, ?F("Need to set option ssl to true before line ~w",
[Lno])};
_ ->
{error, ?F("Expect integer or verify_none, "
"verify_peer at line ~w", [Lno])}
end;
["fail_if_no_peer_cert", '=', Val0] ->
Val = (catch list_to_atom(Val0)),
if
is_record(C#sconf.ssl, ssl) ->
["fail_if_no_peer_cert", '=', Bool] ->
case is_bool(Bool) of
{true, Val} ->
C2 = C#sconf{ssl = (C#sconf.ssl)#ssl{
fail_if_no_peer_cert = Val}},
fload(FD, ssl, GC, C2, Cs, Lno+1, Next);
true ->
{error, ?F("Need to set option fail_if_no_peer_cert "
"to true before line ~w",
[Lno])}
false ->
{error, ?F("Expect true|false at line ~w", [Lno])}
end;
["depth", '=', Val0] ->
Val = (catch list_to_integer(Val0)),
case lists:member(Val, [0, 1,2,3,4,5,6,7]) of
true when is_record(C#sconf.ssl, ssl) ->
true ->
C2 = C#sconf{ssl = (C#sconf.ssl)#ssl{depth = Val}},
fload(FD, ssl, GC, C2, Cs, Lno+1, Next);
true ->
{error, ?F("Need to set option ssl to true before line ~w",
[Lno])};
_ ->
{error, ?F("Expect integer 0..7 at line ~w", [Lno])}
end;
["password", '=', Val] ->
if
is_record(C#sconf.ssl, ssl) ->
C2 = C#sconf{ssl = (C#sconf.ssl)#ssl{password = Val}},
fload(FD, ssl, GC, C2, Cs, Lno+1, Next);
true ->
{error, ?F("Need to set option ssl to true before line ~w",
[Lno])}
end;
C2 = C#sconf{ssl = (C#sconf.ssl)#ssl{password = Val}},
fload(FD, ssl, GC, C2, Cs, Lno+1, Next);
["ciphers", '=', Val] ->
try
L = str2term(Val),
io:format("L = ~p~n",[L]),
Ciphers = ssl:cipher_suites(),
case check_ciphers(L, Ciphers) of
ok ->
if
is_record(C#sconf.ssl, ssl) ->
C2 = C#sconf{ssl = (C#sconf.ssl)#ssl{
ciphers = L}},
fload(FD, ssl, GC, C2, Cs, Lno+1, Next);
true ->
{error, ?F("Need to set option ssl to "
"true before line ~w",
[Lno])}
end;
C2 = C#sconf{ssl = (C#sconf.ssl)#ssl{ciphers = L}},
fload(FD, ssl, GC, C2, Cs, Lno+1, Next);
Err ->
Err
end
Expand All @@ -1834,12 +1801,9 @@ fload(FD, ssl, GC, C, Cs, Lno, Chars) ->
end;
["secure_renegotiate", '=', Bool] ->
case is_bool(Bool) of
{true, Val} when is_record(C#sconf.ssl, ssl) ->
{true, Val} ->
C2 = C#sconf{ssl=(C#sconf.ssl)#ssl{secure_renegotiate=Val}},
fload(FD, ssl, GC, C2, Cs, Lno+1, Next);
{true, _} ->
{error, ?F("Need to set option ssl to true before line ~w",
[Lno])};
false ->
{error, ?F("Expect true|false at line ~w", [Lno])}
end;
Expand Down

0 comments on commit 15a171f

Please sign in to comment.