Ejemplo n.º 1
0
 /**
  * Decode the input using a particular wire format and update this
  * EncryptedContent.
  * @param input The input byte array to be decoded.
  * @param inputLength The length of input.
  * @param wireFormat (optional) A WireFormat object used to decode the input.
  * If omitted, use WireFormat::getDefaultWireFormat().
  */
 void
 wireDecode
   (const uint8_t *input, size_t inputLength,
    WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
 {
   wireFormat.decodeEncryptedContent(*this, input, inputLength);
 }
Ejemplo n.º 2
0
    uint16_t Client::sendPacket( const WireFormat &data )
    {
        if ( udp_socket < 0 )
            openSocket();

        return data.send( udp_socket, NULL, 0 );
    }
Ejemplo n.º 3
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)));
}
Ejemplo n.º 4
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)));
}
Ejemplo n.º 5
0
void
Data::wireDecode(const Blob& input, WireFormat& wireFormat)
{
  size_t signedPortionBeginOffset, signedPortionEndOffset;
  wireFormat.decodeData(*this, input.buf(), input.size(), &signedPortionBeginOffset, &signedPortionEndOffset);

  if (&wireFormat == WireFormat::getDefaultWireFormat())
    // This is the default wire encoding.
    // Take a pointer to the input Blob without copying.
    setDefaultWireEncoding
      (SignedBlob(input, signedPortionBeginOffset, signedPortionEndOffset),
       WireFormat::getDefaultWireFormat());
  else
    setDefaultWireEncoding(SignedBlob(), 0);
}
Ejemplo n.º 6
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)));
}
Ejemplo n.º 7
0
SignedBlob
Data::wireEncode(WireFormat& wireFormat) const
{
  if (getDefaultWireEncoding() && getDefaultWireEncodingFormat() == &wireFormat)
    // We already have an encoding in the desired format.
    return getDefaultWireEncoding();

  size_t signedPortionBeginOffset, signedPortionEndOffset;
  Blob encoding = wireFormat.encodeData(*this, &signedPortionBeginOffset, &signedPortionEndOffset);
  SignedBlob wireEncoding = SignedBlob(encoding, signedPortionBeginOffset, signedPortionEndOffset);

  if (&wireFormat == WireFormat::getDefaultWireFormat())
    // This is the default wire encoding.
    const_cast<Data*>(this)->setDefaultWireEncoding
      (wireEncoding, WireFormat::getDefaultWireFormat());

  return wireEncoding;
}
ptr_lib::shared_ptr<ValidationRequest>
SelfVerifyPolicyManager::checkVerificationPolicy
  (const ptr_lib::shared_ptr<Interest>& interest, int stepCount,
   const OnVerifiedInterest& onVerified,
   const OnVerifyInterestFailed& onVerifyFailed, WireFormat& wireFormat)
{
  // Decode the last two name components of the signed interest
  ptr_lib::shared_ptr<Signature> signature =
    wireFormat.decodeSignatureInfoAndValue
      (interest->getName().get(-2).getValue().buf(),
       interest->getName().get(-2).getValue().size(),
       interest->getName().get(-1).getValue().buf(),
       interest->getName().get(-1).getValue().size());

  // wireEncode returns the cached encoding if available.
  if (verify(signature.get(), interest->wireEncode()))
    onVerified(interest);
  else
    onVerifyFailed(interest);
  
  // No more steps, so return a null ValidationRequest.
  return ptr_lib::shared_ptr<ValidationRequest>();
}
Ejemplo n.º 9
0
 void
 wireDecode(const uint8_t *input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
 {
   wireFormat.decodeControlParameters(*this, input, inputLength);
 }
Ejemplo n.º 10
0
 Blob
 wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
 {
   return wireFormat.encodeControlParameters(*this);
 }
Ejemplo n.º 11
0
 /**
  * Encode this EncryptedContent for a particular wire format.
  * @param wireFormat (optional) A WireFormat object used to encode this
  * EncryptedContent. If omitted, use WireFormat::getDefaultWireFormat().
  * @return The encoded byte array.
  */
 Blob
 wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
 {
   return wireFormat.encodeEncryptedContent(*this);
 }
 void
 wireDecode(const uint8_t *input, size_t inputLength, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
 {
   wireFormat.decodeForwardingEntry(*this, input, inputLength);
 }
 Blob
 wireEncode(WireFormat& wireFormat = *WireFormat::getDefaultWireFormat()) const
 {
   return wireFormat.encodeForwardingEntry(*this);
 }