blob: 4a8ee433802a1adcfe7524ed35610a26a8686be3 [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 Thompson7ed5ef52012-08-26 11:28:48 -070039 <script language="JavaScript" type="text/javascript" src="../security/KeyManager.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="../securityLib/jsbn.js"></script>
42 <script language="JavaScript" type="text/javascript" src="../securityLib/jsbn2.js"></script>
43 <script language="JavaScript" type="text/javascript" src="../securityLib/rsa.js"></script>
44 <script language="JavaScript" type="text/javascript" src="../securityLib/rsa2.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070045
Jeff Thompson7ed5ef52012-08-26 11:28:48 -070046 <script language="JavaScript" type="text/javascript" src="../securityLib/sha1.js"></script>
47 <script language="JavaScript" type="text/javascript" src="../securityLib/sha256.js"></script>
48 <script language="JavaScript" type="text/javascript" src="../securityLib/sha512.js"></script>
49 <script language="JavaScript" type="text/javascript" src="../securityLib/md5.js"></script>
50 <script language="JavaScript" type="text/javascript" src="../securityLib/ripemd160.js"></script>
51 <script language="JavaScript" type="text/javascript" src="../securityLib/base64.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/rsapem-1.1.js"></script>
54 <script language="JavaScript" type="text/javascript" src="../securityLib/rsasign-1.2.js"></script>
55 <script language="JavaScript" type="text/javascript" src="../securityLib/asn1hex-1.1.js"></script>
56 <script language="JavaScript" type="text/javascript" src="../securityLib/x509-1.1.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070057
58 <script type="text/javascript">
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070059
60 function encode(){
Jeff Thompsonf3bd3592012-09-29 23:25:30 -070061 var contentname = new Name( createNameArray(document.getElementById('contentname').value) );
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070062
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070063 var content = document.getElementById('content').value;
64
65 var signedInfo = new SignedInfo();
66 signedInfo.setFields();
67 //var signatureBits = generateSignatureBits(contentname,content,signedInfo);
68
69 //witness is null
70 var signature = new Signature();
71
72
73 var co = new ContentObject(contentname,signedInfo,content,signature);
74
75 co.sign();
76
77
78 var output = encodeToHexContentObject(co);
79
80 document.getElementById('result').innerHTML = output;
81
82 }
83
84 function decode(){
85
86
87
88 var input = document.getElementById('result').innerHTML;
89
90
91 var co = decodeHexContentObject(input);
92
93 if(LOG>3)console.log('CONTENT OBJECT DECODED');
94 if(LOG>3)console.log(co);
95
Meki Cherkaoui8f173612012-06-06 01:05:40 -070096 ///////////////////////////////////////
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070097
98 var output ="";
99
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700100 if(co==-1)
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700101 output+= "NO CONTENT FOUND"
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700102 else if (co==-2)
103 output+= "CONTENT NAME IS EMPTY"
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700104 else{
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700105 if(co.name!=null && co.name.components!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700106 output+= "NAME: ";
107
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700108 for(var i=0;i<co.name.components.length;i++){
109 output+= "/"+ toString(co.name.components[i]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700110 }
111 output+= "<br />";
112 output+= "<br />";
113 }
114
Jeff Thompson86aea882012-09-29 17:32:48 -0700115 if(co.content !=null){
116 output += "CONTENT(ASCII): "+ toString(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700117
118 output+= "<br />";
119 output+= "<br />";
120 }
Jeff Thompson86aea882012-09-29 17:32:48 -0700121 if(co.content !=null){
122 output += "CONTENT(hex): "+ toHex(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700123
124 output+= "<br />";
125 output+= "<br />";
126 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700127 if(co.signature !=null && co.signature.signature!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700128
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700129 output += "SIGNATURE(hex): "+ toHex(co.signature.signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700130
131 output+= "<br />";
132 output+= "<br />";
133 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700134 if(co.signedInfo !=null && co.signedInfo.publisher!=null && co.signedInfo.publisher.publisherPublicKeyDigest!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700135
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700136 output += "Publisher Public Key Digest(hex): "+ toHex(co.signedInfo.publisher.publisherPublicKeyDigest);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700137
138 output+= "<br />";
139 output+= "<br />";
140 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700141 if(co.signedInfo !=null && co.signedInfo.timestamp!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700142
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700143 output += "TimeStamp(hex): "+ co.signedInfo.timestamp.date;
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700144
145 output+= "<br />";
146 output+= "<br />";
147 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700148 if(co.signedInfo!=null && co.signedInfo.locator!=null && co.signedInfo.locator.publicKey!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700149
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700150 var publickey = rstr2b64(toString(co.signedInfo.locator.publicKey));
151 var publickeyHex = toHex(co.signedInfo.locator.publicKey).toLowerCase();
152 var publickeyString = toString(co.signedInfo.locator.publicKey);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700153
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700154 var signature = toHex(co.signature.signature).toLowerCase();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700155
156
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700157 var input = toString(co.rawSignatureData);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700158
159
160 output += "DER Certificate: "+publickey ;
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700161
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700162 output+= "<br />";
163 output+= "<br />";
164
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700165
166
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700167 if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
168 if(LOG>2) console.log(" PublicKey = "+publickey );
169 if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
170 if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
171
172 if(LOG>2) console.log(" Signature "+signature );
173 if(LOG>2) console.log(" Signature NOW IS" );
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700174 if(LOG>2) console.log(co.signature.signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700175
176
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700177 var x509 = new X509();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700178
179 x509.readCertPEM(publickey);
180
181
182 //x509.readCertPEMWithoutRSAInit(publickey);
183
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700184 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);
185 console.log('result is '+result);
186 /*var rsakey = new RSAKey();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700187
188 var kp = publickeyHex.slice(56,314);
189
190 output += "PUBLISHER KEY(hex): "+kp ;
191
192 output+= "<br />";
193 output+= "<br />";
194
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700195 console.log('kp is '+kp);
196
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700197 var exp = publickeyHex.slice(318,324);
198
199 console.log('kp size is '+kp.length );
200 output += "exponent: "+exp ;
201
202 output+= "<br />";
203 output+= "<br />";
204
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700205 console.log('exp is '+exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700206
207
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700208 rsakey.setPublic(kp,exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700209
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700210 var result = rsakey.verifyString(input, signature);*/
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700211
212 if(result)
213 output += 'SIGNATURE VALID';
214 else
215 output += 'SIGNATURE INVALID';
216
217
218
219
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700220 //output += "VALID: "+ toHex(co.signedInfo.locator.publicKey);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700221
222 output+= "<br />";
223 output+= "<br />";
224
225
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700226 if(LOG>4) console.log('str'[1]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700227 }
228 }
229
230 document.getElementById('result').innerHTML = output;
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700231
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700232 }
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700233
234 </script>
235
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700236</head>
237<body >
238 <form>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700239
240 Please Enter a Content Name:<br />
241
242 <input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" />
243
244 Please Enter the Content:<br />
245
246 <textarea id="content" cols="40" rows="5" name="CONTENT" value="SUCCESS" >SUCCESS!</textarea>
247
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700248 </form>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700249 <button onclick="encode()">Encode</button>
250 <button onclick="decode()">Decode</button>
251
252
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700253
254 <p id="result"></p>
255
256</body>
257</html>