├── .travis.d ├── .gitignore ├── id-rsa.enc └── id-rsa.pub ├── ndnProtocol.xpi ├── js ├── browserify-header.js ├── use-subtle-crypto-node.js ├── browserify-footer.js ├── crypto.js ├── browserify-stacktrace.js ├── browserify-tcp-transport.js ├── log.js ├── browserify-require.js ├── encoding │ ├── decoding-exception.js │ ├── der │ │ ├── der-decoding-exception.js │ │ ├── der-encoding-exception.js │ │ └── der-node-type.js │ ├── tlv-0_1_1-wire-format.js │ ├── tlv-0_1-wire-format.js │ ├── oid.js │ └── tlv-wire-format.js ├── security │ ├── key-id-type.js │ ├── validator-config-error.js │ ├── security-types.js │ ├── validator-null.js │ ├── v2 │ │ ├── certificate-container-interface.js │ │ ├── validation-policy-accept-all.js │ │ ├── certificate-fetcher-offline.js │ │ ├── certificate-request.js │ │ ├── validation-policy-simple-hierarchy.js │ │ ├── static-trust-anchor-group.js │ │ └── trust-anchor-group.js │ ├── policy │ │ ├── validation-request.js │ │ └── certificate-cache.js │ ├── certificate │ │ ├── certificate-subject-description.js │ │ └── certificate-extension.js │ └── security-exception.js ├── forwarding-flags.js ├── util │ ├── regex │ │ ├── ndn-regex-backref-manager.js │ │ ├── ndn-regex-pseudo-matcher.js │ │ └── ndn-regex-backref-matcher.js │ ├── ndn-common.js │ └── change-counter.js ├── encrypt │ ├── decrypt-key.js │ ├── encrypt-key.js │ └── encrypt-error.js ├── transport │ └── transport.js ├── lp │ ├── congestion-mark.js │ ├── incoming-face-id.js │ └── lp-packet.js ├── in-memory-storage │ └── in-memory-storage-retaining.js └── use-subtle-crypto.js ├── doc ├── .gitignore └── conf.json ├── waf ├── ndn-protocol.xpi ├── ndn-protocol ├── make-ndn-protocol.sh ├── modules │ ├── make-ndn-js.jsm.sh │ └── ndn-js-header.txt ├── chrome.manifest ├── install.rdf └── content │ ├── toolbar.xul │ └── ndn-toolbar.js ├── tools └── micro-forwarder │ ├── extension.crx │ ├── ndn-micro-forwarder.xpi │ ├── extension │ ├── icons │ │ ├── N-48.png │ │ ├── link-48.png │ │ ├── micro-forwarder.png │ │ └── named-data-network.png │ ├── popup │ │ ├── choose_option.css │ │ ├── choose_option.js │ │ └── choose_option.html │ ├── content.js │ ├── manifest.json │ └── config.html │ ├── make-ndn-micro-forwarder.sh │ ├── ndn_multicast.json │ └── INSTALL.md ├── wsproxy └── README.md ├── NOTICES ├── tests └── node │ ├── integration-tests │ ├── policy_config │ │ ├── hierarchical_ruleset.conf │ │ ├── testData │ │ ├── relation_ruleset_prefix.conf │ │ ├── relation_ruleset_equal.conf │ │ ├── relation_ruleset_strict.conf │ │ ├── certs │ │ │ ├── anchor.cert │ │ │ └── anchor.cert-v2 │ │ ├── simple_rules.conf │ │ ├── regex_ruleset.conf │ │ ├── testKey.pri │ │ └── hyperrelation_ruleset.conf │ ├── test-validator-null.js │ └── hierarchical-validator-fixture.js │ └── unit-tests │ ├── test-control-response.js │ ├── test-control-parameters-encode-decode.js │ └── unit-tests-common.js ├── examples ├── browser │ ├── channel-status.proto │ ├── fib-entry.proto │ ├── rib-entry.proto │ ├── repo-ng │ │ ├── repo-command-response.proto │ │ └── repo-command-parameter.proto │ ├── face-query-filter.proto │ ├── face-status.proto │ ├── test-path.html │ ├── control-parameters.proto │ ├── test-interest-matches-name.html │ ├── test-websocket.html │ ├── test-throughput-http.html │ ├── test-get-async.html │ ├── noconflict.html │ └── test-echo-consumer.html ├── node │ ├── test │ ├── fetch.js │ ├── test-echo-consumer.js │ ├── test-get-async.js │ ├── test-encode-decode-fib-entry.js │ ├── test-chrono-chat-protobuf.js │ ├── test-encode-decode-benchmark.js │ ├── test-pipeline.js │ └── test-list-channels.js ├── ndnping │ ├── ndn-ping.html │ └── ndn-ping.js └── firefly │ └── firefly-chat │ └── chatbuf.js ├── .gitignore ├── .travis.yml ├── package.json ├── contrib ├── securityLib │ ├── CryptoJS-LICENSE.txt │ ├── jsrsasign-LICENSE.txt │ ├── prng4.js │ ├── base64.js │ └── rng.js ├── feross │ ├── LICENSE │ └── ieee754.js └── stacktrace │ └── LICENSE └── INSTALL /.travis.d/.gitignore: -------------------------------------------------------------------------------- 1 | id-rsa 2 | -------------------------------------------------------------------------------- /ndnProtocol.xpi: -------------------------------------------------------------------------------- 1 | ndn-protocol.xpi -------------------------------------------------------------------------------- /js/browserify-header.js: -------------------------------------------------------------------------------- 1 | (function(globals){ 2 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | !conf.json 4 | -------------------------------------------------------------------------------- /waf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-js/HEAD/waf -------------------------------------------------------------------------------- /js/use-subtle-crypto-node.js: -------------------------------------------------------------------------------- 1 | exports.UseSubtleCrypto = function(){return false;}; 2 | -------------------------------------------------------------------------------- /ndn-protocol.xpi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-js/HEAD/ndn-protocol.xpi -------------------------------------------------------------------------------- /.travis.d/id-rsa.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-js/HEAD/.travis.d/id-rsa.enc -------------------------------------------------------------------------------- /ndn-protocol/make-ndn-protocol.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd modules; ./make-ndn-js.jsm.sh; cd .. ; zip -r ../ndn-protocol.xpi . 3 | -------------------------------------------------------------------------------- /tools/micro-forwarder/extension.crx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-js/HEAD/tools/micro-forwarder/extension.crx -------------------------------------------------------------------------------- /tools/micro-forwarder/ndn-micro-forwarder.xpi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-js/HEAD/tools/micro-forwarder/ndn-micro-forwarder.xpi -------------------------------------------------------------------------------- /tools/micro-forwarder/extension/icons/N-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-js/HEAD/tools/micro-forwarder/extension/icons/N-48.png -------------------------------------------------------------------------------- /tools/micro-forwarder/extension/icons/link-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-js/HEAD/tools/micro-forwarder/extension/icons/link-48.png -------------------------------------------------------------------------------- /tools/micro-forwarder/make-ndn-micro-forwarder.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cp ../../build/ndn.js extension 3 | cd extension; zip -r ../ndn-micro-forwarder.xpi . ; cd .. 4 | -------------------------------------------------------------------------------- /tools/micro-forwarder/extension/icons/micro-forwarder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-js/HEAD/tools/micro-forwarder/extension/icons/micro-forwarder.png -------------------------------------------------------------------------------- /tools/micro-forwarder/extension/icons/named-data-network.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/named-data/ndn-js/HEAD/tools/micro-forwarder/extension/icons/named-data-network.png -------------------------------------------------------------------------------- /ndn-protocol/modules/make-ndn-js.jsm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cat ndn-js-header.txt ../../build/ndn.min.js ../../js/transport/xpcom-transport.js ../../js/encoding/mime-types.js > ndn-js.jsm 3 | -------------------------------------------------------------------------------- /doc/conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "source": { 3 | "include": ["js", "README.md"], 4 | "exclude": ["js/browserify-header.js", "js/browserify-footer.js"] 5 | }, 6 | "opts": { 7 | "destination": "doc", 8 | "recurse": true 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tools/micro-forwarder/extension/popup/choose_option.css: -------------------------------------------------------------------------------- 1 | # html, body { 2 | # width: 100px; 3 | # height: 100px; 4 | # } 5 | 6 | .options { 7 | margin: 3% auto; 8 | padding: 4px; 9 | text-align: center; 10 | font-size: 1.0em; 11 | # background-color: #E5F2F2; 12 | cursor: pointer; 13 | } -------------------------------------------------------------------------------- /tools/micro-forwarder/ndn_multicast.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ndn_multicast", 3 | "description": "Receive and multicast on the NDN multicast address", 4 | "path": "ndn-js/tools/micro-forwarder/ndn_multicast.py", 5 | "type": "stdio", 6 | "allowed_extensions": [ "micro-forwarder@named-data.net" ] 7 | } 8 | -------------------------------------------------------------------------------- /wsproxy/README.md: -------------------------------------------------------------------------------- 1 | wsproxy 2 | ======= 3 | 4 | wsproxy was a program that provides a proxy server between NDN JavaScript stack and NDN forwarder. 5 | This program is no longer necessary because [NDN Forwarding Daemon (NFD)](https://github.com/named-data/NFD/) has built-in WebSockets support that is enabled by default. 6 | -------------------------------------------------------------------------------- /ndn-protocol/chrome.manifest: -------------------------------------------------------------------------------- 1 | component {8122e660-1012-11e2-892e-0800200c9a66} components/ndn-protocol-service.js 2 | contract @mozilla.org/network/protocol;1?name=ndn {8122e660-1012-11e2-892e-0800200c9a66} 3 | content modules modules/ 4 | content toolbar content/ 5 | overlay chrome://browser/content/browser.xul chrome://toolbar/content/toolbar.xul 6 | -------------------------------------------------------------------------------- /NOTICES: -------------------------------------------------------------------------------- 1 | See the following licenses for third-party software included in this distribution: 2 | 3 | contrib/dcodeio/LICENSE 4 | contrib/dexie/LICENSE 5 | contrib/feross/LICENSE 6 | contrib/securityLib/CryptoJS-LICENSE.txt 7 | contrib/securityLib/jsrsasig-THIRDPARTY_LICENSE.txt 8 | contrib/securityLib/jsrsasign-LICENSE.txt 9 | contrib/stacktrace/LICENSE 10 | -------------------------------------------------------------------------------- /tests/node/integration-tests/policy_config/hierarchical_ruleset.conf: -------------------------------------------------------------------------------- 1 | validator 2 | { 3 | rule 4 | { 5 | id "Another Rule" 6 | for data 7 | filter 8 | { 9 | type name 10 | regex "^" 11 | } 12 | checker 13 | { 14 | type hierarchical 15 | sig-type rsa-sha256 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tools/micro-forwarder/extension/popup/choose_option.js: -------------------------------------------------------------------------------- 1 | function showConfig() { 2 | chrome.tabs.create({ 3 | url: chrome.extension.getURL("config.html") 4 | }); 5 | } 6 | 7 | document.addEventListener("DOMContentLoaded", function() { 8 | var btn = document.getElementById("showConfig"); 9 | btn.addEventListener("click", function() { 10 | showConfig(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /.travis.d/id-rsa.pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCghPR0z4LB+TdSDYvdIiPbcRc9vmTaQpG/KR2XfHwZm4unGSB742q7A9LlFvk4nwfNDQuK22YUB77gNxBQRi1nTB+q+AZ4XzFZ3u/8+8al7wTvZZrL2spDzjkcidfuqcBSwluSzyohk4TGzic1Hx/GFV8qg7+TJUWG5xAkC460YG3QcGagbI9av5L+NeQjtiabO7HlYP8K+ayXTGpiFaJ00jGoOdIAJIIKtlJ9Yb7Gn8vSPPq/XD07GbqalK8wwfbF60Bpmh8G1+miXUFAZyh5b1PA4xisEaMLxuCRGHJUq04uT5GIu/KHbU6J9eqaMIOZtITtz4BuNi0lrUObJUxb cawka@cawkaMac.local 2 | -------------------------------------------------------------------------------- /tools/micro-forwarder/extension/popup/choose_option.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/node/integration-tests/policy_config/testData: -------------------------------------------------------------------------------- 1 | Bv0BXAcMCAR0ZW1wCAR0ZXN0FAAVFlRoaXMgaXMgc29tZSB0ZXN0IGRhdGEWLhsBARwpBycIBHRlbXAIA0tFWQgRa3NrLTE0MTQxOTU3Nzk2NjUIB0lELUNFUlQX/QEAGb5kqcevg7m3tABnZcKeWC0CZZZVt+fHN0F/Xe6lOq080dnT8j1jAyUHktZ9nH/5LgzYBNW04xOFFf9FXwbO3QLmfZ3iKnzbnHhyxm9baeTaFun6cQM/1cAXO0nS5tvNBsZRdACWQYTQCIX7SKKp3dCHLC/2vS+vVpTXFpL789pe+iuOaRmvTrBiHcEOGFYwDISvXkNxkN8Bx7sG9voThqCb3jixTATBf55/I+16O7M0BYYCvqhJCLdMJKdKsEKwGcoAaz/KyLvx8wJthM245GawkJ0yCWhu/SxHwBqafs2JPp7HXIJpZnCeM4+zIUmb3T68DkBKcOLsL6XTP6QEuA== -------------------------------------------------------------------------------- /examples/browser/channel-status.proto: -------------------------------------------------------------------------------- 1 | // Load this file using: 2 | // var builder = ProtoBuf.loadProtoFile("channel-status.proto"); 3 | 4 | package ndn_message; 5 | 6 | // Protobuf has no "outer" message type, so we need to put the TLV ChannelStatus 7 | // message inside an outer "typeless" ChannelStatusMessage. 8 | message ChannelStatusMessage { 9 | message ChannelStatus { 10 | required string local_uri = 129; 11 | } 12 | 13 | // A ChannelStatusMessage has repeated ChannelStatus. 14 | repeated ChannelStatus channel_status = 130; 15 | } 16 | -------------------------------------------------------------------------------- /tests/node/integration-tests/policy_config/relation_ruleset_prefix.conf: -------------------------------------------------------------------------------- 1 | validator 2 | { 3 | rule 4 | { 5 | id "A rule" 6 | for data 7 | filter 8 | { 9 | type name 10 | name /TestRule1/ 11 | relation is-prefix-of 12 | } 13 | checker 14 | { 15 | type customized 16 | sig-type rsa-sha256 17 | key-locator 18 | { 19 | type name 20 | name /SecurityTestSecRule 21 | relation is-prefix-of 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/node/integration-tests/policy_config/relation_ruleset_equal.conf: -------------------------------------------------------------------------------- 1 | validator 2 | { 3 | rule 4 | { 5 | id "A very strict rule" 6 | for data 7 | filter 8 | { 9 | type name 10 | name /TestRule1/ 11 | relation equal 12 | } 13 | checker 14 | { 15 | type customized 16 | sig-type rsa-sha256 17 | key-locator 18 | { 19 | type name 20 | name /SecurityTestSecRule 21 | relation is-prefix-of 22 | } 23 | } 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /tests/node/integration-tests/policy_config/relation_ruleset_strict.conf: -------------------------------------------------------------------------------- 1 | validator 2 | { 3 | rule 4 | { 5 | id "A strict rule" 6 | for data 7 | filter 8 | { 9 | type name 10 | name /TestRule1/ 11 | relation is-strict-prefix-of 12 | } 13 | checker 14 | { 15 | type customized 16 | sig-type rsa-sha256 17 | key-locator 18 | { 19 | type name 20 | name /SecurityTestSecRule 21 | relation is-prefix-of 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .waf* 2 | .lock* 3 | /tools/yui*.jar 4 | /tools/compiler*.jar 5 | /build/c4che 6 | /build/*.zip 7 | /build/*.log 8 | ndn-protocol/modules/ndn-js.jsm 9 | tools/micro-forwarder/extension/ndn.js 10 | 11 | # Mac OSX 12 | .DS_Store 13 | 14 | # Emacs temp files 15 | *~ 16 | 17 | # Downloaded protobuf/jsrsasign files 18 | js/sync/node_modules/ 19 | js/sync/Protobuf/ 20 | js/sync/jsrsasign/ 21 | 22 | # NPM file 23 | npm-debug.log 24 | 25 | # Temporary test files 26 | js/sync/hash-test.js 27 | tests/node/integration-tests/policy_config/ndnsec-key-file 28 | 29 | # Ignore installed dependencies 30 | node_modules 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | node_js: 4 | - "8" 5 | script: 6 | - npm run doc 7 | deploy: 8 | provider: script 9 | script: 10 | - ssh-keyscan -H $HOSTNAME 2>&1 | tee -a $HOME/.ssh/known_hosts 11 | - openssl aes-256-cbc -K $encrypted_2891f088a2e3_key -iv $encrypted_2891f088a2e3_iv -in .travis.d/id-rsa.enc -out .travis.d/id-rsa -d 12 | - mkdir -p ~/.ssh && mv .travis.d/id-rsa ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa 13 | - rsync -arv --delete --progress doc/ $USERNAME@$HOSTNAME:/var/www/named-data.net/www/doc/ndn-ccl/latest/NDN-JS 14 | # TODO: sync tagged versions 15 | on: 16 | branch: master 17 | -------------------------------------------------------------------------------- /examples/browser/fib-entry.proto: -------------------------------------------------------------------------------- 1 | // Load this file using: 2 | // var builder = ProtoBuf.loadProtoFile("fib-entry.proto"); 3 | 4 | package ndn_message; 5 | 6 | // Protobuf has no "outer" message type, so we need to put the TLV FibEntry 7 | // message inside an outer "typeless" FibEntryMessage. 8 | message FibEntryMessage { 9 | message Name { 10 | repeated bytes component = 8; 11 | } 12 | 13 | message NextHopRecord { 14 | required uint32 face_id = 105; 15 | required uint32 cost = 106; 16 | } 17 | 18 | message FibEntry { 19 | required Name name = 7; 20 | repeated NextHopRecord next_hop_records = 129; 21 | } 22 | 23 | // A FibEntryMessage has one FibEntry. 24 | required FibEntry fib_entry = 128; 25 | } 26 | -------------------------------------------------------------------------------- /examples/browser/rib-entry.proto: -------------------------------------------------------------------------------- 1 | // Load this file using: 2 | // var builder = ProtoBuf.loadProtoFile("rib-entry.proto"); 3 | 4 | package ndn_message; 5 | 6 | // Protobuf has no "outer" message type, so we need to put the TLV RibEntry 7 | // message inside an outer "typeless" RibEntryMessage. 8 | message RibEntryMessage { 9 | message Name { 10 | repeated bytes component = 8; 11 | } 12 | 13 | message Route { 14 | required uint32 face_id = 105; 15 | required uint32 origin = 111; 16 | required uint32 cost = 106; 17 | required uint32 flags = 108; 18 | optional uint32 expiration_period = 109; 19 | } 20 | 21 | message RibEntry { 22 | required Name name = 7; 23 | repeated Route routes = 129; 24 | } 25 | 26 | // A RibEntryMessage has repeated RibEntry. 27 | repeated RibEntry rib_entry = 128; 28 | } 29 | -------------------------------------------------------------------------------- /tools/micro-forwarder/extension/content.js: -------------------------------------------------------------------------------- 1 | var port = null; 2 | 3 | // Add listener to wait for msg from app scripts 4 | window.addEventListener("message", function(event) { 5 | // We only accept messages from ourselves 6 | if (event.source != window) 7 | return; 8 | 9 | if (event.data.type && (event.data.type == "FromMicroForwarderTransport")) { 10 | if (port == null) { 11 | port = chrome.runtime.connect(); 12 | // Add a listener to wait for msg from background script 13 | port.onMessage.addListener(function(msg) { 14 | window.postMessage({ 15 | type: "FromMicroForwarderStub", 16 | object: msg 17 | }, "*"); 18 | }); 19 | console.log("Forwarder stub connected to background script."); 20 | } 21 | port.postMessage(event.data.object); 22 | } 23 | }, false); 24 | 25 | console.log("NDN Micro Forwarder stub is loaded."); 26 | -------------------------------------------------------------------------------- /js/browserify-footer.js: -------------------------------------------------------------------------------- 1 | var _savedGlobals = {}; 2 | Object.keys(ndn).forEach(function(k){ 3 | _savedGlobals[k] = globals[k]; 4 | globals[k] = ndn[k]; 5 | }); 6 | 7 | /** 8 | * Stop exposing ndn-js class names in the global namespace. 9 | * 10 | * By default, ndn-js exposes all class names into the global namespace for convenience. 11 | * This function removes ndn-js class names from the global namespace to avoid conflicts. 12 | * After that, the application must explicitly reference `ndn.` before a class name. 13 | */ 14 | ndn.noConflict = function() { 15 | Object.keys(_savedGlobals).forEach(function(k){ 16 | if (globals[k] === ndn[k]) { 17 | if (typeof _savedGlobals[k] == 'undefined') { 18 | delete globals[k]; 19 | } 20 | else { 21 | globals[k] = _savedGlobals[k]; 22 | } 23 | } 24 | }); 25 | return ndn; 26 | }; 27 | 28 | globals.ndn = ndn; 29 | })(this); 30 | -------------------------------------------------------------------------------- /tools/micro-forwarder/extension/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 2, 3 | "name": "NDN Micro Forwarder", 4 | "description": "NDN Micro Forwarder in the browser!", 5 | "version": "1.1", 6 | "icons": { 7 | "48": "icons/N-48.png" 8 | }, 9 | 10 | "applications": { 11 | "gecko": { 12 | "id": "micro-forwarder@named-data.net", 13 | "strict_min_version": "45.0" 14 | } 15 | }, 16 | 17 | "permissions": ["tabs", "notifications", "nativeMessaging"], 18 | 19 | "background": { 20 | "scripts": ["ndn.js", "bg.js"] 21 | }, 22 | 23 | "browser_action": { 24 | "default_icon": "icons/N-48.png", 25 | "default_title": "MicroForwarder", 26 | "default_popup": "popup/choose_option.html" 27 | }, 28 | 29 | "content_scripts": [ 30 | { 31 | "matches": [""], 32 | "js": ["content.js"] 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /examples/browser/repo-ng/repo-command-response.proto: -------------------------------------------------------------------------------- 1 | // This is the Protobuf definition for RepoCommandResponse, described at: 2 | // http://redmine.named-data.net/projects/repo-ng/wiki/Repo_Command 3 | // Load this file using: 4 | // var builder = ProtoBuf.loadProtoFile("repo-command-response.proto"); 5 | 6 | package ndn_message; 7 | 8 | // Protobuf has no "outer" message type, so we need to put the TLV RepoCommandResponse 9 | // message inside an outer "typeless" RepoCommandResponseMessage. 10 | message RepoCommandResponseMessage { 11 | message RepoCommandResponse { 12 | optional uint64 process_id = 206; 13 | required uint64 status_code = 208; 14 | optional uint64 start_block_id = 204; 15 | optional uint64 end_block_id = 205; 16 | optional uint64 insert_num = 209; 17 | optional uint64 delete_num = 210; 18 | } 19 | 20 | // A RepoCommandResponseMessage has one RepoCommandResponse. 21 | required RepoCommandResponse repo_command_response = 207; 22 | } 23 | -------------------------------------------------------------------------------- /ndn-protocol/install.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {8122e660-1012-11e2-892e-0800200c9a66} 5 | 2 6 | ndn protocol 7 | 0.2 8 | Jeff Thompson 9 | 10 | 11 | {ec8030f7-c20a-464f-9b0e-13a3a9e97384} 12 | 3.5 13 | 4.0.* 14 | 15 | 16 | 17 | 18 | {aa3c5121-dab2-40e2-81ca-7ea25febc110} 19 | 15.0 20 | 18.* 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /js/crypto.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Ryan Bennett 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | //wrap a require call to crypto to that we can redirect calls to this file to browserify.js when being built for the browser 21 | 22 | module.exports = require('crypto') 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ndn-js", 3 | "version": "0.20.0", 4 | "description": "A JavaScript client library for Named Data Networking", 5 | "main": "index.js", 6 | "directories": { 7 | "example": "examples", 8 | "test": "tests" 9 | }, 10 | "scripts": { 11 | "doc": "jsdoc -c doc/conf.json", 12 | "test": "cd tests/node/unit-tests ; mocha . --timeout 10000 ; cd ../../.." 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/named-data/ndn-js" 17 | }, 18 | "keywords": [ 19 | "NDN" 20 | ], 21 | "browser": { 22 | "./js/crypto.js": "./js/browserify.js", 23 | "./js/use-subtle-crypto-node.js": "./js/use-subtle-crypto.js", 24 | "./js/transport/tcp-transport.js": "./js/browserify-tcp-transport.js" 25 | }, 26 | "author": "UCLA", 27 | "license": "LGPL-3.0+", 28 | "bugs": { 29 | "url": "https://github.com/named-data/ndn-js/issues" 30 | }, 31 | "dependencies": { 32 | "jsbn": "*", 33 | "protobufjs": "*" 34 | }, 35 | "devDependencies": { 36 | "jsdoc": "*", 37 | "mocha": "*" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/node/integration-tests/policy_config/certs/anchor.cert: -------------------------------------------------------------------------------- 1 | Bv0DIQdHCBdUZXN0Q29uZmlnUG9saWN5TWFuYWdlcggEdGVtcAgDS0VZCA5rc2stMTQxNjAxMDEyMwgHSUQtQ0VSVAgIAAABSbDXRm8UAxgBAhX9AYUwggGBMCIYDzIwMTQxMTE1MDAyNTM4WhgPMjAxNDEyMTUwMDI1MzhaMDUwMwYDVQQpEywvVGVzdENvbmZpZ1BvbGljeU1hbmFnZXIvdGVtcC9rc2stMTQxNjAxMDEyMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANRP2a560oeAZxExuFusi1/yISgscOxm6RjuXvHj7wnLXuDN5DlqP0MqPhoG8sywD1vYoT8cuPqMpL+gV2HLNakPVnZXBaRWkGQ9Dm4kQ15UAplbvgWryfu3jxfLWcBCR3mxuFyX76tlIYi9WD6ajneEbD0acXq1m8Te5SQYYmFYQBRlbY+kgj6+6Xr6VJ2a05NEXGKaJl5rTLUV5OlLTwbXWUb8Sz4JAQvUqMs5FU0FDz8IUY46IH6zAXvg6z1i3AqeY1fNaNi+/z48M2wN2LVO3+vvO326MsBTSH53kcd6Lbivi+eMDqk5SdylTn07yb8YQV7AVU+QZvsZyEsRk/8CAwEAARZEGwEBHD8HPQgXVGVzdENvbmZpZ1BvbGljeU1hbmFnZXIIBHRlbXAIA0tFWQgOa3NrLTE0MTYwMTAxMjMIB0lELUNFUlQX/QEAqO9vDnZTnyInuwLvJfwAKeuvHN8hW0fndPG9sa87p6E0qFA5IUb98TbOy3Hm7ybMXT0Bur1yFyLMwdSeQmLCmo0to0hkVKKwfvfN4L9zDCYE0E0RyBpFgI5+ZprxTIBHaMOA1KRvaeIKHeUaSkqTh2BhUNSi+9zp8w/KzYSYiA1FRw0gLMkarg8w8B6rOWcNfZFPnKhMItOw0Gm0Pz2UIBhA9stmiGvXqa/uvC5yBFfOEtltdN8g+IoAaZcRs7vDzYPOCzW/YueN7KTbi+YrohPzuzqoE/Y7jxDdOVW4XU98CSmS/VFLrcToeEI0X6Z18qRY31BH8mrdWa9B/AxVOg== -------------------------------------------------------------------------------- /examples/browser/face-query-filter.proto: -------------------------------------------------------------------------------- 1 | // Load this file using: 2 | // var builder = ProtoBuf.loadProtoFile("face-query-filter.proto"); 3 | 4 | package ndn_message; 5 | 6 | // Protobuf has no "outer" message type, so we need to put the TLV FaceQueryFilter 7 | // message inside an outer "typeless" FaceQueryFilterMessage. 8 | message FaceQueryFilterMessage { 9 | enum FaceScope { 10 | NON_LOCAL = 0; 11 | LOCAL = 1; 12 | } 13 | 14 | enum FacePersistency { 15 | PERSISTENT = 0; 16 | ON_DEMAND = 1; 17 | PERMANENT = 2; 18 | } 19 | 20 | enum LinkType { 21 | POINT_TO_POINT = 0; 22 | MULTI_ACCESS = 1; 23 | } 24 | 25 | message FaceQueryFilter { 26 | optional uint64 face_id = 105; 27 | optional string uri_scheme = 131; 28 | optional string uri = 114; 29 | optional string local_uri = 129; 30 | optional FaceScope face_scope = 132; 31 | optional FacePersistency face_persistency = 133; 32 | optional LinkType link_type = 134; 33 | } 34 | 35 | // A FaceQueryFilterMessage has repeated FaceQueryFilter. 36 | repeated FaceQueryFilter face_query_filter = 150; 37 | } 38 | -------------------------------------------------------------------------------- /tests/node/integration-tests/policy_config/certs/anchor.cert-v2: -------------------------------------------------------------------------------- 1 | Bv0C5wdFCBdUZXN0Q29uZmlnUG9saWN5TWFuYWdlcggEdGVtcAgDS0VZCA5rc2st 2 | MTQxNjAxMDEyMwgEc2VsZggJ/QAAAVwOQy0YFAkYAQIZBAA27oAV/QEmMIIBIjAN 3 | BgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuAmnWYKE7E8G+hyy4TiTU7t91KyI 4 | GvglEeT6HWEkW4LKzXLO22a1jVS9+yP96I6vp7N5vpS1t7oXtgWuzkO+O85u6gfb 5 | vwp+67zJe2I89eHO4dmNnP4fx/j7WcCUCyzZfbyW67h5IoouoBIdQge2Xdvh9rFd 6 | ex9UUhyjEZv5676zlcqlhz8xGBrJmQHsqpD9ijY1XhKBvoSIoQ0ZKkpmwVk8QYM9 7 | PbjUqzSQBj4aYXS+BPV6aRudVvyDt2DBXp2FNP0CGrosCXKnSl4Yv8BYp0k0RmFZ 8 | DuJuntLb/XIvPEfMX5li7g3zHzAlIJIVSwT+FRkd3H5cECFSIZFUYIuSQQIDAQAB 9 | FmUbAQEcNgc0CBdUZXN0Q29uZmlnUG9saWN5TWFuYWdlcggEdGVtcAgDS0VZCA5r 10 | c2stMTQxNjAxMDEyM/0A/Sb9AP4PMjAxNzEyMDFUMTc0MTI4/QD/DzIwMzcxMTI2 11 | VDE3NDEyNxf9AQA4sGQi2+ji/a2c1A2vWhZA9j9bZAe/hxY55BM9beZN0HktIVk0 12 | OOZmz7p5p29aO9zgrqsKb/H8oCSGv5F340KUGLixlJ9CaNLnBsn2BfZ4la2OrVO1 13 | 2JY/TPqzscrWzZgSwAGhuu8XJrdlsPhVPK/3fMnhmMZYyA8P+YD5JIZaHMiHm21/ 14 | 3i4hWT0TqOEAw9CcILU6IWljT21Xs0bY9Ay6c8CzKYDDTa7p8FMzANRGjeOECWv+ 15 | 4elVRbHxAu0RYgH6+39JzUs6oT0xu9KsIe9j3naAmzawuDYFUc3eDxVRYva6YKYb 16 | m5fm8bhWjgRXKLhG5lzqzwHBSb3g6vWtuNmo 17 | 18 | -------------------------------------------------------------------------------- /js/browserify-stacktrace.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | // This is included after stacktrace.js and browserify-require.js so that 21 | // require().printStackTrace works. 22 | 23 | exports.printStackTrace = globals.printStackTrace; 24 | -------------------------------------------------------------------------------- /js/browserify-tcp-transport.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2013-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | // The Face constructor uses TcpTransport by default which is not available in the browser, so override to WebSocketTransport. 21 | exports.TcpTransport = require("./transport/web-socket-transport").WebSocketTransport; 22 | -------------------------------------------------------------------------------- /contrib/securityLib/CryptoJS-LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Updated Aug 17, 2013 by Jeff.Mott.OR 3 | 4 | Copyright (c) 2009-2013 Jeff Mott 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 7 | associated documentation files (the "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 15 | NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 17 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 18 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /contrib/feross/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (C) 2013 Feross Aboukhadijeh, and other contributors. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /ndn-protocol/content/toolbar.xul: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 28 | 29 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /js/encoding/der/der-decoding-exception.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | /** 21 | * Create a new DerDecodingException wrapping the given error object. 22 | * Call with: throw new DerDecodingException(new Error("message")). 23 | * @constructor 24 | * @param {Error} error The exception created with new Error. 25 | */ 26 | function DerDecodingException(error) 27 | { 28 | if (error) { 29 | error.__proto__ = DerDecodingException.prototype; 30 | return error; 31 | } 32 | } 33 | DerDecodingException.prototype = new Error(); 34 | DerDecodingException.prototype.name = "DerDecodingException"; 35 | 36 | exports.DerDecodingException = DerDecodingException; 37 | -------------------------------------------------------------------------------- /js/encoding/der/der-encoding-exception.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | /** 21 | * Create a new DerEncodingException wrapping the given error object. 22 | * Call with: throw new DerEncodingException(new Error("message")). 23 | * @constructor 24 | * @param {Error} error The exception created with new Error. 25 | */ 26 | function DerEncodingException(error) 27 | { 28 | if (error) { 29 | error.__proto__ = DerEncodingException.prototype; 30 | return error; 31 | } 32 | } 33 | DerEncodingException.prototype = new Error(); 34 | DerEncodingException.prototype.name = "DerEncodingException"; 35 | 36 | exports.DerEncodingException = DerEncodingException; 37 | -------------------------------------------------------------------------------- /tests/node/integration-tests/policy_config/testKey.pri: -------------------------------------------------------------------------------- 1 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDUT9muetKHgGcRMbhbrItf8iEoLHDsZukY7l7x4+8Jy17gzeQ5aj9DKj4aBvLMsA9b2KE/HLj6jKS/oFdhyzWpD1Z2VwWkVpBkPQ5uJENeVAKZW74Fq8n7t48Xy1nAQkd5sbhcl++rZSGIvVg+mo53hGw9GnF6tZvE3uUkGGJhWEAUZW2PpII+vul6+lSdmtOTRFximiZea0y1FeTpS08G11lG/Es+CQEL1KjLORVNBQ8/CFGOOiB+swF74Os9YtwKnmNXzWjYvv8+PDNsDdi1Tt/r7zt9ujLAU0h+d5HHei24r4vnjA6pOUncpU59O8m/GEFewFVPkGb7GchLEZP/AgMBAAECggEAD6GFXEQspc89R1XKxe0RIdI4wLVs5uq4tJ4wHUzzt1vis1hVOijpWW+NvOrQC2PW7aMoU/YwZDngkz8hz9BfNgAsFHBZuPyqisa3/kHrN9Glk1beyZoZN9AO1+ifxfjbPElqUl7ZRVwfuOp/ybQlUwVL1r/QpQEj472pTxwAejwbu6oI2dKM27Rs/1dkgrsCcS2Z6opOWtuCIDJR+DCYZ0oxc7HXUcVxgiuZvAz6JEwLOHPY729b2lbIa8v1xqpNizkPCkNOi4fnmFoNlFXHQrQT+u2c/uotlcHcL11E9S2ri3lwD+mnF+hA16UNl+lTpLRwvhl7hiwm57EjIlq9kQKBgQDiTTzcI7UtxGbn8qQzudbdOcbuDuYju5zwahCoEqoVjAhRXe1GM7BdcgKgFrjPqicJdJeMrI1OvOhi5R48dLvpuaaRAj9DTS8BKhz/TwX1mFc/Z7AthC3T9bnXNzkqRARYpBceRzg/fWGX8uTl6+i/VaxrdLhVKxwSKpwR8Fud1wKBgQDwLJ2jNAtqAWlsqr/ulcwSJDfr2jDb5Us0W1aeRuvltXVFrLeiUmkE0l+YWU+2846fNI0HIn7AKHnhJQoDlrioD8g3LbDowB47SvLMa2CDiC1xj5GrGgKOA/vCmk6R1EksTGmM6Uu+iOLZqH896Wc519QRoLHNi1lfzjUWJjDmGQKBgQCbWURHJqgQY/v0jCfWbmOmeCwsbcPkkb05eMY4ap+hrQBkwuLIR2FxtHtC5HY38Gld31DNvAJBJAMvKHOqMsRwvQYwE2fUTp7O4NcJGHlR0CNMnmRdypgfIldR+1HdxtVo+DP6kA933h1pzs79WwXqmuiC15xWswJRIjkDQ4nQ/wKBgBMcicK13n6l9ByojbNPijibVzPWXfLxkQVuizr3C8hwow9TSh2Jjz/J+b9mw/gb82ppxRsfPJTP47rttplIghMlhloVsbEjsIQpV566oKh2yp7xvLav0Co62OrIWp4yFUyIHBIRcmyL+fk19kIX85XfvclVTzC6+Patsv27NkLpAoGBAK3wwPxVR4oDK1wcbu/2lmjuqNBtcE9/Phcr/X4ijOol47ukoVfnPsBH+Hum0khowIrgsmtd+TJucFq5d9m/bepT4k+oTBz6aUkmSIrFkndreonD720cRBDmr0cYn5kJtDtj97/k5+WY4leFu3i10cNkjU1PAtssUVijxzXxLXoK 2 | -------------------------------------------------------------------------------- /js/security/key-id-type.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * From ndn-cxx security by Yingdi Yu . 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** 22 | * The KeyIdType enum represents the type of a KeyId component in a key name. 23 | * @constructor 24 | */ 25 | var KeyIdType = function KeyIdType() 26 | { 27 | }; 28 | 29 | exports.KeyIdType = KeyIdType; 30 | 31 | // USER_SPECIFIED: A user-specified key ID. It is the user's responsibility 32 | // to ensure the uniqueness of key names. 33 | KeyIdType.USER_SPECIFIED = 0; 34 | 35 | // SHA256: The SHA256 hash of the public key as the key id. This KeyId type 36 | // guarantees the uniqueness of key names. 37 | KeyIdType.SHA256 = 1; 38 | 39 | // RANDOM: A 64-bit random number as the key id. This KeyId provides rough 40 | // uniqueness of key names. 41 | KeyIdType.RANDOM = 2; 42 | -------------------------------------------------------------------------------- /examples/node/test: -------------------------------------------------------------------------------- 1 | 2 | // Try to fetch using a known name. 3 | var name1 = new Name("/ndn/edu/ucla/remap/demo/ndn-js-test/hello.txt/%FDU%8D%9DM"); 4 | console.log("Express name " + name1.toUri()); 5 | SegmentFetcher.fetch 6 | (new Face({host: "memoria.ndn.ucla.edu"}), new Interest(name1), 7 | null /*validator key*/, 8 | onComplete, function(errorCode, message) { 9 | console.log("Error " + errorCode + ": " + message); 10 | //if (++callbackCount >= 3) 11 | //face.close(); // This will cause the script to quit. 12 | }, 13 | null /*pipeline type (default: Cubic) and its options*/ 14 | ); 15 | 16 | 17 | 18 | // Try to fetch a local file. 19 | var name2 = new Name("/testecho"); 20 | console.log("Express name " + name2.toUri()); 21 | SegmentFetcher.fetch 22 | (new Face({host: "localhost"}), new Interest(name2), 23 | null /*validator key*/, 24 | onComplete, function(errorCode, message) { 25 | console.log("Error " + errorCode + ": " + message); 26 | //if (++callbackcount >= 3) 27 | //face.close(); // this will cause the script to quit. 28 | }, 29 | null /*pipeline type (default: Cubic) and its options*/ 30 | ); 31 | 32 | // Expect this to time out. 33 | var name3 = new Name("/test/timeout"); 34 | console.log("Express name " + name3.toUri()); 35 | SegmentFetcher.fetch 36 | (new Face({host: "localhost"}), new Interest(name3), 37 | null /*validator key*/, 38 | onComplete, function(errorCode, message) { 39 | console.log("Error " + errorCode + ": " + message); 40 | //if (++callbackcount >= 3) 41 | //face.close(); // this will cause the script to quit. 42 | }, 43 | null /*pipeline type (default: Cubic) and its options*/ 44 | ); 45 | -------------------------------------------------------------------------------- /js/security/validator-config-error.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx security https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/security/v2/validator-config/common.hpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** 22 | * Create a new ValidatorConfigError to report an error using ValidatorConfig. 23 | * Call with: throw new ValidatorConfigError(new Error("message")). 24 | * @param {Error} error The exception created with new Error. 25 | * @constructor 26 | */ 27 | var ValidatorConfigError = function ValidatorConfigError(error) 28 | { 29 | if (error) { 30 | error.__proto__ = ValidatorConfigError.prototype; 31 | return error; 32 | } 33 | } 34 | 35 | ValidatorConfigError.prototype = new Error(); 36 | ValidatorConfigError.prototype.name = "ValidatorConfigError"; 37 | 38 | exports.ValidatorConfigError = ValidatorConfigError; 39 | -------------------------------------------------------------------------------- /tools/micro-forwarder/INSTALL.md: -------------------------------------------------------------------------------- 1 | Micro Forwarder: A light-weight forwarder in the browser based on NDN-JS 2 | ======================================================================== 3 | 4 | Native Messaging for multicast 5 | ============================== 6 | 7 | Native Messaging allows a browser to use an authorized application on the computer. 8 | The Micro Forwarder uses the ndn_multicast.py application to send and receive 9 | packets in the NDN multicast group. To authorize it, follow these steps for your platform. 10 | 11 | ## Firefox on macOS 12 | 13 | Native Messaging requires Firefox 50. In a terminal change directory to 14 | `ndn-js/tools/micro-forwarder` . Enter: 15 | 16 | mkdir -p ~/Library/Application\ Support/Mozilla/NativeMessagingHosts 17 | cp ndn_multicast.json ~/Library/Application\ Support/Mozilla/NativeMessagingHosts 18 | 19 | Edit `~/Library/Application\ Support/Mozilla/NativeMessagingHosts/ndn_multicast.json` and 20 | change the line 21 | 22 | "path": "ndn-js/tools/micro-forwarder/ndn_multicast.py", 23 | 24 | to have the full path of the ndn-js project. For example: 25 | 26 | "path": "/Users/username/ndn-js/tools/micro-forwarder/ndn_multicast.py", 27 | 28 | Installing during development 29 | ============================= 30 | 31 | To install the Micro Forwarder extension during development, in a terminal change 32 | directory to `ndn-js/tools/micro-forwarder` . Enter: 33 | 34 | ./make-ndn-micro-forwarder.sh 35 | 36 | This copies ndn.js from the build directory so that the extension can use it. 37 | 38 | ## Firefox 39 | 40 | In the Firefox address bar, enter `about:debugging` . Click "Load Temporary Add-on". 41 | Browse to the directory `ndn-js/tools/micro-forwarder/extension` and click 42 | `manifest.json` . 43 | -------------------------------------------------------------------------------- /tests/node/integration-tests/policy_config/hyperrelation_ruleset.conf: -------------------------------------------------------------------------------- 1 | validator 2 | { 3 | rule 4 | { 5 | id "A rule" 6 | for data 7 | filter 8 | { 9 | type name 10 | name /SecurityTestSecRule/Basic/Longer 11 | relation is-strict-prefix-of 12 | } 13 | checker 14 | { 15 | type customized 16 | sig-type rsa-sha256 17 | key-locator 18 | { 19 | type name 20 | hyper-relation 21 | { 22 | # there are 2 components between SecurityTestSecRule and KEY 23 | # in the key name, and the data name begins with SecurityTestSecRule 24 | k-regex "^()[^]{2}$" 25 | k-expand "\\1" 26 | h-relation is-strict-prefix-of 27 | p-regex "^(<>*)$" 28 | p-expand "\\1" 29 | } 30 | } 31 | } 32 | } 33 | rule 34 | { 35 | id "Another rule" 36 | for data 37 | filter 38 | { 39 | type name 40 | name /SecurityTestSecRule/Basic/ 41 | relation is-prefix-of 42 | } 43 | checker 44 | { 45 | type customized 46 | sig-type rsa-sha256 47 | key-locator 48 | { 49 | type name 50 | hyper-relation 51 | { 52 | # there is 1 component between KEY and key-id 53 | # and the data name must end in a /Data* component 54 | # key identity is a prefix of everything before /Data* in data name 55 | k-regex "^([^]+)(<>)$" 56 | k-expand "\\1\\2" 57 | h-relation is-strict-prefix-of 58 | p-regex "^(<>+)$" 59 | p-expand "\\1" 60 | } 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /examples/node/fetch.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * A copy of the GNU Lesser General Public License is in the file COPYING. 17 | */ 18 | 19 | var Face = require('../..').Face; 20 | var Name = require('../..').Name; 21 | var EncodingUtils = require('../..').EncodingUtils; 22 | 23 | var onData = function(interest, data) { 24 | console.log("Data received in callback."); 25 | console.log('Name: ' + data.getName().toUri()); 26 | console.log('Content: ' + data.getContent().buf().toString()); 27 | console.log(EncodingUtils.dataToHtml(data).replace(/
/g, "\n")); 28 | 29 | console.log('Quit script now.'); 30 | face.close(); // This will cause the script to quit. 31 | }; 32 | 33 | var onTimeout = function(interest) { 34 | console.log("Interest time out."); 35 | console.log('Interest name: ' + interest.getName().toUri()); 36 | console.log('Quit script now.'); 37 | face.close(); // This will cause the script to quit. 38 | }; 39 | 40 | var face = new Face(); 41 | var name = new Name("/"); 42 | console.log("Express name " + name.toUri()); 43 | face.expressInterest(name, onData, onTimeout); 44 | -------------------------------------------------------------------------------- /js/security/security-types.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * From ndn-cxx security by Yingdi Yu . 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** 22 | * This module defines constants used by the security library. 23 | */ 24 | 25 | /** 26 | * The KeyType integer is used by the Sqlite key storage, so don't change them. 27 | * Make these the same as ndn-cxx in case the storage file is shared. 28 | * @constructor 29 | */ 30 | var KeyType = function KeyType() 31 | { 32 | } 33 | 34 | exports.KeyType = KeyType; 35 | 36 | KeyType.RSA = 0; 37 | KeyType.EC = 1; 38 | /** 39 | * @deprecated Use KeyType.EC . 40 | */ 41 | KeyType.ECDSA = 1; 42 | KeyType.AES = 128; 43 | 44 | var KeyClass = function KeyClass() 45 | { 46 | }; 47 | 48 | exports.KeyClass = KeyClass; 49 | 50 | KeyClass.PUBLIC = 1; 51 | KeyClass.PRIVATE = 2; 52 | KeyClass.SYMMETRIC = 3; 53 | 54 | var DigestAlgorithm = function DigestAlgorithm() 55 | { 56 | }; 57 | 58 | exports.DigestAlgorithm = DigestAlgorithm; 59 | 60 | DigestAlgorithm.SHA256 = 1; 61 | -------------------------------------------------------------------------------- /ndn-protocol/content/ndn-toolbar.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This is called from the NDN toolbar and the doorhanger popup on Firefox for Android. 3 | * Copyright (C) 2013-2019 Regents of the University of California. 4 | * @author: Jeff Thompson 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | Components.utils.import("chrome://modules/content/ndn-js.jsm"); 22 | Components.utils.import("chrome://modules/content/ndn-protocol-info.jsm"); 23 | 24 | function ndnToolbarGetVersion(selector) 25 | { 26 | NdnProtocolInfo.getVersion(selector, window, alert); 27 | } 28 | 29 | /* 30 | * This is called when the connected NDN hub changes. 31 | */ 32 | function onNdnHubChanged(host, port) 33 | { 34 | document.getElementById("ndnHubLabel").setAttribute("value", "Hub: " + host + ":" + port); 35 | } 36 | 37 | if (window) 38 | window.addEventListener("load", function() { NdnProtocolInfo.addNdnHubChangedListener(onNdnHubChanged); }, 39 | false); 40 | 41 | function ndnToolbarSetHub() 42 | { 43 | var message = NdnProtocolInfo.setHub(window, alert); 44 | if (message != null) 45 | document.getElementById("ndnHubLabel").setAttribute("value", message); 46 | } 47 | -------------------------------------------------------------------------------- /js/security/validator-null.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx security https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/security/validator-null.hpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var ValidationPolicyAcceptAll = require('./v2/validation-policy-accept-all.js').ValidationPolicyAcceptAll; /** @ignore */ 23 | var CertificateFetcherOffline = require('./v2/certificate-fetcher-offline.js').CertificateFetcherOffline; /** @ignore */ 24 | var Validator = require('./v2/validator.js').Validator; 25 | 26 | /** 27 | * A ValidatorNull extends Validator with an "accept-all" policy and an offline 28 | * certificate fetcher. 29 | * @constructor 30 | */ 31 | var ValidatorNull = function ValidatorNull() 32 | { 33 | // Call the base constructor. 34 | Validator.call 35 | (this, new ValidationPolicyAcceptAll(), new CertificateFetcherOffline()); 36 | }; 37 | 38 | ValidatorNull.prototype = new Validator(new ValidationPolicyAcceptAll()); 39 | ValidatorNull.prototype.name = "ValidatorNull"; 40 | 41 | exports.ValidatorNull = ValidatorNull; 42 | -------------------------------------------------------------------------------- /tools/micro-forwarder/extension/config.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 24 | Micro Forwarder Configuration 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
34 | Domain name of remote forwarder:
35 | 37 |
38 | Prefix:
39 | 40 |
41 | 42 |
43 |
44 | 45 |

46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /examples/ndnping/ndn-ping.html: -------------------------------------------------------------------------------- 1 | 3 | 20 | 21 | 22 | NDN Ping 23 | 24 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |

NDN Ping example

37 | 38 | Using ping responder on NDN testbed, which responds to Interests in 39 | /<topo-prefix>/ping/<random-number>. 40 | 41 |

NDN Testbed Status

42 |

Testbed content ping results retrieved using NDN-JS, a javascript client library for NDN.

43 |

Websocket host:

44 | 45 |
46 |

 

47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /js/forwarding-flags.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2013-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | /** @ignore */ 21 | var RegistrationOptions = require('./registration-options.js').RegistrationOptions; 22 | 23 | /** 24 | * Create a new ForwardingFlags object, possibly copying values from another 25 | * object. 26 | * @param {ForwardingFlags} value (optional) If value is a 27 | * RegistrationOptions (or ForwardingFlags), copy its values. If value is 28 | * omitted, the type is the default with "childInherit" true and other flags 29 | * false. 30 | * @deprecated Use RegistrationOptions. 31 | * @constructor 32 | */ 33 | var ForwardingFlags = function ForwardingFlags(value) 34 | { 35 | // Call the base constructor. 36 | RegistrationOptions.call(this, value); 37 | }; 38 | 39 | ForwardingFlags.prototype = new RegistrationOptions(); 40 | 41 | exports.ForwardingFlags = ForwardingFlags; 42 | 43 | ForwardingFlags.NfdForwardingFlags_CHILD_INHERIT = RegistrationOptions.NfdForwardingFlags_CHILD_INHERIT; 44 | ForwardingFlags.NfdForwardingFlags_CAPTURE = RegistrationOptions.NfdForwardingFlags_CAPTURE; 45 | -------------------------------------------------------------------------------- /js/security/v2/certificate-container-interface.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx security https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/security/v2/trust-anchor-group.cpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** 22 | * @constructor 23 | */ 24 | var CertificateContainerInterface = function CertificateContainerInterface() 25 | { 26 | }; 27 | 28 | exports.CertificateContainerInterface = CertificateContainerInterface; 29 | 30 | /** 31 | * Add the certificate to the container. 32 | * @param {CertificateV2} certificate The certificate to add, which is copied. 33 | */ 34 | CertificateContainerInterface.prototype.add = function(certificate) 35 | { 36 | throw new Error("CertificateContainerInterface.add is unimplemented"); 37 | }; 38 | 39 | /** 40 | * Remove the certificate with the given name. If the name does not exist, 41 | * do nothing. 42 | * @param {Name} certificateName The name of the certificate. 43 | */ 44 | CertificateContainerInterface.prototype.remove = function(certificateName) 45 | { 46 | throw new Error("CertificateContainerInterface.remove is unimplemented"); 47 | }; 48 | -------------------------------------------------------------------------------- /js/util/regex/ndn-regex-backref-manager.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017-2019 Regents of the University of California. 3 | * @author: Yingdi Yu 4 | * @author: Jeff Thompson 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** 22 | * @constructor 23 | */ 24 | var NdnRegexBackrefManager = function NdnRegexBackrefManager() 25 | { 26 | // Array of NdnRegexMatcherBase 27 | this.backrefs_ = [] 28 | }; 29 | 30 | exports.NdnRegexBackrefManager = NdnRegexBackrefManager; 31 | 32 | /** 33 | * @param {NdnRegexMatcherBase} matcher 34 | * @return {number} 35 | */ 36 | NdnRegexBackrefManager.prototype.pushRef = function(matcher) 37 | { 38 | last = this.backrefs_.length; 39 | this.backrefs_.push(matcher); 40 | 41 | return last; 42 | }; 43 | 44 | NdnRegexBackrefManager.prototype.popRef = function() 45 | { 46 | this.backrefs_.pop(); 47 | }; 48 | 49 | /** 50 | * @return {number} 51 | */ 52 | NdnRegexBackrefManager.prototype.size = function() 53 | { 54 | return this.backrefs_.length; 55 | }; 56 | 57 | /** 58 | * @param {number} i 59 | * @return {NdnRegexMatcherBase} 60 | */ 61 | NdnRegexBackrefManager.prototype.getBackref = function(i) 62 | { 63 | return this.backrefs_[i]; 64 | }; 65 | -------------------------------------------------------------------------------- /js/encrypt/decrypt-key.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-group-encrypt src/decrypt-key https://github.com/named-data/ndn-group-encrypt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var Blob = require('../util/blob.js').Blob; 23 | 24 | /** 25 | * A DecryptKey supplies the key for decrypt. 26 | * Create a DecryptKey with the given key value. 27 | * @param {Blob|DecryptKey} value If value is another DecryptKey then copy it. 28 | * Otherwise, value is the key value. 29 | * @note This class is an experimental feature. The API may change. 30 | * @constructor 31 | */ 32 | var DecryptKey = function DecryptKey(value) 33 | { 34 | if (typeof value === 'object' && value instanceof DecryptKey) { 35 | // Make a deep copy. 36 | this.keyBits_ = value.keyBits_; 37 | } 38 | else { 39 | var keyBits = value; 40 | this.keyBits_ = typeof keyBits === 'object' && keyBits instanceof Blob ? 41 | keyBits : new Blob(keyBits); 42 | } 43 | }; 44 | 45 | exports.DecryptKey = DecryptKey; 46 | 47 | /** 48 | * Get the key value. 49 | * @return {Blob} The key value. 50 | */ 51 | DecryptKey.prototype.getKeyBits = function() { return this.keyBits_; }; 52 | -------------------------------------------------------------------------------- /js/encrypt/encrypt-key.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-group-encrypt src/encrypt-key https://github.com/named-data/ndn-group-encrypt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var Blob = require('../util/blob.js').Blob; 23 | 24 | /** 25 | * An EncryptKey supplies the key for encrypt. 26 | * Create an EncryptKey with the given key value. 27 | * @param {Blob|EncryptKey} value If value is another EncryptKey then copy it. 28 | * Otherwise, value is the key value. 29 | * @note This class is an experimental feature. The API may change. 30 | * @constructor 31 | */ 32 | var EncryptKey = function EncryptKey(value) 33 | { 34 | if (typeof value === 'object' && value instanceof EncryptKey) { 35 | // Make a deep copy. 36 | this.keyBits_ = value.keyBits_; 37 | } 38 | else { 39 | var keyBits = value; 40 | this.keyBits_ = typeof keyBits === 'object' && keyBits instanceof Blob ? 41 | keyBits : new Blob(keyBits); 42 | } 43 | }; 44 | 45 | exports.EncryptKey = EncryptKey; 46 | 47 | /** 48 | * Get the key value. 49 | * @return {Blob} The key value. 50 | */ 51 | EncryptKey.prototype.getKeyBits = function() { return this.keyBits_; }; 52 | -------------------------------------------------------------------------------- /examples/browser/control-parameters.proto: -------------------------------------------------------------------------------- 1 | // Load this file using: 2 | // var builder = ProtoBuf.loadProtoFile("control-parameters.proto"); 3 | 4 | package ndn_message; 5 | 6 | // Create ControlParametersTypes so we can define both ControlParametersMessage 7 | // and ControlParametersResponseMessage. 8 | message ControlParametersTypes { 9 | message Name { 10 | repeated bytes component = 8; 11 | } 12 | 13 | message Strategy { 14 | required Name name = 7; 15 | } 16 | 17 | message ControlParameters { 18 | optional Name name = 7; 19 | optional uint64 face_id = 105; 20 | optional string uri = 114; 21 | optional string local_uri = 129; 22 | optional uint64 origin = 111; 23 | optional uint64 cost = 106; 24 | optional uint64 capacity = 131; 25 | optional uint64 count = 132; 26 | optional uint64 flags = 108; 27 | optional uint64 mask = 112; 28 | optional Strategy strategy = 107; 29 | optional uint64 expiration_period = 109; 30 | optional uint64 face_persistency = 133; 31 | optional uint64 base_congestion_marking_interval = 135; 32 | optional uint64 default_congestion_threshold = 136; 33 | optional uint64 mtu = 137; 34 | } 35 | 36 | // A ControlParametersResponse is a ControlResponse where the body is zero or 37 | // more ControlParameters. 38 | message ControlParametersResponse { 39 | required uint64 status_code = 102; 40 | required string status_text = 103; 41 | repeated ControlParameters control_parameters = 104; 42 | } 43 | 44 | // Protobuf has no "outer" message type, so we need to put the TLV ControlParameters 45 | // message inside an outer "typeless" ControlParametersMessage. 46 | message ControlParametersMessage { 47 | // A ControlParametersMessage has one ControlParameters. 48 | required ControlParameters control_parameters = 104; 49 | } 50 | 51 | message ControlParametersResponseMessage { 52 | // A ControlParametersResponseMessage has one ControlParametersResponse. 53 | required ControlParametersResponse control_response = 101; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /js/util/regex/ndn-regex-pseudo-matcher.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017-2019 Regents of the University of California. 3 | * @author: Yingdi Yu 4 | * @author: Jeff Thompson 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var Name = require('../../name.js').Name; /** @ignore */ 23 | var NdnRegexMatcherBase = require('./ndn-regex-matcher-base.js').NdnRegexMatcherBase; 24 | 25 | /** 26 | * Create an NdnRegexPseudoMatcher. 27 | * @constructor 28 | */ 29 | var NdnRegexPseudoMatcher = function NdnRegexPseudoMatcher() 30 | { 31 | // Call the base constructor. 32 | NdnRegexMatcherBase.call 33 | (this, "", NdnRegexMatcherBase.NdnRegexExprType.PSEUDO); 34 | }; 35 | 36 | NdnRegexPseudoMatcher.prototype = new NdnRegexMatcherBase(); 37 | NdnRegexPseudoMatcher.prototype.name = "NdnRegexPseudoMatcher"; 38 | 39 | exports.NdnRegexPseudoMatcher = NdnRegexPseudoMatcher; 40 | 41 | NdnRegexPseudoMatcher.prototype.compile_ = function() 42 | { 43 | }; 44 | 45 | /** 46 | * @param {string} value 47 | */ 48 | NdnRegexPseudoMatcher.prototype.setMatchResult = function(value) 49 | { 50 | this.matchResult_.push(new Name.Component(value)); 51 | }; 52 | 53 | NdnRegexPseudoMatcher.prototype.resetMatchResult = function() 54 | { 55 | this.matchResult_ = []; 56 | }; 57 | -------------------------------------------------------------------------------- /js/security/v2/validation-policy-accept-all.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx security https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/security/v2/validation-policy-accept-all.hpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var ValidationPolicy = require('./validation-policy.js').ValidationPolicy; 23 | 24 | /** 25 | * ValidationPolicyAcceptAll extends ValidationPolicy to implement a validator 26 | * policy that accepts any signature of a Data or Interest packet. 27 | * @constructor 28 | */ 29 | var ValidationPolicyAcceptAll = function ValidationPolicyAcceptAll() 30 | { 31 | // Call the base constructor. 32 | ValidationPolicy.call(this); 33 | }; 34 | 35 | ValidationPolicyAcceptAll.prototype = new ValidationPolicy(); 36 | ValidationPolicyAcceptAll.prototype.name = "ValidationPolicyAcceptAll"; 37 | 38 | exports.ValidationPolicyAcceptAll = ValidationPolicyAcceptAll; 39 | 40 | /** 41 | * @param {Data|Interest} dataOrInterest 42 | * @param {ValidationState} state 43 | * @param {function} continueValidation 44 | */ 45 | ValidationPolicyAcceptAll.prototype.checkPolicy = function 46 | (dataOrInterest, state, continueValidation) 47 | { 48 | continueValidation(null, state); 49 | }; 50 | -------------------------------------------------------------------------------- /js/security/policy/validation-request.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * From ndn-cxx security by Yingdi Yu . 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** 22 | * A ValidationRequest is used to return information from 23 | * PolicyManager.checkVerificationPolicy. 24 | * 25 | * Create a new ValidationRequest with the given values. 26 | * @param {Interest} interest An interest for fetching more data. 27 | * @param {function} onVerified If the signature is verified, this calls 28 | * onVerified(data). 29 | * @param {function} onValidationFailed If the signature check fails, this calls 30 | * onValidationFailed(data, reason). 31 | * @param {number} retry The number of retrials when there is an interest timeout. 32 | * @param {number} stepCount The number of verification steps that have been 33 | * done, used to track the verification progress. 34 | * @constructor 35 | */ 36 | var ValidationRequest = function ValidationRequest 37 | (interest, onVerified, onValidationFailed, retry, stepCount) 38 | { 39 | this.interest = interest; 40 | this.onVerified = onVerified; 41 | this.onValidationFailed = onValidationFailed; 42 | this.retry = retry; 43 | this.stepCount = stepCount; 44 | }; 45 | 46 | exports.ValidationRequest = ValidationRequest; 47 | -------------------------------------------------------------------------------- /js/encoding/tlv-0_1_1-wire-format.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2013-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | /** @ignore */ 21 | var Tlv0_2WireFormat = require('./tlv-0_2-wire-format.js').Tlv0_2WireFormat; 22 | 23 | /** 24 | * A Tlv0_1_1WireFormat extends Tlv0_2WireFormat so that it is an alias in case 25 | * any applications use Tlv0_1_1WireFormat directly. These two wire formats are 26 | * the same except that Tlv0_2WireFormat adds support for the name component 27 | * type ImplicitSha256Digest. 28 | * @constructor 29 | */ 30 | var Tlv0_1_1WireFormat = function Tlv0_1_1WireFormat() 31 | { 32 | // Inherit from Tlv0_2WireFormat. 33 | Tlv0_2WireFormat.call(this); 34 | }; 35 | 36 | Tlv0_1_1WireFormat.prototype = new Tlv0_2WireFormat(); 37 | Tlv0_1_1WireFormat.prototype.name = "Tlv0_1_1WireFormat"; 38 | 39 | exports.Tlv0_1_1WireFormat = Tlv0_1_1WireFormat; 40 | 41 | // Default object. 42 | Tlv0_1_1WireFormat.instance = null; 43 | 44 | /** 45 | * Get a singleton instance of a Tlv0_1_1WireFormat. 46 | * @return {Tlv0_1_1WireFormat} The singleton instance. 47 | */ 48 | Tlv0_1_1WireFormat.get = function() 49 | { 50 | if (Tlv0_1_1WireFormat.instance === null) 51 | Tlv0_1_1WireFormat.instance = new Tlv0_1_1WireFormat(); 52 | return Tlv0_1_1WireFormat.instance; 53 | }; 54 | -------------------------------------------------------------------------------- /js/encoding/tlv-0_1-wire-format.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2013-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | /** @ignore */ 21 | var WireFormat = require('./wire-format.js').WireFormat; /** @ignore */ 22 | var Tlv0_1_1WireFormat = require('./tlv-0_1_1-wire-format.js').Tlv0_1_1WireFormat; 23 | 24 | /** 25 | * A Tlv0_1WireFormat extends Tlv0_1_1WireFormat so that it is an alias in case 26 | * any applications use Tlv0_1WireFormat directly. These two wire formats are 27 | * the same except that Tlv0_1_1WireFormat adds support for 28 | * Sha256WithEcdsaSignature. 29 | * @constructor 30 | */ 31 | var Tlv0_1WireFormat = function Tlv0_1WireFormat() 32 | { 33 | // Inherit from Tlv0_1_1WireFormat. 34 | Tlv0_1_1WireFormat.call(this); 35 | }; 36 | 37 | Tlv0_1WireFormat.prototype = new Tlv0_1_1WireFormat(); 38 | Tlv0_1WireFormat.prototype.name = "Tlv0_1WireFormat"; 39 | 40 | exports.Tlv0_1WireFormat = Tlv0_1WireFormat; 41 | 42 | // Default object. 43 | Tlv0_1WireFormat.instance = null; 44 | 45 | /** 46 | * Get a singleton instance of a Tlv0_1WireFormat. 47 | * @return {Tlv0_1WireFormat} The singleton instance. 48 | */ 49 | Tlv0_1WireFormat.get = function() 50 | { 51 | if (Tlv0_1WireFormat.instance === null) 52 | Tlv0_1WireFormat.instance = new Tlv0_1WireFormat(); 53 | return Tlv0_1WireFormat.instance; 54 | }; 55 | -------------------------------------------------------------------------------- /contrib/securityLib/base64.js: -------------------------------------------------------------------------------- 1 | /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ 2 | */ 3 | var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 4 | var b64pad="="; 5 | 6 | function hex2b64(h) { 7 | var i; 8 | var c; 9 | var ret = ""; 10 | for(i = 0; i+3 <= h.length; i+=3) { 11 | c = parseInt(h.substring(i,i+3),16); 12 | ret += b64map.charAt(c >> 6) + b64map.charAt(c & 63); 13 | } 14 | if(i+1 == h.length) { 15 | c = parseInt(h.substring(i,i+1),16); 16 | ret += b64map.charAt(c << 2); 17 | } 18 | else if(i+2 == h.length) { 19 | c = parseInt(h.substring(i,i+2),16); 20 | ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4); 21 | } 22 | if (b64pad) while((ret.length & 3) > 0) ret += b64pad; 23 | return ret; 24 | } 25 | 26 | // convert a base64 string to hex 27 | function b64tohex(s) { 28 | var ret = "" 29 | var i; 30 | var k = 0; // b64 state, 0-3 31 | var slop; 32 | var v; 33 | for(i = 0; i < s.length; ++i) { 34 | if(s.charAt(i) == b64pad) break; 35 | v = b64map.indexOf(s.charAt(i)); 36 | if(v < 0) continue; 37 | if(k == 0) { 38 | ret += int2char(v >> 2); 39 | slop = v & 3; 40 | k = 1; 41 | } 42 | else if(k == 1) { 43 | ret += int2char((slop << 2) | (v >> 4)); 44 | slop = v & 0xf; 45 | k = 2; 46 | } 47 | else if(k == 2) { 48 | ret += int2char(slop); 49 | ret += int2char(v >> 2); 50 | slop = v & 3; 51 | k = 3; 52 | } 53 | else { 54 | ret += int2char((slop << 2) | (v >> 4)); 55 | ret += int2char(v & 0xf); 56 | k = 0; 57 | } 58 | } 59 | if(k == 1) 60 | ret += int2char(slop << 2); 61 | return ret; 62 | } 63 | 64 | // convert a base64 string to a byte/number array 65 | function b64toBA(s) { 66 | //piggyback on b64tohex for now, optimize later 67 | var h = b64tohex(s); 68 | var i; 69 | var a = new Array(); 70 | for(i = 0; 2*i < h.length; ++i) { 71 | a[i] = parseInt(h.substring(2*i,2*i+2),16); 72 | } 73 | return a; 74 | } 75 | 76 | exports.b64tohex = b64tohex; 77 | exports.b64toBA = b64toBA; 78 | exports.hex2b64 = hex2b64; 79 | 80 | module.exports = exports; 81 | -------------------------------------------------------------------------------- /js/encrypt/encrypt-error.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-group-encrypt src/error-code https://github.com/named-data/ndn-group-encrypt 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** 22 | * EncryptError holds the ErrorCode enum for errors from the encrypt library. 23 | */ 24 | var EncryptError = function EncryptError() 25 | { 26 | }; 27 | 28 | exports.EncryptError = EncryptError; 29 | 30 | EncryptError.ErrorCode = { 31 | KekRetrievalFailure: 1, 32 | KekRetrievalTimeout: 2, 33 | KekInvalidName: 3, 34 | 35 | KdkRetrievalFailure: 11, 36 | KdkRetrievalTimeout: 12, 37 | KdkInvalidName: 13, 38 | KdkDecryptionFailure: 14, 39 | 40 | CkRetrievalFailure: 21, 41 | CkRetrievalTimeout: 22, 42 | CkInvalidName: 23, 43 | 44 | MissingRequiredKeyLocator: 101, 45 | TpmKeyNotFound: 102, 46 | EncryptionFailure: 103, 47 | DecryptionFailure: 104, 48 | MissingRequiredInitialVector: 110, 49 | 50 | General: 200, 51 | 52 | // @deprecated These codes are from the NAC library v1. 53 | Timeout: 1001, 54 | Validation: 1002, 55 | UnsupportedEncryptionScheme: 1032, 56 | InvalidEncryptedFormat: 1033, 57 | NoDecryptKey: 1034, 58 | DataRetrievalFailure: 1036 59 | }; 60 | -------------------------------------------------------------------------------- /js/security/v2/certificate-fetcher-offline.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx security https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/security/v2/certificate-fetcher-offline.hpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var ValidationError = require('./validation-error.js').ValidationError; /** @ignore */ 23 | var CertificateFetcher = require('./certificate-fetcher.js').CertificateFetcher; 24 | 25 | /** 26 | * CertificateFetcherOffline extends CertificateFetcher to implement a fetcher 27 | * that does not fetch certificates (always offline). 28 | * @constructor 29 | */ 30 | var CertificateFetcherOffline = function CertificateFetcherOffline() 31 | { 32 | // Call the base constructor. 33 | CertificateFetcher.call(this); 34 | }; 35 | 36 | CertificateFetcherOffline.prototype = new CertificateFetcher(); 37 | CertificateFetcherOffline.prototype.name = "CertificateFetcherOffline"; 38 | 39 | exports.CertificateFetcherOffline = CertificateFetcherOffline; 40 | 41 | CertificateFetcherOffline.prototype.doFetch_ = function 42 | (certificateRequest, state, continueValidation) 43 | { 44 | state.fail(new ValidationError 45 | (ValidationError.CANNOT_RETRIEVE_CERTIFICATE, 46 | "Cannot fetch certificate " + 47 | certificateRequest.interest_.getName().toUri() + " in offline mode")); 48 | }; 49 | -------------------------------------------------------------------------------- /examples/node/test-echo-consumer.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | var readline = require('readline'); 21 | var Face = require('../..').Face; 22 | var Name = require('../..').Name; 23 | var Interest = require('../..').Interest; 24 | var UnixTransport = require('../..').UnixTransport; 25 | 26 | // Silence the warning from Interest wire encode. 27 | Interest.setDefaultCanBePrefix(true); 28 | 29 | var onData = function(interest, data) { 30 | console.log("Got data packet with name " + data.getName().toUri()); 31 | console.log(data.getContent().buf().toString('binary')); 32 | 33 | face.close(); // This will cause the script to quit. 34 | }; 35 | 36 | var onTimeout = function(interest) { 37 | console.log("Time out for interest " + interest.getName().toUri()); 38 | face.close(); // This will cause the script to quit. 39 | }; 40 | 41 | // Connect to the local forwarder with a Unix socket. 42 | var face = new Face(new UnixTransport()); 43 | 44 | var rl = readline.createInterface({ 45 | input: process.stdin, 46 | output: process.stdout 47 | }); 48 | 49 | rl.question("Enter a word to echo: ", function(word) { 50 | var name = new Name("/testecho"); 51 | name.append(word); 52 | console.log("Express name " + name.toUri()); 53 | face.expressInterest(name, onData, onTimeout); 54 | 55 | rl.close(); 56 | }); 57 | -------------------------------------------------------------------------------- /contrib/securityLib/rng.js: -------------------------------------------------------------------------------- 1 | /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ 2 | */ 3 | // Random number generator - requires a PRNG backend, e.g. prng4.js 4 | 5 | // For best results, put code like 6 | // 7 | // in your main HTML document. 8 | 9 | var rng_state; 10 | var rng_pool; 11 | var rng_pptr; 12 | 13 | // Mix in a 32-bit integer into the pool 14 | function rng_seed_int(x) { 15 | rng_pool[rng_pptr++] ^= x & 255; 16 | rng_pool[rng_pptr++] ^= (x >> 8) & 255; 17 | rng_pool[rng_pptr++] ^= (x >> 16) & 255; 18 | rng_pool[rng_pptr++] ^= (x >> 24) & 255; 19 | if(rng_pptr >= rng_psize) rng_pptr -= rng_psize; 20 | } 21 | 22 | // Mix in the current time (w/milliseconds) into the pool 23 | function rng_seed_time() { 24 | rng_seed_int(new Date().getTime()); 25 | } 26 | 27 | // Initialize the pool with junk if needed. 28 | if(rng_pool == null) { 29 | rng_pool = new Array(); 30 | rng_pptr = 0; 31 | var t; 32 | if(navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) { 33 | // Extract entropy (256 bits) from NS4 RNG if available 34 | var z = window.crypto.random(32); 35 | for(t = 0; t < z.length; ++t) 36 | rng_pool[rng_pptr++] = z.charCodeAt(t) & 255; 37 | } 38 | while(rng_pptr < rng_psize) { // extract some randomness from Math.random() 39 | t = Math.floor(65536 * Math.random()); 40 | rng_pool[rng_pptr++] = t >>> 8; 41 | rng_pool[rng_pptr++] = t & 255; 42 | } 43 | rng_pptr = 0; 44 | rng_seed_time(); 45 | //rng_seed_int(window.screenX); 46 | //rng_seed_int(window.screenY); 47 | } 48 | 49 | function rng_get_byte() { 50 | if(rng_state == null) { 51 | rng_seed_time(); 52 | rng_state = prng_newstate(); 53 | rng_state.init(rng_pool); 54 | for(rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr) 55 | rng_pool[rng_pptr] = 0; 56 | rng_pptr = 0; 57 | //rng_pool = null; 58 | } 59 | // TODO: allow reseeding after first request 60 | return rng_state.next(); 61 | } 62 | 63 | function rng_get_bytes(ba) { 64 | var i; 65 | for(i = 0; i < ba.length; ++i) ba[i] = rng_get_byte(); 66 | } 67 | 68 | function SecureRandom() {} 69 | 70 | SecureRandom.prototype.nextBytes = rng_get_bytes; 71 | -------------------------------------------------------------------------------- /js/security/v2/certificate-request.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx security https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/security/v2/certificate-request.hpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var Interest = require('../../interest.js').Interest; 23 | 24 | /** 25 | * A CertificateRequest represents a request for a certificate, associated with 26 | * the number of retries left. The interest_ and nRetriesLeft_ fields are public 27 | * so that you can modify them. interest_ is the Interest for the requested Data 28 | * packet or Certificate, and nRetriesLeft_ is the number of remaining retries 29 | * after a timeout or NACK. 30 | * 31 | * Create a CertificateRequest with an optional Interest. 32 | * @param {Interest} interest (optional) If supplied, create a 33 | * CertificateRequest with a copy of the interest and 3 retries left. Of omitted, 34 | * create a CertificateRequest with a default Interest object and 0 retries left. 35 | * @constructor 36 | */ 37 | var CertificateRequest = function CertificateRequest(interest) 38 | { 39 | if (interest != undefined) { 40 | this.interest_ = new Interest(interest); 41 | this.nRetriesLeft_ = 3; 42 | } 43 | else { 44 | this.interest_ = new Interest(); 45 | this.nRetriesLeft_ = 0; 46 | } 47 | }; 48 | 49 | exports.CertificateRequest = CertificateRequest; 50 | 51 | -------------------------------------------------------------------------------- /js/encoding/der/der-node-type.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From PyNDN der.py by Adeola Bannis . 5 | * @author: Originally from code in ndn-cxx by Yingdi Yu 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program. If not, see . 19 | * A copy of the GNU Lesser General Public License is in the file COPYING. 20 | */ 21 | 22 | /** 23 | * The DerNodeType enum defines the known DER node types. 24 | */ 25 | var DerNodeType = function DerNodeType() 26 | { 27 | } 28 | 29 | exports.DerNodeType = DerNodeType; 30 | 31 | DerNodeType.Eoc = 0; 32 | DerNodeType.Boolean = 1; 33 | DerNodeType.Integer = 2; 34 | DerNodeType.BitString = 3; 35 | DerNodeType.OctetString = 4; 36 | DerNodeType.Null = 5; 37 | DerNodeType.ObjectIdentifier = 6; 38 | DerNodeType.ObjectDescriptor = 7; 39 | DerNodeType.External = 40; 40 | DerNodeType.Real = 9; 41 | DerNodeType.Enumerated = 10; 42 | DerNodeType.EmbeddedPdv = 43; 43 | DerNodeType.Utf8String = 12; 44 | DerNodeType.RelativeOid = 13; 45 | DerNodeType.Sequence = 48; 46 | DerNodeType.Set = 49; 47 | DerNodeType.NumericString = 18; 48 | DerNodeType.PrintableString = 19; 49 | DerNodeType.T61String = 20; 50 | DerNodeType.VideoTexString = 21; 51 | DerNodeType.Ia5String = 22; 52 | DerNodeType.UtcTime = 23; 53 | DerNodeType.GeneralizedTime = 24; 54 | DerNodeType.GraphicString = 25; 55 | DerNodeType.VisibleString = 26; 56 | DerNodeType.GeneralString = 27; 57 | DerNodeType.UniversalString = 28; 58 | DerNodeType.CharacterString = 29; 59 | DerNodeType.BmpString = 30; 60 | -------------------------------------------------------------------------------- /js/encoding/oid.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From code in ndn-cxx by Yingdi Yu 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** 22 | * @constructor 23 | */ 24 | var OID = function OID(oid) 25 | { 26 | if (typeof oid === 'string') { 27 | var splitString = oid.split("."); 28 | this.oid = []; 29 | for (var i = 0; i < splitString.length; ++i) 30 | this.oid.push(parseInt(splitString[i])); 31 | } 32 | else 33 | // Assume oid is an array of int. Make a copy. 34 | this.oid = oid.slice(0, oid.length); 35 | }; 36 | 37 | exports.OID = OID; 38 | 39 | OID.prototype.getIntegerList = function() 40 | { 41 | return this.oid; 42 | }; 43 | 44 | OID.prototype.setIntegerList = function(oid) 45 | { 46 | // Make a copy. 47 | this.oid = oid.slice(0, oid.length); 48 | }; 49 | 50 | OID.prototype.toString = function() 51 | { 52 | var result = ""; 53 | for (var i = 0; i < this.oid.length; ++i) { 54 | if (i !== 0) 55 | result += "."; 56 | result += this.oid[i]; 57 | } 58 | 59 | return result; 60 | }; 61 | 62 | OID.prototype.equals = function(other) 63 | { 64 | if (!(other instanceof OID)) 65 | return false; 66 | if (this.oid.length !== other.oid.length) 67 | return false; 68 | 69 | for (var i = 0; i < this.oid.length; ++i) { 70 | if (this.oid[i] != other.oid[i]) 71 | return false; 72 | } 73 | return true; 74 | }; 75 | -------------------------------------------------------------------------------- /examples/browser/test-interest-matches-name.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 21 | 22 | 23 | 24 | NDN Interest Matches Name 25 | 26 | 27 | 28 | 40 | 41 | 42 | 43 |
44 | 45 | Please enter the name of an interest:
46 |
47 | 48 | Please enter a name to check if the interest matches the name:
49 |
50 | 51 |
52 | 53 | 54 |

55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /examples/node/test-get-async.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | var Face = require('../..').Face; 21 | var Name = require('../..').Name; 22 | var Interest = require('../..').Interest; 23 | 24 | // Silence the warning from Interest wire encode. 25 | Interest.setDefaultCanBePrefix(true); 26 | 27 | var face = new Face({host: "memoria.ndn.ucla.edu"}); 28 | var callbackCount = 0; 29 | 30 | var onData = function(interest, data) { 31 | console.log("Got data packet with name " + data.getName().toUri()); 32 | console.log(data.getContent().buf().toString('binary')); 33 | 34 | if (++callbackCount >= 3) 35 | // This will cause the script to quit. 36 | face.close(); 37 | }; 38 | 39 | var onTimeout = function(interest) { 40 | console.log("Time out for interest " + interest.getName().toUri()); 41 | 42 | if (++callbackCount >= 3) 43 | // This will cause the script to quit. 44 | face.close(); 45 | }; 46 | 47 | // Try to fetch anything. 48 | var name1 = new Name("/"); 49 | console.log("Express name " + name1.toUri()); 50 | face.expressInterest(name1, onData, onTimeout); 51 | 52 | // Try to fetch using a known name. 53 | var name2 = new Name("/ndn/edu/ucla/remap/demo/ndn-js-test/hello.txt/%FDU%8D%9DM"); 54 | console.log("Express name " + name2.toUri()); 55 | face.expressInterest(name2, onData, onTimeout); 56 | 57 | // Expect this to time out. 58 | var name3 = new Name("/test/timeout"); 59 | console.log("Express name " + name3.toUri()); 60 | face.expressInterest(name3, onData, onTimeout); 61 | -------------------------------------------------------------------------------- /js/transport/transport.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | /** 21 | * Transport is a base class for specific transport classes such as TcpTransport. 22 | * @constructor 23 | */ 24 | var Transport = function Transport() 25 | { 26 | }; 27 | 28 | exports.Transport = Transport; 29 | 30 | /** 31 | * Transport.ConnectionInfo is a base class for connection information used by 32 | * subclasses of Transport. 33 | */ 34 | Transport.ConnectionInfo = function TransportConnectionInfo() 35 | { 36 | }; 37 | 38 | /** 39 | * Determine whether this transport connecting according to connectionInfo is to 40 | * a node on the current machine. This affects the processing of 41 | * Face.registerPrefix(): if the NFD is local, registration occurs with the 42 | * '/localhost/nfd...' prefix; if non-local, the library will attempt to use 43 | * remote prefix registration using '/localhop/nfd...' 44 | * @param {Transport.ConnectionInfo} connectionInfo A ConnectionInfo with the 45 | * host to check. 46 | * @param {function} onResult On success, this calls onResult(isLocal) where 47 | * isLocal is true if the host is local, false if not. We use callbacks because 48 | * this may need to do an asynchronous DNS lookup. 49 | * @param {function} onError On failure for DNS lookup or other error, this 50 | * calls onError(message) where message is an error string. 51 | */ 52 | Transport.prototype.isLocal = function(connectionInfo, onResult, onError) 53 | { 54 | onError("Transport.isLocal is not implemented"); 55 | }; 56 | -------------------------------------------------------------------------------- /js/lp/congestion-mark.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | /** 21 | * CongestionMark represents the congestion mark header field in an NDNLPv2 22 | * packet. 23 | * http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2 24 | * @constructor 25 | */ 26 | var CongestionMark = function CongestionMark() 27 | { 28 | this.congestionMark_ = 0; 29 | }; 30 | 31 | exports.CongestionMark = CongestionMark; 32 | 33 | /** 34 | * Get the congestion mark value. 35 | * @return {number} The congestion mark value. 36 | */ 37 | CongestionMark.prototype.getCongestionMark = function() 38 | { 39 | return this.congestionMark_; 40 | }; 41 | 42 | /** 43 | * Set the congestion mark value. 44 | * @param {number} congestionMark The congestion mark ID value. 45 | */ 46 | CongestionMark.prototype.setCongestionMark = function(congestionMark) 47 | { 48 | this.congestionMark_ = congestionMark; 49 | }; 50 | 51 | /** 52 | * Get the first header field in lpPacket which is a CongestionMark. This is 53 | * an internal method which the application normally would not use. 54 | * @param {LpPacket} lpPacket The LpPacket with the header fields to search. 55 | * @return {CongestionMark} The first CongestionMark header field, or null if 56 | * not found. 57 | */ 58 | CongestionMark.getFirstHeader = function(lpPacket) 59 | { 60 | for (var i = 0; i < lpPacket.countHeaderFields(); ++i) { 61 | var field = lpPacket.getHeaderField(i); 62 | if (field instanceof CongestionMark) 63 | return field; 64 | } 65 | 66 | return null; 67 | }; 68 | -------------------------------------------------------------------------------- /js/lp/incoming-face-id.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx fields.hpp https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/lp/fields.hpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** 22 | * IncomingFaceId represents the incoming face ID header field in an NDNLPv2 packet. 23 | * http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2 24 | * @constructor 25 | */ 26 | var IncomingFaceId = function IncomingFaceId() 27 | { 28 | this.faceId_ = null; 29 | }; 30 | 31 | exports.IncomingFaceId = IncomingFaceId; 32 | 33 | /** 34 | * Get the incoming face ID value. 35 | * @return {number} The face ID value. 36 | */ 37 | IncomingFaceId.prototype.getFaceId = function() { return this.faceId_; }; 38 | 39 | /** 40 | * Set the face ID value. 41 | * @param {number} faceId The incoming face ID value. 42 | */ 43 | IncomingFaceId.prototype.setFaceId = function(faceId) 44 | { 45 | this.faceId_ = faceId; 46 | }; 47 | 48 | /** 49 | * Get the first header field in lpPacket which is an IncomingFaceId. This is 50 | * an internal method which the application normally would not use. 51 | * @param {LpPacket} lpPacket The LpPacket with the header fields to search. 52 | * @return {IncomingFaceId} The first IncomingFaceId header field, or null if 53 | * not found. 54 | */ 55 | IncomingFaceId.getFirstHeader = function(lpPacket) 56 | { 57 | for (var i = 0; i < lpPacket.countHeaderFields(); ++i) { 58 | var field = lpPacket.getHeaderField(i); 59 | if (field instanceof IncomingFaceId) 60 | return field; 61 | } 62 | 63 | return null; 64 | }; 65 | -------------------------------------------------------------------------------- /js/encoding/tlv-wire-format.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2013-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | /** @ignore */ 21 | var WireFormat = require('./wire-format.js').WireFormat; /** @ignore */ 22 | var Tlv0_3WireFormat = require('./tlv-0_3-wire-format.js').Tlv0_3WireFormat; 23 | 24 | /** 25 | * A TlvWireFormat extends WireFormat to override its methods to 26 | * implement encoding and decoding using the preferred implementation of NDN-TLV. 27 | * @constructor 28 | */ 29 | var TlvWireFormat = function TlvWireFormat() 30 | { 31 | // Inherit from Tlv0_3WireFormat. 32 | Tlv0_3WireFormat.call(this); 33 | }; 34 | 35 | TlvWireFormat.prototype = new Tlv0_3WireFormat(); 36 | TlvWireFormat.prototype.name = "TlvWireFormat"; 37 | 38 | exports.TlvWireFormat = TlvWireFormat; 39 | 40 | // Default object. 41 | TlvWireFormat.instance = null; 42 | 43 | /** 44 | * Get a singleton instance of a TlvWireFormat. Assuming that the default 45 | * wire format was set with WireFormat.setDefaultWireFormat(TlvWireFormat.get()), 46 | * you can check if this is the default wire encoding with 47 | * if WireFormat.getDefaultWireFormat() == TlvWireFormat.get(). 48 | * @return {TlvWireFormat} The singleton instance. 49 | */ 50 | TlvWireFormat.get = function() 51 | { 52 | if (TlvWireFormat.instance === null) 53 | TlvWireFormat.instance = new TlvWireFormat(); 54 | return TlvWireFormat.instance; 55 | }; 56 | 57 | // On loading this module, make this the default wire format. 58 | // This module will be loaded because WireFormat loads it. 59 | WireFormat.setDefaultWireFormat(TlvWireFormat.get()); 60 | -------------------------------------------------------------------------------- /examples/node/test-encode-decode-fib-entry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | var ProtoBuf = require("protobufjs"); 21 | var ProtobufTlv = require('../..').ProtobufTlv; 22 | 23 | var builder = ProtoBuf.loadProtoFile("../browser/fib-entry.proto"); 24 | var descriptor = builder.lookup("ndn_message.FibEntryMessage"); 25 | var FibEntryMessage = descriptor.build(); 26 | var message = new FibEntryMessage(); 27 | message.fib_entry = new FibEntryMessage.FibEntry(); 28 | message.fib_entry.name = new FibEntryMessage.Name(); 29 | message.fib_entry.name.add("component", new Buffer("ndn")); 30 | message.fib_entry.name.add("component", new Buffer("ucla")); 31 | var nextHopRecord = new FibEntryMessage.NextHopRecord(); 32 | message.fib_entry.add("next_hop_records", nextHopRecord); 33 | nextHopRecord.face_id = 16; 34 | nextHopRecord.cost = 1; 35 | 36 | // Encode the Protobuf message object as TLV. 37 | var encoding = ProtobufTlv.encode(message, descriptor); 38 | 39 | var decodedMessage = new FibEntryMessage(); 40 | ProtobufTlv.decode(decodedMessage, descriptor, encoding); 41 | 42 | console.log("Re-decoded FibEntry:"); 43 | // This should print the same values that we put in message above. 44 | var value = ""; 45 | value += ProtobufTlv.toName(decodedMessage.fib_entry.name.component).toUri(); 46 | value += " nexthops = {"; 47 | for (var i = 0; i < decodedMessage.fib_entry.next_hop_records.length; ++i) 48 | value += "faceid=" + decodedMessage.fib_entry.next_hop_records[i].face_id 49 | + " (cost=" + decodedMessage.fib_entry.next_hop_records[i].cost + ")"; 50 | value += " }"; 51 | console.log(value); 52 | -------------------------------------------------------------------------------- /ndn-protocol/modules/ndn-js-header.txt: -------------------------------------------------------------------------------- 1 | /* This file is created by running make-ndn-js.jsm.sh in this directory. 2 | * It concatenates ndn-js-header.txt with all the ndn-js source files to 3 | * make ndn-js.jsm . 4 | * The file ../../build/ndn.min.js must already be built. 5 | * 6 | * Copyright (C) 2013-2019 Regents of the University of California. 7 | * author: Jeff Thompson 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | * A copy of the GNU Lesser General Public License is in the file COPYING. 22 | */ 23 | 24 | var EXPORTED_SYMBOLS = ["Data", "DataUtils", "Exclude", "ExponentialReExpress", 25 | "Interest", "MimeTypes", "Face", "Name", "Sha256", "XpcomTransport", "Buffer"]; 26 | 27 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 28 | Components.utils.import("resource://gre/modules/NetUtil.jsm"); 29 | 30 | // jsbn.js needs the navigator object which isn't defined in XPCOM, so make a local hack. 31 | var navigator = { 32 | appName: "Netscape" 33 | }; 34 | 35 | // Some code calls console.log without checking LOG>0. Until this is cleaned up, make a local hack console. 36 | var console = { 37 | log: function(message) { 38 | dump(message); 39 | dump("\n"); 40 | } 41 | }; 42 | 43 | // The Face class uses setTimeout and clearTimeout, so define them using XPCOM. 44 | function setTimeout(callback, delay) { 45 | var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer); 46 | timer.initWithCallback({notify: callback}, delay, Components.interfaces.nsITimer.TYPE_ONE_SHOT); 47 | return timer; 48 | } 49 | 50 | function clearTimeout(timer) { 51 | timer.cancel(); 52 | } 53 | 54 | // Set self so that Dexie in ndn.min.js can set properties (although this add-on doesn't use Dexie). 55 | var self = {}; 56 | -------------------------------------------------------------------------------- /contrib/feross/ieee754.js: -------------------------------------------------------------------------------- 1 | var ieee = {}; 2 | 3 | ieee.read = function(buffer, offset, isLE, mLen, nBytes) { 4 | var e, m, 5 | eLen = nBytes * 8 - mLen - 1, 6 | eMax = (1 << eLen) - 1, 7 | eBias = eMax >> 1, 8 | nBits = -7, 9 | i = isLE ? (nBytes - 1) : 0, 10 | d = isLE ? -1 : 1, 11 | s = buffer[offset + i]; 12 | 13 | i += d; 14 | 15 | e = s & ((1 << (-nBits)) - 1); 16 | s >>= (-nBits); 17 | nBits += eLen; 18 | for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); 19 | 20 | m = e & ((1 << (-nBits)) - 1); 21 | e >>= (-nBits); 22 | nBits += mLen; 23 | for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); 24 | 25 | if (e === 0) { 26 | e = 1 - eBias; 27 | } else if (e === eMax) { 28 | return m ? NaN : ((s ? -1 : 1) * Infinity); 29 | } else { 30 | m = m + Math.pow(2, mLen); 31 | e = e - eBias; 32 | } 33 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen); 34 | }; 35 | 36 | ieee.write = function(buffer, value, offset, isLE, mLen, nBytes) { 37 | var e, m, c, 38 | eLen = nBytes * 8 - mLen - 1, 39 | eMax = (1 << eLen) - 1, 40 | eBias = eMax >> 1, 41 | rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0), 42 | i = isLE ? 0 : (nBytes - 1), 43 | d = isLE ? 1 : -1, 44 | s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; 45 | 46 | value = Math.abs(value); 47 | 48 | if (isNaN(value) || value === Infinity) { 49 | m = isNaN(value) ? 1 : 0; 50 | e = eMax; 51 | } else { 52 | e = Math.floor(Math.log(value) / Math.LN2); 53 | if (value * (c = Math.pow(2, -e)) < 1) { 54 | e--; 55 | c *= 2; 56 | } 57 | if (e + eBias >= 1) { 58 | value += rt / c; 59 | } else { 60 | value += rt * Math.pow(2, 1 - eBias); 61 | } 62 | if (value * c >= 2) { 63 | e++; 64 | c /= 2; 65 | } 66 | 67 | if (e + eBias >= eMax) { 68 | m = 0; 69 | e = eMax; 70 | } else if (e + eBias >= 1) { 71 | m = (value * c - 1) * Math.pow(2, mLen); 72 | e = e + eBias; 73 | } else { 74 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); 75 | e = 0; 76 | } 77 | } 78 | 79 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); 80 | 81 | e = (e << mLen) | m; 82 | eLen += mLen; 83 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8); 84 | 85 | buffer[offset + i - d] |= s * 128; 86 | }; 87 | 88 | exports.ieee = ieee; 89 | -------------------------------------------------------------------------------- /tests/node/unit-tests/test-control-response.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016-2019 Regents of the University of California. 3 | * @author Andrew Brown 4 | * @author: Jeff Thompson 5 | * From jNDN TestControlResponse. 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version, with the additional exemption that 11 | * compiling, linking, and/or using OpenSSL is allowed. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program. If not, see . 20 | * A copy of the GNU Lesser General Public License is in the file COPYING. 21 | */ 22 | 23 | var assert = require('assert'); 24 | var Blob = require('../../..').Blob; 25 | var ControlParameters = require('../../..').ControlParameters; 26 | var ControlResponse = require('../../..').ControlResponse; 27 | 28 | var TestControlResponse1 = new Buffer([ 29 | 0x65, 0x1c, // ControlResponse 30 | 0x66, 0x02, 0x01, 0x94, // StatusCode 31 | 0x67, 0x11, // StatusText 32 | 0x4e, 0x6f, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x6f, 0x74, 0x20, 33 | 0x66, 0x6f, 0x75, 0x6e, 0x64, 34 | 0x68, 0x03, // ControlParameters 35 | 0x69, 0x01, 0x0a // FaceId 36 | ]); 37 | 38 | describe('ControlResponse', function() { 39 | it('encode', function() { 40 | var response = new ControlResponse(); 41 | response.setStatusCode(404); 42 | response.setStatusText("Nothing not found"); 43 | response.setBodyAsControlParameters(new ControlParameters()); 44 | response.getBodyAsControlParameters().setFaceId(10); 45 | var wire = response.wireEncode(); 46 | 47 | assert.ok(wire.equals(new Blob(TestControlResponse1, false))); 48 | }); 49 | 50 | it('decode', function() { 51 | var response = new ControlResponse(); 52 | response.wireDecode(TestControlResponse1); 53 | 54 | assert.equal(response.getStatusCode(), 404); 55 | assert.equal(response.getStatusText(), "Nothing not found"); 56 | assert.equal(response.getBodyAsControlParameters().getFaceId(), 10); 57 | }); 58 | }); 59 | -------------------------------------------------------------------------------- /examples/browser/test-websocket.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 21 | 22 | 23 | 24 | Test WebSocket Support 25 | 26 | 60 | 61 | 62 | 63 | 64 | 65 |

Result here:

66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /examples/browser/test-throughput-http.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 21 | 22 | 23 | 24 | 25 | HTTP Get via XHR 26 | 27 | 28 | 29 | 48 | 49 | 50 | 51 | 52 |
53 | Please Enter an Interest:
54 | 55 |
56 | 57 | 58 | 59 |

Result:

60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /js/util/regex/ndn-regex-backref-matcher.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2017-2019 Regents of the University of California. 3 | * @author: Yingdi Yu 4 | * @author: Jeff Thompson 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var NdnRegexMatcherBase = require('./ndn-regex-matcher-base.js').NdnRegexMatcherBase; 23 | 24 | /** 25 | * Create an NdnRegexBackrefMatcher. 26 | * @param {string} expr 27 | * @param {NdnRegexBackrefManager} backrefManager The back-reference manager. 28 | * @constructor 29 | */ 30 | var NdnRegexBackrefMatcher = function NdnRegexBackrefMatcher 31 | (expr, backrefManager) 32 | { 33 | // Call the base constructor. 34 | NdnRegexMatcherBase.call 35 | (this, expr, NdnRegexMatcherBase.NdnRegexExprType.BACKREF, backrefManager); 36 | }; 37 | 38 | NdnRegexBackrefMatcher.prototype = new NdnRegexMatcherBase(); 39 | NdnRegexBackrefMatcher.prototype.name = "NdnRegexBackrefMatcher"; 40 | 41 | exports.NdnRegexBackrefMatcher = NdnRegexBackrefMatcher; 42 | 43 | NdnRegexBackrefMatcher.prototype.lateCompile = function() 44 | { 45 | this.compile_(); 46 | }; 47 | 48 | NdnRegexBackrefMatcher.prototype.compile_ = function() 49 | { 50 | if (this.expr_.length < 2) 51 | throw new NdnRegexMatcherBase.Error(new Error 52 | ("Unrecognized format: " + this.expr_)); 53 | 54 | var lastIndex = this.expr_.length - 1; 55 | if ('(' === this.expr_[0] && ')' === this.expr_[lastIndex]) { 56 | var matcher = new NdnRegexPatternListMatcher 57 | (this.expr_.substring(1, lastIndex), this.backrefManager_); 58 | this.matchers_.push(matcher); 59 | } 60 | else 61 | throw new NdnRegexMatcherBase.Error(new Error 62 | ("Unrecognized format: " + this.expr_)); 63 | }; 64 | 65 | // Put this last to avoid a require loop. 66 | /** @ignore */ 67 | var NdnRegexPatternListMatcher = require('./ndn-regex-pattern-list-matcher.js').NdnRegexPatternListMatcher; 68 | -------------------------------------------------------------------------------- /examples/firefly/firefly-chat/chatbuf.js: -------------------------------------------------------------------------------- 1 | var SyncDemo = dcodeIO.ProtoBuf.newBuilder().import({ 2 | "package": "SyncDemo", 3 | "messages": [ 4 | { 5 | "name": "ChatMessage", 6 | "fields": [ 7 | { 8 | "rule": "required", 9 | "type": "string", 10 | "name": "to", 11 | "id": 1, 12 | "options": {} 13 | }, 14 | { 15 | "rule": "required", 16 | "type": "string", 17 | "name": "from", 18 | "id": 2, 19 | "options": {} 20 | }, 21 | { 22 | "rule": "required", 23 | "type": "ChatMessageType", 24 | "name": "type", 25 | "id": 3, 26 | "options": { 27 | "default": "CHAT" 28 | } 29 | }, 30 | { 31 | "rule": "optional", 32 | "type": "string", 33 | "name": "data", 34 | "id": 4, 35 | "options": {} 36 | }, 37 | { 38 | "rule": "required", 39 | "type": "int32", 40 | "name": "timestamp", 41 | "id": 5, 42 | "options": {} 43 | } 44 | ], 45 | "enums": [ 46 | { 47 | "name": "ChatMessageType", 48 | "values": [ 49 | { 50 | "name": "CHAT", 51 | "id": 0 52 | }, 53 | { 54 | "name": "HELLO", 55 | "id": 1 56 | }, 57 | { 58 | "name": "LEAVE", 59 | "id": 2 60 | }, 61 | { 62 | "name": "JOIN", 63 | "id": 3 64 | }, 65 | { 66 | "name": "OTHER", 67 | "id": 4 68 | } 69 | ], 70 | "options": {} 71 | } 72 | ], 73 | "messages": [], 74 | "options": {} 75 | } 76 | ], 77 | "enums": [], 78 | "imports": [], 79 | "options": {} 80 | }).build("SyncDemo") 81 | -------------------------------------------------------------------------------- /examples/browser/test-get-async.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 21 | 22 | 23 | 24 | 25 | NDN Get via WebSocket 26 | 27 | 28 | 29 | 54 | 55 | 56 | 57 | 58 |
59 | Please Enter an Interest:
60 | 61 |
62 | 63 | 64 | 65 |

Content:

66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /js/security/certificate/certificate-subject-description.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * From ndn-cxx security by Yingdi Yu . 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var Blob = require('../../util/blob.js').Blob; /** @ignore */ 23 | var OID = require('../../encoding/oid.js').OID; /** @ignore */ 24 | var DerNode = require('../../encoding/der/der-node.js').DerNode; 25 | 26 | /** 27 | * A CertificateSubjectDescription represents the SubjectDescription entry in a 28 | * Certificate. 29 | * Create a new CertificateSubjectDescription. 30 | * @param {string|OID} oid The oid of the subject description entry. 31 | * @param {string} value The value of the subject description entry. 32 | * @constructor 33 | */ 34 | var CertificateSubjectDescription = function CertificateSubjectDescription 35 | (oid, value) 36 | { 37 | if (typeof oid === 'string') 38 | this.oid = new OID(oid); 39 | else 40 | // Assume oid is already an OID. 41 | this.oid = oid; 42 | 43 | this.value = value; 44 | }; 45 | 46 | exports.CertificateSubjectDescription = CertificateSubjectDescription; 47 | 48 | /** 49 | * Encode the object into a DER syntax tree. 50 | * @return {DerNode} The encoded DER syntax tree. 51 | */ 52 | CertificateSubjectDescription.prototype.toDer = function() 53 | { 54 | var root = new DerNode.DerSequence(); 55 | 56 | var oid = new DerNode.DerOid(this.oid); 57 | // Use Blob to convert the String to a ByteBuffer. 58 | var value = new DerNode.DerPrintableString(new Blob(this.value).buf()); 59 | 60 | root.addChild(oid); 61 | root.addChild(value); 62 | 63 | return root; 64 | }; 65 | 66 | CertificateSubjectDescription.prototype.getOidString = function() 67 | { 68 | return this.oid.toString(); 69 | }; 70 | 71 | CertificateSubjectDescription.prototype.getValue = function() 72 | { 73 | return this.value; 74 | }; 75 | -------------------------------------------------------------------------------- /examples/node/test-chrono-chat-protobuf.js: -------------------------------------------------------------------------------- 1 | var ProtoBuf = require("protobufjs"); 2 | 3 | var SyncDemo = ProtoBuf.newBuilder().import({ 4 | "package": "SyncDemo", 5 | "messages": [ 6 | { 7 | "name": "ChatMessage", 8 | "fields": [ 9 | { 10 | "rule": "required", 11 | "type": "string", 12 | "name": "to", 13 | "id": 1, 14 | "options": {} 15 | }, 16 | { 17 | "rule": "required", 18 | "type": "string", 19 | "name": "from", 20 | "id": 2, 21 | "options": {} 22 | }, 23 | { 24 | "rule": "required", 25 | "type": "ChatMessageType", 26 | "name": "type", 27 | "id": 3, 28 | "options": { 29 | "default": "CHAT" 30 | } 31 | }, 32 | { 33 | "rule": "optional", 34 | "type": "string", 35 | "name": "data", 36 | "id": 4, 37 | "options": {} 38 | }, 39 | { 40 | "rule": "required", 41 | "type": "int32", 42 | "name": "timestamp", 43 | "id": 5, 44 | "options": {} 45 | } 46 | ], 47 | "enums": [ 48 | { 49 | "name": "ChatMessageType", 50 | "values": [ 51 | { 52 | "name": "CHAT", 53 | "id": 0 54 | }, 55 | { 56 | "name": "HELLO", 57 | "id": 1 58 | }, 59 | { 60 | "name": "LEAVE", 61 | "id": 2 62 | }, 63 | { 64 | "name": "JOIN", 65 | "id": 3 66 | }, 67 | { 68 | "name": "OTHER", 69 | "id": 4 70 | } 71 | ], 72 | "options": {} 73 | } 74 | ], 75 | "messages": [], 76 | "options": {} 77 | } 78 | ], 79 | "enums": [], 80 | "imports": [], 81 | "options": {} 82 | }).build("SyncDemo"); 83 | 84 | exports.ChatMessage = SyncDemo.ChatMessage; -------------------------------------------------------------------------------- /examples/browser/noconflict.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | ndn.noConflict() example 21 |

ndn.noConflict() example

22 |

identifiers in global namespace before importing ndn-js.

23 |

identifiers in global namespace after importing ndn-js.

24 |

identifiers in global namespace after ndn.noConflict(). New identifiers:

25 | 30 | 31 | 41 | 42 |

Express Interest test:

43 | 51 | -------------------------------------------------------------------------------- /examples/node/test-encode-decode-benchmark.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | var TestEncodeDecodeBenchmark = require("../browser/test-encode-decode-benchmark.js").TestEncodeDecodeBenchmark; 21 | 22 | /** 23 | * Call benchmarkEncodeDataSeconds and benchmarkDecodeDataSeconds with appropriate nInterations. Print the 24 | * results to console.log. 25 | * @param {boolean} useComplex See benchmarkEncodeDataSeconds. 26 | * @param {boolean} useCrypto See benchmarkEncodeDataSeconds and benchmarkDecodeDataSeconds. 27 | * @param {function} onFinished When finished, call onFinished(). It is necessary 28 | * to use a callback because the crypto functions use callbacks. 29 | */ 30 | function benchmarkEncodeDecodeData(useComplex, useCrypto, onFinished) 31 | { 32 | var format = "TLV"; 33 | var nEncodeIterations = useCrypto ? 2000 : 500000; 34 | TestEncodeDecodeBenchmark.benchmarkEncodeDataSeconds 35 | (nEncodeIterations, useComplex, useCrypto, function(duration, encoding) { 36 | console.log("Encode " + (useComplex ? "complex " : "simple ") + format + " data: Crypto? " + (useCrypto ? "RSA" : "no ") 37 | + ", Duration sec, Hz: " + duration + ", " + (nEncodeIterations / duration)); 38 | 39 | var nDecodeIterations = useCrypto ? 20000 : 300000; 40 | TestEncodeDecodeBenchmark.benchmarkDecodeDataSeconds 41 | (nDecodeIterations, useCrypto, encoding, function(duration) { 42 | console.log("Decode " + (useComplex ? "complex " : "simple ") + format + " data: Crypto? " + (useCrypto ? "RSA" : "no ") 43 | + ", Duration sec, Hz: " + duration + ", " + (nDecodeIterations / duration)); 44 | onFinished(); 45 | }); 46 | }); 47 | } 48 | 49 | benchmarkEncodeDecodeData(false, false, function() { 50 | benchmarkEncodeDecodeData(true, false, function() { 51 | benchmarkEncodeDecodeData(false, true, function() { 52 | benchmarkEncodeDecodeData(true, true, function() {}); 53 | }); 54 | }); 55 | }); 56 | -------------------------------------------------------------------------------- /tests/node/integration-tests/test-validator-null.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * From ndn-cxx unit tests: 5 | * https://github.com/named-data/ndn-cxx/blob/master/tests/unit-tests/security/validator-null.t.cpp 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version, with the additional exemption that 11 | * compiling, linking, and/or using OpenSSL is allowed. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program. If not, see . 20 | * A copy of the GNU Lesser General Public License is in the file COPYING. 21 | */ 22 | 23 | var assert = require("assert"); 24 | var Name = require('../../..').Name; 25 | var Data = require('../../..').Data; 26 | var Interest = require('../../..').Interest; 27 | var SigningInfo = require('../../..').SigningInfo; 28 | var ValidatorNull = require('../../..').ValidatorNull; 29 | var IdentityManagementFixture = require('./identity-management-fixture.js').IdentityManagementFixture; 30 | 31 | describe ("TestValidatorNull", function() { 32 | beforeEach(function() { 33 | this.fixture_ = new IdentityManagementFixture(); 34 | }); 35 | 36 | it("ValidateData", function() { 37 | var identity = this.fixture_.addIdentity(new Name("/TestValidator/Null")); 38 | var data = new Data(new Name("/Some/Other/Data/Name")); 39 | this.fixture_.keyChain_.sign(data, new SigningInfo(identity)); 40 | 41 | var validator = new ValidatorNull(); 42 | validator.validate 43 | (data, function(data) { 44 | // Should succeed. 45 | }, function(data, error) { 46 | assert.fail("Validation should not have failed"); 47 | }); 48 | }); 49 | 50 | it("ValidateInterest", function() { 51 | var identity = this.fixture_.addIdentity(new Name("/TestValidator/Null")); 52 | var interest = new Interest(new Name("/Some/Other/Interest/Name")); 53 | this.fixture_.keyChain_.sign(interest, new SigningInfo(identity)); 54 | 55 | var validator = new ValidatorNull(); 56 | validator.validate 57 | (interest, function(interest) { 58 | // Should succeed. 59 | }, function(interest, error) { 60 | assert.fail("Validation should not have failed"); 61 | }); 62 | }); 63 | }); 64 | -------------------------------------------------------------------------------- /tests/node/integration-tests/hierarchical-validator-fixture.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * From ndn-cxx unit tests: 5 | * https://github.com/named-data/ndn-cxx/blob/master/tests/unit-tests/validator-fixture.cpp 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version, with the additional exemption that 11 | * compiling, linking, and/or using OpenSSL is allowed. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program. If not, see . 20 | * A copy of the GNU Lesser General Public License is in the file COPYING. 21 | */ 22 | 23 | var Name = require('../../..').Name; 24 | var CertificateV2 = require('../../..').CertificateV2; 25 | var ValidationPolicyAcceptAll = require('../../..').ValidationPolicyAcceptAll; 26 | var ValidatorFixture = require('./validator-fixture.js').ValidatorFixture; 27 | 28 | /** 29 | * @param {ValidationPolicy} policy 30 | * @constructor 31 | */ 32 | var HierarchicalValidatorFixture = function HierarchicalValidatorFixture(policy) 33 | { 34 | // Call the base constructor. 35 | ValidatorFixture.call(this, policy); 36 | 37 | this.identity_ = this.addIdentity(new Name("/Security/V2/ValidatorFixture")); 38 | this.subIdentity_ = this.addSubCertificate 39 | (new Name("/Security/V2/ValidatorFixture/Sub1"), this.identity_); 40 | this.subSelfSignedIdentity_ = this.addIdentity 41 | (new Name("/Security/V2/ValidatorFixture/Sub1/Sub2")); 42 | this.otherIdentity_ = this.addIdentity(new Name("/Security/V2/OtherIdentity")); 43 | 44 | this.validator_.loadAnchor 45 | ("", new CertificateV2(this.identity_.getDefaultKey().getDefaultCertificate())); 46 | 47 | this.cache_.insert(this.identity_.getDefaultKey().getDefaultCertificate()); 48 | this.cache_.insert(this.subIdentity_.getDefaultKey().getDefaultCertificate()); 49 | this.cache_.insert(this.subSelfSignedIdentity_.getDefaultKey().getDefaultCertificate()); 50 | this.cache_.insert(this.otherIdentity_.getDefaultKey().getDefaultCertificate()); 51 | }; 52 | 53 | HierarchicalValidatorFixture.prototype = new ValidatorFixture 54 | (new ValidationPolicyAcceptAll()); 55 | HierarchicalValidatorFixture.prototype.name = "HierarchicalValidatorFixture"; 56 | 57 | exports.HierarchicalValidatorFixture = HierarchicalValidatorFixture; 58 | -------------------------------------------------------------------------------- /js/util/ndn-common.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Encapsulate a Buffer and support dynamic reallocation. 3 | * Copyright (C) 2015-2019 Regents of the University of California. 4 | * @author: Jeff Thompson 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var printStackTrace = require('../../contrib/stacktrace/stacktrace.js').printStackTrace; 23 | 24 | /** 25 | * NdnCommon has static NDN utility methods and constants. 26 | * @constructor 27 | */ 28 | var NdnCommon = {}; 29 | 30 | exports.NdnCommon = NdnCommon; 31 | 32 | /** 33 | * The practical limit of the size of a network-layer packet. If a packet is 34 | * larger than this, the library or application MAY drop it. This constant is 35 | * defined in this low-level class so that internal code can use it, but 36 | * applications should use the static API method 37 | * Face.getMaxNdnPacketSize() which is equivalent. 38 | */ 39 | NdnCommon.MAX_NDN_PACKET_SIZE = 8800; 40 | 41 | /** 42 | * Get the error message plus its stack trace. 43 | * @param {Error} error The error object. 44 | * @return {string} The error message, plus the stack trace with each line 45 | * separated by '\n'. 46 | */ 47 | NdnCommon.getErrorWithStackTrace = function(error) 48 | { 49 | return error + '\n' + printStackTrace({e: error}).join('\n'); 50 | }; 51 | 52 | /** 53 | * Check for Indexed DB support and call onComplete with the result as described 54 | * below. This has to use an onComplete callback since IndexedDB is async. 55 | * @param {function} onComplete This calls onComplete(haveIndexedDb) where 56 | * haveIndexedDb is true if the browser has Indexed DB support, otherwise false. 57 | */ 58 | NdnCommon.checkIndexedDb = function(onComplete) 59 | { 60 | try { 61 | var database = new Dexie("test-Dexie-support"); 62 | database.version(1).stores({}); 63 | database.open(); 64 | 65 | // Give Dexie a little time to open. 66 | setTimeout(function() { 67 | try { 68 | onComplete(database.isOpen()); 69 | } catch (ex) { 70 | onComplete(false); 71 | } 72 | }, 200); 73 | } catch (ex) { 74 | onComplete(false); 75 | } 76 | }; 77 | -------------------------------------------------------------------------------- /js/security/v2/validation-policy-simple-hierarchy.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx security https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/security/v2/validation-policy-simple-hierarchy.hpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var CertificateRequest = require('./certificate-request.js').CertificateRequest; /** @ignore */ 23 | var ValidationError = require('./validation-error.js').ValidationError; /** @ignore */ 24 | var Interest = require('../../interest.js').Interest; /** @ignore */ 25 | var ValidationPolicy = require('./validation-policy.js').ValidationPolicy; 26 | 27 | /** 28 | * ValidationPolicySimpleHierarchy extends ValidationPolicy to implement a 29 | * Validation policy for a simple hierarchical trust model. 30 | * @constructor 31 | */ 32 | var ValidationPolicySimpleHierarchy = function ValidationPolicySimpleHierarchy() 33 | { 34 | // Call the base constructor. 35 | ValidationPolicy.call(this); 36 | }; 37 | 38 | ValidationPolicySimpleHierarchy.prototype = new ValidationPolicy(); 39 | ValidationPolicySimpleHierarchy.prototype.name = "ValidationPolicySimpleHierarchy"; 40 | 41 | exports.ValidationPolicySimpleHierarchy = ValidationPolicySimpleHierarchy; 42 | 43 | /** 44 | * @param {Data|Interest} dataOrInterest 45 | * @param {ValidationState} state 46 | * @param {function} continueValidation 47 | */ 48 | ValidationPolicySimpleHierarchy.prototype.checkPolicy = function 49 | (dataOrInterest, state, continueValidation) 50 | { 51 | keyLocatorName = ValidationPolicy.getKeyLocatorName(dataOrInterest, state); 52 | if (state.isOutcomeFailed()) 53 | // Already called state.fail().) 54 | return; 55 | 56 | if (keyLocatorName.getPrefix(-2).isPrefixOf(dataOrInterest.getName())) 57 | continueValidation(new CertificateRequest(new Interest(keyLocatorName)), state); 58 | else 59 | state.fail(new ValidationError(ValidationError.INVALID_KEY_LOCATOR, 60 | "Signing policy violation for " + dataOrInterest.getName().toUri() + 61 | " by " + keyLocatorName.toUri())); 62 | }; 63 | -------------------------------------------------------------------------------- /js/security/v2/static-trust-anchor-group.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx security https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/security/v2/trust-anchor-group.cpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var TrustAnchorGroup = require('./trust-anchor-group.js').TrustAnchorGroup; 23 | 24 | /** 25 | * The StaticTrustAnchorGroup class extends TrustAnchorGroup to implement a 26 | * static trust anchor group. 27 | * 28 | * Create a StaticTrustAnchorGroup to use an existing container. 29 | * @param {CertificateContainer} certificateContainer The existing certificate 30 | * container which implements the CertificateContainer interface. 31 | * @param {string} id The group ID. 32 | * @constructor 33 | */ 34 | var StaticTrustAnchorGroup = function StaticTrustAnchorGroup 35 | (certificateContainer, id) 36 | { 37 | // Call the base constructor. 38 | TrustAnchorGroup.call(this, certificateContainer, id); 39 | }; 40 | 41 | StaticTrustAnchorGroup.prototype = new TrustAnchorGroup(); 42 | StaticTrustAnchorGroup.prototype.name = "StaticTrustAnchorGroup"; 43 | 44 | exports.StaticTrustAnchorGroup = StaticTrustAnchorGroup; 45 | 46 | /** 47 | * Load the static anchor certificate. If a certificate with the name is already 48 | * added, do nothing. 49 | * @param {CertificateV2} certificate The certificate to add, which is copied. 50 | */ 51 | StaticTrustAnchorGroup.prototype.add = function(certificate) 52 | { 53 | var certificateNameUri = certificate.getName().toUri(); 54 | if (this.anchorNameUris_[certificateNameUri]) 55 | return; 56 | 57 | this.anchorNameUris_[certificateNameUri] = true; 58 | // This copies the certificate. 59 | this.certificates_.add(certificate); 60 | }; 61 | 62 | /** 63 | * Remove the static anchor with the certificate name. 64 | * @param {Name} certificateName The certificate name. 65 | */ 66 | StaticTrustAnchorGroup.prototype.remove = function(certificateName) 67 | { 68 | delete this.anchorNameUris_[certificateName.toUri()]; 69 | this.certificates_.remove(certificateName); 70 | }; 71 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | NDN-JS: A javascript client library for Named Data Networking 2 | ------------------------------------------------------------- 3 | 4 | BASIC LIBRARY: NO BUILD REQUIRED 5 | ================================ 6 | The basic NDN-JS library does not need to be "built". To use the library in the 7 | browser, include build/ndn.js. See the examples in examples/browser. 8 | 9 | To use the library in Node.js, require index.js at the top of the distribution tree. 10 | See the examples programs in examples/node. 11 | 12 | BUILD A COMBINED, COMPRESSED LIBRARY 13 | ==================================== 14 | 15 | While the combined file ndn.js is useful for debugging, a more efficient way to include the library 16 | is to used the combined, compressed library build/ndn.min.js. 17 | While we try to keep a built version in that directory for convenience, it 18 | may fall out of sync with the library, so we recommend building it as follows if possible. 19 | To build ndn.min.js, Java must be installed. 20 | 21 | To create a combined and compressed versions of NDN-JS scripts: 22 | 23 | ./waf configure 24 | ./waf 25 | 26 | These commands will create a combined version build/ndn.js, and combined version build/ndn.min.js, compressed 27 | using Google's Closure Compiler. 28 | 29 | The compressed version is what we recommend including in applications. 30 | 31 | DOCUMENTATION 32 | ============= 33 | The documentation is auto-generated using JSDoc. If you don't have JSDoc installed, in a terminal enter: 34 | 35 | sudo npm install -g jsdoc 36 | 37 | To make documentation, cd to the root directory of ndn-js and run the following command to put the output in subdirectory doc: 38 | 39 | npm run doc 40 | 41 | WEBSOCKETS PROXY 42 | ================ 43 | 44 | If you wish to run your own WebSockets proxy instead of using the NDN testbed, you must 45 | build and install Node.js (often on the machine also running the ndnd you wish to proxy 46 | for, but that doesn't have to be the case). See wsproxy/README.md 47 | 48 | THE FIREFOX ADD-ON 49 | ================== 50 | 51 | To use the Firefox Add-On, you don't need to build it. To install, in Firefox, open 52 | Tools > Add-ons. In the "gear" or "wrench" menu, click Install Add-on From File and open 53 | ndn-protocol.xpi. (In Firefox for Android, type file: in the address bar and click the 54 | downloaded ndn-protocol.xpi.) Restart Firefox. 55 | 56 | If you want to build ndn-protocol.xpi, first build ndn.min.js, the compressed version of NDN.js. 57 | To build ndn.min.js, Java must be installed. 58 | 59 | ./waf configure 60 | ./waf 61 | 62 | Then go to the ndn-protocol directory and run ./make-ndn-protocol.sh which makes ndn-protocol.xpi in the top directory. 63 | Firefox now requires add-ons to be signed, but for development you can temporarily disable this as follows: 64 | 65 | * Type about:config into the URL bar in Firefox 66 | * In the Search box type xpinstall.signatures.required 67 | * Right-click and select "Toggle" to set it to false 68 | -------------------------------------------------------------------------------- /js/security/certificate/certificate-extension.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * From ndn-cxx security by Yingdi Yu . 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var DerNode = require('../../encoding/der/der-node.js').DerNode; /** @ignore */ 23 | var OID = require('../../encoding/oid.js').OID; 24 | 25 | /** 26 | * A CertificateExtension represents the Extension entry in a certificate. 27 | * Create a new CertificateExtension. 28 | * @param {string|OID} oid The oid of subject description entry. 29 | * @param {boolean} isCritical If true, the extension must be handled. 30 | * @param {Blob} value The extension value. 31 | * @constructor 32 | */ 33 | var CertificateExtension = function CertificateExtension(oid, isCritical, value) 34 | { 35 | if (typeof oid === 'string') 36 | this.extensionId = new OID(oid); 37 | else 38 | // Assume oid is already an OID. 39 | this.extensionId = oid; 40 | 41 | this.isCritical = isCritical; 42 | this.extensionValue = value; 43 | }; 44 | 45 | exports.CertificateExtension = CertificateExtension; 46 | 47 | /** 48 | * Encode the object into a DER syntax tree. 49 | * @return {DerNode} The encoded DER syntax tree. 50 | */ 51 | CertificateExtension.prototype.toDer = function() 52 | { 53 | var root = new DerNode.DerSequence(); 54 | 55 | var extensionId = new DerNode.DerOid(this.extensionId); 56 | var isCritical = new DerNode.DerBoolean(this.isCritical); 57 | var extensionValue = new DerNode.DerOctetString(this.extensionValue.buf()); 58 | 59 | root.addChild(extensionId); 60 | root.addChild(isCritical); 61 | root.addChild(extensionValue); 62 | 63 | root.getSize(); 64 | 65 | return root; 66 | }; 67 | 68 | CertificateExtension.prototype.toDerBlob = function() 69 | { 70 | return this.toDer().encode(); 71 | }; 72 | 73 | CertificateExtension.prototype.getOid = function() 74 | { 75 | return this.extensionId; 76 | }; 77 | 78 | CertificateExtension.prototype.getIsCritical = function() 79 | { 80 | return this.isCritical; 81 | }; 82 | 83 | CertificateExtension.prototype.getValue = function() 84 | { 85 | return this.extensionValue; 86 | }; 87 | -------------------------------------------------------------------------------- /examples/node/test-pipeline.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Chavoosh Ghasemi 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | var Face = require('../..').Face; 21 | var Name = require('../..').Name; 22 | var Interest = require('../..').Interest; 23 | var SegmentFetcher = require('../..').SegmentFetcher; 24 | var Log = require('../../js/log.js').Log; 25 | 26 | // Silence the warning from Interest wire encode. 27 | Interest.setDefaultCanBePrefix(true); 28 | 29 | //var face = new Face({host: "memoria.ndn.ucla.edu"}); 30 | var callbackCount = 1; 31 | 32 | var onComplete = function(content) { 33 | console.log("Successfully received the content"); 34 | }; 35 | 36 | // Try to fetch a remote file using Fixed pipeline 37 | var name1 = new Name("/ndn/edu/ucla/remap/demo/ndn-js-test/hello.txt/%FDU%8D%9DM"); 38 | console.log("Express name " + name1.toUri()); 39 | SegmentFetcher.fetch 40 | (new Face({host: "memoria.ndn.ucla.edu"}), new Interest(name1), 41 | null /*validator key*/, 42 | onComplete, function(errorCode, message) { 43 | console.log("Error " + errorCode + ": " + message); 44 | }, 45 | {pipeline: "fixed"} /*pipeline type (default: Cubic) and its options*/ 46 | ); 47 | 48 | 49 | // Try to fetch a local file using Cubic pipeline 50 | // NOTE: A file under "/test/junkfile" needs to be published on the local machine, first 51 | var name2 = new Name("/test/junkfile"); 52 | console.log("Express name " + name2.toUri()); 53 | SegmentFetcher.fetch 54 | (new Face({host: "localhost"}), new Interest(name2), 55 | null /*validator key*/, 56 | onComplete, function(errorCode, message) { 57 | console.log("Error " + errorCode + ": " + message); 58 | }, 59 | null /*pipeline type (default: Cubic) and its options*/ 60 | ); 61 | 62 | // Expect this to time out 63 | var name3 = new Name("/test/timeout"); 64 | console.log("Express name " + name3.toUri()); 65 | SegmentFetcher.fetch 66 | (new Face({host: "localhost"}), new Interest(name3), 67 | null /*validator key*/, 68 | onComplete, function(errorCode, message) { 69 | console.log("Error " + errorCode + ": " + message); 70 | }, 71 | null /*pipeline type (default: Cubic) and its options*/ 72 | ); 73 | -------------------------------------------------------------------------------- /tests/node/unit-tests/test-control-parameters-encode-decode.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Andrew Brown 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version, with the additional exemption that 9 | * compiling, linking, and/or using OpenSSL is allowed. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | var assert = require('assert'); 22 | var ControlParameters = require('../../..').ControlParameters; 23 | var Name = require('../../..').Name; 24 | 25 | describe('ControlParameters', function() { 26 | it('should encode and decode', function() { 27 | var parameters = new ControlParameters(); 28 | parameters.setName(new Name('/test/control/parameters')); 29 | parameters.setFaceId(1); 30 | // encode 31 | var encoded = parameters.wireEncode(); 32 | // decode 33 | var decodedParameters = new ControlParameters(); 34 | decodedParameters.wireDecode(encoded); 35 | // compare 36 | assert.equal(parameters.getName().toUri(), decodedParameters 37 | .getName().toUri()); 38 | assert.equal(parameters.getFaceId(), decodedParameters.getFaceId()); 39 | assert.equal(parameters.getUri(), decodedParameters.getUri()); 40 | assert.equal(parameters.getForwardingFlags().getChildInherit(), 41 | decodedParameters.getForwardingFlags().getChildInherit(), 42 | "decoded forwarding flags childInherit is different"); 43 | assert.equal(parameters.getForwardingFlags().getCapture(), 44 | decodedParameters.getForwardingFlags().getCapture(), 45 | "decoded forwarding flags capture is different"); 46 | }); 47 | 48 | it('should encode and decode with no name', function() { 49 | var parameters = new ControlParameters(); 50 | parameters.setStrategy(new Name('/localhost/nfd/strategy/broadcast')); 51 | parameters.setUri('null://'); 52 | // encode 53 | var encoded = parameters.wireEncode(); 54 | // decode 55 | var decodedParameters = new ControlParameters(); 56 | decodedParameters.wireDecode(encoded); 57 | // compare 58 | assert.equal(decodedParameters.getName(), null); 59 | assert.equal(parameters.getStrategy().toUri(), decodedParameters 60 | .getStrategy().toUri()); 61 | assert.equal(parameters.getUri(), decodedParameters.getUri()); 62 | }); 63 | }); 64 | -------------------------------------------------------------------------------- /js/security/security-exception.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | /** 21 | * Create a new SecurityException to report an exception from the security 22 | * library, wrapping the given error object. 23 | * Call with: throw new SecurityException(new Error("message")). 24 | * @constructor 25 | * @param {Error} error The exception created with new Error. 26 | */ 27 | function SecurityException(error) 28 | { 29 | if (error) { 30 | error.__proto__ = SecurityException.prototype; 31 | return error; 32 | } 33 | } 34 | 35 | SecurityException.prototype = new Error(); 36 | SecurityException.prototype.name = "SecurityException"; 37 | 38 | exports.SecurityException = SecurityException; 39 | 40 | function UnrecognizedKeyFormatException(error) 41 | { 42 | // Call the base constructor. 43 | SecurityException.call(this, error); 44 | } 45 | UnrecognizedKeyFormatException.prototype = new SecurityException(); 46 | UnrecognizedKeyFormatException.prototype.name = "UnrecognizedKeyFormatException"; 47 | 48 | exports.UnrecognizedKeyFormatException = UnrecognizedKeyFormatException; 49 | 50 | function UnrecognizedDigestAlgorithmException(error) 51 | { 52 | // Call the base constructor. 53 | SecurityException.call(this, error); 54 | } 55 | UnrecognizedDigestAlgorithmException.prototype = new SecurityException(); 56 | UnrecognizedDigestAlgorithmException.prototype.name = "UnrecognizedDigestAlgorithmException"; 57 | 58 | exports.UnrecognizedDigestAlgorithmException = UnrecognizedDigestAlgorithmException; 59 | 60 | /** 61 | * Create a new InvalidArgumentException to report invalid or inconsistent 62 | * arguments. 63 | * Call with: throw new InvalidArgumentException(new Error("message")). 64 | * @constructor 65 | * @param {Error} error The exception created with new Error. 66 | */ 67 | function InvalidArgumentException(error) 68 | { 69 | if (error) { 70 | error.__proto__ = InvalidArgumentException.prototype; 71 | return error; 72 | } 73 | } 74 | 75 | InvalidArgumentException.prototype = new Error(); 76 | InvalidArgumentException.prototype.name = "InvalidArgumentException"; 77 | 78 | exports.InvalidArgumentException = InvalidArgumentException; 79 | -------------------------------------------------------------------------------- /tests/node/unit-tests/unit-tests-common.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2015-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | /** 21 | * UnitTestsCommon has static methods to help in unit tests. 22 | */ 23 | var UnitTestsCommon = function UnitTestsCommon() 24 | { 25 | }; 26 | 27 | exports.UnitTestsCommon = UnitTestsCommon; 28 | 29 | /** 30 | * Convert a UNIX timestamp to ISO time representation with the "T" in the middle. 31 | * @param {number} msSince1970 Timestamp as milliseconds since Jan 1, 1970 UTC. 32 | * @return {string} The string representation. 33 | */ 34 | UnitTestsCommon.toIsoString = function(msSince1970) 35 | { 36 | var utcTime = new Date(Math.round(msSince1970)); 37 | return utcTime.getUTCFullYear() + 38 | UnitTestsCommon.to2DigitString(utcTime.getUTCMonth() + 1) + 39 | UnitTestsCommon.to2DigitString(utcTime.getUTCDate()) + 40 | "T" + 41 | UnitTestsCommon.to2DigitString(utcTime.getUTCHours()) + 42 | UnitTestsCommon.to2DigitString(utcTime.getUTCMinutes()) + 43 | UnitTestsCommon.to2DigitString(utcTime.getUTCSeconds()); 44 | }; 45 | 46 | /** 47 | * A private method to zero pad an integer to 2 digits. 48 | * @param {number} x The number to pad. Assume it is a non-negative integer. 49 | * @return {string} The padded string. 50 | */ 51 | UnitTestsCommon.to2DigitString = function(x) 52 | { 53 | var result = x.toString(); 54 | return result.length === 1 ? "0" + result : result; 55 | }; 56 | 57 | /** 58 | * Convert an ISO time representation with the "T" in the middle to a UNIX 59 | * timestamp. 60 | * @param {string} timeString The ISO time representation. 61 | * @return {number} The timestamp as milliseconds since Jan 1, 1970 UTC. 62 | */ 63 | UnitTestsCommon.fromIsoString = function(timeString) 64 | { 65 | if (timeString.length != 15 || timeString.substr(8, 1) != 'T') 66 | throw new Error("fromIsoString: Format is not the expected yyyymmddThhmmss"); 67 | 68 | return Date.UTC 69 | (parseInt(timeString.substr(0, 4)), 70 | parseInt(timeString.substr(4, 2) - 1), 71 | parseInt(timeString.substr(6, 2)), 72 | parseInt(timeString.substr(9, 2)), 73 | parseInt(timeString.substr(11, 2)), 74 | parseInt(timeString.substr(13, 2))); 75 | }; 76 | -------------------------------------------------------------------------------- /examples/browser/test-echo-consumer.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 22 | 23 | 24 | 25 | NDN Consumer via WebSocket 26 | 27 | 28 | 29 | 71 | 72 | 73 | 74 | If you haven't already, open the Publisher Page. 75 | Enter a Word to Echo and click Express Interest.

76 |
77 | Host:

78 | Word to Echo:
79 |
80 |
81 | 82 |

83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /js/security/policy/certificate-cache.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * From PyNDN certificate_cache.py by Adeola Bannis. 5 | * Originally from Yingdi Yu . 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program. If not, see . 19 | * A copy of the GNU Lesser General Public License is in the file COPYING. 20 | */ 21 | 22 | /** @ignore */ 23 | var IdentityCertificate = require('../certificate/identity-certificate.js').IdentityCertificate; 24 | 25 | /** 26 | * A CertificateCache is used to save other users' certificate during 27 | * verification. 28 | * @constructor 29 | */ 30 | var CertificateCache = function CertificateCache() 31 | { 32 | // The key is the certificate name URI. The value is the wire encoding Blob. 33 | this.cache = {}; 34 | }; 35 | 36 | exports.CertificateCache = CertificateCache; 37 | 38 | /** 39 | * Insert the certificate into the cache. Assumes the timestamp is not yet 40 | * removed from the name. 41 | * @param {IdentityCertificate} certificate The certificate to insert. 42 | */ 43 | CertificateCache.prototype.insertCertificate = function(certificate) 44 | { 45 | var certName = certificate.getName().getPrefix(-1); 46 | this.cache[certName.toUri()] = certificate.wireEncode(); 47 | }; 48 | 49 | /** 50 | * Remove a certificate from the cache. This does nothing if it is not present. 51 | * @param {Name} certificateName The name of the certificate to remove. This 52 | * assumes there is no timestamp in the name. 53 | */ 54 | CertificateCache.prototype.deleteCertificate = function(certificateName) 55 | { 56 | delete this.cache[certificateName.toUri()]; 57 | }; 58 | 59 | /** 60 | * Fetch a certificate from the cache. 61 | * @param {Name} certificateName The name of the certificate to remove. This 62 | * assumes there is no timestamp in the name. 63 | * @return {IdentityCertificate} A new copy of the IdentityCertificate, or null 64 | * if not found. 65 | */ 66 | CertificateCache.prototype.getCertificate = function(certificateName) 67 | { 68 | var certData = this.cache[certificateName.toUri()]; 69 | if (certData === undefined) 70 | return null; 71 | 72 | var cert = new IdentityCertificate(); 73 | cert.wireDecode(certData); 74 | return cert; 75 | }; 76 | 77 | /** 78 | * Clear all certificates from the store. 79 | */ 80 | CertificateCache.prototype.reset = function() 81 | { 82 | this.cache = {}; 83 | }; 84 | -------------------------------------------------------------------------------- /js/in-memory-storage/in-memory-storage-retaining.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx security https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/ims/in-memory-storage-persistent.cpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var Name = require('../name.js').Name; /** @ignore */ 23 | var Data = require('../data.js').Data; 24 | 25 | /** 26 | * InMemoryStorageRetaining provides an application cache with in-memory 27 | * storage, of which no eviction policy will be employed. Entries will only be 28 | * evicted by explicit application control. 29 | * Note: In ndn-cxx, this class is called InMemoryStoragePersistent, but 30 | * "persistent" misleadingly sounds like persistent on-disk storage. 31 | * 32 | * Create an InMemoryStorageRetaining. 33 | * @constructor 34 | */ 35 | var InMemoryStorageRetaining = function InMemoryStorageRetaining() 36 | { 37 | // The dictionary key is the Data packet Name URI string. The value is a Data. 38 | this.cache_ = []; 39 | }; 40 | 41 | exports.InMemoryStorageRetaining = InMemoryStorageRetaining; 42 | 43 | /** 44 | * Insert a Data packet. If a Data packet with the same name, including the 45 | * implicit digest, already exists, replace it. 46 | * @param {Data} data The packet to insert, which is copied. 47 | */ 48 | InMemoryStorageRetaining.prototype.insert = function(data) 49 | { 50 | this.cache_[data.getFullName().toUri()] = new Data(data); 51 | }; 52 | 53 | /** 54 | * Find the best match Data for an Interest. 55 | * @param {Interest} interest The Interest with the Name of the Data packet to 56 | * find. 57 | * @returns {Data} The best match if any, otherwise None. You should not modify 58 | * the returned object. If you need to modify it then you must make a copy. 59 | */ 60 | InMemoryStorageRetaining.prototype.find = function(interest) 61 | { 62 | for (var nameUri in this.cache_) { 63 | // Debug: Check selectors, especially CanBePrefix. 64 | if (interest.getName().isPrefixOf(new Name(nameUri))) 65 | return this.cache_[nameUri]; 66 | } 67 | }; 68 | 69 | /** 70 | * Get the number of packets stored in the in-memory storage. 71 | * @returns {number} The number of packets. 72 | */ 73 | InMemoryStorageRetaining.prototype.size = function() 74 | { 75 | return Object.keys(this.cache_).length; 76 | }; 77 | -------------------------------------------------------------------------------- /examples/ndnping/ndn-ping.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013-2019 Regents of the University of California. 3 | * @author: Jeff Burke 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | /* 20 | NDN Ping example, revised for ndn-tlv-ping 21 | 22 | Using ping responder on NDN testbed, which responds to Interests in 23 | //ping/ 24 | 25 | Jeff Burke 26 | jburke@remap.ucla.edu 27 | */ 28 | 29 | // One of NDN project default hubs 30 | 31 | // TODO: Use NDN hub selection mechanism 32 | // 33 | var hostip = "spurs.cs.ucla.edu"; 34 | 35 | var face = new Face({host:hostip}); 36 | 37 | function onTimeout(interest) 38 | { 39 | var nameStr = interest.getName().toUri().split("/").slice(0,-2).join("/"); 40 | document.getElementById('pingreport').innerHTML += '' + nameStr + ' timeout' ; 41 | } 42 | 43 | function onData(interest, content, T0) 44 | { 45 | var T1 = new Date(); 46 | var nameStr = content.getName().toUri().split("/").slice(0,-2).join("/"); 47 | var strContent = DataUtils.toString(content.getContent().buf()); 48 | 49 | nameStr += ' (unverified)'; 50 | 51 | if (strContent=="NDN TLV Ping Response\0") { 52 | document.getElementById('pingreport').innerHTML += '' + nameStr + ' ' + (T1-T0) + ' ms' ; 53 | } else { 54 | console.log("Unknown content received."); 55 | } 56 | } 57 | 58 | function ping(name) { 59 | var pingname = name + "/ping/" + Math.floor(Math.random()*100000); 60 | var T0 = new Date(); 61 | face.expressInterest 62 | (new Name(pingname), 63 | function(interest, content) { onData(interest, content, T0); }, 64 | onTimeout); 65 | }; 66 | 67 | function dopings() { 68 | ping("/ndn/org/caida"); 69 | ping("/ndn/cn/edu/bupt"); 70 | ping("/ndn/cn/edu/pku"); 71 | ping("/ndn/cn/edu/tongji"); 72 | ping("/ndn/edu/arizona"); 73 | ping("/ndn/edu/colostate"); 74 | ping("/ndn/edu/memphis"); 75 | ping("/ndn/edu/neu"); 76 | ping("/ndn/edu/uci"); 77 | ping("/ndn/edu/ucla"); 78 | ping("/ndn/edu/ucla/remap"); 79 | ping("/ndn/edu/uiuc"); 80 | ping("/ndn/edu/umich "); 81 | ping("/ndn/edu/wustl"); 82 | ping("/ndn/fr/lip6"); 83 | ping("/ndn/fr/orange1"); 84 | }; 85 | 86 | window.onload = function() { 87 | document.getElementById("host").innerHTML=hostip; 88 | dopings() 89 | } 90 | -------------------------------------------------------------------------------- /js/security/v2/trust-anchor-group.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2018-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx security https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/security/v2/trust-anchor-group.cpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var fs = require('fs'); /** @ignore */ 23 | var Blob = require('../../util/blob.js').Blob; /** @ignore */ 24 | var CertificateV2 = require('./certificate-v2.js').CertificateV2; 25 | 26 | /** 27 | * TrustAnchorGroup represents a group of trust anchors which implement the 28 | * CertificateContainer interface. 29 | * 30 | * Create a TrustAnchorGroup to use an existing container. 31 | * @param {CertificateContainer} certificateContainer The existing certificate 32 | * container which implements the CertificateContainer interface. 33 | * @param {string} id The group ID. 34 | * @constructor 35 | */ 36 | var TrustAnchorGroup = function TrustAnchorGroup(certificateContainer, id) 37 | { 38 | this.certificates_ = certificateContainer; 39 | this.id_ = id; 40 | 41 | // The object keys are the set of anchor name URIs, and each value is true. 42 | this.anchorNameUris_ = {}; 43 | }; 44 | 45 | exports.TrustAnchorGroup = TrustAnchorGroup; 46 | 47 | /** 48 | * Get the group id given to the constructor. 49 | * @return {string} The group id. 50 | */ 51 | TrustAnchorGroup.prototype.getId = function() { return this.id_; }; 52 | 53 | /** 54 | * Get the number of certificates in the group. 55 | * @return {number} The number of certificates. 56 | */ 57 | TrustAnchorGroup.prototype.size = function() 58 | { 59 | return Object.keys(this.anchorNameUris_).length; 60 | }; 61 | 62 | /** 63 | * Request a certificate refresh. The base method does nothing. 64 | */ 65 | TrustAnchorGroup.prototype.refresh = function() {}; 66 | 67 | /** 68 | * Read a base-64-encoded certificate from a file. 69 | * @param {string} filePath The certificate file path. 70 | * @return {CertificateV2} The decoded certificate, or null if there is an 71 | * error. 72 | */ 73 | TrustAnchorGroup.readCertificate = function(filePath) 74 | { 75 | try { 76 | var encodedData = fs.readFileSync(filePath).toString(); 77 | var decodedData = new Buffer(encodedData, 'base64'); 78 | var result = new CertificateV2(); 79 | result.wireDecode(new Blob(decodedData, false)); 80 | return result; 81 | } catch (ex) { 82 | return null; 83 | } 84 | }; 85 | 86 | -------------------------------------------------------------------------------- /js/use-subtle-crypto.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This module checks for the availability of various crypto.subtle api's at runtime, 3 | * exporting a function that returns the known availability of necessary NDN crypto apis 4 | * Copyright (C) 2014-2019 Regents of the University of California. 5 | * @author: Ryan Bennett 6 | * 7 | * This program is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program. If not, see . 19 | * A copy of the GNU Lesser General Public License is in the file COPYING. 20 | */ 21 | 22 | function DetectSubtleCrypto(){ 23 | var use = false; 24 | var baselineSupport = ( 25 | (typeof crypto !== 'undefined' && crypto && crypto.subtle) 26 | && ( 27 | (location.protocol === "https:" || "chrome-extension:" || "chrome:") 28 | || (location.hostname === "localhost" || location.hostname === "127.0.0.1") 29 | ) 30 | ) ? true : false ; 31 | if (baselineSupport) { 32 | var algo = { name: "RSASSA-PKCS1-v1_5", modulusLength: 2048, hash:{name:"SHA-256"}, publicExponent: new Uint8Array([0x01, 0x00, 0x01])}; 33 | var keypair; 34 | //try to perform every RSA crypto operation we need, if everything works, set use = true 35 | crypto.subtle.generateKey( 36 | algo, 37 | true, //exportable; 38 | ["sign", "verify"]).then(function(key){ 39 | keypair = key; 40 | return crypto.subtle.sign(algo, key.privateKey, new Uint8Array([1,2,3,4,5])); 41 | }).then(function(signature){ 42 | return crypto.subtle.verify(algo, keypair.publicKey, signature, new Uint8Array([1,2,3,4,5])); 43 | }).then(function(verified){ 44 | return crypto.subtle.exportKey("pkcs8",keypair.privateKey); 45 | }).then(function(pkcs8){ 46 | return crypto.subtle.importKey("pkcs8", pkcs8, algo, true, ["sign"]); 47 | }).then(function(importedKey){ 48 | return crypto.subtle.exportKey("spki", keypair.publicKey); 49 | }).then(function(spki){ 50 | return crypto.subtle.importKey("spki", spki, algo, true, ["verify"]); 51 | }).then(function(importedKey){ 52 | var testDigest = new Uint8Array([1,2,3,4,5]); 53 | return crypto.subtle.digest({name:"SHA-256"}, testDigest.buffer); 54 | }).then(function(result){ 55 | use = true; 56 | }, function(err){ 57 | console.log("DetectSubtleCrypto encountered error, not using crypto.subtle: ", err) 58 | }); 59 | } 60 | return function useSubtleCrypto(){ 61 | return use; 62 | } 63 | } 64 | 65 | var UseSubtleCrypto = DetectSubtleCrypto(); 66 | 67 | exports.UseSubtleCrypto = UseSubtleCrypto; 68 | -------------------------------------------------------------------------------- /examples/node/test-list-channels.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2019 Regents of the University of California. 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU Lesser General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with this program. If not, see . 16 | * A copy of the GNU Lesser General Public License is in the file COPYING. 17 | */ 18 | 19 | /* 20 | * This sends a faces channels request to the local NFD and prints the response. 21 | * This is equivalent to the NFD command line command "nfd-status -c". 22 | * See http://redmine.named-data.net/projects/nfd/wiki/Management . 23 | */ 24 | 25 | var ProtoBuf = require("protobufjs"); 26 | var Face = require('../..').Face; 27 | var Name = require('../..').Name; 28 | var Interest = require('../..').Interest; 29 | var Blob = require('../..').Blob; 30 | var UnixTransport = require('../..').UnixTransport; 31 | var ProtobufTlv = require('../..').ProtobufTlv; 32 | var SegmentFetcher = require('../..').SegmentFetcher; 33 | 34 | function main() 35 | { 36 | // Silence the warning from Interest wire encode. 37 | Interest.setDefaultCanBePrefix(true); 38 | 39 | // Connect to the local forwarder with a Unix socket. 40 | var face = new Face(new UnixTransport()); 41 | 42 | var interest = new Interest(new Name("/localhost/nfd/faces/channels")); 43 | interest.setInterestLifetimeMilliseconds(4000); 44 | console.log("Express interest " + interest.getName().toUri()); 45 | 46 | SegmentFetcher.fetch 47 | (face, interest, null, 48 | function(content) { 49 | face.close(); // This will cause the script to quit. 50 | printChannelStatuses(content); 51 | }, 52 | function(errorCode, message) { 53 | face.close(); // This will cause the script to quit. 54 | console.log(message); 55 | }); 56 | } 57 | 58 | /** 59 | * This is called when all the segments are received to decode the 60 | * encodedMessage repeated TLV ChannelStatus messages and display the values. 61 | * @param {Blob} encodedMessage The repeated TLV-encoded ChannelStatus. 62 | */ 63 | function printChannelStatuses(encodedMessage) 64 | { 65 | var builder = ProtoBuf.loadProtoFile("../browser/channel-status.proto"); 66 | var descriptor = builder.lookup("ndn_message.ChannelStatusMessage"); 67 | var ChannelStatusMessage = descriptor.build(); 68 | 69 | var channelStatusMessage = new ChannelStatusMessage(); 70 | ProtobufTlv.decode(channelStatusMessage, descriptor, encodedMessage); 71 | 72 | console.log("Channels:"); 73 | for (var iEntry = 0; iEntry < channelStatusMessage.channel_status.length; ++iEntry) { 74 | var channelStatus = channelStatusMessage.channel_status[iEntry]; 75 | 76 | // Format to look the same as "nfd-status -c". 77 | console.log(" " + channelStatus.local_uri); 78 | } 79 | } 80 | 81 | main(); 82 | -------------------------------------------------------------------------------- /js/util/change-counter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2014-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this program. If not, see . 17 | * A copy of the GNU Lesser General Public License is in the file COPYING. 18 | */ 19 | 20 | /** 21 | * A ChangeCounter keeps a target object whose change count is tracked by a 22 | * local change count. You can set to a new target which updates the local 23 | * change count, and you can call checkChanged to check if the target (or one of 24 | * the target's targets) has been changed. The target object must have a method 25 | * getChangeCount. 26 | * 27 | * Create a new ChangeCounter to track the given target. If target is not null, 28 | * this sets the local change counter to target.getChangeCount(). 29 | * @param {object} target The target to track, as an object with the method 30 | * getChangeCount(). 31 | * @constructor 32 | */ 33 | var ChangeCounter = function ChangeCounter(target) 34 | { 35 | this.target = target; 36 | this.changeCount = (target == null ? 0 : target.getChangeCount()); 37 | }; 38 | 39 | exports.ChangeCounter = ChangeCounter; 40 | 41 | /** 42 | * Get the target object. If the target is changed, then checkChanged will 43 | * detect it. 44 | * @return {object} The target, as an object with the method 45 | * getChangeCount(). 46 | */ 47 | ChangeCounter.prototype.get = function() 48 | { 49 | return this.target; 50 | }; 51 | 52 | /** 53 | * Set the target to the given target. If target is not null, this sets the 54 | * local change counter to target.getChangeCount(). 55 | * @param {object} target The target to track, as an object with the method 56 | * getChangeCount(). 57 | */ 58 | ChangeCounter.prototype.set = function(target) 59 | { 60 | this.target = target; 61 | this.changeCount = (target == null ? 0 : target.getChangeCount()); 62 | }; 63 | 64 | /** 65 | * If the target's change count is different than the local change count, then 66 | * update the local change count and return true. Otherwise return false, 67 | * meaning that the target has not changed. Also, if the target is null, 68 | * simply return false. This is useful since the target (or one of the target's 69 | * targets) may be changed and you need to find out. 70 | * @return {boolean} True if the change count has been updated, false if not. 71 | */ 72 | ChangeCounter.prototype.checkChanged = function() 73 | { 74 | if (this.target == null) 75 | return false; 76 | 77 | var targetChangeCount = this.target.getChangeCount(); 78 | if (this.changeCount != targetChangeCount) { 79 | this.changeCount = targetChangeCount; 80 | return true; 81 | } 82 | else 83 | return false; 84 | }; 85 | -------------------------------------------------------------------------------- /js/lp/lp-packet.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016-2019 Regents of the University of California. 3 | * @author: Jeff Thompson 4 | * @author: From ndn-cxx packet.hpp https://github.com/named-data/ndn-cxx/blob/master/ndn-cxx/lp/packet.hpp 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Lesser General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public License 17 | * along with this program. If not, see . 18 | * A copy of the GNU Lesser General Public License is in the file COPYING. 19 | */ 20 | 21 | /** @ignore */ 22 | var Blob = require('../util/blob.js').Blob; 23 | 24 | /** 25 | * An LpPacket represents an NDNLPv2 packet including header fields an an 26 | * optional fragment. This is an internal class which the application normally 27 | * would not use. 28 | * http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2 29 | * @constructor 30 | */ 31 | var LpPacket = function LpPacket() 32 | { 33 | this.headerFields_ = []; 34 | this.fragmentWireEncoding_ = new Blob(); 35 | }; 36 | 37 | exports.LpPacket = LpPacket; 38 | 39 | /** 40 | * Get the fragment wire encoding. 41 | * @return {Blob} The wire encoding, or an isNull Blob if not specified. 42 | */ 43 | LpPacket.prototype.getFragmentWireEncoding = function() 44 | { 45 | return this.fragmentWireEncoding_; 46 | }; 47 | 48 | /** 49 | * Get the number of header fields. This does not include the fragment. 50 | * @return {number} The number of header fields. 51 | */ 52 | LpPacket.prototype.countHeaderFields = function() 53 | { 54 | return this.headerFields_.length; 55 | }; 56 | 57 | /** 58 | * Get the header field at the given index. 59 | * @param {number} index The index, starting from 0. It is an error if index is 60 | * greater to or equal to countHeaderFields(). 61 | * @return {object} The header field at the index. 62 | */ 63 | LpPacket.prototype.getHeaderField = function(index) 64 | { 65 | return this.headerFields_[index]; 66 | }; 67 | 68 | /** 69 | * Remove all header fields and set the fragment to an isNull Blob. 70 | */ 71 | LpPacket.prototype.clear = function() 72 | { 73 | this.headerFields_ = []; 74 | this.fragmentWireEncoding_ = new Blob(); 75 | }; 76 | 77 | /** 78 | * Set the fragment wire encoding. 79 | * @param {Blob} fragmentWireEncoding The fragment wire encoding or an isNull 80 | * Blob if not specified. 81 | */ 82 | LpPacket.prototype.setFragmentWireEncoding = function(fragmentWireEncoding) 83 | { 84 | this.fragmentWireEncoding_ = 85 | typeof fragmentWireEncoding === 'object' && fragmentWireEncoding instanceof Blob ? 86 | fragmentWireEncoding : new Blob(fragmentWireEncoding); 87 | }; 88 | 89 | /** 90 | * Add a header field. To add the fragment, use setFragmentWireEncoding(). 91 | * @param {object} headerField The header field to add. 92 | */ 93 | LpPacket.prototype.addHeaderField = function(headerField) 94 | { 95 | this.headerFields_.push(headerField); 96 | }; 97 | --------------------------------------------------------------------------------