blob: 582e7ea3e1ad073ff7871ec1c251f1792c3b81c3 [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>
7 <title>NDN Request Example</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 ContentName = document.getElementById('contentname').value;
83
84 ///////////////////////////////////////
85 createRoute('localhost', 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
Axel Colin de Verdieree5e666f2012-05-22 23:32:00 -070095 var coSize = getContentObjectSize(co);
96
97 document.getElementById('coSize').innerHTML = coSize;
98
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070099 ///////////////////////////////////////
100
101 var output ="";
102
103 if(co==-1)
104 output+= "NO CONTENT FOUND"
105 else if (co==-2)
106 output+= "CONTENT NAME IS EMPTY"
107 else{
Axel Colin de Verdieree5e666f2012-05-22 23:32:00 -0700108 output += "Content: " + toString(toHex(co));
109 output+="<br />";
110 output+= "<br />";
111
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700112 if(co.Name!=null && co.Name.Components!=null){
113 output+= "NAME: ";
114
115 for(var i=0;i<co.Name.Components.length;i++){
116 output+= "/"+ toString(co.Name.Components[i]);
117 }
118 output+= "<br />";
119 output+= "<br />";
120 }
121
122 if(co.Content !=null){
123 output += "CONTENT(ASCII): "+ toString(co.Content);
124
125 output+= "<br />";
126 output+= "<br />";
127 }
128 if(co.Content !=null){
129 output += "CONTENT(hex): "+ toHex(co.Content);
130
131 output+= "<br />";
132 output+= "<br />";
133 }
134
135 if(co.Signature !=null && co.Signature.Signature!=null){
136
137 output += "SIGNATURE(hex): "+ toHex(co.Signature.Signature);
138
139 output+= "<br />";
140 output+= "<br />";
141 }
142 if(co.SignedInfo !=null && co.SignedInfo.Publisher!=null && co.SignedInfo.Publisher.PublisherPublicKeyDigest!=null){
143
Axel Colin de Verdieref049a762012-05-19 12:10:17 -0700144 output += "Publisher Public Key Digest: " + co.SignedInfo.Publisher.PublisherPublicKeyDigest + "<br />";
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700145 output += "Publisher Public Key Digest(hex): "+ toHex(co.SignedInfo.Publisher.PublisherPublicKeyDigest);
146
147 output+= "<br />";
148 output+= "<br />";
149 }
150 if(co.SignedInfo !=null && co.SignedInfo.Timestamp!=null){
151
152 output += "TimeStamp(hex): "+ co.SignedInfo.Timestamp.date;
153
154 output+= "<br />";
155 output+= "<br />";
156 }
157 if(co.SignedInfo!=null && co.SignedInfo.Locator!=null && co.SignedInfo.Locator.PublicKey!=null){
158
159 var publickey = rstr2b64(toString(co.SignedInfo.Locator.PublicKey));
160 var publickeyHex = toHex(co.SignedInfo.Locator.PublicKey).toLowerCase();
161 var publickeyString = toString(co.SignedInfo.Locator.PublicKey);
162
163 var signature = toHex(co.Signature.Signature).toLowerCase();
164
165
166 var input = toString(co.rawSignatureData);
Axel Colin de Verdieree5e666f2012-05-22 23:32:00 -0700167
168 var inputBis = toString(co.rawSignatureData.slice(0,co.rawSignatureData.length-2).concat([0]));
169
170 console.log("Input bis: ", toHex(co.rawSignatureData.slice(0,co.rawSignatureData.length-2).concat([0])));
171
172 if(LOG>2) console.log("Input: ", toHex(co.rawSignatureData), "; raw signature data: ", co.rawSignatureData, "; to hex: ", toHex(co.rawSignatureData));
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700173
174
175 output += "DER Certificate: "+publickey ;
176
177 output+= "<br />";
178 output+= "<br />";
179
180
181
182 if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
183 if(LOG>2) console.log(" PublicKey = "+publickey );
184 if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
185 if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
186
187 if(LOG>2) console.log(" Signature "+signature );
188 if(LOG>2) console.log(" Signature NOW IS" );
189 if(LOG>2) console.log(co.Signature.Signature);
190
191
192 /*var x509 = new X509();
193
194 x509.readCertPEM(publickey);
195
196
197 //x509.readCertPEMWithoutRSAInit(publickey);
198
199 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);*/
200 //console.log('result is '+result);
201
202
203 var kp = publickeyHex.slice(56,314);
204
205 output += "PUBLISHER KEY(hex): "+kp ;
206
207 output+= "<br />";
208 output+= "<br />";
209
210 console.log('kp is '+kp);
211
212 var exp = publickeyHex.slice(318,324);
213
214 console.log('kp size is '+kp.length );
215 output += "exponent: "+exp ;
216
217 output+= "<br />";
218 output+= "<br />";
219
220 console.log('exp is '+exp);
221
222 var rsakey = new RSAKey();
223 rsakey.setPublic(kp,exp);
224 var result = rsakey.verifyString(input, signature);
Axel Colin de Verdieref049a762012-05-19 12:10:17 -0700225
Axel Colin de Verdieree5e666f2012-05-22 23:32:00 -0700226 var resultBis = rsakey.verify(inputBis, signature);
227
228 console.log("result bis: ", resultBis);
229
230 //var inputBis = toHex(co.Name).concat(toHex(co.SignedInfo), toHex(co.Content));
Axel Colin de Verdieref049a762012-05-19 12:10:17 -0700231
232// if(LOG>0){
233// console.log("Input: ", input);
234// console.log("Input bis: ", inputBis);
235// console.log("Verify input bis: ", rsakey.verifyString(inputBis, signature));
236// }
237
238 //var x509 = new X509();
239 //x509.readCertPEM(publickey);
240 //if(LOG>0) console.log("x509 verif: ", x509.subjectPublicKeyRSA.verifyString(input, signature));
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
256 if(LOG>4) console.log('str'[1]);
257 }
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>
Axel Colin de Verdieree5e666f2012-05-22 23:32:00 -0700270 <div>
271 <button onclick="run()">Request Data!</button>
272 </div>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700273 <div >
274 <applet id="JavaSocketBridge" archive="JavaSocketBridge.jar" code="JavaSocketBridge.class" width="0" height="0">
275 </applet>
276 </div>
277
Axel Colin de Verdieree5e666f2012-05-22 23:32:00 -0700278 <div>
279 <p>Size: <span id="coSize"></span></p>
280
281 <p id="result"></p>
282
283 </div>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700284</body>
285</html>