2002-12-06 21:59:19 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : ejabberd_s2s_in.erl
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2006-01-13 02:55:20 +01:00
|
|
|
%%% Purpose : Serve incoming s2s connection
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Created : 6 Dec 2002 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2010-01-12 17:15:16 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2010 ProcessOne
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-19 15:47:33 +01:00
|
|
|
%%%
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License
|
|
|
|
%%% along with this program; if not, write to the Free Software
|
|
|
|
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
%%% 02111-1307 USA
|
|
|
|
%%%
|
2002-12-06 21:59:19 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(ejabberd_s2s_in).
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2002-12-06 21:59:19 +01:00
|
|
|
|
|
|
|
-behaviour(gen_fsm).
|
|
|
|
|
|
|
|
%% External exports
|
2003-11-10 22:25:36 +01:00
|
|
|
-export([start/2,
|
2006-01-13 02:55:20 +01:00
|
|
|
start_link/2,
|
2006-09-25 05:51:11 +02:00
|
|
|
match_domain/2,
|
|
|
|
socket_type/0]).
|
2002-12-06 21:59:19 +01:00
|
|
|
|
|
|
|
%% gen_fsm callbacks
|
2002-12-07 21:27:26 +01:00
|
|
|
-export([init/1,
|
|
|
|
wait_for_stream/2,
|
2005-10-25 03:08:37 +02:00
|
|
|
wait_for_feature_request/2,
|
2002-12-07 21:27:26 +01:00
|
|
|
stream_established/2,
|
2003-01-24 21:18:33 +01:00
|
|
|
handle_event/3,
|
|
|
|
handle_sync_event/4,
|
|
|
|
code_change/4,
|
2002-12-06 21:59:19 +01:00
|
|
|
handle_info/3,
|
|
|
|
terminate/3]).
|
|
|
|
|
2008-06-30 14:13:15 +02:00
|
|
|
-include_lib("exmpp/include/exmpp.hrl").
|
2008-06-26 17:48:19 +02:00
|
|
|
|
2002-12-06 21:59:19 +01:00
|
|
|
-include("ejabberd.hrl").
|
2009-08-15 22:10:49 +02:00
|
|
|
-include("XmppAddr.hrl").
|
2008-01-15 12:11:27 +01:00
|
|
|
-include_lib("ssl/include/ssl_pkix.hrl").
|
2008-03-11 15:25:35 +01:00
|
|
|
-define(PKIXEXPLICIT, 'OTP-PKIX').
|
|
|
|
-define(PKIXIMPLICIT, 'OTP-PKIX').
|
2002-12-06 21:59:19 +01:00
|
|
|
|
2003-10-29 21:09:09 +01:00
|
|
|
-define(DICT, dict).
|
|
|
|
|
2003-11-10 22:25:36 +01:00
|
|
|
-record(state, {socket,
|
2006-10-01 03:53:37 +02:00
|
|
|
sockmod,
|
2003-11-10 22:25:36 +01:00
|
|
|
streamid,
|
|
|
|
shaper,
|
2005-10-25 03:08:37 +02:00
|
|
|
tls = false,
|
|
|
|
tls_enabled = false,
|
|
|
|
tls_options = [],
|
2005-11-03 06:04:54 +01:00
|
|
|
authenticated = false,
|
|
|
|
auth_domain,
|
2003-12-06 20:58:49 +01:00
|
|
|
connections = ?DICT:new(),
|
|
|
|
timer}).
|
2003-10-29 21:09:09 +01:00
|
|
|
|
2002-12-07 21:27:26 +01:00
|
|
|
|
2003-01-13 21:51:17 +01:00
|
|
|
%-define(DBGFSM, true).
|
2002-12-06 21:59:19 +01:00
|
|
|
|
|
|
|
-ifdef(DBGFSM).
|
|
|
|
-define(FSMOPTS, [{debug, [trace]}]).
|
|
|
|
-else.
|
|
|
|
-define(FSMOPTS, []).
|
|
|
|
-endif.
|
|
|
|
|
2007-09-14 16:16:36 +02:00
|
|
|
%% Module start with or without supervisor:
|
|
|
|
-ifdef(NO_TRANSIENT_SUPERVISORS).
|
|
|
|
-define(SUPERVISOR_START, gen_fsm:start(ejabberd_s2s_in, [SockData, Opts],
|
|
|
|
?FSMOPTS)).
|
|
|
|
-else.
|
|
|
|
-define(SUPERVISOR_START, supervisor:start_child(ejabberd_s2s_in_sup,
|
|
|
|
[SockData, Opts])).
|
|
|
|
-endif.
|
|
|
|
|
2008-06-26 17:48:19 +02:00
|
|
|
% These are the namespace already declared by the stream opening. This is
|
|
|
|
% used at serialization time.
|
2008-06-27 15:46:08 +02:00
|
|
|
-define(DEFAULT_NS, ?NS_JABBER_SERVER).
|
|
|
|
-define(PREFIXED_NS, [
|
|
|
|
{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}
|
|
|
|
]).
|
2003-01-04 21:09:25 +01:00
|
|
|
|
2002-12-06 21:59:19 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% API
|
|
|
|
%%%----------------------------------------------------------------------
|
2003-07-20 22:35:35 +02:00
|
|
|
start(SockData, Opts) ->
|
2007-09-14 16:16:36 +02:00
|
|
|
?SUPERVISOR_START.
|
2003-07-20 22:35:35 +02:00
|
|
|
|
2003-11-10 22:25:36 +01:00
|
|
|
start_link(SockData, Opts) ->
|
|
|
|
gen_fsm:start_link(ejabberd_s2s_in, [SockData, Opts], ?FSMOPTS).
|
2002-12-06 21:59:19 +01:00
|
|
|
|
2006-09-25 05:51:11 +02:00
|
|
|
socket_type() ->
|
|
|
|
xml_stream.
|
|
|
|
|
2002-12-06 21:59:19 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% Callback functions from gen_fsm
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: init/1
|
|
|
|
%% Returns: {ok, StateName, StateData} |
|
|
|
|
%% {ok, StateName, StateData, Timeout} |
|
|
|
|
%% ignore |
|
2007-09-14 16:15:44 +02:00
|
|
|
%% {stop, StopReason}
|
2002-12-06 21:59:19 +01:00
|
|
|
%%----------------------------------------------------------------------
|
2006-10-01 03:53:37 +02:00
|
|
|
init([{SockMod, Socket}, Opts]) ->
|
2007-09-14 16:16:04 +02:00
|
|
|
?DEBUG("started: ~p", [{SockMod, Socket}]),
|
2003-11-10 22:25:36 +01:00
|
|
|
Shaper = case lists:keysearch(shaper, 1, Opts) of
|
|
|
|
{value, {_, S}} -> S;
|
|
|
|
_ -> none
|
|
|
|
end,
|
2005-10-25 03:08:37 +02:00
|
|
|
StartTLS = case ejabberd_config:get_local_option(s2s_use_starttls) of
|
|
|
|
undefined ->
|
|
|
|
false;
|
|
|
|
UseStartTLS ->
|
|
|
|
UseStartTLS
|
|
|
|
end,
|
|
|
|
TLSOpts = case ejabberd_config:get_local_option(s2s_certfile) of
|
|
|
|
undefined ->
|
|
|
|
[];
|
|
|
|
CertFile ->
|
|
|
|
[{certfile, CertFile}]
|
|
|
|
end,
|
2003-12-06 20:58:49 +01:00
|
|
|
Timer = erlang:start_timer(?S2STIMEOUT, self(), []),
|
2003-05-12 20:36:13 +02:00
|
|
|
{ok, wait_for_stream,
|
|
|
|
#state{socket = Socket,
|
2006-10-01 03:53:37 +02:00
|
|
|
sockmod = SockMod,
|
2003-11-10 22:25:36 +01:00
|
|
|
streamid = new_id(),
|
2003-12-06 20:58:49 +01:00
|
|
|
shaper = Shaper,
|
2005-10-25 03:08:37 +02:00
|
|
|
tls = StartTLS,
|
|
|
|
tls_enabled = false,
|
|
|
|
tls_options = TLSOpts,
|
2003-12-06 20:58:49 +01:00
|
|
|
timer = Timer}}.
|
2002-12-06 21:59:19 +01:00
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: StateName/2
|
|
|
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
|
|
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
2007-09-14 16:15:44 +02:00
|
|
|
%% {stop, Reason, NewStateData}
|
2002-12-06 21:59:19 +01:00
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
|
2008-06-26 17:48:19 +02:00
|
|
|
wait_for_stream({xmlstreamstart, Opening}, StateData) ->
|
|
|
|
case {exmpp_stream:get_default_ns(Opening),
|
2008-06-27 15:46:08 +02:00
|
|
|
exmpp_xml:is_ns_declared_here(Opening, ?NS_DIALBACK),
|
2010-05-10 08:00:30 +02:00
|
|
|
exmpp_stream:get_receiving_entity(Opening),
|
2008-06-26 17:48:19 +02:00
|
|
|
exmpp_stream:get_version(Opening) == {1, 0}} of
|
2010-05-10 08:00:30 +02:00
|
|
|
{?NS_JABBER_SERVER, _, Server, true} when
|
2005-11-03 06:04:54 +01:00
|
|
|
StateData#state.tls and (not StateData#state.authenticated) ->
|
2008-06-26 17:48:19 +02:00
|
|
|
Opening_Reply = exmpp_stream:opening_reply(Opening,
|
|
|
|
StateData#state.streamid),
|
|
|
|
send_element(StateData,
|
|
|
|
exmpp_stream:set_dialback_support(Opening_Reply)),
|
2005-11-03 06:04:54 +01:00
|
|
|
SASL =
|
|
|
|
if
|
|
|
|
StateData#state.tls_enabled ->
|
2006-10-01 03:53:37 +02:00
|
|
|
case (StateData#state.sockmod):get_peer_certificate(
|
2006-09-05 06:36:01 +02:00
|
|
|
StateData#state.socket) of
|
2005-11-03 06:04:54 +01:00
|
|
|
{ok, _Cert} ->
|
2006-10-01 03:53:37 +02:00
|
|
|
case (StateData#state.sockmod):get_verify_result(
|
2005-11-03 06:04:54 +01:00
|
|
|
StateData#state.socket) of
|
|
|
|
0 ->
|
2008-06-26 17:48:19 +02:00
|
|
|
[exmpp_server_sasl:feature(
|
|
|
|
["EXTERNAL"])];
|
2005-11-03 06:04:54 +01:00
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end;
|
|
|
|
error ->
|
|
|
|
[]
|
|
|
|
end;
|
|
|
|
true ->
|
|
|
|
[]
|
|
|
|
end,
|
|
|
|
StartTLS = if
|
|
|
|
StateData#state.tls_enabled ->
|
|
|
|
[];
|
|
|
|
true ->
|
2008-06-26 17:48:19 +02:00
|
|
|
[exmpp_server_tls:feature()]
|
2005-11-03 06:04:54 +01:00
|
|
|
end,
|
2010-05-10 08:00:30 +02:00
|
|
|
Features = SASL ++ StartTLS ++ ejabberd_hooks:run_fold(
|
|
|
|
c2s_stream_features,
|
|
|
|
Server,
|
|
|
|
[], [Server]),
|
|
|
|
send_element(StateData, exmpp_stream:features(Features)),
|
2005-10-25 03:08:37 +02:00
|
|
|
{next_state, wait_for_feature_request, StateData};
|
2010-05-10 08:00:30 +02:00
|
|
|
{?NS_JABBER_SERVER, _, Server, true} when
|
2005-11-03 06:04:54 +01:00
|
|
|
StateData#state.authenticated ->
|
2008-06-26 17:48:19 +02:00
|
|
|
Opening_Reply = exmpp_stream:opening_reply(Opening,
|
|
|
|
StateData#state.streamid),
|
2005-11-03 06:04:54 +01:00
|
|
|
send_element(StateData,
|
2008-06-26 17:48:19 +02:00
|
|
|
exmpp_stream:set_dialback_support(Opening_Reply)),
|
2010-05-10 08:00:30 +02:00
|
|
|
Features = ejabberd_hooks:run_fold(
|
|
|
|
c2s_stream_features,
|
|
|
|
Server,
|
|
|
|
[], [Server]),
|
|
|
|
send_element(StateData, exmpp_stream:features(Features)),
|
2005-11-03 06:04:54 +01:00
|
|
|
{next_state, stream_established, StateData};
|
2010-05-10 08:00:30 +02:00
|
|
|
{?NS_JABBER_SERVER, true, _Server, _} ->
|
2008-06-26 17:48:19 +02:00
|
|
|
Opening_Reply = exmpp_stream:opening_reply(Opening,
|
|
|
|
StateData#state.streamid),
|
|
|
|
send_element(StateData,
|
|
|
|
exmpp_stream:set_dialback_support(Opening_Reply)),
|
2005-10-25 03:08:37 +02:00
|
|
|
{next_state, stream_established, StateData};
|
2002-12-06 21:59:19 +01:00
|
|
|
_ ->
|
2008-06-26 17:48:19 +02:00
|
|
|
send_element(StateData, exmpp_stream:error('invalid-namespace')),
|
2002-12-06 21:59:19 +01:00
|
|
|
{stop, normal, StateData}
|
|
|
|
end;
|
|
|
|
|
2003-05-12 20:36:13 +02:00
|
|
|
wait_for_stream({xmlstreamerror, _}, StateData) ->
|
2008-06-26 17:48:19 +02:00
|
|
|
Opening_Reply = exmpp_stream:opening_reply(undefined, ?NS_JABBER_SERVER,
|
|
|
|
"", StateData#state.streamid),
|
|
|
|
send_element(StateData, Opening_Reply),
|
|
|
|
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
|
|
|
send_element(StateData, exmpp_stream:closing()),
|
2003-05-12 20:36:13 +02:00
|
|
|
{stop, normal, StateData};
|
|
|
|
|
|
|
|
wait_for_stream(timeout, StateData) ->
|
|
|
|
{stop, normal, StateData};
|
|
|
|
|
2002-12-06 21:59:19 +01:00
|
|
|
wait_for_stream(closed, StateData) ->
|
|
|
|
{stop, normal, StateData}.
|
|
|
|
|
2005-10-25 03:08:37 +02:00
|
|
|
|
|
|
|
wait_for_feature_request({xmlstreamelement, El}, StateData) ->
|
|
|
|
TLS = StateData#state.tls,
|
|
|
|
TLSEnabled = StateData#state.tls_enabled,
|
2006-10-01 03:53:37 +02:00
|
|
|
SockMod = (StateData#state.sockmod):get_sockmod(StateData#state.socket),
|
2008-06-26 17:48:19 +02:00
|
|
|
case El of
|
|
|
|
#xmlel{ns = ?NS_TLS, name = 'starttls'} when TLS == true,
|
2005-10-25 03:08:37 +02:00
|
|
|
TLSEnabled == false,
|
|
|
|
SockMod == gen_tcp ->
|
2007-09-14 16:16:04 +02:00
|
|
|
?DEBUG("starttls", []),
|
2005-10-25 03:08:37 +02:00
|
|
|
Socket = StateData#state.socket,
|
2008-06-30 17:51:23 +02:00
|
|
|
Proceed = exmpp_xml:node_to_list(
|
2008-06-27 15:46:08 +02:00
|
|
|
exmpp_server_tls:proceed(), [?DEFAULT_NS], ?PREFIXED_NS),
|
2005-10-25 03:08:37 +02:00
|
|
|
TLSOpts = StateData#state.tls_options,
|
2006-10-01 03:53:37 +02:00
|
|
|
TLSSocket = (StateData#state.sockmod):starttls(
|
|
|
|
Socket, TLSOpts,
|
2008-06-26 17:48:19 +02:00
|
|
|
Proceed),
|
2005-10-25 03:08:37 +02:00
|
|
|
{next_state, wait_for_stream,
|
2006-09-05 06:26:28 +02:00
|
|
|
StateData#state{socket = TLSSocket,
|
2005-10-25 03:08:37 +02:00
|
|
|
streamid = new_id(),
|
|
|
|
tls_enabled = true
|
|
|
|
}};
|
2008-06-26 17:48:19 +02:00
|
|
|
#xmlel{ns = ?NS_SASL, name = 'auth'} when TLSEnabled ->
|
|
|
|
case exmpp_server_sasl:next_step(El) of
|
|
|
|
{auth, "EXTERNAL", Auth} ->
|
2008-10-10 16:33:16 +02:00
|
|
|
{AuthDomain, AuthRes} = try
|
|
|
|
AuthDomain0 = exmpp_stringprep:nameprep(Auth),
|
|
|
|
AuthRes0 = case (StateData#state.sockmod):get_peer_certificate(
|
2006-09-05 06:36:01 +02:00
|
|
|
StateData#state.socket) of
|
2005-11-03 06:04:54 +01:00
|
|
|
{ok, Cert} ->
|
2006-10-01 03:53:37 +02:00
|
|
|
case (StateData#state.sockmod):get_verify_result(
|
2005-11-03 06:04:54 +01:00
|
|
|
StateData#state.socket) of
|
|
|
|
0 ->
|
2008-10-10 16:33:16 +02:00
|
|
|
case idna:domain_utf8_to_ascii(AuthDomain0) of
|
|
|
|
false ->
|
2005-11-03 06:04:54 +01:00
|
|
|
false;
|
2008-10-10 16:33:16 +02:00
|
|
|
PCAuthDomain ->
|
|
|
|
lists:any(
|
|
|
|
fun(D) ->
|
|
|
|
match_domain(
|
|
|
|
PCAuthDomain, D)
|
|
|
|
end, get_cert_domains(Cert))
|
2005-11-03 06:04:54 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end;
|
|
|
|
error ->
|
2008-10-10 16:33:16 +02:00
|
|
|
{undefined, false}
|
2005-11-03 06:04:54 +01:00
|
|
|
end,
|
2008-10-10 16:33:16 +02:00
|
|
|
{AuthDomain0, AuthRes0}
|
|
|
|
catch
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end,
|
2005-11-03 06:04:54 +01:00
|
|
|
if
|
|
|
|
AuthRes ->
|
2006-10-01 03:53:37 +02:00
|
|
|
(StateData#state.sockmod):reset_stream(
|
2006-09-05 06:26:28 +02:00
|
|
|
StateData#state.socket),
|
2005-11-03 06:04:54 +01:00
|
|
|
send_element(StateData,
|
2008-06-26 17:48:19 +02:00
|
|
|
exmpp_server_sasl:success()),
|
2007-09-14 16:16:04 +02:00
|
|
|
?DEBUG("(~w) Accepted s2s authentication for ~s",
|
2005-11-03 06:04:54 +01:00
|
|
|
[StateData#state.socket, AuthDomain]),
|
|
|
|
{next_state, wait_for_stream,
|
|
|
|
StateData#state{streamid = new_id(),
|
|
|
|
authenticated = true,
|
|
|
|
auth_domain = AuthDomain
|
|
|
|
}};
|
|
|
|
true ->
|
|
|
|
send_element(StateData,
|
2008-06-26 17:48:19 +02:00
|
|
|
exmpp_server_sasl:failure()),
|
|
|
|
send_element(StateData,
|
|
|
|
exmpp_stream:closing()),
|
2005-11-03 06:04:54 +01:00
|
|
|
{stop, normal, StateData}
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
send_element(StateData,
|
2008-06-26 17:48:19 +02:00
|
|
|
exmpp_server_sasl:failure('invalid-mechanism')),
|
2005-11-03 06:04:54 +01:00
|
|
|
{stop, normal, StateData}
|
|
|
|
end;
|
2005-10-25 03:08:37 +02:00
|
|
|
_ ->
|
|
|
|
stream_established({xmlstreamelement, El}, StateData)
|
|
|
|
end;
|
|
|
|
|
|
|
|
wait_for_feature_request({xmlstreamend, _Name}, StateData) ->
|
2008-06-26 17:48:19 +02:00
|
|
|
send_element(StateData, exmpp_stream:closing()),
|
2005-10-25 03:08:37 +02:00
|
|
|
{stop, normal, StateData};
|
|
|
|
|
|
|
|
wait_for_feature_request({xmlstreamerror, _}, StateData) ->
|
2008-06-26 17:48:19 +02:00
|
|
|
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
|
|
|
send_element(StateData, exmpp_stream:closing()),
|
2005-10-25 03:08:37 +02:00
|
|
|
{stop, normal, StateData};
|
|
|
|
|
|
|
|
wait_for_feature_request(closed, StateData) ->
|
|
|
|
{stop, normal, StateData}.
|
|
|
|
|
|
|
|
|
2003-10-29 21:09:09 +01:00
|
|
|
stream_established({xmlstreamelement, El}, StateData) ->
|
2003-12-06 20:58:49 +01:00
|
|
|
cancel_timer(StateData#state.timer),
|
|
|
|
Timer = erlang:start_timer(?S2STIMEOUT, self(), []),
|
2002-12-06 21:59:19 +01:00
|
|
|
case is_key_packet(El) of
|
|
|
|
{key, To, From, Id, Key} ->
|
2007-09-14 16:16:04 +02:00
|
|
|
?DEBUG("GET KEY: ~p", [{To, From, Id, Key}]),
|
2008-06-26 17:48:19 +02:00
|
|
|
LTo = exmpp_stringprep:nameprep(To),
|
|
|
|
LFrom = exmpp_stringprep:nameprep(From),
|
2007-09-14 16:15:44 +02:00
|
|
|
%% Checks if the from domain is allowed and if the to
|
|
|
|
%% domain is handled by this server:
|
2007-07-19 23:17:13 +02:00
|
|
|
case {ejabberd_s2s:allow_host(To, From),
|
|
|
|
lists:member(LTo, ejabberd_router:dirty_get_all_domains())} of
|
|
|
|
{true, true} ->
|
2008-04-18 14:19:45 +02:00
|
|
|
ejabberd_s2s_out:terminate_if_waiting_delay(To, From),
|
2003-07-20 22:35:35 +02:00
|
|
|
ejabberd_s2s_out:start(To, From,
|
2003-09-03 19:49:42 +02:00
|
|
|
{verify, self(),
|
|
|
|
Key, StateData#state.streamid}),
|
2003-10-29 21:09:09 +01:00
|
|
|
Conns = ?DICT:store({LFrom, LTo}, wait_for_verification,
|
|
|
|
StateData#state.connections),
|
2008-06-26 17:48:19 +02:00
|
|
|
change_shaper(StateData, LTo,
|
2009-06-01 18:26:00 +02:00
|
|
|
exmpp_jid:make(LFrom)),
|
2003-03-27 16:28:47 +01:00
|
|
|
{next_state,
|
2003-10-29 21:09:09 +01:00
|
|
|
stream_established,
|
2003-12-06 20:58:49 +01:00
|
|
|
StateData#state{connections = Conns,
|
|
|
|
timer = Timer}};
|
2007-07-19 23:17:13 +02:00
|
|
|
{_, false} ->
|
2008-06-26 17:48:19 +02:00
|
|
|
send_element(StateData, exmpp_stream:error('host-unknown')),
|
2007-07-19 23:17:13 +02:00
|
|
|
{stop, normal, StateData};
|
|
|
|
{false, _} ->
|
2008-06-26 17:48:19 +02:00
|
|
|
send_element(StateData, exmpp_stream:error('invalid-from')),
|
2007-07-19 23:17:13 +02:00
|
|
|
{stop, normal, StateData}
|
2003-03-27 16:28:47 +01:00
|
|
|
end;
|
2002-12-06 21:59:19 +01:00
|
|
|
{verify, To, From, Id, Key} ->
|
2007-09-14 16:16:04 +02:00
|
|
|
?DEBUG("VERIFY KEY: ~p", [{To, From, Id, Key}]),
|
2008-06-26 17:48:19 +02:00
|
|
|
LTo = exmpp_stringprep:nameprep(To),
|
|
|
|
LFrom = exmpp_stringprep:nameprep(From),
|
|
|
|
send_element(StateData, exmpp_dialback:verify_response(
|
|
|
|
El, ejabberd_s2s:has_key({LTo, LFrom}, Key))),
|
2003-12-06 20:58:49 +01:00
|
|
|
{next_state, stream_established, StateData#state{timer = Timer}};
|
2002-12-06 21:59:19 +01:00
|
|
|
_ ->
|
2008-06-26 17:48:19 +02:00
|
|
|
From = case exmpp_stanza:get_sender(El) of
|
|
|
|
undefined ->
|
|
|
|
error;
|
|
|
|
F ->
|
|
|
|
try
|
2009-06-01 18:35:55 +02:00
|
|
|
exmpp_jid:parse(F)
|
2008-06-26 17:48:19 +02:00
|
|
|
catch
|
|
|
|
_Exception1 -> error
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
To = case exmpp_stanza:get_recipient(El) of
|
|
|
|
undefined ->
|
|
|
|
error;
|
|
|
|
T ->
|
|
|
|
try
|
2009-06-01 18:35:55 +02:00
|
|
|
exmpp_jid:parse(T)
|
2008-06-26 17:48:19 +02:00
|
|
|
catch
|
|
|
|
_Exception2 -> error
|
|
|
|
end
|
|
|
|
end,
|
2008-08-26 15:38:49 +02:00
|
|
|
% No namespace conversion (:server <-> :client) is done.
|
2008-06-26 17:48:19 +02:00
|
|
|
% This is handled by C2S and S2S send_element functions.
|
2003-10-29 21:09:09 +01:00
|
|
|
if
|
|
|
|
(To /= error) and (From /= error) ->
|
2009-06-01 18:38:28 +02:00
|
|
|
LFrom = exmpp_jid:prep_domain_as_list(From),
|
|
|
|
LTo = exmpp_jid:prep_domain_as_list(To),
|
2005-11-03 06:04:54 +01:00
|
|
|
if
|
|
|
|
StateData#state.authenticated ->
|
|
|
|
case (LFrom == StateData#state.auth_domain)
|
|
|
|
andalso
|
|
|
|
lists:member(
|
|
|
|
LTo,
|
|
|
|
ejabberd_router:dirty_get_all_domains()) of
|
|
|
|
true ->
|
2008-06-26 17:48:19 +02:00
|
|
|
Name = El#xmlel.name,
|
|
|
|
if ((Name == 'iq') or
|
|
|
|
(Name == 'message') or
|
|
|
|
(Name == 'presence')) ->
|
2008-05-22 12:53:49 +02:00
|
|
|
ejabberd_hooks:run(
|
|
|
|
s2s_receive_packet,
|
2009-09-04 23:33:30 +02:00
|
|
|
exmpp_jid:prep_domain(To),
|
2008-08-26 15:38:49 +02:00
|
|
|
[From, To, El]),
|
2006-01-25 01:35:12 +01:00
|
|
|
ejabberd_router:route(
|
2008-06-30 18:55:03 +02:00
|
|
|
From, To, El);
|
2005-11-03 06:04:54 +01:00
|
|
|
true ->
|
|
|
|
error
|
|
|
|
end;
|
|
|
|
false ->
|
2003-10-29 21:09:09 +01:00
|
|
|
error
|
|
|
|
end;
|
2005-11-03 06:04:54 +01:00
|
|
|
true ->
|
|
|
|
case ?DICT:find({LFrom, LTo},
|
|
|
|
StateData#state.connections) of
|
|
|
|
{ok, established} ->
|
2008-06-26 17:48:19 +02:00
|
|
|
Name = El#xmlel.name,
|
|
|
|
if ((Name == 'iq') or
|
|
|
|
(Name == 'message') or
|
|
|
|
(Name == 'presence')) ->
|
2008-05-22 12:53:49 +02:00
|
|
|
ejabberd_hooks:run(
|
|
|
|
s2s_receive_packet,
|
2009-09-04 23:33:30 +02:00
|
|
|
exmpp_jid:prep_domain(To),
|
2008-08-26 15:38:49 +02:00
|
|
|
[From, To, El]),
|
2006-01-25 01:35:12 +01:00
|
|
|
ejabberd_router:route(
|
2008-06-30 18:55:03 +02:00
|
|
|
From, To, El);
|
2005-11-03 06:04:54 +01:00
|
|
|
true ->
|
|
|
|
error
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
error
|
|
|
|
end
|
2003-10-29 21:09:09 +01:00
|
|
|
end;
|
|
|
|
true ->
|
|
|
|
error
|
2003-12-06 20:58:49 +01:00
|
|
|
end,
|
2008-08-26 15:38:49 +02:00
|
|
|
ejabberd_hooks:run(s2s_loop_debug, [{xmlstreamelement, El}]),
|
2003-12-06 20:58:49 +01:00
|
|
|
{next_state, stream_established, StateData#state{timer = Timer}}
|
|
|
|
end;
|
2002-12-06 21:59:19 +01:00
|
|
|
|
2003-10-29 21:09:09 +01:00
|
|
|
stream_established({valid, From, To}, StateData) ->
|
2008-06-26 17:48:19 +02:00
|
|
|
send_element(StateData, exmpp_dialback:validate(From, To)),
|
|
|
|
LFrom = exmpp_stringprep:nameprep(From),
|
|
|
|
LTo = exmpp_stringprep:nameprep(To),
|
2003-10-29 21:09:09 +01:00
|
|
|
NSD = StateData#state{
|
|
|
|
connections = ?DICT:store({LFrom, LTo}, established,
|
|
|
|
StateData#state.connections)},
|
2003-12-06 20:58:49 +01:00
|
|
|
{next_state, stream_established, NSD};
|
2003-10-29 21:09:09 +01:00
|
|
|
|
|
|
|
stream_established({invalid, From, To}, StateData) ->
|
2008-06-26 17:48:19 +02:00
|
|
|
Valid = exmpp_dialback:validate(From, To),
|
|
|
|
send_element(StateData, exmpp_stanza:set_type(Valid, "invalid")),
|
|
|
|
LFrom = exmpp_stringprep:nameprep(From),
|
|
|
|
LTo = exmpp_stringprep:nameprep(To),
|
2003-10-29 21:09:09 +01:00
|
|
|
NSD = StateData#state{
|
2003-12-06 20:58:49 +01:00
|
|
|
connections = ?DICT:erase({LFrom, LTo},
|
2003-10-29 21:09:09 +01:00
|
|
|
StateData#state.connections)},
|
2003-12-06 20:58:49 +01:00
|
|
|
{next_state, stream_established, NSD};
|
2003-10-29 21:09:09 +01:00
|
|
|
|
|
|
|
stream_established({xmlstreamend, _Name}, StateData) ->
|
2003-05-12 20:36:13 +02:00
|
|
|
{stop, normal, StateData};
|
|
|
|
|
|
|
|
stream_established({xmlstreamerror, _}, StateData) ->
|
2008-06-26 17:48:19 +02:00
|
|
|
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
|
|
|
send_element(StateData, exmpp_stream:closing()),
|
2002-12-07 21:27:26 +01:00
|
|
|
{stop, normal, StateData};
|
2002-12-06 21:59:19 +01:00
|
|
|
|
2003-01-26 21:16:53 +01:00
|
|
|
stream_established(timeout, StateData) ->
|
|
|
|
{stop, normal, StateData};
|
|
|
|
|
2002-12-07 21:27:26 +01:00
|
|
|
stream_established(closed, StateData) ->
|
2002-12-06 21:59:19 +01:00
|
|
|
{stop, normal, StateData}.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: StateName/3
|
|
|
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
|
|
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
|
|
|
%% {reply, Reply, NextStateName, NextStateData} |
|
|
|
|
%% {reply, Reply, NextStateName, NextStateData, Timeout} |
|
|
|
|
%% {stop, Reason, NewStateData} |
|
2007-09-14 16:15:44 +02:00
|
|
|
%% {stop, Reason, Reply, NewStateData}
|
2002-12-06 21:59:19 +01:00
|
|
|
%%----------------------------------------------------------------------
|
2003-01-24 21:18:33 +01:00
|
|
|
%state_name(Event, From, StateData) ->
|
|
|
|
% Reply = ok,
|
|
|
|
% {reply, Reply, state_name, StateData}.
|
2002-12-06 21:59:19 +01:00
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: handle_event/3
|
|
|
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
|
|
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
2007-09-14 16:15:44 +02:00
|
|
|
%% {stop, Reason, NewStateData}
|
2002-12-06 21:59:19 +01:00
|
|
|
%%----------------------------------------------------------------------
|
2003-10-29 21:09:09 +01:00
|
|
|
handle_event(_Event, StateName, StateData) ->
|
2003-12-06 20:58:49 +01:00
|
|
|
{next_state, StateName, StateData}.
|
2009-05-19 11:39:13 +02:00
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: handle_sync_event/4
|
|
|
|
%% Returns: The associated StateData for this connection
|
|
|
|
%% {reply, Reply, NextStateName, NextStateData}
|
|
|
|
%% Reply = {state_infos, [{InfoName::atom(), InfoValue::any()]
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
handle_sync_event(get_state_infos, _From, StateName, StateData) ->
|
|
|
|
SockMod = StateData#state.sockmod,
|
|
|
|
{Addr,Port} = try SockMod:peername(StateData#state.socket) of
|
|
|
|
{ok, {A,P}} -> {A,P};
|
|
|
|
{error, _} -> {unknown,unknown}
|
|
|
|
catch
|
|
|
|
_:_ -> {unknown,unknown}
|
|
|
|
end,
|
2009-08-15 23:39:41 +02:00
|
|
|
Domains = case StateData#state.authenticated of
|
|
|
|
true ->
|
|
|
|
[StateData#state.auth_domain];
|
|
|
|
false ->
|
|
|
|
Connections = StateData#state.connections,
|
|
|
|
[D || {{D, _}, established} <-
|
|
|
|
dict:to_list(Connections)]
|
|
|
|
end,
|
2009-05-19 11:39:13 +02:00
|
|
|
Infos = [
|
|
|
|
{direction, in},
|
|
|
|
{statename, StateName},
|
|
|
|
{addr, Addr},
|
|
|
|
{port, Port},
|
|
|
|
{streamid, StateData#state.streamid},
|
|
|
|
{tls, StateData#state.tls},
|
|
|
|
{tls_enabled, StateData#state.tls_enabled},
|
|
|
|
{tls_options, StateData#state.tls_options},
|
|
|
|
{authenticated, StateData#state.authenticated},
|
|
|
|
{shaper, StateData#state.shaper},
|
2009-08-15 23:39:41 +02:00
|
|
|
{sockmod, SockMod},
|
|
|
|
{domains, Domains}
|
2009-05-19 11:39:13 +02:00
|
|
|
],
|
|
|
|
Reply = {state_infos, Infos},
|
|
|
|
{reply,Reply,StateName,StateData};
|
2002-12-06 21:59:19 +01:00
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: handle_sync_event/4
|
|
|
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
|
|
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
|
|
|
%% {reply, Reply, NextStateName, NextStateData} |
|
|
|
|
%% {reply, Reply, NextStateName, NextStateData, Timeout} |
|
|
|
|
%% {stop, Reason, NewStateData} |
|
2007-09-14 16:15:44 +02:00
|
|
|
%% {stop, Reason, Reply, NewStateData}
|
2002-12-06 21:59:19 +01:00
|
|
|
%%----------------------------------------------------------------------
|
2003-10-29 21:09:09 +01:00
|
|
|
handle_sync_event(_Event, _From, StateName, StateData) ->
|
2002-12-06 21:59:19 +01:00
|
|
|
Reply = ok,
|
|
|
|
{reply, Reply, StateName, StateData}.
|
|
|
|
|
2003-10-29 21:09:09 +01:00
|
|
|
code_change(_OldVsn, StateName, StateData, _Extra) ->
|
2003-01-24 21:18:33 +01:00
|
|
|
{ok, StateName, StateData}.
|
|
|
|
|
2002-12-06 21:59:19 +01:00
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: handle_info/3
|
|
|
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
|
|
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
2007-09-14 16:15:44 +02:00
|
|
|
%% {stop, Reason, NewStateData}
|
2002-12-06 21:59:19 +01:00
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
handle_info({send_text, Text}, StateName, StateData) ->
|
2005-10-25 03:08:37 +02:00
|
|
|
send_text(StateData, Text),
|
2002-12-07 21:27:26 +01:00
|
|
|
{next_state, StateName, StateData};
|
2003-12-06 20:58:49 +01:00
|
|
|
|
2005-11-03 06:04:54 +01:00
|
|
|
handle_info({timeout, Timer, _}, _StateName,
|
2003-12-06 20:58:49 +01:00
|
|
|
#state{timer = Timer} = StateData) ->
|
|
|
|
{stop, normal, StateData};
|
|
|
|
|
2003-10-29 21:09:09 +01:00
|
|
|
handle_info(_, StateName, StateData) ->
|
|
|
|
{next_state, StateName, StateData}.
|
2002-12-07 21:27:26 +01:00
|
|
|
|
2002-12-06 21:59:19 +01:00
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: terminate/3
|
|
|
|
%% Purpose: Shutdown the fsm
|
|
|
|
%% Returns: any
|
|
|
|
%%----------------------------------------------------------------------
|
2003-10-29 21:09:09 +01:00
|
|
|
terminate(Reason, _StateName, StateData) ->
|
2007-09-14 16:16:04 +02:00
|
|
|
?DEBUG("terminated: ~p", [Reason]),
|
2006-10-01 03:53:37 +02:00
|
|
|
(StateData#state.sockmod):close(StateData#state.socket),
|
2002-12-06 21:59:19 +01:00
|
|
|
ok.
|
|
|
|
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% Internal functions
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
2005-10-25 03:08:37 +02:00
|
|
|
send_text(StateData, Text) ->
|
2006-10-01 03:53:37 +02:00
|
|
|
(StateData#state.sockmod):send(StateData#state.socket, Text).
|
2002-12-06 21:59:19 +01:00
|
|
|
|
2008-06-26 17:48:19 +02:00
|
|
|
|
|
|
|
send_element(StateData, #xmlel{ns = ?NS_XMPP, name = 'stream'} = El) ->
|
2009-03-02 16:48:01 +01:00
|
|
|
send_text(StateData, exmpp_stream:to_iolist(El));
|
2005-10-25 03:08:37 +02:00
|
|
|
send_element(StateData, El) ->
|
2009-03-02 16:48:01 +01:00
|
|
|
send_text(StateData, exmpp_stanza:to_iolist(El)).
|
2002-12-06 21:59:19 +01:00
|
|
|
|
2002-12-07 21:27:26 +01:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
change_shaper(StateData, Host, JID) ->
|
2008-07-01 11:41:32 +02:00
|
|
|
Shaper = acl:match_rule(Host, StateData#state.shaper, JID),
|
2006-10-01 03:53:37 +02:00
|
|
|
(StateData#state.sockmod):change_shaper(StateData#state.socket, Shaper).
|
2003-11-10 22:25:36 +01:00
|
|
|
|
2002-12-07 21:27:26 +01:00
|
|
|
|
2002-12-06 21:59:19 +01:00
|
|
|
new_id() ->
|
2002-12-13 21:58:27 +01:00
|
|
|
randoms:get_string().
|
2002-12-06 21:59:19 +01:00
|
|
|
|
2003-12-06 20:58:49 +01:00
|
|
|
cancel_timer(Timer) ->
|
|
|
|
erlang:cancel_timer(Timer),
|
|
|
|
receive
|
|
|
|
{timeout, Timer, _} ->
|
|
|
|
ok
|
|
|
|
after 0 ->
|
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
2002-12-06 21:59:19 +01:00
|
|
|
|
2008-06-27 15:46:08 +02:00
|
|
|
is_key_packet(#xmlel{ns = ?NS_DIALBACK, name = 'result',
|
2008-06-26 17:48:19 +02:00
|
|
|
attrs = Attrs} = El) ->
|
2002-12-06 21:59:19 +01:00
|
|
|
{key,
|
2009-01-21 14:34:26 +01:00
|
|
|
binary_to_list(exmpp_stanza:get_recipient_from_attrs(Attrs)),
|
|
|
|
binary_to_list(exmpp_stanza:get_sender_from_attrs(Attrs)),
|
2008-06-26 17:48:19 +02:00
|
|
|
exmpp_stanza:get_id_from_attrs(Attrs),
|
|
|
|
exmpp_xml:get_cdata_as_list(El)};
|
2008-06-27 15:46:08 +02:00
|
|
|
is_key_packet(#xmlel{ns = ?NS_DIALBACK, name = 'verify',
|
2008-06-26 17:48:19 +02:00
|
|
|
attrs = Attrs} = El) ->
|
2002-12-06 21:59:19 +01:00
|
|
|
{verify,
|
2009-01-21 14:34:26 +01:00
|
|
|
binary_to_list(exmpp_stanza:get_recipient_from_attrs(Attrs)),
|
|
|
|
binary_to_list(exmpp_stanza:get_sender_from_attrs(Attrs)),
|
2008-06-26 17:48:19 +02:00
|
|
|
exmpp_stanza:get_id_from_attrs(Attrs),
|
|
|
|
exmpp_xml:get_cdata_as_list(El)};
|
2002-12-06 21:59:19 +01:00
|
|
|
is_key_packet(_) ->
|
|
|
|
false.
|
|
|
|
|
|
|
|
|
2005-11-03 06:04:54 +01:00
|
|
|
get_cert_domains(Cert) ->
|
|
|
|
{rdnSequence, Subject} =
|
|
|
|
(Cert#'Certificate'.tbsCertificate)#'TBSCertificate'.subject,
|
2005-11-05 22:15:53 +01:00
|
|
|
Extensions =
|
|
|
|
(Cert#'Certificate'.tbsCertificate)#'TBSCertificate'.extensions,
|
2005-11-03 06:04:54 +01:00
|
|
|
lists:flatmap(
|
|
|
|
fun(#'AttributeTypeAndValue'{type = ?'id-at-commonName',
|
|
|
|
value = Val}) ->
|
2008-03-11 15:25:35 +01:00
|
|
|
case ?PKIXEXPLICIT:decode('X520CommonName', Val) of
|
2005-11-03 06:04:54 +01:00
|
|
|
{ok, {_, D1}} ->
|
|
|
|
D = if
|
|
|
|
is_list(D1) -> D1;
|
|
|
|
is_binary(D1) -> binary_to_list(D1);
|
|
|
|
true -> error
|
|
|
|
end,
|
|
|
|
if
|
|
|
|
D /= error ->
|
2009-06-01 18:35:55 +02:00
|
|
|
JID = exmpp_jid:parse(D),
|
2009-06-01 18:40:51 +02:00
|
|
|
case {exmpp_jid:prep_node_as_list(JID),
|
2009-06-01 18:38:28 +02:00
|
|
|
exmpp_jid:prep_domain_as_list(JID),
|
2009-06-01 18:43:15 +02:00
|
|
|
exmpp_jid:prep_resource_as_list(JID)} of
|
2009-01-03 16:15:38 +01:00
|
|
|
{undefined, LD, undefined} ->
|
2005-11-05 22:15:53 +01:00
|
|
|
[LD];
|
|
|
|
_ ->
|
|
|
|
[]
|
2005-11-03 06:04:54 +01:00
|
|
|
end;
|
|
|
|
true ->
|
|
|
|
[]
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end;
|
|
|
|
(_) ->
|
|
|
|
[]
|
2005-11-05 22:15:53 +01:00
|
|
|
end, lists:flatten(Subject)) ++
|
|
|
|
lists:flatmap(
|
|
|
|
fun(#'Extension'{extnID = ?'id-ce-subjectAltName',
|
|
|
|
extnValue = Val}) ->
|
|
|
|
BVal = if
|
|
|
|
is_list(Val) -> list_to_binary(Val);
|
|
|
|
is_binary(Val) -> Val;
|
|
|
|
true -> Val
|
|
|
|
end,
|
2008-03-11 15:25:35 +01:00
|
|
|
case ?PKIXIMPLICIT:decode('SubjectAltName', BVal) of
|
2005-11-05 22:15:53 +01:00
|
|
|
{ok, SANs} ->
|
|
|
|
lists:flatmap(
|
|
|
|
fun({otherName,
|
|
|
|
#'AnotherName'{'type-id' = ?'id-on-xmppAddr',
|
|
|
|
value = XmppAddr
|
|
|
|
}}) ->
|
|
|
|
case 'XmppAddr':decode(
|
|
|
|
'XmppAddr', XmppAddr) of
|
|
|
|
{ok, D} when is_binary(D) ->
|
2009-06-01 18:35:55 +02:00
|
|
|
JID2 = exmpp_jid:parse(binary_to_list(D)),
|
2009-06-01 18:40:51 +02:00
|
|
|
case {exmpp_jid:prep_node_as_list(JID2),
|
2009-06-01 18:38:28 +02:00
|
|
|
exmpp_jid:prep_domain_as_list(JID2),
|
2009-06-01 18:43:15 +02:00
|
|
|
exmpp_jid:prep_resource_as_list(JID2)} of
|
2009-01-03 16:15:38 +01:00
|
|
|
{ undefined, LD, undefined} ->
|
2005-11-17 06:29:33 +01:00
|
|
|
case idna:domain_utf8_to_ascii(LD) of
|
|
|
|
false ->
|
|
|
|
[];
|
|
|
|
PCLD ->
|
|
|
|
[PCLD]
|
|
|
|
end;
|
2005-11-05 22:15:53 +01:00
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end;
|
2005-11-17 06:29:33 +01:00
|
|
|
({dNSName, D}) when is_list(D) ->
|
2009-06-01 18:35:55 +02:00
|
|
|
JID3 = exmpp_jid:parse(D),
|
2009-06-01 18:40:51 +02:00
|
|
|
case {exmpp_jid:prep_node_as_list(JID3),
|
2009-06-01 18:38:28 +02:00
|
|
|
exmpp_jid:prep_domain_as_list(JID3),
|
2009-06-01 18:43:15 +02:00
|
|
|
exmpp_jid:prep_resource_as_list(JID3)} of
|
2009-01-03 16:15:38 +01:00
|
|
|
{undefined, LD, undefined} ->
|
2005-11-17 06:29:33 +01:00
|
|
|
[LD];
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end;
|
2005-11-05 22:15:53 +01:00
|
|
|
(_) ->
|
|
|
|
[]
|
|
|
|
end, SANs);
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end;
|
|
|
|
(_) ->
|
|
|
|
[]
|
|
|
|
end, Extensions).
|
2005-11-03 06:04:54 +01:00
|
|
|
|
2005-11-17 06:29:33 +01:00
|
|
|
match_domain(Domain, Domain) ->
|
|
|
|
true;
|
|
|
|
match_domain(Domain, Pattern) ->
|
|
|
|
DLabels = string:tokens(Domain, "."),
|
|
|
|
PLabels = string:tokens(Pattern, "."),
|
|
|
|
match_labels(DLabels, PLabels).
|
|
|
|
|
|
|
|
match_labels([], []) ->
|
|
|
|
true;
|
|
|
|
match_labels([], [_ | _]) ->
|
|
|
|
false;
|
|
|
|
match_labels([_ | _], []) ->
|
|
|
|
false;
|
|
|
|
match_labels([DL | DLabels], [PL | PLabels]) ->
|
|
|
|
case lists:all(fun(C) -> (($a =< C) andalso (C =< $z))
|
|
|
|
orelse (($0 =< C) andalso (C =< $9))
|
|
|
|
orelse (C == $-) orelse (C == $*)
|
|
|
|
end, PL) of
|
|
|
|
true ->
|
2009-09-02 16:26:01 +02:00
|
|
|
Regexp = xmerl_regexp:sh_to_awk(PL),
|
|
|
|
case re:run(DL, Regexp, [{capture, none}]) of
|
|
|
|
match ->
|
2005-11-17 06:29:33 +01:00
|
|
|
match_labels(DLabels, PLabels);
|
2009-09-02 16:26:01 +02:00
|
|
|
nomatch ->
|
2005-11-17 06:29:33 +01:00
|
|
|
false
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
false
|
|
|
|
end.
|