public void expressHintInterest(Name.Component excludeComp = null) { Name hintName = new Name(prefix); hintName.append(this.getStartTimeComponent()).append(producerNameComponents.trackHint); Interest hintInterest = new Interest(hintName); if (excludeComp != null) { Exclude exclude = new Exclude(); exclude.appendAny(); // Debug.Log (" excluding hint num " + excludeComp.toNumber ()); exclude.appendComponent(excludeComp); hintInterest.setExclude(exclude); } hintInterest.setMustBeFresh(true); hintInterest.setInterestLifetimeMilliseconds(config.defaultHintLifetime); hintInterest.setChildSelector(1); HintHandler handler = new HintHandler(this); FaceSingleton.getFace().expressInterest(hintInterest, handler, handler); }
/// <summary> /// Set the key name in keyHandle according to identityName and params. /// </summary> /// protected static internal void setKeyName(TpmKeyHandle keyHandle, Name identityName, KeyParams paras) { Name.Component keyId; if (paras.getKeyIdType() == net.named_data.jndn.security.KeyIdType.USER_SPECIFIED) { keyId = paras.getKeyId(); } else if (paras.getKeyIdType() == net.named_data.jndn.security.KeyIdType.SHA256) { byte[] digest = net.named_data.jndn.util.Common.digestSha256(keyHandle.derivePublicKey() .buf()); keyId = new Name.Component(digest); } else if (paras.getKeyIdType() == net.named_data.jndn.security.KeyIdType.RANDOM) { if (paras.getKeyId().getValue().size() == 0) { throw new TpmBackEnd.Error( "setKeyName: The keyId is empty for type RANDOM"); } keyId = paras.getKeyId(); } else { throw new TpmBackEnd.Error("setKeyName: unrecognized params.getKeyIdType()"); } keyHandle.setKeyName(net.named_data.jndn.security.pib.PibKey.constructKeyName(identityName, keyId)); }
public void testKeyManagement() { /* foreach */ foreach (TpmBackEnd tpm in backEndList) { Name identityName = new Name("/Test/KeyName"); Name.Component keyId = new Name.Component("1"); Name keyName = net.named_data.jndn.security.pib.PibKey.constructKeyName(identityName, keyId); // The key should not exist. Assert.AssertEquals(false, tpm.hasKey(keyName)); Assert.AssertTrue(tpm.getKeyHandle(keyName) == null); // Create a key, which should exist. Assert.AssertTrue(tpm.createKey(identityName, new RsaKeyParams(keyId)) != null); Assert.AssertTrue(tpm.hasKey(keyName)); Assert.AssertTrue(tpm.getKeyHandle(keyName) != null); // Create a key with the same name, which should throw an error. try { tpm.createKey(identityName, new RsaKeyParams(keyId)); Assert.Fail("Did not throw the expected exception"); } catch (Tpm.Error ex) { } catch (Exception ex_0) { Assert.Fail("Did not throw the expected exception"); } // Delete the key, then it should not exist. tpm.deleteKey(keyName); Assert.AssertEquals(false, tpm.hasKey(keyName)); Assert.AssertTrue(tpm.getKeyHandle(keyName) == null); } }
public void testGetComponent() { Name name = new Name(expectedURI); Name.Component component2 = name.get(2); Assert.AssertTrue("Component at index 2 is incorrect", comp2.equals(component2)); }
public void testUnicode() { Name.Component comp1 = new Name.Component("entr\u00E9e"); String expected = "entr%C3%A9e"; Assert.AssertEquals("Unicode URI not decoded correctly", expected, comp1.toEscapedString()); }
/// <summary> /// Construct a key name based on the appropriate naming conventions. /// </summary> /// /// <param name="identityName">The name of the identity.</param> /// <param name="keyId">The key ID name component.</param> /// <returns>The constructed name as a new Name.</returns> public static Name constructKeyName(Name identityName, Name.Component keyId) { Name keyName = new Name(identityName); keyName.append(net.named_data.jndn.security.v2.CertificateV2.KEY_COMPONENT).append(keyId); return(keyName); }
static internal void setNameComponent(Interest interest, int index, Name.Component component) { Name name = interest.getName().getPrefix(index); name.append(component); name.append(interest.getName().getSubName(name.size())); interest.setName(name); }
// start is called by Unity public void Start() { this.prefix = new Name(config.rootPrefix).append(config.spaceName); startTimeComponent = new Name.Component(); expressInitialInterest(); Track.updatesTillActive = config.trackUpdatesTillActive; Track.timeoutsTillDead = config.trackTimeoutsTillDead; //DUMMY_TRACK = new Track (DUMMY_TRACK_ID); //tracks.Add (DUMMY_TRACK.id, DUMMY_TRACK); }
/// <summary> /// Create a key generation parameter. /// </summary> /// /// <param name="keyType">The type for the created key.</param> /// <param name="keyId"></param> /// <exception cref="System.AssertionError">if keyId is empty.</exception> protected internal KeyParams(KeyType keyType, Name.Component keyId) { this.keyId_ = new Name.Component(); if (keyId.getValue().size() == 0) { throw new AssertionError("KeyParams: keyId is empty"); } keyType_ = keyType; keyIdType_ = net.named_data.jndn.security.KeyIdType.USER_SPECIFIED; keyId_ = keyId; }
public void checkEncryptionKeys(IList result, double testTime, Name.Component roundedTime, int expectedExpressInterestCallCount) { Assert.AssertEquals(expectedExpressInterestCallCount, expressInterestCallCount_[0]); try { Assert.AssertEquals(true, testDb_.hasContentKey(testTime)); contentKey_[0] = testDb_.getContentKey(testTime); } catch (ProducerDb.Error ex) { Assert.Fail("Error in ProducerDb: " + ex); } EncryptParams paras = new EncryptParams( net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.RsaOaep); for (int i = 0; i < result.Count; ++i) { Data key = (Data)result[i]; Name keyName = key.getName(); Assert.AssertEquals(cKeyName_, keyName.getSubName(0, 6)); Assert.AssertEquals(keyName.get(6), roundedTime); Assert.AssertEquals(keyName.get(7), net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_FOR); Assert.AssertEquals(true, outer_TestProducer.decryptionKeys.Contains(keyName.getSubName(8))); Blob decryptionKey = (Blob)ILOG.J2CsMapping.Collections.Collections.Get(outer_TestProducer.decryptionKeys, keyName .getSubName(8)); Assert.AssertEquals(true, decryptionKey.size() != 0); Blob encryptedKeyEncoding = key.getContent(); EncryptedContent content = new EncryptedContent(); try { content.wireDecode(encryptedKeyEncoding); } catch (EncodingException ex_0) { Assert.Fail("Error decoding EncryptedContent" + ex_0); } Blob encryptedKey = content.getPayload(); Blob retrievedKey = null; try { retrievedKey = net.named_data.jndn.encrypt.algo.RsaAlgorithm.decrypt(decryptionKey, encryptedKey, paras); } catch (Exception ex_1) { Assert.Fail("Error in RsaAlgorithm.decrypt: " + ex_1); } Assert.AssertTrue(contentKey_[0].equals(retrievedKey)); } Assert.AssertEquals(3, result.Count); }
public void testHashCode() { Name.Component foo1 = new Name.Component("foo"); Name.Component foo2 = new Name.Component("foo"); Assert.AssertEquals("Hash codes for same strings are not equal", foo1.GetHashCode(), foo2.GetHashCode()); Name.Component bar = new Name.Component("bar"); // Strictly speaking, it is possible for a hash collision, but unlikely. Assert.AssertTrue("Hash codes for different strings are not different", foo1.GetHashCode() != bar.GetHashCode()); }
getChild(Name.Component component) { Namespace child; if (children_.TryGetValue(component, out child)) { return(child); } else { return(createChild(component, true)); } }
/// <summary> /// Exclude all components in the range beginning at "from". /// </summary> /// /// <param name="exclude">The Exclude object to update.</param> /// <param name="from">The first component in the exclude range.</param> private static void excludeAfter(Exclude exclude, Name.Component from) { ArrayList entries = getExcludeEntries(exclude); int iNewFrom; int iFoundFrom = findEntryBeforeOrAt(entries, from); if (iFoundFrom < 0) { // There is no entry before "from" so insert at the beginning. entries.Insert(0, new Producer.ExcludeEntry(from, true)); iNewFrom = 0; } else { Producer.ExcludeEntry foundFrom = (Producer.ExcludeEntry)entries[iFoundFrom]; if (!foundFrom.anyFollowsComponent_) { if (foundFrom.component_.equals(from)) { // There is already an entry with "from", so just set the "ANY" flag. foundFrom.anyFollowsComponent_ = true; iNewFrom = iFoundFrom; } else { // Insert following the entry before "from". entries.Insert(iFoundFrom + 1, new Producer.ExcludeEntry(from, true)); iNewFrom = iFoundFrom + 1; } } else { // The entry before "from" already has an "ANY" flag, so do nothing. iNewFrom = iFoundFrom; } } // Remove entries after the new "from". int iRemoveBegin = iNewFrom + 1; int nRemoveNeeded = entries.Count - iRemoveBegin; for (int i = 0; i < nRemoveNeeded; ++i) { ILOG.J2CsMapping.Collections.Collections.RemoveAt(entries, iRemoveBegin); } setExcludeEntries(exclude, entries); }
/// <summary> /// Create an AccessManagerV2 to serve the NAC public key for other data /// producers to fetch, and to serve encrypted versions of the private keys /// (as safe bags) for authorized consumers to fetch. /// KEK and KDK naming: /// [identity]/NAC/[dataset]/KEK /[key-id] (== KEK, public key) /// [identity]/NAC/[dataset]/KDK/[key-id] /ENCRYPTED-BY/[user]/KEY/[key-id] (== KDK, encrypted private key) /// \_____________ ______________/ /// \/ /// registered with NFD /// </summary> /// /// <param name="identity"></param> /// <param name="dataset">The name of dataset that this manager is controlling.</param> /// <param name="keyChain">The KeyChain used to sign Data packets.</param> /// <param name="face"></param> public AccessManagerV2(PibIdentity identity, Name dataset, KeyChain keyChain, Face face) { this.storage_ = new InMemoryStorageRetaining(); identity_ = identity; keyChain_ = keyChain; face_ = face; // The NAC identity is: <identity>/NAC/<dataset> // Generate the NAC key. PibIdentity nacIdentity = keyChain_.createIdentityV2( new Name(identity.getName()).append( net.named_data.jndn.encrypt.EncryptorV2.NAME_COMPONENT_NAC).append(dataset), new RsaKeyParams()); nacKey_ = nacIdentity.getDefaultKey(); if (nacKey_.getKeyType() != net.named_data.jndn.security.KeyType.RSA) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "Cannot re-use existing KEK/KDK pair, as it is not an RSA key, regenerating"); nacKey_ = keyChain_.createKey(nacIdentity, new RsaKeyParams()); } Name.Component nacKeyId = nacKey_.getName().get(-1); Name kekPrefix = new Name(nacKey_.getIdentityName()) .append(net.named_data.jndn.encrypt.EncryptorV2.NAME_COMPONENT_KEK); Data kekData = new Data(nacKey_.getDefaultCertificate()); kekData.setName(new Name(kekPrefix).append(nacKeyId)); kekData.getMetaInfo().setFreshnessPeriod( DEFAULT_KEK_FRESHNESS_PERIOD_MS); keyChain_.sign(kekData, new SigningInfo(identity_)); // A KEK looks like a certificate, but doesn't have a ValidityPeriod. storage_.insert(kekData); OnInterestCallback serveFromStorage = new AccessManagerV2.Anonymous_C1(this); OnRegisterFailed onRegisterFailed = new AccessManagerV2.Anonymous_C0(); kekRegisteredPrefixId_ = face_.registerPrefix(kekPrefix, serveFromStorage, onRegisterFailed); Name kdkPrefix = new Name(nacKey_.getIdentityName()).append( net.named_data.jndn.encrypt.EncryptorV2.NAME_COMPONENT_KDK).append(nacKeyId); kdkRegisteredPrefixId_ = face_.registerPrefix(kdkPrefix, serveFromStorage, onRegisterFailed); }
// start is called by Unity public void Start() { if (theConsumer != null) { Debug.LogError("Only one OpenPTrackListener should be created"); } else { theConsumer = this; } face = new Face(config.hostName); this.prefix = new Name(config.rootPrefix).append(config.spaceName); startTimeComponent = new Name.Component(); expressInitialInterest(); }
/// <summary> /// Get the latest entry in the list whose component_ is less than or equal to /// component. /// </summary> /// /// <param name="entries">The list of ExcludeEntry.</param> /// <param name="component">The component to compare.</param> /// <returns>The index of the found entry, or -1 if not found.</returns> private static int findEntryBeforeOrAt(ArrayList entries, Name.Component component) { int i = entries.Count - 1; while (i >= 0) { if (((Producer.ExcludeEntry)entries[i]).component_.compare(component) <= 0) { break; } --i; } return(i); }
createChild(Name.Component component, bool fireCallbacks) { var child = new Namespace(new Name(name_).append(component)); child.parent_ = this; children_[component] = child; if (fireCallbacks) { var nameSpace = this; while (nameSpace != null) { nameSpace.fireOnNameAdded(child); nameSpace = nameSpace.parent_; } } return(child); }
public void expressHintInterest(Name.Component excludeComp = null) { Name hintName = new Name(prefix); hintName.append(this.getStartTimeComponent()).append(producerNameComponents.trackHint); Interest hintInterest = new Interest(hintName); if (excludeComp != null) { Exclude exclude = new Exclude(); exclude.appendAny(); exclude.appendComponent(excludeComp); } hintInterest.setMustBeFresh(true); hintInterest.setInterestLifetimeMilliseconds(config.defaultHintLifetime); HintHandler handler = new HintHandler(this); face.expressInterest(hintInterest, handler, handler); }
//fetchTrack public void expressInterestForTrack(string trackID, Name.Component excludeComp = null) { Name trackName = new Name(prefix); trackName.append(startTimeComponent).append(producerNameComponents.tracks).append(trackID); //.append ("0"); Interest trackInterest = new Interest(trackName); if (excludeComp != null) { Exclude exclude = new Exclude(); exclude.appendAny(); exclude.appendComponent(excludeComp); trackInterest.setExclude(exclude); } trackInterest.setMustBeFresh(true); trackInterest.setChildSelector(1); TrackHandler handler = new TrackHandler(this); FaceSingleton.getFace().expressInterest(trackInterest, handler, handler); }
/// <summary> /// Create a key for the identityName according to params. /// </summary> /// /// <param name="identityName">The name if the identity.</param> /// <param name="params">The KeyParams for creating the key.</param> /// <returns>The handle of the created key.</returns> /// <exception cref="Tpm.Error">if params is invalid.</exception> /// <exception cref="TpmBackEnd.Error">if the key cannot be created.</exception> public TpmKeyHandle createKey(Name identityName, KeyParams paras) { // Do key name checking. if (paras.getKeyIdType() == net.named_data.jndn.security.KeyIdType.USER_SPECIFIED) { // The keyId is pre-set. Name keyName = net.named_data.jndn.security.pib.PibKey.constructKeyName(identityName, paras.getKeyId()); if (hasKey(keyName)) { throw new Tpm.Error("Key `" + keyName.toUri() + "` already exists"); } } else if (paras.getKeyIdType() == net.named_data.jndn.security.KeyIdType.SHA256) { // The key name will be assigned in setKeyName after the key is generated. } else if (paras.getKeyIdType() == net.named_data.jndn.security.KeyIdType.RANDOM) { Name keyName_0; Name.Component keyId; ByteBuffer random = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(8); do { net.named_data.jndn.util.Common.getRandom().nextBytes(random.array()); keyId = new Name.Component(new Blob(random, false)); keyName_0 = net.named_data.jndn.security.pib.PibKey.constructKeyName(identityName, keyId); } while (hasKey(keyName_0)); paras.setKeyId(keyId); } else { throw new Tpm.Error("Unsupported key id type"); } return(doCreateKey(identityName, paras)); }
public AesKeyParams(Name.Component keyId, int size) : base(getType(), keyId) { size_ = size; }
public void onInterest(Name prefix, Interest interest, Face face, long interestFilterId, InterestFilter filter) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "MemoryContentCache: Received Interest {0}", interest.toUri()); double nowMilliseconds = net.named_data.jndn.util.Common.getNowMilliseconds(); doCleanup(nowMilliseconds); Name.Component selectedComponent = null; Blob selectedEncoding = null; // We need to iterate over both arrays. int totalSize = staleTimeCache_.Count + noStaleTimeCache_.Count; for (int i = 0; i < totalSize; ++i) { MemoryContentCache.Content content; bool isFresh = true; if (i < staleTimeCache_.Count) { MemoryContentCache.StaleTimeContent staleTimeContent = staleTimeCache_[i]; content = staleTimeContent; isFresh = staleTimeContent.isFresh(nowMilliseconds); } else { // We have iterated over the first array. Get from the second. content = noStaleTimeCache_[i - staleTimeCache_.Count]; } if (interest.matchesName(content.getName()) && !(interest.getMustBeFresh() && !isFresh)) { if (interest.getChildSelector() < 0) { // No child selector, so send the first match that we have found. logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "MemoryContentCache: Reply Data {0}", content.getName()); try { face.send(content.getDataEncoding()); } catch (IOException ex) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex); } return; } else { // Update selectedEncoding based on the child selector. Name.Component component; if (content.getName().size() > interest.getName().size()) { component = content.getName().get( interest.getName().size()); } else { component = emptyComponent_; } bool gotBetterMatch = false; if (selectedEncoding == null) { // Save the first match. gotBetterMatch = true; } else { if (interest.getChildSelector() == 0) { // Leftmost child. if (component.compare(selectedComponent) < 0) { gotBetterMatch = true; } } else { // Rightmost child. if (component.compare(selectedComponent) > 0) { gotBetterMatch = true; } } } if (gotBetterMatch) { selectedComponent = component; selectedEncoding = content.getDataEncoding(); } } } } if (selectedEncoding != null) { // We found the leftmost or rightmost child. try { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "MemoryContentCache: Reply Data to Interest {0}", interest.toUri()); face.send(selectedEncoding); } catch (IOException ex_0) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_0); } } else { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "MemoryContentCache: onDataNotFound for {0}", interest.toUri()); // Call the onDataNotFound callback (if defined). Object onDataNotFound = ILOG.J2CsMapping.Collections.Collections.Get(onDataNotFoundForPrefix_, prefix.toUri()); if (onDataNotFound != null) { try { ((OnInterestCallback)onDataNotFound).onInterest(prefix, interest, face, interestFilterId, filter); } catch (Exception ex_1) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onDataNotFound", ex_1); } } } }
benchmarkEncodeDataSeconds (int nIterations, bool useComplex, bool useCrypto, KeyType keyType, Blob[] encoding) { Name name; Blob content; if (useComplex) { // Use a large name and content. name = new Name ("/ndn/ucla.edu/apps/lwndn-test/numbers.txt/%FD%05%05%E8%0C%CE%1D/%00"); StringBuilder contentStream = new StringBuilder(); int count = 1; contentStream.append(count++); while (contentStream.toString().Length < 1115) { contentStream.append(" ").append(count++); } content = new Blob(contentStream.toString()); } else { // Use a small name and content. name = new Name("/test"); content = new Blob("abc"); } Name.Component finalBlockId = new Name.Component(new Blob(new byte[] { (byte)0 })); // Initialize the KeyChain storage in case useCrypto is true. MemoryIdentityStorage identityStorage = new MemoryIdentityStorage(); MemoryPrivateKeyStorage privateKeyStorage = new MemoryPrivateKeyStorage(); KeyChain keyChain = new KeyChain (new IdentityManager(identityStorage, privateKeyStorage), 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"); privateKeyStorage.setKeyPairForKeyName (keyName, KeyType.RSA, new ByteBuffer(DEFAULT_RSA_PUBLIC_KEY_DER), new ByteBuffer(DEFAULT_RSA_PRIVATE_KEY_DER)); Blob signatureBits = new Blob(new byte[256]); Blob emptyBlob = new Blob(new byte[0]); double start = getNowSeconds(); for (int i = 0; i < nIterations; ++i) { Data data = new Data(name); data.setContent(content); if (useComplex) { data.getMetaInfo().setFreshnessPeriod(30000); data.getMetaInfo().setFinalBlockId(finalBlockId); } if (useCrypto) { // This sets the signature fields. keyChain.sign(data, certificateName); } else { // Imitate IdentityManager.signByCertificate to set up the signature // fields, but don't sign. KeyLocator keyLocator = new KeyLocator(); keyLocator.setType(KeyLocatorType.KEYNAME); keyLocator.setKeyName(certificateName); Sha256WithRsaSignature sha256Signature = (Sha256WithRsaSignature)data.getSignature(); sha256Signature.setKeyLocator(keyLocator); sha256Signature.setSignature(signatureBits); } encoding[0] = data.wireEncode(); } double finish = getNowSeconds(); return(finish - start); }
public ExcludeEntry(Name.Component component, bool anyFollowsComponent) { component_ = component; anyFollowsComponent_ = anyFollowsComponent; }
public void testContentKeyRequest() { Name prefix = new Name("/prefix"); Name suffix = new Name("/a/b/c"); Name expectedInterest = new Name(prefix); expectedInterest.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_READ); expectedInterest.append(suffix); expectedInterest.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_E_KEY); Name cKeyName = new Name(prefix); cKeyName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_SAMPLE); cKeyName.append(suffix); cKeyName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_C_KEY); Name timeMarker = new Name("20150101T100000/20150101T120000"); double testTime1 = net.named_data.jndn.encrypt.Schedule.fromIsoString("20150101T100001"); double testTime2 = net.named_data.jndn.encrypt.Schedule.fromIsoString("20150101T110001"); Name.Component testTimeRounded1 = new Name.Component( "20150101T100000"); Name.Component testTimeRounded2 = new Name.Component( "20150101T110000"); Name.Component testTimeComponent2 = new Name.Component( "20150101T110001"); // Create content keys required for this test case: for (int i = 0; i < suffix.size(); ++i) { createEncryptionKey(expectedInterest, timeMarker); expectedInterest = expectedInterest.getPrefix(-2).append( net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_E_KEY); } int[] expressInterestCallCount = new int[] { 0 }; // Prepare a LocalTestFace to instantly answer calls to expressInterest. TestProducer.LocalTestFace face = new TestProducer.LocalTestFace(this, timeMarker, expressInterestCallCount); // Verify that the content key is correctly encrypted for each domain, and // the produce method encrypts the provided data with the same content key. ProducerDb testDb = new Sqlite3ProducerDb( databaseFilePath.FullName); Producer producer = new Producer(prefix, suffix, face, keyChain, testDb); Blob[] contentKey = new Blob[] { null }; TestProducer.CheckEncryptionKeys checkEncryptionKeys = new TestProducer.CheckEncryptionKeys( this, expressInterestCallCount, contentKey, cKeyName, testDb); // An initial test to confirm that keys are created for this time slot. Name contentKeyName1 = producer.createContentKey(testTime1, new TestProducer.Anonymous_C4(checkEncryptionKeys, testTimeRounded1, testTime1)); // Verify that we do not repeat the search for e-keys. The total // expressInterestCallCount should be the same. Name contentKeyName2 = producer.createContentKey(testTime2, new TestProducer.Anonymous_C3(checkEncryptionKeys, testTime2, testTimeRounded2)); // Confirm content key names are correct Assert.AssertEquals(cKeyName, contentKeyName1.getPrefix(-1)); Assert.AssertEquals(testTimeRounded1, contentKeyName1.get(6)); Assert.AssertEquals(cKeyName, contentKeyName2.getPrefix(-1)); Assert.AssertEquals(testTimeRounded2, contentKeyName2.get(6)); // Confirm that produce encrypts with the correct key and has the right name. Data testData = new Data(); producer.produce(testData, testTime2, new Blob(DATA_CONTENT, false)); Name producedName = testData.getName(); Assert.AssertEquals(cKeyName.getPrefix(-1), producedName.getSubName(0, 5)); Assert.AssertEquals(testTimeComponent2, producedName.get(5)); Assert.AssertEquals(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_FOR, producedName.get(6)); Assert.AssertEquals(cKeyName, producedName.getSubName(7, 6)); Assert.AssertEquals(testTimeRounded2, producedName.get(13)); Blob dataBlob = testData.getContent(); EncryptedContent dataContent = new EncryptedContent(); dataContent.wireDecode(dataBlob); Blob encryptedData = dataContent.getPayload(); Blob initialVector = dataContent.getInitialVector(); EncryptParams paras = new EncryptParams(net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.AesCbc, 16); paras.setInitialVector(initialVector); Blob decryptTest = net.named_data.jndn.encrypt.algo.AesAlgorithm.decrypt(contentKey[0], encryptedData, paras); Assert.AssertTrue(decryptTest.equals(new Blob(DATA_CONTENT, false))); }
/// <summary> /// Exclude all components in the range ending at "to". /// </summary> /// /// <param name="exclude">The Exclude object to update.</param> /// <param name="to">The last component in the exclude range.</param> private static void excludeBefore(Exclude exclude, Name.Component to) { excludeRange(exclude, new Name.Component(), to); }
public void setKeyId(Name.Component keyId) { keyId_ = keyId; }
/// <summary> /// Exclude all components in the range beginning at "from" and ending at "to". /// </summary> /// /// <param name="exclude">The Exclude object to update.</param> /// <param name="from">The first component in the exclude range.</param> /// <param name="to">The last component in the exclude range.</param> private static void excludeRange(Exclude exclude, Name.Component from, Name.Component to) { if (from.compare(to) >= 0) { if (from.compare(to) == 0) { throw new Exception( "excludeRange: from == to. To exclude a single component, sue excludeOne."); } else { throw new Exception( "excludeRange: from must be less than to. Invalid range: [" + from.toEscapedString() + ", " + to.toEscapedString() + "]"); } } ArrayList entries = getExcludeEntries(exclude); int iNewFrom; int iFoundFrom = findEntryBeforeOrAt(entries, from); if (iFoundFrom < 0) { // There is no entry before "from" so insert at the beginning. entries.Insert(0, new Producer.ExcludeEntry(from, true)); iNewFrom = 0; } else { Producer.ExcludeEntry foundFrom = (Producer.ExcludeEntry)entries[iFoundFrom]; if (!foundFrom.anyFollowsComponent_) { if (foundFrom.component_.equals(from)) { // There is already an entry with "from", so just set the "ANY" flag. foundFrom.anyFollowsComponent_ = true; iNewFrom = iFoundFrom; } else { // Insert following the entry before "from". entries.Insert(iFoundFrom + 1, new Producer.ExcludeEntry(from, true)); iNewFrom = iFoundFrom + 1; } } else { // The entry before "from" already has an "ANY" flag, so do nothing. iNewFrom = iFoundFrom; } } // We have at least one "from" before "to", so we know this will find an entry. int iFoundTo = findEntryBeforeOrAt(entries, to); Producer.ExcludeEntry foundTo = (Producer.ExcludeEntry)entries[iFoundTo]; if (iFoundTo == iNewFrom) { // Insert the "to" immediately after the "from". entries.Insert(iNewFrom + 1, new Producer.ExcludeEntry(to, false)); } else { int iRemoveEnd; if (!foundTo.anyFollowsComponent_) { if (foundTo.component_.equals(to)) { // The "to" entry already exists. Remove up to it. iRemoveEnd = iFoundTo; } else { // Insert following the previous entry, which will be removed. entries.Insert(iFoundTo + 1, new Producer.ExcludeEntry(to, false)); iRemoveEnd = iFoundTo + 1; } } else { // "to" follows a component which is already followed by "ANY", meaning // the new range now encompasses it, so remove the component. iRemoveEnd = iFoundTo + 1; } // Remove intermediate entries since they are inside the range. int iRemoveBegin = iNewFrom + 1; int nRemoveNeeded = iRemoveEnd - iRemoveBegin; for (int i = 0; i < nRemoveNeeded; ++i) { ILOG.J2CsMapping.Collections.Collections.RemoveAt(entries, iRemoveBegin); } } setExcludeEntries(exclude, entries); }
public AesKeyParams(Name.Component keyId) : base(getType(), keyId) { size_ = getDefaultSize(); }
public EcdsaKeyParams(Name.Component keyId) : base(keyId) { }