Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -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. |
Jeff Thompson | 06e787d | 2013-09-12 19:00:55 -0700 | [diff] [blame] | 3 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
Jeff Thompson | 86e1d75 | 2013-09-17 17:22:38 -0700 | [diff] [blame] | 8 | #if 1 |
| 9 | #include "../../c/util/crypto.h" |
| 10 | #endif |
| 11 | #include "../../sha256-with-rsa-signature.hpp" |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 12 | #include "identity-manager.hpp" |
| 13 | |
| 14 | namespace ndn { |
| 15 | |
Jeff Thompson | 86e1d75 | 2013-09-17 17:22:38 -0700 | [diff] [blame] | 16 | #if 1 |
| 17 | static unsigned char DEFAULT_PUBLIC_KEY_DER[] = { |
| 18 | 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, |
| 19 | 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xE1, 0x7D, 0x30, 0xA7, 0xD8, 0x28, 0xAB, 0x1B, 0x84, 0x0B, 0x17, |
| 20 | 0x54, 0x2D, 0xCA, 0xF6, 0x20, 0x7A, 0xFD, 0x22, 0x1E, 0x08, 0x6B, 0x2A, 0x60, 0xD1, 0x6C, 0xB7, 0xF5, 0x44, 0x48, 0xBA, |
| 21 | 0x9F, 0x3F, 0x08, 0xBC, 0xD0, 0x99, 0xDB, 0x21, 0xDD, 0x16, 0x2A, 0x77, 0x9E, 0x61, 0xAA, 0x89, 0xEE, 0xE5, 0x54, 0xD3, |
| 22 | 0xA4, 0x7D, 0xE2, 0x30, 0xBC, 0x7A, 0xC5, 0x90, 0xD5, 0x24, 0x06, 0x7C, 0x38, 0x98, 0xBB, 0xA6, 0xF5, 0xDC, 0x43, 0x60, |
| 23 | 0xB8, 0x45, 0xED, 0xA4, 0x8C, 0xBD, 0x9C, 0xF1, 0x26, 0xA7, 0x23, 0x44, 0x5F, 0x0E, 0x19, 0x52, 0xD7, 0x32, 0x5A, 0x75, |
| 24 | 0xFA, 0xF5, 0x56, 0x14, 0x4F, 0x9A, 0x98, 0xAF, 0x71, 0x86, 0xB0, 0x27, 0x86, 0x85, 0xB8, 0xE2, 0xC0, 0x8B, 0xEA, 0x87, |
| 25 | 0x17, 0x1B, 0x4D, 0xEE, 0x58, 0x5C, 0x18, 0x28, 0x29, 0x5B, 0x53, 0x95, 0xEB, 0x4A, 0x17, 0x77, 0x9F, 0x02, 0x03, 0x01, |
| 26 | 0x00, 01 |
| 27 | }; |
| 28 | #endif |
| 29 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 30 | void |
Jeff Thompson | 86e1d75 | 2013-09-17 17:22:38 -0700 | [diff] [blame] | 31 | IdentityManager::signByCertificate(Data &data, const Name &certificateName, WireFormat& wireFormat) |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 32 | { |
Jeff Thompson | 86e1d75 | 2013-09-17 17:22:38 -0700 | [diff] [blame] | 33 | #if 0 |
| 34 | Name keyName = m_publicStorage->getKeyNameForCertificate(certName); |
| 35 | |
| 36 | Ptr<Publickey> publickey = m_privateStorage->getPublickey (keyName.toUri()); |
| 37 | #else |
| 38 | Name keyName; |
| 39 | #endif |
| 40 | |
| 41 | // For temporary usage, we support RSA + SHA256 only, but will support more. |
| 42 | data.setSignature(Sha256WithRsaSignature()); |
| 43 | // Get a pointer to the clone which Data made. |
| 44 | Sha256WithRsaSignature *signature = dynamic_cast<Sha256WithRsaSignature*>(data.getSignature()); |
| 45 | DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256; |
| 46 | |
| 47 | signature->getKeyLocator().setType(ndn_KeyLocatorType_KEYNAME); |
| 48 | signature->getKeyLocator().setKeyName(certificateName); |
| 49 | signature->getKeyLocator().setKeyNameType(ndn_KeyNameType_PUBLISHER_CERTIFICATE_DIGEST); |
| 50 | #if 0 |
| 51 | signature->getKeyLocator().setKeyData(certificateDigest); |
| 52 | #endif |
| 53 | // Ignore witness and leave the digestAlgorithm as the default. |
| 54 | #if 0 |
| 55 | signature->getPublisherPublicKeyDigest().setPublisherKeyDigest (*publickey->getDigest ()); |
| 56 | #else |
| 57 | unsigned char publicKeyDigest[SHA256_DIGEST_LENGTH]; |
| 58 | ndn_digestSha256(DEFAULT_PUBLIC_KEY_DER, sizeof(DEFAULT_PUBLIC_KEY_DER), publicKeyDigest); |
| 59 | signature->getPublisherPublicKeyDigest().setPublisherPublicKeyDigest(publicKeyDigest, sizeof(publicKeyDigest)); |
| 60 | #endif |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 61 | |
Jeff Thompson | 86e1d75 | 2013-09-17 17:22:38 -0700 | [diff] [blame] | 62 | // Encode once to get the signed portion. |
| 63 | SignedBlob encoding = data.wireEncode(wireFormat); |
| 64 | |
| 65 | signature->setSignature |
| 66 | (privateKeyStorage_->sign(encoding.signedBuf(), encoding.signedSize(), keyName.toUri(), digestAlgorithm)); |
| 67 | |
| 68 | // Encode again to include the signature. |
| 69 | data.wireEncode(wireFormat); |
Jeff Thompson | 4147191 | 2013-09-12 16:21:50 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | } |