blob: d9b5e037e361f4d49341e22f178d13f192994a3e [file] [log] [blame]
<?xml version = "1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>NDN Decode Interest + Face Instance</title>
<script type="text/javascript" src="../java_socket_bridge.js"></script>
<script type="text/javascript" src="../util/CCNProtocolDTags.js"></script>
<script type="text/javascript" src="../util/CCNTime.js"></script>
<script type="text/javascript" src="../Name.js"></script>
<script type="text/javascript" src="../ContentObject.js"></script>
<script type="text/javascript" src="../encoding/DateFormat.js"></script>
<script type="text/javascript" src="../Interest.js"></script>
<script type="text/javascript" src="../Key.js"></script>
<script type="text/javascript" src="../PublisherID.js"></script>
<script type="text/javascript" src="../PublisherPublicKeyDigest.js"></script>
<script type="text/javascript" src="../FaceInstance.js"></script>
<script type="text/javascript" src="../ForwardingEntry.js"></script>
<script type="text/javascript" src="../encoding/BinaryXMLEncoder.js"></script>
<script type="text/javascript" src="../encoding/BinaryXMLDecoder.js"></script>
<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>
<script language="JavaScript" type="text/javascript" src="../securityLib/jsbn2.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/rsa.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/rsa2.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/sha1.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/sha256.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/sha512.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/md5.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/ripemd160.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/base64.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/rsapem-1.1.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/rsasign-1.2.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/asn1hex-1.1.js"></script>
<script language="JavaScript" type="text/javascript" src="../securityLib/x509-1.1.js"></script>
<script type="text/javascript">
function decode(){
var input = document.getElementById('result').innerHTML;
var interest = decodeHexInterest(input);
if(LOG>3)console.log('INTEREST DECODED');
if(LOG>3)console.log(interest);
///////////////////////////////////////
var output ="";
if(interest.name!=null && interest.name.components!=null){
output+= "NAME: ";
for(var i=0;i<interest.name.components.length;i++){
output+= "/"+ DataUtils.toString(interest.name.components[i]);
}
output+= "<br />";
output+= "<br />";
}
if(interest.faceInstance!=null ){
output+= "FaceInstance: ";
output+= interest.faceInstance;
output+= "<br />";
output+= "<br />";
}
if(interest.exclude!=null ){
output+= "Exclude: ";
output+= interest.exclude;
output+= "<br />";
output+= "<br />";
}
if(interest.childSelector!=null ){
output+= "ChildSelector: ";
output+= interest.childSelector;
output+= "<br />";
output+= "<br />";
}
if(interest.answerOriginKind!=null ){
output+= "AnswerOriginKind: ";
output+= interest.answerOriginKind;
output+= "<br />";
output+= "<br />";
}
if(interest.interestLifetime!=null ){
output+= "InterestLifetime: ";
output+= interest.interestLifetime;
output+= "<br />";
output+= "<br />";
}
if(interest.nonce!=null ){
output+= "Nonce: ";
output+= interest.nonce;
output+= "<br />";
output+= "<br />";
}
if(interest.scope!=null ){
output+= "SCOPE: ";
output+= interest.scope;
output+= "<br />";
output+= "<br />";
}
if(interest.publisherPublicKeyDigest!=null ){
output+= "PUBLISHER PUBLIC KEY DIGEST: ";
output+= interest.publisherPublicKeyDigest.publisherPublicKeyDigest;
output+= "<br />";
output+= "<br />";
}
if(interest.maxSuffixComponents!=null ){
output+= "MaxSuffixComponents : ";
output+= interest.maxSuffixComponents;
output+= "<br />";
output+= "<br />";
}
if(interest.minSuffixComponents!=null ){
output+= "MinSuffixComponents : ";
output+= interest.minSuffixComponents;
output+= "<br />";
output+= "<br />";
}
if(interest.name.components[3] !=null){
var input = DataUtils.toHex(interest.name.components[3]) ;
var contentObject = decodeHexContentObject(input);
if(contentObject.content!=null ){
output+= "Content of content Object: ";
output+= DataUtils.toHex(contentObject.content);
output+= "<br />";
output+= "<br />";
}
var content = DataUtils.toHex(contentObject.content);
var co = contentObject;
////////////////////////////////////////
if(co.name!=null && co.name.components!=null){
output+= "NAME: ";
for(var i=0;i<co.name.components.length;i++){
output+= "/"+ DataUtils.toString(co.name.components[i]);
}
output+= "<br />";
output+= "<br />";
}
if(co.content !=null){
output += "CONTENT(ASCII): "+ DataUtils.toString(co.content);
output+= "<br />";
output+= "<br />";
}
if(co.content !=null){
output += "CONTENT(hex): "+ DataUtils.toHex(co.content);
output+= "<br />";
output+= "<br />";
}
if(co.signature !=null && co.signature.signature!=null){
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): "+ 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 );
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.type!=null){
output += "Type: "+co.signedInfo.type;
output+= "<br />";
output+= "<br />";
}
if(co.signedInfo !=null && co.signedInfo.locator!=null){
output += "Locator: "+co.signedInfo.locator.type;
output+= "<br />";
output+= "<br />";
}
if(co.signedInfo !=null && co.signedInfo.freshnessSeconds!=null){
output += "FreshnessSeconds: "+co.signedInfo.freshnessSeconds;
output+= "<br />";
output+= "<br />";
}
if(co.signedInfo !=null && co.signedInfo.finalBlockID!=null){
output += "FinalBlockID: "+co.signedInfo.finalBlockID;
output+= "<br />";
output+= "<br />";
}
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.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]);
}
////////////////////////////////////////
var forwardingEntry = decodeHexForwardingEntry(content);
if(LOG>3)console.log('FORWARDING ENTRY IS PRESENT');
if(LOG>3)console.log(forwardingEntry);
///////////////////////////////////////
//var output ="";
if(forwardingEntry.action!=null ){
output+= "Action: ";
output+= DataUtils.toHex(forwardingEntry.action);
output+= "<br />";
output+= "<br />";
}
if(forwardingEntry.prefixName!=null){
output+= "PrefixName: ";
output+= forwardingEntry.prefixName.getName();
output+= "<br />";
}
if(forwardingEntry.ccndID!=null){
output+= "ccndID: ";
output+= forwardingEntry.ccndID;
output+= "<br />";
}
if(forwardingEntry.flags!=null){
output+= "Flags: ";
output+= forwardingEntry.flags;
output+= "<br />";
}
if(forwardingEntry.lifetime!=null){
output+= "Lifetime: ";
output+= forwardingEntry.lifetime;
output+= "<br />";
}
}
document.getElementById('result').innerHTML = output;
}
</script>
</head>
<body >
<form>
Please Press Decode:<br />
</form>
<button onclick="decode()">Decode</button>
<!-- p id="result-old-from-ccnx">01d2f2faa563636e7800fa0285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f00fabd73656c6672656700fa1bf5048202aa03b208854a18988c72aee624da28e2e1acbccb209b8e89429041985521ed68f95a1c546872fba3d854b1377dc249b6d8ec5935e5069256c97a7f6d8a62e86222ccd2cfe5097aed3fe5ede6732ce191a8680d78e39d0c5058a2b7bb0f0687994e9f045de346b66c46498547a08da1f2f0cdfafba3afdfe7107931935ede79040137ba94a90000f20001a203e202851a4860caa4991e829bcdc9429fb711d52440968d23560726606050bf147acffc0002bab504fcb3f03aa40001e201da0a9530819f300d06092a864886f70d010101050003818d00308189028181008ed27580e3d1c4c67672208665133a1ba12d8ebf5cad8e054571926b3ff0782a04c71703384021a6cefb6616b66cbd8a679b761d69d6373a851546e26f7105510b4c23be9a3c7f2e652e100ecc1471855730659f1477ce4e8504ad1fd8f44116baaeae2ff67eec33abba790157a79bf5039e5a528a471d9d67c94e70117ed7490203010001000000019a0585058a04cabe73656c6672656700f2faad726f63636f000003e20285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f0004fa8e330003d2d63231343734383336343700000000000002d28e310000</p-->
<p id="result">01d2f2faa563636e7800fa0285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f00facd70726566697872656700fa29ad048202aa03b208854ddbf69779cdf4ef74be99474478c8bc3ca0873e0ffa1fa60120aa276db122b83404e595a8a3caeaf09630276658ba4e7beaadb4b91a8cc58e19ac4a42289507ed8d609aa9bef61a5a507f349c83d2944b8c16fecfd90d4a40ddb8687592c0a57517564235b2e359db54f51a37e1ac39e518a2196e3ffda7eb2fb301f3c404dd0000f20001a203e20285ef7c4f5d4743a8b8586ea2e741b7fc39d1dc0dbe1b1930e787cfd1d833ea7a610002bab504fce9e253d70001e2018219fd3082019b30820104020900b7d85c906bad52ee300d06092a864886f70d010105050030123110300e060355040313076178656c636476301e170d3132303432383233343433375a170d3132303532383233343433375a30123110300e060355040313076178656c63647630819f300d06092a864886f70d010101050003818d0030818902818100e17d30a7d828ab1b840b17542dcaf6207afd221e086b2a60d16cb7f54448ba9f3f08bcd099db21dd162a779e61aa89eee554d3a47de230bc7ac590d524067c3898bba6f5dc4360b845eda48cbd9cf126a723445f0e1952d7325a75faf556144f9a98af7186b0278685b8e2c08bea87171b4dee585c1828295b5395eb4a17779f0203010001300d06092a864886f70d010105050003818100cb3ab0357d7cd2ae97ed501e51a3a0e2817d418e47fb17906477af61495a7e8d8789141065b082d001f4b15193d0b43fb661cde20a6498372c6abbd3dcb9f0d12659ef07b3c6dbdf8bdf2f65477eed7adcd457d793b1c27badda7c5ade80ce95b7d8827fe78c8a35f3fb4ba648a081be2cfe84231abab3c2b531746df2e0492b000000019a02d5058a04cabe73656c6672656700f2faa56d656b69000004fa8e330003d2d63231343734383336343700000000000002d28e310000</p>
</body>
</html>