encrypt the httpsig for zot6 transport

This commit is contained in:
zotlabs 2018-02-07 21:53:47 -08:00
parent b21a5c3ce9
commit 6cf2e9945a
2 changed files with 24 additions and 4 deletions

View File

@ -121,7 +121,7 @@ function queue_deliver($outq, $immediate = false) {
$base = null; $base = null;
$h = parse_url($outq['outq_posturl']); $h = parse_url($outq['outq_posturl']);
if($h) if($h !== false)
$base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : ''); $base = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : '');
if(($base) && ($base !== z_root()) && ($immediate)) { 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); $arr = array('outq' => $outq, 'base' => $base, 'handled' => false, 'immediate' => $immediate);
call_hooks('queue_deliver',$arr); call_hooks('queue_deliver',$arr);
if($arr['handled']) if($arr['handled'])
@ -223,9 +226,24 @@ function queue_deliver($outq, $immediate = false) {
$channel = channelx_by_n($outq['outq_channel']); $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']; $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']) { if($result['success']) {

View File

@ -288,9 +288,11 @@ function zot_best_algorithm($methods) {
* *
* @param string $url * @param string $url
* @param array $data * @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 * @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 = []; $headers = [];
@ -298,7 +300,7 @@ 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;
$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; $redirects = 0;