updates
This commit is contained in:
parent
aec8958ca8
commit
4015e792dd
10
README.md
10
README.md
|
@ -23,10 +23,10 @@ leCore.
|
|||
|
||||
## API
|
||||
|
||||
```
|
||||
LeCore.registerNewAccount();
|
||||
```javascript
|
||||
LeCore.registerNewAccount(options, cb);
|
||||
|
||||
LeCore.getCertificate();
|
||||
LeCore.getCertificate(options, cb);
|
||||
|
||||
LeCore.Acme // Signs requests with JWK
|
||||
acme = new Acme(lePrivateKey) // privateKey format is abstract
|
||||
|
@ -35,7 +35,9 @@ LeCore.Acme // Signs requests with JWK
|
|||
acme.getNonce(url, cb) // (internal) HEAD request to get 'replay-nonce' strings
|
||||
|
||||
LeCore.leCrypto
|
||||
generateSignature(lePrivateKey, nodeBufferBody, nonceString)
|
||||
thumbprint(lePubKey) // generates thumbprint
|
||||
generateSignature(lePrivKey, bodyBuf, nonce) // generates a signature
|
||||
importPemPrivateKey(privateKeyPem); // returns abstract private key
|
||||
```
|
||||
|
||||
For testing and development, you can also inject the dependencies you want to use:
|
||||
|
|
|
@ -4,14 +4,16 @@
|
|||
* Some code used from https://github.com/letsencrypt/boulder/tree/master/test/js
|
||||
* MPL 2.0
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports.create = function (deps) {
|
||||
var NOOP=function () {}, log=NOOP;
|
||||
var request=require('request');
|
||||
var util=require('./acme-util');
|
||||
var cryptoUtil=require('./crypto-util');
|
||||
var Acme = require('./acme-client');
|
||||
var importPemPrivateKey = deps.leCrypto.importPemPrivateKey;
|
||||
var thumbprinter = deps.leCrypto.thumbprint;
|
||||
var generateCsr = deps.leCrypto.generateCsr || deps.leCrypto.generateCSR;
|
||||
var Acme = deps.Acme;
|
||||
|
||||
function getCert(options, cb) {
|
||||
var state={
|
||||
|
@ -40,10 +42,10 @@ function getCert(options, cb) {
|
|||
state.domains = options.domains.slice(0); // copy array
|
||||
try {
|
||||
state.accountKeyPem=options.accountPrivateKeyPem;
|
||||
state.accountKeyPair=cryptoUtil.importPemPrivateKey(state.accountKeyPem);
|
||||
state.accountKeyPair=importPemPrivateKey(state.accountKeyPem);
|
||||
state.acme=new Acme(state.accountKeyPair);
|
||||
state.certPrivateKeyPem=options.domainPrivateKeyPem;
|
||||
state.certPrivateKey=cryptoUtil.importPemPrivateKey(state.certPrivateKeyPem);
|
||||
state.certPrivateKey=importPemPrivateKey(state.certPrivateKeyPem);
|
||||
} catch(err) {
|
||||
return handleErr(err, 'Failed to parse privateKey');
|
||||
}
|
||||
|
@ -100,7 +102,7 @@ function getCert(options, cb) {
|
|||
}
|
||||
challenge=httpChallenges[0];
|
||||
|
||||
thumbprint=cryptoUtil.thumbprint(state.accountKeyPair.publicKey);
|
||||
thumbprint=thumbprinter(state.accountKeyPair.publicKey);
|
||||
keyAuthorization=challenge.token+'.'+thumbprint;
|
||||
state.responseUrl=challenge.uri;
|
||||
|
||||
|
@ -152,7 +154,7 @@ function getCert(options, cb) {
|
|||
}
|
||||
|
||||
function getCertificate() {
|
||||
var csr=cryptoUtil.generateCSR(state.certPrivateKey, state.validatedDomains);
|
||||
var csr=generateCsr(state.certPrivateKey, state.validatedDomains);
|
||||
log('Requesting certificate...');
|
||||
state.acme.post(state.newCertificateUrl, {
|
||||
resource:'new-cert',
|
||||
|
@ -234,7 +236,6 @@ function getCert(options, cb) {
|
|||
log(text, err, info);
|
||||
cb(err || new Error(text));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function certBufferToPem(cert) {
|
||||
|
@ -243,4 +244,5 @@ function certBufferToPem(cert) {
|
|||
return '-----BEGIN CERTIFICATE-----\n'+cert+'\n-----END CERTIFICATE-----';
|
||||
}
|
||||
|
||||
module.exports = getCert;
|
||||
return getCert;
|
||||
};
|
||||
|
|
2
node.js
2
node.js
|
@ -9,7 +9,7 @@ function create(deps) {
|
|||
var LeCore = {};
|
||||
|
||||
LeCore.leCrypto = deps.leCrypto;
|
||||
LeCore.Acme = require('./lib/acme-client').create(deps);
|
||||
deps.Acme = LeCore.Acme = require('./lib/acme-client').create(deps);
|
||||
LeCore.registerNewAccount = require('./lib/register-new-account').create(deps);
|
||||
LeCore.getCertificate = require('./lib/get-certificate').create(deps);
|
||||
|
||||
|
|
Loading…
Reference in New Issue