diff --git a/apps/emqx_psk_file/.gitignore b/apps/emqx_psk_file/.gitignore deleted file mode 100644 index 0379a99df..000000000 --- a/apps/emqx_psk_file/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -.eunit -deps -*.o -*.beam -*.plt -erl_crash.dump -ebin -rel/example_project -.concrete/DEV_MODE -.rebar -.erlang.mk/ -data/ -emqx_actorcloud_schema_parser.d -.DS_Store -_build -rebar.lock diff --git a/apps/emqx_psk_file/README.md b/apps/emqx_psk_file/README.md deleted file mode 100644 index 3ba976b81..000000000 --- a/apps/emqx_psk_file/README.md +++ /dev/null @@ -1,2 +0,0 @@ -## EMQX TLS/DTLS PSK Plugin from file - diff --git a/apps/emqx_psk_file/etc/emqx_psk_file.conf b/apps/emqx_psk_file/etc/emqx_psk_file.conf deleted file mode 100644 index 88c5bbdb1..000000000 --- a/apps/emqx_psk_file/etc/emqx_psk_file.conf +++ /dev/null @@ -1,2 +0,0 @@ -psk.file.path = "{{ platform_etc_dir }}/psk.txt" -psk.file.delimiter = ":" diff --git a/apps/emqx_psk_file/etc/psk.txt b/apps/emqx_psk_file/etc/psk.txt deleted file mode 100644 index 3cf33d814..000000000 --- a/apps/emqx_psk_file/etc/psk.txt +++ /dev/null @@ -1,2 +0,0 @@ -client1:1234 -client2:abcd diff --git a/apps/emqx_psk_file/priv/emqx_psk_file.schema b/apps/emqx_psk_file/priv/emqx_psk_file.schema deleted file mode 100644 index 0c784d99b..000000000 --- a/apps/emqx_psk_file/priv/emqx_psk_file.schema +++ /dev/null @@ -1,10 +0,0 @@ -%%-*- mode: erlang -*- -%% emqx_psk_file config mapping - -{mapping, "psk.file.path", "emqx_psk_file.path", [ - {datatype, string} -]}. - -{mapping, "psk.file.delimiter", "emqx_psk_file.delimiter", [ - {datatype, string} -]}. \ No newline at end of file diff --git a/apps/emqx_psk_file/rebar.config b/apps/emqx_psk_file/rebar.config deleted file mode 100644 index 7ac3b98c8..000000000 --- a/apps/emqx_psk_file/rebar.config +++ /dev/null @@ -1,16 +0,0 @@ -{deps, []}. - -{edoc_opts, [{preprocess, true}]}. -{erl_opts, [warn_unused_vars, - warn_shadow_vars, - warn_unused_import, - warn_obsolete_guard, - debug_info, - {parse_transform}]}. - -{xref_checks, [undefined_function_calls, undefined_functions, - locals_not_used, deprecated_function_calls, - warnings_as_errors, deprecated_functions]}. -{cover_enabled, true}. -{cover_opts, [verbose]}. -{cover_export_enabled, true}. diff --git a/apps/emqx_psk_file/src/emqx_psk_file.app.src b/apps/emqx_psk_file/src/emqx_psk_file.app.src deleted file mode 100644 index ef18c8b69..000000000 --- a/apps/emqx_psk_file/src/emqx_psk_file.app.src +++ /dev/null @@ -1,14 +0,0 @@ -{application, emqx_psk_file, - [{description,"EMQX PSK Plugin from File"}, - {vsn, "4.3.1"}, % strict semver, bump manually! - {modules,[]}, - {registered,[emqx_psk_file_sup]}, - {applications,[kernel,stdlib]}, - {mod,{emqx_psk_file_app,[]}}, - {env, []}, - {licenses, ["Apache-2.0"]}, - {maintainers, ["EMQ X Team "]}, - {links, [{"Homepage", "https://emqx.io/"}, - {"Github", "https://github.com/emqx/emqx-psk-file"} - ]} - ]}. diff --git a/apps/emqx_psk_file/src/emqx_psk_file.appup.src b/apps/emqx_psk_file/src/emqx_psk_file.appup.src deleted file mode 100644 index c34a3f71a..000000000 --- a/apps/emqx_psk_file/src/emqx_psk_file.appup.src +++ /dev/null @@ -1,13 +0,0 @@ -%% -*-: erlang -*- -{VSN, - [ - {"4.3.0", [ - {restart_application, emqx_psk_file} - ]} - ], - [ - {"4.3.0", [ - {restart_application, emqx_psk_file} - ]} - ] -}. diff --git a/apps/emqx_psk_file/src/emqx_psk_file.erl b/apps/emqx_psk_file/src/emqx_psk_file.erl deleted file mode 100644 index 3afd6dc73..000000000 --- a/apps/emqx_psk_file/src/emqx_psk_file.erl +++ /dev/null @@ -1,82 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%%-------------------------------------------------------------------- - --module(emqx_psk_file). - --include_lib("emqx/include/emqx.hrl"). --include_lib("emqx/include/logger.hrl"). - --import(proplists, [get_value/2]). - --export([load/1, unload/0]). - -%% Hooks functions --export([on_psk_lookup/2]). - --define(TAB, ?MODULE). --define(LF, 10). - --record(psk_entry, {psk_id :: binary(), - psk_str :: binary()}). - -%% Called when the plugin application start -load(Env) -> - _ = ets:new(?TAB, [set, named_table, {keypos, #psk_entry.psk_id}]), - {ok, PskFile} = file:open(get_value(path, Env), [read, raw, binary, read_ahead]), - preload_psks(PskFile, bin(get_value(delimiter, Env))), - _ = file:close(PskFile), - emqx:hook('tls_handshake.psk_lookup', {?MODULE, on_psk_lookup, []}). - -%% Called when the plugin application stop -unload() -> - emqx:unhook('tls_handshake.psk_lookup', {?MODULE, on_psk_lookup}). - -on_psk_lookup(ClientPSKID, UserState) -> - case ets:lookup(?TAB, ClientPSKID) of - [#psk_entry{psk_str = PskStr}] -> - {stop, PskStr}; - [] -> - {ok, UserState} - end. - -preload_psks(FileHandler, Delimiter) -> - case file:read_line(FileHandler) of - {ok, Line} -> - case binary:split(Line, Delimiter) of - [Key, Rem] -> - ets:insert(?TAB, #psk_entry{psk_id = Key, psk_str = trim_lf(Rem)}), - preload_psks(FileHandler, Delimiter); - [Line] -> - ?LOG(warning, "[~p] - Invalid line: ~p, delimiter: ~p", [?MODULE, Line, Delimiter]) - end; - eof -> - ?LOG(info, "[~p] - PSK file is preloaded", [?MODULE]); - {error, Reason} -> - ?LOG(error, "[~p] - Read lines from PSK file: ~p", [?MODULE, Reason]) - end. - -bin(Str) when is_list(Str) -> list_to_binary(Str); -bin(Bin) when is_binary(Bin) -> Bin. - -%% Trim the tailing LF -trim_lf(<<>>) -> <<>>; -trim_lf(Bin) -> - Size = byte_size(Bin), - case binary:at(Bin, Size-1) of - ?LF -> binary_part(Bin, 0, Size-1); - _ -> Bin - end. - diff --git a/apps/emqx_psk_file/src/emqx_psk_file_app.erl b/apps/emqx_psk_file/src/emqx_psk_file_app.erl deleted file mode 100644 index 934ffe49e..000000000 --- a/apps/emqx_psk_file/src/emqx_psk_file_app.erl +++ /dev/null @@ -1,33 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%%-------------------------------------------------------------------- - --module(emqx_psk_file_app). - --behaviour(application). - --emqx_plugin(?MODULE). - -%% Application callbacks --export([start/2, stop/1]). - -start(_StartType, _StartArgs) -> - {ok, Sup} = emqx_psk_file_sup:start_link(), - _ = emqx_psk_file:load( - application:get_all_env(emqx_psk_file)), - {ok, Sup}. - -stop(_State) -> - emqx_psk_file:unload(). diff --git a/apps/emqx_psk_file/src/emqx_psk_file_sup.erl b/apps/emqx_psk_file/src/emqx_psk_file_sup.erl deleted file mode 100644 index 041eecdb6..000000000 --- a/apps/emqx_psk_file/src/emqx_psk_file_sup.erl +++ /dev/null @@ -1,32 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%%-------------------------------------------------------------------- - --module(emqx_psk_file_sup). - --behaviour(supervisor). - -%% API --export([start_link/0]). - -%% Supervisor callbacks --export([init/1]). - -start_link() -> - supervisor:start_link({local, ?MODULE}, ?MODULE, []). - -init([]) -> - {ok, { {one_for_one, 0, 1}, []} }. - diff --git a/apps/emqx_psk_file/test/emqx_psk_file_SUITE.erl b/apps/emqx_psk_file/test/emqx_psk_file_SUITE.erl deleted file mode 100644 index d0083247d..000000000 --- a/apps/emqx_psk_file/test/emqx_psk_file_SUITE.erl +++ /dev/null @@ -1,24 +0,0 @@ -%%-------------------------------------------------------------------- -%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved. -%% -%% Licensed under the Apache License, Version 2.0 (the "License"); -%% you may not use this file except in compliance with the License. -%% You may obtain a copy of the License at -%% -%% http://www.apache.org/licenses/LICENSE-2.0 -%% -%% Unless required by applicable law or agreed to in writing, software -%% distributed under the License is distributed on an "AS IS" BASIS, -%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%% See the License for the specific language governing permissions and -%% limitations under the License. -%%-------------------------------------------------------------------- - --module(emqx_psk_file_SUITE). --compile(nowarn_export_all). --compile(export_all). - -all() -> []. - -groups() -> - []. diff --git a/rebar.config.erl b/rebar.config.erl index 5f00f87b2..14a8f93bc 100644 --- a/rebar.config.erl +++ b/rebar.config.erl @@ -297,7 +297,6 @@ relx_plugin_apps_per_rel(cloud) -> , emqx_exhook , emqx_exproto , emqx_prometheus - , emqx_psk_file ]; relx_plugin_apps_per_rel(edge) -> []. @@ -355,7 +354,6 @@ etc_overlay(ReleaseType) -> extra_overlay(cloud) -> [ {copy,"{{base_dir}}/lib/emqx_lwm2m/lwm2m_xml","etc/"} - , {copy, "{{base_dir}}/lib/emqx_psk_file/etc/psk.txt", "etc/psk.txt"} ]; extra_overlay(edge) -> []. diff --git a/scripts/inject-deps.escript b/scripts/inject-deps.escript index 0b6371342..8100c3959 100755 --- a/scripts/inject-deps.escript +++ b/scripts/inject-deps.escript @@ -44,7 +44,6 @@ edge_excludes() -> , emqx_exhook , emqx_exproto , emqx_prometheus - , emqx_psk_file ]. base_deps() ->