first stab at it from keyoxide-web end

This commit is contained in:
Preston Maness 2023-06-11 23:41:33 -05:00
parent 5e0561df7e
commit ecc789a4a9
6 changed files with 21 additions and 15 deletions

View file

@ -192,7 +192,8 @@ const doVerification = async (data) => {
const verificationOptions = { const verificationOptions = {
proxy: { proxy: {
hostname: process.env.PROXY_HOSTNAME, 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'
} }
} }

View file

@ -195,7 +195,8 @@ const doVerification = async (data) => {
const verificationOptions = { const verificationOptions = {
proxy: { proxy: {
hostname: process.env.PROXY_HOSTNAME, 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'
} }
} }

View file

@ -48,6 +48,7 @@ app.set('env', process.env.NODE_ENV || 'production')
app.engine('pug', pug.__express).set('view engine', 'pug') app.engine('pug', pug.__express).set('view engine', 'pug')
app.set('port', process.env.PORT || 3000) app.set('port', process.env.PORT || 3000)
app.set('domain', process.env.DOMAIN) app.set('domain', process.env.DOMAIN)
app.set('scheme', process.env.SCHEME || 'https')
app.set('keyoxide_version', packageData.version) app.set('keyoxide_version', packageData.version)
app.set('onion_url', process.env.ONION_URL) app.set('onion_url', process.env.ONION_URL)
@ -65,7 +66,8 @@ if (app.get('onion_url')) {
} }
app.use(stringReplace({ 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/ contentTypeFilterRegexp: /application\/javascript/
})) }))

View file

@ -46,7 +46,7 @@ const generateWKDProfile = async (id) => {
keyData = processKeyData(keyData) keyData = processKeyData(keyData)
const keyoxideData = {} 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', logger.debug('Generating a WKD profile',
{ component: 'wkd_profile_generator', action: 'done', profile_id: id }) { component: 'wkd_profile_generator', action: 'done', profile_id: id })
@ -88,9 +88,9 @@ const generateHKPProfile = async (id, keyserverDomain) => {
const keyoxideData = {} const keyoxideData = {}
if (!keyserverDomain || keyserverDomain === 'keys.openpgp.org') { 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 { } 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', logger.debug('Generating a HKP profile',
@ -196,7 +196,7 @@ const generateKeybaseProfile = async (username, fingerprint) => {
keyData = processKeyData(keyData) keyData = processKeyData(keyData)
const keyoxideData = {} 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', logger.debug('Generating a Keybase profile',
{ component: 'keybase_profile_generator', action: 'done', username, fingerprint }) { component: 'keybase_profile_generator', action: 'done', username, fingerprint })

View file

@ -49,7 +49,8 @@ export class Claim extends HTMLElement {
await claim.verify({ await claim.verify({
proxy: { proxy: {
policy: 'adaptive', policy: 'adaptive',
hostname: 'PLACEHOLDER__PROXY_HOSTNAME' hostname: 'PLACEHOLDER__PROXY_HOSTNAME',
scheme: 'PLACEHOLDER__PROXY_SCHEME'
} }
}); });
this.setAttribute('data-claim', JSON.stringify(claim)); 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 subsection_info_text = subsection_info.appendChild(document.createElement('div'));
const result_proxyUsed = subsection_info_text.appendChild(document.createElement('p')); const result_proxyUsed = subsection_info_text.appendChild(document.createElement('p'));
result_proxyUsed.innerHTML = `A proxy was used to fetch the proof: <a href="https://PLACEHOLDER__PROXY_HOSTNAME" aria-label="Link to proxy server">PLACEHOLDER__PROXY_HOSTNAME</a>`; result_proxyUsed.innerHTML = `A proxy was used to fetch the proof: <a href="PLACEHOLDER__PROXY_SCHEME://PLACEHOLDER__PROXY_HOSTNAME" aria-label="Link to proxy server">PLACEHOLDER__PROXY_HOSTNAME</a>`;
} }
// TODO Display errors // TODO Display errors
@ -217,4 +218,4 @@ export class Claim extends HTMLElement {
// }); // });
// } // }
} }
} }

View file

@ -46,19 +46,20 @@ export async function computeWKDLocalPart(localPart) {
// Generate Keyoxide profile URL // Generate Keyoxide profile URL
export async function generateProfileURL(data) { export async function generateProfileURL(data) {
let hostname = data.hostname || window.location.hostname; let hostname = data.hostname || window.location.hostname;
let scheme = data.scheme || window.location.protocol.slice(0,-1);
if (data.input == "") { if (data.input == "") {
return "Waiting for input…"; return "Waiting for input…";
} }
switch (data.source) { switch (data.source) {
case "wkd": case "wkd":
return `https://${hostname}/${data.input}`; return `${scheme}://${hostname}/${data.input}`;
break; break;
case "hkp": case "hkp":
if (/.*@.*\..*/.test(data.input)) { if (/.*@.*\..*/.test(data.input)) {
return `https://${hostname}/hkp/${data.input}`; return `${scheme}://${hostname}/hkp/${data.input}`;
} else { } else {
return `https://${hostname}/${data.input}`; return `${scheme}://${hostname}/${data.input}`;
} }
break; break;
case "keybase": case "keybase":
@ -67,7 +68,7 @@ export async function generateProfileURL(data) {
return "Incorrect Keybase public key URL."; return "Incorrect Keybase public key URL.";
} }
const match = data.input.match(re); const match = data.input.match(re);
return `https://${hostname}/keybase/${match[1]}/${match[2]}`; return `${scheme}://${hostname}/keybase/${match[1]}/${match[2]}`;
break; break;
} }
} }
@ -240,4 +241,4 @@ export async function verifyBcryptHash(input, hash) {
} catch (_) { } catch (_) {
return false; return false;
} }
} }