| 1026 | } |
| 1027 | |
| 1028 | void authkey_(char **args, int numargs) // set up misc keys |
| 1029 | { |
| 1030 | if(numargs > 0) |
| 1031 | { |
| 1032 | string buf; |
| 1033 | if(!strcasecmp(args[0], "CLEAR")) |
| 1034 | { // authkey clear |
| 1035 | if(authkeys.length()) |
| 1036 | { |
| 1037 | char *oldfile = loadfile(AUTHKEYSCFGFILE, NULL); |
| 1038 | if(oldfile) |
| 1039 | { |
| 1040 | stream *f = openfile(AUTHKEYSCFGFILE, "wb"); |
| 1041 | if(f) |
| 1042 | { // don't really delete the old keys, just comment them out |
| 1043 | for(char *b, *l = strtok_r(oldfile, "\n\r", &b); l; l = strtok_r(NULL, "\n\r", &b)) if(*l) f->printf("// %s\n", l); |
| 1044 | delete f; |
| 1045 | } |
| 1046 | delete[] oldfile; |
| 1047 | } |
| 1048 | authkeys.shrink(0); |
| 1049 | conoutf("all authkeys deleted"); |
| 1050 | } |
| 1051 | } |
| 1052 | else if(!strcasecmp(args[0], "LIST")) |
| 1053 | { // authkey list |
| 1054 | if(authkeys.length()) |
| 1055 | { |
| 1056 | conoutf("name\tpubkey"); |
| 1057 | loopv(authkeys) conoutf("%s\t%s", authkeys[i]->name, bin2hex(buf, authkeys[i]->sk + 32, 32)); |
| 1058 | } |
| 1059 | else conoutf("no authkeys"); |
| 1060 | } |
| 1061 | else if(!strcasecmp(args[0], "DELETE")) |
| 1062 | { // authkey delete name |
| 1063 | if(numargs > 1) delauthkey(args[1]); |
| 1064 | } |
| 1065 | else if(!strcasecmp(args[0], "NEW")) |
| 1066 | { // authkey new name |
| 1067 | if(numargs > 1 && args[1][0]) |
| 1068 | { |
| 1069 | uchar prepriv[42], priv[32], pub[32]; |
| 1070 | delauthkey(args[1]); |
| 1071 | entropy_get(prepriv, 42); |
| 1072 | privkey_from_prepriv(priv, prepriv, 42); |
| 1073 | ed25519_pubkey_from_private(pub, priv); |
| 1074 | authkey *ak = new authkey(args[1], bin2hex(buf, priv, 32)); |
| 1075 | if(ak->name) |
| 1076 | { |
| 1077 | authkeys.add(ak); |
| 1078 | stream *f = openfile(AUTHKEYSCFGFILE, "ab"); |
| 1079 | if(f) |
| 1080 | { |
| 1081 | f->printf("// authkey \"%s\", generated %s\n", ak->name, timestring("%c")); |
| 1082 | f->printf("// prepriv %s\n", bin2hex(buf, prepriv, 42)); |
| 1083 | f->printf("// priv %s\n", bin2hex(buf, priv, 32)); |
| 1084 | f->printf("// pub %s\n", bin2hex(buf, pub, 32)); |
| 1085 | f->printf("authkey add %s %s\n\n", ak->name, bin2hex(buf, priv, 32)); |
nothing calls this directly
no test coverage detected