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