Example #1
0
void
IdentityManager::signInterestWithSha256
  (Interest& interest, WireFormat& wireFormat)
{
  DigestSha256Signature signature;
  // Append the encoded SignatureInfo.
  interest.getName().append(wireFormat.encodeSignatureInfo(signature));

  // Append an empty signature so that the "signedPortion" is correct.
  interest.getName().append(Name::Component());
  // Encode once to get the signed portion.
  SignedBlob encoding = interest.wireEncode(wireFormat);

  // Digest and set the signature.
  uint8_t signedPortionDigest[ndn_SHA256_DIGEST_SIZE];
  ndn_digestSha256
    (encoding.signedBuf(), encoding.signedSize(), signedPortionDigest);
  signature.setSignature(Blob(signedPortionDigest, sizeof(signedPortionDigest)));

  // Remove the empty signature and append the real one.
  interest.setName(interest.getName().getPrefix(-1).append
    (wireFormat.encodeSignatureValue(signature)));
}
Example #2
0
void
KeyChain::sign
  (Interest& interest, const Name& certificateName, WireFormat& wireFormat)
{
  // TODO: Handle signature algorithms other than Sha256WithRsa.
  Sha256WithRsaSignature signature;
  signature.getKeyLocator().setType(ndn_KeyLocatorType_KEYNAME);
  signature.getKeyLocator().setKeyName(certificateName.getPrefix(-1));

  // Append the encoded SignatureInfo.
  interest.getName().append(wireFormat.encodeSignatureInfo(signature));

  // Append an empty signature so that the "signedPortion" is correct.
  interest.getName().append(Name::Component());
  // Encode once to get the signed portion, and sign.
  SignedBlob encoding = interest.wireEncode(wireFormat);
  ptr_lib::shared_ptr<Signature> signedSignature = sign
    (encoding.signedBuf(), encoding.signedSize(), certificateName);

  // Remove the empty signature and append the real one.
  interest.setName(interest.getName().getPrefix(-1).append
    (wireFormat.encodeSignatureValue(*signedSignature)));
}
Example #3
0
void
IdentityManager::signInterestByCertificate
  (Interest& interest, const Name& certificateName, WireFormat& wireFormat)
{
  DigestAlgorithm digestAlgorithm;
  ptr_lib::shared_ptr<Signature> signature = makeSignatureByCertificate
    (certificateName, digestAlgorithm);

  // Append the encoded SignatureInfo.
  interest.getName().append(wireFormat.encodeSignatureInfo(*signature));

  // Append an empty signature so that the "signedPortion" is correct.
  interest.getName().append(Name::Component());
  // Encode once to get the signed portion, and sign.
  SignedBlob encoding = interest.wireEncode(wireFormat);
  signature->setSignature
    (privateKeyStorage_->sign(encoding.signedBuf(), encoding.signedSize(),
     IdentityCertificate::certificateNameToPublicKeyName(certificateName),
     digestAlgorithm));

  // Remove the empty signature and append the real one.
  interest.setName(interest.getName().getPrefix(-1).append
    (wireFormat.encodeSignatureValue(*signature)));
}