From 0bb0d8de72c17e7a215d87e16e7cb00b8af48cb0 Mon Sep 17 00:00:00 2001 From: fenwick67 Date: Sun, 13 Oct 2024 12:38:08 -0400 Subject: [PATCH] change the fuckin key algo --- index.js | 2 +- lib/apCryptoShit.js | 6 +++--- lib/apGet.js | 3 ++- utils/ensure-keys-work.js | 7 ++----- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 8f72093..ce762c5 100644 --- a/index.js +++ b/index.js @@ -205,7 +205,7 @@ app.get('/.well-known/webfinger', function(req,res){ return res.send(JSON.stringify(resJson)); } else { res.status(404); - res.send(); + res.send("unknown user"); } }) diff --git a/lib/apCryptoShit.js b/lib/apCryptoShit.js index ebd8bba..1162d78 100644 --- a/lib/apCryptoShit.js +++ b/lib/apCryptoShit.js @@ -21,16 +21,16 @@ function getKeyId(){ function sign(str){ _precheck() - var signerObject = crypto.createSign("RSA-SHA256"); + var signerObject = crypto.createSign("RSA-SHA256");// needs to be "RSASSA-PKCS1-v1_5 with SHA-256" I'm assuming this is RSA_PKCS1_PADDING...??? signerObject.update(str); - return signerObject.sign({key:getPrivateKey(),padding:crypto.constants.RSA_PKCS1_PSS_PADDING}, "base64"); + return signerObject.sign({key:_privKey,padding:crypto.constants.RSA_PKCS1_PADDING}, "base64"); } function verify(str,signature){ _precheck(); var verifierObject = crypto.createVerify("RSA-SHA256"); verifierObject.update(str); - var verified = verifierObject.verify({key:_pubKey, padding:crypto.constants.RSA_PKCS1_PSS_PADDING}, signature, "base64"); + return verifierObject.verify({key:_pubKey, padding:crypto.constants.RSA_PKCS1_PADDING}, signature, "base64"); } // private diff --git a/lib/apGet.js b/lib/apGet.js index c6c88a7..1ab958d 100644 --- a/lib/apGet.js +++ b/lib/apGet.js @@ -64,7 +64,8 @@ module.exports = async function apGet(url,ttl) { axiosOpts.headers.Signature=Authorization; - console.log("axios request info: \n"+JSON.stringify(axiosOpts,null,2)) + console.log("axios request info: \n"+JSON.stringify(axiosOpts,null,2)); + console.log('string that was signed: \n---\n'+plaintext+'\n---') let response try { diff --git a/utils/ensure-keys-work.js b/utils/ensure-keys-work.js index b77ba25..5875545 100644 --- a/utils/ensure-keys-work.js +++ b/utils/ensure-keys-work.js @@ -3,9 +3,6 @@ const cryptoShit = require('../lib/apCryptoShit.js') var signature = cryptoShit.sign("hello world") -console.info("signature: %s", signature); -//verify String -var verifierObject = crypto.createVerify("RSA-SHA256"); -verifierObject.update("hello world"); -var verified = verifierObject.verify({key:cryptoShit.getPublicKey(), padding:crypto.constants.RSA_PKCS1_PSS_PADDING}, signature, "base64"); +var verified = cryptoShit.verify("hello world", signature) + console.info("is signature ok?: %s", verified); \ No newline at end of file