ActivityPub: Add a Public PEM key, little fixes to the JSON Encoder

This commit is contained in:
veselcraft 2021-12-28 17:21:26 +03:00
parent d1528a6355
commit 0c2a5b5eb7
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E
4 changed files with 27 additions and 2 deletions

View file

@ -42,7 +42,8 @@ ln -s /path/to/chandler/extensions/available/openvk /path/to/chandler/extensions
6. Copy `openvk-example.yml` to `openvk.yml` and change options
7. Run `composer install` in OpenVK directory
8. Move to `Web/static/js` and execute `yarn install`
9. Set `openvk` as your root app in `chandler.yml`
9. Generate the private and public OpenSSL keys by running `openssl genrsa -out data/private.pem 2048` and `openssl rsa -in private.pem -outform PEM -pubout -out data/public.pem` in OpenVK directory
10. Set `openvk` as your root app in `chandler.yml`
Once you are done, you can login as a system administrator on the network itself (no registration required):
* **Login**: `admin@localhost.localdomain6`

View file

@ -256,13 +256,15 @@ abstract class OpenVKPresenter extends SimplePresenter
protected function returnJson(array $json): void
{
$payload = json_encode($json);
$payload = json_encode($json, JSON_UNESCAPED_UNICODE);
$size = strlen($payload);
header("Content-Type: application/json");
header("Content-Length: $size");
exit($payload);
}
/* ActivityPub quicks :DDD */
function isActivityPubClient(): bool
{
$accept = explode(";", $_SERVER['HTTP_ACCEPT']);
@ -304,4 +306,18 @@ abstract class OpenVKPresenter extends SimplePresenter
]');
// Гришк)
}
/**
* @param private If true, it will return the private key. Otherwise, it will return the public key.
*/
function getKey(bool $private = false)
{
if(!file_exists(OPENVK_ROOT . ($private ? "/data/private.pem" : "/data/public.pem")))
throw new ISE("private.pem and public.pem files are missing. Please, check 10th step for a installation guide in README file.");
$key = file(OPENVK_ROOT . ($private ? "/data/private.pem" : "/data/public.pem"));
$key[0] = null;
$key[count($key)-1] = null;
return "-----BEGIN PUBLIC KEY-----\n" . str_replace("\n", '', implode('', $key)) . "\n-----END PUBLIC KEY-----\n";
}
}

View file

@ -44,6 +44,11 @@ final class UserPresenter extends OpenVKPresenter
"inbox" => $user->getFullURL() . "/inbox",
"outbox" => $user->getFullURL() . "/outbox",
"endpoints" => array("sharedInbox" => ovk_scheme(true) . $_SERVER['SERVER_NAME']),
"publicKey" => array(
"id" => $user->getFullURL(true) . "#main-key",
"owner" => $user->getFullURL(true),
"publicKeyPem" => $this->getKey()
),
"wall" => ovk_scheme(true) . $_SERVER['SERVER_NAME'] . "/wall" . $user->getId(),
"firstName" => $user->getFirstName(),
"lastName" => $user->getLastName(),

3
data/.gitignore vendored Executable file
View file

@ -0,0 +1,3 @@
private.pem
public.pem
knowledgebase/*