diff options
author | magnus <mfeuer@jaguarlandrover.com> | 2014-10-05 16:05:30 -0700 |
---|---|---|
committer | magnus <mfeuer@jaguarlandrover.com> | 2014-10-05 16:05:30 -0700 |
commit | a254dd792b7f39434689ad42995993ffb2dc7795 (patch) | |
tree | 78d586b21726042b9f50125dcfcc3660982aa482 /components/authorize/src | |
parent | 0bfa448b4200d3a8a0652bcd4c874cb428f4a354 (diff) | |
parent | 3c7daa5785b2f2b2669bb4d8102aa30681a6783c (diff) | |
download | rvi_core-a254dd792b7f39434689ad42995993ffb2dc7795.tar.gz |
Add 'components/authorize/' from commit '3c7daa5785b2f2b2669bb4d8102aa30681a6783c'
git-subtree-dir: components/authorize
git-subtree-mainline: 0bfa448b4200d3a8a0652bcd4c874cb428f4a354
git-subtree-split: 3c7daa5785b2f2b2669bb4d8102aa30681a6783c
Diffstat (limited to 'components/authorize/src')
-rw-r--r-- | components/authorize/src/authorize.app.src | 23 | ||||
-rw-r--r-- | components/authorize/src/authorize_app.erl | 32 | ||||
-rw-r--r-- | components/authorize/src/authorize_rpc.erl | 123 | ||||
-rw-r--r-- | components/authorize/src/authorize_sup.erl | 44 |
4 files changed, 222 insertions, 0 deletions
diff --git a/components/authorize/src/authorize.app.src b/components/authorize/src/authorize.app.src new file mode 100644 index 0000000..e11caf5 --- /dev/null +++ b/components/authorize/src/authorize.app.src @@ -0,0 +1,23 @@ +%% +%% Copyright (C) 2014, Jaguar Land Rover +%% +%% This program is licensed under the terms and conditions of the +%% Mozilla Public License, version 2.0. The full text of the +%% Mozilla Public License is at https://www.mozilla.org/MPL/2.0/ +%% + + +%% -*- erlang -*- +{application, authorize, + [ + {description, ""}, + {vsn, "0.1"}, + {registered, []}, + {applications, [ + kernel, + stdlib, + rvi_common + ]}, + {mod, { authorize_app, []}}, + {start_phases, [{init, []}]} + ]}. diff --git a/components/authorize/src/authorize_app.erl b/components/authorize/src/authorize_app.erl new file mode 100644 index 0000000..4b33c2f --- /dev/null +++ b/components/authorize/src/authorize_app.erl @@ -0,0 +1,32 @@ +%% +%% Copyright (C) 2014, Jaguar Land Rover +%% +%% This program is licensed under the terms and conditions of the +%% Mozilla Public License, version 2.0. The full text of the +%% Mozilla Public License is at https://www.mozilla.org/MPL/2.0/ +%% + + +-module(authorize_app). + +-behaviour(application). + +%% Application callbacks +-export([start/2, + start_phase/3, + stop/1]). + +%% =================================================================== +%% Application callbacks +%% =================================================================== + +start(_StartType, _StartArgs) -> + authorize_sup:start_link(). + +start_phase(init, _, _) -> + authorize_rpc:init(), + ok. + + +stop(_State) -> + ok. diff --git a/components/authorize/src/authorize_rpc.erl b/components/authorize/src/authorize_rpc.erl new file mode 100644 index 0000000..8a4d2d0 --- /dev/null +++ b/components/authorize/src/authorize_rpc.erl @@ -0,0 +1,123 @@ +%% +%% Copyright (C) 2014, Jaguar Land Rover +%% +%% This program is licensed under the terms and conditions of the +%% Mozilla Public License, version 2.0. The full text of the +%% Mozilla Public License is at https://www.mozilla.org/MPL/2.0/ +%% + + +-module(authorize_rpc). + +-export([handle_rpc/2]). +-export([init/0]). + +-include_lib("lager/include/log.hrl"). + +init() -> + ?debug("authorize_rpc:init(): called"), + case rvi_common:get_component_config(authorize, exo_http_opts) of + { ok, ExoHttpOpts } -> + exoport_exo_http:instance(authorize_sup, + authorize_rpc, + ExoHttpOpts); + Err -> Err + end. + + +%% Retrieve certificate. +%% Certificate will be passed to exo_json:encode() in order +%% to be translated to JSON. +get_certificate_body(_CallingService, _ServiceName) -> + {struct, + [ + %% Topic tree patterns that this node is authorized to + %% process requests for. + { "sources", + { array, [ + "jaguarlandrover.com/cloud/media_server" + ] + } + }, + %% Services that can be accessed by the source service. + { destinations, + { array, [ + "rpc:jaguarlandrover.com/vin/+/services/media_player" + ] + } + + }, + %% Public key for source. + %% Used to validate signature of requests, etc. + { public_key, + { struct, [ + { algorithm, "some_algorithm" }, + { key, "some_public_key" } + ] + } + }, + %% Period during which certificate is valid. UTC + { validity, + { struct, [ + { start, 1401918299 }, + { stop, 1402000000 } + ] + } + }, + %% A system wide unique id for the certificate + { id, "b674546e-76ae-4204-b551-3f850fbffb4b" }, + + %% UTC timestamp of when the certificate was created. + { create_timestamp, 1403825201 }, + + %% Signed by provisioning server. + %% All nodes have provisioning server's public key. + %% Signature covers all data in claims element. + { signature, + { struct, [ + { algorithm, "signature_algorithm" }, + { signature, "signature" } + ] + } + } + ] + }. + +authorize_local_message(ServiceName, CallingService) -> + ?debug("authorize_rpc:authorize_local_msg(): service_name: ~p ~n", [ServiceName]), + ?debug("authorize_rpc:authorize_local_msg(): calling_service: ~p ~n", [CallingService]), + {ok, + [ + { status, rvi_common:json_rpc_status(ok)}, + { signature, "fixme_add_signature" }, +%% { certificate, get_certificate_body(CallingService, ServiceName) } + { certificate, "certificate" } + ]}. + +authorize_remote_message(ServiceName, Signature, Certificate) -> + ?debug("authorize_rpc:authorize_remote_msg(): service_name: ~p ~n", [ServiceName]), + ?debug("authorize_rpc:authorize_remote_msg(): signature: ~p ~n", [Signature]), + ?debug("authorize_rpc:authorize_remote_msg(): certificate: ~p ~n", [Certificate]), + {ok, + [ + { status, rvi_common:json_rpc_status(ok) }, + { signature, Signature }, + { certificate, Certificate } + ]}. + +%% JSON-RPC entry point +%% CAlled by local exo http server +handle_rpc("authorize_local_message", Args) -> + {ok, ServiceName} = rvi_common:get_json_element(["service_name"], Args), + {ok, CallingService} = rvi_common:get_json_element(["calling_service"], Args), + authorize_local_message(ServiceName, CallingService); + +handle_rpc("authorize_remote_message", Args) -> + {ok, ServiceName} = rvi_common:get_json_element(["service_name"], Args), + {ok, Signature} = rvi_common:get_json_element(["signature"], Args), + {ok, Certificate} = rvi_common:get_json_element(["certificate"], Args), + authorize_remote_message(ServiceName , Signature, Certificate); + +handle_rpc(Other, _Args) -> + ?debug("authorize_rpc:handle_rpc(~p): unknown", [ Other ]), + { ok, [ { status, rvi_common:json_rpc_status(invalid_command)} ] }. diff --git a/components/authorize/src/authorize_sup.erl b/components/authorize/src/authorize_sup.erl new file mode 100644 index 0000000..8e5a941 --- /dev/null +++ b/components/authorize/src/authorize_sup.erl @@ -0,0 +1,44 @@ +%% +%% Copyright (C) 2014, Jaguar Land Rover +%% +%% This program is licensed under the terms and conditions of the +%% Mozilla Public License, version 2.0. The full text of the +%% Mozilla Public License is at https://www.mozilla.org/MPL/2.0/ +%% + + +-module(authorize_sup). + +-behaviour(supervisor). + +%% API +-export([start_link/0]). + +%% Supervisor callbacks +-export([init/1]). + +%% Helper macro for declaring children of supervisor +-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}). + +%% =================================================================== +%% API functions +%% =================================================================== + +start_link() -> + supervisor:start_link({local, ?MODULE}, ?MODULE, []). + +%% =================================================================== +%% Supervisor callbacks +%% =================================================================== + +init([]) -> + {ok, { {one_for_one, 5, 10}, + [ +%% ?CHILD(authorize_alarms, worker), +%% ?CHILD(authorize_log, worker), +%% ?CHILD(authorize_can, worker), +%% ?CHILD(authorize_waypoints, worker) + %% ?CHILD(authorize_gps, worker), + %% ?CHILD(exodmo_config, worker) + ]} }. + |