Merge branch 'master' of gitlab.com:zxq9/zx
This commit is contained in:
commit
13e06cf2c9
@ -1 +1 @@
|
||||
0.10.7
|
||||
0.10.9
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{application,zx,
|
||||
[{description,"An Erlang development tool and Zomp user client"},
|
||||
{vsn,"0.10.7"},
|
||||
{vsn,"0.10.9"},
|
||||
{applications,[stdlib,kernel]},
|
||||
{modules,[zx,zx_auth,zx_conn,zx_conn_sup,zx_daemon,zx_key,
|
||||
zx_lib,zx_local,zx_net,zx_peer,zx_peer_man,
|
||||
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
@ -24,7 +24,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-behavior(application).
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
@ -9,7 +9,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_auth).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
-license("GPL-3.0").
|
||||
@ -7,7 +7,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_conn).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
-license("GPL-3.0").
|
||||
@ -5,7 +5,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_conn_sup).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-behavior(supervisor).
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
@ -138,7 +138,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_daemon).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-behavior(gen_server).
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
@ -1406,6 +1406,14 @@ eval_queue(Actions, State) ->
|
||||
|
||||
local_dispatch([], State) ->
|
||||
State;
|
||||
local_dispatch([{request, Pid, ID, {fetch, R, N, V}} | Rest], State) ->
|
||||
Result =
|
||||
case zomp_realm_man:lookup(R) of
|
||||
{ok, RealmPID} -> local_fetch(RealmPID, {R, N, V});
|
||||
Error -> Error
|
||||
end,
|
||||
Pid ! {result, ID, Result},
|
||||
local_dispatch(Rest, State);
|
||||
local_dispatch([{request, Pid, ID, Message} | Rest], State) ->
|
||||
Realm = element(2, Message),
|
||||
Result =
|
||||
@ -1452,6 +1460,46 @@ local_request(R, {list_sysops}) -> zomp_realm:list_sysops(R);
|
||||
local_request(R, {list_type, T}) -> zomp_realm:list_type(R, T).
|
||||
|
||||
|
||||
local_fetch(RealmPID, PackageID = {_, N, V}) ->
|
||||
{ok, PackageString} = zx_lib:package_string(PackageID),
|
||||
ok = tell("Fetching ~s", [PackageString]),
|
||||
case zomp_realm:fetch(RealmPID, {N, V}) of
|
||||
{ok, Bin} -> do_import_package(Bin);
|
||||
upstream -> local_fetch_upstream(PackageID, 0);
|
||||
Error -> Error
|
||||
end.
|
||||
|
||||
local_fetch_upstream(PackageID, Tries) ->
|
||||
Realm = element(1, PackageID),
|
||||
case zomp_node_man:lookup(Realm) of
|
||||
{ok, NodePID} ->
|
||||
ok = tell("Found node connector at ~p", [NodePID]),
|
||||
ok = zomp_node:fetch(NodePID, PackageID),
|
||||
wait_hops(PackageID);
|
||||
wait ->
|
||||
wait_upstream_node(PackageID, Tries);
|
||||
error ->
|
||||
{error, bad_realm}
|
||||
end.
|
||||
|
||||
wait_hops(PackageID) ->
|
||||
receive
|
||||
{ok, PackageID, Bin} ->
|
||||
do_import_package(Bin);
|
||||
{hops, PackageID, Distance} ->
|
||||
ok = tell("Fetch in progress. Hops: ~w", [Distance]),
|
||||
wait_hops(PackageID)
|
||||
after 60000 ->
|
||||
{error, timeout}
|
||||
end.
|
||||
|
||||
wait_upstream_node(PackageID, Tries) when Tries < 10 ->
|
||||
_ = erlang:send_after(1000, self(), retry),
|
||||
receive retry -> local_fetch_upstream(PackageID, Tries + 1) end;
|
||||
wait_upstream_node(_, _) ->
|
||||
{error, timeout}.
|
||||
|
||||
|
||||
remote_dispatch([], State) ->
|
||||
State;
|
||||
remote_dispatch([Action = {request, Pid, ID, Message} | Rest],
|
||||
@ -1628,7 +1676,8 @@ do_fetch(PackageID, Requestor, State = #s{id = ID}) ->
|
||||
Action = {fetch, Realm, Name, Version},
|
||||
do_request(Requestor, Action, State);
|
||||
Error ->
|
||||
Requestor ! {result, ID, Error}
|
||||
Requestor ! {result, ID, Error},
|
||||
State
|
||||
end.
|
||||
|
||||
do_fetch2(Bin, Requestor, ID) ->
|
||||
@ -8,7 +8,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_key).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
-license("GPL-3.0").
|
||||
@ -20,6 +20,7 @@
|
||||
sign/2, verify/3]).
|
||||
|
||||
-include("zx_logger.hrl").
|
||||
-include_lib("public_key/include/OTP-PUB-KEY.hrl").
|
||||
|
||||
|
||||
-spec generate_rsa(Owner) -> Result
|
||||
@ -32,125 +33,30 @@
|
||||
%% NOTE: The current version of this command is likely to only work on a unix system.
|
||||
|
||||
generate_rsa(Owner) ->
|
||||
{ok, TmpDir} = zx_lib:mktemp_dir({"otpr", "zx"}),
|
||||
PemFile = filename:join(TmpDir, "zx-tmp.pem"),
|
||||
PubFile = filename:join(TmpDir, "zx-tmp.pub.der"),
|
||||
KeyFile = filename:join(TmpDir, "zx-tmp.key.der"),
|
||||
ok = tell("Generating keys. Please be patient..."),
|
||||
case gen_p_key(KeyFile) of
|
||||
ok ->
|
||||
ok = der_to_pem(KeyFile, PemFile),
|
||||
{ok, PemBin} = file:read_file(PemFile),
|
||||
[PemData] = public_key:pem_decode(PemBin),
|
||||
Pub = public_key:pem_entry_decode(PemData),
|
||||
PubDer = public_key:der_encode('RSAPublicKey', Pub),
|
||||
ok = file:write_file(PubFile, PubDer),
|
||||
generate_rsa2(Owner, PemFile, KeyFile, PubFile);
|
||||
{error, no_ssl} ->
|
||||
ok = tell(error, "OpenSSL not found."),
|
||||
{error, keygen_fail}
|
||||
end.
|
||||
|
||||
generate_rsa2(Owner, PemFile, KeyFile, PubFile) ->
|
||||
{ok, PubBin} = file:read_file(PubFile),
|
||||
{ok, KeyBin} = file:read_file(KeyFile),
|
||||
Pub = public_key:der_decode('RSAPublicKey', PubBin),
|
||||
Key = public_key:der_decode('RSAPrivateKey', KeyBin),
|
||||
ok = tell("Generating keys. This can take several minutes. Please be patient..."),
|
||||
Key =
|
||||
#'RSAPrivateKey'{modulus = Mod,
|
||||
publicExponent = PE} =
|
||||
public_key:generate_key({rsa, 16384, 65537}),
|
||||
Pub =
|
||||
#'RSAPublicKey'{modulus = Mod,
|
||||
publicExponent = PE},
|
||||
TestMessage = <<"Some test data to sign.">>,
|
||||
Signature = public_key:sign(TestMessage, sha512, Key),
|
||||
case public_key:verify(TestMessage, sha512, Signature, Pub) of
|
||||
true ->
|
||||
PubHash = crypto:hash(sha512, PubBin),
|
||||
KeyData = {PubHash, {none, PubBin}, {none, KeyBin}},
|
||||
KeyDER = public_key:der_encode('RSAPrivateKey', Key),
|
||||
PubDER = public_key:der_encode('RSAPublicKey', Pub),
|
||||
PubHash = crypto:hash(sha512, PubDER),
|
||||
KeyData = {PubHash, {none, PubDER}, {none, KeyDER}},
|
||||
ok = zx_daemon:register_key(Owner, KeyData),
|
||||
ok = zx_lib:rm_rf(filename:dirname(KeyFile)),
|
||||
{ok, PubHash};
|
||||
false ->
|
||||
ok = lists:foreach(fun file:delete/1, [PemFile, KeyFile, PubFile]),
|
||||
ok = tell(error, "Something has gone wrong."),
|
||||
{error, keygen_fail}
|
||||
end.
|
||||
|
||||
|
||||
-spec gen_p_key(KeyFile) -> Result
|
||||
when KeyFile :: file:filename(),
|
||||
Result :: ok
|
||||
| {error, no_ssl}.
|
||||
%% @private
|
||||
%% Format an openssl shell command that will generate proper 16k RSA keys.
|
||||
|
||||
gen_p_key(KeyFile) ->
|
||||
case openssl() of
|
||||
{ok, OpenSSL} ->
|
||||
Command =
|
||||
io_lib:format("~ts genpkey"
|
||||
" -algorithm rsa"
|
||||
" -out ~ts"
|
||||
" -outform DER"
|
||||
" -pkeyopt rsa_keygen_bits:16384",
|
||||
[OpenSSL, KeyFile]),
|
||||
Out = os:cmd(Command),
|
||||
io:format(Out);
|
||||
Error ->
|
||||
Error
|
||||
end.
|
||||
|
||||
|
||||
-spec der_to_pem(KeyFile, PemFile) -> ok
|
||||
when KeyFile :: file:filename(),
|
||||
PemFile :: file:filename().
|
||||
%% @private
|
||||
%% Format an openssl shell command that will convert the given keyfile to a pemfile.
|
||||
%% The reason for this conversion is to sidestep some formatting weirdness that OpenSSL
|
||||
%% injects into its generated DER formatted key output (namely, a few empty headers)
|
||||
%% which Erlang's ASN.1 defintion files do not take into account. A conversion to PEM
|
||||
%% then a conversion back to DER (via Erlang's ASN.1 module) resolves this in a reliable
|
||||
%% way.
|
||||
|
||||
der_to_pem(KeyFile, PemFile) ->
|
||||
case openssl() of
|
||||
{ok, OpenSSL} ->
|
||||
Command =
|
||||
io_lib:format("~ts rsa"
|
||||
" -inform DER"
|
||||
" -in ~ts"
|
||||
" -outform PEM"
|
||||
" -pubout"
|
||||
" -out ~ts",
|
||||
[OpenSSL, KeyFile, PemFile]),
|
||||
Out = os:cmd(Command),
|
||||
io:format(Out);
|
||||
Error ->
|
||||
Error
|
||||
end.
|
||||
|
||||
|
||||
-spec openssl() -> Result
|
||||
when Result :: {ok, Executable}
|
||||
| {error, no_ssl},
|
||||
Executable :: file:filename().
|
||||
%% @private
|
||||
%% Attempt to locate the installed openssl executable for use in shell commands.
|
||||
%% TODO: Determine whether it is even worth it to perform this check VS restricting
|
||||
%% os:cmd/1 directed zx_key functions by platform.
|
||||
|
||||
openssl() ->
|
||||
OpenSSL =
|
||||
case os:type() of
|
||||
{unix, _} -> "openssl";
|
||||
{win32, _} -> "openssl.exe"
|
||||
end,
|
||||
case os:find_executable(OpenSSL) of
|
||||
false ->
|
||||
M = "OpenSSL not foud in PATH. Install OpenSSL or add to path and retry.",
|
||||
ok = tell(error, M),
|
||||
{error, no_ssl};
|
||||
Path ->
|
||||
ok = tell("OpenSSL executable found at: ~ts", [Path]),
|
||||
{ok, OpenSSL}
|
||||
end.
|
||||
|
||||
|
||||
-spec save(Type, KeyID, Key) -> Result
|
||||
when Type :: private | public,
|
||||
KeyID :: zx:key_id(),
|
||||
@ -10,7 +10,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_lib).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
-license("GPL-3.0").
|
||||
@ -6,7 +6,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_local).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
-license("GPL-3.0").
|
||||
@ -1937,7 +1937,7 @@ store_realm(#realm_init{realm = Realm,
|
||||
"3. Become the prime node: `zx takeover ~ts`~n"
|
||||
"~n"
|
||||
"ZX CLIENT and ZOMP DISTRIBUTION NODE configuration requires one command:~n"
|
||||
"1. Configure the realm: `zx add realm ~ts`~n"
|
||||
"1. Configure the realm: `zx import realm ~ts`~n"
|
||||
"~n"
|
||||
"How to distribute ~ts is up to you.~n"
|
||||
"=============================================================================~n",
|
||||
@ -5,7 +5,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_net).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
-license("GPL-3.0").
|
||||
@ -8,7 +8,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_peer).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
-license("GPL-3.0").
|
||||
@ -166,7 +166,7 @@ handle_message(<<Command:8, Bin/binary>>) ->
|
||||
9 -> deferred(fun zx_daemon:search/1, Payload);
|
||||
10 -> deferred(fun zx_daemon:list_deps/1, Payload);
|
||||
11 -> deferred(fun zx_daemon:list_sysops/1, Payload);
|
||||
12 -> zx_daemon:fetch(Payload);
|
||||
12 -> deferred(fun zx_daemon:fetch/1, Payload);
|
||||
13 -> zx_daemon:keychain(Payload);
|
||||
14 -> zx_daemon:install(Payload);
|
||||
15 -> zx_daemon:build(Payload);
|
||||
@ -9,7 +9,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_peer_man).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-behavior(gen_server).
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
@ -6,7 +6,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_peer_sup).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-behaviour(supervisor).
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
@ -10,7 +10,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_peers).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-behavior(supervisor).
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
@ -5,7 +5,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_proxy).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
-license("GPL-3.0").
|
||||
@ -5,7 +5,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_sup).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-behavior(supervisor).
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
@ -6,7 +6,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_tty).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
-license("GPL-3.0").
|
||||
@ -5,7 +5,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_userconf).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
-license("GPL-3.0").
|
||||
@ -7,7 +7,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(zx_zsp).
|
||||
-vsn("0.10.7").
|
||||
-vsn("0.10.9").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||
-license("GPL-3.0").
|
||||
@ -9,7 +9,7 @@
|
||||
{license,"MIT"}.
|
||||
{modules,[]}.
|
||||
{name,"zx"}.
|
||||
{package_id,{"otpr","zx",{0,10,7}}}.
|
||||
{package_id,{"otpr","zx",{0,10,9}}}.
|
||||
{prefix,"zx_"}.
|
||||
{repo_url,"https://gitlab.com/zxq9/zx"}.
|
||||
{tags,["tools","package manager","erlang"]}.
|
||||
Loading…
x
Reference in New Issue
Block a user