Axel Colin de Verdiere | d363e63 | 2012-06-06 05:16:43 -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 </title> |
| 8 | <script type="text/javascript" src="java_socket_bridge.js"></script> |
| 9 | |
| 10 | <script type="text/javascript" src="CCNProtocolDTags.js"></script> |
| 11 | |
| 12 | <script type="text/javascript" src="CCNTime.js"></script> |
| 13 | |
| 14 | <script type="text/javascript" src="ContentName.js"></script> |
| 15 | |
| 16 | <script type="text/javascript" src="ContentObject.js"></script> |
| 17 | |
| 18 | <script type="text/javascript" src="DateFormat.js"></script> |
| 19 | |
| 20 | <script type="text/javascript" src="Exclude.js"></script> |
| 21 | |
| 22 | <script type="text/javascript" src="ExcludeAny.js"></script> |
| 23 | |
| 24 | <script type="text/javascript" src="ExcludeComponent.js"></script> |
| 25 | |
| 26 | <script type="text/javascript" src="Interest.js"></script> |
| 27 | |
| 28 | <script type="text/javascript" src="KeyLocator.js"></script> |
| 29 | |
| 30 | <script type="text/javascript" src="KeyName.js"></script> |
| 31 | |
| 32 | <script type="text/javascript" src="PublisherID.js"></script> |
| 33 | |
| 34 | <script type="text/javascript" src="Signature.js"></script> |
| 35 | |
| 36 | <script type="text/javascript" src="SignedInfo.js"></script> |
| 37 | |
| 38 | <script type="text/javascript" src="PublisherPublicKeyDigest.js"></script> |
| 39 | |
| 40 | <script type="text/javascript" src="FaceInstance.js"></script> |
| 41 | |
| 42 | <script type="text/javascript" src="ForwardingEntry.js"></script> |
| 43 | |
| 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 type="text/javascript" src="encoding/EncodingUtils.js"></script> |
| 54 | |
| 55 | <script type="text/javascript" src="lwNDN.js"></script> |
| 56 | |
| 57 | <script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script> |
| 58 | |
| 59 | <script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script> |
| 60 | <script language="JavaScript" type="text/javascript" src="securityLib/jsbn2.js"></script> |
| 61 | <script language="JavaScript" type="text/javascript" src="securityLib/rsa.js"></script> |
| 62 | <script language="JavaScript" type="text/javascript" src="securityLib/rsa2.js"></script> |
| 63 | |
| 64 | <script language="JavaScript" type="text/javascript" src="securityLib/sha1.js"></script> |
| 65 | <script language="JavaScript" type="text/javascript" src="securityLib/sha256.js"></script> |
| 66 | <script language="JavaScript" type="text/javascript" src="securityLib/sha512.js"></script> |
| 67 | <script language="JavaScript" type="text/javascript" src="securityLib/md5.js"></script> |
| 68 | <script language="JavaScript" type="text/javascript" src="securityLib/ripemd160.js"></script> |
| 69 | <script language="JavaScript" type="text/javascript" src="securityLib/base64.js"></script> |
| 70 | |
| 71 | <script language="JavaScript" type="text/javascript" src="securityLib/rsapem-1.1.js"></script> |
| 72 | <script language="JavaScript" type="text/javascript" src="securityLib/rsasign-1.2.js"></script> |
| 73 | <script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.js"></script> |
| 74 | <script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.js"></script> |
| 75 | |
| 76 | <script type="text/javascript"> |
| 77 | function run(){ |
| 78 | |
| 79 | |
| 80 | var contentName = document.getElementById('contentname').value; |
| 81 | |
| 82 | /////////////////////////////////////// |
| 83 | //createRoute('131.179.141.15', 9695); |
| 84 | //createRoute('borges.metwi.ucla.edu', 9695); |
| 85 | /// /ndn/ucla.edu/apps/hydra/mainvideo |
| 86 | /////////////////////////////////////// |
| 87 | |
| 88 | var connector = new lwNDN('127.0.0.1', 9695); |
| 89 | //var connector = new lwNDN('borges.metwi.ucla.edu', 9695); |
| 90 | |
| 91 | var co = connector.get( contentName ); |
| 92 | |
| 93 | /////////////////////////////////////// |
| 94 | //PRINT OUTPUT |
| 95 | /////////////////////////////////////// |
| 96 | |
| 97 | var output =""; |
| 98 | |
| 99 | if(co==null) |
| 100 | output+= "NO CONTENT FOUND" |
| 101 | else{ |
| 102 | if(co.Name!=null && co.Name.Components!=null){ |
| 103 | output+= "NAME: "; |
| 104 | |
| 105 | for(var i=0;i<co.Name.Components.length;i++){ |
| 106 | output+= "/"+ DataUtils.toString(co.Name.Components[i]); |
| 107 | } |
| 108 | output+= "<br />"; |
| 109 | output+= "<br />"; |
| 110 | } |
| 111 | |
| 112 | if(co.Content !=null){ |
| 113 | output += "CONTENT(ASCII): "+ DataUtils.toString(co.Content); |
| 114 | |
| 115 | output+= "<br />"; |
| 116 | output+= "<br />"; |
| 117 | } |
| 118 | if(co.Content !=null){ |
| 119 | output += "CONTENT(hex): "+ DataUtils.toHex(co.Content); |
| 120 | |
| 121 | output+= "<br />"; |
| 122 | output+= "<br />"; |
| 123 | } |
| 124 | |
| 125 | if(co.Signature !=null && co.Signature.Signature!=null){ |
| 126 | |
| 127 | output += "SIGNATURE(hex): "+ DataUtils.toHex(co.Signature.Signature); |
| 128 | |
| 129 | output+= "<br />"; |
| 130 | output+= "<br />"; |
| 131 | } |
| 132 | if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){ |
| 133 | |
| 134 | output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest); |
| 135 | |
| 136 | output+= "<br />"; |
| 137 | output+= "<br />"; |
| 138 | } |
| 139 | if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){ |
| 140 | |
| 141 | output += "TimeStamp: "+ co.SignedInfo.Timestamp.getJavascriptDate(); |
| 142 | |
| 143 | output+= "<br />"; |
| 144 | output+= "<br />"; |
| 145 | |
| 146 | output += "TimeStamp (MILLISECONDS): "+ co.SignedInfo.Timestamp.msec; |
| 147 | |
| 148 | output+= "<br />"; |
| 149 | output+= "<br />"; |
| 150 | } |
| 151 | if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){ |
| 152 | |
| 153 | var publickey = rstr2b64(DataUtils.toString(co.SignedInfo.Locator.PublicKey)); |
| 154 | var publickeyHex = DataUtils.toHex(co.SignedInfo.Locator.PublicKey).toLowerCase(); |
| 155 | var publickeyString = DataUtils.toString(co.SignedInfo.Locator.PublicKey); |
| 156 | |
| 157 | var signature = DataUtils.toHex(co.Signature.Signature).toLowerCase(); |
| 158 | |
| 159 | |
| 160 | var input = DataUtils.toString(co.rawSignatureData); |
| 161 | |
| 162 | |
| 163 | output += "DER Certificate: "+publickey ; |
| 164 | |
| 165 | output+= "<br />"; |
| 166 | output+= "<br />"; |
| 167 | |
| 168 | |
| 169 | |
| 170 | if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input); |
| 171 | if(LOG>2) console.log(" PublicKey = "+publickey ); |
| 172 | if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex ); |
| 173 | if(LOG>2) console.log(" PublicKeyString = "+publickeyString ); |
| 174 | |
| 175 | if(LOG>2) console.log(" Signature "+signature ); |
| 176 | |
| 177 | if(LOG>2) console.log(" Signature NOW IS" ); |
| 178 | |
| 179 | if(LOG>2) console.log(co.Signature.Signature); |
| 180 | |
| 181 | |
| 182 | /*var x509 = new X509(); |
| 183 | |
| 184 | x509.readCertPEM(publickey); |
| 185 | |
| 186 | |
| 187 | //x509.readCertPEMWithoutRSAInit(publickey); |
| 188 | |
| 189 | var result = x509.subjectPublicKeyRSA.verifyString(input, signature);*/ |
| 190 | //console.log('result is '+result); |
| 191 | |
| 192 | |
| 193 | var kp = publickeyHex.slice(56,314); |
| 194 | |
| 195 | output += "PUBLISHER KEY(hex): "+kp ; |
| 196 | |
| 197 | output+= "<br />"; |
| 198 | output+= "<br />"; |
| 199 | |
| 200 | console.log('PUBLIC KEY IN HEX is '); |
| 201 | console.log(kp); |
| 202 | |
| 203 | var exp = publickeyHex.slice(318,324); |
| 204 | |
| 205 | console.log('kp size is '+kp.length ); |
| 206 | output += "exponent: "+exp ; |
| 207 | |
| 208 | output+= "<br />"; |
| 209 | output+= "<br />"; |
| 210 | |
| 211 | console.log('EXPONENT is '); |
| 212 | console.log(exp); |
| 213 | |
| 214 | |
| 215 | |
| 216 | /*var c1 = hex_sha256(input); |
| 217 | var c2 = signature; |
| 218 | |
| 219 | if(LOG>4)console.log('input is '); |
| 220 | if(LOG>4)console.log(input); |
| 221 | if(LOG>4)console.log('C1 is '); |
| 222 | if(LOG>4)console.log(c1); |
| 223 | if(LOG>4)console.log('C2 is '); |
| 224 | if(LOG>4)console.log(c2); |
| 225 | var result = c1 == c2;*/ |
| 226 | |
| 227 | var rsakey = new RSAKey(); |
| 228 | |
| 229 | rsakey.setPublic(kp,exp); |
| 230 | |
| 231 | var result = rsakey.verifyByteArray(co.rawSignatureData,signature); |
| 232 | // var result = rsakey.verifyString(input, signature); |
| 233 | |
| 234 | |
| 235 | |
| 236 | console.log('PUBLIC KEY n after is '); |
| 237 | console.log(rsakey.n); |
| 238 | |
| 239 | console.log('EXPONENT e after is '); |
| 240 | console.log(rsakey.e); |
| 241 | |
| 242 | |
| 243 | if(result) |
| 244 | output += 'SIGNATURE VALID'; |
| 245 | else |
| 246 | output += 'SIGNATURE INVALID'; |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | //output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey); |
| 252 | |
| 253 | output+= "<br />"; |
| 254 | output+= "<br />"; |
| 255 | |
| 256 | document.getElementById('image').src += DataUtils.toString(co.Content); |
| 257 | //if(LOG>4) console.log('str'[1]); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | document.getElementById('result').innerHTML = output; |
| 262 | } |
| 263 | |
| 264 | </script> |
| 265 | |
| 266 | </head> |
| 267 | <body > |
| 268 | <form> |
| 269 | Please Enter a Content Name:<br /><input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" /> <br /> |
| 270 | </form> |
| 271 | <button onclick="run()">Request Data!</button> |
| 272 | <div > |
| 273 | <applet id="JavaSocketBridge" archive="JavaSocketBridge.jar" code="JavaSocketBridge.class" width="0" height="0"> |
| 274 | </applet> |
| 275 | </div> |
| 276 | |
| 277 | <p id="result"></p> |
| 278 | <div> |
| 279 | <img id="image" src="data:image/png;base64," alt="Red dot" /> |
| 280 | </div> |
| 281 | |
| 282 | </body> |
| 283 | </html> |