Compare commits

..

No commits in common. "master" and "v3.0.0" have entirely different histories.

3 changed files with 35 additions and 38 deletions

View File

@ -37,19 +37,14 @@ module.exports.create = function (opts) {
// This is our dummy in-memory storage. // This is our in-memory storage.
// (we optionally receive it as an option so that it can be defined outside to make testing easier) // We take it from the outside to make testing the dummy module easier.
var cache = opts.cache || {}; var cache = opts.cache || {};
if (!cache.accounts) { cache.accounts = {}; } if (!cache.accounts) { cache.accounts = {}; }
if (!cache.certificates) { cache.certificates = {}; } if (!cache.certificates) { cache.certificates = {}; }
// Although we could have two collections of keypairs, // Although we could have two collections of keypairs,
// it's also fine to store both types together (their ids will be distinct). // it's also fine to store both types together.
if (!cache.keypairs) { cache.keypairs = {}; } if (!cache.keypairs) { cache.keypairs = {}; }
// This is an in-memory store, hence we don't actually save it.
function saveCertificate(id, blob) { cache.certificates[id] = blob; return null; }
function getCertificate(id) { return cache.certificates[id]; }
function saveKeypair(id, blob) { cache.keypairs[id] = blob; return null; }
function getKeypair(id) { return cache.keypairs[id]; }
@ -64,16 +59,17 @@ module.exports.create = function (opts) {
// Whenever a new keypair is used to successfully create an account, we need to save its keypair // Whenever a new keypair is used to successfully create an account, we need to save its keypair
store.accounts.setKeypair = function (opts) { store.accounts.setKeypair = function (opts) {
console.log('accounts.setKeypair:', opts.account, opts.email); console.log('accounts.setKeypair:', opts.account, opts.email, opts.keypair);
console.log(opts.keypair);
var id = opts.account.id || opts.email || 'default'; var id = opts.account.id || opts.email || 'default';
var keypair = opts.keypair; var keypair = opts.keypair;
return saveKeypair(id, JSON.stringify({ cache.keypairs[id] = JSON.stringify({
privateKeyPem: keypair.privateKeyPem // string PEM privateKeyPem: keypair.privateKeyPem
, privateKeyJwk: keypair.privateKeyJwk // object JWK , privateKeyJwk: keypair.privateKeyJwk
})); // Must return or Promise `null` instead of `undefined` });
return null; // or Promise.resolve(null);
}; };
@ -83,7 +79,7 @@ module.exports.create = function (opts) {
console.log('accounts.checkKeypair:', opts.account, opts.email); console.log('accounts.checkKeypair:', opts.account, opts.email);
var id = opts.account.id || opts.email || 'default'; var id = opts.account.id || opts.email || 'default';
var keyblob = getKeypair(id); var keyblob = cache.keypairs[id];
if (!keyblob) { return null; } if (!keyblob) { return null; }
@ -113,21 +109,21 @@ module.exports.create = function (opts) {
// Certificate Keypairs must not be used for Accounts and vice-versamust not be the same as any account keypair // Certificate Keypairs must not be used for Accounts and vice-versamust not be the same as any account keypair
// //
store.certificates.setKeypair = function (opts) { store.certificates.setKeypair = function (opts) {
console.log('certificates.setKeypair:', opts.certificate, opts.subject); console.log('certificates.setKeypair:', opts.certificate, opts.subject, opts.keypair);
console.log(opts.keypair);
// The ID is a string that doesn't clash between accounts and certificates. // The ID is a string that doesn't clash between accounts and certificates.
// That's all you need to know... unless you're doing something special (in which case you're on your own). // That's all you need to know... unless you're doing something special (in which case you're on your own).
var id = opts.certificate.kid || opts.certificate.id || opts.subject; var id = opts.certificate.kid || opts.certificate.id || opts.subject;
var keypair = opts.keypair; var keypair = opts.keypair;
return saveKeypair(id, JSON.stringify({ cache.keypairs[id] = JSON.stringify({
privateKeyPem: keypair.privateKeyPem // string PEM privateKeyPem: keypair.privateKeyPem
, privateKeyJwk: keypair.privateKeyJwk // object JWK , privateKeyJwk: keypair.privateKeyJwk
})); // Must return or Promise `null` instead of `undefined` });
// Note: you can use the "keypairs" package to convert between
// Side Note: you can use the "keypairs" package to convert between
// public and private for jwk and pem, as well as convert JWK <-> PEM // public and private for jwk and pem, as well as convert JWK <-> PEM
return null;
}; };
@ -137,7 +133,7 @@ module.exports.create = function (opts) {
console.log('certificates.checkKeypair:', opts.certificate, opts.subject); console.log('certificates.checkKeypair:', opts.certificate, opts.subject);
var id = opts.certificate.kid || opts.certificate.id || opts.subject; var id = opts.certificate.kid || opts.certificate.id || opts.subject;
var keyblob = getKeypair(id); var keyblob = cache.keypairs[id];
if (!keyblob) { return null; } if (!keyblob) { return null; }
@ -151,18 +147,19 @@ module.exports.create = function (opts) {
// the key using the "cert-info" package. // the key using the "cert-info" package.
store.certificates.set = function (opts) { store.certificates.set = function (opts) {
console.log('certificates.set:', opts.certificate, opts.subject); console.log('certificates.set:', opts.certificate, opts.subject);
console.log(opts.pems);
var id = opts.certificate.id || opts.subject; var id = opts.certificate.id || opts.subject;
var pems = opts.pems; var pems = opts.pems;
return saveCertificate(id, JSON.stringify({ cache.certificates[id] = JSON.stringify({
cert: pems.cert // string PEM cert: pems.cert
, chain: pems.chain // string PEM , chain: pems.chain
, subject: pems.subject // string name 'example.com , subject: pems.subject
, altnames: pems.altnames // Array of string names [ 'example.com', '*.example.com', 'foo.bar.example.com' ] , altnames: pems.altnames
, issuedAt: pems.issuedAt // date number in ms (a.k.a. NotBefore) , issuedAt: pems.issuedAt // a.k.a. NotBefore
, expiresAt: pems.expiresAt // date number in ms (a.k.a. NotAfter) , expiresAt: pems.expiresAt // a.k.a. NotAfter
})); // Must return or Promise `null` instead of `undefined` });
return null;
}; };
@ -174,7 +171,7 @@ module.exports.create = function (opts) {
console.log('certificates.check:', opts.certificate, opts.subject); console.log('certificates.check:', opts.certificate, opts.subject);
var id = opts.certificate.id || opts.subject; var id = opts.certificate.id || opts.subject;
var certblob = getCertificate(id); var certblob = cache.certificates[id];
if (!certblob) { return null; } if (!certblob) { return null; }

2
package-lock.json generated
View File

@ -1,5 +1,5 @@
{ {
"name": "greenlock-store-memory", "name": "greenlock-store-memory",
"version": "3.0.3", "version": "3.0.0",
"lockfileVersion": 1 "lockfileVersion": 1
} }

View File

@ -1,8 +1,8 @@
{ {
"name": "greenlock-store-memory", "name": "greenlock-store-memory",
"version": "3.0.3", "version": "3.0.0",
"description": "An in-memory reference implementation for account, certificate, and keypair storage strategies in Greenlock", "description": "An in-memory reference implementation for account, certificate, and keypair storage strategies in Greenlock",
"homepage": "https://git.coolaj86.com/coolaj86/greenlock-store-memory.js", "homepage": "https://git.coolaj86.com/coolaj86/le-store-memory.js",
"main": "index.js", "main": "index.js",
"directories": { "directories": {
"test": "tests" "test": "tests"
@ -12,7 +12,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://git.coolaj86.com/coolaj86/greenlock-store-memory.js.git" "url": "https://git.coolaj86.com/coolaj86/le-store-memory.js.git"
}, },
"keywords": [ "keywords": [
"greenlock", "greenlock",