blob: 922d34064fb7e86a050f557b2d5dc6f35c394962 [file] [log] [blame]
Meki Cherkaoui8f173612012-06-06 01:05:40 -07001<?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 Send Hex</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 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 function run(){
74 //console.log(unescape('%04%82%02%AA%03%B2%08%85H%8EY%0C%94p%F1-%C5%E2%23lW%19%8B%0D%25%81%8D%DEBeNX%BA%0D%D0%10W%7D%BA%9F%C6%8C%2AU%BC%B8%BA%5E%F3%D1l%CDmJ%EE%C4%9D%21%0F%0Djhm%1Ah%86P%D91x%26%AC%B8%8Co%C1%CF%29.l6Mc%B4%DC%C8%D4%86%97%8F%D2%1A%7C%A2%ED%93%89%F3%E9%9D%3C%E0%D4%90%28%D4%11%A2%5D%08%EB%A4%AF%96j%15%A5s%C8%D2Jr%96q%0F%87%7F%D5%D7%B3%D3T%96%F3%16L%00%00%F2%00%01%A2%03%E2%02%85%20Ht%04Z%9F%AC%98%EB%B7%DF%AD%C4%BB%D1%AB%15%A6%E4%06SI%C6%C8%3A%84%60%84N%AB1%85%00%02%BA%B5%04%FA%C3%F9%D7%97%00%01%E2%01%DA%0A%950%81%9F0%0D%06%09%2A%86H%86%F7%0D%01%01%01%05%00%03%81%8D%000%81%89%02%81%81%00%BD%95eU%9C%17%95%C0I%A5%EFM%C9%D1%BC%8B%98%1Bf%09~%A2S%F5%D0%F5%0F%1A%1D%F9%08%ACNi%A7%97%DA%DD%2C%05%90%94Jn%84%9E%1F%BBsq%C5%3D%FD%DB%E7%80%26V%E1%D5%F4I%B8S%0D%9C%7D%A8%D6%AB%EB%D9%0E%06%12M%92%7F%2FlW%21%F1%D0%E4%9E%7Fj%11g%CA%F9%60%D9o%F5%AF%AA-%25g3wr%A9D%C8%E6%CE%B8Y%B2Z%23%1D%9E%CA%875t%FF%98%22%5C%85%3F8%EF%02%03%01%00%01%00%00%00%01%9A%06%8D%05%82%04%CA%BEnewface%00%03%E2%02%85%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F%00%04%D2%8E0%00%04%DA%9617%00%04%E2%CE127.0.0.1%00%04%EA%A69695%00%03%D2%D62147483647%00%00%00%00'));
75
76 //var a = escape('%04%82%02%AA%03%B2%08%85L%90%D5X%2C%B06wHi%C5%E2%1C%03%D2M%5DB%BF%A5%8C%C8%E8g%99%EB%A7%84%25l%8EB%92%3E%AA%D8%F6%85t%FF%BB%CE%3D%B1%F4%F8%27%A7%1D.%B0%EEU%A6%06%AB%CD%1F3%C6W%93%A9%10X%28-7%7CW%D4%E4%8A3%CF%2B%E4%95%D6%B2%1D%3B%7C%E8%7C%88%7D%7B%F5%80%BC%F7%28%3A%FC%F5w%5B%8C%24%0E%0A%24%DBk%9B%8D%B5%28d%D0A%1E%BEq%0F%0Cc%DB%15%B6%26%1B%E7%E3%E3XL%00%00%F2%00%01%A2%03%E2%02%85%20Ht%04Z%9F%AC%98%EB%B7%DF%AD%C4%BB%D1%AB%15%A6%E4%06SI%C6%C8%3A%84%60%84N%AB1%85%00%02%BA%B5%04%FA%C4%C7%D3I%00%01%E2%01%DA%0A%950%81%9F0%0D%06%09%2A%86H%86%F7%0D%01%01%01%05%00%03%81%8D%000%81%89%02%81%81%00%BD%95eU%9C%17%95%C0I%A5%EFM%C9%D1%BC%8B%98%1Bf%09~%A2S%F5%D0%F5%0F%1A%1D%F9%08%ACNi%A7%97%DA%DD%2C%05%90%94Jn%84%9E%1F%BBsq%C5%3D%FD%DB%E7%80%26V%E1%D5%F4I%B8S%0D%9C%7D%A8%D6%AB%EB%D9%0E%06%12M%92%7F%2FlW%21%F1%D0%E4%9E%7Fj%11g%CA%F9%60%D9o%F5%AF%AA-%25g3wr%A9D%C8%E6%CE%B8Y%B2Z%23%1D%9E%CA%875t%FF%98%22%5C%85%3F8%EF%02%03%01%00%01%00%00%00%01%9A%06%8D%05%82%04%CA%BEnewface%00%03%E2%02%85%E0%A0%1E%099h%F9t%0C%E7%F46%1B%AB%F5%BB%05%A4%E5Z%AC%A5%E5%8Fs%ED%DE%B8%E0%13%AA%8F%00%04%D2%8E0%00%04%DA%9617%00%04%E2%CE127.0.0.1%00%04%EA%A69695%00%03%D2%D62147483647%00%00%00%00');
77
78 //var n = a.replace("%","");
79
80 //console.log(n);
81
82 var hex = document.getElementById('contentname').value;
83
84 ///////////////////////////////////////
85 //createRoute(, 9695);
86
87
88 /// /ndn/ucla.edu/apps/hydra/mainvideo
89 //createRoute('131.179.141.15', 9695);
90 //createRoute('borges.metwi.ucla.edu', 9695);
91
92 //content object
93 //var co = queryPrefix( ContentName );
94 console.log('HEX IS');
95 console.log(hex);
96
97 var result = get_java_socket_bridge().connectAndStart('localhost',9695,hex);
98
99 console.log('BINARY RESPONSE IS ' +result);
100
101 var output ="";
102 output += "HEX ANSWER IS: "+ result;
103
104 output+= "<br />";
105 output+= "<br />";
106
107 //result[0] and result[1] should be 0 and 4 if there is a content object found
108 if(result==null || result==undefined || result =="" ){
109
110
111 if(LOG>2)console.log('INVALID ANSWER');
112 output += "NO CONTENT FOUND";
113
114 output+= "<br />";
115 output+= "<br />";
116 }
117
118 else if(result[0] != '0'||result[1]!='4') {
119 if(LOG>2)console.log('INVALID ANSWER');
120 output += "INVALID ANSWER";
121
122 output+= "<br />";
123 output+= "<br />";
124 }
125 else{
126
127 var numbers = DataUtils.toNumbers(result);
128
129 console.log('HEX RESPONSE IS \n'+numbers);
130 decoder = new BinaryXMLDecoder(numbers);
131
132
133 co = new ContentObject();
134
135 co.decode(decoder);
136
137 if(LOG>2) console.log(co);
138
139 ///////////////////////////////////////
140
141
142 if(co==-1)
143 output+= "NO CONTENT FOUND"
144 else if (co==-2)
145 output+= "CONTENT NAME IS EMPTY"
146 else{
147 if(co.Name!=null && co.Name.Components!=null){
148 output+= "NAME: ";
149
150 for(var i=0;i<co.Name.Components.length;i++){
151 output+= "/"+ DataUtils.toString(co.Name.Components[i]);
152 }
153 output+= "<br />";
154 output+= "<br />";
155 }
156
157 if(co.Content !=null){
158 output += "CONTENT(ASCII): "+ DataUtils.toString(co.Content);
159
160 output+= "<br />";
161 output+= "<br />";
162 }
163 if(co.Content !=null){
164 output += "CONTENT(hex): "+ DataUtils.toHex(co.Content);
165
166 output+= "<br />";
167 output+= "<br />";
168 }
169
170 if(co.Signature !=null && co.Signature.Signature!=null){
171
172 output += "SIGNATURE(hex): "+ DataUtils.toHex(co.Signature.Signature);
173
174 output+= "<br />";
175 output+= "<br />";
176 }
177 if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){
178
179 output += "Publisher Public Key Digest(hex): "+ toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);
180
181 output+= "<br />";
182 output+= "<br />";
183 }
184 if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){
185
186 output += "TimeStamp(hex): "+ co.SignedInfo.Timestamp.date;
187
188 output+= "<br />";
189 output+= "<br />";
190 }
191 if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){
192
193 var publickey = rstr2b64(toString(co.SignedInfo.Locator.PublicKey));
194 var publickeyHex = toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();
195 var publickeyString = toString(co.SignedInfo.Locator.PublicKey);
196
197 var signature = toHex(co.Signature.Signature).toLowerCase();
198
199
200 var input = toString(co.rawSignatureData);
201
202
203 output += "DER Certificate: "+publickey ;
204
205 output+= "<br />";
206 output+= "<br />";
207
208
209
210 if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
211 if(LOG>2) console.log(" PublicKey = "+publickey );
212 if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
213 if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
214
215 if(LOG>2) console.log(" Signature "+signature );
216
217 if(LOG>2) console.log(" Signature NOW IS" );
218
219 if(LOG>2) console.log(co.Signature.Signature);
220
221
222 /*var x509 = new X509();
223
224 x509.readCertPEM(publickey);
225
226
227 //x509.readCertPEMWithoutRSAInit(publickey);
228
229 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);*/
230 //console.log('result is '+result);
231
232
233 var kp = publickeyHex.slice(56,314);
234
235 output += "PUBLISHER KEY(hex): "+kp ;
236
237 output+= "<br />";
238 output+= "<br />";
239
240 console.log('PUBLIC KEY IN HEX is ');
241 console.log(kp);
242
243 var exp = publickeyHex.slice(318,324);
244
245 console.log('kp size is '+kp.length );
246 output += "exponent: "+exp ;
247
248 output+= "<br />";
249 output+= "<br />";
250
251 console.log('EXPONENT is ');
252 console.log(exp);
253
254 var rsakey = new RSAKey();
255
256 rsakey.setPublic(kp,exp);
257
258 var result = rsakey.verifyString(input, signature);
259
260 console.log('PUBLIC KEY n after is ');
261 console.log(rsakey.n);
262
263 console.log('EXPONENT e after is ');
264 console.log(rsakey.e);
265
266
267 if(result)
268 output += 'SIGNATURE VALID';
269 else
270 output += 'SIGNATURE INVALID';
271
272
273
274
275 //output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey);
276
277 output+= "<br />";
278 output+= "<br />";
279
280
281 //if(LOG>4) console.log('str'[1]);
282 }
283 }
284 }
285 document.getElementById('result').innerHTML = output;
286 }
287
288 </script>
289
290</head>
291<body >
292 <form>
293 Please Enter a Content Name:<br /><input id="contentname" type="text" name="CONTENTNAME" value="01D2F2FAA55041524300FA9D616263000000" /> <br />
294 </form>
295 <button onclick="run()">Request Data!</button>
296 <div >
297 <applet id="JavaSocketBridge" archive="JavaSocketBridge.jar" code="JavaSocketBridge.class" width="0" height="0">
298 </applet>
299 </div>
300
301 <p id="result"></p>
302
303</body>
304</html>