Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * @author: ucla-cs |
| 3 | * This class represents Signature Objects |
| 4 | */ |
| 5 | |
| 6 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 7 | var Signature = function Signature(_witness,_signature,_digestAlgorithm) { |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 8 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 9 | this.Witness = _witness;//byte [] _witness; |
| 10 | this.signature = _signature;//byte [] _signature; |
| 11 | this.digestAlgorithm = _digestAlgorithm//String _digestAlgorithm; |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 12 | }; |
| 13 | |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 14 | var generateSignature = function(contentName,content,signedinfo){ |
| 15 | |
| 16 | var enc = new BinaryXMLEncoder(); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 17 | contentName.to_ccnb(enc); |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 18 | var hex1 = toHex(enc.getReducedOstream()); |
| 19 | |
| 20 | var enc = new BinaryXMLEncoder(); |
Jeff Thompson | 86aea88 | 2012-09-29 17:32:48 -0700 | [diff] [blame] | 21 | content.to_ccnb(enc); |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 22 | var hex2 = toHex(enc.getReducedOstream()); |
| 23 | |
| 24 | var enc = new BinaryXMLEncoder(); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 25 | signedinfo.to_ccnb(enc); |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 26 | var hex3 = toHex(enc.getReducedOstream()); |
| 27 | |
| 28 | var hex = hex1+hex2+hex3; |
| 29 | |
| 30 | //globalKeyManager.sig |
| 31 | |
| 32 | }; |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 33 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 34 | Signature.prototype.from_ccnb =function( decoder) { |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 35 | decoder.readStartElement(this.getElementLabel()); |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 36 | |
| 37 | if(LOG>4)console.log('STARTED DECODING SIGNATURE '); |
| 38 | |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 39 | if (decoder.peekStartElement(CCNProtocolDTags.DigestAlgorithm)) { |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 40 | |
| 41 | if(LOG>4)console.log('DIGIEST ALGORITHM FOUND'); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 42 | this.digestAlgorithm = decoder.readUTF8Element(CCNProtocolDTags.DigestAlgorithm); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 43 | } |
| 44 | if (decoder.peekStartElement(CCNProtocolDTags.Witness)) { |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 45 | if(LOG>4)console.log('WITNESS FOUND FOUND'); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 46 | this.Witness = decoder.readBinaryElement(CCNProtocolDTags.Witness); |
| 47 | } |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 48 | |
| 49 | //FORCE TO READ A SIGNATURE |
| 50 | |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 51 | //if(LOG>4)console.log('SIGNATURE FOUND '); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 52 | this.signature = decoder.readBinaryElement(CCNProtocolDTags.SignatureBits); |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 53 | if(LOG>4)console.log('READ SIGNATURE '); |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 54 | |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 55 | decoder.readEndElement(); |
| 56 | |
| 57 | }; |
| 58 | |
| 59 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 60 | Signature.prototype.to_ccnb= function( encoder){ |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 61 | |
| 62 | if (!this.validate()) { |
| 63 | throw new Exception("Cannot encode: field values missing."); |
| 64 | } |
| 65 | |
| 66 | encoder.writeStartElement(this.getElementLabel()); |
| 67 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 68 | if ((null != this.digestAlgorithm) && (!this.digestAlgorithm.equals(CCNDigestHelper.DEFAULT_DIGEST_ALGORITHM))) { |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 69 | encoder.writeElement(CCNProtocolDTags.DigestAlgorithm, OIDLookup.getDigestOID(this.DigestAlgorithm)); |
| 70 | } |
| 71 | |
| 72 | if (null != this.Witness) { |
| 73 | // needs to handle null witness |
| 74 | encoder.writeElement(CCNProtocolDTags.Witness, this.Witness); |
| 75 | } |
| 76 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 77 | encoder.writeElement(CCNProtocolDTags.SignatureBits, this.signature); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 78 | |
| 79 | encoder.writeEndElement(); |
| 80 | }; |
| 81 | |
| 82 | Signature.prototype.getElementLabel = function() { return CCNProtocolDTags.Signature; }; |
| 83 | |
| 84 | |
| 85 | Signature.prototype.validate = function() { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame^] | 86 | return null != this.signature; |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 87 | }; |
| 88 | |