blob: 8ea3e9307ce69a09ff6caded94e208f8d8cd8e1f [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>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -07007 <title>NDN Request Example</title>
8
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 Thompsonf3bd3592012-09-29 23:25:30 -070015 <script type="text/javascript" src="../Name.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 Cherkaoui88d59cd2012-05-14 07:34:58 -070018
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070019 <script type="text/javascript" src="../DateFormat.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070020
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070021 <script type="text/javascript" src="../Exclude.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070022
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070023 <script type="text/javascript" src="../ExcludeAny.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070024
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070025 <script type="text/javascript" src="../ExcludeComponent.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070026
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070027 <script type="text/javascript" src="../Interest.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070028
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070029 <script type="text/javascript" src="../KeyLocator.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>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -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 language="JavaScript" type="text/javascript" src="../security/KeyManager.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070052
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070053 <script language="JavaScript" type="text/javascript" src="../securityLib/jsbn.js"></script>
54 <script language="JavaScript" type="text/javascript" src="../securityLib/jsbn2.js"></script>
55 <script language="JavaScript" type="text/javascript" src="../securityLib/rsa.js"></script>
56 <script language="JavaScript" type="text/javascript" src="../securityLib/rsa2.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070057
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070058 <script language="JavaScript" type="text/javascript" src="../securityLib/sha1.js"></script>
59 <script language="JavaScript" type="text/javascript" src="../securityLib/sha256.js"></script>
60 <script language="JavaScript" type="text/javascript" src="../securityLib/sha512.js"></script>
61 <script language="JavaScript" type="text/javascript" src="../securityLib/md5.js"></script>
62 <script language="JavaScript" type="text/javascript" src="../securityLib/ripemd160.js"></script>
63 <script language="JavaScript" type="text/javascript" src="../securityLib/base64.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070064
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070065 <script language="JavaScript" type="text/javascript" src="../securityLib/rsapem-1.1.js"></script>
66 <script language="JavaScript" type="text/javascript" src="../securityLib/rsasign-1.2.js"></script>
67 <script language="JavaScript" type="text/javascript" src="../securityLib/asn1hex-1.1.js"></script>
68 <script language="JavaScript" type="text/javascript" src="../securityLib/x509-1.1.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070069
70 <script type="text/javascript">
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070071
72 function encode(){
Jeff Thompsonf3bd3592012-09-29 23:25:30 -070073 var contentname = new Name( createNameArray(document.getElementById('contentname').value) );
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070074
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070075 var content = document.getElementById('content').value;
76
77 var signedInfo = new SignedInfo();
78 signedInfo.setFields();
79 //var signatureBits = generateSignatureBits(contentname,content,signedInfo);
80
81 //witness is null
82 var signature = new Signature();
83
84
85 var co = new ContentObject(contentname,signedInfo,content,signature);
86
87 co.sign();
88
89
90 var output = encodeToHexContentObject(co);
91
92 document.getElementById('result').innerHTML = output;
93
94 }
95
96 function decode(){
97
98
99
100 var input = document.getElementById('result').innerHTML;
101
102
103 var co = decodeHexContentObject(input);
104
105 if(LOG>3)console.log('CONTENT OBJECT DECODED');
106 if(LOG>3)console.log(co);
107
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700108 ///////////////////////////////////////
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700109
110 var output ="";
111
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700112 if(co==-1)
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700113 output+= "NO CONTENT FOUND"
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700114 else if (co==-2)
115 output+= "CONTENT NAME IS EMPTY"
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700116 else{
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700117 if(co.name!=null && co.name.components!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700118 output+= "NAME: ";
119
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700120 for(var i=0;i<co.name.components.length;i++){
121 output+= "/"+ toString(co.name.components[i]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700122 }
123 output+= "<br />";
124 output+= "<br />";
125 }
126
Jeff Thompson86aea882012-09-29 17:32:48 -0700127 if(co.content !=null){
128 output += "CONTENT(ASCII): "+ toString(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700129
130 output+= "<br />";
131 output+= "<br />";
132 }
Jeff Thompson86aea882012-09-29 17:32:48 -0700133 if(co.content !=null){
134 output += "CONTENT(hex): "+ toHex(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700135
136 output+= "<br />";
137 output+= "<br />";
138 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700139 if(co.signature !=null && co.signature.signature!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700140
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700141 output += "SIGNATURE(hex): "+ toHex(co.signature.signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700142
143 output+= "<br />";
144 output+= "<br />";
145 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700146 if(co.signedInfo !=null && co.signedInfo.publisher!=null && co.signedInfo.publisher.publisherPublicKeyDigest!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700147
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700148 output += "Publisher Public Key Digest(hex): "+ toHex(co.signedInfo.publisher.publisherPublicKeyDigest);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700149
150 output+= "<br />";
151 output+= "<br />";
152 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700153 if(co.signedInfo !=null && co.signedInfo.timestamp!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700154
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700155 output += "TimeStamp(hex): "+ co.signedInfo.timestamp.date;
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700156
157 output+= "<br />";
158 output+= "<br />";
159 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700160 if(co.signedInfo!=null && co.signedInfo.locator!=null && co.signedInfo.locator.publicKey!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700161
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700162 var publickey = rstr2b64(toString(co.signedInfo.locator.publicKey));
163 var publickeyHex = toHex(co.signedInfo.locator.publicKey).toLowerCase();
164 var publickeyString = toString(co.signedInfo.locator.publicKey);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700165
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700166 var signature = toHex(co.signature.signature).toLowerCase();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700167
168
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700169 var input = toString(co.rawSignatureData);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700170
171
172 output += "DER Certificate: "+publickey ;
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700173
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700174 output+= "<br />";
175 output+= "<br />";
176
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700177
178
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700179 if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
180 if(LOG>2) console.log(" PublicKey = "+publickey );
181 if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
182 if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
183
184 if(LOG>2) console.log(" Signature "+signature );
185 if(LOG>2) console.log(" Signature NOW IS" );
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700186 if(LOG>2) console.log(co.signature.signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700187
188
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700189 var x509 = new X509();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700190
191 x509.readCertPEM(publickey);
192
193
194 //x509.readCertPEMWithoutRSAInit(publickey);
195
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700196 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);
197 console.log('result is '+result);
198 /*var rsakey = new RSAKey();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700199
200 var kp = publickeyHex.slice(56,314);
201
202 output += "PUBLISHER KEY(hex): "+kp ;
203
204 output+= "<br />";
205 output+= "<br />";
206
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700207 console.log('kp is '+kp);
208
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700209 var exp = publickeyHex.slice(318,324);
210
211 console.log('kp size is '+kp.length );
212 output += "exponent: "+exp ;
213
214 output+= "<br />";
215 output+= "<br />";
216
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700217 console.log('exp is '+exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700218
219
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700220 rsakey.setPublic(kp,exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700221
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700222 var result = rsakey.verifyString(input, signature);*/
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700223
224 if(result)
225 output += 'SIGNATURE VALID';
226 else
227 output += 'SIGNATURE INVALID';
228
229
230
231
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700232 //output += "VALID: "+ toHex(co.signedInfo.locator.publicKey);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700233
234 output+= "<br />";
235 output+= "<br />";
236
237
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700238 if(LOG>4) console.log('str'[1]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700239 }
240 }
241
242 document.getElementById('result').innerHTML = output;
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700243
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700244 }
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700245
246 </script>
247
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700248</head>
249<body >
250 <form>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700251
252 Please Enter a Content Name:<br />
253
254 <input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" />
255
256 Please Enter the Content:<br />
257
258 <textarea id="content" cols="40" rows="5" name="CONTENT" value="SUCCESS" >SUCCESS!</textarea>
259
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700260 </form>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700261 <button onclick="encode()">Encode</button>
262 <button onclick="decode()">Decode</button>
263
264
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700265
266 <p id="result"></p>
267
268</body>
269</html>