From 2de1285121b5f0260699a93249bab11dc74edec5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 16 Jan 2018 18:15:58 -0800 Subject: z6 deliver --- Zotlabs/Web/HTTPSig.php | 15 ++++++++++ include/queue_fn.php | 19 +++++++++++- include/zot.php | 79 ++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 104 insertions(+), 9 deletions(-) diff --git a/Zotlabs/Web/HTTPSig.php b/Zotlabs/Web/HTTPSig.php index 63033ce5e..ef03dac94 100644 --- a/Zotlabs/Web/HTTPSig.php +++ b/Zotlabs/Web/HTTPSig.php @@ -137,6 +137,21 @@ class HTTPSig { } } + + if(in_array('x-zot-digest',$signed_headers)) { + $result['content_signed'] = true; + $digest = explode('=', $headers['x-zot-digest']); + if($digest[0] === 'SHA-256') + $hashalg = 'sha256'; + if($digest[0] === 'SHA-512') + $hashalg = 'sha512'; + + // The explode operation will have stripped the '=' padding, so compare against unpadded base64 + if(rtrim(base64_encode(hash($hashalg,$_POST['data'],true)),'=') === $digest[1]) { + $result['content_valid'] = true; + } + } + logger('Content_Valid: ' . $result['content_valid']); return $result; diff --git a/include/queue_fn.php b/include/queue_fn.php index 5fb0d5f1e..88da90479 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -216,7 +216,24 @@ function queue_deliver($outq, $immediate = false) { // normal zot delivery logger('deliver: dest: ' . $outq['outq_posturl'], LOGGER_DEBUG); - $result = zot_zot($outq['outq_posturl'],$outq['outq_notify']); + + + + $msg = $outq['outq_notify']; + $channel = null; + + if($outq['outq_msg']) { + $tmp = json_decode($msg,true); + $tmp['pickup'] = json_decode($outq['outq_msg'],true); + $msg = json_encode($tmp); + if($outq['outq_channel']) { + $channel = channelx_by_n($outq['outq_channel']); + } + } + + $result = zot_zot($outq['outq_posturl'],$msg,$channel); + + if($result['success']) { logger('deliver: remote zot delivery succeeded to ' . $outq['outq_posturl']); zot_process_response($outq['outq_posturl'],$result, $outq); diff --git a/include/zot.php b/include/zot.php index 8e3d03ad8..1ab858480 100644 --- a/include/zot.php +++ b/include/zot.php @@ -211,8 +211,19 @@ function zot_best_algorithm($methods) { * @param array $data * @return array see z_post_url() for returned data format */ -function zot_zot($url, $data) { - return z_post_url($url, array('data' => $data)); +function zot_zot($url, $data, $channel = null) { + + $headers = []; + + if($channel) { + $headers['X-Zot-Token'] = random_string(); + $hash = \Zotlabs\Web\HTTPSig::generate_digest($data,false); + $headers['X-Zot-Digest'] = 'SHA-256=' . $hash; + \Zotlabs\Web\HTTPSig::create_sig('',$headers,$channel['channel_prvkey'],'acct:' . $channel['channel_address'] . '@' . \App::get_hostname(),false,true,'sha512'); + } + + $redirects = 0; + return z_post_url($url, array('data' => $data),$redirects,((is_empty($headers)) ? [] : [ 'headers' => $headers ])); } /** @@ -4967,21 +4978,73 @@ function zot_reply_refresh($sender, $recipients) { } +function zot6_check_sig() { + + $ret = [ 'success' => false ]; + + foreach([ 'REDIRECT_REMOTE_USER', 'HTTP_AUTHORIZATION' ] as $head) { + if(array_key_exists($head,$_SERVER) && substr(trim($_SERVER[$head]),0,9) === 'Signature') { + if($head !== 'HTTP_AUTHORIZATION') { + $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER[$head]; + continue; + } + + $sigblock = \Zotlabs\Web\HTTPSig::parse_sigheader($_SERVER[$head]); + if($sigblock) { + $keyId = $sigblock['keyId']; + + if($keyId) { + $r = q("select hubloc.*, site_crypto from hubloc left join site on hubloc_url = site_url + where hubloc_addr = '%s' ", + dbesc(str_replace('acct:','',$keyId)) + ); + if($r) { + foreach($r as $hubloc) { + $verified = \Zotlabs\Web\HTTPSig::verify('',$hubloc['xchan_pubkey']); + if($verified && $verified['header_signed'] && $verified['header_valid'] && $verified['content_signed'] && $verified['content_valid']) { + $ret['hubloc'] = $hubloc; + $ret['success'] = true; + return $ret; + } + } + } + } + } + } + } + + return $ret; +} + function zot_reply_notify($data) { $ret = array('success' => false); logger('notify received from ' . $data['sender']['url']); - $async = get_config('system','queued_fetch'); + // handle zot6 delivery - if($async) { - // add to receive queue - // qreceive_add($data); + $zret = zot6_check_sig(); + if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $data['sender']['guid']) { + logger('zot6_delivery'); + logger('zot6_data: ' . print_r($data,true),LOGGER_DATA); + $x = zot_import($data,$data['sender']['url']); + if($x) { + $x = crypto_encapsulate(json_encode($x),$zret['hubloc']['hubloc_sitekey'],zot_best_algorithm($zret['hubloc']['site_crypto'])); + $ret['delivery_report'] = $x; + } } else { - $x = zot_fetch($data); - $ret['delivery_report'] = $x; + $async = get_config('system','queued_fetch'); + + if($async) { + // add to receive queue + // qreceive_add($data); + } + else { + $x = zot_fetch($data); + $ret['delivery_report'] = $x; + } } $ret['success'] = true; -- cgit v1.2.3 From 05de59d4ad174cb106c3a5b5890732af51730384 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 16 Jan 2018 20:08:10 -0800 Subject: initial z6 delivery --- Zotlabs/Daemon/Queue.php | 4 ++-- include/queue_fn.php | 12 ++++++------ include/zot.php | 50 ++++++++++++++++++++++-------------------------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/Zotlabs/Daemon/Queue.php b/Zotlabs/Daemon/Queue.php index 17d150250..1bab582bc 100644 --- a/Zotlabs/Daemon/Queue.php +++ b/Zotlabs/Daemon/Queue.php @@ -13,8 +13,8 @@ class Queue { require_once('include/bbcode.php'); - if(argc() > 1) - $queue_id = argv(1); + if($argc > 1) + $queue_id = $argv[1]; else $queue_id = 0; diff --git a/include/queue_fn.php b/include/queue_fn.php index 88da90479..d1c50de67 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -217,19 +217,19 @@ function queue_deliver($outq, $immediate = false) { logger('deliver: dest: ' . $outq['outq_posturl'], LOGGER_DEBUG); - - - $msg = $outq['outq_notify']; $channel = null; if($outq['outq_msg']) { - $tmp = json_decode($msg,true); - $tmp['pickup'] = json_decode($outq['outq_msg'],true); - $msg = json_encode($tmp); + $msg = json_decode($outq['outq_notify'],true); + $msg['pickup'] = [ 'notify' => json_decode($outq['outq_notify'],true), 'message' => json_decode($outq['outq_msg'],true) ]; + $msg = json_encode($msg); if($outq['outq_channel']) { $channel = channelx_by_n($outq['outq_channel']); } } + else { + $msg = $outq['outq_notify']; + } $result = zot_zot($outq['outq_posturl'],$msg,$channel); diff --git a/include/zot.php b/include/zot.php index 1ab858480..d97fe8113 100644 --- a/include/zot.php +++ b/include/zot.php @@ -219,11 +219,11 @@ function zot_zot($url, $data, $channel = null) { $headers['X-Zot-Token'] = random_string(); $hash = \Zotlabs\Web\HTTPSig::generate_digest($data,false); $headers['X-Zot-Digest'] = 'SHA-256=' . $hash; - \Zotlabs\Web\HTTPSig::create_sig('',$headers,$channel['channel_prvkey'],'acct:' . $channel['channel_address'] . '@' . \App::get_hostname(),false,true,'sha512'); + $h = \Zotlabs\Web\HTTPSig::create_sig('',$headers,$channel['channel_prvkey'],'acct:' . $channel['channel_address'] . '@' . \App::get_hostname(),false,false,'sha512'); } $redirects = 0; - return z_post_url($url, array('data' => $data),$redirects,((is_empty($headers)) ? [] : [ 'headers' => $headers ])); + return z_post_url($url, array('data' => $data),$redirects,((empty($h)) ? [] : [ 'headers' => $h ])); } /** @@ -4982,30 +4982,26 @@ function zot6_check_sig() { $ret = [ 'success' => false ]; - foreach([ 'REDIRECT_REMOTE_USER', 'HTTP_AUTHORIZATION' ] as $head) { - if(array_key_exists($head,$_SERVER) && substr(trim($_SERVER[$head]),0,9) === 'Signature') { - if($head !== 'HTTP_AUTHORIZATION') { - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER[$head]; - continue; - } - - $sigblock = \Zotlabs\Web\HTTPSig::parse_sigheader($_SERVER[$head]); - if($sigblock) { - $keyId = $sigblock['keyId']; - - if($keyId) { - $r = q("select hubloc.*, site_crypto from hubloc left join site on hubloc_url = site_url - where hubloc_addr = '%s' ", - dbesc(str_replace('acct:','',$keyId)) - ); - if($r) { - foreach($r as $hubloc) { - $verified = \Zotlabs\Web\HTTPSig::verify('',$hubloc['xchan_pubkey']); - if($verified && $verified['header_signed'] && $verified['header_valid'] && $verified['content_signed'] && $verified['content_valid']) { - $ret['hubloc'] = $hubloc; - $ret['success'] = true; - return $ret; - } +logger('server: ' . print_r($_SERVER,true)); + + if(array_key_exists('HTTP_SIGNATURE',$_SERVER)) { +logger('parsing signature header'); + $sigblock = \Zotlabs\Web\HTTPSig::parse_sigheader($_SERVER['HTTP_SIGNATURE']); + if($sigblock) { + $keyId = $sigblock['keyId']; + + if($keyId) { + $r = q("select hubloc.*, site_crypto from hubloc left join site on hubloc_url = site_url + where hubloc_addr = '%s' ", + dbesc(str_replace('acct:','',$keyId)) + ); + if($r) { + foreach($r as $hubloc) { + $verified = \Zotlabs\Web\HTTPSig::verify('',$hubloc['xchan_pubkey']); + if($verified && $verified['header_signed'] && $verified['header_valid'] && $verified['content_signed'] && $verified['content_valid']) { + $ret['hubloc'] = $hubloc; + $ret['success'] = true; + return $ret; } } } @@ -5028,7 +5024,7 @@ function zot_reply_notify($data) { if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $data['sender']['guid']) { logger('zot6_delivery'); logger('zot6_data: ' . print_r($data,true),LOGGER_DATA); - $x = zot_import($data,$data['sender']['url']); + $x = zot_import([ 'body' => json_encode($data) ],$data['sender']['url']); if($x) { $x = crypto_encapsulate(json_encode($x),$zret['hubloc']['hubloc_sitekey'],zot_best_algorithm($zret['hubloc']['site_crypto'])); $ret['delivery_report'] = $x; -- cgit v1.2.3 From 3a0db39fa05668831e7661ac6edaabfd09d864e2 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Feb 2018 18:38:10 -0800 Subject: more zot6 delivery work --- Zotlabs/Daemon/Notifier.php | 4 +-- include/queue_fn.php | 14 +++----- include/zot.php | 86 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 13 deletions(-) diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index b168db5ae..957b859af 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -618,8 +618,8 @@ class Notifier { $packet = zot_build_packet($channel,$packet_type,(($packet_recips) ? $packet_recips : null)); } if($packet_type === 'keychange') { - $packet = zot_build_packet($channel,$packet_type,(($packet_recips) ? $packet_recips : null)); $pmsg = get_pconfig($channel['channel_id'],'system','keychange'); + $packet = zot_build_packet($channel,$packet_type,(($packet_recips) ? $packet_recips : null)); } elseif($packet_type === 'request') { $env = (($hub_env && $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']]) ? $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']] : ''); @@ -640,7 +640,7 @@ class Notifier { } else { $env = (($hub_env && $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']]) ? $hub_env[$hub['hubloc_host'] . $hub['hubloc_sitekey']] : ''); - $packet = zot_build_packet($channel,'notify',$env,(($private) ? $hub['hubloc_sitekey'] : null), $hub['site_crypto'],$hash); + $packet = zot6_build_packet($channel,'notify',$env, json_encode($encoded_item), (($private) ? $hub['hubloc_sitekey'] : null), $hub['site_crypto'],$hash); queue_insert( [ 'hash' => $hash, diff --git a/include/queue_fn.php b/include/queue_fn.php index d1c50de67..d31e41b61 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -219,18 +219,12 @@ function queue_deliver($outq, $immediate = false) { $channel = null; - if($outq['outq_msg']) { - $msg = json_decode($outq['outq_notify'],true); - $msg['pickup'] = [ 'notify' => json_decode($outq['outq_notify'],true), 'message' => json_decode($outq['outq_msg'],true) ]; - $msg = json_encode($msg); - if($outq['outq_channel']) { - $channel = channelx_by_n($outq['outq_channel']); - } - } - else { - $msg = $outq['outq_notify']; + if($outq['outq_msg'] && $outq['outq_channel']) { + $channel = channelx_by_n($outq['outq_channel']); } + $msg = $outq['outq_notify']; + $result = zot_zot($outq['outq_posturl'],$msg,$channel); diff --git a/include/zot.php b/include/zot.php index d97fe8113..e8ed827e2 100644 --- a/include/zot.php +++ b/include/zot.php @@ -158,6 +158,85 @@ function zot_build_packet($channel, $type = 'notify', $recipients = null, $remot return json_encode($data); } + +/** + * @brief Builds a zot6 notification packet. + * + * Builds a zot6 notification packet that you can either store in the queue with + * a message array or call zot_zot to immediately zot it to the other side. + * + * @param array $channel + * sender channel structure + * @param string $type + * packet type: one of 'ping', 'pickup', 'purge', 'refresh', 'keychange', 'force_refresh', 'notify', 'auth_check' + * @param array $recipients + * envelope information, array ( 'guid' => string, 'guid_sig' => string ); empty for public posts + * @param string $remote_key + * optional public site key of target hub used to encrypt entire packet + * NOTE: remote_key and encrypted packets are required for 'auth_check' packets, optional for all others + * @param string $methods + * optional comma separated list of encryption methods @ref zot_best_algorithm() + * @param string $secret + * random string, required for packets which require verification/callback + * e.g. 'pickup', 'purge', 'notify', 'auth_check'. Packet types 'ping', 'force_refresh', and 'refresh' do not require verification + * @param string $extra + * @returns string json encoded zot packet + */ +function zot6_build_packet($channel, $type = 'notify', $recipients = null, $msg = '', $remote_key = null, $methods = '', $secret = null, $extra = null) { + + $sig_method = get_config('system','signature_algorithm','sha256'); + + $data = [ + 'type' => $type, + 'sender' => [ + 'guid' => $channel['channel_guid'], + 'guid_sig' => base64url_encode(rsa_sign($channel['channel_guid'],$channel['channel_prvkey'],$sig_method)), + 'url' => z_root(), + 'url_sig' => base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey'],$sig_method)), + 'sitekey' => get_config('system','pubkey') + ], + 'callback' => '/post', + 'version' => Zotlabs\Lib\System::get_zot_revision(), + 'encryption' => crypto_methods(), + 'signing' => signing_methods() + ]; + + if ($recipients) { + for ($x = 0; $x < count($recipients); $x ++) + unset($recipients[$x]['hash']); + + $data['recipients'] = $recipients; + } + + if($msg) { + $data['msg'] = $msg; + } + + if ($secret) { + $data['secret'] = preg_replace('/[^0-9a-fA-F]/','',$secret); + $data['secret_sig'] = base64url_encode(rsa_sign($secret,$channel['channel_prvkey'],$sig_method)); + } + + if ($extra) { + foreach ($extra as $k => $v) + $data[$k] = $v; + } + + logger('zot6_build_packet: ' . print_r($data,true), LOGGER_DATA, LOG_DEBUG); + + // Hush-hush ultra top-secret mode + + if($remote_key) { + $algorithm = zot_best_algorithm($methods); + $data = crypto_encapsulate(json_encode($data),$remote_key, $algorithm); + } + + return json_encode($data); +} + + + + /** * @brief Choose best encryption function from those available on both sites. * @@ -5024,7 +5103,12 @@ function zot_reply_notify($data) { if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $data['sender']['guid']) { logger('zot6_delivery'); logger('zot6_data: ' . print_r($data,true),LOGGER_DATA); - $x = zot_import([ 'body' => json_encode($data) ],$data['sender']['url']); + $import = [ 'pickup' => [ [ 'notify' => $data, 'message' => $data['msg'] ] ] ]; + unset($import['pickup'][0]['notify']['msg']); + + logger('import: ' . print_r($import,true), LOGGER_DATA); + + $x = zot_import([ 'body' => json_encode($import) ],$data['sender']['url']); if($x) { $x = crypto_encapsulate(json_encode($x),$zret['hubloc']['hubloc_sitekey'],zot_best_algorithm($zret['hubloc']['site_crypto'])); $ret['delivery_report'] = $x; -- cgit v1.2.3 From 5057a4bd4cfa34ef9821889e8b11707f495d64f0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Feb 2018 19:15:56 -0800 Subject: zot6 delivery work --- include/zot.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/zot.php b/include/zot.php index e8ed827e2..b44991fab 100644 --- a/include/zot.php +++ b/include/zot.php @@ -5101,10 +5101,10 @@ function zot_reply_notify($data) { $zret = zot6_check_sig(); if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $data['sender']['guid']) { - logger('zot6_delivery'); + logger('zot6_delivery',LOGGER_DEBUG); logger('zot6_data: ' . print_r($data,true),LOGGER_DATA); - $import = [ 'pickup' => [ [ 'notify' => $data, 'message' => $data['msg'] ] ] ]; - unset($import['pickup'][0]['notify']['msg']); + $import = [ 'success' => true, 'pickup' => [ [ 'notify' => $data, 'message' => json_decode($data['msg'],true) ] ] ]; + // unset($import['pickup'][0]['notify']['msg']); logger('import: ' . print_r($import,true), LOGGER_DATA); -- cgit v1.2.3 From b21a5c3ce902c4c88b2bb3dcae5d63a93e25479c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Feb 2018 20:17:32 -0800 Subject: compatibility: fallback to legacy zot if OWA succeeds but no data['msg'] is present --- include/zot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/zot.php b/include/zot.php index b44991fab..5fb18d5a7 100644 --- a/include/zot.php +++ b/include/zot.php @@ -5100,7 +5100,7 @@ function zot_reply_notify($data) { // handle zot6 delivery $zret = zot6_check_sig(); - if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $data['sender']['guid']) { + if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $data['sender']['guid'] && $data['msg']) { logger('zot6_delivery',LOGGER_DEBUG); logger('zot6_data: ' . print_r($data,true),LOGGER_DATA); $import = [ 'success' => true, 'pickup' => [ [ 'notify' => $data, 'message' => json_decode($data['msg'],true) ] ] ]; -- cgit v1.2.3 From 6cf2e9945a08451e3d53b6e79002843e9cdb8dc6 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Feb 2018 21:53:47 -0800 Subject: encrypt the httpsig for zot6 transport --- include/queue_fn.php | 22 ++++++++++++++++++++-- include/zot.php | 6 ++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/queue_fn.php b/include/queue_fn.php index d31e41b61..e50d58dd7 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -121,7 +121,7 @@ function queue_deliver($outq, $immediate = false) { $base = null; $h = parse_url($outq['outq_posturl']); - if($h) + if($h !== false) $base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : ''); if(($base) && ($base !== z_root()) && ($immediate)) { @@ -160,6 +160,9 @@ function queue_deliver($outq, $immediate = false) { + + + $arr = array('outq' => $outq, 'base' => $base, 'handled' => false, 'immediate' => $immediate); call_hooks('queue_deliver',$arr); if($arr['handled']) @@ -223,9 +226,24 @@ function queue_deliver($outq, $immediate = false) { $channel = channelx_by_n($outq['outq_channel']); } + $host_crypto = null; + + if($channel && $base) { + $h = q("select hubloc_sitekey, site_crypto from hubloc left join site on hubloc_url = site_url where site_url = '%s' order by hubloc_id desc limit 1", + dbesc($base) + ); + if($h) { + $host_crypto = $h[0]; + } + } + + + + + $msg = $outq['outq_notify']; - $result = zot_zot($outq['outq_posturl'],$msg,$channel); + $result = zot_zot($outq['outq_posturl'],$msg,$channel,$host_crypto); if($result['success']) { diff --git a/include/zot.php b/include/zot.php index 5fb18d5a7..c00caebb4 100644 --- a/include/zot.php +++ b/include/zot.php @@ -288,9 +288,11 @@ function zot_best_algorithm($methods) { * * @param string $url * @param array $data + * @param array $channel (optional if using zot6 delivery) + * @param array $crypto (optional if encrypted httpsig, requires hubloc_sitekey and site_crypto elements) * @return array see z_post_url() for returned data format */ -function zot_zot($url, $data, $channel = null) { +function zot_zot($url, $data, $channel = null,$crypto = null) { $headers = []; @@ -298,7 +300,7 @@ function zot_zot($url, $data, $channel = null) { $headers['X-Zot-Token'] = random_string(); $hash = \Zotlabs\Web\HTTPSig::generate_digest($data,false); $headers['X-Zot-Digest'] = 'SHA-256=' . $hash; - $h = \Zotlabs\Web\HTTPSig::create_sig('',$headers,$channel['channel_prvkey'],'acct:' . $channel['channel_address'] . '@' . \App::get_hostname(),false,false,'sha512'); + $h = \Zotlabs\Web\HTTPSig::create_sig('',$headers,$channel['channel_prvkey'],'acct:' . $channel['channel_address'] . '@' . \App::get_hostname(),false,false,'sha512',(($crypto) ? $crypto['hubloc_sitekey'] : ''), (($crypto) ? zot_best_algorithm($crypto['site_crypto']) : '')); } $redirects = 0; -- cgit v1.2.3 From 4c27fa5c37fbe4fc6debaadeaf3b4b134bc9068b Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 7 Feb 2018 22:04:53 -0800 Subject: debug the crypto function --- Zotlabs/Web/HTTPSig.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Zotlabs/Web/HTTPSig.php b/Zotlabs/Web/HTTPSig.php index ef03dac94..8c94a4ff0 100644 --- a/Zotlabs/Web/HTTPSig.php +++ b/Zotlabs/Web/HTTPSig.php @@ -210,6 +210,9 @@ class HTTPSig { if($crypt_key) { $x = crypto_encapsulate($headerval,$crypt_key,$crypt_alg); + +logger(cryptosig: ' . print_r($x,true)); + $headerval = 'iv="' . $x['iv'] . '",key="' . $x['key'] . '",alg="' . $x['alg'] . '",data="' . $x['data']; } -- cgit v1.2.3 From 635c5e532bd945fe50dc3fae73e4da005158e3de Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 8 Feb 2018 15:32:54 -0800 Subject: z6 testing --- Zotlabs/Web/HTTPSig.php | 2 +- include/queue_fn.php | 4 ---- include/zot.php | 2 ++ 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Zotlabs/Web/HTTPSig.php b/Zotlabs/Web/HTTPSig.php index 8c94a4ff0..dba5c4687 100644 --- a/Zotlabs/Web/HTTPSig.php +++ b/Zotlabs/Web/HTTPSig.php @@ -209,7 +209,7 @@ class HTTPSig { . '",headers="' . $x['headers'] . '",signature="' . $x['signature'] . '"'; if($crypt_key) { - $x = crypto_encapsulate($headerval,$crypt_key,$crypt_alg); + $x = crypto_encapsulate($headerval,$crypt_key,$crypt_algo); logger(cryptosig: ' . print_r($x,true)); diff --git a/include/queue_fn.php b/include/queue_fn.php index e50d58dd7..798ac36db 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -237,10 +237,6 @@ function queue_deliver($outq, $immediate = false) { } } - - - - $msg = $outq['outq_notify']; $result = zot_zot($outq['outq_posturl'],$msg,$channel,$host_crypto); diff --git a/include/zot.php b/include/zot.php index c00caebb4..16b0a1c8e 100644 --- a/include/zot.php +++ b/include/zot.php @@ -296,6 +296,8 @@ function zot_zot($url, $data, $channel = null,$crypto = null) { $headers = []; +logger('crypto: ' . print_r($crypto,true)); + if($channel) { $headers['X-Zot-Token'] = random_string(); $hash = \Zotlabs\Web\HTTPSig::generate_digest($data,false); -- cgit v1.2.3 From e4503f743e0a51ebb91401746bcfa800dd890dc9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 8 Feb 2018 15:36:22 -0800 Subject: logging --- Zotlabs/Web/HTTPSig.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Zotlabs/Web/HTTPSig.php b/Zotlabs/Web/HTTPSig.php index dba5c4687..a6b8d67a4 100644 --- a/Zotlabs/Web/HTTPSig.php +++ b/Zotlabs/Web/HTTPSig.php @@ -194,6 +194,8 @@ class HTTPSig { static function create_sig($request,$head,$prvkey,$keyid = 'Key',$send_headers = false,$auth = false,$alg = 'sha256', $crypt_key = null, $crypt_algo = 'aes256ctr') { +logger('cryptkey' . $crypt_key); + $return_headers = []; if($alg === 'sha256') { @@ -211,7 +213,7 @@ class HTTPSig { if($crypt_key) { $x = crypto_encapsulate($headerval,$crypt_key,$crypt_algo); -logger(cryptosig: ' . print_r($x,true)); +logger('cryptosig: ' . print_r($x,true)); $headerval = 'iv="' . $x['iv'] . '",key="' . $x['key'] . '",alg="' . $x['alg'] . '",data="' . $x['data']; } -- cgit v1.2.3 From beec49847f54d89f15b205482cbf375782553527 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 8 Feb 2018 15:45:33 -0800 Subject: missing quote --- Zotlabs/Web/HTTPSig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zotlabs/Web/HTTPSig.php b/Zotlabs/Web/HTTPSig.php index a6b8d67a4..0b264ca7a 100644 --- a/Zotlabs/Web/HTTPSig.php +++ b/Zotlabs/Web/HTTPSig.php @@ -215,7 +215,7 @@ logger('cryptkey' . $crypt_key); logger('cryptosig: ' . print_r($x,true)); - $headerval = 'iv="' . $x['iv'] . '",key="' . $x['key'] . '",alg="' . $x['alg'] . '",data="' . $x['data']; + $headerval = 'iv="' . $x['iv'] . '",key="' . $x['key'] . '",alg="' . $x['alg'] . '",data="' . $x['data'] . '"'; } if($auth) { -- cgit v1.2.3 From cd1e5d417167836ee5ac64d042815b377c22b694 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 8 Feb 2018 16:22:10 -0800 Subject: zot6 testing --- Zotlabs/Web/HTTPSig.php | 7 +------ include/zot.php | 12 ++++++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Zotlabs/Web/HTTPSig.php b/Zotlabs/Web/HTTPSig.php index 0b264ca7a..a27edb73d 100644 --- a/Zotlabs/Web/HTTPSig.php +++ b/Zotlabs/Web/HTTPSig.php @@ -152,7 +152,7 @@ class HTTPSig { } } - logger('Content_Valid: ' . $result['content_valid']); + logger('Content_Valid: ' . (($result['content_valid']) ? 'true' : 'false')); return $result; @@ -194,8 +194,6 @@ class HTTPSig { static function create_sig($request,$head,$prvkey,$keyid = 'Key',$send_headers = false,$auth = false,$alg = 'sha256', $crypt_key = null, $crypt_algo = 'aes256ctr') { -logger('cryptkey' . $crypt_key); - $return_headers = []; if($alg === 'sha256') { @@ -212,9 +210,6 @@ logger('cryptkey' . $crypt_key); if($crypt_key) { $x = crypto_encapsulate($headerval,$crypt_key,$crypt_algo); - -logger('cryptosig: ' . print_r($x,true)); - $headerval = 'iv="' . $x['iv'] . '",key="' . $x['key'] . '",alg="' . $x['alg'] . '",data="' . $x['data'] . '"'; } diff --git a/include/zot.php b/include/zot.php index 16b0a1c8e..331ec35e3 100644 --- a/include/zot.php +++ b/include/zot.php @@ -296,8 +296,6 @@ function zot_zot($url, $data, $channel = null,$crypto = null) { $headers = []; -logger('crypto: ' . print_r($crypto,true)); - if($channel) { $headers['X-Zot-Token'] = random_string(); $hash = \Zotlabs\Web\HTTPSig::generate_digest($data,false); @@ -5107,18 +5105,24 @@ function zot_reply_notify($data) { if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $data['sender']['guid'] && $data['msg']) { logger('zot6_delivery',LOGGER_DEBUG); logger('zot6_data: ' . print_r($data,true),LOGGER_DATA); + + $ret['collected'] = true; + $import = [ 'success' => true, 'pickup' => [ [ 'notify' => $data, 'message' => json_decode($data['msg'],true) ] ] ]; - // unset($import['pickup'][0]['notify']['msg']); + unset($import['pickup'][0]['notify']['msg']); logger('import: ' . print_r($import,true), LOGGER_DATA); - $x = zot_import([ 'body' => json_encode($import) ],$data['sender']['url']); + $x = zot_import([ 'success' => true, 'body' => json_encode($import) ], $data['sender']['url']); if($x) { $x = crypto_encapsulate(json_encode($x),$zret['hubloc']['hubloc_sitekey'],zot_best_algorithm($zret['hubloc']['site_crypto'])); $ret['delivery_report'] = $x; } } else { + + // handle traditional zot delivery + $async = get_config('system','queued_fetch'); if($async) { -- cgit v1.2.3 From 9f5d44fa32b1ef9e103f98dcf7d68bfef1fdd94f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 8 Feb 2018 16:30:44 -0800 Subject: turn the logs down again --- include/zot.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/zot.php b/include/zot.php index 331ec35e3..1a9909de1 100644 --- a/include/zot.php +++ b/include/zot.php @@ -5063,10 +5063,9 @@ function zot6_check_sig() { $ret = [ 'success' => false ]; -logger('server: ' . print_r($_SERVER,true)); + logger('server: ' . print_r($_SERVER,true), LOGGER_DATA); if(array_key_exists('HTTP_SIGNATURE',$_SERVER)) { -logger('parsing signature header'); $sigblock = \Zotlabs\Web\HTTPSig::parse_sigheader($_SERVER['HTTP_SIGNATURE']); if($sigblock) { $keyId = $sigblock['keyId']; -- cgit v1.2.3 From 3dfafb710c901cd78b75681e39156a9f018b1ac9 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 8 Feb 2018 21:32:18 -0800 Subject: cosmetic --- include/zot.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/zot.php b/include/zot.php index 1a9909de1..1042f09d9 100644 --- a/include/zot.php +++ b/include/zot.php @@ -5108,9 +5108,8 @@ function zot_reply_notify($data) { $ret['collected'] = true; $import = [ 'success' => true, 'pickup' => [ [ 'notify' => $data, 'message' => json_decode($data['msg'],true) ] ] ]; - unset($import['pickup'][0]['notify']['msg']); - logger('import: ' . print_r($import,true), LOGGER_DATA); + logger('zot6_import: ' . print_r($import,true), LOGGER_DATA); $x = zot_import([ 'success' => true, 'body' => json_encode($import) ], $data['sender']['url']); if($x) { -- cgit v1.2.3