From f86bda3bb709f29e4264fb8de45242f518128744 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Thu, 5 Mar 2020 20:36:15 +0100 Subject: [PATCH] fix: allow importing simpler passphrases as `oct` keys --- lib/jwk/import.js | 2 +- test/jwk/oct.test.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/jwk/import.js b/lib/jwk/import.js index 46aa42b8cc..c07d71d723 100644 --- a/lib/jwk/import.js +++ b/lib/jwk/import.js @@ -26,7 +26,7 @@ const mergedParameters = (target = {}, source = {}) => { } } -const openSSHpublicKey = /^[a-zA-Z0-9-]+ (?:[a-zA-Z0-9+/])*(?:==|=)?(?: .*)?$/ +const openSSHpublicKey = /^[a-zA-Z0-9-]+ AAAA(?:[0-9A-Za-z+/])+(?:==|=)?(?: .*)?$/ const asKey = (key, parameters, { calculateMissingRSAPrimes = false } = {}) => { let privateKey, publicKey, secret diff --git a/test/jwk/oct.test.js b/test/jwk/oct.test.js index 1bbba1ef9b..27244884d7 100644 --- a/test/jwk/oct.test.js +++ b/test/jwk/oct.test.js @@ -204,3 +204,11 @@ b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW` }, { instanceOf: errors.JWKImportFailed, message: 'key import failed' }) }) }) + +test('some phrases do not fall through to openssh check', t => { + asKey('secret') + asKey('secret phrase') + asKey('longer secret phrase') + asKey('very long secret phrase') + t.pass() +})