Mercurial > hg > marc_php
comparison marcus.php @ 4:c642254dc9ee draft default tip
Fixed transfer chain generation and construction of empty updates, some small improvements in tools
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sat, 22 Nov 2014 18:18:52 +0100 |
parents | 5c8c4fa95803 |
children |
comparison
equal
deleted
inserted
replaced
3:5c8c4fa95803 | 4:c642254dc9ee |
---|---|
66 case 'KEY': | 66 case 'KEY': |
67 switch (strtoupper($argv[$argi++])) { | 67 switch (strtoupper($argv[$argi++])) { |
68 case 'CREATE': | 68 case 'CREATE': |
69 $key = array('store' => TRUE); | 69 $key = array('store' => TRUE); |
70 $key['pk'] = nacl_crypto_sign_ed25519_keypair($key['sk'], randombytes(32)); | 70 $key['pk'] = nacl_crypto_sign_ed25519_keypair($key['sk'], randombytes(32)); |
71 $dbchanged = TRUE; | |
72 echo 'Created public key '.bin2hex($key['pk'])."\n"; | 71 echo 'Created public key '.bin2hex($key['pk'])."\n"; |
73 break; | 72 break; |
74 case 'FORGET': | 73 case 'FORGET': |
75 $key['store'] = FALSE; | 74 $key['store'] = FALSE; |
76 $dbchanged = TRUE; | |
77 break; | 75 break; |
78 case 'STORE': | 76 case 'STORE': |
79 $key['store'] = TRUE; | 77 $key['store'] = TRUE; |
80 $dbchanged = TRUE; | |
81 break; | 78 break; |
82 case 'USE': | 79 case 'USE': |
83 $key = array('store' => FALSE, 'pk' => $resource['key']); | 80 $key = array('store' => FALSE, 'pk' => $resource['key']); |
84 if (isset($resource['value']['seckey'])) $key['locked'] = $resource['value']['seckey']; | 81 if (isset($resource['value']['seckey'])) $key['locked'] = $resource['value']['seckey']; |
85 break; | 82 break; |
86 case 'IMPORT': | 83 case 'IMPORT': |
87 $key = array('store' => FALSE); | 84 $key = array('store' => FALSE); |
88 $key['pk'] = nacl_crypto_sign_ed25519_keypair($key['sk'], hex2bin($argv[$argi++])); | 85 $key['pk'] = nacl_crypto_sign_ed25519_keypair($key['sk'], hex2bin($argv[$argi++])); |
89 $dbchanged = TRUE; | |
90 break; | 86 break; |
91 case 'UNLOCK': | 87 case 'UNLOCK': |
92 if (!isset($key['locked'])) throw new Exception('The key is not locked'); | 88 if (!isset($key['locked'])) throw new Exception('The key is not locked'); |
93 if (!is_array($key['locked']) || !isset($key['locked']['key'])) throw new Exception('The locked key is invalid'); | 89 if (!is_array($key['locked']) || !isset($key['locked']['key'])) throw new Exception('The locked key is invalid'); |
94 $rounds = isset($key['locked']['rounds']) ? intval($key['locked']['rounds']) : 0; | 90 $rounds = isset($key['locked']['rounds']) ? intval($key['locked']['rounds']) : 0; |
219 $resource = array('label' => argtolabel($argv, $argi)); | 215 $resource = array('label' => argtolabel($argv, $argi)); |
220 break; | 216 break; |
221 case 'SELECT': | 217 case 'SELECT': |
222 if ($reschanged) echo "Warning: selected resource has not been updated.\n"; | 218 if ($reschanged) echo "Warning: selected resource has not been updated.\n"; |
223 $reschanged = FALSE; | 219 $reschanged = FALSE; |
224 $label = argtolabel($argv, $argi); | 220 if (strcasecmp($argv[$argi], 'TRANSFERCHAIN') == 0) { |
225 $resource = $database->GetResource($label); | 221 $resource = MARCUpdate::Decode($resource['transferchain']); |
226 if (!$resource) echo "Warning: resource ".labeltoname($label)." does not exist.\n"; | 222 if (!$resource) echo "Warning: failed to decode chained transfer data.\n"; |
227 else $resource = $resource->ToArray(); | 223 $argi++; |
224 } else { | |
225 $label = argtolabel($argv, $argi); | |
226 $resource = $database->GetResource($label); | |
227 if (!$resource) echo "Warning: resource ".labeltoname($label)." does not exist.\n"; | |
228 } | |
229 if ($resource) $resource = $resource->ToArray(); | |
228 break; | 230 break; |
229 case 'HELP': | 231 case 'HELP': |
230 print_help(); | 232 print_help(); |
231 break; | 233 break; |
232 default: | 234 default: |
268 default: | 270 default: |
269 if (preg_match('/^AS[0-9]{1-9}$/', $t)) return chr(3).marc_decode_int32be(substr($t, 2)); | 271 if (preg_match('/^AS[0-9]{1-9}$/', $t)) return chr(3).marc_decode_int32be(substr($t, 2)); |
270 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); | 272 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); |
271 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); | 273 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); |
272 if (preg_match('/^[a-f0-9]{64}$/i', $t)) return chr(0).hex2bin($t); | 274 if (preg_match('/^[a-f0-9]{64}$/i', $t)) return chr(0).hex2bin($t); |
273 if (preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}$/i', $t)) return chr(4).strtolower(trim($t, '.')); | 275 if (preg_match('/^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z0-9]{2,6}$/i', $t)) return chr(4).strtolower(trim($t, '.')); |
274 throw new Exception('Could not detect label type for '.$t); | 276 throw new Exception('Could not detect label type for '.$t); |
275 } | 277 } |
276 } | 278 } |
277 function ipnettolabel($s) { | 279 function ipnettolabel($s) { |
278 $ip = inet_pton(strtok($s, '/')); | 280 $ip = inet_pton(strtok($s, '/')); |
340 create ip|ip6|ipv6 [ipv6network] - create resource for IPv6 network | 342 create ip|ip6|ipv6 [ipv6network] - create resource for IPv6 network |
341 create dom|domain [ipv6network] - create resource for domain name | 343 create dom|domain [ipv6network] - create resource for domain name |
342 select [identifier] - select resource given by identifier | 344 select [identifier] - select resource given by identifier |
343 select currentkey - select key resource for current key pair | 345 select currentkey - select key resource for current key pair |
344 select resourcekey - select key resource for the key that signed the currently selected resource | 346 select resourcekey - select key resource for the key that signed the currently selected resource |
347 select transferchain - extract the chained transfer data from the currently selected resource | |
345 select label [identifier] - select resource by hexadecimal label | 348 select label [identifier] - select resource by hexadecimal label |
346 select key [publickey] - select key resource (hexadecimal) | 349 select key [publickey] - select key resource (hexadecimal) |
347 select ip|ip4|ipv4 [ipv4network] - select resource for IPv4 network | 350 select ip|ip4|ipv4 [ipv4network] - select resource for IPv4 network |
348 select ip|ip6|ipv6 [ipv6network] - select resource for IPv6 network | 351 select ip|ip6|ipv6 [ipv6network] - select resource for IPv6 network |
349 select dom|domain [ipv6network] - select resource for domain name | 352 select dom|domain [ipv6network] - select resource for domain name |