blob: b86170b69ab98bd628bfd91516ee3354c4200f05 [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 Request </title>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -07008 <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
Meki Cherkaoui8f173612012-06-06 01:05:40 -070053 <script type="text/javascript" src="encoding/EncodingUtils.js"></script>
54
55 <script type="text/javascript" src="lwNDN.js"></script>
56
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070057 <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(){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070078
Meki Cherkaoui8f173612012-06-06 01:05:40 -070079
80 var contentName = document.getElementById('contentname').value;
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070081
82 ///////////////////////////////////////
Meki Cherkaoui8f173612012-06-06 01:05:40 -070083 //createRoute('131.179.141.15', 9695);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070084 //createRoute('borges.metwi.ucla.edu', 9695);
Meki Cherkaoui8f173612012-06-06 01:05:40 -070085 /// /ndn/ucla.edu/apps/hydra/mainvideo
86 ///////////////////////////////////////
87
88 var connector = new lwNDN('127.0.0.1', 9695);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070089
Meki Cherkaoui8f173612012-06-06 01:05:40 -070090 var co = connector.get( contentName );
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070091
92 ///////////////////////////////////////
Meki Cherkaoui8f173612012-06-06 01:05:40 -070093 //PRINT OUTPUT
94 ///////////////////////////////////////
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070095
96 var output ="";
97
Meki Cherkaoui8f173612012-06-06 01:05:40 -070098 if(co==null)
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070099 output+= "NO CONTENT FOUND"
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700100 else{
Jeff Thompson86aea882012-09-29 17:32:48 -0700101 if(co.name!=null && co.name.Components!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700102 output+= "NAME: ";
103
Jeff Thompson86aea882012-09-29 17:32:48 -0700104 for(var i=0;i<co.name.Components.length;i++){
105 output+= "/"+ DataUtils.toString(co.name.Components[i]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700106 }
107 output+= "<br />";
108 output+= "<br />";
109 }
110
Jeff Thompson86aea882012-09-29 17:32:48 -0700111 if(co.content !=null){
112 output += "CONTENT(ASCII): "+ DataUtils.toString(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700113
114 output+= "<br />";
115 output+= "<br />";
116 }
Jeff Thompson86aea882012-09-29 17:32:48 -0700117 if(co.content !=null){
118 output += "CONTENT(hex): "+ DataUtils.toHex(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700119
120 output+= "<br />";
121 output+= "<br />";
122 }
123
124 if(co.Signature !=null && co.Signature.Signature!=null){
125
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700126 output += "SIGNATURE(hex): "+ DataUtils.toHex(co.Signature.Signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700127
128 output+= "<br />";
129 output+= "<br />";
130 }
131 if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){
132
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700133 output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700134
135 output+= "<br />";
136 output+= "<br />";
137 }
138 if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){
139
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700140 output += "TimeStamp: "+ co.SignedInfo.Timestamp.getJavascriptDate();
141
142 output+= "<br />";
143 output+= "<br />";
144
145 output += "TimeStamp (MILLISECONDS): "+ co.SignedInfo.Timestamp.msec;
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700146
147 output+= "<br />";
148 output+= "<br />";
149 }
150 if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){
151
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700152 var publickey = rstr2b64(DataUtils.toString(co.SignedInfo.Locator.PublicKey));
153 var publickeyHex = DataUtils.toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();
154 var publickeyString = DataUtils.toString(co.SignedInfo.Locator.PublicKey);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700155
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700156 var signature = DataUtils.toHex(co.Signature.Signature).toLowerCase();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700157
158
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700159 var input = DataUtils.toString(co.rawSignatureData);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700160
161
162 output += "DER Certificate: "+publickey ;
Meki Cherkaoui81bfc282012-06-06 03:23:25 -0700163
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700164 output+= "<br />";
165 output+= "<br />";
166
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700167 if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
168 if(LOG>2) console.log(" PublicKey = "+publickey );
169 if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
170 if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
171
172 if(LOG>2) console.log(" Signature "+signature );
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700173
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700174 if(LOG>2) console.log(" Signature NOW IS" );
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700175
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700176 if(LOG>2) console.log(co.Signature.Signature);
177
178
179 /*var x509 = new X509();
180
181 x509.readCertPEM(publickey);
182
183
184 //x509.readCertPEMWithoutRSAInit(publickey);
185
186 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);*/
187 //console.log('result is '+result);
188
189
190 var kp = publickeyHex.slice(56,314);
191
192 output += "PUBLISHER KEY(hex): "+kp ;
193
194 output+= "<br />";
195 output+= "<br />";
196
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700197 console.log('PUBLIC KEY IN HEX is ');
198 console.log(kp);
199
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700200 var exp = publickeyHex.slice(318,324);
201
202 console.log('kp size is '+kp.length );
203 output += "exponent: "+exp ;
204
205 output+= "<br />";
206 output+= "<br />";
207
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700208 console.log('EXPONENT is ');
209 console.log(exp);
210
211
212
213 /*var c1 = hex_sha256(input);
214 var c2 = signature;
215
216 if(LOG>4)console.log('input is ');
217 if(LOG>4)console.log(input);
218 if(LOG>4)console.log('C1 is ');
219 if(LOG>4)console.log(c1);
220 if(LOG>4)console.log('C2 is ');
221 if(LOG>4)console.log(c2);
222 var result = c1 == c2;*/
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700223
224 var rsakey = new RSAKey();
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700225
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700226 rsakey.setPublic(kp,exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700227
228 var result = rsakey.verifyByteArray(co.rawSignatureData,signature);
229 // var result = rsakey.verifyString(input, signature);
230
231
232
233 console.log('PUBLIC KEY n after is ');
234 console.log(rsakey.n);
235
236 console.log('EXPONENT e after is ');
237 console.log(rsakey.e);
238
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700239
240 if(result)
241 output += 'SIGNATURE VALID';
242 else
243 output += 'SIGNATURE INVALID';
244
245
246
247
248 //output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey);
249
250 output+= "<br />";
251 output+= "<br />";
252
253
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700254 //if(LOG>4) console.log('str'[1]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700255 }
256 }
257
258 document.getElementById('result').innerHTML = output;
259 }
260
261 </script>
262
263</head>
264<body >
265 <form>
266 Please Enter a Content Name:<br /><input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" /> <br />
267 </form>
268 <button onclick="run()">Request Data!</button>
269 <div >
270 <applet id="JavaSocketBridge" archive="JavaSocketBridge.jar" code="JavaSocketBridge.class" width="0" height="0">
271 </applet>
272 </div>
273
274 <p id="result"></p>
275
276</body>
277</html>