letiny-core -> le-acme-core

This commit is contained in:
AJ ONeal 2016-08-08 11:58:08 -06:00
parent 4e5d373055
commit c1513fe120
3 changed files with 76 additions and 67 deletions

View File

@ -1,4 +1,6 @@
# letiny-core # le-acme-core
<!-- rename to le-acme-core -->
A framework for building letsencrypt clients, forked from `letiny`. A framework for building letsencrypt clients, forked from `letiny`.
@ -21,7 +23,31 @@ You probably want one of these pre-built clients instead:
## Install & Usage: ## Install & Usage:
```bash ```bash
npm install --save letiny-core npm install --save le-acme-core
```
To use the default dependencies:
```javascript
'use strict';
var ACME = require('le-acme-core').ACME.create();
```
For **testing** and **development**, you can also inject the dependencies you want to use:
```javascript
'use strict';
var ACME = require('le-acme-core').ACME.create({
request: require('request')
, RSA: require('rsa-compat').RSA
});
// now uses node `request` (could also use jQuery or Angular in the browser)
ACME.getAcmeUrls(discoveryUrl, function (err, urls) {
console.log(urls);
});
``` ```
You will follow these steps to obtain certificates: You will follow these steps to obtain certificates:
@ -49,12 +75,12 @@ Note: use **YOUR EMAIL** and accept the terms of service (run `ddns --help` to s
<!-- TODO tutorial on ddns --> <!-- TODO tutorial on ddns -->
Install letiny-core and its dependencies. **Note**: it's okay if you're on windows Install le-acme-core and its dependencies. **Note**: it's okay if you're on windows
and `ursa` fails to compile. It'll still work. and `ursa` fails to compile. It'll still work.
```bash ```bash
git clone https://github.com/Daplie/letiny-core.git ~/letiny-core git clone https://github.com/Daplie/le-acme-core.git ~/le-acme-core
pushd ~/letiny-core pushd ~/le-acme-core
npm install npm install
``` ```
@ -73,7 +99,7 @@ The Goodies
```javascript ```javascript
// Accounts // Accounts
LeCore.registerNewAccount(options, cb) // returns "regr" registration data ACME.registerNewAccount(options, cb) // returns "regr" registration data
{ newRegUrl: '<url>' // no defaults, specify acmeUrls.newAuthz { newRegUrl: '<url>' // no defaults, specify acmeUrls.newAuthz
, email: '<email>' // valid email (server checks MX records) , email: '<email>' // valid email (server checks MX records)
@ -84,7 +110,7 @@ LeCore.registerNewAccount(options, cb) // returns "regr" registration dat
} }
// Registration // Registration
LeCore.getCertificate(options, cb) // returns (err, pems={ privkey (key), cert, chain (ca) }) ACME.getCertificate(options, cb) // returns (err, pems={ privkey (key), cert, chain (ca) })
{ newAuthzUrl: '<url>' // specify acmeUrls.newAuthz { newAuthzUrl: '<url>' // specify acmeUrls.newAuthz
, newCertUrl: '<url>' // specify acmeUrls.newCert , newCertUrl: '<url>' // specify acmeUrls.newCert
@ -102,49 +128,32 @@ LeCore.getCertificate(options, cb) // returns (err, pems={ privkey (k
} }
// Discovery URLs // Discovery URLs
LeCore.getAcmeUrls(acmeDiscoveryUrl, cb) // returns (err, acmeUrls={newReg,newAuthz,newCert,revokeCert}) ACME.getAcmeUrls(acmeDiscoveryUrl, cb) // returns (err, acmeUrls={newReg,newAuthz,newCert,revokeCert})
``` ```
Helpers & Stuff Helpers & Stuff
```javascript ```javascript
// Constants // Constants
LeCore.productionServerUrl // https://acme-v01.api.letsencrypt.org/directory ACME.productionServerUrl // https://acme-v01.api.letsencrypt.org/directory
LeCore.stagingServerUrl // https://acme-staging.api.letsencrypt.org/directory ACME.stagingServerUrl // https://acme-staging.api.letsencrypt.org/directory
LeCore.acmeChallengePrefix // /.well-known/acme-challenge/ ACME.acmeChallengePrefix // /.well-known/acme-challenge/
LeCore.configDir // /etc/letsencrypt/ ACME.knownEndpoints // new-authz, new-cert, new-reg, revoke-cert
LeCore.logsDir // /var/log/letsencrypt/
LeCore.workDir // /var/lib/letsencrypt/
LeCore.knownEndpoints // new-authz, new-cert, new-reg, revoke-cert
// HTTP Client Helpers // HTTP Client Helpers
LeCore.Acme // Signs requests with JWK ACME.Acme // Signs requests with JWK
acme = new Acme(keypair) // 'keypair' is an object with `privateKeyPem` and/or `privateKeyJwk` acme = new Acme(keypair) // 'keypair' is an object with `privateKeyPem` and/or `privateKeyJwk`
acme.post(url, body, cb) // POST with signature acme.post(url, body, cb) // POST with signature
acme.parseLinks(link) // (internal) parses 'link' header acme.parseLinks(link) // (internal) parses 'link' header
acme.getNonce(url, cb) // (internal) HEAD request to get 'replay-nonce' strings acme.getNonce(url, cb) // (internal) HEAD request to get 'replay-nonce' strings
``` ```
For testing and development, you can also inject the dependencies you want to use:
```javascript
LeCore = LeCore.create({
request: require('request')
, RSA: rquire('rsa-compat').RSA
});
// now uses node `request` (could also use jQuery or Angular in the browser)
LeCore.getAcmeUrls(discoveryUrl, function (err, urls) {
console.log(urls);
});
```
## Example ## Example
Below you'll find a stripped-down example. You can see the full example in the example folder. Below you'll find a stripped-down example. You can see the full example in the example folder.
* [example/](https://github.com/Daplie/letiny-core/blob/master/example/) * [example/](https://github.com/Daplie/le-acme-core/blob/master/example/)
#### Register Account & Domain #### Register Account & Domain
@ -153,12 +162,12 @@ This is how you **register an ACME account** and **get an HTTPS certificate**
```javascript ```javascript
'use strict'; 'use strict';
var LeCore = require('letiny-core'); var ACME = require('le-acme-core').ACME.create();
var RSA = require('rsa-compat').RSA; var RSA = require('rsa-compat').RSA;
var email = 'user@example.com'; // CHANGE TO YOUR EMAIL var email = 'user@example.com'; // CHANGE TO YOUR EMAIL
var domains = 'example.com'; // CHANGE TO YOUR DOMAIN var domains = 'example.com'; // CHANGE TO YOUR DOMAIN
var acmeDiscoveryUrl = LeCore.stagingServerUrl; // CHANGE to production, when ready var acmeDiscoveryUrl = ACME.stagingServerUrl; // CHANGE to production, when ready
var accountKeypair = null; // { privateKeyPem: null, privateKeyJwk: null }; var accountKeypair = null; // { privateKeyPem: null, privateKeyJwk: null };
var domainKeypair = null; // same as above var domainKeypair = null; // same as above
@ -167,14 +176,14 @@ var acmeUrls = null;
RSA.generateKeypair(2048, 65537, function (err, keypair) { RSA.generateKeypair(2048, 65537, function (err, keypair) {
accountKeypair = keypair; accountKeypair = keypair;
// ... // ...
LeCore.getAcmeUrls(acmeDiscoveryUrl, function (err, urls) { ACME.getAcmeUrls(acmeDiscoveryUrl, function (err, urls) {
// ... // ...
runDemo(); runDemo();
}); });
}); });
function runDemo() { function runDemo() {
LeCore.registerNewAccount( ACME.registerNewAccount(
{ newRegUrl: acmeUrls.newReg { newRegUrl: acmeUrls.newReg
, email: email , email: email
, accountKeypair: accountKeypair , accountKeypair: accountKeypair
@ -186,7 +195,7 @@ function runDemo() {
} }
, function (err, regr) { , function (err, regr) {
LeCore.getCertificate( ACME.getCertificate(
{ newAuthzUrl: acmeUrls.newAuthz { newAuthzUrl: acmeUrls.newAuthz
, newCertUrl: acmeUrls.newCert , newCertUrl: acmeUrls.newCert
@ -214,7 +223,7 @@ function runDemo() {
``` ```
**But wait**, there's more! **But wait**, there's more!
See [example/letsencrypt.js](https://github.com/Daplie/letiny-core/blob/master/example/letsencrypt.js) See [example/letsencrypt.js](https://github.com/Daplie/le-acme-core/blob/master/example/letsencrypt.js)
#### Run a Server on 80, 443, and 5001 (https/tls) #### Run a Server on 80, 443, and 5001 (https/tls)
@ -261,7 +270,7 @@ http.createServer(acmeResponder).listen(80, function () {
``` ```
**But wait**, there's more! **But wait**, there's more!
See [example/serve.js](https://github.com/Daplie/letiny-core/blob/master/example/serve.js) See [example/serve.js](https://github.com/Daplie/le-acme-core/blob/master/example/serve.js)
#### Put some storage in place #### Put some storage in place
@ -302,8 +311,8 @@ var certStore = {
**But wait**, there's more! **But wait**, there's more!
See See
* [example/challenge-store.js](https://github.com/Daplie/letiny-core/blob/master/challenge-store.js) * [example/challenge-store.js](https://github.com/Daplie/le-acme-core/blob/master/challenge-store.js)
* [example/cert-store.js](https://github.com/Daplie/letiny-core/blob/master/cert-store.js) * [example/cert-store.js](https://github.com/Daplie/le-acme-core/blob/master/cert-store.js)
## Authors ## Authors

View File

@ -1,12 +0,0 @@
/*!
* letiny-core
* Copyright(c) 2015 AJ ONeal <aj@daplie.com> https://daplie.com
* Apache-2.0 OR MIT (and hence also MPL 2.0)
*/
'use strict';
var request = require('request');
var RSA = require('rsa-compat').RSA;
module.exports.request = request;
module.exports.RSA = RSA;

42
node.js
View File

@ -5,26 +5,38 @@
*/ */
'use strict'; 'use strict';
var defaults = {
productionServerUrl: "https://acme-v01.api.letsencrypt.org/directory"
, stagingServerUrl: "https://acme-staging.api.letsencrypt.org/directory"
, acmeChallengePrefix: "/.well-known/acme-challenge/"
, knownEndpoints: [ 'new-authz', 'new-cert', 'new-reg', 'revoke-cert' ]
};
function create(deps) { function create(deps) {
var LeCore = {}; deps = deps || {};
deps.LeCore = {};
// Note: these are NOT DEFAULTS Object.keys(defaults).forEach(function (key) {
// They are de facto standards that you may deps[key] = defaults[key];
// or may not use in your implementation deps.LeCore[key] = defaults[key];
LeCore.productionServerUrl = "https://acme-v01.api.letsencrypt.org/directory"; });
LeCore.stagingServerUrl = "https://acme-staging.api.letsencrypt.org/directory";
LeCore.acmeChallengePrefix = "/.well-known/acme-challenge/";
LeCore.knownEndpoints = [ 'new-authz', 'new-cert', 'new-reg', 'revoke-cert' ];
deps.LeCore = LeCore; deps.RSA = deps.RSA || require('rsa-compat').RSA;
deps.Acme = LeCore.Acme = require('./lib/acme-client').create(deps); deps.request = deps.request || require('request');
LeCore.getAcmeUrls = require('./lib/get-acme-urls').create(deps); deps.LeCore.Acme = require('./lib/acme-client').create(deps);
LeCore.registerNewAccount = require('./lib/register-new-account').create(deps); deps.LeCore.getAcmeUrls = require('./lib/get-acme-urls').create(deps);
LeCore.getCertificate = require('./lib/get-certificate').create(deps); deps.LeCore.registerNewAccount = require('./lib/register-new-account').create(deps);
deps.LeCore.getCertificate = require('./lib/get-certificate').create(deps);
return LeCore; deps.Acme = deps.LeCore.Acme;
return deps.LeCore;
} }
module.exports = create(require('./lib/node')); // TODO nix this usage in v2
module.exports = create();
module.exports.create = create; module.exports.create = create;
// TODO make this the official usage
module.exports.ACME = { create: create };