UNPKG

ndn-js

Version:

A JavaScript client library for Named Data Networking

604 lines (545 loc) 33.4 kB
/** * Copyright (C) 2014-2019 Regents of the University of California. * @author: Jeff Thompson <jefft0@remap.ucla.edu> * 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 Crypto = require("crypto"); var Data = require('../../..').Data; var Name = require('../../..').Name; var Blob = require('../../..').Blob; var Sha256WithRsaSignature = require('../../..').Sha256WithRsaSignature; var GenericSignature = require('../../..').GenericSignature; var ContentType = require('../../..').ContentType; var KeyType = require('../../..').KeyType; var KeyLocatorType = require('../../..').KeyLocatorType; var MemoryIdentityStorage = require('../../..').MemoryIdentityStorage; var MemoryPrivateKeyStorage = require('../../..').MemoryPrivateKeyStorage; var IdentityManager = require('../../..').IdentityManager; var SelfVerifyPolicyManager = require('../../..').SelfVerifyPolicyManager; var KeyChain = require('../../..').KeyChain; var TlvWireFormat = require('../../..').TlvWireFormat; var LpPacket = require('../../../js/lp/lp-packet.js').LpPacket; 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, 0xb8, 0x09, 0xa7, 0x59, 0x82, 0x84, 0xec,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, 0x3a, 0xff, 0x74, 0xfa, 0x32, 0x24, 0xe0, 0x11, 0x2b, 0x71, 0xad, 0x7e, 0x14, 0xa0, 0x77, 0x21, 0x68, 0x4f, 0xcc, 0xb6, 0x1b, 0xe8, 0x00, 0x49, 0x13, 0x21, 0x02, 0x81, 0x81, 0x00, 0xb6, 0x18, 0x73, 0x59, 0x2c, 0x4f, 0x92, 0xac, 0xa2, 0x2e, 0x5f, 0xb6, 0xbe, 0x78, 0x5d, 0x47, 0x71, 0x04, 0x92, 0xf0, 0xd7, 0xe8, 0xc5, 0x7a, 0x84, 0x6b, 0xb8, 0xb4, 0x30, 0x1f, 0xd8, 0x0d, 0x58, 0xd0, 0x64, 0x80, 0xa7, 0x21, 0x1a, 0x48, 0x00, 0x37, 0xd6, 0x19, 0x71, 0xbb, 0x91, 0x20, 0x9d, 0xe2, 0xc3, 0xec, 0xdb, 0x36, 0x1c, 0xca, 0x48, 0x7d, 0x03, 0x32, 0x74, 0x1e, 0x65, 0x73, 0x02, 0x90, 0x73, 0xd8, 0x3f, 0xb5, 0x52, 0x35, 0x79, 0x1c, 0xee, 0x93, 0xa3, 0x32, 0x8b, 0xed, 0x89, 0x98, 0xf1, 0x0c, 0xd8, 0x12, 0xf2, 0x89, 0x7f, 0x32, 0x23, 0xec, 0x67, 0x66, 0x52, 0x83, 0x89, 0x99, 0x5e, 0x42, 0x2b, 0x42, 0x4b, 0x84, 0x50, 0x1b, 0x3e, 0x47, 0x6d, 0x74, 0xfb, 0xd1, 0xa6, 0x10, 0x20, 0x6c, 0x6e, 0xbe, 0x44, 0x3f, 0xb9, 0xfe, 0xbc, 0x8d, 0xda, 0xcb, 0xea, 0x8f ]); var DEFAULT_EC_PUBLIC_KEY_DER = new Buffer([ 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x98, 0x9a, 0xf0, 0x61, 0x70, 0x43, 0x2e, 0xb6, 0x12, 0x92, 0xf5, 0x57, 0x08, 0x07, 0xe7, 0xaf, 0x23, 0xab, 0x79, 0x0b, 0x05, 0xaf, 0xa0, 0x3f, 0x8f, 0x23, 0x04, 0x50, 0xd2, 0x30, 0x47, 0x00, 0x1a, 0xff, 0x77, 0xba, 0x08, 0x5b, 0x9a, 0xb1, 0xe6, 0x1a, 0xc4, 0x6a, 0x38, 0x00, 0x79, 0x15, 0xf8, 0x92, 0x3d, 0x9d, 0x8e, 0x16, 0x29, 0x57, 0x34, 0x0b, 0xd4, 0x66, 0xb2, 0xe7, 0x54, 0x0b ]); // For OpenSSL, we use the inner PKCS #1 private key with full parameters. var DEFAULT_EC_PRIVATE_KEY_DER = new Buffer([ 0x30, 0x82, 0x01, 0x22, 0x02, 0x01, 0x01, 0x04, 0x20, 0x49, 0x35, 0xef, 0x6c, 0xbf, 0xca, 0x40, 0x55, 0xfc, 0x63, 0x61, 0x69, 0xa2, 0x8a, 0x5d, 0x1e, 0x48, 0x7b, 0x83, 0x44, 0xf4, 0x65, 0xd3, 0xe2, 0xab, 0x2b, 0xc0, 0xbc, 0x8d, 0x6f, 0x17, 0x1b, 0xa0, 0x81, 0xfa, 0x30, 0x81, 0xf7, 0x02, 0x01, 0x01, 0x30, 0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x30, 0x5b, 0x04, 0x20, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x04, 0x20, 0x5a, 0xc6, 0x35, 0xd8, 0xaa, 0x3a, 0x93, 0xe7, 0xb3, 0xeb, 0xbd, 0x55, 0x76, 0x98, 0x86, 0xbc, 0x65, 0x1d, 0x06, 0xb0, 0xcc, 0x53, 0xb0, 0xf6, 0x3b, 0xce, 0x3c, 0x3e, 0x27, 0xd2, 0x60, 0x4b, 0x03, 0x15, 0x00, 0xc4, 0x9d, 0x36, 0x08, 0x86, 0xe7, 0x04, 0x93, 0x6a, 0x66, 0x78, 0xe1, 0x13, 0x9d, 0x26, 0xb7, 0x81, 0x9f, 0x7e, 0x90, 0x04, 0x41, 0x04, 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96, 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbc, 0xe6, 0xfa, 0xad, 0xa7, 0x17, 0x9e, 0x84, 0xf3, 0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x51, 0x02, 0x01, 0x01 ]); var codedData = new Buffer([ 0x06, 0xCE, // NDN Data 0x07, 0x0A, 0x08, 0x03, 0x6E, 0x64, 0x6E, 0x08, 0x03, 0x61, 0x62, 0x63, // Name 0x14, 0x0A, // MetaInfo 0x19, 0x02, 0x13, 0x88, // FreshnessPeriod 0x1A, 0x04, // FinalBlockId 0x08, 0x02, 0x00, 0x09, // NameComponent 0x15, 0x08, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x21, // Content 0x16, 0x28, // SignatureInfo 0x1B, 0x01, 0x01, // SignatureType 0x1C, 0x23, // KeyLocator 0x07, 0x21, // Name 0x08, 0x08, 0x74, 0x65, 0x73, 0x74, 0x6E, 0x61, 0x6D, 0x65, 0x08, 0x03, 0x4B, 0x45, 0x59, 0x08, 0x07, 0x44, 0x53, 0x4B, 0x2D, 0x31, 0x32, 0x33, 0x08, 0x07, 0x49, 0x44, 0x2D, 0x43, 0x45, 0x52, 0x54, 0x17, 0x80, // SignatureValue 0x1A, 0x03, 0xC3, 0x9C, 0x4F, 0xC5, 0x5C, 0x36, 0xA2, 0xE7, 0x9C, 0xEE, 0x52, 0xFE, 0x45, 0xA7, 0xE1, 0x0C, 0xFB, 0x95, 0xAC, 0xB4, 0x9B, 0xCC, 0xB6, 0xA0, 0xC3, 0x4A, 0xAA, 0x45, 0xBF, 0xBF, 0xDF, 0x0B, 0x51, 0xD5, 0xA4, 0x8B, 0xF2, 0xAB, 0x45, 0x97, 0x1C, 0x24, 0xD8, 0xE2, 0xC2, 0x8A, 0x4D, 0x40, 0x12, 0xD7, 0x77, 0x01, 0xEB, 0x74, 0x35, 0xF1, 0x4D, 0xDD, 0xD0, 0xF3, 0xA6, 0x9A, 0xB7, 0xA4, 0xF1, 0x7F, 0xA7, 0x84, 0x34, 0xD7, 0x08, 0x25, 0x52, 0x80, 0x8B, 0x6C, 0x42, 0x93, 0x04, 0x1E, 0x07, 0x1F, 0x4F, 0x76, 0x43, 0x18, 0xF2, 0xF8, 0x51, 0x1A, 0x56, 0xAF, 0xE6, 0xA9, 0x31, 0xCB, 0x6C, 0x1C, 0x0A, 0xA4, 0x01, 0x10, 0xFC, 0xC8, 0x66, 0xCE, 0x2E, 0x9C, 0x0B, 0x2D, 0x7F, 0xB4, 0x64, 0xA0, 0xEE, 0x22, 0x82, 0xC8, 0x34, 0xF7, 0x9A, 0xF5, 0x51, 0x12, 0x2A, 0x84, 1 ]); var experimentalSignatureType = 100; var experimentalSignatureInfo = new Buffer([ 0x16, 0x08, // SignatureInfo 0x1B, 0x01, experimentalSignatureType, // SignatureType 0x81, 0x03, 1, 2, 3 // Experimental info ]); var experimentalSignatureInfoNoSignatureType = new Buffer([ 0x16, 0x05, // SignatureInfo 0x81, 0x03, 1, 2, 3 // Experimental info ]); var experimentalSignatureInfoBadTlv = new Buffer([ 0x16, 0x08, // SignatureInfo 0x1B, 0x01, experimentalSignatureType, // SignatureType 0x81, 0x10, 1, 2, 3 // Bad TLV encoding (length 0x10 doesn't match the value length. ]); var CONGESTION_MARK_PACKET = new Buffer([ 0x64, 0xfd, 0x03, 0x5f, // LpPacket 0xfd, 0x03, 0x40, 0x01, 0x01, // CongestionMark = 1 0x50, 0xfd, 0x03, 0x56, // Fragment 0x06, 0xfd, 0x03, 0x52, // NDN Data 0x07, 0x18, 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x09, 0xfd, 0x00, 0x00, 0x01, 0x62, 0xd5, 0x29, 0x3f, 0xa8, 0x08, 0x05, 0x00, 0x00, 0x01, 0x57, 0xc3, 0x14, 0x0d, 0x19, 0x02, 0x27, 0x10, 0x1a, 0x07, 0x08, 0x05, 0x00, 0x00, 0x02, 0xda, 0xcc, 0x15, 0xfd, 0x01, 0xf4, 0x65, 0x64, 0x20, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x20, 0x74, 0x6f, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x68, 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x73, 0x65, 0x72, 0x27, 0x73, 0x20, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x73, 0x75, 0x62, 0x74, 0x6c, 0x65, 0x2e, 0x0a, 0x2f, 0x2a, 0x2a, 0x20, 0x40, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x20, 0x2a, 0x2f, 0x0a, 0x76, 0x61, 0x72, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x73, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x73, 0x27, 0x29, 0x3b, 0x20, 0x2f, 0x2a, 0x2a, 0x20, 0x40, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x20, 0x2a, 0x2f, 0x0a, 0x76, 0x61, 0x72, 0x20, 0x43, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x2e, 0x2e, 0x2f, 0x2e, 0x2e, 0x2f, 0x63, 0x72, 0x79, 0x70, 0x74, 0x6f, 0x2e, 0x6a, 0x73, 0x27, 0x29, 0x3b, 0x20, 0x2f, 0x2a, 0x2a, 0x20, 0x40, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x20, 0x2a, 0x2f, 0x0a, 0x76, 0x61, 0x72, 0x20, 0x4b, 0x65, 0x79, 0x54, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x2e, 0x2e, 0x2f, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x73, 0x27, 0x29, 0x2e, 0x4b, 0x65, 0x79, 0x54, 0x79, 0x70, 0x65, 0x3b, 0x20, 0x2f, 0x2a, 0x2a, 0x20, 0x40, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x20, 0x2a, 0x2f, 0x0a, 0x76, 0x61, 0x72, 0x20, 0x45, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x2e, 0x2e, 0x2f, 0x2e, 0x2e, 0x2f, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x2f, 0x61, 0x6c, 0x67, 0x6f, 0x2f, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x2d, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x2e, 0x6a, 0x73, 0x27, 0x29, 0x2e, 0x45, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x3b, 0x20, 0x2f, 0x2a, 0x2a, 0x20, 0x40, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x20, 0x2a, 0x2f, 0x0a, 0x76, 0x61, 0x72, 0x20, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x2e, 0x2e, 0x2f, 0x73, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x6a, 0x73, 0x27, 0x29, 0x2e, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x3b, 0x20, 0x2f, 0x2a, 0x2a, 0x20, 0x40, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x65, 0x20, 0x2a, 0x2f, 0x0a, 0x76, 0x61, 0x72, 0x20, 0x44, 0x61, 0x74, 0x61, 0x55, 0x74, 0x69, 0x6c, 0x73, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x2e, 0x2e, 0x2f, 0x2e, 0x2e, 0x2f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x2f, 0x64, 0x61, 0x74, 0x61, 0x2d, 0x75, 0x74, 0x69, 0x6c, 0x73, 0x2e, 0x6a, 0x73, 0x27, 0x16, 0x2b, 0x1b, 0x01, 0x01, 0x1c, 0x26, 0x07, 0x24, 0x08, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74, 0x08, 0x08, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x08, 0x03, 0x4b, 0x45, 0x59, 0x08, 0x08, 0xfb, 0x5d, 0x48, 0xd6, 0xf6, 0x2a, 0x80, 0x4a, 0x17, 0xfd, 0x01, 0x00, 0x77, 0x1e, 0x6f, 0x13, 0x53, 0x08, 0x1b, 0xf6, 0x11, 0x2e, 0xaf, 0x82, 0x60, 0x86, 0xb7, 0x64, 0x42, 0xf5, 0xf5, 0x7e, 0x66, 0xf1, 0xb4, 0x22, 0x51, 0x52, 0xaf, 0x3c, 0x73, 0x87, 0xed, 0x73, 0xcf, 0xbf, 0x8b, 0x0c, 0x60, 0x61, 0xc7, 0x44, 0x5d, 0x4b, 0xb7, 0x2b, 0x13, 0x3b, 0xa9, 0xab, 0x1a, 0x35, 0x71, 0x8b, 0x68, 0xd1, 0xf6, 0xa1, 0x10, 0xdd, 0x85, 0x1f, 0x07, 0x56, 0x99, 0xcb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0x66, 0x05, 0x23, 0xa4, 0xda, 0x19, 0x85, 0xfd, 0xe1 ]); function dump(s1, s2) { var result = s1; if (s2) result += " " + s2; return result; } function dumpData(data) { var result = []; result.push(dump("name:", data.getName().toUri())); if (data.getContent().size() > 0) { result.push(dump("content (raw):", data.getContent().buf().toString('binary'))); result.push(dump("content (hex):", data.getContent().toHex())); } else result.push(dump("content: <empty>")); if (!(data.getMetaInfo().getType() == ContentType.BLOB)) { result.push(dump("metaInfo.type:", data.getMetaInfo().getType() == ContentType.LINK ? "LINK" : (data.getMetaInfo().getType() == ContentType.KEY ? "KEY" : "unknown"))); } result.push(dump("metaInfo.freshnessPeriod (milliseconds):", data.getMetaInfo().getFreshnessPeriod() >= 0 ? data.getMetaInfo().getFreshnessPeriod() : "<none>")); result.push(dump("metaInfo.finalBlockId:", data.getMetaInfo().getFinalBlockId().getValue().size() > 0 ? data.getMetaInfo().getFinalBlockId().toEscapedString() : "<none>")); var signature = data.getSignature(); if (signature instanceof Sha256WithRsaSignature) { result.push(dump("signature.signature:", signature.getSignature().size() == 0 ? "<none>" : signature.getSignature().toHex())); if (signature.getKeyLocator().getType() != null) { if (signature.getKeyLocator().getType() == KeyLocatorType.KEY_LOCATOR_DIGEST) result.push(dump("signature.keyLocator: KeyLocatorDigest:", signature.getKeyLocator().getKeyData().toHex())); else if (signature.getKeyLocator().getType() == KeyLocatorType.KEYNAME) result.push(dump("signature.keyLocator: KeyName:", signature.getKeyLocator().getKeyName().toUri())); else result.push(dump("signature.keyLocator: <unrecognized KeyLocatorType")); } else result.push(dump("signature.keyLocator: <none>")); } return result; } var initialDump = ['name: /ndn/abc', 'content (raw): SUCCESS!', 'content (hex): 5355434345535321', 'metaInfo.freshnessPeriod (milliseconds): 5000', 'metaInfo.finalBlockId: %00%09', 'signature.signature: 1a03c39c4fc55c36a2e79cee52fe45a7e10cfb95acb49bccb6a0c34aaa45bfbfdf0b51d5a48bf2ab45971c24d8e2c28a4d4012d77701eb7435f14dddd0f3a69ab7a4f17fa78434d7082552808b6c4293041e071f4f764318f2f8511a56afe6a931cb6c1c0aa40110fcc866ce2e9c0b2d7fb464a0ee2282c834f79af551122a84', 'signature.keyLocator: KeyName: /testname/KEY/DSK-123/ID-CERT']; /** * Return a copy of the strings array, removing any string that start with prefix. */ function removeStartingWith(strings, prefix) { var result = []; for (var i = 0; i < strings.length; ++i) { if (strings[i].substr(0, prefix.length) != prefix) result.push(strings[i]); } return result; } // ignoring signature, see if two data dumps are equal function dataDumpsEqual(d1, d2) { var prefix = "signature.signature:"; d1 = removeStartingWith(d1, prefix); d2 = removeStartingWith(d2, prefix); if (d1.length != d2.length) return false; for (var i = 0; i < d1.length; ++i) { if (d1[i] != d2[i]) return false; } return true; } var CredentialStorage = function CredentialStorage() { this.identityStorage = new MemoryIdentityStorage(); this.privateKeyStorage = new MemoryPrivateKeyStorage(); this.keyChain = new KeyChain (new IdentityManager(this.identityStorage, this.privateKeyStorage), new SelfVerifyPolicyManager(this.identityStorage)); var keyName = new Name("/testname/DSK-123"); this.defaultCertName = keyName.getSubName(0, keyName.size() - 1).append ("KEY").append(keyName.get(-1)).append("ID-CERT").append("0"); var ecdsaKeyName = new Name("/testEcdsa/DSK-123"); this.ecdsaCertName = ecdsaKeyName.getSubName(0, ecdsaKeyName.size() - 1).append ("KEY").append(ecdsaKeyName.get(-1)).append("ID-CERT").append("0"); this.identityStorage.addKey (keyName, KeyType.RSA, new Blob(DEFAULT_RSA_PUBLIC_KEY_DER, false)); this.privateKeyStorage.setKeyPairForKeyName (keyName, KeyType.RSA, DEFAULT_RSA_PUBLIC_KEY_DER, DEFAULT_RSA_PRIVATE_KEY_DER); this.identityStorage.addKey (ecdsaKeyName, KeyType.EC, new Blob(DEFAULT_EC_PUBLIC_KEY_DER, false)); this.privateKeyStorage.setKeyPairForKeyName (ecdsaKeyName, KeyType.EC, DEFAULT_EC_PUBLIC_KEY_DER, DEFAULT_EC_PRIVATE_KEY_DER); }; CredentialStorage.prototype.signData = function(data, certificateName) { if (!certificateName) certificateName = this.defaultCertName; this.keyChain.sign(data, certificateName); }; CredentialStorage.prototype.signDataWithSha256 = function(data) { this.keyChain.signWithSha256(data); }; CredentialStorage.prototype.verifyData = function (data, verifiedCallback, failedCallback) { this.keyChain.verifyData(data, verifiedCallback, failedCallback); }; function createFreshData() { var freshData = new Data(new Name("/ndn/abc")); freshData.setContent(new Blob("SUCCESS!")); freshData.getMetaInfo().setFreshnessPeriod(5000); freshData.getMetaInfo().setFinalBlockId(new Name("/%00%09").get(0)); return freshData; } var credentials; var freshData; describe('TestDataMethods', function() { beforeEach(function() { credentials = new CredentialStorage(); freshData = createFreshData(); }); it('Dump', function() { var data = new Data(); data.wireDecode(new Blob(codedData, false)); assert.deepEqual(dumpData(data), initialDump, 'Initial dump does not have expected format'); }); it('EncodeDecode', function() { var data = new Data(); data.wireDecode(new Blob(codedData, false)); // Set the content again to clear the cached encoding so we encode again. data.setContent(data.getContent()); var encoding = data.wireEncode(); var reDecodedData = new Data(); reDecodedData.wireDecode(encoding); assert.deepEqual(dumpData(reDecodedData), initialDump, 'Re-decoded data does not match original dump'); }); it('EmptySignature', function() { // make sure nothing is set in the signature of newly created data var data = new Data(); var signature = data.getSignature(); assert.equal(signature.getKeyLocator().getType(), null, 'Key locator type on unsigned data should not be set'); assert.ok(signature.getSignature().isNull(), 'Non-empty signature on unsigned data'); }); it('CopyFields', function() { var data = new Data(freshData.getName()); data.setContent(freshData.getContent()); data.setMetaInfo(freshData.getMetaInfo()); credentials.signData(data); var freshDump = dumpData(data); assert.ok(dataDumpsEqual(freshDump, initialDump), 'Freshly created data does not match original dump'); }); it('Verify', function() { // We create simple callbacks to count calls since we're not interested in // the effect of the callbacks themselves. var failedCallCount = 0; var verifiedCallCount = 0; credentials.signData(freshData); credentials.verifyData (freshData, function() { ++verifiedCallCount; }, function() { ++failedCallCount; }); assert.equal(failedCallCount, 0, 'Signature verification failed'); assert.equal(verifiedCallCount, 1, 'Verification callback was not used.'); }); it('VerifyEcdsa', function() { // We create simple callbacks to count calls since we're not interested in // the effect of the callbacks themselves. var failedCallCount = 0; var verifiedCallCount = 0; credentials.signData(freshData, credentials.ecdsaCertName); credentials.verifyData (freshData, function() { ++verifiedCallCount; }, function() { ++failedCallCount; }); assert.equal(failedCallCount, 0, 'Signature verification failed'); assert.equal(verifiedCallCount, 1, 'Verification callback was not used.'); }); it('VerifyDigestSha256', function() { // We create simple callbacks to count calls since we're not interested in // the effect of the callbacks themselves. var failedCallCount = 0; var verifiedCallCount = 0; credentials.signDataWithSha256(freshData); credentials.verifyData (freshData, function() { ++verifiedCallCount; }, function() { ++failedCallCount; }); assert.equal(failedCallCount, 0, 'Signature verification failed'); assert.equal(verifiedCallCount, 1, 'Verification callback was not used.'); }); it('GenericSignature', function() { // Test correct encoding. var signature = new GenericSignature(); signature.setSignatureInfoEncoding (new Blob(experimentalSignatureInfo, false), null); var signatureValue = new Blob([1, 2, 3, 4], false); signature.setSignature(signatureValue); freshData.setSignature(signature); var encoding = freshData.wireEncode(); var decodedData = new Data(); decodedData.wireDecode(encoding); var decodedSignature = decodedData.getSignature(); assert.equal(decodedSignature.getTypeCode(), experimentalSignatureType); assert.ok(new Blob(experimentalSignatureInfo, false).equals (decodedSignature.getSignatureInfoEncoding())); assert.ok(signatureValue.equals(decodedSignature.getSignature())); // Test bad encoding. signature = new GenericSignature(); signature.setSignatureInfoEncoding (new Blob(experimentalSignatureInfoNoSignatureType, false), null); signature.setSignature(signatureValue); freshData.setSignature(signature); var gotError = true; try { freshData.wireEncode(); gotError = false; } catch (ex) {} if (!gotError) assert.fail('', '', "Expected encoding error for experimentalSignatureInfoNoSignatureType"); signature = new GenericSignature(); signature.setSignatureInfoEncoding (new Blob(experimentalSignatureInfoBadTlv, false), null); signature.setSignature(signatureValue); freshData.setSignature(signature); gotError = true; try { freshData.wireEncode(); gotError = false; } catch (ex) {} if (!gotError) assert.fail('', '', "Expected encoding error for experimentalSignatureInfoBadTlv"); }); it('FullName', function() { var data = new Data(); data.wireDecode(codedData); // Check the full name format. assert.equal(data.getFullName().size(), data.getName().size() + 1); assert.ok(data.getName().equals(data.getFullName().getPrefix(-1))); assert.equal(data.getFullName().get(-1).getValue().size(), 32); // Check the independent digest calculation. var hash = Crypto.createHash('sha256'); hash.update(codedData); var newDigest = new Blob(hash.digest(), false); assert.ok(newDigest.equals(data.getFullName().get(-1).getValue())); // Check the expected URI. assert.equal (data.getFullName().toUri(), "/ndn/abc/sha256digest=" + "96556d685dcb1af04be4ae57f0e7223457d4055ea9b3d07c0d337bef4a8b3ee9"); // Changing the Data packet should change the full name. var saveFullName = new Name(data.getFullName()); data.setContent(new Blob()); assert.ok(!data.getFullName().get(-1).equals(saveFullName.get(-1))); }); it('CongestionMark', function() { // Imitate onReceivedElement. var lpPacket = new LpPacket(); // Set copy false so that the fragment is a slice which will be copied below. // The header fields are all integers and don't need to be copied. TlvWireFormat.get().decodeLpPacket(lpPacket, CONGESTION_MARK_PACKET, false); var element = lpPacket.getFragmentWireEncoding().buf(); var data = new Data(); data.wireDecode(element, TlvWireFormat.get()); data.setLpPacket(lpPacket); assert.equal(1, data.getCongestionMark()); }); });