blob: 482e5c0c1aed04f697ee5f53f1e67b5dbfada470 [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 Example</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="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>
<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="KeyName.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 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 encode(){
var contentname = new ContentName( createNameArray(document.getElementById('contentname').value) );
var content = document.getElementById('content').value;
var signedInfo = new SignedInfo();
signedInfo.setFields();
//var signatureBits = generateSignatureBits(contentname,content,signedInfo);
//witness is null
var signature = new Signature();
var co = new ContentObject(contentname,signedInfo,content,signature);
co.sign();
var coSize = getContentObjectSize(co);
var output = encodeToHexContentObject(co);
if(LOG>3) console.log("Size: ", coSize);
document.getElementById('coSize').innerHTML = coSize;
document.getElementById('result').innerHTML = output;
}
function decode(){
var input = document.getElementById('result').innerHTML;
var co = decodeHexContentObject(input);
var output ="";
if(co==-1)
output+= "NO CONTENT FOUND"
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+= "<br />";
output+= "<br />";
}
if(co.Content !=null){
output += "CONTENT(ASCII): "+ toString(co.Content);
output+= "<br />";
output+= "<br />";
}
if(co.Content !=null){
output += "CONTENT(hex): "+ toHex(co.Content);
output+= "<br />";
output+= "<br />";
}
if(co.Signature !=null && co.Signature.Signature!=null){
output += "SIGNATURE(hex): "+ 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: " + co.SignedInfo.Publisher.PublisherPublicKeyDigest + "<br />";
output += "Publisher Public Key Digest(hex): "+ toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);
output+= "<br />";
output+= "<br />";
}
if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){
output += "TimeStamp(hex): "+ co.SignedInfo.Timestamp.date;
output+= "<br />";
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();
var input = toString(co.rawSignatureData);
if(LOG>2) console.log("Input: ", input, "; raw signature data: ", 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);
var kp = publickeyHex.slice(336,594)
// var kp = '00bd9565559c1795c049a5ef4dc9d1bc8b981b66097ea253f5d0f50f1a1df908ac4e69a797dadd2c0590944a6e849e1fbb7371c53dfddbe7802656e1d5f449b8530d9c7da8d6abebd90e06124d927f2f6c5721f1d0e49e7f6a1167caf960d96ff5afaa2d2567337772a944c8e6ceb859b25a231d9eca873574ff98225c853f38ef';
output += "PUBLISHER KEY(hex): "+kp ;
output+= "<br />";
output+= "<br />";
if(LOG>3) console.log('kp is '+kp);
//var exp = publickeyHex.slice(318,324);
var exp = publickeyHex.slice(598,604);
// var exp = '5e8e57d7661e014bc1afe87644d5be1365cf2c8a49c5ced888dae1286690a1f9c6b63da7a8baad4d2d3a39117c459d9011d949c64c8a54a17efdd06fb502dbd27c27d89a6d984eddc7c41a20178ad3cf6998c82d4ca576c6e34b47d1e49d39e7f4ddb31371e2af7bf2f6ef21bf79a82132035e756b6e2ab44d4d8521dd0bb461';
if(LOG>3) console.log('kp size is '+kp.length );
output += "exponent: "+exp ;
output+= "<br />";
output+= "<br />";
console.log('exp is '+exp);
var rsakey = new RSAKey();
rsakey.setPublic(kp,exp);
var result = rsakey.verifyString(input, signature);
var inputBis = toHex(co.Name).concat(toHex(co.SignedInfo), toHex(co.Content));
// if(LOG>0){
// console.log("Input: ", input);
// console.log("Input bis: ", inputBis);
// console.log("Verify input bis: ", rsakey.verifyString(inputBis, signature));
// }
//var x509 = new X509();
//x509.readCertPEM(publickey);
//if(LOG>0) console.log("x509 verif: ", x509.subjectPublicKeyRSA.verifyString(input, signature));
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;
return input;
}
</script>
</head>
<body >
<form>
Please Enter a Content Name:<br />
<input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" />
Please Enter the Content:<br />
<textarea id="content" cols="40" rows="5" name="CONTENT" value="SUCCESS" >SUCCESS!</textarea>
</form>
<div>
<button onclick="encode()">Encode</button>
<button onclick="decode()">Decode</button>
</div>
<div>
<p>Size: <span id="coSize"></span></p>
<p id="result"></p>
</div>
</body>
</html>