réplica de https://github.com/therootcompany/acme.js
AJ ONeal
hace 6 años
Se han modificado 7 ficheros con 765 adiciones y 459 borrados
@ -0,0 +1,53 @@ |
|||
'use strict'; |
|||
|
|||
var ACME2 = require('./').ACME; |
|||
|
|||
function resolveFn(cb) { |
|||
return function (val) { |
|||
// nextTick to get out of Promise chain
|
|||
process.nextTick(function () { cb(null, val); }); |
|||
}; |
|||
} |
|||
function rejectFn(cb) { |
|||
return function (err) { |
|||
console.log('reject something or other:'); |
|||
console.log(err.stack); |
|||
// nextTick to get out of Promise chain
|
|||
process.nextTick(function () { cb(err); }); |
|||
}; |
|||
} |
|||
|
|||
function create(deps) { |
|||
deps.LeCore = {}; |
|||
var acme2 = ACME2.create(deps); |
|||
acme2.registerNewAccount = function (options, cb) { |
|||
acme2.accounts.create(options).then(resolveFn(cb), rejectFn(cb)); |
|||
}; |
|||
acme2.getCertificate = function (options, cb) { |
|||
acme2.certificates.create(options).then(resolveFn(cb), rejectFn(cb)); |
|||
}; |
|||
acme2.getAcmeUrls = function (options, cb) { |
|||
acme2.init(options).then(resolveFn(cb), rejectFn(cb)); |
|||
}; |
|||
acme2.stagingServerUrl = module.exports.defaults.stagingServerUrl; |
|||
acme2.productionServerUrl = module.exports.defaults.productionServerUrl; |
|||
return acme2; |
|||
} |
|||
|
|||
module.exports.ACME = { }; |
|||
module.exports.defaults = { |
|||
productionServerUrl: 'https://acme-v02.api.letsencrypt.org/directory' |
|||
, stagingServerUrl: 'https://acme-staging-v02.api.letsencrypt.org/directory' |
|||
, knownEndpoints: [ 'keyChange', 'meta', 'newAccount', 'newNonce', 'newOrder', 'revokeCert' ] |
|||
, challengeTypes: [ 'http-01', 'dns-01' ] |
|||
, challengeType: 'http-01' |
|||
, keyType: 'rsa' // ecdsa
|
|||
, keySize: 2048 // 256
|
|||
}; |
|||
Object.keys(module.exports.defaults).forEach(function (key) { |
|||
module.exports.ACME[key] = module.exports.defaults[key]; |
|||
}); |
|||
Object.keys(ACME2).forEach(function (key) { |
|||
module.exports.ACME[key] = ACME2[key]; |
|||
module.exports.ACME.create = create; |
|||
}); |
@ -0,0 +1,75 @@ |
|||
'use strict'; |
|||
|
|||
module.exports.run = function run(web, chType, email) { |
|||
var RSA = require('rsa-compat').RSA; |
|||
var directoryUrl = 'https://acme-staging-v02.api.letsencrypt.org/directory'; |
|||
var acme2 = require('./compat').ACME.create({ RSA: RSA }); |
|||
// [ 'test.ppl.family' ] 'coolaj86@gmail.com''http-01'
|
|||
console.log(web, chType, email); |
|||
return; |
|||
acme2.init(directoryUrl).then(function (body) { |
|||
console.log(body); |
|||
return; |
|||
|
|||
var options = { |
|||
agreeToTerms: function (tosUrl, agree) { |
|||
agree(null, tosUrl); |
|||
} |
|||
, setChallenge: function (opts, cb) { |
|||
|
|||
console.log(""); |
|||
console.log('identifier:'); |
|||
console.log(opts.identifier); |
|||
console.log('hostname:'); |
|||
console.log(opts.hostname); |
|||
console.log('type:'); |
|||
console.log(opts.type); |
|||
console.log('token:'); |
|||
console.log(opts.token); |
|||
console.log('thumbprint:'); |
|||
console.log(opts.thumbprint); |
|||
console.log('keyAuthorization:'); |
|||
console.log(opts.keyAuthorization); |
|||
console.log('dnsAuthorization:'); |
|||
console.log(opts.dnsAuthorization); |
|||
console.log(""); |
|||
|
|||
console.log("Put the string '" + opts.keyAuthorization + "' into a file at '" + opts.hostname + "/" + opts.token + "'"); |
|||
console.log("\nThen hit the 'any' key to continue (must be specifically the 'any' key)..."); |
|||
|
|||
function onAny() { |
|||
process.stdin.pause(); |
|||
process.stdin.removeEventListener('data', onAny); |
|||
process.stdin.setRawMode(false); |
|||
cb(); |
|||
} |
|||
process.stdin.setRawMode(true); |
|||
process.stdin.resume(); |
|||
process.stdin.on('data', onAny); |
|||
} |
|||
, removeChallenge: function (opts, cb) { |
|||
// hostname, key
|
|||
console.log('[DEBUG] remove challenge', hostname, key); |
|||
setTimeout(cb, 1 * 1000); |
|||
} |
|||
, challengeType: chType |
|||
, email: email |
|||
, accountKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/account.privkey.pem') }) |
|||
, domainKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/privkey.pem') }) |
|||
, domains: web |
|||
}; |
|||
|
|||
acme2.registerNewAccount(options).then(function (account) { |
|||
console.log('account:'); |
|||
console.log(account); |
|||
|
|||
acme2.getCertificate(options, function (fullchainPem) { |
|||
console.log('[acme-v2] A fullchain.pem:'); |
|||
console.log(fullchainPem); |
|||
}).then(function (fullchainPem) { |
|||
console.log('[acme-v2] B fullchain.pem:'); |
|||
console.log(fullchainPem); |
|||
}); |
|||
}); |
|||
}); |
|||
}; |
@ -0,0 +1,57 @@ |
|||
'use strict'; |
|||
|
|||
var RSA = require('rsa-compat').RSA; |
|||
|
|||
module.exports.run = function (web, chType, email) { |
|||
console.log('[DEBUG] run', web, chType, email); |
|||
|
|||
var acme2 = require('./compat.js').ACME.create({ RSA: RSA }); |
|||
acme2.getAcmeUrls(acme2.stagingServerUrl, function (err, body) { |
|||
if (err) { console.log('err 1'); throw err; } |
|||
console.log(body); |
|||
|
|||
var options = { |
|||
agreeToTerms: function (tosUrl, agree) { |
|||
agree(null, tosUrl); |
|||
} |
|||
, setChallenge: function (hostname, token, val, cb) { |
|||
console.log("Put the string '" + val + "' into a file at '" + hostname + "/" + acme2.acmeChallengePrefix + "/" + token + "'"); |
|||
console.log("echo '" + val + "' > '" + hostname + "/" + acme2.acmeChallengePrefix + "/" + token + "'"); |
|||
console.log("\nThen hit the 'any' key to continue (must be specifically the 'any' key)..."); |
|||
|
|||
function onAny() { |
|||
console.log("'any' key was hit"); |
|||
process.stdin.pause(); |
|||
process.stdin.removeListener('data', onAny); |
|||
process.stdin.setRawMode(false); |
|||
cb(); |
|||
} |
|||
|
|||
process.stdin.setRawMode(true); |
|||
process.stdin.resume(); |
|||
process.stdin.on('data', onAny); |
|||
} |
|||
, removeChallenge: function (hostname, key, cb) { |
|||
console.log('[DEBUG] remove challenge', hostname, key); |
|||
setTimeout(cb, 1 * 1000); |
|||
} |
|||
, challengeType: chType |
|||
, email: email |
|||
, accountKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/account.privkey.pem') }) |
|||
, domainKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/privkey.pem') }) |
|||
, domains: web |
|||
}; |
|||
|
|||
acme2.registerNewAccount(options, function (err, account) { |
|||
if (err) { console.log('err 2'); throw err; } |
|||
console.log('account:'); |
|||
console.log(account); |
|||
|
|||
acme2.getCertificate(options, function (err, fullchainPem) { |
|||
if (err) { console.log('err 3'); throw err; } |
|||
console.log('[acme-v2] A fullchain.pem:'); |
|||
console.log(fullchainPem); |
|||
}); |
|||
}); |
|||
}); |
|||
}; |
@ -1,56 +1,45 @@ |
|||
'use strict'; |
|||
|
|||
var RSA = require('rsa-compat').RSA; |
|||
var acme2 = require('./').ACME.create({ RSA: RSA }); |
|||
var readline = require('readline'); |
|||
var rl = readline.createInterface({ |
|||
input: process.stdin, |
|||
output: process.stdout |
|||
}); |
|||
|
|||
acme2.getAcmeUrls(acme2.stagingServerUrl).then(function (body) { |
|||
console.log(body); |
|||
function getWeb() { |
|||
rl.question('What web address(es) would you like to get certificates for? (ex: example.com,*.example.com) ', function (web) { |
|||
web = (web||'').trim().split(/,/g); |
|||
if (!web[0]) { getWeb(); return; } |
|||
|
|||
var options = { |
|||
agreeToTerms: function (tosUrl, agree) { |
|||
agree(null, tosUrl); |
|||
} |
|||
/* |
|||
, setupChallenge: function (opts) { |
|||
console.log('type:'); |
|||
console.log(ch.type); |
|||
console.log('ch.token:'); |
|||
console.log(ch.token); |
|||
console.log('thumbprint:'); |
|||
console.log(thumbprint); |
|||
console.log('keyAuthorization:'); |
|||
console.log(keyAuthorization); |
|||
console.log('dnsAuthorization:'); |
|||
console.log(dnsAuthorization); |
|||
} |
|||
*/ |
|||
// teardownChallenge
|
|||
, setChallenge: function (hostname, key, val, cb) { |
|||
console.log('[DEBUG] set challenge', hostname, key, val); |
|||
console.log("You have 20 seconds to put the string '" + val + "' into a file at '" + hostname + "/" + key + "'"); |
|||
setTimeout(cb, 20 * 1000); |
|||
if (web.some(function (w) { return '*' === w[0]; })) { |
|||
console.log('Wildcard domains must use dns-01'); |
|||
getEmail(web, 'dns-01'); |
|||
} else { |
|||
getChallengeType(web); |
|||
} |
|||
, removeChallenge: function (hostname, key, cb) { |
|||
console.log('[DEBUG] remove challenge', hostname, key); |
|||
setTimeout(cb, 1 * 1000); |
|||
} |
|||
, challengeType: 'http-01' |
|||
, email: 'coolaj86@gmail.com' |
|||
, accountKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/account.privkey.pem') }) |
|||
, domainKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/privkey.pem') }) |
|||
, domains: [ 'test.ppl.family' ] |
|||
}; |
|||
|
|||
acme2.registerNewAccount(options).then(function (account) { |
|||
console.log('account:'); |
|||
console.log(account); |
|||
|
|||
acme2.getCertificate(options, function (fullchainPem) { |
|||
console.log('[acme-v2] A fullchain.pem:'); |
|||
console.log(fullchainPem); |
|||
}).then(function (fullchainPem) { |
|||
console.log('[acme-v2] B fullchain.pem:'); |
|||
console.log(fullchainPem); |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
function getChallengeType(web) { |
|||
rl.question('What challenge will you be testing today? http-01 or dns-01? [http-01] ', function (chType) { |
|||
chType = (chType||'').trim(); |
|||
if (!chType) { chType = 'http-01'; } |
|||
|
|||
getEmail(web, chType); |
|||
}); |
|||
} |
|||
|
|||
function getEmail(web, chType) { |
|||
rl.question('What email should we use? (optional) ', function (email) { |
|||
email = (email||'').trim(); |
|||
if (!email) { email = null; } |
|||
|
|||
rl.close(); |
|||
console.log("[DEBUG] rl blah blah"); |
|||
require('./test.compat.js').run(web, chType, email); |
|||
//require('./test.cb.js').run(web, chType, email);
|
|||
//require('./test.promise.js').run(web, chType, email);
|
|||
}); |
|||
} |
|||
|
|||
getWeb(); |
|||
|
@ -0,0 +1,84 @@ |
|||
'use strict'; |
|||
|
|||
/* global Promise */ |
|||
|
|||
module.exports.run = function run(web, chType, email) { |
|||
var RSA = require('rsa-compat').RSA; |
|||
var directoryUrl = 'https://acme-staging-v02.api.letsencrypt.org/directory'; |
|||
var acme2 = require('./compat').ACME.create({ RSA: RSA }); |
|||
// [ 'test.ppl.family' ] 'coolaj86@gmail.com''http-01'
|
|||
console.log(web, chType, email); |
|||
return; |
|||
acme2.init(directoryUrl).then(function (body) { |
|||
console.log(body); |
|||
return; |
|||
|
|||
var options = { |
|||
agreeToTerms: function (tosUrl, agree) { |
|||
agree(null, tosUrl); |
|||
} |
|||
, setChallenge: function (opts) { |
|||
|
|||
console.log(""); |
|||
console.log('identifier:'); |
|||
console.log(opts.identifier); |
|||
console.log('hostname:'); |
|||
console.log(opts.hostname); |
|||
console.log('type:'); |
|||
console.log(opts.type); |
|||
console.log('token:'); |
|||
console.log(opts.token); |
|||
console.log('thumbprint:'); |
|||
console.log(opts.thumbprint); |
|||
console.log('keyAuthorization:'); |
|||
console.log(opts.keyAuthorization); |
|||
console.log('dnsAuthorization:'); |
|||
console.log(opts.dnsAuthorization); |
|||
console.log(""); |
|||
|
|||
console.log("Put the string '" + opts.keyAuthorization + "' into a file at '" + opts.hostname + "/" + opts.token + "'"); |
|||
console.log("\nThen hit the 'any' key to continue (must be specifically the 'any' key)..."); |
|||
|
|||
return new Promise(function (resolve) { |
|||
function onAny() { |
|||
process.stdin.pause(); |
|||
process.stdin.removeEventListener('data', onAny); |
|||
process.stdin.setRawMode(false); |
|||
|
|||
resolve(); |
|||
} |
|||
process.stdin.setRawMode(true); |
|||
process.stdin.resume(); |
|||
process.stdin.on('data', onAny); |
|||
}); |
|||
} |
|||
, removeChallenge: function (opts) { |
|||
// hostname, key
|
|||
console.log('[DEBUG] remove challenge', opts.hostname, opts.keyAuthorization); |
|||
console.log("Remove the file '" + opts.hostname + "/" + opts.token + "'"); |
|||
|
|||
return new Promise(function (resolve) { |
|||
setTimeout(resolve, 1 * 1000); |
|||
}); |
|||
} |
|||
, challengeType: chType |
|||
, email: email |
|||
, accountKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/account.privkey.pem') }) |
|||
, domainKeypair: RSA.import({ privateKeyPem: require('fs').readFileSync(__dirname + '/privkey.pem') }) |
|||
, domains: web |
|||
}; |
|||
|
|||
acme2.registerNewAccount(options).then(function (account) { |
|||
console.log('account:'); |
|||
console.log(account); |
|||
|
|||
acme2.getCertificate(options, function (fullchainPem) { |
|||
console.log('[acme-v2] A fullchain.pem:'); |
|||
console.log(fullchainPem); |
|||
}).then(function (fullchainPem) { |
|||
console.log('[acme-v2] B fullchain.pem:'); |
|||
console.log(fullchainPem); |
|||
}); |
|||
}); |
|||
}); |
|||
}; |
Cargando…
Referencia en una nueva incidencia