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 {
const normalizedName = _.camelCase(module.moduleInfo.name);
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);
}
Log.info({ moduleName: normalizedName }, 'Initializing web handler module.');
Log.info(
{ moduleName: normalizedName },
'Initializing web handler module.'
);
moduleInst.init(err => {
return nextModule(err);

View File

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

View File

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