diff options
author | zotlabs <mike@macgirvin.com> | 2018-02-07 18:38:10 -0800 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2018-02-07 18:38:10 -0800 |
commit | 3a0db39fa05668831e7661ac6edaabfd09d864e2 (patch) | |
tree | 2a0a7718eafaaeb5564bd95cea7dee8e4bbfa625 | |
parent | 1d8d2c6e5517ec7cbb9aa089993918ff6492f5c3 (diff) | |
download | volse-hubzilla-3a0db39fa05668831e7661ac6edaabfd09d864e2.tar.gz volse-hubzilla-3a0db39fa05668831e7661ac6edaabfd09d864e2.tar.bz2 volse-hubzilla-3a0db39fa05668831e7661ac6edaabfd09d864e2.zip |
more zot6 delivery work
-rw-r--r-- | Zotlabs/Daemon/Notifier.php | 4 | ||||
-rw-r--r-- | include/queue_fn.php | 14 | ||||
-rw-r--r-- | 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; |