2015-12-15 22:07:02 +00:00
|
|
|
# letiny-core
|
2015-12-13 16:50:04 +00:00
|
|
|
|
2015-12-15 22:07:02 +00:00
|
|
|
A framework for building letsencrypt clients, forked from `letiny`.
|
|
|
|
|
|
|
|
* browser
|
|
|
|
* node with `forge` (works on windows)
|
|
|
|
* node with `ursa` (works fast)
|
|
|
|
* any javascript implementation
|
2015-12-13 16:50:04 +00:00
|
|
|
|
|
|
|
## Usage:
|
|
|
|
|
2015-12-15 22:07:02 +00:00
|
|
|
```bash
|
|
|
|
npm install --save letiny-core
|
2015-12-13 16:50:04 +00:00
|
|
|
```
|
|
|
|
|
2015-12-15 22:07:02 +00:00
|
|
|
```javascript
|
|
|
|
'use strict';
|
|
|
|
|
2015-12-16 00:51:44 +00:00
|
|
|
var LeCore = require('letiny-core');
|
|
|
|
var accountPrivateKeyPem = '...'; // leCrypto.generateRsaKeypair(bitLen, exp, cb)
|
|
|
|
var domainPrivateKeyPem = '...'; // (same)
|
|
|
|
|
|
|
|
LeCore.getAcmeUrls(
|
|
|
|
LeCore.stagingServerUrl // or choose LeCore.productionServerUrl
|
|
|
|
, function (err, urls) {
|
|
|
|
|
|
|
|
LeCore.registerNewAccount(
|
|
|
|
{ newRegUrl: urls.newReg
|
|
|
|
, email: 'user@example.com'
|
|
|
|
, accountPrivateKeyPem: accountPrivateKeyPem
|
|
|
|
, agreeToTerms: function (tosUrl, done) {
|
|
|
|
// agree to these exact terms
|
|
|
|
done(null, tosUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
, function (err, regr) {
|
|
|
|
|
|
|
|
// Note: you should save the registration
|
|
|
|
// record to disk (or db)
|
|
|
|
|
|
|
|
LeCore.getCertificate(
|
|
|
|
{
|
|
|
|
}
|
|
|
|
, function (err, certs) {
|
|
|
|
|
|
|
|
// Note: you should save certs to disk (or db)
|
|
|
|
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
2015-12-13 16:50:04 +00:00
|
|
|
```
|
|
|
|
|
2015-12-15 22:07:02 +00:00
|
|
|
## API
|
|
|
|
|
2015-12-16 00:51:44 +00:00
|
|
|
The Goodies
|
|
|
|
|
2015-12-16 00:13:07 +00:00
|
|
|
```javascript
|
2015-12-16 00:51:44 +00:00
|
|
|
{ newRegUrl: '...' // no defaults, specify LeCore.nproductionServerUrl
|
|
|
|
|
|
|
|
// Accounts
|
|
|
|
LeCore.registerNewAccount(options, cb) // returns (err, acmeUrls={newReg,newAuthz,newCert,revokeCert})
|
|
|
|
|
|
|
|
{ newRegUrl: '...' // no defaults, specify LeCore.newAuthz
|
|
|
|
, email: '...' // valid email (server checks MX records)
|
|
|
|
, agreeToTerms: fn (tosUrl, cb) {} // callback to allow user interaction for tosUrl
|
|
|
|
// cb(err=null, agree=tosUrl) // must specify agree=tosUrl to continue (or falsey to end)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Registration
|
|
|
|
LeCore.getCertificate(options, cb)
|
|
|
|
|
|
|
|
{ newAuthzUrl: '...' // no defaults, specify acmeUrls.newAuthz
|
|
|
|
```
|
2015-12-15 22:07:02 +00:00
|
|
|
|
2015-12-16 00:51:44 +00:00
|
|
|
Helpers & Stuff
|
2015-12-15 22:07:02 +00:00
|
|
|
|
2015-12-16 00:51:44 +00:00
|
|
|
```javascript
|
|
|
|
// Constants
|
|
|
|
LeCore.productionServerUrl // https://acme-v01.api.letsencrypt.org/directory
|
|
|
|
LeCore.stagingServerUrl // https://acme-staging.api.letsencrypt.org/directory
|
|
|
|
LeCore.configDir // /etc/letsencrypt/
|
|
|
|
LeCore.logsDir // /var/log/letsencrypt/
|
|
|
|
LeCore.workDir // /var/lib/letsencrypt/
|
|
|
|
|
|
|
|
|
|
|
|
// HTTP Client Helpers
|
2015-12-16 00:13:07 +00:00
|
|
|
LeCore.Acme // Signs requests with JWK
|
|
|
|
acme = new Acme(lePrivateKey) // privateKey format is abstract
|
|
|
|
acme.post(url, body, cb) // POST with signature
|
|
|
|
acme.parseLinks(link) // (internal) parses 'link' header
|
|
|
|
acme.getNonce(url, cb) // (internal) HEAD request to get 'replay-nonce' strings
|
2015-12-15 22:07:02 +00:00
|
|
|
|
2015-12-16 00:51:44 +00:00
|
|
|
// Note: some of these are not async,
|
|
|
|
// but they will be soon. Don't rely
|
|
|
|
// on their API yet.
|
|
|
|
|
|
|
|
// Crypto Helpers
|
2015-12-15 22:07:02 +00:00
|
|
|
LeCore.leCrypto
|
2015-12-16 00:51:44 +00:00
|
|
|
generateRsaKeypair(bitLen, exponent, cb); // returns { privateKeyPem, privateKeyJwk, publicKeyPem, publicKeyMd5 }
|
|
|
|
thumbprint(lePubKey) // generates public key thumbprint
|
2015-12-16 00:13:07 +00:00
|
|
|
generateSignature(lePrivKey, bodyBuf, nonce) // generates a signature
|
2015-12-16 00:51:44 +00:00
|
|
|
privateJwkToPems(jwk) // { n: '...', e: '...', iq: '...', ... } to PEMs
|
|
|
|
privatePemToJwk // PEM to JWK (see line above)
|
|
|
|
importPemPrivateKey(privateKeyPem) // (internal) returns abstract private key
|
2015-12-13 16:50:04 +00:00
|
|
|
```
|
|
|
|
|
2015-12-15 22:07:02 +00:00
|
|
|
For testing and development, you can also inject the dependencies you want to use:
|
|
|
|
|
|
|
|
```javascript
|
2015-12-16 00:51:44 +00:00
|
|
|
LeCore = LeCore.create({
|
2015-12-15 22:07:02 +00:00
|
|
|
request: require('request')
|
|
|
|
, leCrypto: rquire('./lib/letsencrypt-forge')
|
|
|
|
});
|
2015-12-16 00:51:44 +00:00
|
|
|
|
|
|
|
// now uses node `request` (could also use jQuery or Angular in the browser)
|
|
|
|
LeCore.getAcmeUrls({
|
|
|
|
se
|
|
|
|
});
|
2015-12-15 22:07:02 +00:00
|
|
|
```
|
2015-12-13 16:50:04 +00:00
|
|
|
|
|
|
|
## Licence
|
2015-12-15 22:07:02 +00:00
|
|
|
|
2015-12-13 16:50:04 +00:00
|
|
|
MPL 2.0
|
|
|
|
|
2015-12-15 22:07:02 +00:00
|
|
|
All of the code is available under the MPL-2.0.
|
|
|
|
|
|
|
|
Some of the files are original work not modified from `letiny`
|
|
|
|
and are made available under MIT as well (check file headers).
|