fix som things

This commit is contained in:
Philipp Kunz 2017-01-15 12:21:29 +01:00
parent fce25c60ed
commit 4dadcf227c
8 changed files with 107 additions and 44 deletions

View File

@ -18,5 +18,5 @@ export declare class AcmeAccount {
* agree to letsencrypr terms of service
*/
agreeTos(): q.Promise<{}>;
createAcmeCert(domainNameArg: string): void;
createAcmeCert(domainNameArg: string, countryArg?: string, countryShortArg?: string, city?: string, companyArg?: string, companyShortArg?: string): q.Promise<{}>;
}

View File

@ -1,5 +1,6 @@
"use strict";
const q = require("q");
const smartacme_classes_acmecert_1 = require("./smartacme.classes.acmecert");
/**
* class AcmeAccount represents an AcmeAccount
*/
@ -47,8 +48,24 @@ class AcmeAccount {
});
return done.promise;
}
createAcmeCert(domainNameArg) {
createAcmeCert(domainNameArg, countryArg = 'Germany', countryShortArg = 'DE', city = 'Bremen', companyArg = 'Some Company', companyShortArg = 'SC') {
let done = q.defer();
let acmeCert = new smartacme_classes_acmecert_1.AcmeCert({
bit: 2064,
key: null,
domain: domainNameArg,
country: countryArg,
country_short: countryShortArg,
locality: city,
organization: companyArg,
organization_short: companyShortArg,
password: null,
unstructured: null,
subject_alt_names: null
}, this);
done.resolve(acmeCert);
return done.promise;
}
}
exports.AcmeAccount = AcmeAccount;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhY21lLmNsYXNzZXMuYWNtZWFjY291bnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGFjbWUuY2xhc3Nlcy5hY21lYWNjb3VudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsdUJBQXNCO0FBUXRCOztHQUVHO0FBQ0g7SUFLSSxZQUFZLGtCQUE2QjtRQUNyQyxJQUFJLENBQUMsZUFBZSxHQUFHLGtCQUFrQixDQUFBO0lBQzdDLENBQUM7SUFFRDs7T0FFRztJQUNILFFBQVE7UUFDSixJQUFJLElBQUksR0FBRyxDQUFDLEN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UFDckIsVUFBVSxHQUFHLFNBQVMsRUFDdEIsZUFBZSxHQUFHLElBQUksRUFDdEIsSUFBSSxHQUFHLFFBQVEsRUFDZixVQUFVLEdBQUcsY0FBYyxFQUMzQixlQUFlLEdBQUcsSUFBSTtRQUd0QixJQUFJLElBQUksR0FBRyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUE7UUFDcEIsSUFBSSxRQUFRLEdBQUcsSUFBSSxxQ0FBUSxDQUN2QjtZQUNJLEdBQUcsRUFBRSxJQUFJO1lBQ1QsR0FBRyxFQUFFLElBQUk7WUFDVCxNQUFNLEVBQUUsYUFBYTtZQUNyQixPQUFPLEVBQUUsVUFBVTtZQUNuQixhQUFhLEVBQUUsZUFBZTtZQUM5QixRQUFRLEVBQUUsSUFBSTtZQUNkLFlBQVksRUFBRSxVQUFVO1lBQ3hCLGtCQUFrQixFQUFFLGVBQWU7WUFDbkMsUUFBUSxFQUFFLElBQUk7WUFDZCxZQUFZLEVBQUUsSUFBSTtZQUNsQixpQkFBaUIsRUFBRSxJQUFJO1NBQzFCLEVBQ0QsSUFBSSxDQUNQLENBQUE7UUFDRCxJQUFJLENBQUMsT0FBTyxDQUFDLFFBQVEsQ0FBQyxDQUFBO1FBQ3RCLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7Q0FDSjtBQWxGRCxrQ0FrRkMifQ==

View File

