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 | 38422f4 | 2012-11-15 00:20:39 -0800 | [diff] [blame^] | 9 | <script type="text/javascript" src="../Helper.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 10 |
|
| 11 | <script type="text/javascript">
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 12 |
|
| 13 | function encode(){
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 14 | var contentname = new Name( Name.createNameArray(document.getElementById('contentname').value) );
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 15 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 16 | 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 Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 49 | ///////////////////////////////////////
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 50 |
|
| 51 | var output ="";
|
| 52 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 53 | if(co==-1)
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 54 | output+= "NO CONTENT FOUND"
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 55 | else if (co==-2)
|
| 56 | output+= "CONTENT NAME IS EMPTY"
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 57 | else{
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 58 | if(co.name!=null && co.name.components!=null){
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 59 | output+= "NAME: ";
|
| 60 |
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 61 | for(var i=0;i<co.name.components.length;i++){
|
| 62 | output+= "/"+ toString(co.name.components[i]);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 63 | }
|
| 64 | output+= "<br />";
|
| 65 | output+= "<br />";
|
| 66 | }
|
| 67 |
|
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 68 | if(co.content !=null){
|
| 69 | output += "CONTENT(ASCII): "+ toString(co.content);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 70 |
|
| 71 | output+= "<br />";
|
| 72 | output+= "<br />";
|
| 73 | }
|
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 74 | if(co.content !=null){
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 75 | output += "CONTENT(hex): "+ DataUtils.toHex(co.content);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 76 |
|
| 77 | output+= "<br />";
|
| 78 | output+= "<br />";
|
| 79 | }
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 80 | if(co.signature !=null && co.signature.signature!=null){
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 81 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 82 | output += "SIGNATURE(hex): "+ DataUtils.toHex(co.signature.signature);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 83 |
|
| 84 | output+= "<br />";
|
| 85 | output+= "<br />";
|
| 86 | }
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 87 | 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] | 88 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 89 | output += "Publisher Public Key Digest(hex): "+ DataUtils.toHex(co.signedInfo.publisher.publisherPublicKeyDigest);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 90 |
|
| 91 | output+= "<br />";
|
| 92 | output+= "<br />";
|
| 93 | }
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 94 | if(co.signedInfo !=null && co.signedInfo.timestamp!=null){
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 95 |
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 96 | output += "TimeStamp(hex): "+ co.signedInfo.timestamp.date;
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 97 |
|
| 98 | output+= "<br />";
|
| 99 | output+= "<br />";
|
| 100 | }
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 101 | 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] | 102 |
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 103 | var publickey = rstr2b64(toString(co.signedInfo.locator.publicKey));
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 104 | var publickeyHex = DataUtils.toHex(co.signedInfo.locator.publicKey).toLowerCase();
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 105 | var publickeyString = toString(co.signedInfo.locator.publicKey);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 106 |
|
Jeff Thompson | 287a318 | 2012-11-11 18:12:20 -0800 | [diff] [blame] | 107 | var signature = DataUtils.toHex(co.signature.signature).toLowerCase();
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 108 |
|
| 109 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 110 | var input = toString(co.rawSignatureData);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 111 |
|
| 112 |
|
| 113 | output += "DER Certificate: "+publickey ;
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 114 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 115 | output+= "<br />";
|
| 116 | output+= "<br />";
|
| 117 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 118 |
|
| 119 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 120 | 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 Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 127 | if(LOG>2) console.log(co.signature.signature);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 128 |
|
| 129 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 130 | var x509 = new X509();
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 131 |
|
| 132 | x509.readCertPEM(publickey);
|
| 133 |
|
| 134 |
|
| 135 | //x509.readCertPEMWithoutRSAInit(publickey);
|
| 136 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 137 | var result = x509.subjectPublicKeyRSA.verifyString(input, signature);
|
| 138 | console.log('result is '+result);
|
| 139 | /*var rsakey = new RSAKey();
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 140 |
|
| 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 Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 148 | console.log('kp is '+kp);
|
| 149 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 150 | 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 Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 158 | console.log('exp is '+exp);
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 159 |
|
| 160 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 161 | rsakey.setPublic(kp,exp);
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 162 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 163 | var result = rsakey.verifyString(input, signature);*/
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 164 |
|
| 165 | if(result)
|
| 166 | output += 'SIGNATURE VALID';
|
| 167 | else
|
| 168 | output += 'SIGNATURE INVALID';
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 173 | //output += "VALID: "+ toHex(co.signedInfo.locator.publicKey);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 174 |
|
| 175 | output+= "<br />";
|
| 176 | output+= "<br />";
|
| 177 |
|
| 178 |
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 179 | if(LOG>4) console.log('str'[1]);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 180 | }
|
| 181 | }
|
| 182 |
|
| 183 | document.getElementById('result').innerHTML = output;
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 184 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 185 | }
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 186 |
|
| 187 | </script>
|
| 188 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 189 | </head>
|
| 190 | <body >
|
| 191 | <form>
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 192 |
|
| 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 Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 201 | </form>
|
Axel Colin de Verdiere | 2758c46 | 2012-06-06 08:50:05 -0700 | [diff] [blame] | 202 | <button onclick="encode()">Encode</button>
|
| 203 | <button onclick="decode()">Decode</button>
|
| 204 |
|
| 205 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 206 |
|
| 207 | <p id="result"></p>
|
| 208 |
|
| 209 | </body>
|
| 210 | </html> |