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