0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00
ghost/core/server/web/well-known.js
naz 6cc0c2b76b
🐛 Fixed signing key identificaiton in JWKs
refs https://github.com/TryGhost/Team/issues/1640

- The signing key returned by `GET /ghost/.well-known/jwks.json` was missing an OPTIONAL `use: "sig"` attribute needed to identify it as a signing key in client libraries. E.g. pyton lib: "pyjwt" or node lib: "jwks-client"
- More about the "use" attribute at RFC7515 - https://www.rfc-editor.org/rfc/rfc7515#section-4.1.4
2022-05-24 12:20:30 +01:00

36 lines
1 KiB
JavaScript

const express = require('../../shared/express');
const settings = require('../../shared/settings-cache');
module.exports = function setupWellKnownApp() {
const wellKnownApp = express('well-known');
const jose = require('node-jose');
const dangerousPrivateKey = settings.get('ghost_private_key');
const keyStore = jose.JWK.createKeyStore();
const keyStoreReady = keyStore.add(dangerousPrivateKey, 'pem');
const getSafePublicJWKS = async () => {
await keyStoreReady;
return keyStore.toJSON();
};
wellKnownApp.get('/jwks.json', async (req, res) => {
const jwks = await getSafePublicJWKS();
// there's only one key in the store atm
// based on this setting all of the keys to have
// "use": "sig" property
const keys = jwks.keys
.map(key => ({
e: key.e,
kid: key.kid,
kty: key.kty,
n: key.n,
use: 'sig'
}));
res.json({keys});
});
return wellKnownApp;
};