Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 1 | <?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 Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 7 | <title>NDN Request Example</title>
|
| 8 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 9 | <script type="text/javascript" src="../java_socket_bridge.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 10 |
|
Jeff Thompson | c316472 | 2012-09-30 18:35:02 -0700 | [diff] [blame] | 11 | <script type="text/javascript" src="../util/CCNProtocolDTags.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 12 |
|
Jeff Thompson | c316472 | 2012-09-30 18:35:02 -0700 | [diff] [blame] | 13 | <script type="text/javascript" src="../util/CCNTime.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 14 |
|
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 15 | <script type="text/javascript" src="../Name.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 16 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 17 | <script type="text/javascript" src="../ContentObject.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 18 |
|
Jeff Thompson | c316472 | 2012-09-30 18:35:02 -0700 | [diff] [blame] | 19 | <script type="text/javascript" src="../encoding/DateFormat.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 20 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 21 | <script type="text/javascript" src="../Interest.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 22 |
|
Jeff Thompson | c316472 | 2012-09-30 18:35:02 -0700 | [diff] [blame] | 23 | <script type="text/javascript" src="../Key.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 24 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 25 | <script type="text/javascript" src="../PublisherID.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 26 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 27 | <script type="text/javascript" src="../PublisherPublicKeyDigest.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 28 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 29 | <script type="text/javascript" src="../FaceInstance.js"></script>
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 30 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 31 | <script type="text/javascript" src="../ForwardingEntry.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 32 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 33 | <script type="text/javascript" src="../encoding/BinaryXMLEncoder.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 34 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 35 | <script type="text/javascript" src="../encoding/BinaryXMLCodec.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 36 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 37 | <script type="text/javascript" src="../encoding/BinaryXMLDecoder.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 38 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 39 | <script type="text/javascript" src="../encoding/DataUtils.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 40 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 41 | <script language="JavaScript" type="text/javascript" src="../security/KeyManager.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 42 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 43 | <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 Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 47 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 48 | <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 Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 54 |
|
Jeff Thompson | 7ed5ef5 | 2012-08-26 11:28:48 -0700 | [diff] [blame] | 55 | <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 Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 59 |
|
| 60 | <script type="text/javascript">
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 61 |
|
| 62 | function encode(){
|
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 63 | var contentname = new Name( createNameArray(document.getElementById('contentname').value) );
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 64 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 65 | 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 Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 98 | ///////////////////////////////////////
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 99 |
|
| 100 | var output ="";
|
| 101 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 102 | if(co==-1)
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 103 | output+= "NO CONTENT FOUND"
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 104 | else if (co==-2)
|
| 105 | output+= "CONTENT NAME IS EMPTY"
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 106 | else{
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 107 | if(co.name!=null && co.name.components!=null){
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 108 | output+= "NAME: ";
|
| 109 |
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 110 | for(var i=0;i<co.name.components.length;i++){
|
| 111 | output+= "/"+ toString(co.name.components[i]);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 112 | }
|
| 113 | output+= "<br />";
|
| 114 | output+= "<br />";
|
| 115 | }
|
| 116 |
|
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 117 | if(co.content !=null){
|
| 118 | output += "CONTENT(ASCII): "+ toString(co.content);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 119 |
|
| 120 | output+= "<br />";
|
| 121 | output+= "<br />";
|
| 122 | }
|
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 123 | if(co.content !=null){
|
| 124 | output += "CONTENT(hex): "+ toHex(co.content);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 125 |
|
| 126 | output+= "<br />";
|
| 127 | output+= "<br />";
|
| 128 | }
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 129 | if(co.signature !=null && co.signature.signature!=null){
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 130 |
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 131 | output += "SIGNATURE(hex): "+ toHex(co.signature.signature);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 132 |
|
| 133 | output+= "<br />";
|
| 134 | output+= "<br />";
|
| 135 | }
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 136 | if(co.signedInfo !=null && co.signedInfo.publisher!=null && co.signedInfo.publisher.publisherPublicKeyDigest!=null){
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 137 |
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 138 | output += "Publisher Public Key Digest(hex): "+ toHex(co.signedInfo.publisher.publisherPublicKeyDigest);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 139 |
|
| 140 | output+= "<br />";
|
| 141 | output+= "<br />";
|
| 142 | }
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 143 | if(co.signedInfo !=null && co.signedInfo.timestamp!=null){
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 144 |
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 145 | output += "TimeStamp(hex): "+ co.signedInfo.timestamp.date;
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 146 |
|
| 147 | output+= "<br />";
|
| 148 | output+= "<br />";
|
| 149 | }
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 150 | if(co.signedInfo!=null && co.signedInfo.locator!=null && co.signedInfo.locator.publicKey!=null){
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 151 |
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 152 | 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 Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 155 |
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 156 | var signature = toHex(co.signature.signature).toLowerCase();
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 157 |
|
| 158 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 159 | var input = toString(co.rawSignatureData);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 160 |
|
| 161 |
|
| 162 | output += "DER Certificate: "+publickey ;
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 163 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 164 | output+= "<br />";
|
| 165 | output+= "<br />";
|
| 166 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 167 |
|
| 168 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 169 | 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 Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 176 | if(LOG>2) console.log(co.signature.signature);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 177 |
|
| 178 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 179 | var x509 = new X509();
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 180 |
|
| 181 | x509.readCertPEM(publickey);
|
| 182 |
|
| 183 |
|
| 184 | //x509.readCertPEMWithoutRSAInit(publickey);
|
| 185 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 186 | var result = x509.subjectPublicKeyRSA.verifyString(input, signature);
|
| 187 | console.log('result is '+result);
|
| 188 | /*var rsakey = new RSAKey();
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 189 |
|
| 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 Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 197 | console.log('kp is '+kp);
|
| 198 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 199 | 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 Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 207 | console.log('exp is '+exp);
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 208 |
|
| 209 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 210 | rsakey.setPublic(kp,exp);
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 211 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 212 | var result = rsakey.verifyString(input, signature);*/
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 213 |
|
| 214 | if(result)
|
| 215 | output += 'SIGNATURE VALID';
|
| 216 | else
|
| 217 | output += 'SIGNATURE INVALID';
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 222 | //output += "VALID: "+ toHex(co.signedInfo.locator.publicKey);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 223 |
|
| 224 | output+= "<br />";
|
| 225 | output+= "<br />";
|
| 226 |
|
| 227 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 228 | if(LOG>4) console.log('str'[1]);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 229 | }
|
| 230 | }
|
| 231 |
|
| 232 | document.getElementById('result').innerHTML = output;
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 233 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 234 | }
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 235 |
|
| 236 | </script>
|
| 237 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 238 | </head>
|
| 239 | <body >
|
| 240 | <form>
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 241 |
|
| 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 Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 250 | </form>
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 251 | <button onclick="encode()">Encode</button>
|
| 252 | <button onclick="decode()">Decode</button>
|
| 253 |
|
| 254 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 255 |
|
| 256 | <p id="result"></p>
|
| 257 |
|
| 258 | </body>
|
| 259 | </html> |