update tests

This commit is contained in:
AJ ONeal 2019-10-08 15:50:17 -06:00
parent cd35f26e95
commit 5623ed1914
1 changed files with 34 additions and 5 deletions

View File

@ -2,6 +2,9 @@
require('dotenv').config(); require('dotenv').config();
var CSR = require('@root/csr');
var Enc = require('@root/encoding/base64');
var PEM = require('../pem.js');
var punycode = require('punycode'); var punycode = require('punycode');
var ACME = require('../acme.js'); var ACME = require('../acme.js');
var Keypairs = require('../keypairs.js'); var Keypairs = require('../keypairs.js');
@ -113,14 +116,23 @@ async function happyPath(accKty, srvKty, rnd) {
throw new Error('Failed to ask the user to agree to terms'); throw new Error('Failed to ask the user to agree to terms');
} }
var serverKeypair = await Keypairs.generate({ kty: srvKty }); var certKeypair = await Keypairs.generate({ kty: srvKty });
var pem = await Keypairs.export({
jwk: certKeypair.private,
encoding: 'pem'
});
if (config.debug) { if (config.debug) {
console.info('Server Key Created'); console.info('Server Key Created');
console.info(JSON.stringify(serverKeypair, null, 2)); console.info('privkey.jwk.json');
console.info(JSON.stringify(certKeypair, null, 2));
// This should be saved as `privkey.pem`
console.info(); console.info();
console.info('privkey.' + srvKty.toLowerCase() + '.pem:');
console.info(pem);
console.info(); console.info();
} }
// 'subject' should be first in list
var domains = randomDomains(rnd); var domains = randomDomains(rnd);
if (config.debug) { if (config.debug) {
console.info('Get certificates for random domains:'); console.info('Get certificates for random domains:');
@ -137,14 +149,31 @@ async function happyPath(accKty, srvKty, rnd) {
); );
console.info(); console.info();
} }
// Create CSR
var csrDer = await CSR.csr({
jwk: certKeypair.private,
domains: domains,
encoding: 'der'
});
var csr = Enc.bufToUrlBase64(csrDer);
var csrPem = PEM.packBlock({
type: 'CERTIFICATE REQUEST',
bytes: csrDer /* { jwk: jwk, domains: opts.domains } */
});
if (config.debug) {
console.info('Certificate Signing Request');
console.info(csrPem);
console.info();
}
var results = await acme.certificates.create({ var results = await acme.certificates.create({
account: account, account: account,
accountKeypair: { privateKeyJwk: accountKeypair.private }, accountKeypair: { privateKeyJwk: accountKeypair.private },
serverKeypair: { privateKeyJwk: serverKeypair.private }, csr: csr,
domains: domains, domains: domains,
challenges: challenges, // must be implemented challenges: challenges, // must be implemented
customerEmail: null, customerEmail: null
skipDryRun: true
}); });
if (config.debug) { if (config.debug) {