initial z6 delivery

This commit is contained in:
zotlabs 2018-01-16 20:08:10 -08:00
parent 2de1285121
commit 05de59d4ad
3 changed files with 29 additions and 33 deletions

View File

@ -13,8 +13,8 @@ class Queue {
require_once('include/bbcode.php'); require_once('include/bbcode.php');
if(argc() > 1) if($argc > 1)
$queue_id = argv(1); $queue_id = $argv[1];
else else
$queue_id = 0; $queue_id = 0;

View File

@ -217,19 +217,19 @@ function queue_deliver($outq, $immediate = false) {
logger('deliver: dest: ' . $outq['outq_posturl'], LOGGER_DEBUG); logger('deliver: dest: ' . $outq['outq_posturl'], LOGGER_DEBUG);
$msg = $outq['outq_notify'];
$channel = null; $channel = null;
if($outq['outq_msg']) { if($outq['outq_msg']) {
$tmp = json_decode($msg,true); $msg = json_decode($outq['outq_notify'],true);
$tmp['pickup'] = json_decode($outq['outq_msg'],true); $msg['pickup'] = [ 'notify' => json_decode($outq['outq_notify'],true), 'message' => json_decode($outq['outq_msg'],true) ];
$msg = json_encode($tmp); $msg = json_encode($msg);
if($outq['outq_channel']) { if($outq['outq_channel']) {
$channel = channelx_by_n($outq['outq_channel']); $channel = channelx_by_n($outq['outq_channel']);
} }
} }
else {
$msg = $outq['outq_notify'];
}
$result = zot_zot($outq['outq_posturl'],$msg,$channel); $result = zot_zot($outq['outq_posturl'],$msg,$channel);

View File

@ -219,11 +219,11 @@ function zot_zot($url, $data, $channel = null) {
$headers['X-Zot-Token'] = random_string(); $headers['X-Zot-Token'] = random_string();
$hash = \Zotlabs\Web\HTTPSig::generate_digest($data,false); $hash = \Zotlabs\Web\HTTPSig::generate_digest($data,false);
$headers['X-Zot-Digest'] = 'SHA-256=' . $hash; $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; $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 ]; $ret = [ 'success' => false ];
foreach([ 'REDIRECT_REMOTE_USER', 'HTTP_AUTHORIZATION' ] as $head) { logger('server: ' . print_r($_SERVER,true));
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(array_key_exists('HTTP_SIGNATURE',$_SERVER)) {
if($sigblock) { logger('parsing signature header');
$keyId = $sigblock['keyId']; $sigblock = \Zotlabs\Web\HTTPSig::parse_sigheader($_SERVER['HTTP_SIGNATURE']);
if($sigblock) {
$keyId = $sigblock['keyId'];
if($keyId) { if($keyId) {
$r = q("select hubloc.*, site_crypto from hubloc left join site on hubloc_url = site_url $r = q("select hubloc.*, site_crypto from hubloc left join site on hubloc_url = site_url
where hubloc_addr = '%s' ", where hubloc_addr = '%s' ",
dbesc(str_replace('acct:','',$keyId)) dbesc(str_replace('acct:','',$keyId))
); );
if($r) { if($r) {
foreach($r as $hubloc) { foreach($r as $hubloc) {
$verified = \Zotlabs\Web\HTTPSig::verify('',$hubloc['xchan_pubkey']); $verified = \Zotlabs\Web\HTTPSig::verify('',$hubloc['xchan_pubkey']);
if($verified && $verified['header_signed'] && $verified['header_valid'] && $verified['content_signed'] && $verified['content_valid']) { if($verified && $verified['header_signed'] && $verified['header_valid'] && $verified['content_signed'] && $verified['content_valid']) {
$ret['hubloc'] = $hubloc; $ret['hubloc'] = $hubloc;
$ret['success'] = true; $ret['success'] = true;
return $ret; return $ret;
}
} }
} }
} }
@ -5028,7 +5024,7 @@ function zot_reply_notify($data) {
if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $data['sender']['guid']) { if($zret['success'] && $zret['hubloc'] && $zret['hubloc']['hubloc_guid'] === $data['sender']['guid']) {
logger('zot6_delivery'); logger('zot6_delivery');
logger('zot6_data: ' . print_r($data,true),LOGGER_DATA); 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) { if($x) {
$x = crypto_encapsulate(json_encode($x),$zret['hubloc']['hubloc_sitekey'],zot_best_algorithm($zret['hubloc']['site_crypto'])); $x = crypto_encapsulate(json_encode($x),$zret['hubloc']['hubloc_sitekey'],zot_best_algorithm($zret['hubloc']['site_crypto']));
$ret['delivery_report'] = $x; $ret['delivery_report'] = $x;