/// <summary> /// Decode the input using a particular wire format and update this DelegationSet. /// </summary> /// /// <param name="input">The input blob to decode.</param> /// <param name="wireFormat">A WireFormat object used to decode the input.</param> /// <exception cref="EncodingException">For invalid encoding.</exception> public void wireDecode(Blob input, WireFormat wireFormat) { wireFormat.decodeDelegationSet(this, input.buf(), false); }
/// <summary> /// Decode the input using the default wire format /// WireFormat.getDefaultWireFormat() and update this DelegationSet. /// </summary> /// /// <param name="input">The input blob to decode.</param> /// <exception cref="EncodingException">For invalid encoding.</exception> public void wireDecode(Blob input) { wireDecode(input.buf()); }
/// <summary> /// Send the encoded packet out through the face. /// </summary> /// /// <param name="encoding">The blob with the the encoded packet to send.</param> /// <exception cref="System.Exception">If the encoded packet size exceeds getMaxNdnPacketSize().</exception> public void send(Blob encoding) { send(encoding.buf()); }
/// <summary> /// Decode the input using a particular wire format and update this Name. /// </summary> /// /// <param name="input">The input blob to decode.</param> /// <param name="wireFormat">A WireFormat object used to decode the input.</param> /// <exception cref="EncodingException">For invalid encoding.</exception> public void wireDecode(Blob input, WireFormat wireFormat) { wireFormat.decodeName(this, input.buf(), false); }
/// <summary> /// Decode the input using a particular wire format and update this Data. If /// wireFormat is the default wire format, also set the defaultWireEncoding /// field another pointer to the input Blob. /// </summary> /// /// <param name="input"></param> /// <param name="wireFormat">A WireFormat object used to decode the input.</param> /// <exception cref="EncodingException">For invalid encoding.</exception> public virtual void wireDecode(Blob input, WireFormat wireFormat) { int[] signedPortionBeginOffset = new int[1]; int[] signedPortionEndOffset = new int[1]; wireFormat.decodeData(this, input.buf(), signedPortionBeginOffset, signedPortionEndOffset, false); if (wireFormat == net.named_data.jndn.encoding.WireFormat.getDefaultWireFormat()) // This is the default wire encoding. setDefaultWireEncoding(new SignedBlob(input, signedPortionBeginOffset[0], signedPortionEndOffset[0]), net.named_data.jndn.encoding.WireFormat.getDefaultWireFormat()); else setDefaultWireEncoding(new SignedBlob(), null); }
/// <summary> /// Derive a new encrypt key from the given decrypt key value. /// </summary> /// /// <param name="keyBits"></param> /// <returns>The new encrypt key (DER-encoded public key).</returns> public static EncryptKey deriveEncryptKey(Blob keyBits) { // Decode the PKCS #8 private key. (We don't use RSAPrivateCrtKey because // the Android library doesn't have an easy way to decode into it.) DerNode parsedNode = net.named_data.jndn.encoding.der.DerNode.parse(keyBits.buf(), 0); IList pkcs8Children = parsedNode.getChildren(); IList algorithmIdChildren = net.named_data.jndn.encoding.der.DerNode.getSequence(pkcs8Children, 1) .getChildren(); String oidString = ((DerNode.DerOid) algorithmIdChildren[0]) .toVal().toString(); Blob rsaPrivateKeyDer = ((DerNode) pkcs8Children[2]).getPayload(); String RSA_ENCRYPTION_OID = "1.2.840.113549.1.1.1"; if (!oidString.equals(RSA_ENCRYPTION_OID)) throw new DerDecodingException( "The PKCS #8 private key is not RSA_ENCRYPTION"); // Decode the PKCS #1 RSAPrivateKey. parsedNode = net.named_data.jndn.encoding.der.DerNode.parse(rsaPrivateKeyDer.buf(), 0); IList rsaPrivateKeyChildren = parsedNode.getChildren(); Blob modulus = ((DerNode) rsaPrivateKeyChildren[1]).getPayload(); Blob publicExponent = ((DerNode) rsaPrivateKeyChildren[2]) .getPayload(); System.SecurityPublicKey publicKey = keyFactory_ .generatePublic(new RSAPublicKeySpec(new Int64(modulus .getImmutableArray()), new Int64(publicExponent .getImmutableArray()))); return new EncryptKey(new Blob(publicKey.getEncoded(), false)); }
/** * Loop to decode a data packet nIterations times. * @param nIterations The number of iterations. * @param useCrypto If true, verify the signature. If false, don't verify. * @param keyType KeyType.RSA or EC, used if useCrypto is true. * @param encoding The wire encoding to decode. * @return The number of seconds for all iterations. * @throws EncodingException */ private static double benchmarkDecodeDataSeconds(int nIterations, bool useCrypto, KeyType keyType, Blob encoding) { // Initialize the KeyChain storage in case useCrypto is true. MemoryIdentityStorage identityStorage = new MemoryIdentityStorage(); KeyChain keyChain = new KeyChain (new IdentityManager(identityStorage, new MemoryPrivateKeyStorage()), new SelfVerifyPolicyManager(identityStorage)); Name keyName = new Name("/testname/DSK-123"); Name certificateName = keyName.getSubName(0, keyName.size() - 1).append ("KEY").append(keyName.get(-1)).append("ID-CERT").append("0"); identityStorage.addKey(keyName, KeyType.RSA, new Blob(DEFAULT_RSA_PUBLIC_KEY_DER)); VerifyCallbacks callbacks = new VerifyCallbacks(); double start = getNowSeconds(); for (int i = 0; i < nIterations; ++i) { Data data = new Data(); data.wireDecode(encoding.buf()); if (useCrypto) keyChain.verifyData(data, callbacks, callbacks); } double finish = getNowSeconds(); return finish - start; }
/// <summary> /// Decode the input using a particular wire format and update this Interest. If /// wireFormat is the default wire format, also set the defaultWireEncoding /// field another pointer to the input Blob. /// </summary> /// /// <param name="input">The input blob to decode.</param> /// <param name="wireFormat">A WireFormat object used to decode the input.</param> /// <exception cref="EncodingException">For invalid encoding.</exception> public void wireDecode(Blob input, WireFormat wireFormat) { wireDecodeHelper(input.buf(), wireFormat, false); }
/// <summary> /// Decode the input using a particular wire format and update this ControlResponse. /// </summary> /// /// <param name="input">The input blob to decode.</param> /// <param name="wireFormat">A WireFormat object used to decode the input.</param> /// <exception cref="EncodingException">For invalid encoding.</exception> public void wireDecode(Blob input, WireFormat wireFormat) { wireFormat.decodeControlResponse(this, input.buf(), false); }
/// <summary> /// Decode the input using a particular wire format and update this ControlParameters. /// </summary> /// /// <param name="input">The input blob to decode.</param> /// <param name="wireFormat">A WireFormat object used to decode the input.</param> /// <exception cref="EncodingException">For invalid encoding.</exception> public void wireDecode(Blob input, WireFormat wireFormat) { wireFormat.decodeControlParameters(this, input.buf(), false); }
/// <summary> /// Decode the input using a particular wire format and update this /// EncryptedContent. /// </summary> /// /// <param name="input">The input blob to decode.</param> /// <param name="wireFormat">A WireFormat object used to decode the input.</param> /// <exception cref="EncodingException">For invalid encoding.</exception> public void wireDecode(Blob input, WireFormat wireFormat) { wireFormat.decodeEncryptedContent(this, input.buf(), false); }
public void setUp() { // Don't show INFO log messages. ILOG.J2CsMapping.Util.Logging.Logger.getLogger("").setLevel(ILOG.J2CsMapping.Util.Logging.Level.WARNING); FileInfo policyConfigDirectory = net.named_data.jndn.tests.integration_tests.IntegrationTestsCommon .getPolicyConfigDirectory(); dKeyDatabaseFilePath = new FileInfo(System.IO.Path.Combine(policyConfigDirectory.FullName,"manager-d-key-test.db")); dKeyDatabaseFilePath.delete(); eKeyDatabaseFilePath = new FileInfo(System.IO.Path.Combine(policyConfigDirectory.FullName,"manager-e-key-test.db")); eKeyDatabaseFilePath.delete(); intervalDatabaseFilePath = new FileInfo(System.IO.Path.Combine(policyConfigDirectory.FullName,"manager-interval-test.db")); intervalDatabaseFilePath.delete(); groupKeyDatabaseFilePath = new FileInfo(System.IO.Path.Combine(policyConfigDirectory.FullName,"manager-group-key-test.db")); groupKeyDatabaseFilePath.delete(); RsaKeyParams paras = new RsaKeyParams(); DecryptKey memberDecryptKey = net.named_data.jndn.encrypt.algo.RsaAlgorithm.generateKey(paras); decryptKeyBlob = memberDecryptKey.getKeyBits(); EncryptKey memberEncryptKey = net.named_data.jndn.encrypt.algo.RsaAlgorithm .deriveEncryptKey(decryptKeyBlob); encryptKeyBlob = memberEncryptKey.getKeyBits(); // Generate the certificate. certificate.setName(new Name("/ndn/memberA/KEY/ksk-123/ID-CERT/123")); PublicKey contentPublicKey = new PublicKey(encryptKeyBlob); certificate.setPublicKeyInfo(contentPublicKey); certificate.encode(); Blob signatureInfoBlob = new Blob(SIG_INFO, false); Blob signatureValueBlob = new Blob(SIG_VALUE, false); Signature signature = net.named_data.jndn.encoding.TlvWireFormat.get().decodeSignatureInfoAndValue( signatureInfoBlob.buf(), signatureValueBlob.buf()); certificate.setSignature(signature); certificate.wireEncode(); // Set up the keyChain. MemoryIdentityStorage identityStorage = new MemoryIdentityStorage(); MemoryPrivateKeyStorage privateKeyStorage = new MemoryPrivateKeyStorage(); keyChain = new KeyChain(new IdentityManager(identityStorage, privateKeyStorage), new NoVerifyPolicyManager()); Name identityName = new Name("TestGroupManager"); keyChain.createIdentityAndCertificate(identityName); keyChain.getIdentityManager().setDefaultIdentity(identityName); net.named_data.jndn.encrypt.GroupManager.setFriendAccess(this); }
/// <summary> /// Create a new PublicKey by decoding the keyDer. Set the key type from the /// decoding. /// </summary> /// /// <param name="keyDer">The blob of the SubjectPublicKeyInfo DER.</param> /// <exception cref="UnrecognizedKeyFormatException">if can't decode the key DER.</exception> public PublicKey(Blob keyDer) { keyDer_ = keyDer; // Get the public key OID. String oidString = null; try { DerNode parsedNode = net.named_data.jndn.encoding.der.DerNode.parse(keyDer.buf(), 0); IList rootChildren = parsedNode.getChildren(); IList algorithmIdChildren = net.named_data.jndn.encoding.der.DerNode.getSequence(rootChildren, 0) .getChildren(); oidString = "" + ((DerNode) algorithmIdChildren[0]).toVal(); } catch (DerDecodingException ex) { throw new UnrecognizedKeyFormatException( "PublicKey: Error decoding the public key: " + ex.Message); } // Verify that the we can decode. if (oidString.equals(RSA_ENCRYPTION_OID)) { keyType_ = net.named_data.jndn.security.KeyType.RSA; KeyFactory keyFactory = null; try { keyFactory = System.KeyFactory.getInstance("RSA"); } catch (Exception exception) { // Don't expect this to happen. throw new UnrecognizedKeyFormatException( "RSA is not supported: " + exception.Message); } try { keyFactory.generatePublic(new X509EncodedKeySpec(keyDer .getImmutableArray())); } catch (InvalidKeySpecException exception_0) { // Don't expect this to happen. throw new UnrecognizedKeyFormatException( "X509EncodedKeySpec is not supported for RSA: " + exception_0.Message); } } else if (oidString.equals(EC_ENCRYPTION_OID)) { keyType_ = net.named_data.jndn.security.KeyType.ECDSA; KeyFactory keyFactory_1 = null; try { keyFactory_1 = System.KeyFactory.getInstance("EC"); } catch (Exception exception_2) { // Don't expect this to happen. throw new UnrecognizedKeyFormatException( "EC is not supported: " + exception_2.Message); } try { keyFactory_1.generatePublic(new X509EncodedKeySpec(keyDer .getImmutableArray())); } catch (InvalidKeySpecException exception_3) { // Don't expect this to happen. throw new UnrecognizedKeyFormatException( "X509EncodedKeySpec is not supported for EC: " + exception_3.Message); } } else throw new UnrecognizedKeyFormatException( "PublicKey: Unrecognized OID " + oidString); }