From ae8cdc3b42a01bfa6a8a7baf80bad2544c3821a7 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 31 Aug 2017 21:38:03 -0700 Subject: some changes after testing server-to-server magic auth --- Zotlabs/Module/Cdav.php | 14 ++++++++------ Zotlabs/Module/Dav.php | 15 +++++++++------ Zotlabs/Web/HTTPSig.php | 10 ++++++++-- 3 files changed, 25 insertions(+), 14 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Cdav.php b/Zotlabs/Module/Cdav.php index bae3fc6aa..abaec26a6 100644 --- a/Zotlabs/Module/Cdav.php +++ b/Zotlabs/Module/Cdav.php @@ -32,6 +32,11 @@ class Cdav extends \Zotlabs\Web\Controller { /* Signature authentication */ 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']; @@ -43,20 +48,17 @@ class Cdav extends \Zotlabs\Web\Controller { $c = channelx_by_hash($r[0]['hubloc_hash']); if($c) { $a = q("select * from account where account_id = %d limit 1", - intval($c[0]['channel_account_id']) + intval($c['channel_account_id']) ); if($a) { - $record = [ 'channel' => $c[0], 'account' => $a[0] ]; - $channel_login = $c[0]['channel_id']; + $record = [ 'channel' => $c, 'account' => $a[0] ]; + $channel_login = $c['channel_id']; } } } if(! $record) continue; - if($head !== 'HTTP_AUTHORIZATION') { - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER[$head]; - } if($record) { $verified = \Zotlabs\Web\HTTPSig::verify('',$record['channel']['channel_pubkey']); if(! ($verified && $verified['header_signed'] && $verified['header_valid'])) { diff --git a/Zotlabs/Module/Dav.php b/Zotlabs/Module/Dav.php index 8c4512806..d506fe9f5 100644 --- a/Zotlabs/Module/Dav.php +++ b/Zotlabs/Module/Dav.php @@ -41,6 +41,11 @@ class Dav extends \Zotlabs\Web\Controller { /* Signature authentication */ 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']; @@ -52,19 +57,17 @@ class Dav extends \Zotlabs\Web\Controller { $c = channelx_by_hash($r[0]['hubloc_hash']); if($c) { $a = q("select * from account where account_id = %d limit 1", - intval($c[0]['channel_account_id']) + intval($c['channel_account_id']) ); if($a) { - $record = [ 'channel' => $c[0], 'account' => $a[0] ]; - $channel_login = $c[0]['channel_id']; + $record = [ 'channel' => $c, 'account' => $a[0] ]; + $channel_login = $c['channel_id']; } } } if(! $record) continue; - if($head !== 'HTTP_AUTHORIZATION') { - $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER[$head]; - } + if($record) { $verified = \Zotlabs\Web\HTTPSig::verify('',$record['channel']['channel_pubkey']); if(! ($verified && $verified['header_signed'] && $verified['header_valid'])) { diff --git a/Zotlabs/Web/HTTPSig.php b/Zotlabs/Web/HTTPSig.php index 537cd52a1..1f485a881 100644 --- a/Zotlabs/Web/HTTPSig.php +++ b/Zotlabs/Web/HTTPSig.php @@ -145,7 +145,7 @@ class HTTPSig { - static function create_sig($request,$head,$prvkey,$keyid = 'Key',$send_headers = false,$alg = 'sha256') { + static function create_sig($request,$head,$prvkey,$keyid = 'Key',$send_headers = false,$auth = false,$alg = 'sha256') { $return_headers = []; @@ -155,8 +155,14 @@ class HTTPSig { $x = self::sign($request,$head,$prvkey,$alg); - $sighead = 'Signature: keyId="' . $keyid . '",algorithm="' . $algorithm + if($auth) { + $sighead = 'Authorization: Signature keyId="' . $keyid . '",algorithm="' . $algorithm . '",headers="' . $x['headers'] . '",signature="' . $x['signature'] . '"'; + } + else { + $sighead = 'Signature: keyId="' . $keyid . '",algorithm="' . $algorithm + . '",headers="' . $x['headers'] . '",signature="' . $x['signature'] . '"'; + } if($head) { foreach($head as $k => $v) { -- cgit v1.2.3