This commit is contained in:
Bryan Ashby 2023-01-06 13:49:13 -07:00
parent d615b53f1f
commit 848044bec6
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
3 changed files with 1012 additions and 998 deletions

View File

@ -168,11 +168,17 @@ exports.getModule = class WebServerModule extends ServerModule {
try { try {
const normalizedName = _.camelCase(module.moduleInfo.name); const normalizedName = _.camelCase(module.moduleInfo.name);
if (!WebHandlerModule.isEnabled(normalizedName)) { if (!WebHandlerModule.isEnabled(normalizedName)) {
Log.info({ moduleName: normalizedName }, 'Skipping web handler module - not enabled.'); Log.info(
{ moduleName: normalizedName },
'Skipping web handler module - not enabled.'
);
return nextModule(null); return nextModule(null);
} }
Log.info({ moduleName: normalizedName }, 'Initializing web handler module.'); Log.info(
{ moduleName: normalizedName },
'Initializing web handler module.'
);
moduleInst.init(err => { moduleInst.init(err => {
return nextModule(err); return nextModule(err);

View File

@ -58,7 +58,10 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
userFromAccount(accountName, (err, user) => { userFromAccount(accountName, (err, user) => {
if (err) { if (err) {
Log.info({ accountName: accountName }, 'Unable to find user from account retrieving self url.'); Log.info(
{ accountName: accountName },
'Unable to find user from account retrieving self url.'
);
return this._notFound(resp); return this._notFound(resp);
} }
@ -71,23 +74,21 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
if (sendActor) { if (sendActor) {
return this._selfAsActorHandler(user, req, resp); return this._selfAsActorHandler(user, req, resp);
} } else {
else {
return this._standardSelfHandler(user, req, resp); return this._standardSelfHandler(user, req, resp);
} }
}); });
} }
_selfAsActorHandler(user, req, resp) { _selfAsActorHandler(user, req, resp) {
const selfUrl = selfUrl(this.webServer, user);
const sUrl = selfUrl(this.webServer, user);
const bodyJson = { const bodyJson = {
'@context': [ '@context': [
'https://www.w3.org/ns/activitystreams', 'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1', 'https://w3id.org/security/v1',
], ],
id: sUrl, id: selfUrl,
type: 'Person', type: 'Person',
preferredUsername: user.username, preferredUsername: user.username,
name: user.getSanitizedName('real'), name: user.getSanitizedName('real'),
@ -105,11 +106,14 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
}; };
const publicKeyPem = user.getProperty(UserProps.PublicKeyMain); const publicKeyPem = user.getProperty(UserProps.PublicKeyMain);
if (!(_.isEmpty(publicKeyPem))) { if (!_.isEmpty(publicKeyPem)) {
bodyJson['publicKey'] = { id: sUrl + '#main-key', owner: sUrl, publicKeyPem: user.getProperty(UserProps.PublicKeyMain) }; bodyJson['publicKey'] = {
} id: selfUrl + '#main-key',
else { owner: sUrl,
Log.debug({ User: user.username }, 'User does not have a publickey.'); publicKeyPem: user.getProperty(UserProps.PublicKeyMain),
};
} else {
Log.debug({ username: user.username }, 'User does not have a publickey.');
} }
const body = JSON.stringify(bodyJson); const body = JSON.stringify(bodyJson);

View File

@ -644,23 +644,27 @@ module.exports = class User {
} }
generateMainKeyPair(cb) { generateMainKeyPair(cb) {
crypto.generateKeyPair('rsa', { crypto.generateKeyPair(
'rsa',
{
modulusLength: 4096, modulusLength: 4096,
publicKeyEncoding: { publicKeyEncoding: {
type: 'spki', type: 'spki',
format: 'pem' format: 'pem',
}, },
privateKeyEncoding: { privateKeyEncoding: {
type: 'pkcs8', type: 'pkcs8',
format: 'pem' format: 'pem',
} },
}, (err, publicKey, privateKey) => { },
(err, publicKey, privateKey) => {
if (!err) { if (!err) {
this.setProperty(UserProps.PrivateKeyMain, privateKey); this.setProperty(UserProps.PrivateKeyMain, privateKey);
this.setProperty(UserProps.PublicKeyMain, publicKey); this.setProperty(UserProps.PublicKeyMain, publicKey);
} }
return cb(err); return cb(err);
}); }
);
} }
persistProperties(properties, transOrDb, cb) { persistProperties(properties, transOrDb, cb) {