Merge remote-tracking branch 'mike/master' into dev
This commit is contained in:
commit
e25db4d1b5
@ -196,7 +196,6 @@ class ThreadStream {
|
|||||||
$item->set_commentable(false);
|
$item->set_commentable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once('include/channel.php');
|
|
||||||
|
|
||||||
$item->set_conversation($this);
|
$item->set_conversation($this);
|
||||||
$this->threads[] = $item;
|
$this->threads[] = $item;
|
||||||
|
47
Zotlabs/Module/Zot_probe.php
Normal file
47
Zotlabs/Module/Zot_probe.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zotlabs\Module;
|
||||||
|
|
||||||
|
use Zotlabs\Lib\Zotfinger;
|
||||||
|
use Zotlabs\Zot6\HTTPSig;
|
||||||
|
|
||||||
|
class Zot_probe extends \Zotlabs\Web\Controller {
|
||||||
|
|
||||||
|
function get() {
|
||||||
|
|
||||||
|
$o .= '<h3>Zot6 Probe Diagnostic</h3>';
|
||||||
|
|
||||||
|
$o .= '<form action="zot_probe" method="get">';
|
||||||
|
$o .= 'Lookup URI: <input type="text" style="width: 250px;" name="addr" value="' . $_GET['addr'] .'" /><br>';
|
||||||
|
$o .= '<input type="submit" name="submit" value="Submit" /></form>';
|
||||||
|
|
||||||
|
$o .= '<br /><br />';
|
||||||
|
|
||||||
|
if(x($_GET,'addr')) {
|
||||||
|
$addr = $_GET['addr'];
|
||||||
|
|
||||||
|
|
||||||
|
$x = Zotfinger::exec($addr);
|
||||||
|
|
||||||
|
$o .= '<pre>' . htmlspecialchars(print_array($x)) . '</pre>';
|
||||||
|
|
||||||
|
$headers = 'Accept: application/x-zot+json, application/jrd+json, application/json';
|
||||||
|
|
||||||
|
$redirects = 0;
|
||||||
|
$x = z_fetch_url($addr,true,$redirects, [ 'headers' => [ $headers ]]);
|
||||||
|
|
||||||
|
if($x['success']) {
|
||||||
|
|
||||||
|
$o .= '<pre>' . htmlspecialchars($x['header']) . '</pre>' . EOL;
|
||||||
|
|
||||||
|
$o .= 'verify returns: ' . str_replace("\n",EOL,print_r(HTTPSig::verify($x),true)) . EOL;
|
||||||
|
|
||||||
|
$o .= '<pre>' . htmlspecialchars(json_encode(json_decode($x['body']),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)) . '</pre>' . EOL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return $o;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,13 +6,17 @@ class Wiki_list {
|
|||||||
|
|
||||||
function widget($arr) {
|
function widget($arr) {
|
||||||
|
|
||||||
|
if(argc() < 3) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$channel = channelx_by_n(\App::$profile_uid);
|
$channel = channelx_by_n(\App::$profile_uid);
|
||||||
|
|
||||||
$wikis = \Zotlabs\Lib\NativeWiki::listwikis($channel,get_observer_hash());
|
$wikis = \Zotlabs\Lib\NativeWiki::listwikis($channel,get_observer_hash());
|
||||||
|
|
||||||
if($wikis) {
|
if($wikis) {
|
||||||
return replace_macros(get_markup_template('wikilist_widget.tpl'), array(
|
return replace_macros(get_markup_template('wikilist_widget.tpl'), array(
|
||||||
'$header' => t('Wiki List'),
|
'$header' => t('Wikis'),
|
||||||
'$channel' => $channel['channel_address'],
|
'$channel' => $channel['channel_address'],
|
||||||
'$wikis' => $wikis['wikis']
|
'$wikis' => $wikis['wikis']
|
||||||
));
|
));
|
||||||
|
507
Zotlabs/Zot6/HTTPSig.php
Normal file
507
Zotlabs/Zot6/HTTPSig.php
Normal file
@ -0,0 +1,507 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zotlabs\Zot6;
|
||||||
|
|
||||||
|
use Zotlabs\Lib\ActivityStreams;
|
||||||
|
use Zotlabs\Lib\Webfinger;
|
||||||
|
use Zotlabs\Web\HTTPHeaders;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Implements HTTP Signatures per draft-cavage-http-signatures-10.
|
||||||
|
*
|
||||||
|
* @see https://tools.ietf.org/html/draft-cavage-http-signatures-10
|
||||||
|
*/
|
||||||
|
|
||||||
|
class HTTPSig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RFC5843
|
||||||
|
*
|
||||||
|
* @see https://tools.ietf.org/html/rfc5843
|
||||||
|
*
|
||||||
|
* @param string $body The value to create the digest for
|
||||||
|
* @param string $alg hash algorithm (one of 'sha256','sha512')
|
||||||
|
* @return string The generated digest header string for $body
|
||||||
|
*/
|
||||||
|
|
||||||
|
static function generate_digest_header($body,$alg = 'sha256') {
|
||||||
|
|
||||||
|
$digest = base64_encode(hash($alg, $body, true));
|
||||||
|
switch($alg) {
|
||||||
|
case 'sha512':
|
||||||
|
return 'SHA-512=' . $digest;
|
||||||
|
case 'sha256':
|
||||||
|
default:
|
||||||
|
return 'SHA-256=' . $digest;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static function find_headers($data,&$body) {
|
||||||
|
|
||||||
|
// decide if $data arrived via controller submission or curl
|
||||||
|
|
||||||
|
if(is_array($data) && $data['header']) {
|
||||||
|
if(! $data['success'])
|
||||||
|
return [];
|
||||||
|
|
||||||
|
$h = new HTTPHeaders($data['header']);
|
||||||
|
$headers = $h->fetcharr();
|
||||||
|
$body = $data['body'];
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
$headers = [];
|
||||||
|
$headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI'];
|
||||||
|
$headers['content-type'] = $_SERVER['CONTENT_TYPE'];
|
||||||
|
|
||||||
|
foreach($_SERVER as $k => $v) {
|
||||||
|
if(strpos($k,'HTTP_') === 0) {
|
||||||
|
$field = str_replace('_','-',strtolower(substr($k,5)));
|
||||||
|
$headers[$field] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//logger('SERVER: ' . print_r($_SERVER,true), LOGGER_ALL);
|
||||||
|
|
||||||
|
//logger('headers: ' . print_r($headers,true), LOGGER_ALL);
|
||||||
|
|
||||||
|
return $headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// See draft-cavage-http-signatures-10
|
||||||
|
|
||||||
|
static function verify($data,$key = '') {
|
||||||
|
|
||||||
|
$body = $data;
|
||||||
|
$headers = null;
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'signer' => '',
|
||||||
|
'portable_id' => '',
|
||||||
|
'header_signed' => false,
|
||||||
|
'header_valid' => false,
|
||||||
|
'content_signed' => false,
|
||||||
|
'content_valid' => false
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
$headers = self::find_headers($data,$body);
|
||||||
|
|
||||||
|
if(! $headers)
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
$sig_block = null;
|
||||||
|
|
||||||
|
if(array_key_exists('signature',$headers)) {
|
||||||
|
$sig_block = self::parse_sigheader($headers['signature']);
|
||||||
|
}
|
||||||
|
elseif(array_key_exists('authorization',$headers)) {
|
||||||
|
$sig_block = self::parse_sigheader($headers['authorization']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(! $sig_block) {
|
||||||
|
logger('no signature provided.', LOGGER_DEBUG);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warning: This log statement includes binary data
|
||||||
|
// logger('sig_block: ' . print_r($sig_block,true), LOGGER_DATA);
|
||||||
|
|
||||||
|
$result['header_signed'] = true;
|
||||||
|
|
||||||
|
$signed_headers = $sig_block['headers'];
|
||||||
|
if(! $signed_headers)
|
||||||
|
$signed_headers = [ 'date' ];
|
||||||
|
|
||||||
|
$signed_data = '';
|
||||||
|
foreach($signed_headers as $h) {
|
||||||
|
if(array_key_exists($h,$headers)) {
|
||||||
|
$signed_data .= $h . ': ' . $headers[$h] . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$signed_data = rtrim($signed_data,"\n");
|
||||||
|
|
||||||
|
$algorithm = null;
|
||||||
|
if($sig_block['algorithm'] === 'rsa-sha256') {
|
||||||
|
$algorithm = 'sha256';
|
||||||
|
}
|
||||||
|
if($sig_block['algorithm'] === 'rsa-sha512') {
|
||||||
|
$algorithm = 'sha512';
|
||||||
|
}
|
||||||
|
|
||||||
|
if(! array_key_exists('keyId',$sig_block))
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
$result['signer'] = $sig_block['keyId'];
|
||||||
|
|
||||||
|
$key = self::get_key($key,$result['signer']);
|
||||||
|
|
||||||
|
if(! ($key && $key['public_key'])) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
$x = rsa_verify($signed_data,$sig_block['signature'],$key['public_key'],$algorithm);
|
||||||
|
|
||||||
|
logger('verified: ' . $x, LOGGER_DEBUG);
|
||||||
|
|
||||||
|
if(! $x)
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
$result['portable_id'] = $key['portable_id'];
|
||||||
|
$result['header_valid'] = true;
|
||||||
|
|
||||||
|
if(in_array('digest',$signed_headers)) {
|
||||||
|
$result['content_signed'] = true;
|
||||||
|
$digest = explode('=', $headers['digest'], 2);
|
||||||
|
if($digest[0] === 'SHA-256')
|
||||||
|
$hashalg = 'sha256';
|
||||||
|
if($digest[0] === 'SHA-512')
|
||||||
|
$hashalg = 'sha512';
|
||||||
|
|
||||||
|
if(base64_encode(hash($hashalg,$body,true)) === $digest[1]) {
|
||||||
|
$result['content_valid'] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger('Content_Valid: ' . (($result['content_valid']) ? 'true' : 'false'));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static function get_key($key,$id) {
|
||||||
|
|
||||||
|
if($key) {
|
||||||
|
if(function_exists($key)) {
|
||||||
|
return $key($id);
|
||||||
|
}
|
||||||
|
return [ 'public_key' => $key ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = self::get_webfinger_key($id);
|
||||||
|
|
||||||
|
if(! $key) {
|
||||||
|
$key = self::get_activitystreams_key($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $key;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function convertKey($key) {
|
||||||
|
|
||||||
|
if(strstr($key,'RSA ')) {
|
||||||
|
return rsatopem($key);
|
||||||
|
}
|
||||||
|
elseif(substr($key,0,5) === 'data:') {
|
||||||
|
return convert_salmon_key($key);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @return boolean|string
|
||||||
|
* false if no pub key found, otherwise return the pub key
|
||||||
|
*/
|
||||||
|
|
||||||
|
function get_activitystreams_key($id) {
|
||||||
|
|
||||||
|
$x = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_addr = '%s' or hubloc_id_url = '%s' limit 1",
|
||||||
|
dbesc(str_replace('acct:','',$id)),
|
||||||
|
dbesc($id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if($x && $x[0]['xchan_pubkey']) {
|
||||||
|
return [ 'portable_id' => $x[0]['xchan_hash'], 'public_key' => $x[0]['xchan_pubkey'] , 'hubloc' => $x[0] ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$r = ActivityStreams::fetch_property($id);
|
||||||
|
|
||||||
|
if($r) {
|
||||||
|
if(array_key_exists('publicKey',$j) && array_key_exists('publicKeyPem',$j['publicKey']) && array_key_exists('id',$j['publicKey'])) {
|
||||||
|
if($j['publicKey']['id'] === $id || $j['id'] === $id) {
|
||||||
|
return [ 'public_key' => self::convertKey($j['publicKey']['publicKeyPem']), 'portable_id' => '', 'hubloc' => [] ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function get_webfinger_key($id) {
|
||||||
|
|
||||||
|
$x = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_addr = '%s' or hubloc_id_url = '%s' limit 1",
|
||||||
|
dbesc(str_replace('acct:','',$id)),
|
||||||
|
dbesc($id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if($x && $x[0]['xchan_pubkey']) {
|
||||||
|
return [ 'portable_id' => $x[0]['xchan_hash'], 'public_key' => $x[0]['xchan_pubkey'] , 'hubloc' => $x[0] ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$wf = Webfinger::exec($id);
|
||||||
|
$key = [ 'portable_id' => '', 'public_key' => '', 'hubloc' => [] ];
|
||||||
|
|
||||||
|
if($wf) {
|
||||||
|
if(array_key_exists('properties',$wf) && array_key_exists('https://w3id.org/security/v1#publicKeyPem',$wf['properties'])) {
|
||||||
|
$key['public_key'] = self::convertKey($wf['properties']['https://w3id.org/security/v1#publicKeyPem']);
|
||||||
|
}
|
||||||
|
if(array_key_exists('links', $wf) && is_array($wf['links'])) {
|
||||||
|
foreach($wf['links'] as $l) {
|
||||||
|
if(! (is_array($l) && array_key_exists('rel',$l))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if($l['rel'] === 'magic-public-key' && array_key_exists('href',$l) && $key['public_key'] === EMPTY_STR) {
|
||||||
|
$key['public_key'] = self::convertKey($l['href']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (($key['public_key']) ? $key : false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function get_zotfinger_key($id) {
|
||||||
|
|
||||||
|
$x = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_addr = '%s' or hubloc_id_url = '%s' limit 1",
|
||||||
|
dbesc(str_replace('acct:','',$id)),
|
||||||
|
dbesc($id)
|
||||||
|
);
|
||||||
|
if($x && $x[0]['xchan_pubkey']) {
|
||||||
|
return [ 'portable_id' => $x[0]['xchan_hash'], 'public_key' => $x[0]['xchan_pubkey'] , 'hubloc' => $x[0] ];
|
||||||
|
}
|
||||||
|
|
||||||
|
$wf = Webfinger::exec($id);
|
||||||
|
$key = [ 'portable_id' => '', 'public_key' => '', 'hubloc' => [] ];
|
||||||
|
|
||||||
|
if($wf) {
|
||||||
|
if(array_key_exists('properties',$wf) && array_key_exists('https://w3id.org/security/v1#publicKeyPem',$wf['properties'])) {
|
||||||
|
$key['public_key'] = self::convertKey($wf['properties']['https://w3id.org/security/v1#publicKeyPem']);
|
||||||
|
}
|
||||||
|
if(array_key_exists('links', $wf) && is_array($wf['links'])) {
|
||||||
|
foreach($wf['links'] as $l) {
|
||||||
|
if(! (is_array($l) && array_key_exists('rel',$l))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if($l['rel'] === 'http://purl.org/zot/protocol/6.0' && array_key_exists('href',$l) && $l['href'] !== EMPTY_STR) {
|
||||||
|
$z = \Zotlabs\Lib\Zotfinger::exec($l['href']);
|
||||||
|
if($z) {
|
||||||
|
$i = Zotlabs\Lib\Libzot::import_xchan($z['data']);
|
||||||
|
if($i['success']) {
|
||||||
|
$key['portable_id'] = $i['hash'];
|
||||||
|
|
||||||
|
$x = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_id_url = '%s' limit 1",
|
||||||
|
dbesc($l['href'])
|
||||||
|
);
|
||||||
|
if($x) {
|
||||||
|
$key['hubloc'] = $x[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($l['rel'] === 'magic-public-key' && array_key_exists('href',$l) && $key['public_key'] === EMPTY_STR) {
|
||||||
|
$key['public_key'] = self::convertKey($l['href']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (($key['public_key']) ? $key : false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param array $head
|
||||||
|
* @param string $prvkey
|
||||||
|
* @param string $keyid (optional, default '')
|
||||||
|
* @param boolean $auth (optional, default false)
|
||||||
|
* @param string $alg (optional, default 'sha256')
|
||||||
|
* @param array $encryption [ 'key', 'algorithm' ] or false
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
static function create_sig($head, $prvkey, $keyid = EMPTY_STR, $auth = false, $alg = 'sha256', $encryption = false ) {
|
||||||
|
|
||||||
|
$return_headers = [];
|
||||||
|
|
||||||
|
if($alg === 'sha256') {
|
||||||
|
$algorithm = 'rsa-sha256';
|
||||||
|
}
|
||||||
|
if($alg === 'sha512') {
|
||||||
|
$algorithm = 'rsa-sha512';
|
||||||
|
}
|
||||||
|
|
||||||
|
$x = self::sign($head,$prvkey,$alg);
|
||||||
|
|
||||||
|
$headerval = 'keyId="' . $keyid . '",algorithm="' . $algorithm . '",headers="' . $x['headers'] . '",signature="' . $x['signature'] . '"';
|
||||||
|
|
||||||
|
if($encryption) {
|
||||||
|
$x = crypto_encapsulate($headerval,$encryption['key'],$encryption['algorithm']);
|
||||||
|
if(is_array($x)) {
|
||||||
|
$headerval = 'iv="' . $x['iv'] . '",key="' . $x['key'] . '",alg="' . $x['alg'] . '",data="' . $x['data'] . '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($auth) {
|
||||||
|
$sighead = 'Authorization: Signature ' . $headerval;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$sighead = 'Signature: ' . $headerval;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($head) {
|
||||||
|
foreach($head as $k => $v) {
|
||||||
|
// strip the request-target virtual header from the output headers
|
||||||
|
if($k === '(request-target)') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$return_headers[] = $k . ': ' . $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$return_headers[] = $sighead;
|
||||||
|
|
||||||
|
return $return_headers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief set headers
|
||||||
|
*
|
||||||
|
* @param array $headers
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
static function set_headers($headers) {
|
||||||
|
if($headers && is_array($headers)) {
|
||||||
|
foreach($headers as $h) {
|
||||||
|
header($h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param array $head
|
||||||
|
* @param string $prvkey
|
||||||
|
* @param string $alg (optional) default 'sha256'
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
|
||||||
|
static function sign($head, $prvkey, $alg = 'sha256') {
|
||||||
|
|
||||||
|
$ret = [];
|
||||||
|
|
||||||
|
$headers = '';
|
||||||
|
$fields = '';
|
||||||
|
|
||||||
|
if($head) {
|
||||||
|
foreach($head as $k => $v) {
|
||||||
|
$headers .= strtolower($k) . ': ' . trim($v) . "\n";
|
||||||
|
if($fields)
|
||||||
|
$fields .= ' ';
|
||||||
|
|
||||||
|
$fields .= strtolower($k);
|
||||||
|
}
|
||||||
|
// strip the trailing linefeed
|
||||||
|
$headers = rtrim($headers,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
$sig = base64_encode(rsa_sign($headers,$prvkey,$alg));
|
||||||
|
|
||||||
|
$ret['headers'] = $fields;
|
||||||
|
$ret['signature'] = $sig;
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param string $header
|
||||||
|
* @return array associate array with
|
||||||
|
* - \e string \b keyID
|
||||||
|
* - \e string \b algorithm
|
||||||
|
* - \e array \b headers
|
||||||
|
* - \e string \b signature
|
||||||
|
*/
|
||||||
|
|
||||||
|
static function parse_sigheader($header) {
|
||||||
|
|
||||||
|
$ret = [];
|
||||||
|
$matches = [];
|
||||||
|
|
||||||
|
// if the header is encrypted, decrypt with (default) site private key and continue
|
||||||
|
|
||||||
|
if(preg_match('/iv="(.*?)"/ism',$header,$matches))
|
||||||
|
$header = self::decrypt_sigheader($header);
|
||||||
|
|
||||||
|
if(preg_match('/keyId="(.*?)"/ism',$header,$matches))
|
||||||
|
$ret['keyId'] = $matches[1];
|
||||||
|
if(preg_match('/algorithm="(.*?)"/ism',$header,$matches))
|
||||||
|
$ret['algorithm'] = $matches[1];
|
||||||
|
if(preg_match('/headers="(.*?)"/ism',$header,$matches))
|
||||||
|
$ret['headers'] = explode(' ', $matches[1]);
|
||||||
|
if(preg_match('/signature="(.*?)"/ism',$header,$matches))
|
||||||
|
$ret['signature'] = base64_decode(preg_replace('/\s+/','',$matches[1]));
|
||||||
|
|
||||||
|
if(($ret['signature']) && ($ret['algorithm']) && (! $ret['headers']))
|
||||||
|
$ret['headers'] = [ 'date' ];
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @param string $header
|
||||||
|
* @param string $prvkey (optional), if not set use site private key
|
||||||
|
* @return array|string associative array, empty string if failue
|
||||||
|
* - \e string \b iv
|
||||||
|
* - \e string \b key
|
||||||
|
* - \e string \b alg
|
||||||
|
* - \e string \b data
|
||||||
|
*/
|
||||||
|
|
||||||
|
static function decrypt_sigheader($header, $prvkey = null) {
|
||||||
|
|
||||||
|
$iv = $key = $alg = $data = null;
|
||||||
|
|
||||||
|
if(! $prvkey) {
|
||||||
|
$prvkey = get_config('system', 'prvkey');
|
||||||
|
}
|
||||||
|
|
||||||
|
$matches = [];
|
||||||
|
|
||||||
|
if(preg_match('/iv="(.*?)"/ism',$header,$matches))
|
||||||
|
$iv = $matches[1];
|
||||||
|
if(preg_match('/key="(.*?)"/ism',$header,$matches))
|
||||||
|
$key = $matches[1];
|
||||||
|
if(preg_match('/alg="(.*?)"/ism',$header,$matches))
|
||||||
|
$alg = $matches[1];
|
||||||
|
if(preg_match('/data="(.*?)"/ism',$header,$matches))
|
||||||
|
$data = $matches[1];
|
||||||
|
|
||||||
|
if($iv && $key && $alg && $data) {
|
||||||
|
return crypto_unencapsulate([ 'encrypted' => true, 'iv' => $iv, 'key' => $key, 'alg' => $alg, 'data' => $data ] , $prvkey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -238,6 +238,7 @@ function can_comment_on_post($observer_xchan, $item) {
|
|||||||
'item' => $item,
|
'item' => $item,
|
||||||
'allowed' => 'unset'
|
'allowed' => 'unset'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hooks can_comment_on_post
|
* @hooks can_comment_on_post
|
||||||
* Called when deciding whether or not to present a comment box for a post.
|
* Called when deciding whether or not to present a comment box for a post.
|
||||||
@ -245,26 +246,34 @@ function can_comment_on_post($observer_xchan, $item) {
|
|||||||
* * \e array \b item
|
* * \e array \b item
|
||||||
* * \e boolean \b allowed - return value
|
* * \e boolean \b allowed - return value
|
||||||
*/
|
*/
|
||||||
|
|
||||||
call_hooks('can_comment_on_post', $x);
|
call_hooks('can_comment_on_post', $x);
|
||||||
if($x['allowed'] !== 'unset')
|
|
||||||
|
if($x['allowed'] !== 'unset') {
|
||||||
return $x['allowed'];
|
return $x['allowed'];
|
||||||
|
}
|
||||||
|
|
||||||
if(! $observer_xchan)
|
if(! $observer_xchan) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if($item['comment_policy'] === 'none')
|
if($item['comment_policy'] === 'none') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if(comments_are_now_closed($item))
|
if(comments_are_now_closed($item)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if($observer_xchan === $item['author_xchan'] || $observer_xchan === $item['owner_xchan'])
|
if($observer_xchan === $item['author_xchan'] || $observer_xchan === $item['owner_xchan']) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
switch($item['comment_policy']) {
|
switch($item['comment_policy']) {
|
||||||
case 'self':
|
case 'self':
|
||||||
if($observer_xchan === $item['author_xchan'] || $observer_xchan === $item['owner_xchan'])
|
if($observer_xchan === $item['author_xchan'] || $observer_xchan === $item['owner_xchan']) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'public':
|
case 'public':
|
||||||
case 'authenticated':
|
case 'authenticated':
|
||||||
@ -276,17 +285,22 @@ function can_comment_on_post($observer_xchan, $item) {
|
|||||||
case 'any connections':
|
case 'any connections':
|
||||||
case 'contacts':
|
case 'contacts':
|
||||||
case '':
|
case '':
|
||||||
if(array_key_exists('owner',$item) && get_abconfig($item['uid'],$item['owner']['abook_xchan'],'their_perms','post_comments')) {
|
if(local_channel() && get_abconfig(local_channel(),$item['owner_xchan'],'their_perms','post_comments')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(intval($item['item_wall']) && perm_is_allowed($item['uid'],$observer_xchan,'post_comments')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(strstr($item['comment_policy'],'network:') && strstr($item['comment_policy'],'red'))
|
if(strstr($item['comment_policy'],'network:') && strstr($item['comment_policy'],'red')) {
|
||||||
return true;
|
return true;
|
||||||
if(strstr($item['comment_policy'],'site:') && strstr($item['comment_policy'],App::get_hostname()))
|
}
|
||||||
|
if(strstr($item['comment_policy'],'site:') && strstr($item['comment_policy'],App::get_hostname())) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
[region=aside]
|
[region=aside]
|
||||||
[widget=vcard][/widget]
|
[widget=vcard][/widget]
|
||||||
|
[widget=wiki_list][/widget]
|
||||||
[widget=wiki_pages][/widget]
|
[widget=wiki_pages][/widget]
|
||||||
[/region]
|
[/region]
|
||||||
[region=right_aside]
|
[region=right_aside]
|
||||||
|
Reference in New Issue
Block a user