blob: a5adfc3af69cb5c6c7cab63f39062503643dc9ab [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#include "../../sha256-with-rsa-signature.hpp"
Jeff Thompson41471912013-09-12 16:21:50 -07009#include "identity-manager.hpp"
10
Jeff Thompson9296f0c2013-09-23 18:10:27 -070011using namespace std;
12using namespace ndn::ptr_lib;
Jeff Thompson41471912013-09-12 16:21:50 -070013
Jeff Thompson9296f0c2013-09-23 18:10:27 -070014namespace ndn {
Jeff Thompson86e1d752013-09-17 17:22:38 -070015
Jeff Thompson0050abe2013-09-17 12:50:25 -070016void
Jeff Thompson86e1d752013-09-17 17:22:38 -070017IdentityManager::signByCertificate(Data &data, const Name &certificateName, WireFormat& wireFormat)
Jeff Thompson41471912013-09-12 16:21:50 -070018{
Jeff Thompson9296f0c2013-09-23 18:10:27 -070019 Name keyName = identityStorage_->getKeyNameForCertificate(certificateName);
20
21 shared_ptr<PublicKey> publicKey = privateKeyStorage_->getPublicKey(keyName);
Jeff Thompson86e1d752013-09-17 17:22:38 -070022
23 // For temporary usage, we support RSA + SHA256 only, but will support more.
24 data.setSignature(Sha256WithRsaSignature());
25 // Get a pointer to the clone which Data made.
26 Sha256WithRsaSignature *signature = dynamic_cast<Sha256WithRsaSignature*>(data.getSignature());
27 DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256;
28
29 signature->getKeyLocator().setType(ndn_KeyLocatorType_KEYNAME);
30 signature->getKeyLocator().setKeyName(certificateName);
Jeff Thompson9296f0c2013-09-23 18:10:27 -070031 // Omit the certificate digest.
32 signature->getKeyLocator().setKeyNameType((ndn_KeyNameType)-1);
Jeff Thompson86e1d752013-09-17 17:22:38 -070033 // Ignore witness and leave the digestAlgorithm as the default.
Jeff Thompson9296f0c2013-09-23 18:10:27 -070034 signature->getPublisherPublicKeyDigest().setPublisherPublicKeyDigest(publicKey->getDigest());
Jeff Thompson41471912013-09-12 16:21:50 -070035
Jeff Thompson86e1d752013-09-17 17:22:38 -070036 // Encode once to get the signed portion.
37 SignedBlob encoding = data.wireEncode(wireFormat);
38
39 signature->setSignature
Jeff Thompson9296f0c2013-09-23 18:10:27 -070040 (privateKeyStorage_->sign(encoding.signedBuf(), encoding.signedSize(), keyName, digestAlgorithm));
Jeff Thompson86e1d752013-09-17 17:22:38 -070041
42 // Encode again to include the signature.
43 data.wireEncode(wireFormat);
Jeff Thompson41471912013-09-12 16:21:50 -070044}
45
46}