-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from apigee/development
Development
- Loading branch information
Showing
15 changed files
with
674 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
const https = require('https'); | ||
const http = require('http'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const edgeConfig = require('microgateway-config'); | ||
const gatewayService = require('../index'); | ||
const { getJWT } = require('./helper.js'); | ||
let { user, username, password, key, secret, org, env, tokenSecret, tokenId } = require('./env.js'); | ||
var gateway; | ||
var jwtkn; | ||
let helloWorldSrv; | ||
let helloWorldSrvPort = 4435; | ||
let config; | ||
describe('Certificate Revocation List', () => { | ||
before(done => { | ||
helloWorldSrv = http | ||
.createServer((req, res) => { | ||
res.end('hello world'); | ||
}) | ||
.listen(helloWorldSrvPort, () => { | ||
done(); | ||
}); | ||
}); | ||
after(done => { | ||
gateway.stop(); | ||
helloWorldSrv.close(); | ||
done(); | ||
}); | ||
describe('MGW SSL CRL', () => { | ||
it('MGW SSL w CRL does not block valid client cert', done => { | ||
edgeConfig.get( | ||
{ keys: { key, secret }, source: `${__dirname}/fixtures/crl-config.yaml` }, | ||
(err, configDownload) => { | ||
config = configDownload; | ||
config.edgemicro.ssl = { | ||
cert: `${__dirname}/fixtures/server-crt.pem`, | ||
key: `${__dirname}/fixtures/server-key.pem`, | ||
ca: `${__dirname}/fixtures/ca-crt.pem`, | ||
crl: `${__dirname}/fixtures/ca-crl.pem`, | ||
requestCert: true, | ||
rejectUnauthorized: true | ||
}; | ||
|
||
config.proxies[0].url = `http://localhost:${helloWorldSrvPort}`; | ||
config.proxies[0].base_path = '/hello_world'; | ||
gateway = gatewayService(config); | ||
gateway.start(function() { | ||
getJWT(function(tkn) { | ||
jwtkn = tkn; | ||
let options = { | ||
hostname: 'localhost', | ||
port: config.edgemicro.port, | ||
path: '/hello_world', | ||
method: 'GET', | ||
key: fs.readFileSync(__dirname + '/fixtures/client1-key.pem'), | ||
cert: fs.readFileSync(__dirname + '/fixtures/client1-crt.pem'), | ||
ca: fs.readFileSync(__dirname + '/fixtures/ca-crt.pem'), | ||
headers: { | ||
Authorization: `Bearer ${tkn}` | ||
} | ||
}; | ||
let req = https.request(options, res => { | ||
let dataStr = ''; | ||
res.on('data', data => { | ||
dataStr += `${data}`; | ||
if (dataStr.includes('hello world')) done(); | ||
}); | ||
}); | ||
req.end(); | ||
req.on('error', err => { | ||
assert.equal(err, null); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
} | ||
); | ||
}); | ||
|
||
it('Refuses connection presenting revoked client cert', done => { | ||
let options = { | ||
hostname: 'localhost', | ||
port: config.edgemicro.port, | ||
path: '/hello_world', | ||
method: 'GET', | ||
key: fs.readFileSync(__dirname + '/fixtures/client2-key.pem'), | ||
cert: fs.readFileSync(__dirname + '/fixtures/client2-crt.pem'), //cert has been revoked on fixtures/ca-crl.pem | ||
ca: fs.readFileSync(__dirname + '/fixtures/ca-crt.pem'), | ||
headers: { | ||
Authorization: `Bearer ${jwtkn}` | ||
} | ||
}; | ||
let req = https.request(options, res => { | ||
let dataStr = ''; | ||
res.on('data', data => { | ||
dataStr += `${data}`; | ||
if (dataStr.includes('hello world')) { | ||
assert(false); | ||
done(); | ||
} | ||
}); | ||
}); | ||
req.end(); | ||
req.on('error', err => { | ||
assert.equal(err.code, 'ECONNRESET'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
const https = require('https'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const request = require('request'); | ||
const edgeConfig = require('microgateway-config'); | ||
const gatewayService = require('../index'); | ||
const { getJWT } = require('./helper.js'); | ||
let gateway; | ||
let jwtkn; | ||
let config = {}; | ||
let { user, username, password, key, secret, org, env, tokenSecret, tokenId } = require('./env.js'); | ||
let configPath = `${__dirname}/fixtures/crl-config.yaml`; //set to edgemicro config file path | ||
|
||
let options = { | ||
ca: fs.readFileSync(`${__dirname}/fixtures/ca-crt.pem`), | ||
requestCert: true, | ||
rejectUnauthorized: true | ||
}; | ||
|
||
let srv1Opts = { | ||
key: fs.readFileSync(`${__dirname}/fixtures/server-key.pem`), | ||
cert: fs.readFileSync(`${__dirname}/fixtures/server-crt.pem`) | ||
}; | ||
|
||
let srv1 = https.createServer({ ...options, ...srv1Opts }, (req, res) => { | ||
res.end('hello world valid\n'); | ||
}); | ||
|
||
let srv2Opts = { | ||
key: fs.readFileSync(`${__dirname}/fixtures/server-key2.pem`), | ||
cert: fs.readFileSync(`${__dirname}/fixtures/server-crt2.pem`) | ||
}; | ||
//srv2 uses a cert revoked on fixtures/ca-crl.pem | ||
let srv2 = https.createServer({ ...options, ...srv2Opts }, (req, res) => { | ||
res.end('hello world invalid\n'); | ||
}); | ||
|
||
const srv1Port = 8433; | ||
const srv2Port = 8434; | ||
|
||
describe('Certificate Revocation List', () => { | ||
before(done => { | ||
srv1.listen(srv1Port, () => { | ||
srv2.listen(srv2Port, () => { | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
after(done => { | ||
gateway.stop(); | ||
srv1.close(); | ||
srv2.close(); | ||
done(); | ||
}); | ||
describe('Outbound Target Server CRL', () => { | ||
it('Does not block valid certs', done => { | ||
edgeConfig.get({ keys: { key, secret }, source: configPath }, (err, configDownload) => { | ||
config = configDownload; | ||
config.edgemicro = { | ||
port: 8000, | ||
logging: { level: 'info', dir: './tests/log' } | ||
}; | ||
config.targets = [ | ||
{ | ||
host: 'localhost', | ||
ssl: { | ||
client: { | ||
cert: `${__dirname}/fixtures/client1-crt.pem`, | ||
key: `${__dirname}/fixtures/client1-key.pem`, | ||
ca: `${__dirname}/fixtures/ca-crt.pem`, | ||
crl: `${__dirname}/fixtures/ca-crl.pem`, | ||
rejectUnauthorized: true | ||
} | ||
} | ||
} | ||
]; | ||
config.proxies[0] = {}; | ||
config.proxies[1] = {}; | ||
config.proxies[0].url = `https://localhost:${srv1Port}/`; | ||
config.proxies[0].base_path = '/edgemicro_testcrl01'; | ||
config.proxies[1].url = `https://localhost:${srv2Port}/`; | ||
config.proxies[1].base_path = '/edgemicro_testcrl02'; | ||
|
||
gateway = gatewayService(config); | ||
gateway.start(() => { | ||
getJWT(tkn => { | ||
jwtkn = tkn; | ||
request( | ||
{ | ||
method: 'get', | ||
uri: `http://localhost:${config.edgemicro.port}/edgemicro_testcrl01`, | ||
auth: { | ||
bearer: tkn | ||
}, | ||
json: true | ||
}, | ||
(err, resp, body) => { | ||
if (err) console.error('crl02 err', err); | ||
assert.equal(err, null); | ||
assert.equal(resp.statusCode, 200); | ||
assert(body.includes('hello world valid')); | ||
done(); | ||
} | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it('Blocks revoked certs', done => { | ||
request( | ||
{ | ||
method: 'get', | ||
uri: `http://localhost:${config.edgemicro.port}/edgemicro_testcrl02`, | ||
auth: { | ||
bearer: jwtkn | ||
}, | ||
json: true | ||
}, | ||
(err, resp, body) => { | ||
if (err) console.error('err crl02', err); | ||
assert.equal(resp.statusCode, 502); | ||
assert.equal(body.message, 'certificate revoked'); | ||
assert.equal(body.code, 'CERT_REVOKED'); | ||
done(); | ||
} | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-----BEGIN X509 CRL----- | ||
MIIDAjCB6zANBgkqhkiG9w0BAQQFADCBgTELMAkGA1UEBhMCVVMxCzAJBgNVBAgM | ||
Ak1BMQ8wDQYDVQQHDAZCb3N0b24xEzARBgNVBAoMCkV4YW1wbGUgQ28xEDAOBgNV | ||
BAsMB3RlY2hvcHMxCzAJBgNVBAMMAmNhMSAwHgYJKoZIhvcNAQkBFhFjZXJ0c0Bl | ||
eGFtcGxlLmNvbRcNMTkwMzEzMDMxMjUxWhcNNDYwNzI4MDMxMjUxWjA4MBoCCQDP | ||
GXRZmAJ+phcNMTkwMzEzMDMxMjQ0WjAaAgkAzxl0WZgCfqcXDTE5MDMxMjE4NDIx | ||
NFowDQYJKoZIhvcNAQEEBQADggIBANN85WHF5v1d4rn+Yc4w57oRGox3gxJ7xo93 | ||
nD1SBwyDtiCNIP1JDOzEPtRAMtbCaGGROpKF1Hh7MQB4a8wOLCtbJ3PdoBKoP0Tg | ||
RO8EgZlFQkOCb3LTX3I4gJcMzQbLd3JLpJFrFhyCr7c1TDet82hL6bsewPUJ+Kob | ||
SHTbQOfg0KlpfkeOdsty7O5JZUM1aXGDOU8J/9d/I0xuV91poFjkevNozKr/5eV/ | ||
jc+uEMx+gMTigOAoZACFkn0urhCHcv6s9s9QshQP0a96HKTNb16HLxwaoQygp5DP | ||
KDRcL1ZDxQk7cMrrpXITTpGEPEQLzL3CQvC2vw6yLwsSXCaI79hbZPphAhFG5oN4 | ||
1ujAb3i4vosqPLuRQc6YYRtXTeXyMFUIQoNh4AHqiYtQpbWgF00hsR004EcTZ0le | ||
snecQjIJcBA2TvqReSsVOOBApBV/I4JjRP+PwEqiSrzT5IQ08HTU8tRCh9XyQv+s | ||
hlkizPpYQwiOJtTfxaDyuPpM+ry2Nl/p6XWofX0flombQI4GmIt9uGRKSgbACCAF | ||
C+hbIpo2wj6WefIFE/cP6a7ox9ahPsPBXowLuuuOG+5YP+GAzyvH4xwO+aQQG5+J | ||
cBR7PCB5oLkyUq4ZX9EjUYve/zzXua+ttEzuRHB/es4jT/XVuaSpa2gYf5m3Vqc4 | ||
PuHDfk9M | ||
-----END X509 CRL----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIFgDCCA2gCCQDMjD+tmugHNTANBgkqhkiG9w0BAQsFADCBgTELMAkGA1UEBhMC | ||
VVMxCzAJBgNVBAgMAk1BMQ8wDQYDVQQHDAZCb3N0b24xEzARBgNVBAoMCkV4YW1w | ||
bGUgQ28xEDAOBgNVBAsMB3RlY2hvcHMxCzAJBgNVBAMMAmNhMSAwHgYJKoZIhvcN | ||
AQkBFhFjZXJ0c0BleGFtcGxlLmNvbTAeFw0xOTAzMTIxODIyMTdaFw00NjA3Mjcx | ||
ODIyMTdaMIGBMQswCQYDVQQGEwJVUzELMAkGA1UECAwCTUExDzANBgNVBAcMBkJv | ||
c3RvbjETMBEGA1UECgwKRXhhbXBsZSBDbzEQMA4GA1UECwwHdGVjaG9wczELMAkG | ||
A1UEAwwCY2ExIDAeBgkqhkiG9w0BCQEWEWNlcnRzQGV4YW1wbGUuY29tMIICIjAN | ||
BgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA6U7N4HOot/iG0kpkyKC9cEw5c1d9 | ||
0lJNembn43q6jt7Cr/OBmOBHxDUn7VeUmOEzAr/JQCaqopWTgOhkQcODcSXjshCX | ||
cFrX0aQze9oFAYcpsCtJG2EUoHeUQvDywefN3Tbqqf34pGRqlrJ7bVGCUmHWihNT | ||
CJBQSo+k8+H9rkaJC7BO0RisBdNObN88OHvF2A8rvyOwZAKC5p6bZ7HqhqBve3Zl | ||
sa5f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bMLuddFbWrrdo9MVMDeZ/CH1l9Odvt6xAGw19EvCstWPTjIEj6ILiDStzF | ||
zzzJLvxK0OupVXM5w4BvRbTLz5fjQJrfmjBLSUb60nuEtLwnRGf896U8hYN1Vr5W | ||
B3TFROhM9+SNEIC6CQ5dQwzKGvs= | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIFijCCA3KgAwIBAgIJAM8ZdFmYAn6lMA0GCSqGSIb3DQEBBQUAMIGBMQswCQYD | ||
VQQGEwJVUzELMAkGA1UECAwCTUExDzANBgNVBAcMBkJvc3RvbjETMBEGA1UECgwK | ||
RXhhbXBsZSBDbzEQMA4GA1UECwwHdGVjaG9wczELMAkGA1UEAwwCY2ExIDAeBgkq | ||
hkiG9w0BCQEWEWNlcnRzQGV4YW1wbGUuY29tMB4XDTE5MDMxMjE4MjUzMVoXDTIx | ||
MTIwNTE4MjUzMVowgYYxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJNQTEPMA0GA1UE | ||
BwwGQm9zdG9uMRMwEQYDVQQKDApFeGFtcGxlIENvMRAwDgYDVQQLDAd0ZWNob3Bz | ||
MRAwDgYDVQQDDAdjbGllbnQxMSAwHgYJKoZIhvcNAQkBFhFjZXJ0c0BleGFtcGxl | ||
LmNvbTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAJ8Mon9yTsiCW4Mg | ||
fHtsfYZCS5uF7jRTzHVIHKIP+3FE7nCsL7tUdhWsgij0e7i2gFSXgIm4krN8wyn3 | ||
tjVGYR2uLYQEftKQ2XTzz8bNoK+Wpw3xEkVMmg4ncdK1CapILRwiYHTSyMSg3D6j | ||
kE9LPvVCKYdyUkyByvfYi8Ufk4ajyZ3MX9egB24Lt/oFFIAuvU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9amxjgGOzM24oftLqAZPZgvBxnqW+ | ||
kmnPT4SZRut9FrKZvD42b9vkRBlhx1fl1/bo0pFtSN2vftADaqa6CacQmOqkMlj2 | ||
H7z/L+kQbGS8Ex+K2TwELWw3qPtNhpzc+C4XoAHEsDRbNduo9c7eZQl4VHny/mds | ||
yu8tPm+IgoAT6z5WnwJSYAKNMLydTC88328ZHsOd | ||
-----END CERTIFICATE----- |
Oops, something went wrong.