blob: 9fb6a4fd1c2b86e97c57d4725279ddf70bd47e1b [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 Request </title>
<script type="text/javascript" src="java_socket_bridge.js"></script>
<script type="text/javascript" src="CCNProtocolDTags.js"></script>
<script type="text/javascript" src="CCNTime.js"></script>
<script type="text/javascript" src="Name.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>
<script type="text/javascript" src="ExcludeComponent.js"></script>
<script type="text/javascript" src="Interest.js"></script>
<script type="text/javascript" src="KeyLocator.js"></script>
<script type="text/javascript" src="PublisherID.js"></script>
<script type="text/javascript" src="Signature.js"></script>
<script type="text/javascript" src="SignedInfo.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/BinaryXMLCodec.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 type="text/javascript" src="lwNDN.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 run(){
var contentName = document.getElementById('contentname').value;
///////////////////////////////////////
//createRoute('131.179.141.15', 9695);
//createRoute('borges.metwi.ucla.edu', 9695);
/// /ndn/ucla.edu/apps/hydra/mainvideo
///////////////////////////////////////
var connector = new lwNDN('127.0.0.1', 9695);
var co = connector.get( contentName );
///////////////////////////////////////
//PRINT OUTPUT
///////////////////////////////////////
var output ="";
if(co==null)
output+= "NO CONTENT FOUND"
else{
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){
output += "TimeStamp: "+ co.signedInfo.timestamp.getJavascriptDate();
output+= "<br />";
output+= "<br />";
output += "TimeStamp (MILLISECONDS): "+ co.signedInfo.timestamp.msec;
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.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]);
}
}
document.getElementById('result').innerHTML = output;
}
</script>
</head>
<body >
<form>
Please Enter a Content Name:<br /><input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" /> <br />
</form>
<button onclick="run()">Request Data!</button>
<div >
<applet id="JavaSocketBridge" archive="JavaSocketBridge.jar" code="JavaSocketBridge.class" width="0" height="0">
</applet>
</div>
<p id="result"></p>
</body>
</html>