blob: b8c45db2c287ea7bf4c15bad4b8b273c72881189 [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/BinaryXMLCodec.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070036
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070037 <script type="text/javascript" src="../encoding/BinaryXMLDecoder.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070038
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070039 <script type="text/javascript" src="../encoding/DataUtils.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070040
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070041 <script language="JavaScript" type="text/javascript" src="../security/KeyManager.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070042
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070043 <script language="JavaScript" type="text/javascript" src="../securityLib/jsbn.js"></script>
44 <script language="JavaScript" type="text/javascript" src="../securityLib/jsbn2.js"></script>
45 <script language="JavaScript" type="text/javascript" src="../securityLib/rsa.js"></script>
46 <script language="JavaScript" type="text/javascript" src="../securityLib/rsa2.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070047
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070048 <script language="JavaScript" type="text/javascript" src="../securityLib/sha1.js"></script>
49 <script language="JavaScript" type="text/javascript" src="../securityLib/sha256.js"></script>
50 <script language="JavaScript" type="text/javascript" src="../securityLib/sha512.js"></script>
51 <script language="JavaScript" type="text/javascript" src="../securityLib/md5.js"></script>
52 <script language="JavaScript" type="text/javascript" src="../securityLib/ripemd160.js"></script>
53 <script language="JavaScript" type="text/javascript" src="../securityLib/base64.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070054
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070055 <script language="JavaScript" type="text/javascript" src="../securityLib/rsapem-1.1.js"></script>
56 <script language="JavaScript" type="text/javascript" src="../securityLib/rsasign-1.2.js"></script>
57 <script language="JavaScript" type="text/javascript" src="../securityLib/asn1hex-1.1.js"></script>
58 <script language="JavaScript" type="text/javascript" src="../securityLib/x509-1.1.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070059
60 <script type="text/javascript">
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070061
62 function encode(){
Jeff Thompsonf3bd3592012-09-29 23:25:30 -070063 var contentname = new Name( createNameArray(document.getElementById('contentname').value) );
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070064
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070065 var content = document.getElementById('content').value;
66
67 var signedInfo = new SignedInfo();
68 signedInfo.setFields();
69 //var signatureBits = generateSignatureBits(contentname,content,signedInfo);
70
71 //witness is null
72 var signature = new Signature();
73
74
75 var co = new ContentObject(contentname,signedInfo,content,signature);
76
77 co.sign();
78
79
80 var output = encodeToHexContentObject(co);
81
82 document.getElementById('result').innerHTML = output;
83
84 }
85
86 function decode(){
87
88
89
90 var input = document.getElementById('result').innerHTML;
91
92
93 var co = decodeHexContentObject(input);
94
95 if(LOG>3)console.log('CONTENT OBJECT DECODED');
96 if(LOG>3)console.log(co);
97
Meki Cherkaoui8f173612012-06-06 01:05:40 -070098 ///////////////////////////////////////
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070099
100 var output ="";
101
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700102 if(co==-1)
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700103 output+= "NO CONTENT FOUND"
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700104 else if (co==-2)
105 output+= "CONTENT NAME IS EMPTY"
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700106 else{
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700107 if(co.name!=null && co.name.components!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700108 output+= "NAME: ";
109
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700110 for(var i=0;i<co.name.components.length;i++){
111 output+= "/"+ toString(co.name.components[i]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700112 }
113 output+= "<br />";
114 output+= "<br />";
115 }
116
Jeff Thompson86aea882012-09-29 17:32:48 -0700117 if(co.content !=null){
118 output += "CONTENT(ASCII): "+ toString(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700119
120 output+= "<br />";
121 output+= "<br />";
122 }
Jeff Thompson86aea882012-09-29 17:32:48 -0700123 if(co.content !=null){
124 output += "CONTENT(hex): "+ toHex(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700125
126 output+= "<br />";
127 output+= "<br />";
128 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700129 if(co.signature !=null && co.signature.signature!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700130
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700131 output += "SIGNATURE(hex): "+ toHex(co.signature.signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700132
133 output+= "<br />";
134 output+= "<br />";
135 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700136 if(co.signedInfo !=null && co.signedInfo.publisher!=null && co.signedInfo.publisher.publisherPublicKeyDigest!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700137
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700138 output += "Publisher Public Key Digest(hex): "+ toHex(co.signedInfo.publisher.publisherPublicKeyDigest);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700139
140 output+= "<br />";
141 output+= "<br />";
142 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700143 if(co.signedInfo !=null && co.signedInfo.timestamp!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700144
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700145 output += "TimeStamp(hex): "+ co.signedInfo.timestamp.date;
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700146
147 output+= "<br />";
148 output+= "<br />";
149 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700150 if(co.signedInfo!=null && co.signedInfo.locator!=null && co.signedInfo.locator.publicKey!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700151
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700152 var publickey = rstr2b64(toString(co.signedInfo.locator.publicKey));
153 var publickeyHex = toHex(co.signedInfo.locator.publicKey).toLowerCase();
154 var publickeyString = toString(co.signedInfo.locator.publicKey);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700155
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700156 var signature = toHex(co.signature.signature).toLowerCase();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700157
158
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700159 var input = toString(co.rawSignatureData);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700160
161
162 output += "DER Certificate: "+publickey ;
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700163
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700164 output+= "<br />";
165 output+= "<br />";
166
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700167
168
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 );
175 if(LOG>2) console.log(" Signature NOW IS" );
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700176 if(LOG>2) console.log(co.signature.signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700177
178
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700179 var x509 = new X509();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700180
181 x509.readCertPEM(publickey);
182
183
184 //x509.readCertPEMWithoutRSAInit(publickey);
185
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700186 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);
187 console.log('result is '+result);
188 /*var rsakey = new RSAKey();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700189
190 var kp = publickeyHex.slice(56,314);
191
192 output += "PUBLISHER KEY(hex): "+kp ;
193
194 output+= "<br />";
195 output+= "<br />";
196
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700197 console.log('kp is '+kp);
198
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700199 var exp = publickeyHex.slice(318,324);
200
201 console.log('kp size is '+kp.length );
202 output += "exponent: "+exp ;
203
204 output+= "<br />";
205 output+= "<br />";
206
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700207 console.log('exp is '+exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700208
209
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700210 rsakey.setPublic(kp,exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700211
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700212 var result = rsakey.verifyString(input, signature);*/
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700213
214 if(result)
215 output += 'SIGNATURE VALID';
216 else
217 output += 'SIGNATURE INVALID';
218
219
220
221
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700222 //output += "VALID: "+ toHex(co.signedInfo.locator.publicKey);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700223
224 output+= "<br />";
225 output+= "<br />";
226
227
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700228 if(LOG>4) console.log('str'[1]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700229 }
230 }
231
232 document.getElementById('result').innerHTML = output;
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700233
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700234 }
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700235
236 </script>
237
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700238</head>
239<body >
240 <form>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700241
242 Please Enter a Content Name:<br />
243
244 <input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" />
245
246 Please Enter the Content:<br />
247
248 <textarea id="content" cols="40" rows="5" name="CONTENT" value="SUCCESS" >SUCCESS!</textarea>
249
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700250 </form>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700251 <button onclick="encode()">Encode</button>
252 <button onclick="decode()">Decode</button>
253
254
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700255
256 <p id="result"></p>
257
258</body>
259</html>