blob: 6910e7cd106d6cbb323fb0d5e1a226a458699b1d [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 Decode Interest + Face Instance</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 type="text/javascript" src="encoding/EncodingUtils.js"></script>
54
55
56 <script language="JavaScript" type="text/javascript" src="security/KeyManager.js"></script>
57
58 <script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>
59 <script language="JavaScript" type="text/javascript" src="securityLib/jsbn2.js"></script>
60 <script language="JavaScript" type="text/javascript" src="securityLib/rsa.js"></script>
61 <script language="JavaScript" type="text/javascript" src="securityLib/rsa2.js"></script>
62
63 <script language="JavaScript" type="text/javascript" src="securityLib/sha1.js"></script>
64 <script language="JavaScript" type="text/javascript" src="securityLib/sha256.js"></script>
65 <script language="JavaScript" type="text/javascript" src="securityLib/sha512.js"></script>
66 <script language="JavaScript" type="text/javascript" src="securityLib/md5.js"></script>
67 <script language="JavaScript" type="text/javascript" src="securityLib/ripemd160.js"></script>
68 <script language="JavaScript" type="text/javascript" src="securityLib/base64.js"></script>
69
70 <script language="JavaScript" type="text/javascript" src="securityLib/rsapem-1.1.js"></script>
71 <script language="JavaScript" type="text/javascript" src="securityLib/rsasign-1.2.js"></script>
72 <script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.js"></script>
73 <script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.js"></script>
74
75 <script type="text/javascript">
76
77
78
79 function decode(){
80
81
82 var input = document.getElementById('result').innerHTML;
83
84
85 var interest = decodeHexInterest(input);
86
87 if(LOG>3)console.log('INTEREST DECODED');
88 if(LOG>3)console.log(interest);
89
90 ///////////////////////////////////////
91
92 var output ="";
93
94
95 if(interest.Name!=null && interest.Name.Components!=null){
96 output+= "NAME: ";
97
98 for(var i=0;i<interest.Name.Components.length;i++){
99 output+= "/"+ DataUtils.toString(interest.Name.Components[i]);
100 }
101 output+= "<br />";
102 output+= "<br />";
103 }
104
105 if(interest.FaceInstance!=null ){
106 output+= "FaceInstance: ";
107
108 output+= interest.FaceInstance;
109
110 output+= "<br />";
111 output+= "<br />";
112 }
113
114 if(interest.Exclude!=null ){
115 output+= "Exclude: ";
116
117 output+= interest.Exclude;
118
119 output+= "<br />";
120 output+= "<br />";
121 }
122
123 if(interest.ChildSelector!=null ){
124 output+= "ChildSelector: ";
125
126 output+= interest.ChildSelector;
127
128 output+= "<br />";
129 output+= "<br />";
130 }
131
132 if(interest.AnswerOriginKind!=null ){
133 output+= "AnswerOriginKind: ";
134
135 output+= interest.AnswerOriginKind;
136
137 output+= "<br />";
138 output+= "<br />";
139 }
140
141 if(interest.InterestLifetime!=null ){
142 output+= "InterestLifetime: ";
143
144 output+= interest.InterestLifetime;
145
146 output+= "<br />";
147 output+= "<br />";
148 }
149
150 if(interest.Nonce!=null ){
151 output+= "Nonce: ";
152
153 output+= interest.Nonce;
154
155 output+= "<br />";
156 output+= "<br />";
157 }
158
159
160 if(interest.Scope!=null ){
161 output+= "SCOPE: ";
162
163 output+= interest.Scope;
164
165 output+= "<br />";
166 output+= "<br />";
167 }
168
169 if(interest.PublisherID!=null ){
170 output+= "PUBLISHER ID: ";
171
172 output+= interest.PublisherID.PublisherID;
173
174 output+= "PUBLISHER ID TYPE: ";
175 output+= interest.PublisherID.PublisherType;
176 output+= "<br />";
177 output+= "<br />";
178 }
179
180 if(interest.MaxSuffixComponents!=null ){
181 output+= "MaxSuffixComponents : ";
182
183 output+= interest.MaxSuffixComponents;
184
185 output+= "<br />";
186 output+= "<br />";
187 }
188
189 if(interest.MinSuffixComponents!=null ){
190 output+= "MinSuffixComponents : ";
191
192 output+= interest.MinSuffixComponents;
193
194 output+= "<br />";
195 output+= "<br />";
196 }
197
198 if(interest.MinSuffixComponents!=null ){
199 output+= "MinSuffixComponents : ";
200
201 output+= interest.MinSuffixComponents;
202
203 output+= "<br />";
204 output+= "<br />";
205 }
206
207 if(interest.Name.Components[3] !=null){
208
209
210 var input = DataUtils.toHex(interest.Name.Components[3]) ;
211
212 var contentObject = decodeHexContentObject(input);
213
214 if(contentObject.Content!=null ){
215 output+= "Content of content Object: ";
216
217 output+= DataUtils.toHex(contentObject.Content);
218
219 output+= "<br />";
220 output+= "<br />";
221 }
222
223
224 var content = DataUtils.toHex(contentObject.Content);
225
226 var co = contentObject;
227
228
229 ////////////////////////////////////////
230
231
232 if(co.Name!=null && co.Name.Components!=null){
233 output+= "NAME: ";
234
235 for(var i=0;i<co.Name.Components.length;i++){
236 output+= "/"+ DataUtils.toString(co.Name.Components[i]);
237 }
238 output+= "<br />";
239 output+= "<br />";
240 }
241
242 if(co.Content !=null){
243 output += "CONTENT(ASCII): "+ DataUtils.toString(co.Content);
244
245 output+= "<br />";
246 output+= "<br />";
247 }
248 if(co.Content !=null){
249 output += "CONTENT(hex): "+ DataUtils.toHex(co.Content);
250
251 output+= "<br />";
252 output+= "<br />";
253 }
254 if(co.Signature !=null && co.Signature.Signature!=null){
255
256 output += "SIGNATURE(hex): "+ DataUtils.toHex(co.Signature.Signature);
257
258 output+= "<br />";
259 output+= "<br />";
260 }
261 if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){
262
263 output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);
264
265 output+= "<br />";
266 output+= "<br />";
267 }
268 if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){
269 var d = new Date();
270 d.setTime( co.SignedInfo.Timestamp.msec );
271
272 var bytes = [217, 185, 12, 225, 217, 185, 12, 225];
273
274 output += "TimeStamp: "+d;
275 output+= "<br />";
276 output += "TimeStamp(number): "+ co.SignedInfo.Timestamp.msec;
277
278
279 output+= "<br />";
280 }
281 if(co.SignedInfo !=null && co.SignedInfo.Type!=null){
282
283 output += "Type: "+co.SignedInfo.Type;
284 output+= "<br />";
285 output+= "<br />";
286 }
287 if(co.SignedInfo !=null && co.SignedInfo.Locator!=null){
288
289 output += "Locator: "+co.SignedInfo.Locator.Type;
290 output+= "<br />";
291 output+= "<br />";
292 }
293 if(co.SignedInfo !=null && co.SignedInfo.FreshnessSeconds!=null){
294
295 output += "FreshnessSeconds: "+co.SignedInfo.FreshnessSeconds;
296 output+= "<br />";
297 output+= "<br />";
298 }
299 if(co.SignedInfo !=null && co.SignedInfo.FinalBlockID!=null){
300
301 output += "FinalBlockID: "+co.SignedInfo.FinalBlockID;
302 output+= "<br />";
303 output+= "<br />";
304 }
305
306 if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){
307
308 var publickey = rstr2b64(DataUtils.toString(co.SignedInfo.Locator.PublicKey));
309 var publickeyHex = DataUtils.toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();
310 var publickeyString = DataUtils.toString(co.SignedInfo.Locator.PublicKey);
311
312 var signature = DataUtils.toHex(co.Signature.Signature).toLowerCase();
313
314
315 var input = DataUtils.toString(co.rawSignatureData);
316
317
318 output += "DER Certificate: "+publickey ;
319
320 output+= "<br />";
321 output+= "<br />";
322
323
324
325 if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
326 if(LOG>2) console.log(" PublicKey = "+publickey );
327 if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
328 if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
329
330 if(LOG>2) console.log(" Signature "+signature );
331
332 if(LOG>2) console.log(" Signature NOW IS" );
333
334 if(LOG>2) console.log(co.Signature.Signature);
335
336
337 /*var x509 = new X509();
338
339 x509.readCertPEM(publickey);
340
341
342 //x509.readCertPEMWithoutRSAInit(publickey);
343
344 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);*/
345 //console.log('result is '+result);
346
347
348 var kp = publickeyHex.slice(56,314);
349
350 output += "PUBLISHER KEY(hex): "+kp ;
351
352 output+= "<br />";
353 output+= "<br />";
354
355 console.log('PUBLIC KEY IN HEX is ');
356 console.log(kp);
357
358 var exp = publickeyHex.slice(318,324);
359
360 console.log('kp size is '+kp.length );
361 output += "exponent: "+exp ;
362
363 output+= "<br />";
364 output+= "<br />";
365
366 console.log('EXPONENT is ');
367 console.log(exp);
368
369
370
371 /*var c1 = hex_sha256(input);
372 var c2 = signature;
373
374 if(LOG>4)console.log('input is ');
375 if(LOG>4)console.log(input);
376 if(LOG>4)console.log('C1 is ');
377 if(LOG>4)console.log(c1);
378 if(LOG>4)console.log('C2 is ');
379 if(LOG>4)console.log(c2);
380 var result = c1 == c2;*/
381
382 var rsakey = new RSAKey();
383
384 rsakey.setPublic(kp,exp);
385
386 var result = rsakey.verifyString(input, signature);
387
388
389
390 console.log('PUBLIC KEY n after is ');
391 console.log(rsakey.n);
392
393 console.log('EXPONENT e after is ');
394 console.log(rsakey.e);
395
396
397 if(result)
398 output += 'SIGNATURE VALID';
399 else
400 output += 'SIGNATURE INVALID';
401
402 //output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey);
403
404 output+= "<br />";
405 output+= "<br />";
406
407
408 //if(LOG>4) console.log('str'[1]);
409 }
410
411 ////////////////////////////////////////
412
413
414 var forwardingEntry = decodeHexForwardingEntry(content);
415
416 if(LOG>3)console.log('FORWARDING ENTRY IS PRESENT');
417 if(LOG>3)console.log(forwardingEntry);
418
419 ///////////////////////////////////////
420
421 //var output ="";
422
423 if(forwardingEntry.Action!=null ){
424 output+= "Action: ";
425
426 output+= DataUtils.toHex(forwardingEntry.Action);
427
428 output+= "<br />";
429 output+= "<br />";
430 }
431
432 if(forwardingEntry.PrefixName!=null){
433 output+= "PrefixName: ";
434
435 output+= forwardingEntry.PrefixName.getName();
436 output+= "<br />";
437 }
438
439 if(forwardingEntry.CCNID!=null){
440 output+= "CCNID: ";
441
442 output+= forwardingEntry.CCNID;
443 output+= "<br />";
444 }
445
446 if(forwardingEntry.Flags!=null){
447 output+= "Flags: ";
448
449 output+= forwardingEntry.Flags;
450 output+= "<br />";
451 }
452
453 if(forwardingEntry.Lifetime!=null){
454 output+= "Lifetime: ";
455
456 output+= forwardingEntry.Lifetime;
457 output+= "<br />";
458 }
459
460
461 }
462
463
464
465 document.getElementById('result').innerHTML = output;
466
467 }
468
469 </script>
470
471</head>
472<body >
473 <form>
474
475 Please Press decode:<br />
476
477
478 </form>
479 <button onclick="decode()">Decode</button>
480
481 <!-- p id="result-old-from-ccnx">01d2f2faa563636e7800fa0285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f00fabd73656c6672656700fa1bf5048202aa03b208854a18988c72aee624da28e2e1acbccb209b8e89429041985521ed68f95a1c546872fba3d854b1377dc249b6d8ec5935e5069256c97a7f6d8a62e86222ccd2cfe5097aed3fe5ede6732ce191a8680d78e39d0c5058a2b7bb0f0687994e9f045de346b66c46498547a08da1f2f0cdfafba3afdfe7107931935ede79040137ba94a90000f20001a203e202851a4860caa4991e829bcdc9429fb711d52440968d23560726606050bf147acffc0002bab504fcb3f03aa40001e201da0a9530819f300d06092a864886f70d010101050003818d00308189028181008ed27580e3d1c4c67672208665133a1ba12d8ebf5cad8e054571926b3ff0782a04c71703384021a6cefb6616b66cbd8a679b761d69d6373a851546e26f7105510b4c23be9a3c7f2e652e100ecc1471855730659f1477ce4e8504ad1fd8f44116baaeae2ff67eec33abba790157a79bf5039e5a528a471d9d67c94e70117ed7490203010001000000019a0585058a04cabe73656c6672656700f2faad726f63636f000003e20285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f0004fa8e330003d2d63231343734383336343700000000000002d28e310000</p-->
482
483 <p id="result">01d2f2faa563636e7800fa0285e0a01e093968f9740ce7f4361babf5bb05a4e55aaca5e58f73eddeb8e013aa8f00facd70726566697872656700fa29ad048202aa03b208854ddbf69779cdf4ef74be99474478c8bc3ca0873e0ffa1fa60120aa276db122b83404e595a8a3caeaf09630276658ba4e7beaadb4b91a8cc58e19ac4a42289507ed8d609aa9bef61a5a507f349c83d2944b8c16fecfd90d4a40ddb8687592c0a57517564235b2e359db54f51a37e1ac39e518a2196e3ffda7eb2fb301f3c404dd0000f20001a203e20285ef7c4f5d4743a8b8586ea2e741b7fc39d1dc0dbe1b1930e787cfd1d833ea7a610002bab504fce9e253d70001e2018219fd3082019b30820104020900b7d85c906bad52ee300d06092a864886f70d010105050030123110300e060355040313076178656c636476301e170d3132303432383233343433375a170d3132303532383233343433375a30123110300e060355040313076178656c63647630819f300d06092a864886f70d010101050003818d0030818902818100e17d30a7d828ab1b840b17542dcaf6207afd221e086b2a60d16cb7f54448ba9f3f08bcd099db21dd162a779e61aa89eee554d3a47de230bc7ac590d524067c3898bba6f5dc4360b845eda48cbd9cf126a723445f0e1952d7325a75faf556144f9a98af7186b0278685b8e2c08bea87171b4dee585c1828295b5395eb4a17779f0203010001300d06092a864886f70d010105050003818100cb3ab0357d7cd2ae97ed501e51a3a0e2817d418e47fb17906477af61495a7e8d8789141065b082d001f4b15193d0b43fb661cde20a6498372c6abbd3dcb9f0d12659ef07b3c6dbdf8bdf2f65477eed7adcd457d793b1c27badda7c5ade80ce95b7d8827fe78c8a35f3fb4ba648a081be2cfe84231abab3c2b531746df2e0492b000000019a02d5058a04cabe73656c6672656700f2faa56d656b69000004fa8e330003d2d63231343734383336343700000000000002d28e310000</p>
484
485</body>
486</html>