Security implemented + Partial publish
diff --git a/js/test-encode-decode-ContentObject.html b/js/test-encode-decode-ContentObject.html
index a737d3f..4d55cd7 100644
--- a/js/test-encode-decode-ContentObject.html
+++ b/js/test-encode-decode-ContentObject.html
@@ -4,7 +4,7 @@
 <html xmlns = "http://www.w3.org/1999/xhtml">

 

 <head>

-	<title>NDN Request Example</title>

+	<title>NDN Encode/Decode Content Object</title>

 	

 	<script type="text/javascript" src="java_socket_bridge.js"></script>

 	

@@ -15,9 +15,7 @@
 	<script type="text/javascript" src="ContentName.js"></script>

 	

 	<script type="text/javascript" src="ContentObject.js"></script>

-	

-	<script type="text/javascript" src="DateFormat.js"></script>

-	

+		

 	<script type="text/javascript" src="Exclude.js"></script>

 

 	<script type="text/javascript" src="ExcludeAny.js"></script>

@@ -50,6 +48,8 @@
 	

 	<script type="text/javascript" src="encoding/DataUtils.js"></script>

 	

+	<script type="text/javascript" src="encoding/EncodingUtils.js"></script>

+	

 	<script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>

 	

 	<script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>

@@ -72,11 +72,12 @@
 	<script type="text/javascript">

 	

 		function encode(){

-			var contentname = new ContentName( createNameArray(document.getElementById('contentname').value) );

+			var contentname = new ContentName( document.getElementById('contentname').value );

 			

 			var content = document.getElementById('content').value;

 			

 			var signedInfo = new SignedInfo();

+			

 			signedInfo.setFields();

 			//var signatureBits = generateSignatureBits(contentname,content,signedInfo);

 			

@@ -101,6 +102,7 @@
 			

 			var input = document.getElementById('result').innerHTML;

 

+			input = input.toUpperCase();

 			

 			var co = decodeHexContentObject(input);

 			

@@ -116,59 +118,75 @@
 			else if (co==-2)

 				output+= "CONTENT NAME IS EMPTY"

 			else{

+				

+				

 				if(co.Name!=null && co.Name.Components!=null){

 					output+= "NAME: ";

 					

 					for(var i=0;i<co.Name.Components.length;i++){

-						output+= "/"+ toString(co.Name.Components[i]);

+						output+= "/"+ DataUtils.toString(co.Name.Components[i]);

 					}

 					output+= "<br />";

 					output+= "<br />";

 				}

 	

 				if(co.Content !=null){

-					output += "CONTENT(ASCII): "+ toString(co.Content);

+					output += "CONTENT(ASCII): "+ DataUtils.toString(co.Content);

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.Content !=null){

-					output += "CONTENT(hex): "+ toHex(co.Content);

+					output += "CONTENT(hex): "+ DataUtils.toHex(co.Content);

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.Signature !=null && co.Signature.Signature!=null){

 					

-					output += "SIGNATURE(hex): "+ toHex(co.Signature.Signature);

+					output += "SIGNATURE(hex): "+ DataUtils.toHex(co.Signature.Signature);

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){

 					

-					output += "Publisher Public Key Digest(hex): "+ toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);

+					output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);

 					

 					output+= "<br />";

 					output+= "<br />";

 				}

 				if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){

+					var d = new Date();

+					d.setTime( co.SignedInfo.Timestamp.msec );

 					

-					output += "TimeStamp(hex): "+ co.SignedInfo.Timestamp.date;

+					var bytes = [217, 185, 12, 225, 217, 185, 12, 225];

 					

+					output += "TimeStamp: "+d;

 					output+= "<br />";

+					output += "TimeStamp(number): "+ co.SignedInfo.Timestamp.msec;

+					

+					

 					output+= "<br />";

 				}

