WIP: Grand shakeout awaits!
This commit is contained in:
parent
a7a8ad72f2
commit
1fde98932c
@ -1,4 +1,7 @@
|
||||
{realm, "otpr"}.
|
||||
{prime, {"zomp.psychobitch.party",11311}}.
|
||||
{sysop, "zxq9"}.
|
||||
{key, "zxq9-root"}.
|
||||
{sysop, {"zxq9", "Craig Everett", [{"email", "zxq9@zxq9.com"}]}}.
|
||||
{key, <<38,103,252,11,212,145,139,235,72,17,254,18,49,212,225,154,251,31,136,0,11,
|
||||
230,252,220,118,33,116,200,63,200,8,166,213,29,94,176,113,70,228,47,37,54,90,
|
||||
124,151,66,121,221,136,7,5,112,114,74,165,205,88,29,138,226,27,104,84,250>>}.
|
||||
{timestamp, {{2019, 12, 16}, {13, 01, 21}}}.
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -842,10 +842,10 @@ handle_call({takeover, Realm}, _, State = #s{conf = Conf}) ->
|
||||
{Result, NewConf} = do_takeover(Realm, Conf),
|
||||
NewState = eval_queue(State#s{conf = NewConf}),
|
||||
{reply, Result, NewState};
|
||||
handle_call({drop_realm, Realm}, _, State = #s{conf = Conf}) ->
|
||||
{Result, NewConf} = do_drop_realm(Realm, Conf),
|
||||
NewState = eval_queue(State#s{conf = NewConf}),
|
||||
{reply, Result, NewState};
|
||||
handle_call({drop_realm, Realm}, _, State) ->
|
||||
NextState = do_drop_realm(Realm, State),
|
||||
NewState = eval_queue(NextState),
|
||||
{reply, ok, NewState};
|
||||
handle_call(hosts, _, State = #s{cx = CX}) ->
|
||||
Result = cx_mirrors(CX),
|
||||
{reply, Result, State};
|
||||
@ -1868,24 +1868,24 @@ do_takeover(Realm, C = #conf{realms = Realms, managed = Managed}) ->
|
||||
end.
|
||||
|
||||
|
||||
-spec do_abdicate(Realm, Conf) -> {Result, NewConf}
|
||||
-spec do_abdicate(Realm, State) -> {Result, NewState}
|
||||
when Realm :: zx:realm(),
|
||||
Conf :: conf(),
|
||||
State :: state(),
|
||||
Result :: ok
|
||||
| {error, unmanaged},
|
||||
NewConf :: conf().
|
||||
NewState :: state().
|
||||
|
||||
do_abdicate(Realm, C = #conf{managed = Managed}) ->
|
||||
do_abdicate(Realm, State = #s{conf = C = #conf{managed = Managed}}) ->
|
||||
case sets:is_element(Realm, Managed) of
|
||||
true ->
|
||||
NewManaged = sets:del_element(Realm, Managed),
|
||||
NewC = C#conf{managed = NewManaged},
|
||||
ok = save_conf(NewC),
|
||||
ok = log(info, "No longer managing realm: ~160tp", [Realm]),
|
||||
{ok, NewC};
|
||||
{ok, State#s{conf = NewC}};
|
||||
false ->
|
||||
ok = log(error, "Cannot abdicate an unmanaged realm."),
|
||||
{{error, unmanaged}, C}
|
||||
ok = tell(error, "Cannot abdicate an unmanaged realm."),
|
||||
{{error, unmanaged}, State}
|
||||
end.
|
||||
|
||||
|
||||
@ -2121,25 +2121,27 @@ do_list_keys(private, Realm, {RK, _, _}) ->
|
||||
end.
|
||||
|
||||
|
||||
-spec do_drop_realm(Realm, State) -> {ok, NewState}
|
||||
-spec do_drop_realm(Realm, State) -> NewState
|
||||
when Realm :: zx:realm(),
|
||||
State :: state(),
|
||||
NewState :: state().
|
||||
|
||||
do_drop_realm(Realm, State = #s{kx = {RealmIndex, Pairs}}) ->
|
||||
do_drop_realm(Realm, State = #s{kx = {RealmIndex, Pairs, Owners}}) ->
|
||||
NewKX =
|
||||
case maps:take(Realm, RealmIndex) of
|
||||
{KeyIndex, NextRealmIndex} ->
|
||||
NewPairs = scrub_pairs(maps:values(KeyIndex), Pairs),
|
||||
{NextRealmIndex, NewPairs};
|
||||
Screen = fun({{R, _}, _}) -> R == Realm end,
|
||||
NewOwners = maps:filter(Screen, Owners),
|
||||
{NextRealmIndex, NewPairs, NewOwners};
|
||||
error ->
|
||||
{RealmIndex, Pairs}
|
||||
{RealmIndex, Pairs, Owners}
|
||||
end,
|
||||
Dirs = [etc, var, tmp, log, key, zsp, lib],
|
||||
RM = fun(D) -> ok = zx_lib:rm_rf(zx_lib:path(D, Realm)) end,
|
||||
ok = lists:foreach(RM, Dirs),
|
||||
NewState = do_abdicate(Realm, State),
|
||||
{ok, NewState#s{kx = NewKX}}.
|
||||
{_, NewState} = do_abdicate(Realm, State),
|
||||
NewState#s{kx = NewKX}.
|
||||
|
||||
scrub_pairs([#key{pubhash = PubHash, keyhash = KeyHash} | Rest], Pairs) ->
|
||||
scrub_pairs(Rest, maps:without([PubHash, KeyHash], Pairs));
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
|
||||
-spec path(public | private, zx:key_id()) -> file:filename().
|
||||
|
||||
path(Type, {Realm, KeyHash}) when is_binary(KeyHash) ->
|
||||
path(Type, {Realm, KeyHash}) ->
|
||||
Size = byte_size(KeyHash) * 8,
|
||||
<<N:Size>> = KeyHash,
|
||||
String = integer_to_list(N, 36),
|
||||
@ -33,9 +33,7 @@ path(Type, {Realm, KeyHash}) when is_binary(KeyHash) ->
|
||||
public -> String ++ ".pub.der";
|
||||
private -> String ++ ".key.der"
|
||||
end,
|
||||
zx_lib:path(key, Realm, Name);
|
||||
path(Type, {Realm, KeyName}) ->
|
||||
zx_lib:path(key, Realm, KeyName).
|
||||
zx_lib:path(key, Realm, Name).
|
||||
|
||||
|
||||
|
||||
@ -82,12 +80,10 @@ generate_rsa2(Owner, PemFile, KeyFile, PubFile) ->
|
||||
true ->
|
||||
ok = tell(info, "~ts and ~ts agree", [KeyFile, PubFile]),
|
||||
PubHash = crypto:hash(sha512, PubBin),
|
||||
KeyHash = crypto:hash(sha512, KeyBin),
|
||||
PairHash = crypto:hash(sha512, <<PubHash/binary, KeyHash/binary>>),
|
||||
KeyData = {PairHash, {none, PubBin}, {none, KeyBin}},
|
||||
KeyData = {PubHash, {none, PubBin}, {none, KeyBin}},
|
||||
ok = zx_daemon:register_key(Owner, KeyData),
|
||||
ok = zx_lib:rm_rf(filename:dirname(KeyFile)),
|
||||
{ok, PairHash};
|
||||
{ok, PubHash};
|
||||
false ->
|
||||
ok = lists:foreach(fun file:delete/1, [PemFile, KeyFile, PubFile]),
|
||||
ok = tell(error, "Something has gone wrong."),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user