Improve update_activitypub_profiles.php daemon

Add sanity case to ensure public key method of rsa class
This commit is contained in:
Diogo Cordeiro
2018-08-07 03:54:14 +01:00
parent b2f6f9f08e
commit 6fbf37b7fe
5 changed files with 201 additions and 170 deletions

View File

@@ -83,7 +83,6 @@ class Activitypub_rsa extends Managed_DataObject
return $apRSA->private_key;
}
/**
* Guarantees a Public Key for a given profile.
*
@@ -104,7 +103,8 @@ class Activitypub_rsa extends Managed_DataObject
} else {
// This should never happen, but try to recover!
if ($fetch) {
// TODO: Call profile updater
$res = Activitypub_explorer::get_remote_user_activity(ActivityPubPlugin::actor_uri($profile));
Activitypub_rsa::update_public_key($profile, $res['publicKey']['publicKeyPem']);
return ensure_public_key($profile, false);
} else {
throw new ServerException('Activitypub_rsa: Failed to find keys for given profile. That should have not happened!');
@@ -156,4 +156,23 @@ class Activitypub_rsa extends Managed_DataObject
$public_key = $pubKey["key"];
unset($pubKey);
}
/**
* Update public key.
*
* @author Diogo Cordeiro <diogo@fc.up.pt>
* @param Profile $profile
* @param string $public_key
*/
public static function update_public_key($profile, $public_key)
{
// Public Key
$apRSA = new Activitypub_rsa();
$apRSA->profile_id = $profile->getID();
$apRSA->public_key = $public_key;
$apRSA->modified = common_sql_now();
if(!$apRSA->update()) {
$apRSA->insert();
}
}
}