| 799 | } |
| 800 | |
| 801 | void authsetup(char **args, int numargs) // set up private and public keys |
| 802 | { |
| 803 | const int preprivminlen = 32, preprivmaxlen = 128; |
| 804 | static uchar *buf = NULL, pub[32], keyhash[128], psalt[16], salt[16], preprivlen = 0; |
| 805 | static uint preprivpwdcfg = 0, privpwdcfg = 0; |
| 806 | static void *passdrunning = NULL, *passdcleanup = NULL; |
| 807 | static char *sleepcmd = NULL; |
| 808 | if(!buf) entropy_get((buf = new uchar[1536]), 1536); |
| 809 | uint32_t offs = 7337; |
| 810 | loopi(16) fnv1a_add(offs, buf[i]); |
| 811 | uchar *priv = buf + 24 + (offs & 0xfc), *prepriv = priv + 112 + ((offs >> 9) & 0xfc), res = 0; |
| 812 | #ifdef _DEBUG |
| 813 | char hextemp[2 * preprivmaxlen + 1]; |
| 814 | #endif |
| 815 | |
| 816 | if(passdrunning) |
| 817 | { |
| 818 | if(numargs < 0) |
| 819 | { // finish password decryption (background mode) |
| 820 | privpwdcfg = 0; |
| 821 | passdcleanup = passdrunning; |
| 822 | passdrunning = NULL; |
| 823 | if(sleepcmd) addsleep(0, sleepcmd); |
| 824 | DELSTRING(sleepcmd); |
| 825 | } |
| 826 | else return; // ignore further "authsetup" commands while a password decryption is running in the background |
| 827 | } |
| 828 | else |
| 829 | { |
| 830 | if(numargs < 0) return; // should not happen |
| 831 | else if(passdcleanup) |
| 832 | { |
| 833 | sl_waitthread(passdcleanup); |
| 834 | passdcleanup = NULL; |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | if(numargs > 0) |
| 839 | { |
| 840 | if(!strcasecmp(args[0], "PRE")) |
| 841 | { |
| 842 | // authsetup pre preprivhex [psalthex pwdcfg] |
| 843 | preprivlen = numargs > 1 ? clamp(int(strlen(args[1])) / 2, preprivminlen, preprivmaxlen) : 32; |
| 844 | if(numargs > 1) hex2bin(prepriv, args[1], preprivlen); |
| 845 | if(numargs > 2) hex2bin(psalt, args[2], 16); |
| 846 | preprivpwdcfg = numargs > 3 ? atoi(args[3]) : 0; |
| 847 | } |
| 848 | else if(!strcasecmp(args[0], "PRIV")) |
| 849 | { |
| 850 | // authsetup priv privhex [salthex pwdcfg] |
| 851 | if(numargs > 1) hex2bin(priv, args[1], 32); |
| 852 | if(numargs > 2) hex2bin(salt, args[2], 16); |
| 853 | privpwdcfg = numargs > 3 ? atoi(args[3]) : 0; |
| 854 | sk = NULL; |
| 855 | } |
| 856 | else if(!strcasecmp(args[0], "PUB")) |
| 857 | { |
| 858 | // authsetup pub pubhex |
no test coverage detected