blob: 0378c5ff2ad234a2929a1fe33a8d581e8861b587 [file] [log] [blame]
Jeff Thompson41471912013-09-12 16:21:50 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
Jeff Thompson06e787d2013-09-12 19:00:55 -07003 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
Jeff Thompson7687dc02013-09-13 11:54:07 -07004 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson41471912013-09-12 16:21:50 -07005 * See COPYING for copyright and distribution information.
6 */
7
Jeff Thompson86e1d752013-09-17 17:22:38 -07008#if 1
9#include "../../c/util/crypto.h"
10#endif
11#include "../../sha256-with-rsa-signature.hpp"
Jeff Thompson41471912013-09-12 16:21:50 -070012#include "identity-manager.hpp"
13
14namespace ndn {
15
Jeff Thompson86e1d752013-09-17 17:22:38 -070016#if 1
17static unsigned char DEFAULT_PUBLIC_KEY_DER[] = {
180x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81,
190x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xE1, 0x7D, 0x30, 0xA7, 0xD8, 0x28, 0xAB, 0x1B, 0x84, 0x0B, 0x17,
200x54, 0x2D, 0xCA, 0xF6, 0x20, 0x7A, 0xFD, 0x22, 0x1E, 0x08, 0x6B, 0x2A, 0x60, 0xD1, 0x6C, 0xB7, 0xF5, 0x44, 0x48, 0xBA,
210x9F, 0x3F, 0x08, 0xBC, 0xD0, 0x99, 0xDB, 0x21, 0xDD, 0x16, 0x2A, 0x77, 0x9E, 0x61, 0xAA, 0x89, 0xEE, 0xE5, 0x54, 0xD3,
220xA4, 0x7D, 0xE2, 0x30, 0xBC, 0x7A, 0xC5, 0x90, 0xD5, 0x24, 0x06, 0x7C, 0x38, 0x98, 0xBB, 0xA6, 0xF5, 0xDC, 0x43, 0x60,
230xB8, 0x45, 0xED, 0xA4, 0x8C, 0xBD, 0x9C, 0xF1, 0x26, 0xA7, 0x23, 0x44, 0x5F, 0x0E, 0x19, 0x52, 0xD7, 0x32, 0x5A, 0x75,
240xFA, 0xF5, 0x56, 0x14, 0x4F, 0x9A, 0x98, 0xAF, 0x71, 0x86, 0xB0, 0x27, 0x86, 0x85, 0xB8, 0xE2, 0xC0, 0x8B, 0xEA, 0x87,
250x17, 0x1B, 0x4D, 0xEE, 0x58, 0x5C, 0x18, 0x28, 0x29, 0x5B, 0x53, 0x95, 0xEB, 0x4A, 0x17, 0x77, 0x9F, 0x02, 0x03, 0x01,
260x00, 01
27};
28#endif
29
Jeff Thompson0050abe2013-09-17 12:50:25 -070030void
Jeff Thompson86e1d752013-09-17 17:22:38 -070031IdentityManager::signByCertificate(Data &data, const Name &certificateName, WireFormat& wireFormat)
Jeff Thompson41471912013-09-12 16:21:50 -070032{
Jeff Thompson86e1d752013-09-17 17:22:38 -070033#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 Thompson41471912013-09-12 16:21:50 -070061
Jeff Thompson86e1d752013-09-17 17:22:38 -070062 // 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 Thompson41471912013-09-12 16:21:50 -070070}
71
72}