-				if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){

-					

-					var publickey = rstr2b64(toString(co.SignedInfo.Locator.PublicKey));

-					var publickeyHex = toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();

-					var publickeyString = toString(co.SignedInfo.Locator.PublicKey);

-					

-					var signature = toHex(co.Signature.Signature).toLowerCase();

+				if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.Certificate!=null){

 					

 					

-					var input = toString(co.rawSignatureData);

+					var tmp = DataUtils.toString(co.SignedInfo.Locator.Certificate);

+					

+					

+					var publickey = rstr2b64(tmp);

+					

+					

+					

+					var publickeyHex = DataUtils.toHex(co.SignedInfo.Locator.Certificate).toLowerCase();

+					

+					var publickeyString = DataUtils.toString(co.SignedInfo.Locator.Certificate);

+					

+					var signature = DataUtils.toHex(co.Signature.Signature).toLowerCase();

+					

+					

+					var input = DataUtils.toString(co.rawSignatureData);

 					 

 					

 					output += "DER Certificate: "+publickey ;

@@ -179,24 +197,41 @@
 					

 					

 					if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);

+					

+					if(LOG>2) console.log("HEX OF ContentName + SignedInfo + Content = ");

+					if(LOG>2) console.log(DataUtils.stringtoBase64(input));

+					

 					if(LOG>2) console.log(" PublicKey = "+publickey );

 					if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );

 					if(LOG>2) console.log(" PublicKeyString = "+publickeyString );

 					

-					if(LOG>2) console.log(" Signature "+signature );

-					if(LOG>2) console.log(" Signature NOW IS" );

-					if(LOG>2) console.log(co.Signature.Signature);

-					

-					

+					if(LOG>2) console.log(" Signature is");

+					if(LOG>2) console.log( signature );

+					//if(LOG>2) console.log(" Signature NOW IS" );

+					//if(LOG>2) console.log(co.Signature.Signature);

+

+

 					var x509 = new X509();

-					

+

+

 					x509.readCertPEM(publickey);

 					

-					

 					//x509.readCertPEMWithoutRSAInit(publickey);

 

-					var result = x509.subjectPublicKeyRSA.verifyString(input, signature);

-					console.log('result is '+result);

+					var result = x509.subjectPublicKeyRSA.verifyByteArray(co.rawSignatureData, signature);

+					if(LOG>2) console.log('result is '+result);

+

+					

+					var n = x509.subjectPublicKeyRSA.n;

+					

+					var e =  x509.subjectPublicKeyRSA.e;

+					

+					if(LOG>2) console.log('PUBLIC KEY n after is ');

+					if(LOG>2) console.log(n);

+

+					if(LOG>2) console.log('EXPONENT e after is ');

+					if(LOG>2) console.log(e);

+					

 					/*var rsakey = new RSAKey();

 					

 					var kp = publickeyHex.slice(56,314);

@@ -237,7 +272,114 @@
 					output+= "<br />";

 					

 					

-					if(LOG>4) console.log('str'[1]);

+				    //if(LOG>4) console.log('str'[1]);

+				}

+				if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){

+					

+

+					var publickey = rstr2b64(DataUtils.toString(co.SignedInfo.Locator.PublicKey));

+					var publickeyHex = DataUtils.toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();

+					var publickeyString = DataUtils.toString(co.SignedInfo.Locator.PublicKey);

+					

+					var signature = DataUtils.toHex(co.Signature.Signature).toLowerCase();

+					

+					

+					var input = DataUtils.toString(co.rawSignatureData);

+					 

+					

+					output += "DER Certificate: "+publickey ;

+			

+					output+= "<br />";

+					output+= "<br />";

+					

+					if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);

+					if(LOG>2) console.log(" PublicKey = "+publickey );

+					if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );

+					if(LOG>2) console.log(" PublicKeyString = "+publickeyString );

+					

+					if(LOG>2) console.log(" Signature "+signature );

+					

+					if(LOG>2) console.log(" Signature NOW IS" );

+					

+					if(LOG>2) console.log(co.Signature.Signature);

+					

+					

+					/*var x509 = new X509();

+					

+					x509.readCertPEM(publickey);

+					

+					

+					//x509.readCertPEMWithoutRSAInit(publickey);

+

+					var result = x509.subjectPublicKeyRSA.verifyString(input, signature);*/

