blob: 4bbebe438958e1147332c116f54d1fa744236794 [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 Thompsonc3164722012-09-30 18:35:02 -070011 <script type="text/javascript" src="../util/CCNProtocolDTags.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070012
Jeff Thompsonc3164722012-09-30 18:35:02 -070013 <script type="text/javascript" src="../util/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 Thompsonc3164722012-09-30 18:35:02 -070019 <script type="text/javascript" src="../encoding/DateFormat.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070020
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070021 <script type="text/javascript" src="../Interest.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070022
Jeff Thompsonc3164722012-09-30 18:35:02 -070023 <script type="text/javascript" src="../Key.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070024
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070025 <script type="text/javascript" src="../PublisherID.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070026
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070027 <script type="text/javascript" src="../PublisherPublicKeyDigest.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070028
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070029 <script type="text/javascript" src="../FaceInstance.js"></script>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070030
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070031 <script type="text/javascript" src="../ForwardingEntry.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070032
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070033 <script type="text/javascript" src="../encoding/BinaryXMLEncoder.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070034
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070035 <script type="text/javascript" src="../encoding/BinaryXMLDecoder.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070036
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070037 <script type="text/javascript" src="../encoding/DataUtils.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070038
Jeff Thompson287a3182012-11-11 18:12:20 -080039 <script type="text/javascript" src="../encoding/EncodingUtils.js"></script>
40
41
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070042 <script language="JavaScript" type="text/javascript" src="../security/KeyManager.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070043
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070044 <script language="JavaScript" type="text/javascript" src="../securityLib/jsbn.js"></script>
45 <script language="JavaScript" type="text/javascript" src="../securityLib/jsbn2.js"></script>
46 <script language="JavaScript" type="text/javascript" src="../securityLib/rsa.js"></script>
47 <script language="JavaScript" type="text/javascript" src="../securityLib/rsa2.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070048
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070049 <script language="JavaScript" type="text/javascript" src="../securityLib/sha1.js"></script>
50 <script language="JavaScript" type="text/javascript" src="../securityLib/sha256.js"></script>
51 <script language="JavaScript" type="text/javascript" src="../securityLib/sha512.js"></script>
52 <script language="JavaScript" type="text/javascript" src="../securityLib/md5.js"></script>
53 <script language="JavaScript" type="text/javascript" src="../securityLib/ripemd160.js"></script>
54 <script language="JavaScript" type="text/javascript" src="../securityLib/base64.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070055
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070056 <script language="JavaScript" type="text/javascript" src="../securityLib/rsapem-1.1.js"></script>
57 <script language="JavaScript" type="text/javascript" src="../securityLib/rsasign-1.2.js"></script>
58 <script language="JavaScript" type="text/javascript" src="../securityLib/asn1hex-1.1.js"></script>
59 <script language="JavaScript" type="text/javascript" src="../securityLib/x509-1.1.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070060
61 <script type="text/javascript">
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070062
63 function encode(){
Jeff Thompson287a3182012-11-11 18:12:20 -080064 var contentname = new Name( Name.createNameArray(document.getElementById('contentname').value) );
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070065
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070066 var content = document.getElementById('content').value;
67
68 var signedInfo = new SignedInfo();
69 signedInfo.setFields();
70 //var signatureBits = generateSignatureBits(contentname,content,signedInfo);
71
72 //witness is null
73 var signature = new Signature();
74
75
76 var co = new ContentObject(contentname,signedInfo,content,signature);
77
78 co.sign();
79
80
81 var output = encodeToHexContentObject(co);
82
83 document.getElementById('result').innerHTML = output;
84
85 }
86
87 function decode(){
88
89
90
91 var input = document.getElementById('result').innerHTML;
92
93
94 var co = decodeHexContentObject(input);
95
96 if(LOG>3)console.log('CONTENT OBJECT DECODED');
97 if(LOG>3)console.log(co);
98
Meki Cherkaoui8f173612012-06-06 01:05:40 -070099 ///////////////////////////////////////
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700100
101 var output ="";
102
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700103 if(co==-1)
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700104 output+= "NO CONTENT FOUND"
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700105 else if (co==-2)
106 output+= "CONTENT NAME IS EMPTY"
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700107 else{
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700108 if(co.name!=null && co.name.components!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700109 output+= "NAME: ";
110
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700111 for(var i=0;i<co.name.components.length;i++){
112 output+= "/"+ toString(co.name.components[i]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700113 }
114 output+= "<br />";
115 output+= "<br />";
116 }
117
Jeff Thompson86aea882012-09-29 17:32:48 -0700118 if(co.content !=null){
119 output += "CONTENT(ASCII): "+ toString(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700120
121 output+= "<br />";
122 output+= "<br />";
123 }
Jeff Thompson86aea882012-09-29 17:32:48 -0700124 if(co.content !=null){
Jeff Thompson287a3182012-11-11 18:12:20 -0800125 output += "CONTENT(hex): "+ DataUtils.toHex(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700126
127 output+= "<br />";
128 output+= "<br />";
129 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700130 if(co.signature !=null && co.signature.signature!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700131
Jeff Thompson287a3182012-11-11 18:12:20 -0800132 output += "SIGNATURE(hex): "+ DataUtils.toHex(co.signature.signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700133
134 output+= "<br />";
135 output+= "<br />";
136 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700137 if(co.signedInfo !=null && co.signedInfo.publisher!=null && co.signedInfo.publisher.publisherPublicKeyDigest!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700138
Jeff Thompson287a3182012-11-11 18:12:20 -0800139 output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.signedInfo.publisher.publisherPublicKeyDigest);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700140
141 output+= "<br />";
142 output+= "<br />";
143 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700144 if(co.signedInfo !=null && co.signedInfo.timestamp!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700145
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700146 output += "TimeStamp(hex): "+ co.signedInfo.timestamp.date;
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700147
148 output+= "<br />";
149 output+= "<br />";
150 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700151 if(co.signedInfo!=null && co.signedInfo.locator!=null && co.signedInfo.locator.publicKey!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700152
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700153 var publickey = rstr2b64(toString(co.signedInfo.locator.publicKey));
Jeff Thompson287a3182012-11-11 18:12:20 -0800154 var publickeyHex = DataUtils.toHex(co.signedInfo.locator.publicKey).toLowerCase();
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700155 var publickeyString = toString(co.signedInfo.locator.publicKey);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700156
Jeff Thompson287a3182012-11-11 18:12:20 -0800157 var signature = DataUtils.toHex(co.signature.signature).toLowerCase();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700158
159
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700160 var input = toString(co.rawSignatureData);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700161
162
163 output += "DER Certificate: "+publickey ;
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700164
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700165 output+= "<br />";
166 output+= "<br />";
167
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700168
169
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700170 if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
171 if(LOG>2) console.log(" PublicKey = "+publickey );
172 if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
173 if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
174
175 if(LOG>2) console.log(" Signature "+signature );
176 if(LOG>2) console.log(" Signature NOW IS" );
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700177 if(LOG>2) console.log(co.signature.signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700178
179
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700180 var x509 = new X509();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700181
182 x509.readCertPEM(publickey);
183
184
185 //x509.readCertPEMWithoutRSAInit(publickey);
186
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700187 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);
188 console.log('result is '+result);
189 /*var rsakey = new RSAKey();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700190
191 var kp = publickeyHex.slice(56,314);
192
193 output += "PUBLISHER KEY(hex): "+kp ;
194
195 output+= "<br />";
196 output+= "<br />";
197
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700198 console.log('kp is '+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
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700208 console.log('exp is '+exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700209
210
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700211 rsakey.setPublic(kp,exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700212
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700213 var result = rsakey.verifyString(input, signature);*/
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700214
215 if(result)
216 output += 'SIGNATURE VALID';
217 else
218 output += 'SIGNATURE INVALID';
219
220
221
222
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700223 //output += "VALID: "+ toHex(co.signedInfo.locator.publicKey);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700224
225 output+= "<br />";
226 output+= "<br />";
227
228
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700229 if(LOG>4) console.log('str'[1]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700230 }
231 }
232
233 document.getElementById('result').innerHTML = output;
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700234
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700235 }
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700236
237 </script>
238
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700239</head>
240<body >
241 <form>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700242
243 Please Enter a Content Name:<br />
244
245 <input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" />
246
247 Please Enter the Content:<br />
248
249 <textarea id="content" cols="40" rows="5" name="CONTENT" value="SUCCESS" >SUCCESS!</textarea>
250
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700251 </form>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700252 <button onclick="encode()">Encode</button>
253 <button onclick="decode()">Decode</button>
254
255
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700256
257 <p id="result"></p>
258
259</body>
260</html>