@ -37,6 +37,7 @@ export interface IAcmeCsrConstructorOptions {
* class AcmeCert represents a cert for domain
*/
export declare class AcmeCert {
domainName: string;
attributes: any;
fullchain: string;
parentAcmeAccount: AcmeAccount;
@ -45,13 +46,13 @@ export declare class AcmeCert {
validTo: Date;
keypair: IRsaKeypair;
keyPairFinal: IRsaKeypair;
constructor(optionsArg: IAcmeCsrConstructorOptions, parentSmartAcmeArg: any);
constructor(optionsArg: IAcmeCsrConstructorOptions, parentAcmeAccount: AcmeAccount);
/**
* requests a challenge for a domain
* @param domainNameArg - the domain name to request a challenge for
* @param challengeType - the challenge type to request
*/
requestChallenge(domainNameArg: string, challengeTypeArg?: TChallengeType): q.Promise<ISmartAcmeChallengeAccepted>;
requestChallenge(challengeTypeArg?: TChallengeType): q.Promise<ISmartAcmeChallengeAccepted>;
/**
* validates a challenge, only call after you have set the challenge at the expected location
*/

File diff suppressed because one or more lines are too long

View File

@ -6,6 +6,7 @@ const smartacme = require("../dist/index");
describe('smartacme', function () {
let testSmartAcme;
let testAcmeAccount;
let testAcmeCert;
let testChallenge;
it('should create a valid instance', function (done) {
this.timeout(10000);
@ -21,15 +22,22 @@ describe('smartacme', function () {
it('should register a new account', function (done) {
this.timeout(10000);
testSmartAcme.createAccount().then(x => {
testAcmeAccount = x;
done();
}).catch(err => {
console.log(err);
done(err);
});
});
it.skip('should request a cert for a domain', function (done) {
it('should create a AcmeCert', function () {
testAcmeAccount.createAcmeCert('bleu.de').then(x => {
testAcmeCert = x;
should(testAcmeAccount).be.instanceOf(smartacme.AcmeCert);
});
});
it('should get a challenge for a AcmeCert', function (done) {
this.timeout(10000);
testAcmeAccount.requestChallenge('bleu.de').then((challengeAccepted) => {
testAcmeCert.requestChallenge().then((challengeAccepted) => {
console.log(challengeAccepted);
testChallenge = challengeAccepted;
done();
@ -42,4 +50,4 @@ describe('smartacme', function () {
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFHaEMsNEJBQTRCO0FBQzVCLDJDQUEwQztBQUUxQyxRQUFRLENBQUMsV0FBVyxFQUFFO0lBQ2xCLElBQUksYUFBa0MsQ0FBQTtJQUN0QyxJQUFJLGVBQXNDLENBQUE7SUFDMUMsSUFBSSxhQUFvRCxDQUFBO0lBQ3hELEVBQUUsQ0FBQyxnQ0FBZ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@ import * as smartacme from '../dist/index'
describe('smartacme', function () {
let testSmartAcme: smartacme.SmartAcme
let testAcmeAccount: smartacme.AcmeAccount
let testAcmeCert: smartacme.AcmeCert
let testChallenge: smartacme.ISmartAcmeChallengeAccepted
it('should create a valid instance', function (done) {
this.timeout(10000)
@ -25,6 +26,7 @@ describe('smartacme', function () {
it('should register a new account', function (done) {
this.timeout(10000)
testSmartAcme.createAccount().then(x => {
testAcmeAccount = x
done()
}).catch(err => {
console.log(err)
@ -32,9 +34,16 @@ describe('smartacme', function () {
})
})
it.skip('should request a cert for a domain', function (done) {
it('should create a AcmeCert', function() {
testAcmeAccount.createAcmeCert('bleu.de').then(x => {
testAcmeCert = x
should(testAcmeAccount).be.instanceOf(smartacme.AcmeCert)
})
})
it('should get a challenge for a AcmeCert', function (done) {
this.timeout(10000)
testAcmeAccount.requestChallenge('bleu.de').then((challengeAccepted) => {
testAcmeCert.requestChallenge().then((challengeAccepted) => {
console.log(challengeAccepted)
testChallenge = challengeAccepted
done()

View File

@ -62,7 +62,33 @@ export class AcmeAccount {
return done.promise
}
createAcmeCert(domainNameArg: string) {
createAcmeCert(
domainNameArg: string,
countryArg = 'Germany',
countryShortArg = 'DE',
city = 'Bremen',
companyArg = 'Some Company',
companyShortArg = 'SC'
) {
let done = q.defer()
let acmeCert = new AcmeCert(
{
bit: 2064,
key: null, // not needed right now
domain: domainNameArg,
country: countryArg,
country_short: countryShortArg,
locality: city,
organization: companyArg,
organization_short: companyShortArg,
password: null,
unstructured: null,
subject_alt_names: null
},
this
)
done.resolve(acmeCert)
return done.promise
}
}

View File

@ -46,6 +46,7 @@ export interface IAcmeCsrConstructorOptions {
* class AcmeCert represents a cert for domain
*/
export class AcmeCert {
domainName: string
attributes
fullchain: string
parentAcmeAccount: AcmeAccount
@ -54,8 +55,9 @@ export class AcmeCert {
validTo: Date
keypair: IRsaKeypair
keyPairFinal: IRsaKeypair
constructor(optionsArg: IAcmeCsrConstructorOptions, parentSmartAcmeArg) {
this.parentAcmeAccount = parentSmartAcmeArg
constructor(optionsArg: IAcmeCsrConstructorOptions, parentAcmeAccount: AcmeAccount) {
this.domainName = optionsArg.domain
this.parentAcmeAccount = parentAcmeAccount
this.keypair = helpers.createKeypair(optionsArg.bit)
let privateKeyForged = plugins.nodeForge.pki.privateKeyFromPem(this.keypair.privateKey)
let publicKeyForged = plugins.nodeForge.pki.publicKeyToPem(
@ -94,13 +96,13 @@ export class AcmeCert {
* @param domainNameArg - the domain name to request a challenge for
* @param challengeType - the challenge type to request
*/
requestChallenge(domainNameArg: string, challengeTypeArg: TChallengeType = 'dns-01') {
requestChallenge(challengeTypeArg: TChallengeType = 'dns-01') {
let done = q.defer<ISmartAcmeChallengeAccepted>()
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.newAuthz(
{
identifier: {
type: 'dns',
value: domainNameArg
value: this.domainName
}
},
this.parentAcmeAccount.parentSmartAcme.keyPair,
@ -194,18 +196,6 @@ export class AcmeCert {
*/
let keyHash: string = plugins.rawacme.dnsKeyAuthzHash(authKey) // needed if dns challenge is chosen
/**
* the return challenge
*/
let returnDNSChallenge: ISmartAcmeChallengeAccepted = {
uri: challenge.uri,
type: challenge.type,
token: challenge.token,
keyAuthorization: challenge.keyAuthorization,
keyHash: keyHash,
status: challenge.status
}
this.parentAcmeAccount.parentSmartAcme.rawacmeClient.post(
challenge.uri,
{
@ -218,6 +208,17 @@ export class AcmeCert {
console.log(err)
done.reject(err)
}
/**
* the return challenge
*/
let returnDNSChallenge: ISmartAcmeChallengeAccepted = {
uri: res.body.uri,
type: res.body.type,
token: res.body.token,
keyAuthorization: res.body.keyAuthorization,
keyHash: keyHash,
status: res.body.status
}
done.resolve(returnDNSChallenge)
}
)