Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
2eba60251a
  1. 19
      iguana/SuperNET.c
  2. 43
      iguana/SuperNET_keys.c
  3. 2
      iguana/iguana_rpc.c
  4. 44
      iguana/iguana_wallet.c
  5. 1
      iguana/tests/backupwallet
  6. 1
      iguana/tests/dumpwallet
  7. 2
      iguana/tests/encryptwallet
  8. 2
      iguana/tests/login
  9. 3
      iguana/tests/walletpassphrase

19
iguana/SuperNET.c

@ -1381,23 +1381,25 @@ struct supernet_info *SuperNET_accountfind(cJSON *json)
FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase)
{
char *str,*decryptstr = 0; cJSON *argjson; uint32_t expire = myinfo->expiration;
char savehandle[1024],savepassword[1024],savepermanentfile[1024],*str,*decryptstr = 0; cJSON *argjson; uint32_t expire = myinfo->expiration;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
safecopy(savehandle,myinfo->handle,sizeof(myinfo->handle));
safecopy(savepassword,myinfo->secret,sizeof(myinfo->secret));
safecopy(savepermanentfile,myinfo->permanentfile,sizeof(myinfo->permanentfile));
if ( bits256_nonz(myinfo->persistent_priv) != 0 && (str= SuperNET_logout(IGUANA_CALLARGS)) != 0 )
free(str);
myinfo->expiration = expire;
if ( handle != 0 )
{
if ( handle != 0 && handle[0] != 0 )
safecopy(myinfo->handle,handle,sizeof(myinfo->handle));
safecopy(myinfo->secret,password,sizeof(myinfo->secret));
safecopy(myinfo->permanentfile,permanentfile,sizeof(myinfo->permanentfile));
}
else safecopy(myinfo->handle,savehandle,sizeof(myinfo->handle));
safecopy(myinfo->secret,savepassword,sizeof(myinfo->secret));
safecopy(myinfo->permanentfile,savepermanentfile,sizeof(myinfo->permanentfile));
if ( (passphrase == 0 || passphrase[0] == 0) && (decryptstr= SuperNET_decryptjson(IGUANA_CALLARGS,password,permanentfile)) != 0 )
{
if ( (argjson= cJSON_Parse(decryptstr)) != 0 )
{
printf("decrypted.(%s) exp.%u\n",decryptstr,myinfo->expiration);
//printf("decrypted.(%s) exp.%u\n",decryptstr,myinfo->expiration);
if ( myinfo->decryptstr != 0 )
free(myinfo->decryptstr);
myinfo->decryptstr = decryptstr;
@ -1405,6 +1407,7 @@ FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase)
{
SuperNET_setkeys(myinfo,passphrase,(int32_t)strlen(passphrase),1);
free_json(argjson);
myinfo->expiration = (uint32_t)(time(NULL) + 3600*24);
return(SuperNET_activehandle(IGUANA_CALLARGS));
}
else
@ -1422,7 +1425,7 @@ FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase)
if ( passphrase != 0 && passphrase[0] != 0 )
{
SuperNET_setkeys(myinfo,passphrase,(int32_t)strlen(passphrase),1);
if ( (str= SuperNET_encryptjson(IGUANA_CALLARGS,password,permanentfile,passphrase)) != 0 )
if ( (str= SuperNET_encryptjson(IGUANA_CALLARGS,myinfo->secret,myinfo->permanentfile,passphrase)) != 0 )
free(str);
return(SuperNET_activehandle(IGUANA_CALLARGS));
}

43
iguana/SuperNET_keys.c

@ -135,7 +135,7 @@ int32_t SuperNET_savejsonfile(char *fname,bits256 privkey,bits256 destpubkey,cJS
//sprintf(fname,"confs/iguana.%llu",(long long)wallet2shared.txid);
if ( (ciphered= SuperNET_cipher(0,0,json,0,privkey,destpubkey,confstr)) != 0 )
{
printf("ciphered.save (%s) <- (%s)\n",fname,confstr);
//printf("ciphered.save (%s) <- (%s)\n",fname,confstr);
if ( (fp= fopen(fname,"wb")) != 0 )
{
fwrite(ciphered,1,strlen(ciphered)+1,fp);
@ -176,9 +176,9 @@ int32_t SuperNET_userkeys(char *passphrase,int32_t passsize,char *fname2fa,int32
return(-1);
}
cJSON *SuperNET_decryptedjson(char *passphrase,int32_t passsize,bits256 wallethash,char *fname2fa,int32_t fnamesize,bits256 wallet2priv)
cJSON *SuperNET_decryptedjson(char *destfname,char *passphrase,int32_t passsize,bits256 wallethash,char *fname2fa,int32_t fnamesize,bits256 wallet2priv)
{
long allocsize; cJSON *filejson,*msgjson=0,*json=0; char *confstr=0,*deciphered,fname[512],str[65];
long allocsize; cJSON *filejson,*msgjson=0,*json=0; char *confstr=0,*deciphered,str[65];
bits256 wallet2shared,wallet2pub; int32_t first,second;
msgjson = 0;
first = (bits256_nonz(wallethash) != 0 && bits256_cmp(wallethash,GENESIS_PRIVKEY) != 0);
@ -200,17 +200,17 @@ cJSON *SuperNET_decryptedjson(char *passphrase,int32_t passsize,bits256 walletha
wallethash = GENESIS_PRIVKEY;
wallet2shared = SuperNET_wallet2shared(wallethash,wallet2priv);
wallet2pub = curve25519(wallet2shared,curve25519_basepoint9());
sprintf(fname,"confs/%s",bits256_str(str,wallet2pub));
//printf("fname.(%s) wallet2shared.%s\n",fname,bits256_str(str,wallet2pub));
if ( (confstr= OS_filestr(&allocsize,fname)) != 0 )
sprintf(destfname,"confs/%s",bits256_str(str,wallet2pub));
//printf("fname.(%s) wallet2pub.%s < [%s, %s]\n",destfname,bits256_str(str,wallet2pub),passphrase,fname2fa);
if ( (confstr= OS_filestr(&allocsize,destfname)) != 0 )
{
if ( (filejson= cJSON_Parse(confstr)) != 0 )
{
printf("confstr.(%s)\n",confstr);
//printf("confstr.(%s)\n",confstr);
if ( (deciphered= SuperNET_decipher(0,0,0,0,wallet2shared,curve25519(wallethash,curve25519_basepoint9()),jstr(filejson,"result"))) != 0 )
{
if ( (json= cJSON_Parse(deciphered)) == 0 )
printf("cant decipher (%s) [%s]\n",fname,confstr);
printf("cant decipher (%s) [%s]\n",destfname,confstr);
else
{
if ( (msgjson= cJSON_Parse(jstr(json,"message"))) == 0 )
@ -220,16 +220,16 @@ cJSON *SuperNET_decryptedjson(char *passphrase,int32_t passsize,bits256 walletha
}
free_json(filejson);
}
} else printf("couldnt load (%s)\n",fname);
} else printf("couldnt load (%s)\n",destfname);
}
else
{
sprintf(fname,"confs/iguana.conf");
if ( (confstr= OS_filestr(&allocsize,fname)) != 0 )
sprintf(destfname,"confs/iguana.conf");
if ( (confstr= OS_filestr(&allocsize,destfname)) != 0 )
{
if ( (json= cJSON_Parse(confstr)) != 0 )
msgjson = json;
} else printf("couldnt open (%s)\n",fname);
} else printf("couldnt open (%s)\n",destfname);
}
if ( msgjson != 0 )
msgjson = jduplicate(msgjson);
@ -251,7 +251,7 @@ int32_t _SuperNET_encryptjson(char *destfname,char *passphrase,int32_t passsize,
wallet2shared = SuperNET_wallet2shared(wallethash,wallet2priv);
wallet2pub = curve25519(wallet2shared,curve25519_basepoint9());
sprintf(destfname,"confs/%s",bits256_str(str,wallet2pub));
printf("SAVE ARGJSON.(%s)\n",jprint(argjson,0));
//printf("SAVE ARGJSON.(%s) [%s, %s] -> destfname.(%s)\n",jprint(argjson,0),passphrase,fname2fa,destfname);
//printf("shared.%llx -> pub.%s\n",(long long)wallet2shared.txid,bits256_str(str,wallet2pub));
SuperNET_savejsonfile(destfname,wallethash,wallet2pub,argjson);
return(0);
@ -320,7 +320,7 @@ char *SuperNET_keysinit(struct supernet_info *myinfo,char *argjsonstr)
wallethash = wallet2priv = GENESIS_PRIVKEY;
coinargs = SuperNET_parsemainargs(myinfo,&wallethash,&wallet2priv,argjsonstr);
//printf("wallethash.%s 2.(%s)\n",bits256_str(str,wallethash),bits256_str(str2,wallet2priv));
if ( (msgjson= SuperNET_decryptedjson(passphrase,sizeof(passphrase),wallethash,fname2fa,sizeof(fname2fa),wallet2priv)) != 0 )
if ( (msgjson= SuperNET_decryptedjson(destfname,passphrase,sizeof(passphrase),wallethash,fname2fa,sizeof(fname2fa),wallet2priv)) != 0 )
{
SuperNET_parsemyinfo(myinfo,msgjson);
free_json(msgjson);
@ -398,7 +398,7 @@ THREE_STRINGS(SuperNET,encryptjson,password,permanentfile,payload)
TWO_STRINGS(SuperNET,decryptjson,password,permanentfile)
{
char pass[8192],fname2[1023]; cJSON *retjson,*obj; bits256 wallethash,wallet2priv;
char pass[8192],fname2[1023],destfname[1024]; cJSON *retjson; bits256 wallethash,wallet2priv;
safecopy(pass,password,sizeof(pass));
safecopy(fname2,permanentfile,sizeof(fname2));
wallethash = wallet2priv = GENESIS_PRIVKEY;
@ -406,15 +406,12 @@ TWO_STRINGS(SuperNET,decryptjson,password,permanentfile)
wallethash = bits256_conv(pass);
if ( strlen(fname2) == sizeof(wallet2priv)*2 && is_hexstr(fname2,(int32_t)sizeof(bits256)*2) > 0 )
wallet2priv = bits256_conv(fname2);
printf("decrypt.(%s %s)\n",pass,fname2);
if ( (retjson= SuperNET_decryptedjson(pass,sizeof(pass),wallethash,fname2,sizeof(fname2),wallet2priv)) != 0 )
{
if ( 0 )
if ( (retjson= SuperNET_decryptedjson(destfname,pass,sizeof(pass),wallethash,fname2,sizeof(fname2),wallet2priv)) != 0 )
{
obj = jduplicate(jobj(retjson,"payload"));
jdelete(retjson,"payload");
jadd(retjson,"result",obj);
}
//printf("decrypt pass.(%s) fname2.(%s) -> destfname.(%s)\n",pass,fname2,destfname);
//obj = jduplicate(jobj(retjson,"payload"));
//jdelete(retjson,"payload");
//jadd(retjson,"result",obj);
return(jprint(retjson,1));
}
else return(clonestr("{\"error\":\"couldnt decrypt json file\"}"));

2
iguana/iguana_rpc.c

@ -359,7 +359,7 @@ static char *importwallet(RPCARGS)
static char *walletpassphrase(RPCARGS)
{
return(sglue3(0,CALLGLUE,"bitcoinrpc","walletpassphrase","passphrase",params[0],"permanentfile",params[2],"timeout",params[1]));
return(sglue3(0,CALLGLUE,"bitcoinrpc","walletpassphrase","password",params[0],"permanentfile",params[2],"timeout",params[1]));
}
static char *walletpassphrasechange(RPCARGS)

44
iguana/iguana_wallet.c

@ -189,6 +189,8 @@ void iguana_walletlock(struct supernet_info *myinfo)
memset(&myinfo->persistent_priv,0,sizeof(myinfo->persistent_priv));
memset(myinfo->secret,0,sizeof(myinfo->secret));
memset(myinfo->permanentfile,0,sizeof(myinfo->permanentfile));
if ( myinfo->decryptstr != 0 )
free(myinfo->decryptstr), myinfo->decryptstr = 0;
myinfo->expiration = 0;
//printf("wallet locked\n");
}
@ -335,8 +337,8 @@ int32_t iguana_loginsave(struct supernet_info *myinfo,struct iguana_info *coin,c
if ( (passphrase= jstr(loginjson,"passphrase")) != 0 )
{
_SuperNET_encryptjson(destfname,passphrase,0,myinfo->permanentfile,0,loginjson);
//printf("loginsave.(%s) <= (%s)\n",destfname,newstr);
//iguana_walletlock(myinfo);
printf("loginsave.(%s) <= (%s)\n",destfname,newstr);
}
free_json(loginjson);
return(0);
@ -348,7 +350,9 @@ int32_t iguana_payloadupdate(struct supernet_info *myinfo,struct iguana_info *co
cJSON *retjson,*accountobj,*payload,*obj; char *newstr; int32_t retval = -1;
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
payload = cJSON_DetachItemFromObject(retjson,"payload");
if ( account == 0 || account[0] == 0 )
account = "default";
payload = cJSON_DetachItemFromObject(retjson,"wallet");
if ( payload == 0 )
payload = cJSON_CreateObject();
if ( (accountobj= jobj(payload,account)) != 0 && (obj= jobj(accountobj,waddr->coinaddr)) != 0 )
@ -357,10 +361,15 @@ int32_t iguana_payloadupdate(struct supernet_info *myinfo,struct iguana_info *co
free_json(payload);
return(0);
}
jaddbits256(payload,waddr->coinaddr,waddr->privkey);
jadd(retjson,"payload",payload);
if ( accountobj == 0 )
{
accountobj = cJSON_CreateObject();
jaddbits256(accountobj,waddr->coinaddr,waddr->privkey);
jadd(payload,account,accountobj);
} else jaddbits256(accountobj,waddr->coinaddr,waddr->privkey);
jadd(retjson,"wallet",payload);
newstr = jprint(retjson,1);
printf("newstr.(%s)\n",newstr);
//printf("newstr.(%s)\n",newstr);
retval = iguana_loginsave(myinfo,coin,newstr);
free(newstr);
} else printf("iguana_payloadupdate: error parsing.(%s)\n",retstr);
@ -676,11 +685,30 @@ ZERO_ARGS(bitcoinrpc,repairwallet)
STRING_ARG(bitcoinrpc,dumpwallet,filename)
{
char *retstr,*walletstr; cJSON *retjson,*walletobj,*strobj;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->expiration != 0 )
return(SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,0));
else return(clonestr("{\"error\":\"wallet is locked, cant backup\"}"));
{
if ( (retstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,0)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (walletstr= myinfo->decryptstr) != 0 )
{
myinfo->decryptstr = 0;
if ( (strobj= cJSON_Parse(walletstr)) != 0 )
{
if ( (walletobj= jobj(strobj,"wallet")) != 0 )
jadd(retjson,"wallet",jduplicate(walletobj));
free_json(strobj);
}
}
return(jprint(retjson,1));
} else printf("cant parse retstr.(%s)\n",retstr);
} else return(clonestr("{\"error\":\"couldnt decrypt wallet\"}"));
}
return(clonestr("{\"error\":\"wallet is locked, cant backup\"}"));
}
// RZXuGgmzABFpXRmGJet8AbJoqVGEs27WgdvkSSXUMg7en8jjBW2m 2016-03-26T18:40:06Z reserve=1 # addr=GRVaqhY6XVWGeEabEEx5gE7mAQ7EYQi5JV
@ -713,7 +741,7 @@ STRING_ARG(bitcoinrpc,backupwallet,filename)
loginstr = myinfo->decryptstr, myinfo->decryptstr = 0;
if ( (retjson= cJSON_Parse(loginstr)) != 0 )
{
if ( (payloadstr= jstr(retjson,"payload")) != 0 )
if ( (payloadstr= jstr(retjson,"wallet")) != 0 )
retstr = iguana_payloadsave(filename,payloadstr);
free_json(retjson);
}

1
iguana/tests/backupwallet

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"method\":\"backupwallet\",\"params\":[\"testwallet\"]}"

1
iguana/tests/dumpwallet

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"method\":\"dumpwallet\",\"params\":[]}"

2
iguana/tests/encryptwallet

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"encryptwallet\",\"passphrase\":\"$1\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"encryptwallet\",\"passphrase\":\"test\"}"

2
iguana/tests/login

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"SuperNET\",\"method\":\"login\",\"passphrase\":\"$1\"}"
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"SuperNET\",\"method\":\"login\",\"passphrase\":\"test\"}"

3
iguana/tests/walletpassphrase

@ -1 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"walletpassphrase\",\"passphrase\":\"$1\",\"timeout\":$2}"
curl --url "http://127.0.0.1:7778" --data "{\"method\":\"walletpassphrase\",\"params\":[\"test\", 600]}"
#curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"walletpassphrase\",\"password\":\"test\",\"timeout\":300}"

Loading…
Cancel
Save