From b965141dd2c2fd56fc019bda0b45fb34b93d3c05 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 16 Dec 2015 10:07:00 +0000 Subject: [PATCH] readying for launch --- examples/commandline-minimal.js | 4 ++-- examples/commandline.js | 2 -- examples/config-minimal.js | 3 --- index.js | 5 +++-- lib/default-handlers.js | 2 +- lib/letiny-core.js | 36 +++++++++++++-------------------- package.json | 4 ++-- 7 files changed, 22 insertions(+), 34 deletions(-) diff --git a/examples/commandline-minimal.js b/examples/commandline-minimal.js index 5b63799..61d3cb8 100644 --- a/examples/commandline-minimal.js +++ b/examples/commandline-minimal.js @@ -14,8 +14,8 @@ config.le.server = LE.stagingServer; var le = LE.create(config.le); le.register({ agreeTos: true -, domains: ['example.com'] // CHANGE TO YOUR DOMAIN -, email: 'user@example.com' // CHANGE TO YOUR EMAIL +, domains: [process.argv[3] || 'example.com'] // CHANGE TO YOUR DOMAIN +, email: process.argv[2] || 'user@example.com' // CHANGE TO YOUR EMAIL }, function (err) { if (err) { console.error('[Error]: node-letsencrypt/examples/standalone'); diff --git a/examples/commandline.js b/examples/commandline.js index fe4ce8c..47604d0 100644 --- a/examples/commandline.js +++ b/examples/commandline.js @@ -28,8 +28,6 @@ var bkDefaults = { // backend-specific , logsDir: path.join(__dirname, '..', 'tests', 'letsencrypt.logs') , workDir: path.join(__dirname, '..', 'tests', 'letsencrypt.work') -, text: true -, pythonClientPath: require('os').homedir() + '/.local/share/letsencrypt/bin/letsencrypt' }; var le = LE.create(bkDefaults, { diff --git a/examples/config-minimal.js b/examples/config-minimal.js index bc4b26b..454119f 100644 --- a/examples/config-minimal.js +++ b/examples/config-minimal.js @@ -2,8 +2,6 @@ var path = require('path'); -var binpath = require('homedir') + '/.local/share/letsencrypt/bin/letsencrypt'; - var config = { plainPort: 80 @@ -21,7 +19,6 @@ var config = { // these are specific to the python client and won't be needed with the purejs library , logsDir: path.join(__dirname, '..', 'tests', 'letsencrypt.logs') , workDir: path.join(__dirname, '..', 'tests', 'letsencrypt.work') - , pythonClientPath: binpath } }; diff --git a/index.js b/index.js index 91e9284..3d23ae8 100644 --- a/index.js +++ b/index.js @@ -5,13 +5,14 @@ var PromiseA = require('bluebird'); var crypto = require('crypto'); var tls = require('tls'); -var path = require('path'); var leCore = require('./lib/letiny-core'); var LE = module.exports; LE.productionServerUrl = leCore.productionServerUrl; LE.stagingServer = leCore.stagingServerUrl; LE.configDir = leCore.configDir; +LE.logsDir = leCore.logsDir; +LE.workDir = leCore.workDir; LE.acmeChallengPrefix = leCore.acmeChallengPrefix; LE.knownEndpoints = leCore.knownEndpoints; @@ -204,7 +205,7 @@ LE.create = function (defaults, handlers, backend) { cb(null, true); } , middleware: function () { - var prefix = '/.well-known/acme-challenge/'; + var prefix = leCore.acmeChallengePrefix; return function (req, res, next) { if (0 !== req.url.indexOf(prefix)) { diff --git a/lib/default-handlers.js b/lib/default-handlers.js index a4bcacc..dfcd225 100644 --- a/lib/default-handlers.js +++ b/lib/default-handlers.js @@ -36,5 +36,5 @@ module.exports.getChallenge = function (args, key, done) { module.exports.removeChallenge = function (args, key, done) { //var hostname = args.domains[0]; - fs.unlinkSync(path.join(args.webrootPath, key), done); + fs.unlink(path.join(args.webrootPath, key), done); }; diff --git a/lib/letiny-core.js b/lib/letiny-core.js index 7930a5c..bc1b790 100644 --- a/lib/letiny-core.js +++ b/lib/letiny-core.js @@ -1,8 +1,10 @@ 'use strict'; var PromiseA = require('bluebird'); +var mkdirpAsync = PromiseA.promisify(require('mkdirp')); var path = require('path'); var fs = PromiseA.promisifyAll(require('fs')); +var sfs = require('safe-replace'); var LE = require('../'); var LeCore = PromiseA.promisifyAll(require('letiny-core')); @@ -22,19 +24,13 @@ function getAcmeUrls(args) { return LeCore.getAcmeUrlsAsync(args.server).then(function (data) { ipc.acmeUrlsUpdatedAt = Date.now(); - ipc.acmeUrls = { - newAuthz: data['new-authz'] - , newCert: data['new-cert'] - , newReg: data['new-reg'] - , revokeCert: data['revoke-cert'] - }; + ipc.acmeUrls = data; return ipc.acmeUrls; }); } function createAccount(args, handlers) { - var mkdirpAsync = PromiseA.promisify(require('mkdirp')); var os = require("os"); var localname = os.hostname(); @@ -45,14 +41,15 @@ function createAccount(args, handlers) { return LeCore.registerNewAccountAsync({ email: args.email - , newReg: args._acmeUrls.newReg - , debug: args.debug || handlers.debug + , newRegUrl: args._acmeUrls.newReg , agreeToTerms: function (tosUrl, agree) { // args.email = email; // already there args.tosUrl = tosUrl; handlers.agreeToTerms(args, agree); } , accountPrivateKeyPem: pems.privateKeyPem + + , debug: args.debug || handlers.debug }).then(function (body) { var accountDir = path.join(args.accountsDir, pems.publicKeyMd5); @@ -144,21 +141,14 @@ function getCertificateAsync(account, args, defaults, handlers) { var pyconf = PromiseA.promisifyAll(require('pyconf')); return leCrypto.generateRsaKeypairAsync(args.rsaBitLength, args.rsaExponent).then(function (domain) { - return lef.getCertificateAsyncAsync({ - newAuthorizationUrl: args._acmeUrls.newAuthz - , newCertificateUrl: args._acmeUrls.newCert + return LeCore.getCertificateAsync({ + newAuthzUrl: args._acmeUrls.newAuthz + , newCertUrl: args._acmeUrls.newCert , accountPrivateKeyPem: account.privateKeyPem , domainPrivateKeyPem: domain.privateKeyPem , domains: args.domains - /* - , getChallenge: function (domain, key, done) { - args.domains = [domain]; - args.webrootPath = args.webrootPath || defaults.webrootPath; - handlers.getChallenge(args, key, done); - } - */ , setChallenge: function (domain, key, value, done) { args.domains = [domain]; args.webrootPath = args.webrootPath || defaults.webrootPath; @@ -181,7 +171,7 @@ function getCertificateAsync(account, args, defaults, handlers) { // TODO write to archive first, then write to live return mkdirpAsync(liveDir).then(function () { - return PromisA.all([ + return PromiseA.all([ sfs.writeFileAsync(certPath, result.cert, 'ascii') , sfs.writeFileAsync(chainPath, result.chain, 'ascii') , sfs.writeFileAsync(fullchainPath, result.fullchain, 'ascii') @@ -198,11 +188,13 @@ function getCertificateAsync(account, args, defaults, handlers) { function registerWithAcme(args, defaults, handlers) { var pyconf = PromiseA.promisifyAll(require('pyconf')); - var server = args.server || defaults.server || LE.liveServer; // https://acme-v01.api.letsencrypt.org/directory + var server = args.server || defaults.server || LeCore.stagingServerUrl; // https://acme-v01.api.letsencrypt.org/directory var acmeHostname = require('url').parse(server).hostname; var configDir = args.configDir || defaults.configDir || LE.configDir; args.server = server; + console.log('args.server'); + console.log(server); args.renewalDir = args.renewalDir || path.join(configDir, 'renewal', args.domains[0] + '.conf'); args.accountsDir = args.accountsDir || path.join(configDir, 'accounts', acmeHostname, 'directory'); @@ -212,7 +204,7 @@ function registerWithAcme(args, defaults, handlers) { return accountId; }, function (err) { - if ("EENOENT" === err.code) { + if ("ENOENT" === err.code) { return getAccountByEmail(args, handlers); } diff --git a/package.json b/package.json index 2ef3f64..23dcce6 100644 --- a/package.json +++ b/package.json @@ -37,14 +37,14 @@ "ursa": "^0.9.1" }, "dependencies": { - "node-forge": "^0.6.38", "bluebird": "^3.0.6", "homedir": "^0.6.0", "letiny-core": "^1.0.1", "mkdirp": "^0.5.1", + "node-forge": "^0.6.38", "pyconf": "^1.0.0", "request": "^2.67.0", - "safe-replace": "^1.0.0", + "safe-replace": "^1.0.2", "serve-static": "^1.10.0" } }