add hash to channel structure for consistency/redundancy

This commit is contained in:
friendica 2012-10-04 03:13:57 -07:00
parent e124c9fa5c
commit ff43d62e44
6 changed files with 30 additions and 22 deletions

View File

@ -100,7 +100,9 @@ CREATE TABLE IF NOT EXISTS `channel` (
`channel_primary` tinyint(1) unsigned NOT NULL DEFAULT '0',
`channel_name` char(255) NOT NULL DEFAULT '',
`channel_address` char(255) NOT NULL DEFAULT '',
`channel_global_id` char(255) NOT NULL DEFAULT '',
`channel_guid` char(255) NOT NULL DEFAULT '',
`channel_guid_sig` char(255) NOT NULL DEFAULT '',
`channel_hash` char(255) NOT NULL DEFAULT '',
`channel_timezone` char(128) NOT NULL DEFAULT 'UTC',
`channel_location` char(255) NOT NULL DEFAULT '',
`channel_theme` char(255) NOT NULL DEFAULT '',
@ -133,7 +135,6 @@ CREATE TABLE IF NOT EXISTS `channel` (
KEY `channel_primary` (`channel_primary`),
KEY `channel_name` (`channel_name`),
KEY `channel_address` (`channel_address`),
KEY `channel_global_id` (`channel_global_id`),
KEY `channel_timezone` (`channel_timezone`),
KEY `channel_location` (`channel_location`),
KEY `channel_theme` (`channel_theme`),
@ -152,7 +153,10 @@ CREATE TABLE IF NOT EXISTS `channel` (
KEY `channel_w_comment` (`channel_w_comment`),
KEY `channel_w_mail` (`channel_w_mail`),
KEY `channel_w_photos` (`channel_w_photos`),
KEY `channel_w_chat` (`channel_w_chat`)
KEY `channel_w_chat` (`channel_w_chat`),
KEY `channel_guid` (`channel_guid`),
KEY `channel_guid_sig` (`channel_guid_sig`),
KEY `channel_hash` (`channel_hash`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `clients` (

View File

@ -25,12 +25,12 @@ function map_perms($channel,$zguid,$zsig) {
$is_contact = true;
$contact = $r[0];
}
$r = q("select * from channel where channel_global_id = '%s'",
$r = q("select * from channel where channel_guid = '%s'",
dbesc($zguid)
);
if($r && count($r)) {
foreach($r as $rr) {
if(base64url_encode(rsa_sign($rr['channel_global_id'],$rr['channel_prvkey'])) === $zsig) {
if(base64url_encode(rsa_sign($rr['channel_guid'],$rr['channel_prvkey'])) === $zsig) {
$is_site = true;
break;
}

View File

@ -51,25 +51,31 @@ function create_identity($arr) {
$guid = zot_new_uid($nick);
$key = new_keypair(4096);
$sig = base64url_encode(rsa_sign($guid,$key['prvkey']));
$hash = base64url_encode(hash('whirlpool',$guid . $sig,true));
$primary = true;
$r = q("insert into channel ( channel_account_id, channel_primary,
channel_name, channel_address, channel_global_id, channel_prvkey,
channel_pubkey, channel_pageflags )
values ( %d, %d, '%s', '%s', '%s', '%s', '%s', %d ) ",
channel_name, channel_address, channel_guid, channel_guid_sig,
channel_hash, channel_prvkey, channel_pubkey, channel_pageflags )
values ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d ) ",
intval($arr['account_id']),
intval($primary),
dbesc($name),
dbesc($nick),
dbesc($guid),
dbesc($sig),
dbesc($hash),
dbesc($key['prvkey']),
dbesc($key['pubkey']),
intval(PAGE_NORMAL)
);
$r = q("select * from channel where channel_account_id = %d
and channel_global_id = '%s' limit 1",
and channel_guid = '%s' limit 1",
intval($arr['account_id']),
dbesc($guid)
);
@ -83,15 +89,13 @@ function create_identity($arr) {
set_default_login_identity($arr['account_id'],$ret['channel']['channel_id'],false);
$sig = base64url_encode(rsa_sign($ret['channel']['channel_global_id'],$ret['channel']['channel_prvkey']));
$hash = base64url_encode(hash('whirlpool',$ret['channel']['channel_global_id'] . $sig,true));
// Create a verified hub location pointing to this site.
$r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_flags,
hubloc_url, hubloc_url_sig, hubloc_callback, hubloc_sitekey )
values ( '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s' )",
dbesc($ret['channel']['channel_global_id']),
dbesc($guid),
dbesc($sig),
dbesc($hash),
intval(($primary) ? HUBLOC_FLAGS_PRIMARY : 0),
@ -108,7 +112,7 @@ function create_identity($arr) {
$r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_photo, xchan_addr, xchan_profile, xchan_name ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
dbesc($hash),
dbesc($ret['channel']['channel_global_id']),
dbesc($ret['channel']['channel_guid']),
dbesc($sig),
dbesc($a->get_baseurl() . "/photo/profile/{$newuid}"),
dbesc($ret['channel']['channel_address'] . '@' . $a->get_hostname()),

View File

@ -62,7 +62,7 @@ function zot_verify(&$item,$identity) {
function zot_notify($channel,$url) {
$x = z_post_url($url, array(
'type' => 'notify',
'guid' => $channel['channel_global_id'],
'guid' => $channel['channel_guid'],
'guid_sig' => base64url_encode($guid,$channel['prvkey']),
'hub' => z_root(),
'hub_sig' => base64url_encode(z_root,$channel['prvkey']),

View File

@ -13,7 +13,7 @@ function zfinger_init(&$a) {
$r = null;
if(strlen($zguid)) {
$r = q("select * from channel where channel_global_id = '%s' limit 1",
$r = q("select * from channel where channel_guid = '%s' limit 1",
dbesc($zguid)
);
}
@ -49,8 +49,8 @@ function zfinger_init(&$a) {
// Communication details
$ret['guid'] = $e['channel_global_id'];
$ret['guid_sig'] = base64url_encode(rsa_sign($e['channel_global_id'],$e['channel_prvkey']));
$ret['guid'] = $e['channel_guid'];
$ret['guid_sig'] = base64url_encode(rsa_sign($e['channel_guid'],$e['channel_prvkey']));
$ret['key'] = $e['channel_pubkey'];
$ret['name'] = $e['channel_name'];
$ret['address'] = $e['channel_address'];
@ -60,7 +60,7 @@ function zfinger_init(&$a) {
// array of (verified) hubs this channel uses
$ret['hubs'] = array();
$x = zot_get_hubloc(array($e['channel_global_id']));
$x = zot_get_hubloc(array($e['channel_guid']));
if($x && count($x)) {
foreach($x as $hub) {
if(! ($hub['hubloc_flags'] & HUBLOC_FLAGS_UNVERIFIED)) {

View File

@ -16,7 +16,7 @@ function zperms_init(&$a) {
$r = null;
if(strlen($zguid)) {
$r = q("select * from channel where channel_global_id = '%s' limit 1",
$r = q("select * from channel where channel_guid = '%s' limit 1",
dbesc($zguid)
);
}
@ -49,8 +49,8 @@ function zperms_init(&$a) {
$ret['success'] = true;
$ret['guid'] = $e['channel_global_id'];
$ret['guid_sig'] = base64url_encode(rsa_sign($e['channel_global_id'],$e['channel_prvkey']));
$ret['guid'] = $e['channel_guid'];
$ret['guid_sig'] = base64url_encode(rsa_sign($e['channel_guid'],$e['channel_prvkey']));
$ret['key'] = $e['channel_pubkey'];
$ret['name'] = $e['channel_name'];
$ret['address'] = $e['channel_address'];
@ -63,7 +63,7 @@ function zperms_init(&$a) {
// array of (verified) hubs this channel uses
$ret['hubs'] = array();
$x = zot_get_hubloc(array($e['channel_global_id']));
$x = zot_get_hubloc(array($e['channel_guid']));
if($x && count($x)) {
foreach($x as $hub) {
if(! ($hub['hubloc_flags'] & HUBLOC_FLAGS_UNVERIFIED)) {