Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #ifndef NDN_KEY_CHAIN_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 7 | #define NDN_KEY_CHAIN_HPP |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 8 | |
Jeff Thompson | 7a67cb6 | 2013-08-26 11:43:18 -0700 | [diff] [blame] | 9 | #include "../data.hpp" |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 10 | |
| 11 | namespace ndn { |
| 12 | |
| 13 | class KeyChain { |
| 14 | public: |
| 15 | /** |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 16 | * In data, set the signed info publisher public key digest and key locator key to the public key and set the |
| 17 | * signature using the private key. |
Jeff Thompson | ade5b1e | 2013-08-09 12:16:45 -0700 | [diff] [blame] | 18 | * Note: the caller must make sure the timestamp is correct, for example with |
| 19 | * data.getSignedInfo().setTimestampMilliseconds(time(NULL) * 1000.0). |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 20 | * @param data The Data object to sign and set the key and signature. |
| 21 | * @param publicKeyDer A pointer to a buffer with the DER-encoded public key. |
| 22 | * @param publicKeyDerLength The number of bytes in publicKeyDer. |
| 23 | * @param privateKeyDer A pointer to a buffer with the DER-encoded private key. |
| 24 | * @param privateKeyDerLength The number of bytes in privateKeyDer. |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 25 | * @param wireFormat The WireFormat for calling encodeData. |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 26 | */ |
| 27 | static void sign |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame^] | 28 | (Data& data, const unsigned char *publicKeyDer, unsigned int publicKeyDerLength, |
| 29 | const unsigned char *privateKeyDer, unsigned int privateKeyDerLength, WireFormat& wireFormat); |
Jeff Thompson | 3c73da4 | 2013-08-12 11:19:05 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Call sign with the default public and private keys. |
| 33 | * @param data |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 34 | * @param wireFormat The WireFormat for calling encodeData. |
| 35 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame^] | 36 | static void defaultSign(Data& data, WireFormat& wireFormat); |
Jeff Thompson | 8efe5ad | 2013-08-20 17:36:38 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Call sign with the default public and private keys. For wireFormat, use WireFormat::getDefaultWireFormat(). |
| 40 | * @param data |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 41 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame^] | 42 | static void defaultSign(Data& data); |
Jeff Thompson | 1e90d8c | 2013-08-12 16:09:25 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Use the WireFormat to decode the input as a Data packet and use the public key in the key locator to |
| 46 | * verify the signature. |
| 47 | * This does just uses the public key without checking whether it is certified. |
| 48 | * @param input A pointer to the input buffer to decode. |
| 49 | * @param inputLength The number of bytes in input. |
| 50 | * @param wireFormat The WireFormat for calling decodeData. |
| 51 | * @return true if the public key in the Data object verifies the object, false if not or if the Data object |
| 52 | * doesn't have a public key. |
| 53 | */ |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame^] | 54 | static bool selfVerifyData(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat); |
Jeff Thompson | 1e90d8c | 2013-08-12 16:09:25 -0700 | [diff] [blame] | 55 | |
| 56 | static bool selfVerifyData(const unsigned char *input, unsigned int inputLength) |
| 57 | { |
| 58 | return selfVerifyData(input, inputLength, *WireFormat::getDefaultWireFormat()); |
| 59 | } |
Jeff Thompson | 47c93cf | 2013-08-09 00:38:48 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } |
| 63 | |
| 64 | #endif |