Permalink
Browse files

improved error messaging, handling more than 3 zone levels

  • Loading branch information...
larryboymi committed Mar 30, 2018
1 parent 116029f commit 97849c64ad1481dc0da28c1c8594c47795f1bd8c
View
@@ -2,7 +2,7 @@ const cert = require('../app.js')
const testContext = {
succeed: (data) => {
console.log(data)
console.log(`Results are ${JSON.stringify(data)}`)
process.exit(0)
}
}
@@ -7,6 +7,7 @@ const config = require('../../../config')
const promisify = require('es6-promisify')
const resolveTxt = promisify(dns.resolveTxt)
const urlB64 = require('../urlB64')
const retry = require('../../retry')(config['acme-dns-retry-delay-ms'], config['acme-dns-retry'])
const getTokenDigest = (dnsChallenge, acctKeyPair) =>
crypto.createHash('sha256').update(`${dnsChallenge.token}.${RSA.thumbprint(acctKeyPair)}`).digest()
@@ -26,11 +27,6 @@ const updateDNSChallenge = (domain, dnsChallenge, acctKeyPair) => {
})
}
const delayPromise = (delay) => (data) =>
new Promise((resolve, reject) => {
setTimeout(() => { resolve(data) }, delay)
})
const dnsPreCheck = (domain, expect) => (tryCount) => {
console.log(`Attempt ${tryCount + 1} to resolve TXT record for ${domain}`)
return resolveTxt(`_acme-challenge.${domain}`)
@@ -56,12 +52,4 @@ const validateDNSChallenge = (domain, dnsChallengeText) => {
})
}
const retry = (tryCount, promise) =>
promise(tryCount).then(delayPromise(config['acme-dns-retry-delay-ms']))
.then((data) =>
(tryCount < config['acme-dns-retry'] && !data.result)
? retry(data.tryCount, promise)
: data
)
module.exports = updateDNSChallenge
View
@@ -3,7 +3,20 @@ const sendSignedRequestV2 = require('./sendSignedRequestV2')
module.exports = (domains, keypair, orderUrl, nonceUrl, url) => {
console.log(`Submitting new order to ${orderUrl} for ${JSON.stringify(domains)}`)
return sendSignedRequestV2({
"identifiers": domains.map(domain => ({"type": "dns", "value": domain}))
"identifiers": domains.map(domain =>
typeof domain === 'object'
? ({"type": "dns", "value": domain.name})
: ({"type": "dns", "value": domain})
)
}, keypair, orderUrl, nonceUrl, url)
.then(data => data.header['location'])
.catch(err => {
if (err.response && err.response.text) {
const detailObj = JSON.parse(err.response.text)
if (detailObj.detail && detailObj.detail.indexOf('redundant') > -1) {
console.log(`Fatal error, thought we would show it to you: ${detailObj.detail}`)
}
}
throw err
})
}
@@ -3,13 +3,22 @@ const downloadtext = require('../../util/downloadText')
const {toIssuerCert, toPEM, toStandardB64} = require('../certUtils')
const newCertificate = (keypair, finalizeUrl, nonceUrl, url) => (csr) => {
console.log('Requesting certificate from lets-encrypt')
console.log('Requesting certificate.')
return sendSignedRequestV2({
csr
}, keypair, finalizeUrl, nonceUrl, url)
.then(({body}) =>
downloadtext(body.certificate)
)
.catch(err => {
if (err.response && err.response.text) {
const detailObj = JSON.parse(err.response.text)
if (detailObj.type && detailObj.type.indexOf('serverInternal') > -1) {
console.log(`Encountered an internal acme server error, will need to retry this configuration (re-run lambda).`)
}
}
throw err
})
}
module.exports = newCertificate
@@ -8,7 +8,12 @@ const sendSignedRequest = (payload, keypair, url, nonceUrl, kid = undefined) =>
const {header} = RSA.signJws(keypair, new Buffer(JSON.stringify(payload)), nonce)
const toSend = RSA.signJws(keypair, undefined, Object.assign(kid ? {kid, alg: header.alg} : header, {nonce, url}), new Buffer(JSON.stringify(payload)))
return agent.post(url)
.type('application/jose+json')
.send(toSend)
// .catch(err => { for extra debug you can uncomment this block for v2 cases
// console.log(`The error was ${JSON.stringify(err.response)}`)
// throw err
// })
})
module.exports = sendSignedRequest
View
@@ -5,8 +5,12 @@ const readFile = (bucket, siteId, fileName) =>
Bucket: bucket,
Key: `${siteId}/${fileName}`
}).promise()
.catch((e) => {
console.error(`Couldn't read s3://${bucket}/${siteId}/${fileName}`, e)
.catch(e => {
if (e.message.indexOf('does not exist')) {
console.log(`s3://${bucket}/${siteId}/${fileName} does not exist.`)
} else {
console.error(`Couldn't read s3://${bucket}/${siteId}/${fileName}`, e)
}
throw e
})
View
@@ -0,0 +1,14 @@
const delayPromise = delay => data =>
new Promise((resolve, reject) => {
setTimeout(() => { resolve(data) }, delay)
})
const retry = (delay, howManyTimes) => (tryCount, promise) =>
promise(tryCount).then(delayPromise(delay))
.then((data) =>
(tryCount < howManyTimes && !data.result)
? retry(delay, howManyTimes)(data.tryCount, promise)
: data
)
module.exports = retry

0 comments on commit 97849c6

Please sign in to comment.