Wait to merge
diff --git a/js/Key.js b/js/Key.js
index 7f02090..ecce73d 100644
--- a/js/Key.js
+++ b/js/Key.js
@@ -148,10 +148,8 @@
* KeyName is only used by KeyLocator.
*/
var KeyName = function KeyName() {
-
-
- this.contentName = this.contentName;//contentName
- this.publisherID =this.publisherID;//publisherID
+ this.contentName = this.contentName; //contentName
+ this.publisherID = this.publisherID; //publisherID
};
diff --git a/js/WebSocketTransport.js b/js/WebSocketTransport.js
index 6b65b37..6d359e6 100644
--- a/js/WebSocketTransport.js
+++ b/js/WebSocketTransport.js
@@ -103,8 +103,7 @@
}
} else if (decoder.peekStartElement(CCNProtocolDTags.ContentObject)) { // Content packet
- //if (LOG > 3)
- console.log('ContentObject packet received.');
+ if (LOG > 3) console.log('ContentObject packet received.');
var co = new ContentObject();
co.from_ccnb(decoder);
@@ -167,7 +166,7 @@
} else if (kind == Closure.UPCALL_CONTENT) {
console.log("In KeyFetchClosure.upcall: signature verification passed");
var keyHex = DataUtils.toHex(upcallInfo.contentObject.content).toLowerCase();
- console.log("Key: " + keyHex);
+ //console.log("Key: " + keyHex);
var kp = keyHex.slice(56, 314);
var exp = keyHex.slice(318, 324);
@@ -177,7 +176,7 @@
var verified = rsakey.verifyByteArray(this.contentObject.rawSignatureData, this.signature);
var flag = (verified == true) ? Closure.UPCALL_CONTENT : Closure.UPCALL_CONTENT_BAD;
- console.log("raise encapsulated closure");
+ //console.log("raise encapsulated closure");
this.closure.upcall(flag, new UpcallInfo(ndn, null, 0, this.contentObject));
}
};
diff --git a/js/tools/build/ndn-js-uncomp.js b/js/tools/build/ndn-js-uncomp.js
index 0a291f1..9ce8d3e 100644
--- a/js/tools/build/ndn-js-uncomp.js
+++ b/js/tools/build/ndn-js-uncomp.js
@@ -382,8 +382,7 @@
}
} else if (decoder.peekStartElement(CCNProtocolDTags.ContentObject)) { // Content packet
- //if (LOG > 3)
- console.log('ContentObject packet received.');
+ if (LOG > 3) console.log('ContentObject packet received.');
var co = new ContentObject();
co.from_ccnb(decoder);
@@ -446,7 +445,7 @@
} else if (kind == Closure.UPCALL_CONTENT) {
console.log("In KeyFetchClosure.upcall: signature verification passed");
var keyHex = DataUtils.toHex(upcallInfo.contentObject.content).toLowerCase();
- console.log("Key: " + keyHex);
+ //console.log("Key: " + keyHex);
var kp = keyHex.slice(56, 314);
var exp = keyHex.slice(318, 324);
@@ -456,8 +455,12 @@
var verified = rsakey.verifyByteArray(this.contentObject.rawSignatureData, this.signature);
var flag = (verified == true) ? Closure.UPCALL_CONTENT : Closure.UPCALL_CONTENT_BAD;
- console.log("raise encapsulated closure");
+ //console.log("raise encapsulated closure");
this.closure.upcall(flag, new UpcallInfo(ndn, null, 0, this.contentObject));
+
+ // Store key in cache
+ var keyEntry = new KeyStoreEntry(keylocator.keyName, keyHex, rsakey);
+ NDN.KeyStore.push(keyEntry);
}
};
@@ -486,10 +489,6 @@
var flag = (verified == true) ? Closure.UPCALL_CONTENT : Closure.UPCALL_CONTENT_BAD;
currentClosure.upcall(flag, new UpcallInfo(ndn, null, 0, co));
-
- // Store key in cache
- var keyEntry = new KeyStoreEntry(keylocator.keyName, keyHex, rsakey);
- NDN.KeyStore.push(keyEntry);
} else {
console.log("Fetch key according to keylocator");
@@ -2183,10 +2182,8 @@
* KeyName is only used by KeyLocator.
*/
var KeyName = function KeyName() {
-
-
- this.contentName = this.contentName;//contentName
- this.publisherID =this.publisherID;//publisherID
+ this.contentName = this.contentName; //contentName
+ this.publisherID = this.publisherID; //publisherID
};
diff --git a/js/tools/build/ndn-js.js b/js/tools/build/ndn-js.js
index 33b3faf..447853e 100644
--- a/js/tools/build/ndn-js.js
+++ b/js/tools/build/ndn-js.js
@@ -12,14 +12,14 @@
WebSocketTransport.prototype.connectWebSocket=function(a){null!=this.ws&&delete this.ws;this.ws=new WebSocket("ws://"+a.host+":"+a.port);0<LOG&&console.log("ws connection created.");this.ws.binaryType="arraybuffer";var b=this;this.ws.onmessage=function(c){c=c.data;if(null==c||void 0==c||""==c)console.log("INVALID ANSWER");else if(c instanceof ArrayBuffer){var d=new Uint8Array(c);3<LOG&&console.log("BINARY RESPONSE IS "+DataUtils.toHex(d));try{if(d.length+b.bufferOffset>=b.buffer.byteLength){3<LOG&&
console.log("NDN.ws.onmessage: buffer overflow. Accumulate received length: "+b.bufferOffset+". Current packet length: "+d.length+".");delete b.structureDecoder;delete b.buffer;b.structureDecoder=new BinaryXMLStructureDecoder;b.buffer=new Uint8Array(b.maxBufferSize);b.bufferOffset=0;return}b.buffer.set(d,b.bufferOffset);b.bufferOffset+=d.length;if(!b.structureDecoder.findElementEnd(b.buffer.subarray(0,b.bufferOffset))){3<LOG&&console.log("Incomplete packet received. Length "+d.length+". Wait for more input.");
return}3<LOG&&console.log("Complete packet received. Length "+d.length+". Start decoding.")}catch(e){console.log("NDN.ws.onmessage exception: "+e);return}c=new BinaryXMLDecoder(b.buffer);if(c.peekStartElement(CCNProtocolDTags.Interest)){3<LOG&&console.log("Interest packet received.");d=new Interest;d.from_ccnb(c);3<LOG&&console.log(d);var f=escape(d.name.getName());3<LOG&&console.log(f);var g=getEntryForRegisteredPrefix(f);null!=g&&(d=new UpcallInfo(a,d,0,null),g.closure.upcall(Closure.UPCALL_INTEREST,
-d)==Closure.RESULT_INTEREST_CONSUMED&&null!=d.contentObject&&(g=encodeToBinaryContentObject(d.contentObject),d=new Uint8Array(g.length),d.set(g),b.ws.send(d.buffer)))}else if(c.peekStartElement(CCNProtocolDTags.ContentObject))if(console.log("ContentObject packet received."),d=new ContentObject,d.from_ccnb(c),3<LOG&&console.log(d),f=d.name.getName(),console.log(f),null==b.ccndid&&null!=f.match(NDN.ccndIdFetcher))!d.signedInfo||!d.signedInfo.publisher||!d.signedInfo.publisher.publisherPublicKeyDigest?
-(console.log("Cannot contact router, close NDN now."),a.readyStatus=NDN.CLOSED,a.onclose()):(b.ccndid=d.signedInfo.publisher.publisherPublicKeyDigest,3<LOG&&console.log(b.ccndid),a.readyStatus=NDN.OPENED,a.onopen());else{if(g=NDN.getEntryForExpressedInterest(d.name),null!=g){var h=NDN.PITTable.indexOf(g);0<=h&&NDN.PITTable.splice(h,1);h=g.closure;clearTimeout(h.timerID);var j=!1,k=function(a,b,c,d){this.contentObject=a;this.closure=b;this.keyName=c;this.signature=d;Closure.call(this)};k.prototype.upcall=
-function(b,c){if(b==Closure.UPCALL_INTEREST_TIMED_OUT)console.log("In KeyFetchClosure.upcall: interest time out.");else if(b==Closure.UPCALL_CONTENT){console.log("In KeyFetchClosure.upcall: signature verification passed");var d=DataUtils.toHex(c.contentObject.content).toLowerCase();console.log("Key: "+d);var e=d.slice(56,314),d=d.slice(318,324),f=new RSAKey;f.setPublic(e,d);e=!0==f.verifyByteArray(this.contentObject.rawSignatureData,this.signature)?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD;
-console.log("raise encapsulated closure");this.closure.upcall(e,new UpcallInfo(a,null,0,this.contentObject))}};if(d.signedInfo&&d.signedInfo.locator&&d.signature)if(3<LOG&&console.log("Key verification..."),j=DataUtils.toHex(d.signature.signature).toLowerCase(),g=d.signedInfo.locator,g.type==KeyLocatorType.KEYNAME){console.log("KeyLocator contains KEYNAME");var m=g.keyName.contentName.getName();console.log(m);if(f.match(m)){console.log("Content is key itself");k=DataUtils.toHex(d.content).toLowerCase();
-console.log("Key content: "+k);var m=k.slice(56,314),n=k.slice(318,324),f=new RSAKey;f.setPublic(m,n);j=f.verifyByteArray(d.rawSignatureData,j);j=!0==j?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD;h.upcall(j,new UpcallInfo(a,null,0,d));f=new KeyStoreEntry(g.keyName,k,f);NDN.KeyStore.push(f)}else console.log("Fetch key according to keylocator"),(f=NDN.getKeyByName(g.keyName))?(console.log("Local key cache hit"),f=f.rsaKey,j=f.verifyByteArray(d.rawSignatureData,j),j=!0==j?Closure.UPCALL_CONTENT:
-Closure.UPCALL_CONTENT_BAD,h.upcall(Closure.UPCALL_CONTENT,new UpcallInfo(a,null,0,d))):(h=new k(d,h,m,j),d=new Interest(g.keyName.contentName.getPrefix(4)),d.interestLifetime=4,b.expressInterest(a,d,h))}else g.type==KeyLocatorType.KEY?(console.log("Keylocator contains KEY"),k=DataUtils.toHex(g.publicKey).toLowerCase(),console.log(k),m=k.slice(56,314),n=k.slice(318,324),f=new RSAKey,f.setPublic(m,n),j=f.verifyByteArray(d.rawSignatureData,j),j=!0==j?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD,
-h.upcall(Closure.UPCALL_CONTENT,new UpcallInfo(a,null,0,d)),f=new KeyStoreEntry(g.keyName,k,f),NDN.KeyStore.push(f)):(d=g.certificate,console.log("KeyLocator contains CERT"),console.log(d))}}else console.log("Incoming packet is not Interest or ContentObject. Discard now.");delete c;delete b.structureDecoder;delete b.buffer;b.structureDecoder=new BinaryXMLStructureDecoder;b.buffer=new Uint8Array(b.maxBufferSize);b.bufferOffset=0}};this.ws.onopen=function(a){3<LOG&&console.log(a);3<LOG&&console.log("ws.onopen: WebSocket connection opened.");
-3<LOG&&console.log("ws.onopen: ReadyState: "+this.readyState);a=new Interest(new Name(NDN.ccndIdFetcher));a.interestLifetime=4;var a=encodeToBinaryInterest(a),d=new Uint8Array(a.length);d.set(a);b.ws.send(d.buffer)};this.ws.onerror=function(a){console.log("ws.onerror: ReadyState: "+this.readyState);console.log(a);console.log("ws.onerror: WebSocket error: "+a.data)};this.ws.onclose=function(){console.log("ws.onclose: WebSocket connection closed.");b.ws=null;a.readyStatus=NDN.CLOSED;a.onclose()}};
+d)==Closure.RESULT_INTEREST_CONSUMED&&null!=d.contentObject&&(g=encodeToBinaryContentObject(d.contentObject),d=new Uint8Array(g.length),d.set(g),b.ws.send(d.buffer)))}else if(c.peekStartElement(CCNProtocolDTags.ContentObject))if(3<LOG&&console.log("ContentObject packet received."),d=new ContentObject,d.from_ccnb(c),3<LOG&&console.log(d),f=d.name.getName(),console.log(f),null==b.ccndid&&null!=f.match(NDN.ccndIdFetcher))!d.signedInfo||!d.signedInfo.publisher||!d.signedInfo.publisher.publisherPublicKeyDigest?
+(console.log("Cannot contact router, close NDN now."),a.readyStatus=NDN.CLOSED,a.onclose()):(b.ccndid=d.signedInfo.publisher.publisherPublicKeyDigest,3<LOG&&console.log(b.ccndid),a.readyStatus=NDN.OPENED,a.onopen());else{if(g=NDN.getEntryForExpressedInterest(d.name),null!=g){var h=NDN.PITTable.indexOf(g);0<=h&&NDN.PITTable.splice(h,1);g=g.closure;clearTimeout(g.timerID);var h=!1,j=function(a,b,c,d){this.contentObject=a;this.closure=b;this.keyName=c;this.signature=d;Closure.call(this)};j.prototype.upcall=
+function(b,c){if(b==Closure.UPCALL_INTEREST_TIMED_OUT)console.log("In KeyFetchClosure.upcall: interest time out.");else if(b==Closure.UPCALL_CONTENT){console.log("In KeyFetchClosure.upcall: signature verification passed");var d=DataUtils.toHex(c.contentObject.content).toLowerCase(),e=d.slice(56,314),f=d.slice(318,324),g=new RSAKey;g.setPublic(e,f);e=!0==g.verifyByteArray(this.contentObject.rawSignatureData,this.signature)?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD;this.closure.upcall(e,new UpcallInfo(a,
+null,0,this.contentObject));d=new KeyStoreEntry(k.keyName,d,g);NDN.KeyStore.push(d)}};if(d.signedInfo&&d.signedInfo.locator&&d.signature){3<LOG&&console.log("Key verification...");var h=DataUtils.toHex(d.signature.signature).toLowerCase(),k=d.signedInfo.locator;if(k.type==KeyLocatorType.KEYNAME){console.log("KeyLocator contains KEYNAME");var m=k.keyName.contentName.getName();console.log(m);if(f.match(m)){console.log("Content is key itself");f=DataUtils.toHex(d.content).toLowerCase();console.log("Key content: "+
+f);var m=f.slice(56,314),n=f.slice(318,324),f=new RSAKey;f.setPublic(m,n);h=f.verifyByteArray(d.rawSignatureData,h);h=!0==h?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD;g.upcall(h,new UpcallInfo(a,null,0,d))}else console.log("Fetch key according to keylocator"),(f=NDN.getKeyByName(k.keyName))?(console.log("Local key cache hit"),f=f.rsaKey,h=f.verifyByteArray(d.rawSignatureData,h),h=!0==h?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD,g.upcall(Closure.UPCALL_CONTENT,new UpcallInfo(a,null,0,
+d))):(g=new j(d,g,m,h),d=new Interest(k.keyName.contentName.getPrefix(4)),d.interestLifetime=4,b.expressInterest(a,d,g))}else k.type==KeyLocatorType.KEY?(console.log("Keylocator contains KEY"),j=DataUtils.toHex(k.publicKey).toLowerCase(),console.log(j),m=j.slice(56,314),n=j.slice(318,324),f=new RSAKey,f.setPublic(m,n),h=f.verifyByteArray(d.rawSignatureData,h),h=!0==h?Closure.UPCALL_CONTENT:Closure.UPCALL_CONTENT_BAD,g.upcall(Closure.UPCALL_CONTENT,new UpcallInfo(a,null,0,d)),f=new KeyStoreEntry(k.keyName,
+j,f),NDN.KeyStore.push(f)):(d=k.certificate,console.log("KeyLocator contains CERT"),console.log(d))}}}else console.log("Incoming packet is not Interest or ContentObject. Discard now.");delete c;delete b.structureDecoder;delete b.buffer;b.structureDecoder=new BinaryXMLStructureDecoder;b.buffer=new Uint8Array(b.maxBufferSize);b.bufferOffset=0}};this.ws.onopen=function(a){3<LOG&&console.log(a);3<LOG&&console.log("ws.onopen: WebSocket connection opened.");3<LOG&&console.log("ws.onopen: ReadyState: "+
+this.readyState);a=new Interest(new Name(NDN.ccndIdFetcher));a.interestLifetime=4;var a=encodeToBinaryInterest(a),d=new Uint8Array(a.length);d.set(a);b.ws.send(d.buffer)};this.ws.onerror=function(a){console.log("ws.onerror: ReadyState: "+this.readyState);console.log(a);console.log("ws.onerror: WebSocket error: "+a.data)};this.ws.onclose=function(){console.log("ws.onclose: WebSocket connection closed.");b.ws=null;a.readyStatus=NDN.CLOSED;a.onclose()}};
WebSocketTransport.prototype.expressInterest=function(a,b,c){if(null!=this.ws){var d=encodeToBinaryInterest(b),e=new Uint8Array(d.length);e.set(d);var f=new PITEntry(b,c);NDN.PITTable.push(f);this.ws.send(e.buffer);3<LOG&&console.log("ws.send() returned.");c.timerID=setTimeout(function(){3<LOG&&console.log("Interest time out.");var d=NDN.PITTable.indexOf(f);0<=d&&NDN.PITTable.splice(d,1);c.upcall(Closure.UPCALL_INTEREST_TIMED_OUT,new UpcallInfo(a,b,0,null))},1E3*b.interestLifetime)}else console.log("WebSocket connection is not established.")};
var CSTable=[],CSEntry=function(a,b){this.name=a;this.closure=b};function getEntryForRegisteredPrefix(a){for(var b=0;b<CSTable.length;b++)if(null!=CSTable[b].name.match(a))return CSTable[b];return null}
WebSocketTransport.prototype.registerPrefix=function(a,b,c){if(null!=this.ws){if(null==this.ccndid)return console.log("ccnd node ID unkonwn. Cannot register prefix."),-1;var a=new ForwardingEntry("selfreg",b,null,null,3,2147483647),a=encodeForwardingEntry(a),d=new SignedInfo;d.setFields();a=new ContentObject(new Name,d,a,new Signature);a.sign();a=encodeToBinaryContentObject(a);a=new Name(["ccnx",this.ccndid,"selfreg",a]);a=new Interest(a);a.scope=1;d=encodeToBinaryInterest(a);a=new Uint8Array(d.length);