blob: 52fe138cbb52cb3b0802081e94fd37bdf4d447d9 [file] [log] [blame]
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -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>
Meki Cherkaoui8f173612012-06-06 01:05:40 -07007 <title>NDN Encode/Decode Content Object</title>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -07008
Jeff Thompson7ed5ef52012-08-26 11:28:48 -07009 <script type="text/javascript" src="../java_socket_bridge.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070010
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070011 <script type="text/javascript" src="../CCNProtocolDTags.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070012
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070013 <script type="text/javascript" src="../CCNTime.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070014
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070015 <script type="text/javascript" src="../ContentName.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070016
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070017 <script type="text/javascript" src="../ContentObject.js"></script>
Meki Cherkaoui8f173612012-06-06 01:05:40 -070018
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070019 <script type="text/javascript" src="../Exclude.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070020
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070021 <script type="text/javascript" src="../ExcludeAny.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070022
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070023 <script type="text/javascript" src="../ExcludeComponent.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070024
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070025 <script type="text/javascript" src="../Interest.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070026
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070027 <script type="text/javascript" src="../KeyLocator.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070028
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070029 <script type="text/javascript" src="../KeyName.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070030
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070031 <script type="text/javascript" src="../PublisherID.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070032
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070033 <script type="text/javascript" src="../Signature.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070034
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070035 <script type="text/javascript" src="../SignedInfo.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070036
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070037 <script type="text/javascript" src="../PublisherPublicKeyDigest.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070038
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070039 <script type="text/javascript" src="../FaceInstance.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070040
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070041 <script type="text/javascript" src="../ForwardingEntry.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070042
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070043 <script type="text/javascript" src="../encoding/BinaryXMLEncoder.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070044
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070045 <script type="text/javascript" src="../encoding/BinaryXMLCodec.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070046
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070047 <script type="text/javascript" src="../encoding/BinaryXMLDecoder.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070048
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070049 <script type="text/javascript" src="../encoding/DataUtils.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070050
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070051 <script type="text/javascript" src="../encoding/EncodingUtils.js"></script>
Meki Cherkaoui8f173612012-06-06 01:05:40 -070052
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070053 <script language="JavaScript" type="text/javascript" src="../security/KeyManager.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070054
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070055 <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>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070059
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070060 <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>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070066
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070067 <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>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070071
72 <script type="text/javascript">
73
74 function encode(){
Meki Cherkaoui8f173612012-06-06 01:05:40 -070075 var contentname = new ContentName( document.getElementById('contentname').value );
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070076
77 var content = document.getElementById('content').value;
78
79 var signedInfo = new SignedInfo();
Meki Cherkaoui8f173612012-06-06 01:05:40 -070080
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070081 signedInfo.setFields();
82 //var signatureBits = generateSignatureBits(contentname,content,signedInfo);
83
84 //witness is null
85 var signature = new Signature();
86
87
88 var co = new ContentObject(contentname,signedInfo,content,signature);
89
90 co.sign();
91
92
93 var output = encodeToHexContentObject(co);
94
95 document.getElementById('result').innerHTML = output;
96
97 }
98
99 function decode(){
100
101
102
103 var input = document.getElementById('result').innerHTML;
104
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700105 input = input.toUpperCase();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700106
107 var co = decodeHexContentObject(input);
108
109 if(LOG>3)console.log('CONTENT OBJECT DECODED');
110 if(LOG>3)console.log(co);
111
112 ///////////////////////////////////////
113
114 var output ="";
115
116 if(co==-1)
117 output+= "NO CONTENT FOUND"
118 else if (co==-2)
119 output+= "CONTENT NAME IS EMPTY"
120 else{
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700121
122
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700123 if(co.Name!=null && co.Name.Components!=null){
124 output+= "NAME: ";
125
126 for(var i=0;i<co.Name.Components.length;i++){
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700127 output+= "/"+ DataUtils.toString(co.Name.Components[i]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700128 }
129 output+= "<br />";
130 output+= "<br />";
131 }
132
133 if(co.Content !=null){
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700134 output += "CONTENT(ASCII): "+ DataUtils.toString(co.Content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700135
136 output+= "<br />";
137 output+= "<br />";
138 }
139 if(co.Content !=null){
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700140 output += "CONTENT(hex): "+ DataUtils.toHex(co.Content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700141
142 output+= "<br />";
143 output+= "<br />";
144 }
145 if(co.Signature !=null && co.Signature.Signature!=null){
146
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700147 output += "SIGNATURE(hex): "+ DataUtils.toHex(co.Signature.Signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700148
149 output+= "<br />";
150 output+= "<br />";
151 }
152 if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){
153
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700154 output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700155
156 output+= "<br />";
157 output+= "<br />";
158 }
159 if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700160 var d = new Date();
161 d.setTime( co.SignedInfo.Timestamp.msec );
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700162
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700163 var bytes = [217, 185, 12, 225, 217, 185, 12, 225];
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700164
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700165 output += "TimeStamp: "+d;
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700166 output+= "<br />";
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700167 output += "TimeStamp(number): "+ co.SignedInfo.Timestamp.msec;
168
169
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700170 output+= "<br />";
171 }
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700172 if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.Certificate!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700173
174
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700175 var tmp = DataUtils.toString(co.SignedInfo.Locator.Certificate);
176
177
178 var publickey = rstr2b64(tmp);
179
180
181
182 var publickeyHex = DataUtils.toHex(co.SignedInfo.Locator.Certificate).toLowerCase();
183
184 var publickeyString = DataUtils.toString(co.SignedInfo.Locator.Certificate);
185
186 var signature = DataUtils.toHex(co.Signature.Signature).toLowerCase();
187
188
189 var input = DataUtils.toString(co.rawSignatureData);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700190
191
192 output += "DER Certificate: "+publickey ;
193
194 output+= "<br />";
195 output+= "<br />";
196
197
198
199 if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700200
201 if(LOG>2) console.log("HEX OF ContentName + SignedInfo + Content = ");
202 if(LOG>2) console.log(DataUtils.stringtoBase64(input));
203
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700204 if(LOG>2) console.log(" PublicKey = "+publickey );
205 if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
206 if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
207
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700208 if(LOG>2) console.log(" Signature is");
209 if(LOG>2) console.log( signature );
210 //if(LOG>2) console.log(" Signature NOW IS" );
211 //if(LOG>2) console.log(co.Signature.Signature);
212
213
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700214 var x509 = new X509();
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700215
216
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700217 x509.readCertPEM(publickey);
218
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700219 //x509.readCertPEMWithoutRSAInit(publickey);
220
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700221 var result = x509.subjectPublicKeyRSA.verifyByteArray(co.rawSignatureData, signature);
222 if(LOG>2) console.log('result is '+result);
223
224
225 var n = x509.subjectPublicKeyRSA.n;
226
227 var e = x509.subjectPublicKeyRSA.e;
228
229 if(LOG>2) console.log('PUBLIC KEY n after is ');
230 if(LOG>2) console.log(n);
231
232 if(LOG>2) console.log('EXPONENT e after is ');
233 if(LOG>2) console.log(e);
234
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700235 /*var rsakey = new RSAKey();
236
237 var kp = publickeyHex.slice(56,314);
238
239 output += "PUBLISHER KEY(hex): "+kp ;
240
241 output+= "<br />";
242 output+= "<br />";
243
244 console.log('kp is '+kp);
245
246 var exp = publickeyHex.slice(318,324);
247
248 console.log('kp size is '+kp.length );
249 output += "exponent: "+exp ;
250
251 output+= "<br />";
252 output+= "<br />";
253
254 console.log('exp is '+exp);
255
256
257 rsakey.setPublic(kp,exp);
258
259 var result = rsakey.verifyString(input, signature);*/
260
261 if(result)
262 output += 'SIGNATURE VALID';
263 else
264 output += 'SIGNATURE INVALID';
265
266
267
268
269 //output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey);
270
271 output+= "<br />";
272 output+= "<br />";
273
274
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700275 //if(LOG>4) console.log('str'[1]);
276 }
277 if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){
278
279
280 var publickey = rstr2b64(DataUtils.toString(co.SignedInfo.Locator.PublicKey));
281 var publickeyHex = DataUtils.toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();
282 var publickeyString = DataUtils.toString(co.SignedInfo.Locator.PublicKey);
283
284 var signature = DataUtils.toHex(co.Signature.Signature).toLowerCase();
285
286
287 var input = DataUtils.toString(co.rawSignatureData);
288
289
290 output += "DER Certificate: "+publickey ;
291
292 output+= "<br />";
293 output+= "<br />";
294
295 if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
296 if(LOG>2) console.log(" PublicKey = "+publickey );
297 if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
298 if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
299
300 if(LOG>2) console.log(" Signature "+signature );
301
302 if(LOG>2) console.log(" Signature NOW IS" );
303
304 if(LOG>2) console.log(co.Signature.Signature);
305
306
307 /*var x509 = new X509();
308
309 x509.readCertPEM(publickey);
310
311
312 //x509.readCertPEMWithoutRSAInit(publickey);
313
314 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);*/
315 //console.log('result is '+result);
316
317
318 var kp = publickeyHex.slice(56,314);
319
320 output += "PUBLISHER KEY(hex): "+kp ;
321
322 output+= "<br />";
323 output+= "<br />";
324
325 console.log('PUBLIC KEY IN HEX is ');
326 console.log(kp);
327
328 var exp = publickeyHex.slice(318,324);
329
330 console.log('kp size is '+kp.length );
331 output += "exponent: "+exp ;
332
333 output+= "<br />";
334 output+= "<br />";
335
336 console.log('EXPONENT is ');
337 console.log(exp);
338
339
340
341 /*var c1 = hex_sha256(input);
342 var c2 = signature;
343
344 if(LOG>4)console.log('input is ');
345 if(LOG>4)console.log(input);
346 if(LOG>4)console.log('C1 is ');
347 if(LOG>4)console.log(c1);
348 if(LOG>4)console.log('C2 is ');
349 if(LOG>4)console.log(c2);
350 var result = c1 == c2;*/
351
352 var rsakey = new RSAKey();
353
354 rsakey.setPublic(kp,exp);
355
356 var result = rsakey.verifyByteArray(co.rawSignatureData,signature);
357 // var result = rsakey.verifyString(input, signature);
358
359
360
361 console.log('PUBLIC KEY n after is ');
362 console.log(rsakey.n);
363
364 console.log('EXPONENT e after is ');
365 console.log(rsakey.e);
366
367
368 if(result)
369 output += 'SIGNATURE VALID';
370 else
371 output += 'SIGNATURE INVALID';
372
373
374
375
376 //output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey);
377
378 output+= "<br />";
379 output+= "<br />";
380
381
382 //if(LOG>4) console.log('str'[1]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700383 }
384 }
385
386 document.getElementById('result').innerHTML = output;
387
388 }
389
390 </script>
391
392</head>
393<body >
394 <form>
395
396 Please Enter a Content Name:<br />
397
398 <input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" />
399
Jeff Thompson12b029d2012-08-26 11:51:27 -0700400 <br />Please Enter the Content:<br />
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700401
402 <textarea id="content" cols="40" rows="5" name="CONTENT" value="SUCCESS" >SUCCESS!</textarea>
403
404 </form>
405 <button onclick="encode()">Encode</button>
406 <button onclick="decode()">Decode</button>
407
408
Jeff Thompson12b029d2012-08-26 11:51:27 -0700409 <p id="result"></p>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700410
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700411
412</body>
413</html>