blob: df3e7005627c655d73301c959cfc15ea8ada98da [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 Thompson38422f42012-11-15 00:20:39 -08009 <script type="text/javascript" src="../Helper.js"></script>
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070010
11 <script type="text/javascript">
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070012
13 function encode(){
Jeff Thompson287a3182012-11-11 18:12:20 -080014 var contentname = new Name( Name.createNameArray(document.getElementById('contentname').value) );
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070015
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070016 var content = document.getElementById('content').value;
17
18 var signedInfo = new SignedInfo();
19 signedInfo.setFields();
20 //var signatureBits = generateSignatureBits(contentname,content,signedInfo);
21
22 //witness is null
23 var signature = new Signature();
24
25
26 var co = new ContentObject(contentname,signedInfo,content,signature);
27
28 co.sign();
29
30
31 var output = encodeToHexContentObject(co);
32
33 document.getElementById('result').innerHTML = output;
34
35 }
36
37 function decode(){
38
39
40
41 var input = document.getElementById('result').innerHTML;
42
43
44 var co = decodeHexContentObject(input);
45
46 if(LOG>3)console.log('CONTENT OBJECT DECODED');
47 if(LOG>3)console.log(co);
48
Meki Cherkaoui8f173612012-06-06 01:05:40 -070049 ///////////////////////////////////////
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070050
51 var output ="";
52
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070053 if(co==-1)
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070054 output+= "NO CONTENT FOUND"
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -070055 else if (co==-2)
56 output+= "CONTENT NAME IS EMPTY"
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070057 else{
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070058 if(co.name!=null && co.name.components!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070059 output+= "NAME: ";
60
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070061 for(var i=0;i<co.name.components.length;i++){
62 output+= "/"+ toString(co.name.components[i]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070063 }
64 output+= "<br />";
65 output+= "<br />";
66 }
67
Jeff Thompson86aea882012-09-29 17:32:48 -070068 if(co.content !=null){
69 output += "CONTENT(ASCII): "+ toString(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070070
71 output+= "<br />";
72 output+= "<br />";
73 }
Jeff Thompson86aea882012-09-29 17:32:48 -070074 if(co.content !=null){
Jeff Thompson287a3182012-11-11 18:12:20 -080075 output += "CONTENT(hex): "+ DataUtils.toHex(co.content);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070076
77 output+= "<br />";
78 output+= "<br />";
79 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070080 if(co.signature !=null && co.signature.signature!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070081
Jeff Thompson287a3182012-11-11 18:12:20 -080082 output += "SIGNATURE(hex): "+ DataUtils.toHex(co.signature.signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070083
84 output+= "<br />";
85 output+= "<br />";
86 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070087 if(co.signedInfo !=null && co.signedInfo.publisher!=null && co.signedInfo.publisher.publisherPublicKeyDigest!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070088
Jeff Thompson287a3182012-11-11 18:12:20 -080089 output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.signedInfo.publisher.publisherPublicKeyDigest);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070090
91 output+= "<br />";
92 output+= "<br />";
93 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070094 if(co.signedInfo !=null && co.signedInfo.timestamp!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070095
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070096 output += "TimeStamp(hex): "+ co.signedInfo.timestamp.date;
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070097
98 output+= "<br />";
99 output+= "<br />";
100 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700101 if(co.signedInfo!=null && co.signedInfo.locator!=null && co.signedInfo.locator.publicKey!=null){
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700102
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700103 var publickey = rstr2b64(toString(co.signedInfo.locator.publicKey));
Jeff Thompson287a3182012-11-11 18:12:20 -0800104 var publickeyHex = DataUtils.toHex(co.signedInfo.locator.publicKey).toLowerCase();
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700105 var publickeyString = toString(co.signedInfo.locator.publicKey);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700106
Jeff Thompson287a3182012-11-11 18:12:20 -0800107 var signature = DataUtils.toHex(co.signature.signature).toLowerCase();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700108
109
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700110 var input = toString(co.rawSignatureData);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700111
112
113 output += "DER Certificate: "+publickey ;
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700114
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700115 output+= "<br />";
116 output+= "<br />";
117
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700118
119
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700120 if(LOG>2) console.log(" ContentName + SignedInfo + Content = "+input);
121 if(LOG>2) console.log(" PublicKey = "+publickey );
122 if(LOG>2) console.log(" PublicKeyHex = "+publickeyHex );
123 if(LOG>2) console.log(" PublicKeyString = "+publickeyString );
124
125 if(LOG>2) console.log(" Signature "+signature );
126 if(LOG>2) console.log(" Signature NOW IS" );
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700127 if(LOG>2) console.log(co.signature.signature);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700128
129
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700130 var x509 = new X509();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700131
132 x509.readCertPEM(publickey);
133
134
135 //x509.readCertPEMWithoutRSAInit(publickey);
136
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700137 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);
138 console.log('result is '+result);
139 /*var rsakey = new RSAKey();
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700140
141 var kp = publickeyHex.slice(56,314);
142
143 output += "PUBLISHER KEY(hex): "+kp ;
144
145 output+= "<br />";
146 output+= "<br />";
147
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700148 console.log('kp is '+kp);
149
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700150 var exp = publickeyHex.slice(318,324);
151
152 console.log('kp size is '+kp.length );
153 output += "exponent: "+exp ;
154
155 output+= "<br />";
156 output+= "<br />";
157
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700158 console.log('exp is '+exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700159
160
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700161 rsakey.setPublic(kp,exp);
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700162
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700163 var result = rsakey.verifyString(input, signature);*/
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700164
165 if(result)
166 output += 'SIGNATURE VALID';
167 else
168 output += 'SIGNATURE INVALID';
169
170
171
172
Jeff Thompsone85ff1d2012-09-29 21:21:57 -0700173 //output += "VALID: "+ toHex(co.signedInfo.locator.publicKey);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700174
175 output+= "<br />";
176 output+= "<br />";
177
178
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700179 if(LOG>4) console.log('str'[1]);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700180 }
181 }
182
183 document.getElementById('result').innerHTML = output;
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700184
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700185 }
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700186
187 </script>
188
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700189</head>
190<body >
191 <form>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700192
193 Please Enter a Content Name:<br />
194
195 <input id="contentname" type="text" name="CONTENTNAME" value="/PARC/abc" />
196
197 Please Enter the Content:<br />
198
199 <textarea id="content" cols="40" rows="5" name="CONTENT" value="SUCCESS" >SUCCESS!</textarea>
200
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700201 </form>
Axel Colin de Verdiere2758c462012-06-06 08:50:05 -0700202 <button onclick="encode()">Encode</button>
203 <button onclick="decode()">Decode</button>
204
205
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700206
207 <p id="result"></p>
208
209</body>
210</html>