blob: 11a69b0217f8f91a43066db13e104364dc66b759 [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{
101 if(co.Name!=null && co.Name.Components!=null){
102 output+= "NAME: ";
103
104 for(var i=0;i<co.Name.Components.length;i++){
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700105 output+= "/"+ DataUtils.toString(co.Name.Components[i]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700106 }
107 output+= "<br />";
108 output+= "<br />";
109 }
110
111 if(co.Content !=null){
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700112 output += "CONTENT(ASCII): "+ DataUtils.toString(co.Content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700113
114 output+= "<br />";
115 output+= "<br />";
116 }
117 if(co.Content !=null){
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700118 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 ;
163
164 output+= "<br />";
165 output+= "<br />";
166
167
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700168
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700169 if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
170 if(LOG>2) console.log(" PublicKey = "+publickey );
171 if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
172 if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
173
174 if(LOG>2) console.log(" Signature "+signature );
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700175
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700176 if(LOG>2) console.log(" Signature NOW IS" );
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700177
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700178 if(LOG>2) console.log(co.Signature.Signature);
179
180
181 /*var x509 = new X509();
182
183 x509.readCertPEM(publickey);
184
185
186 //x509.readCertPEMWithoutRSAInit(publickey);
187
188 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);*/
189 //console.log('result is '+result);
190
191
192 var kp = publickeyHex.slice(56,314);
193
194 output += "PUBLISHER KEY(hex): "+kp ;
195
196 output+= "<br />";
197 output+= "<br />";
198
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700199 console.log('PUBLIC KEY IN HEX is ');
200 console.log(kp);
201
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700202 var exp = publickeyHex.slice(318,324);
203
204 console.log('kp size is '+kp.length );
205 output += "exponent: "+exp ;
206
207 output+= "<br />";
208 output+= "<br />";
209
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700210 console.log('EXPONENT is ');
211 console.log(exp);
212
213
214
215 /*var c1 = hex_sha256(input);
216 var c2 = signature;
217
218 if(LOG>4)console.log('input is ');
219 if(LOG>4)console.log(input);
220 if(LOG>4)console.log('C1 is ');
221 if(LOG>4)console.log(c1);
222 if(LOG>4)console.log('C2 is ');
223 if(LOG>4)console.log(c2);
224 var result = c1 == c2;*/
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700225
226 var rsakey = new RSAKey();
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700227
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700228 rsakey.setPublic(kp,exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700229
230 var result = rsakey.verifyByteArray(co.rawSignatureData,signature);
231 // var result = rsakey.verifyString(input, signature);
232
233
234
235 console.log('PUBLIC KEY n after is ');
236 console.log(rsakey.n);
237
238 console.log('EXPONENT e after is ');
239 console.log(rsakey.e);
240
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700241
242 if(result)
243 output += 'SIGNATURE VALID';
244 else
245 output += 'SIGNATURE INVALID';
246
247
248
249
250 //output += "VALID: "+ toHex(co.SignedInfo.Locator.PublicKey);
251
252 output+= "<br />";
253 output+= "<br />";
254
255
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700256 //if(LOG>4) console.log('str'[1]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700257 }
258 }
259
260 document.getElementById('result').innerHTML = output;
261 }
262
263 </script>
264
265</head>
266<body >
267 <form>
268 Please Enter a Content Name:<br /><input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" /> <br />
269 </form>
270 <button onclick="run()">Request Data!</button>
271 <div >
272 <applet id="JavaSocketBridge" archive="JavaSocketBridge.jar" code="JavaSocketBridge.class" width="0" height="0">
273 </applet>
274 </div>
275
276 <p id="result"></p>
277
278</body>
279</html>