From ecc789a4a92b49a220fb25057be154bd07e55ec7 Mon Sep 17 00:00:00 2001 From: Preston Maness Date: Sun, 11 Jun 2023 23:41:33 -0500 Subject: [PATCH] first stab at it from keyoxide-web end --- src/api/v0/index.js | 3 ++- src/api/v2/keyoxide_profile.js | 3 ++- src/index.js | 4 +++- src/server/index.js | 8 ++++---- static-src/kx-claim.js | 7 ++++--- static-src/utils.js | 11 ++++++----- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/api/v0/index.js b/src/api/v0/index.js index 32c7764..c99e526 100644 --- a/src/api/v0/index.js +++ b/src/api/v0/index.js @@ -192,7 +192,8 @@ const doVerification = async (data) => { const verificationOptions = { proxy: { hostname: process.env.PROXY_HOSTNAME, - policy: (process.env.PROXY_HOSTNAME !== '') ? 'adaptive' : 'never' + policy: (process.env.PROXY_HOSTNAME !== '') ? 'adaptive' : 'never', + scheme: (process.env.PROXY_SCHEME !== '') ? process.env.PROXY_SCHEME : (process.env.SCHEME !== '') ? process.env.SCHEME : 'https' } } diff --git a/src/api/v2/keyoxide_profile.js b/src/api/v2/keyoxide_profile.js index f13a7c2..c009808 100644 --- a/src/api/v2/keyoxide_profile.js +++ b/src/api/v2/keyoxide_profile.js @@ -195,7 +195,8 @@ const doVerification = async (data) => { const verificationOptions = { proxy: { hostname: process.env.PROXY_HOSTNAME, - policy: (process.env.PROXY_HOSTNAME !== '') ? 'adaptive' : 'never' + policy: (process.env.PROXY_HOSTNAME !== '') ? 'adaptive' : 'never', + scheme: (process.env.PROXY_SCHEME !== '') ? process.env.PROXY_SCHEME : (process.env.SCHEME !== '') ? process.env.SCHEME : 'https' } } diff --git a/src/index.js b/src/index.js index 4e5008e..691e462 100644 --- a/src/index.js +++ b/src/index.js @@ -48,6 +48,7 @@ app.set('env', process.env.NODE_ENV || 'production') app.engine('pug', pug.__express).set('view engine', 'pug') app.set('port', process.env.PORT || 3000) app.set('domain', process.env.DOMAIN) +app.set('scheme', process.env.SCHEME || 'https') app.set('keyoxide_version', packageData.version) app.set('onion_url', process.env.ONION_URL) @@ -65,7 +66,8 @@ if (app.get('onion_url')) { } app.use(stringReplace({ - PLACEHOLDER__PROXY_HOSTNAME: process.env.PROXY_HOSTNAME || process.env.DOMAIN || 'null' + PLACEHOLDER__PROXY_HOSTNAME: process.env.PROXY_HOSTNAME || process.env.DOMAIN || 'null', + PLACEHOLDER__PROXY_SCHEME: process.env.PROXY_SCHEME || process.env.SCHEME || 'https' }, { contentTypeFilterRegexp: /application\/javascript/ })) diff --git a/src/server/index.js b/src/server/index.js index 06ad467..c348a13 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -46,7 +46,7 @@ const generateWKDProfile = async (id) => { keyData = processKeyData(keyData) const keyoxideData = {} - keyoxideData.url = `https://${process.env.DOMAIN}/wkd/${id}` + keyoxideData.url = `${process.env.SCHEME}://${process.env.DOMAIN}/wkd/${id}` logger.debug('Generating a WKD profile', { component: 'wkd_profile_generator', action: 'done', profile_id: id }) @@ -88,9 +88,9 @@ const generateHKPProfile = async (id, keyserverDomain) => { const keyoxideData = {} if (!keyserverDomain || keyserverDomain === 'keys.openpgp.org') { - keyoxideData.url = `https://${process.env.DOMAIN}/hkp/${id}` + keyoxideData.url = `${process.env.SCHEME}://${process.env.DOMAIN}/hkp/${id}` } else { - keyoxideData.url = `https://${process.env.DOMAIN}/hkp/${keyserverDomain}/${id}` + keyoxideData.url = `${process.env.SCHEME}://${process.env.DOMAIN}/hkp/${keyserverDomain}/${id}` } logger.debug('Generating a HKP profile', @@ -196,7 +196,7 @@ const generateKeybaseProfile = async (username, fingerprint) => { keyData = processKeyData(keyData) const keyoxideData = {} - keyoxideData.url = `https://${process.env.DOMAIN}/keybase/${username}/${fingerprint}` + keyoxideData.url = `${process.env.SCHEME}://${process.env.DOMAIN}/keybase/${username}/${fingerprint}` logger.debug('Generating a Keybase profile', { component: 'keybase_profile_generator', action: 'done', username, fingerprint }) diff --git a/static-src/kx-claim.js b/static-src/kx-claim.js index fa4ab83..5db2adf 100644 --- a/static-src/kx-claim.js +++ b/static-src/kx-claim.js @@ -49,7 +49,8 @@ export class Claim extends HTMLElement { await claim.verify({ proxy: { policy: 'adaptive', - hostname: 'PLACEHOLDER__PROXY_HOSTNAME' + hostname: 'PLACEHOLDER__PROXY_HOSTNAME', + scheme: 'PLACEHOLDER__PROXY_SCHEME' } }); this.setAttribute('data-claim', JSON.stringify(claim)); @@ -192,7 +193,7 @@ export class Claim extends HTMLElement { const subsection_info_text = subsection_info.appendChild(document.createElement('div')); const result_proxyUsed = subsection_info_text.appendChild(document.createElement('p')); - result_proxyUsed.innerHTML = `A proxy was used to fetch the proof: PLACEHOLDER__PROXY_HOSTNAME`; + result_proxyUsed.innerHTML = `A proxy was used to fetch the proof: PLACEHOLDER__PROXY_HOSTNAME`; } // TODO Display errors @@ -217,4 +218,4 @@ export class Claim extends HTMLElement { // }); // } } -} \ No newline at end of file +} diff --git a/static-src/utils.js b/static-src/utils.js index 50e21b5..98135cb 100644 --- a/static-src/utils.js +++ b/static-src/utils.js @@ -46,19 +46,20 @@ export async function computeWKDLocalPart(localPart) { // Generate Keyoxide profile URL export async function generateProfileURL(data) { let hostname = data.hostname || window.location.hostname; + let scheme = data.scheme || window.location.protocol.slice(0,-1); if (data.input == "") { return "Waiting for input…"; } switch (data.source) { case "wkd": - return `https://${hostname}/${data.input}`; + return `${scheme}://${hostname}/${data.input}`; break; case "hkp": if (/.*@.*\..*/.test(data.input)) { - return `https://${hostname}/hkp/${data.input}`; + return `${scheme}://${hostname}/hkp/${data.input}`; } else { - return `https://${hostname}/${data.input}`; + return `${scheme}://${hostname}/${data.input}`; } break; case "keybase": @@ -67,7 +68,7 @@ export async function generateProfileURL(data) { return "Incorrect Keybase public key URL."; } const match = data.input.match(re); - return `https://${hostname}/keybase/${match[1]}/${match[2]}`; + return `${scheme}://${hostname}/keybase/${match[1]}/${match[2]}`; break; } } @@ -240,4 +241,4 @@ export async function verifyBcryptHash(input, hash) { } catch (_) { return false; } -} \ No newline at end of file +}