ndn-js
Version:
A JavaScript client library for Named Data Networking
383 lines (331 loc) • 20 kB
JavaScript
/**
* Copyright (C) 2014-2019 Regents of the University of California.
* @author: Jeff Thompson <jefft0@remap.ucla.edu>, Jiayi Meng <mjycom@hotmail.com>
* From PyNDN unit-tests by Adeola Bannis.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version, with the additional exemption that
* compiling, linking, and/or using OpenSSL is allowed.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* A copy of the GNU Lesser General Public License is in the file COPYING.
*/
var assert = require("assert");
var fs = require("fs");
var Name = require('../../..').Name;
var Data = require('../../..').Data;
var Blob = require('../../..').Blob;
var KeyType = require('../../..').KeyType;
var MemoryIdentityStorage = require('../../..').MemoryIdentityStorage;
var MemoryPrivateKeyStorage = require('../../..').MemoryPrivateKeyStorage;
var IdentityManager = require('../../..').IdentityManager;
var KeyChain = require('../../..').KeyChain;
var ConfigPolicyManager = require('../../..').ConfigPolicyManager;
var NoVerifyPolicyManager = require('../../..').NoVerifyPolicyManager;
var SelfVerifyPolicyManager = require('../../..').SelfVerifyPolicyManager;
var Face = require('../../..').Face;
var Interest = require('../../..').Interest;
var IdentityCertificate = require('../../../js/security/certificate/identity-certificate.js').IdentityCertificate;
var DEFAULT_RSA_PUBLIC_KEY_DER = new Buffer([
0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01,
0x00, 0xd4, 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jY1CAdJRC1DRVJUCAgA" +
"AAFJRKMe3BQDGAECFf0BcDCCAWwwIhgPMjAxNDEwMjUwMDA5NDFaGA8yMDM0MTAy" +
"MDAwMDk0MVowIDAeBgNVBCkTFy90ZW1wL2tzay0xNDE0MTk1Nzc5NjY1MIIBIjAN" +
"BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA58yUcdGPsYx/+ZRwbrfdqeNyCIgJ" +
"bZ7tsV3XC4awJEOwWsEp6KWcihAdfUfFGOvB+q4IAbg0GrpuRlD7/RjMMfOVrOj5" +
"BmWvpW5unHUIZ4DNGsICH6f/e4DUvcCwxbXpJmtHRit2Pllep/4M62YZLKlaqQAJ" +
"kfXseVEzKSIBmeHu5fPBGNizFoZTG2mocAya5grWzMX5boBjHddAGXC5VswviAHM" +
"XcOUDre0+8Rg4BGl0Yt4DGuD2LcfijxCTGRJrT9M0ENKbxj8AMB6Grner0xN6thJ" +
"LW4VLHBVkOTrjx/4USImgw9xQd0m+CshY+R6HXVDSGQ0ckno9MNWOZPjHQIDAQAB" +
"Fi4bAQEcKQcnCAR0ZW1wCANLRVkIEWtzay0xNDE0MTk1Nzc5NjY1CAdJRC1DRVJU" +
"F/0BADWC/f623e3XZSQe5sLHKlHMa1eWmvaBmQrVLa1BvhyVdjbdujXSh2cMv9Wi" +
"qtVgALftzQpuhRA6wYX9PgP3A+0uGjjljKijuKDOWPPZodtWJqzDSt0UX4WU4hT5" +
"is4g4VdZ/aRc8x/z17QmUOdrN6yidLGKzx814JDy+npqZVXYYkcLgUu6o+3rddId" +
"DCp8sT/zjjGORj04Gh6qCp0QBEfNmZke8aI4DGor83AL5b9eDvWv3TtMNRzrWcF7" +
"NgvRyxKNDIXJZym0qpHQQVjdQJezWNxf82swBV2S7nbJCI4djOwbRTnRFuwi4vHs" +
"BmWVlUfyAg8noGdPRS8MGQs24vw=";
var identityStorage_;
var privateKeyStorage_;
var identityManager_;
var keyChain_;
var policyManager_;
var identityName_;
var keyName_;
var face_;
function getNowSeconds()
{
var currentDate = new Date();
return currentDate.getMilliseconds() / 1000.0;
}
// checkPolicyManager
describe ("TestPolicyMatching", function() {
beforeEach(function() {
identityStorage_ = new MemoryIdentityStorage();
privateKeyStorage_ = new MemoryPrivateKeyStorage();
identityManager_ = new IdentityManager(identityStorage_, privateKeyStorage_);
policyManager_ = new ConfigPolicyManager("policy_config/simple_rules.conf");
identityName_ = new Name("/TestConfigPolicyManager/temp");
keyName_ = new Name(identityName_).append("ksk-1416010123");
identityStorage_.addKey
(keyName_, KeyType.RSA, new Blob(DEFAULT_RSA_PUBLIC_KEY_DER, false));
privateKeyStorage_.setKeyPairForKeyName
(keyName_, KeyType.RSA, DEFAULT_RSA_PUBLIC_KEY_DER, DEFAULT_RSA_PRIVATE_KEY_DER);
var cert = identityManager_.selfSign(keyName_);
identityStorage_.setDefaultKeyNameForIdentity(keyName_);
identityManager_.addCertificateAsDefault(cert);
face_ = new Face("localhost");
keyChain_ = new KeyChain(identityManager_, policyManager_);
});
afterEach(function() {
try {
fs.unlinkSync('policy_config/certs/testData.cert');
}
catch (e) {}
face_.close();
});
it("NoVerify", function() {
var policyManager = new NoVerifyPolicyManager();
var identityName = new Name("TestValidator/Null").appendVersion(getNowSeconds());
var keyChain = new KeyChain(identityManager_, policyManager);
keyChain.createIdentityAndCertificate(identityName);
var data = new Data(new Name(identityName).append("data"));
keyChain.signByIdentity(data, identityName);
var failureCount = 0;
var successCount = 0;
var vr = policyManager.checkVerificationPolicy(data, 0,
function() { ++successCount; }, function() { ++failureCount; });
assert.equal(vr, null, "NoVerifyPolicyManager returned a ValidationRequest");
assert.equal
(failureCount, 0, "Verification failed with NoVerifyPolicyManager");
assert.equal
(successCount, 1,
"Verification success called " + successCount + " times instead of 1");
});
it("SelfVerification", function() {
var policyManager = new SelfVerifyPolicyManager(identityStorage_);
var identityName = new Name("TestValidator/RsaSignatureVerification");
var keyChain = new KeyChain(identityManager_, policyManager);
keyChain.createIdentityAndCertificate(identityName);
var data = new Data(new Name("/TestData/1"));
keyChain.signByIdentity(data, identityName);
var failureCount = 0;
var successCount = 0;
var vr = policyManager.checkVerificationPolicy(data, 0,
function() { ++successCount; }, function() { ++failureCount; });
assert.equal(vr, null, "SelfVerifyPolicyManager returned a ValidationRequest");
assert.equal
(failureCount, 0, "Verification of identity-signed data failed");
assert.equal
(successCount, 1,
"Verification success called " + successCount + " times instead of 1");
data = new Data(new Name("/TestData/2"));
failureCount = 0;
successCount = 0;
vr = policyManager.checkVerificationPolicy(data, 0,
function() { ++successCount; }, function() { ++failureCount; });
assert.equal(vr, null, "SelfVerifyPolicyManager returned a ValidationRequest");
assert.equal
(successCount, 0, "Verification of unsigned data succeeded");
assert.equal
(failureCount, 1,
"Verification failure callback called " + failureCount + " times instead of 1");
});
it("InterestTimestamp", function(done) {
var interestName = new Name("/ndn/ucla/edu/something");
var certName = identityManager_.getDefaultCertificateNameForIdentity(identityName_);
face_.setCommandSigningInfo(keyChain_, certName);
var oldInterest = new Interest(interestName);
face_.makeCommandInterest(oldInterest);
setTimeout(function() {
var newInterest = new Interest(interestName);
face_.makeCommandInterest(newInterest);
var failureCount = 0;
var successCount = 0;
var vr = policyManager_.checkVerificationPolicy(newInterest, 0,
function() { ++successCount; }, function() { ++failureCount; });
assert.equal
(vr, null, "ConfigPolicyManager returned ValidationRequest but certificate is known");
assert.equal
(failureCount, 0, "Verification of valid interest failed");
assert.equal
(successCount, 1,
"Verification success called " + successCount + " times instead of 1");
failureCount = 0;
successCount = 0;
vr = policyManager_.checkVerificationPolicy(oldInterest, 0,
function() { ++successCount; }, function() { ++failureCount; });
assert.equal
(vr, null, "ConfigPolicyManager returned ValidationRequest but certificate is known");
assert.equal
(successCount, 0, "Verification of stale interest succeeded");
assert.equal
(failureCount, 1,
"Verification failure callback called " + failureCount + " times instead of 1");
done();
}, 100);
});
it("Refresh10s", function(done) {
this.timeout(10000);
var encodedData;
encodedData = fs.readFileSync('policy_config/testData');
var decodedData = new Buffer(encodedData.toString(), 'base64');
var data = new Data();
data.wireDecode(new Blob(decodedData));
var failureCount = 0;
var successCount = 0;
var vr = policyManager_.checkVerificationPolicy(data, 0,
function() { ++successCount; }, function() { ++failureCount; });
assert.notEqual
(vr, null,
"ConfigPolicyManager did not create ValidationRequest for unknown certificate");
assert.equal
(successCount, 0,
"ConfigPolicyManager called success callback with pending ValidationRequest");
assert.equal
(failureCount, 0,
"ConfigPolicyManager called failure callback with pending ValidationRequest");
// Now save the cert data to our anchor directory, and wait.
// We have to sign it with the current identity or the policy manager will
// create an interest for the signing certificate.
var cert = new IdentityCertificate();
var certData = new Buffer(CERT_DUMP, 'base64');
cert.wireDecode(new Blob(certData));
keyChain_.signByIdentity(cert, identityName_);
var signedCertBlob = cert.wireEncode();
var encodedCert = signedCertBlob.buf().toString('base64');
fs.writeSync
(fs.openSync('policy_config/certs/testData.cert', 'w'), encodedCert);
failureCount = 0;
successCount = 0;
vr = policyManager_.checkVerificationPolicy(data, 0,
function() { ++successCount; }, function() { ++failureCount; });
assert.notEqual
(vr, null, "ConfigPolicyManager refresh occured sooner than specified");
assert.equal
(successCount, 0,
"ConfigPolicyManager called success callback with pending ValidationRequest");
assert.equal
(failureCount, 0,
"ConfigPolicyManager called failure callback with pending ValidationRequest");
setTimeout(function() {
failureCount = 0;
successCount = 0;
vr = policyManager_.checkVerificationPolicy(data, 0,
function() { ++successCount; }, function() { ++failureCount; });
assert.equal
(vr, null, "ConfigPolicyManager did not refresh certificate store");
assert.equal
(failureCount, 0, "ConfigPolicyManager did not verify valid signed data");
assert.equal
(successCount, 1,
"Verification success called " + successCount + " times instead of 1");
done();
}, 6000);
});
});