Skip to content

Commit

Permalink
Merge pull request #718 from basho/feature/tedb/cleanup-ssl-cn-check
Browse files Browse the repository at this point in the history
A touch more cleanup related to [RIAK-1506]

Reviewed-by: macintux
  • Loading branch information
borshop committed Mar 13, 2015
2 parents bbd7758 + 8ffde5a commit 74e3b1a
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/riak_core_ssl_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%%
%% riak_core: Core Riak Application
%%
%% Copyright (c) 2007-2013 Basho Technologies, Inc. All Rights Reserved.
%% Copyright (c) 2007-2015 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
Expand Down Expand Up @@ -172,11 +172,22 @@ load_cert(Cert) ->
Type == 'Certificate', Cipher == 'not_encrypted']
end.

%% Reject another node whose common name is the same as ours unless it's a wildcard
%% Reject another node whose common name is the same as ours unless it's
%% a wildcard. A wildcard is defined ONLY as beginning with '*'.
%%
%% The test ONLY returns 'true' when the strings are identical (disregarding
%% case) AND do not start with the character '*'. All other cases return false,
%% hence the various shortcuts.
invalid_cn_pair([$* | _], _) ->
false;
invalid_cn_pair(LeftCN, RightCN) ->
string:to_lower(LeftCN) == string:to_lower(RightCN).
invalid_cn_pair(_, [$* | _]) ->
false;
invalid_cn_pair(SameCN, SameCN) ->
true;
invalid_cn_pair(LeftCN, RightCN) when length(LeftCN) == length(RightCN) ->
string:to_lower(LeftCN) == string:to_lower(RightCN);
invalid_cn_pair(_, _) ->
false.

%% Custom SSL verification function for checking common names against the
%% whitelist.
Expand All @@ -198,15 +209,16 @@ verify_ssl(Cert, valid_peer, {App, MyCommonName}) ->
"certificate's common name: ~p", [CommonName]),
{fail, duplicate_common_name};
_ ->
case validate_common_name(CommonName,
app_helper:get_env(App, peer_common_name_acl, "*")) of
ACL = app_helper:get_env(App, peer_common_name_acl, "*"),
case validate_common_name(CommonName, ACL) of
{true, Filter} ->
lager:info("SSL connection from ~s granted by ACL ~s",
lager:info("SSL connection from ~s granted by ACL \"~s\"",
[CommonName, Filter]),
{valid, MyCommonName};
false ->
lager:error("SSL connection from ~s denied, no matching ACL",
[CommonName]),
lager:error(
"SSL connection from ~s denied, no matching ACL in ~p",
[CommonName, ACL]),
{fail, no_acl}
end
end.
Expand Down

0 comments on commit 74e3b1a

Please sign in to comment.