+					//console.log('result is '+result);

+					

+					

+					var kp = publickeyHex.slice(56,314);

+					

+					output += "PUBLISHER KEY(hex): "+kp ;

+					

+					output+= "<br />";

+					output+= "<br />";

+					

+					console.log('PUBLIC KEY IN HEX is ');

+					console.log(kp);

+

+					var exp = publickeyHex.slice(318,324);

+					

+					console.log('kp size is '+kp.length );

+					output += "exponent: "+exp ;

+					

+					output+= "<br />";

+					output+= "<br />";

+					

+					console.log('EXPONENT is ');

+					console.log(exp);

+

+					

+					

+					/*var c1 = hex_sha256(input);

+					var c2 = signature;

+					

+					if(LOG>4)console.log('input is ');

+					if(LOG>4)console.log(input);

+					if(LOG>4)console.log('C1 is ');

+					if(LOG>4)console.log(c1);

+					if(LOG>4)console.log('C2 is ');

+					if(LOG>4)console.log(c2);

+					var result = c1 == c2;*/

+					

+					var rsakey = new RSAKey();

+					

+					rsakey.setPublic(kp,exp);

+					

+					var result = rsakey.verifyByteArray(co.rawSignatureData,signature);

+				   // var result = rsakey.verifyString(input, signature);

+					

+				    

+				    

+				    console.log('PUBLIC KEY n after is ');

+					console.log(rsakey.n);

+

+					console.log('EXPONENT e after is ');

+					console.log(rsakey.e);

+					

+					

+					if(result)

+						output += 'SIGNATURE VALID';

+					else

+						output += 'SIGNATURE INVALID';

+

+						

+					

+					

+					//output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey);

+					

+					output+= "<br />";

+					output+= "<br />";

+					

+					

+					//if(LOG>4) console.log('str'[1]);

 				}

 			}

 			

@@ -264,8 +406,9 @@
 	<button onclick="decode()">Decode</button>

 	

 	

+	<p id="result">048202aa03b20885a8592ebf94205e85de1b143fb423680729910012bce6e2c9b2045e2988b2d7a358bf659d8bd714fbf1859560df6dacef07d07760e29d37a9a71d61ed51d04aa1ba1f6470fb985e3a328e5dcc215bc4c3aa61e3fe8f609709b34912dda892463e611fd86af2e69ff7688008f0dd1ee5680a037be308f4fbb1aef333ad33bf31170000f2fafdc12e4d2e532e6c6f63616c686f737400fabdc12e4d2e53525600faa563636e6400fa9d4b455900fa02b5c12e4d2e4b00e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f00fabdfd04fcc87f5ade00fa8d00000001a203e20285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f0002bab504fcc88dd36f0002c29d28463f0003d29e3630300003da8d000001e201eaf2fafdc12e4d2e532e6c6f63616c686f737400fabdc12e4d2e53525600faa563636e6400fa9d4b455900fa02b5c12e4d2e4b00e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f00fabdfd04fcc87f5ade0000000000019a0a9530819f300d06092a864886f70d010101050003818d0030818902818100b945ae17ef820242f542eb1af9eb92ad00a475741db5f8b4cb9d3a1131ad7f7d977e7b7809258f50cee91b56d6f16adb9c7a9492fe004f789bc5d4919b309740f910c26b8603d3f165bb62fef303663df67f244370492c6f1c5e5e9917fe7d4a3f6b0756760a805c467bcb0f143a159e267dc10eb1f4320f1ff2f247c3cbfd25020301000100000000000</p>

+	<!--  p id="result">058203e20285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f0004d29632310004da9631370004e2c631302e312e312e310004eaa6393639350003d2d6323134373438333634370000</p-->

 

-		<p id="result"></p>

 

 </body>

 </html>
\ No newline at end of file