now getting a valid response

This commit is contained in:
Philipp Kunz 2017-01-25 02:45:48 +01:00
parent 5fa530456b
commit 20ea599f9d
8 changed files with 141 additions and 120 deletions

View File

@ -17,7 +17,7 @@ export interface ISmartAcmeChallenge {
token: string; token: string;
keyAuthorization: string; keyAuthorization: string;
} }
export interface ISmartAcmeChallengeAccepted extends ISmartAcmeChallenge { export interface ISmartAcmeChallengeChosen extends ISmartAcmeChallenge {
dnsKeyHash: string; dnsKeyHash: string;
domainName: string; domainName: string;
domainNamePrefixed: string; domainNamePrefixed: string;
@ -41,7 +41,6 @@ export interface IAcmeCsrConstructorOptions {
export declare class AcmeCert { export declare class AcmeCert {
domainName: string; domainName: string;
attributes: any; attributes: any;
acceptedChallenge: ISmartAcmeChallengeAccepted;
fullchain: string; fullchain: string;
parentAcmeAccount: AcmeAccount; parentAcmeAccount: AcmeAccount;
csr: any; csr: any;
@ -49,13 +48,15 @@ export declare class AcmeCert {
validTo: Date; validTo: Date;
keypair: IRsaKeypair; keypair: IRsaKeypair;
keyPairFinal: IRsaKeypair; keyPairFinal: IRsaKeypair;
chosenChallenge: ISmartAcmeChallengeChosen;
dnsKeyHash: string;
constructor(optionsArg: IAcmeCsrConstructorOptions, parentAcmeAccount: AcmeAccount); constructor(optionsArg: IAcmeCsrConstructorOptions, parentAcmeAccount: AcmeAccount);
/** /**
* requests a challenge for a domain * requests a challenge for a domain
* @param domainNameArg - the domain name to request a challenge for * @param domainNameArg - the domain name to request a challenge for
* @param challengeType - the challenge type to request * @param challengeType - the challenge type to request
*/ */
requestChallenge(challengeTypeArg?: TChallengeType): q.Promise<ISmartAcmeChallengeAccepted>; requestChallenge(challengeTypeArg?: TChallengeType): q.Promise<ISmartAcmeChallengeChosen>;
/** /**
* checks if DNS records are set, will go through a max of 30 cycles * checks if DNS records are set, will go through a max of 30 cycles
*/ */
@ -75,5 +76,5 @@ export declare class AcmeCert {
/** /**
* accept a challenge - for private use only * accept a challenge - for private use only
*/ */
private acceptChallenge(challengeArg); acceptChallenge(): q.Promise<{}>;
} }

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ export interface IRsaKeypair {
privateKey: string; privateKey: string;
} }
export { AcmeAccount } from './smartacme.classes.acmeaccount'; export { AcmeAccount } from './smartacme.classes.acmeaccount';
export { AcmeCert, ISmartAcmeChallenge, ISmartAcmeChallengeAccepted } from './smartacme.classes.acmecert'; export { AcmeCert, ISmartAcmeChallenge, ISmartAcmeChallengeChosen } from './smartacme.classes.acmecert';
/** /**
* class SmartAcme exports methods for maintaining SSL Certificates * class SmartAcme exports methods for maintaining SSL Certificates
*/ */

View File

@ -63,4 +63,4 @@ class SmartAcme {
} }
} }
exports.SmartAcme = SmartAcme; exports.SmartAcme = SmartAcme;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRhY21lLmNsYXNzZXMuc21hcnRhY21lLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxzQkFBc0I7QUFDdEIsdUJBQXNCLENBQUMsV0FBVztBQUNsQywrQ0FBOEM7QUFDOUMsK0NBQThDO0FBRTlDLG1GQUE2RDtBQVU3RCxpRkFBNkQ7QUFBcEQsc0RBQUEsV0FBVyxDQUFBO0FBQ3BCLDJFQUF5RztBQUFoRyxnREFBQSxRQUFRLENBQUE7QUFFakI7O0dBRUc7QUFDSDtJQU1JOztPQUVHO0lBQ0gsWUFBWSxnQkFBeUIsS0FBSztRQUN0QyxJQUFJLENBQUMsY0FBYyxHQUFHLGFBQWEsQ0FBQTtRQUNuQyxJQUFJLENBQUMsT0FBTyxHQUFHLE9BQU8sQ0FBQyxhQUFhLEVBQUUsQ0FBQTtRQUN0QyxFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsY0FBYyxDQUFDLENBQUMsQ0FBQztZQUN0QixJQU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BQ3ZCLENBQUM7SUFFRDs7O09BR0c7SUFDSCxpQkFBaUI7UUFDYixJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFlLENBQUE7UUFDakMsSUFBSSxXQUFXLEdBQUcsSUFBSSwyQ0FBVyxDQUFDLElBQUksQ0FBQyxDQUFBO1FBQ3ZDLFdBQVcsQ0FBQyxRQUFRLEVBQUUsQ0FBQyxJQUFJLENBQUM7WUFDeEIsTUFBTSxDQUFDLFdBQVcsQ0FBQyxRQUFRLEVBQUUsQ0FBQTtRQUNqQyxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUM7WUFDSixJQUFJLENBQUMsT0FBTyxDQUFDLFdBQVcsQ0FBQyxDQUFBO1FBQzdCLENBQUMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztDQUNKO0FBNURELDhCQTREQyJ9

View File

@ -18,7 +18,7 @@ describe('smartacme', function () {
let testChallenge; let testChallenge;
it('should create a valid instance', function (done) { it('should create a valid instance', function (done) {
this.timeout(10000); this.timeout(10000);
testSmartAcme = new smartacme.SmartAcme(); testSmartAcme = new smartacme.SmartAcme(false);
testSmartAcme.init().then(() => { testSmartAcme.init().then(() => {
should(testSmartAcme).be.instanceOf(smartacme.SmartAcme); should(testSmartAcme).be.instanceOf(smartacme.SmartAcme);
done(); done();
@ -38,32 +38,36 @@ describe('smartacme', function () {
}); });
}); });
it('should create a AcmeCert', function () { it('should create a AcmeCert', function () {
testAcmeAccount.createAcmeCert('test1.bleu.de').then(x => { testAcmeAccount.createAcmeCert('carglide.com').then(x => {
testAcmeCert = x; testAcmeCert = x;
should(testAcmeAccount).be.instanceOf(smartacme.AcmeCert); should(testAcmeAccount).be.instanceOf(smartacme.AcmeCert);
}); });
}); });
it('should get a challenge for a AcmeCert', function (done) { it('should get a challenge for a AcmeCert', function (done) {
this.timeout(10000); this.timeout(10000);
testAcmeCert.requestChallenge().then((challengeAccepted) => { testAcmeCert.requestChallenge().then((challengeChosen) => {
console.log(challengeAccepted); console.log(challengeChosen);
testChallenge = challengeAccepted; testChallenge = challengeChosen;
done(); done();
}); });
}); });
it('should set the challenge', function (done) { it('should set the challenge', function (done) {
this.timeout(30000); this.timeout(10000);
myCflareAccount.createRecord(testChallenge.domainNamePrefixed, 'TXT', testChallenge.dnsKeyHash).then(() => { myCflareAccount.createRecord(testChallenge.domainNamePrefixed, 'TXT', testChallenge.dnsKeyHash).then(() => {
done(); done();
}); });
}); });
it('should check for a DNS record', function (done) { it('should check for a DNS record', function (done) {
this.timeout(40000); this.timeout(20000);
testAcmeCert.checkDns().then(x => { testAcmeCert.checkDns().then(x => {
console.log(x); console.log(x);
done(); done();
}); });
}); });
it('should accept the challenge', function (done) {
this.timeout(10000);
testAcmeCert.acceptChallenge().then(() => { done(); });
});
it('should poll for validation of a challenge', function (done) { it('should poll for validation of a challenge', function (done) {
this.timeout(700000); this.timeout(700000);
testAcmeCert.requestValidation().then(x => { testAcmeCert.requestValidation().then(x => {
@ -72,4 +76,4 @@ describe('smartacme', function () {
}); });
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFDaEMsaUNBQWdDO0FBQ2hDLDZCQUE0QjtBQUU1QixJQUFJLFFBQVEsR0FBRyxJQUFJLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLEdBQUcsRUFBRSxFQUFFLE9BQU8sQ0FBQyxHQUFHLEVBQUUsR0FBRyxTQUFTLENBQUMsQ0FBQTtBQUV0RSw0QkFBNEI7QUFDNUIsMkNBQTBDO0FBRTFDLElBQUksZUFBZSxHQUFHLElBQUksTUFBTSxDQUFDLGFBQWEsR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JLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFBO1FBQ25CLFlBQVksQ0FBQyxlQUFlLEVBQUUsQ0FBQyxJQUFJLENBQUMsUUFBUSxJQUFJLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO0lBQ3pELENBQUMsQ0FBQyxDQUFBO0lBRUYsRUFBRSxDQUFDLDJDQUEyQyxFQUFFLFVBQVUsSUFBSTtRQUMxRCxJQUFJLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFBO1FBQ3BCLFlBQVksQ0FBQyxpQkFBaUIsRUFBRSxDQUFDLElBQUksQ0FBQyxDQUFDO1lBQ25DLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUE7WUFDZCxJQUFJLEVBQUUsQ0FBQTtRQUNWLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9

View File

@ -18,11 +18,11 @@ describe('smartacme', function () {
let testSmartAcme: smartacme.SmartAcme let testSmartAcme: smartacme.SmartAcme
let testAcmeAccount: smartacme.AcmeAccount let testAcmeAccount: smartacme.AcmeAccount
let testAcmeCert: smartacme.AcmeCert let testAcmeCert: smartacme.AcmeCert
let testChallenge: smartacme.ISmartAcmeChallengeAccepted let testChallenge: smartacme.ISmartAcmeChallengeChosen
it('should create a valid instance', function (done) { it('should create a valid instance', function (done) {
this.timeout(10000) this.timeout(10000)
testSmartAcme = new smartacme.SmartAcme() testSmartAcme = new smartacme.SmartAcme(false)
testSmartAcme.init().then(() => { testSmartAcme.init().then(() => {
should(testSmartAcme).be.instanceOf(smartacme.SmartAcme) should(testSmartAcme).be.instanceOf(smartacme.SmartAcme)
done() done()
@ -45,7 +45,7 @@ describe('smartacme', function () {
}) })
it('should create a AcmeCert', function() { it('should create a AcmeCert', function() {
testAcmeAccount.createAcmeCert('test1.bleu.de').then(x => { testAcmeAccount.createAcmeCert('carglide.com').then(x => {
testAcmeCert = x testAcmeCert = x
should(testAcmeAccount).be.instanceOf(smartacme.AcmeCert) should(testAcmeAccount).be.instanceOf(smartacme.AcmeCert)
}) })
@ -53,15 +53,15 @@ describe('smartacme', function () {
it('should get a challenge for a AcmeCert', function (done) { it('should get a challenge for a AcmeCert', function (done) {
this.timeout(10000) this.timeout(10000)
testAcmeCert.requestChallenge().then((challengeAccepted) => { testAcmeCert.requestChallenge().then((challengeChosen) => {
console.log(challengeAccepted) console.log(challengeChosen)
testChallenge = challengeAccepted testChallenge = challengeChosen
done() done()
}) })
}) })
it('should set the challenge', function(done) { it('should set the challenge', function(done) {
this.timeout(30000) this.timeout(10000)
myCflareAccount.createRecord( myCflareAccount.createRecord(
testChallenge.domainNamePrefixed, testChallenge.domainNamePrefixed,
'TXT', testChallenge.dnsKeyHash 'TXT', testChallenge.dnsKeyHash
@ -71,13 +71,18 @@ describe('smartacme', function () {
}) })
it('should check for a DNS record', function(done) { it('should check for a DNS record', function(done) {
this.timeout(40000) this.timeout(20000)
testAcmeCert.checkDns().then(x => { testAcmeCert.checkDns().then(x => {
console.log(x) console.log(x)
done() done()
}) })
}) })
it('should accept the challenge', function(done){
this.timeout(10000)
testAcmeCert.acceptChallenge().then(() => { done() })
})
it('should poll for validation of a challenge', function (done) { it('should poll for validation of a challenge', function (done) {
this.timeout(700000) this.timeout(700000)
testAcmeCert.requestValidation().then(x => { testAcmeCert.requestValidation().then(x => {

View File

@ -24,7 +24,7 @@ export interface ISmartAcmeChallenge {
keyAuthorization: string keyAuthorization: string
} }
export interface ISmartAcmeChallengeAccepted extends ISmartAcmeChallenge { export interface ISmartAcmeChallengeChosen extends ISmartAcmeChallenge {
dnsKeyHash: string dnsKeyHash: string
domainName: string domainName: string
domainNamePrefixed: string domainNamePrefixed: string
@ -53,7 +53,6 @@ let myDnsly = new plugins.dnsly.Dnsly('google')
export class AcmeCert { export class AcmeCert {
domainName: string domainName: string
attributes attributes
acceptedChallenge: ISmartAcmeChallengeAccepted
fullchain: string fullchain: string
parentAcmeAccount: AcmeAccount parentAcmeAccount: AcmeAccount
csr csr
@ -61,6 +60,8 @@ export class AcmeCert {
validTo: Date validTo: Date
keypair: IRsaKeypair keypair: IRsaKeypair
keyPairFinal: IRsaKeypair keyPairFinal: IRsaKeypair
chosenChallenge: ISmartAcmeChallengeChosen
dnsKeyHash: string
constructor(optionsArg: IAcmeCsrConstructorOptions, parentAcmeAccount: AcmeAccount) { constructor(optionsArg: IAcmeCsrConstructorOptions, parentAcmeAccount: AcmeAccount) {
this.domainName = optionsArg.domain this.domainName = optionsArg.domain
this.parentAcmeAccount = parentAcmeAccount this.parentAcmeAccount = parentAcmeAccount
@ -103,7 +104,7 @@ export class AcmeCert {
* @param challengeType - the challenge type to request * @param challengeType - the challenge type to request
*/ */
requestChallenge(challengeTypeArg: TChallengeType = 'dns-01') { requestChallenge(challengeTypeArg: TChallengeType = 'dns-01') {
let done = q.defer<ISmartAcmeChallengeAccepted>() let done = q.defer<ISmartAcmeChallengeChosen>()
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.newAuthz( this.parentAcmeAccount.parentSmartAcme.rawacmeClient.newAuthz(
{ {
identifier: { identifier: {
@ -118,13 +119,36 @@ export class AcmeCert {
console.log(err) console.log(err)
done.reject(err) done.reject(err)
} }
let dnsChallenge = res.body.challenges.filter(x => { let preChosenChallenge = res.body.challenges.filter(x => {
return x.type === challengeTypeArg return x.type === challengeTypeArg
})[0] })[0]
this.acceptChallenge(dnsChallenge)
.then((x: ISmartAcmeChallengeAccepted) => { /**
done.resolve(x) * the key is needed to accept the challenge
}) */
let authKey: string = plugins.rawacme.keyAuthz(
preChosenChallenge.token,
this.parentAcmeAccount.parentSmartAcme.keyPair.publicKey
)
/**
* needed in case selected challenge is of type dns-01
*/
this.dnsKeyHash = plugins.rawacme.dnsKeyAuthzHash(authKey) // needed if dns challenge is chosen
/**
* the return challenge
*/
this.chosenChallenge = {
uri: preChosenChallenge.uri,
type: preChosenChallenge.type,
token: preChosenChallenge.token,
keyAuthorization: authKey,
status: preChosenChallenge.status,
dnsKeyHash: this.dnsKeyHash,
domainName: this.domainName,
domainNamePrefixed: helpers.prefixName(this.domainName)
}
done.resolve(this.chosenChallenge)
} }
) )
return done.promise return done.promise
@ -134,13 +158,7 @@ export class AcmeCert {
* checks if DNS records are set, will go through a max of 30 cycles * checks if DNS records are set, will go through a max of 30 cycles
*/ */
async checkDns(cycleArg = 1) { async checkDns(cycleArg = 1) {
console.log(`checkDns failed ${cycleArg} times and has ${30 - cycleArg} cycles to go before it fails permanently!`) let redoCheck = async (err?) => {
let myRecord
try {
myRecord = await myDnsly.getRecord(helpers.prefixName(this.domainName), 'TXT')
console.log('DNS is set!')
return myRecord[0][0]
} catch (err) {
if (cycleArg < 30) { if (cycleArg < 30) {
cycleArg++ cycleArg++
await plugins.smartdelay.delayFor(2000) await plugins.smartdelay.delayFor(2000)
@ -150,17 +168,32 @@ export class AcmeCert {
throw err throw err
} }
} }
console.log(`checkDns failed ${cycleArg} times and has ${30 - cycleArg} cycles to go before it fails permanently!`)
let myRecord
try {
myRecord = await myDnsly.getRecord(helpers.prefixName(this.domainName), 'TXT')
myRecord = myRecord[0][0]
if (myRecord === this.dnsKeyHash) {
console.log('and matches the required dnsKeyHash')
} else {
console.log('but does not match required dns keyHash!')
return redoCheck()
}
console.log('DNS is set!')
return myRecord
} catch (err) {
return redoCheck()
}
} }
/** /**
* validates a challenge, only call after you have set the challenge at the expected location * validates a challenge, only call after you have set the challenge at the expected location
*/ */
async requestValidation() { async requestValidation() {
console.log('give it 2 minutes to settle!') await plugins.smartdelay.delayFor(20000)
await plugins.smartdelay.delayFor(120000)
let makeRequest = () => { let makeRequest = () => {
let done = q.defer() let done = q.defer()
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.poll(this.acceptedChallenge.uri, async (err, res) => { this.parentAcmeAccount.parentSmartAcme.rawacmeClient.poll(this.chosenChallenge.uri, async (err, res) => {
if (err) { if (err) {
console.log(err) console.log(err)
return return
@ -168,8 +201,8 @@ export class AcmeCert {
console.log(`Validation response:`) console.log(`Validation response:`)
console.log(JSON.stringify(res.body)) console.log(JSON.stringify(res.body))
if (res.body.status === 'pending' || 'invalid') { if (res.body.status === 'pending' || 'invalid') {
console.log('retry in 4 minutes!') console.log('retry in 6 minutes!')
await plugins.smartdelay.delayFor(240000) await plugins.smartdelay.delayFor(3000)
makeRequest().then((x: any) => { done.resolve(x) }) makeRequest().then((x: any) => { done.resolve(x) })
} else { } else {
done.resolve(res.body) done.resolve(res.body)
@ -220,27 +253,13 @@ export class AcmeCert {
/** /**
* accept a challenge - for private use only * accept a challenge - for private use only
*/ */
private acceptChallenge(challengeArg: ISmartAcmeChallenge) { acceptChallenge() {
let done = q.defer() let done = q.defer()
/**
* the key is needed to accept the challenge
*/
let authKey: string = plugins.rawacme.keyAuthz(
challengeArg.token,
this.parentAcmeAccount.parentSmartAcme.keyPair.publicKey
)
/**
* needed in case selected challenge is of type dns-01
*/
let keyHash: string = plugins.rawacme.dnsKeyAuthzHash(authKey) // needed if dns challenge is chosen
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.post( this.parentAcmeAccount.parentSmartAcme.rawacmeClient.post(
challengeArg.uri, this.chosenChallenge.uri,
{ {
resource: 'challenge', resource: 'challenge',
keyAuthorization: authKey keyAuthorization: this.chosenChallenge.keyAuthorization
}, },
this.parentAcmeAccount.parentSmartAcme.keyPair, this.parentAcmeAccount.parentSmartAcme.keyPair,
(err, res) => { (err, res) => {
@ -248,21 +267,7 @@ export class AcmeCert {
console.log(err) console.log(err)
done.reject(err) done.reject(err)
} }
/** done.resolve(res.body)
* the return challenge
*/
let returnDNSChallenge: ISmartAcmeChallengeAccepted = {
uri: res.body.uri,
type: res.body.type,
token: res.body.token,
keyAuthorization: res.body.keyAuthorization,
status: res.body.status,
dnsKeyHash: keyHash,
domainName: this.domainName,
domainNamePrefixed: helpers.prefixName(this.domainName)
}
this.acceptedChallenge = returnDNSChallenge
done.resolve(returnDNSChallenge)
} }
) )
return done.promise return done.promise

View File

@ -14,7 +14,7 @@ export interface IRsaKeypair {
} }
export { AcmeAccount } from './smartacme.classes.acmeaccount' export { AcmeAccount } from './smartacme.classes.acmeaccount'
export { AcmeCert, ISmartAcmeChallenge, ISmartAcmeChallengeAccepted } from './smartacme.classes.acmecert' export { AcmeCert, ISmartAcmeChallenge, ISmartAcmeChallengeChosen } from './smartacme.classes.acmecert'
/** /**
* class SmartAcme exports methods for maintaining SSL Certificates * class SmartAcme exports methods for maintaining SSL Certificates