# HG changeset patch # User Ivo Smits # Date 1416676732 -3600 # Node ID c642254dc9ee643f116c4abed7ea66b6d48f6c87 # Parent 5c8c4fa95803d7ea0b61eb60bd7fcb1440ea0d61 Fixed transfer chain generation and construction of empty updates, some small improvements in tools diff -r 5c8c4fa95803 -r c642254dc9ee anoclaims.php --- a/anoclaims.php Mon Nov 17 01:19:05 2014 +0100 +++ b/anoclaims.php Sat Nov 22 18:18:52 2014 +0100 @@ -54,7 +54,7 @@ if (preg_match('/^AS[0-9]{1-9}$/', $t)) return chr(3).marc_decode_int32be(substr($argv[$argi++], 2)); if (preg_match('_^[0-9]{1-3}\.[0-9]{1-3}\.[0-9]{1-3}\.[0-9]{1-3}/[0-9]{1-2}$_', $t)) return ipv4tolabel($t); if (preg_match('_^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})\z/[0-9]{1-3}_i', $t)) return ipv6tolabel($t); - if (preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/i', $t)) return chr(4).strtolower(trim($t, '.')); + if (preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z0-9]{2,6}$/i', $t)) return chr(4).strtolower(trim($t, '.')); throw new Exception('Could not detect label type for '.$t); } function ipnettolabel($s) { diff -r 5c8c4fa95803 -r c642254dc9ee marccore.php --- a/marccore.php Mon Nov 17 01:19:05 2014 +0100 +++ b/marccore.php Sat Nov 22 18:18:52 2014 +0100 @@ -99,25 +99,22 @@ if (isset($upd['transfer']) && (strlen($upd['transfer']) != 0 && strlen($upd['transfer']) != NACL_CRYPTO_SIGN_ed25519_PUBLICKEYBYTES)) throw new Exception('Transfer recipient key is not valid'); if ($current) { unset($upd['transferchain']); - if (isset($current['transferchain']) && ($chain = self::Decode($current['transferchain'])) && $chain->Verify() && $chain->serial >= time() - 365*24*60*60 && isset($chain->transfer) && ($chain->transfer == $upd['key'] || ($upd['key'] == $current['key'] && !strlen($chain->transfer)))) { - $upd['transferchain'] = $current['transferchain']; - } elseif (isset($current['transfer']) && isset($current['updatemessage']) && $current['serial'] >= time() - 365*24*60*60 && isset($current['transfer']) && ($current['transfer'] == $upd['key'] || !strlen($current['transfer']))) { - $upd['transferchain'] = $current['updatemessage']; + if (isset($current['transferchain']) && ($chain = self::Decode($current['transferchain'])) && $chain->Verify() && ($current['key'] == $upd['key'] || ($chain->key == $current['key'] && $chain->serial == $current['serial']))) { + $chain = $chain; + } elseif (isset($current['updatemessage']) && $current['key'] != $upd['key']) { + $chain = $current; + } else { + $chain = NULL; } + while ($chain && $chain->key == $upd['key']) $chain = isset($chain->transferchain) ? self::Decode($chain->transferchain) : NULL; + if ($chain && $chain->Verify() && $chain->serial >= time() - 365*24*60*60) $upd['transferchain'] = $chain->updatemessage; } - if (isset($upd['transfer'])) { - if (isset($upd['transferchain'])) { - $chain = self::Decode($upd['transferchain']); - while ($chain && $chain->key == $upd['key']) $chain = ($chain->Verify() && $chain->serial >= time() - 365*24*60*60 && isset($chain->transferchain)) ? self::Decode($chain->transferchain) : NULL; - if ($chain && $chain->Verify() && $chain->serial >= time() - 365*24*60*60) $upd['transferchain'] = $chain->updatemessage; else unset($upd['transferchain']); - } - if (isset($upd['value']) && !is_null($upd['value'])) { - $chain = array('label' => $upd['label'], 'serial' => $upd['serial'], 'key' => $upd['key'], 'transfer' => $upd['transfer']); - if (isset($upd['expiration'])) $chain['expiration'] = $upd['expiration']; - if (isset($upd['transferchain'])) $chain['transferchain'] = $upd['transferchain']; - $chain = self::Create($chain, $seckey); - if ($chain && strlen($chain->updatemessage) <= 0xffff) $upd['transferchain'] = $chain->updatemessage; - } + if (isset($upd['transfer']) && isset($upd['value']) && !is_null($upd['value'])) { + $chain = array('label' => $upd['label'], 'serial' => $upd['serial'], 'key' => $upd['key'], 'transfer' => $upd['transfer']); + if (isset($upd['expiration'])) $chain['expiration'] = $upd['expiration']; + if (isset($upd['transferchain'])) $chain['transferchain'] = $upd['transferchain']; + $chain = self::Create($chain, $seckey); + if ($chain && strlen($chain->updatemessage) <= 0xffff) $upd['transferchain'] = $chain->updatemessage; } $data = marc_encode_int32be($upd['serial']); $data .= chr(strlen($upd['label'])).$upd['label']; @@ -133,7 +130,7 @@ if (strlen($item) > 0xffff) throw new Exception('Extension data too big'); $data .= chr($identifier).marc_encode_int16be(strlen($item)).$item; } - if (isset($upd['value'])) $data .= self::EncodeValue($upd['value']); + $data .= self::EncodeValue(isset($upd['value']) ? $upd['value'] : NULL); $data = nacl_crypto_sign_ed25519($data, $seckey); if (!strlen($data)) throw new Exception('Failed to sign data'); if (!strlen(nacl_crypto_sign_ed25519_open($data, $upd['key']))) throw new Exception('Key pair is not valid'); diff -r 5c8c4fa95803 -r c642254dc9ee marcus.php --- a/marcus.php Mon Nov 17 01:19:05 2014 +0100 +++ b/marcus.php Sat Nov 22 18:18:52 2014 +0100 @@ -68,16 +68,13 @@ case 'CREATE': $key = array('store' => TRUE); $key['pk'] = nacl_crypto_sign_ed25519_keypair($key['sk'], randombytes(32)); - $dbchanged = TRUE; echo 'Created public key '.bin2hex($key['pk'])."\n"; break; case 'FORGET': $key['store'] = FALSE; - $dbchanged = TRUE; break; case 'STORE': $key['store'] = TRUE; - $dbchanged = TRUE; break; case 'USE': $key = array('store' => FALSE, 'pk' => $resource['key']); @@ -86,7 +83,6 @@ case 'IMPORT': $key = array('store' => FALSE); $key['pk'] = nacl_crypto_sign_ed25519_keypair($key['sk'], hex2bin($argv[$argi++])); - $dbchanged = TRUE; break; case 'UNLOCK': if (!isset($key['locked'])) throw new Exception('The key is not locked'); @@ -221,10 +217,16 @@ case 'SELECT': if ($reschanged) echo "Warning: selected resource has not been updated.\n"; $reschanged = FALSE; - $label = argtolabel($argv, $argi); - $resource = $database->GetResource($label); - if (!$resource) echo "Warning: resource ".labeltoname($label)." does not exist.\n"; - else $resource = $resource->ToArray(); + if (strcasecmp($argv[$argi], 'TRANSFERCHAIN') == 0) { + $resource = MARCUpdate::Decode($resource['transferchain']); + if (!$resource) echo "Warning: failed to decode chained transfer data.\n"; + $argi++; + } else { + $label = argtolabel($argv, $argi); + $resource = $database->GetResource($label); + if (!$resource) echo "Warning: resource ".labeltoname($label)." does not exist.\n"; + } + if ($resource) $resource = $resource->ToArray(); break; case 'HELP': print_help(); @@ -270,7 +272,7 @@ if (preg_match('_^[0-9]{1-3}\.[0-9]{1-3}\.[0-9]{1-3}\.[0-9]{1-3}/[0-9]{1-2}$_', $t)) return ipnettolabel($t); if (preg_match('_^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})\z/[0-9]{1-3}_i', $t)) return ipnettolabel($t); if (preg_match('/^[a-f0-9]{64}$/i', $t)) return chr(0).hex2bin($t); - if (preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/i', $t)) return chr(4).strtolower(trim($t, '.')); + if (preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z0-9]{2,6}$/i', $t)) return chr(4).strtolower(trim($t, '.')); throw new Exception('Could not detect label type for '.$t); } } @@ -342,6 +344,7 @@ select [identifier] - select resource given by identifier select currentkey - select key resource for current key pair select resourcekey - select key resource for the key that signed the currently selected resource +select transferchain - extract the chained transfer data from the currently selected resource select label [identifier] - select resource by hexadecimal label select key [publickey] - select key resource (hexadecimal) select ip|ip4|ipv4 [ipv4network] - select resource for IPv4 network