Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 1 | <?xml version = "1.0" encoding="utf-8" ?>
|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
| 3 | "DTD/xhtml1-strict.dtd">
|
| 4 | <html xmlns = "http://www.w3.org/1999/xhtml">
|
| 5 |
|
| 6 | <head>
|
| 7 | <title>NDN Request Example</title>
|
| 8 |
|
| 9 | <script type="text/javascript" src="java_socket_bridge.js"></script>
|
| 10 |
|
| 11 | <script type="text/javascript" src="CCNProtocolDTags.js"></script>
|
| 12 |
|
| 13 | <script type="text/javascript" src="CCNTime.js"></script>
|
| 14 |
|
| 15 | <script type="text/javascript" src="ContentName.js"></script>
|
| 16 |
|
| 17 | <script type="text/javascript" src="ContentObject.js"></script>
|
| 18 |
|
| 19 | <script type="text/javascript" src="DateFormat.js"></script>
|
| 20 |
|
| 21 | <script type="text/javascript" src="Exclude.js"></script>
|
| 22 |
|
| 23 | <script type="text/javascript" src="ExcludeAny.js"></script>
|
| 24 |
|
| 25 | <script type="text/javascript" src="ExcludeComponent.js"></script>
|
| 26 |
|
| 27 | <script type="text/javascript" src="Interest.js"></script>
|
| 28 |
|
| 29 | <script type="text/javascript" src="KeyLocator.js"></script>
|
| 30 |
|
| 31 | <script type="text/javascript" src="KeyName.js"></script>
|
| 32 |
|
| 33 | <script type="text/javascript" src="PublisherID.js"></script>
|
| 34 |
|
| 35 | <script type="text/javascript" src="Signature.js"></script>
|
| 36 |
|
| 37 | <script type="text/javascript" src="SignedInfo.js"></script>
|
| 38 |
|
| 39 | <script type="text/javascript" src="PublisherPublicKeyDigest.js"></script>
|
| 40 |
|
| 41 | <script type="text/javascript" src="FaceInstance.js"></script>
|
| 42 |
|
| 43 | <script type="text/javascript" src="ForwardingEntry.js"></script>
|
| 44 |
|
| 45 | <script type="text/javascript" src="encoding/BinaryXMLEncoder.js"></script>
|
| 46 |
|
| 47 | <script type="text/javascript" src="encoding/BinaryXMLCodec.js"></script>
|
| 48 |
|
| 49 | <script type="text/javascript" src="encoding/BinaryXMLDecoder.js"></script>
|
| 50 |
|
| 51 | <script type="text/javascript" src="encoding/DataUtils.js"></script>
|
| 52 |
|
| 53 | <script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>
|
| 54 |
|
| 55 | <script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>
|
| 56 | <script language="JavaScript" type="text/javascript" src="securityLib/jsbn2.js"></script>
|
| 57 | <script language="JavaScript" type="text/javascript" src="securityLib/rsa.js"></script>
|
| 58 | <script language="JavaScript" type="text/javascript" src="securityLib/rsa2.js"></script>
|
| 59 |
|
| 60 | <script language="JavaScript" type="text/javascript" src="securityLib/sha1.js"></script>
|
| 61 | <script language="JavaScript" type="text/javascript" src="securityLib/sha256.js"></script>
|
| 62 | <script language="JavaScript" type="text/javascript" src="securityLib/sha512.js"></script>
|
| 63 | <script language="JavaScript" type="text/javascript" src="securityLib/md5.js"></script>
|
| 64 | <script language="JavaScript" type="text/javascript" src="securityLib/ripemd160.js"></script>
|
| 65 | <script language="JavaScript" type="text/javascript" src="securityLib/base64.js"></script>
|
| 66 |
|
| 67 | <script language="JavaScript" type="text/javascript" src="securityLib/rsapem-1.1.js"></script>
|
| 68 | <script language="JavaScript" type="text/javascript" src="securityLib/rsasign-1.2.js"></script>
|
| 69 | <script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.js"></script>
|
| 70 | <script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.js"></script>
|
| 71 |
|
| 72 | <script type="text/javascript">
|
| 73 |
|
| 74 | function encode(){
|
| 75 | var contentname = new ContentName( createNameArray(document.getElementById('contentname').value) );
|
| 76 |
|
| 77 | var content = document.getElementById('content').value;
|
| 78 |
|
| 79 | var signedInfo = new SignedInfo();
|
| 80 | signedInfo.setFields();
|
| 81 | //var signatureBits = generateSignatureBits(contentname,content,signedInfo);
|
| 82 |
|
| 83 | //witness is null
|
| 84 | var signature = new Signature();
|
| 85 |
|
| 86 |
|
| 87 | var co = new ContentObject(contentname,signedInfo,content,signature);
|
| 88 |
|
| 89 | co.sign();
|
| 90 |
|
| 91 |
|
| 92 | var output = encodeToHexContentObject(co);
|
| 93 |
|
| 94 | document.getElementById('result').innerHTML = output;
|
| 95 |
|
| 96 | }
|
| 97 |
|
| 98 | function decode(){
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 | var input = document.getElementById('result').innerHTML;
|
| 103 |
|
| 104 |
|
| 105 | var co = decodeHexContentObject(input);
|
| 106 |
|
| 107 | if(LOG>3)console.log('CONTENT OBJECT DECODED');
|
| 108 | if(LOG>3)console.log(co);
|
| 109 |
|
| 110 | ///////////////////////////////////////
|
| 111 |
|
| 112 | var output ="";
|
| 113 |
|
| 114 | if(co==-1)
|
| 115 | output+= "NO CONTENT FOUND"
|
| 116 | else if (co==-2)
|
| 117 | output+= "CONTENT NAME IS EMPTY"
|
| 118 | else{
|
| 119 | if(co.Name!=null && co.Name.Components!=null){
|
| 120 | output+= "NAME: ";
|
| 121 |
|
| 122 | for(var i=0;i<co.Name.Components.length;i++){
|
| 123 | output+= "/"+ toString(co.Name.Components[i]);
|
| 124 | }
|
| 125 | output+= "<br />";
|
| 126 | output+= "<br />";
|
| 127 | }
|
| 128 |
|
| 129 | if(co.Content !=null){
|
| 130 | output += "CONTENT(ASCII): "+ toString(co.Content);
|
| 131 |
|
| 132 | output+= "<br />";
|
| 133 | output+= "<br />";
|
| 134 | }
|
| 135 | if(co.Content !=null){
|
| 136 | output += "CONTENT(hex): "+ toHex(co.Content);
|
| 137 |
|
| 138 | output+= "<br />";
|
| 139 | output+= "<br />";
|
| 140 | }
|
| 141 | if(co.Signature !=null && co.Signature.Signature!=null){
|
| 142 |
|
| 143 | output += "SIGNATURE(hex): "+ toHex(co.Signature.Signature);
|
| 144 |
|
| 145 | output+= "<br />";
|
| 146 | output+= "<br />";
|
| 147 | }
|
| 148 | if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){
|
| 149 |
|
| 150 | output += "Publisher Public Key Digest(hex): "+ toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);
|
| 151 |
|
| 152 | output+= "<br />";
|
| 153 | output+= "<br />";
|
| 154 | }
|
| 155 | if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){
|
| 156 |
|
| 157 | output += "TimeStamp(hex): "+ co.SignedInfo.Timestamp.date;
|
| 158 |
|
| 159 | output+= "<br />";
|
| 160 | output+= "<br />";
|
| 161 | }
|
| 162 | if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){
|
| 163 |
|
| 164 | var publickey = rstr2b64(toString(co.SignedInfo.Locator.PublicKey));
|
| 165 | var publickeyHex = toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();
|
| 166 | var publickeyString = toString(co.SignedInfo.Locator.PublicKey);
|
| 167 |
|
| 168 | var signature = toHex(co.Signature.Signature).toLowerCase();
|
| 169 |
|
| 170 |
|
| 171 | var input = toString(co.rawSignatureData);
|
| 172 |
|
| 173 |
|
| 174 | output += "DER Certificate: "+publickey ;
|
| 175 |
|
| 176 | output+= "<br />";
|
| 177 | output+= "<br />";
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 | if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
|
| 182 | if(LOG>2) console.log(" PublicKey = "+publickey );
|
| 183 | if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
|
| 184 | if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
|
| 185 |
|
| 186 | if(LOG>2) console.log(" Signature "+signature );
|
| 187 | if(LOG>2) console.log(" Signature NOW IS" );
|
| 188 | if(LOG>2) console.log(co.Signature.Signature);
|
| 189 |
|
| 190 |
|
| 191 | var x509 = new X509();
|
| 192 |
|
| 193 | x509.readCertPEM(publickey);
|
| 194 |
|
| 195 |
|
| 196 | //x509.readCertPEMWithoutRSAInit(publickey);
|
| 197 |
|
| 198 | var result = x509.subjectPublicKeyRSA.verifyString(input, signature);
|
| 199 | console.log('result is '+result);
|
| 200 | /*var rsakey = new RSAKey();
|
| 201 |
|
| 202 | var kp = publickeyHex.slice(56,314);
|
| 203 |
|
| 204 | output += "PUBLISHER KEY(hex): "+kp ;
|
| 205 |
|
| 206 | output+= "<br />";
|
| 207 | output+= "<br />";
|
| 208 |
|
| 209 | console.log('kp is '+kp);
|
| 210 |
|
| 211 | var exp = publickeyHex.slice(318,324);
|
| 212 |
|
| 213 | console.log('kp size is '+kp.length );
|
| 214 | output += "exponent: "+exp ;
|
| 215 |
|
| 216 | output+= "<br />";
|
| 217 | output+= "<br />";
|
| 218 |
|
| 219 | console.log('exp is '+exp);
|
| 220 |
|
| 221 |
|
| 222 | rsakey.setPublic(kp,exp);
|
| 223 |
|
| 224 | var result = rsakey.verifyString(input, signature);*/
|
| 225 |
|
| 226 | if(result)
|
| 227 | output += 'SIGNATURE VALID';
|
| 228 | else
|
| 229 | output += 'SIGNATURE INVALID';
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 | //output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey);
|
| 235 |
|
| 236 | output+= "<br />";
|
| 237 | output+= "<br />";
|
| 238 |
|
| 239 |
|
| 240 | if(LOG>4) console.log('str'[1]);
|
| 241 | }
|
| 242 | }
|
| 243 |
|
| 244 | document.getElementById('result').innerHTML = output;
|
| 245 |
|
| 246 | }
|
| 247 |
|
| 248 | </script>
|
| 249 |
|
| 250 | </head>
|
| 251 | <body >
|
| 252 | <form>
|
| 253 |
|
| 254 | Please Enter a Content Name:<br />
|
| 255 |
|
| 256 | <input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" />
|
| 257 |
|
| 258 | Please Enter the Content:<br />
|
| 259 |
|
| 260 | <textarea id="content" cols="40" rows="5" name="CONTENT" value="SUCCESS" >SUCCESS!</textarea>
|
| 261 |
|
| 262 | </form>
|
| 263 | <button onclick="encode()">Encode</button>
|
| 264 | <button onclick="decode()">Decode</button>
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 | <p id="result"></p>
|
| 269 |
|
| 270 | </body>
|
| 271 | </html> |