Exemplo n.º 1
0
 public Anonymous_C5(DecryptorV2 paramouter_DecryptorV2,
                     net.named_data.jndn.encrypt.EncryptError.OnError onError_0, DecryptorV2.ContentKey contentKey_1)
 {
     this.onError           = onError_0;
     this.contentKey        = contentKey_1;
     this.outer_DecryptorV2 = paramouter_DecryptorV2;
 }
Exemplo n.º 2
0
 public Anonymous_C2(EncryptorV2 paramouter_EncryptorV2,
                     IRunnable onReady_0, net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
 {
     this.onReady           = onReady_0;
     this.onError           = onError_1;
     this.outer_EncryptorV2 = paramouter_EncryptorV2;
 }
Exemplo n.º 3
0
 public Anonymous_C6(Consumer paramouter_Consumer,
                     Consumer.OnConsumeComplete onConsumeComplete_0, net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
 {
     this.onConsumeComplete = onConsumeComplete_0;
     this.onError           = onError_1;
     this.outer_Consumer    = paramouter_Consumer;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Make a CK Data packet for ckName_ encrypted by the KEK in kekData_ and
        /// insert it in the storage_.
        /// </summary>
        ///
        /// <param name="onError_0">error string.</param>
        /// <returns>True on success, else false.</returns>
        internal bool makeAndPublishCkData(net.named_data.jndn.encrypt.EncryptError.OnError onError_0)
        {
            try {
                PublicKey kek = new PublicKey(kekData_.getContent());

                EncryptedContent content = new EncryptedContent();
                content.setPayload(kek.encrypt(ckBits_,
                                               net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.RsaOaep));

                Data ckData = new Data(new Name(ckName_).append(
                                           NAME_COMPONENT_ENCRYPTED_BY).append(kekData_.getName()));
                ckData.setContent(content.wireEncodeV2());
                // FreshnessPeriod can serve as a soft access control for revoking access.
                ckData.getMetaInfo().setFreshnessPeriod(
                    DEFAULT_CK_FRESHNESS_PERIOD_MS);
                keyChain_.sign(ckData, ckDataSigningInfo_);
                storage_.insert(ckData);

                logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "Publishing CK data: {0}", ckData.getName());
                return(true);
            } catch (Exception ex) {
                onError_0.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.EncryptionFailure,
                                  "Failed to encrypt generated CK with KEK "
                                  + kekData_.getName().toUri());
                return(false);
            }
        }
Exemplo n.º 5
0
 public Anonymous_C3(Consumer.OnPlainText callerOnPlainText_0, net.named_data.jndn.encrypt.EncryptError.OnError onError_1,
                     Blob encryptedPayloadBlob_2)
 {
     this.callerOnPlainText    = callerOnPlainText_0;
     this.onError              = onError_1;
     this.encryptedPayloadBlob = encryptedPayloadBlob_2;
 }
Exemplo n.º 6
0
 public Anonymous_C2(Consumer paramouter_Consumer, net.named_data.jndn.encrypt.EncryptError.OnError onError_0,
                     OnVerified onVerified_1)
 {
     this.onError        = onError_0;
     this.onVerified     = onVerified_1;
     this.outer_Consumer = paramouter_Consumer;
 }
Exemplo n.º 7
0
        /// <summary>
        /// Send an interest with the given name through the face with callbacks to
        /// handleCoveringKey, handleTimeout and handleNetworkNack.
        /// </summary>
        ///
        /// <param name="interest">The interest to send.</param>
        /// <param name="timeSlot_0"></param>
        /// <param name="onEncryptedKeys_1"></param>
        private void sendKeyInterest(Interest interest, double timeSlot_0,
                                     Producer.OnEncryptedKeys onEncryptedKeys_1, net.named_data.jndn.encrypt.EncryptError.OnError onError_2)
        {
            OnData onKey = new Producer.Anonymous_C2(this, timeSlot_0, onEncryptedKeys_1, onError_2);

            OnTimeout onTimeout = new Producer.Anonymous_C1(this, onEncryptedKeys_1, onError_2, timeSlot_0);

            OnNetworkNack onNetworkNack = new Producer.Anonymous_C0(this, onError_2, timeSlot_0, onEncryptedKeys_1);

            Interest request;

            if (keyRetrievalLink_.getDelegations().size() == 0)
            {
                // We can use the supplied interest without copying.
                request = interest;
            }
            else
            {
                // Copy the supplied interest and add the Link.
                request = new Interest(interest);
                // This will use a cached encoding if available.
                request.setLinkWireEncoding(keyRetrievalLink_.wireEncode());
            }

            face_.expressInterest(request, onKey, onTimeout, onNetworkNack);
        }
Exemplo n.º 8
0
 public Anonymous_C0(EncryptorV2 paramouter_EncryptorV2, int nTriesLeft_0,
                     IRunnable onReady_1, net.named_data.jndn.encrypt.EncryptError.OnError onError_2)
 {
     this.nTriesLeft        = nTriesLeft_0;
     this.onReady           = onReady_1;
     this.onError           = onError_2;
     this.outer_EncryptorV2 = paramouter_EncryptorV2;
 }
Exemplo n.º 9
0
 public Anonymous_C1(Consumer paramouter_Consumer, Interest interest_0,
                     OnData onData_1, net.named_data.jndn.encrypt.EncryptError.OnError onError_2)
 {
     this.interest       = interest_0;
     this.onData         = onData_1;
     this.onError        = onError_2;
     this.outer_Consumer = paramouter_Consumer;
 }
Exemplo n.º 10
0
 public Anonymous_C0(Producer paramouter_Producer, net.named_data.jndn.encrypt.EncryptError.OnError onError_0,
                     double timeSlot_1, Producer.OnEncryptedKeys onEncryptedKeys_2)
 {
     this.onError         = onError_0;
     this.timeSlot        = timeSlot_1;
     this.onEncryptedKeys = onEncryptedKeys_2;
     this.outer_Producer  = paramouter_Producer;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Decrypt cKeyData.
        /// </summary>
        ///
        /// <param name="cKeyData">The C-KEY data packet.</param>
        /// <param name="onPlainText_0"></param>
        /// <param name="onError_1">This calls onError.onError(errorCode, message) for an error.</param>
        internal void decryptCKey(Data cKeyData, Consumer.OnPlainText onPlainText_0,
                                  net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
        {
            // Get the encrypted content.
            Blob             cKeyContent            = cKeyData.getContent();
            EncryptedContent cKeyEncryptedContent_2 = new EncryptedContent();

            try {
                cKeyEncryptedContent_2.wireDecode(cKeyContent);
            } catch (EncodingException ex) {
                try {
                    onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.InvalidEncryptedFormat,
                                      ex.Message);
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
                }
                return;
            }
            Name eKeyName   = cKeyEncryptedContent_2.getKeyLocator().getKeyName();
            Name dKeyName_3 = eKeyName.getPrefix(-3);

            dKeyName_3.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_D_KEY).append(
                eKeyName.getSubName(-2));

            // Check if the decryption key is already in the store.
            Blob dKey = (Blob)ILOG.J2CsMapping.Collections.Collections.Get(dKeyMap_, dKeyName_3);

            if (dKey != null)
            {
                decrypt(cKeyEncryptedContent_2, dKey, onPlainText_0, onError_1);
            }
            else
            {
                // Get the D-Key Data.
                Name interestName = new Name(dKeyName_3);
                interestName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_FOR).append(
                    consumerName_);
                Interest interest_4 = new Interest(interestName);

                // Prepare the callback functions.
                OnData onData_5 = new Consumer.Anonymous_C2(this, onError_1, onPlainText_0, cKeyEncryptedContent_2,
                                                            dKeyName_3);

                OnTimeout onTimeout = new Consumer.Anonymous_C1(this, interest_4, onData_5, onError_1);

                // Express the Interest.
                try {
                    face_.expressInterest(interest_4, onData_5, onTimeout);
                } catch (IOException ex_6) {
                    try {
                        onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.IOException,
                                          "expressInterest error: " + ex_6.Message);
                    } catch (Exception exception_7) {
                        logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception_7);
                    }
                }
            }
        }
Exemplo n.º 12
0
 public Anonymous_C0(Consumer paramouter_Consumer, net.named_data.jndn.encrypt.EncryptError.OnError onError_0,
                     OnVerified onVerified_1, Link link_2, int nRetrials_3)
 {
     this.onError        = onError_0;
     this.onVerified     = onVerified_1;
     this.link           = link_2;
     this.nRetrials      = nRetrials_3;
     this.outer_Consumer = paramouter_Consumer;
 }
Exemplo n.º 13
0
        /// <summary>
        /// Express an Interest to fetch the content packet with contentName, and
        /// decrypt it, fetching keys as needed.
        /// </summary>
        ///
        /// <param name="contentName">The name of the content packet.</param>
        /// <param name="onConsumeComplete_0">contentData is the fetched Data packet and result is the decrypted plain text Blob. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onError_1">better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="link_2">getDelegations().size() is zero, don't use it.</param>
        public void consume(Name contentName,
                            Consumer.OnConsumeComplete onConsumeComplete_0, net.named_data.jndn.encrypt.EncryptError.OnError onError_1,
                            Link link_2)
        {
            Interest interest = new Interest(contentName);

            // Copy the Link object since the passed link may become invalid.
            sendInterest(interest, 1, new Link(link_2), new Consumer.Anonymous_C6(this, onConsumeComplete_0, onError_1), onError_1);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Send an interest with the given name through the face with callbacks to
        /// handleCoveringKey and handleTimeout.
        /// </summary>
        ///
        /// <param name="interest">The interest to send.</param>
        /// <param name="timeSlot_0"></param>
        /// <param name="onEncryptedKeys_1"></param>
        private void sendKeyInterest(Interest interest, double timeSlot_0,
                                     Producer.OnEncryptedKeys onEncryptedKeys_1, net.named_data.jndn.encrypt.EncryptError.OnError onError_2)
        {
            OnData onKey = new Producer.Anonymous_C1(this, onError_2, onEncryptedKeys_1, timeSlot_0);

            OnTimeout onTimeout = new Producer.Anonymous_C0(this, onError_2, timeSlot_0, onEncryptedKeys_1);

            face_.expressInterest(interest, onKey, onTimeout);
        }
Exemplo n.º 15
0
 public Anonymous_C2(DecryptorV2 paramouter_DecryptorV2, Name kdkPrefix_0,
                     net.named_data.jndn.encrypt.EncryptError.OnError onError_1, DecryptorV2.ContentKey contentKey_2, Data ckData_3)
 {
     this.kdkPrefix         = kdkPrefix_0;
     this.onError           = onError_1;
     this.contentKey        = contentKey_2;
     this.ckData            = ckData_3;
     this.outer_DecryptorV2 = paramouter_DecryptorV2;
 }
Exemplo n.º 16
0
 public Anonymous_C4(Consumer paramouter_Consumer,
                     Consumer.OnPlainText onPlainText_0, Name dKeyName_1, net.named_data.jndn.encrypt.EncryptError.OnError onError_2,
                     EncryptedContent cKeyEncryptedContent_3)
 {
     this.onPlainText          = onPlainText_0;
     this.dKeyName             = dKeyName_1;
     this.onError              = onError_2;
     this.cKeyEncryptedContent = cKeyEncryptedContent_3;
     this.outer_Consumer       = paramouter_Consumer;
 }
Exemplo n.º 17
0
 public Anonymous_C5(Consumer paramouter_Consumer,
                     EncryptedContent dataEncryptedContent_0, net.named_data.jndn.encrypt.EncryptError.OnError onError_1,
                     Consumer.OnPlainText onPlainText_2, Name cKeyName_3)
 {
     this.dataEncryptedContent = dataEncryptedContent_0;
     this.onError        = onError_1;
     this.onPlainText    = onPlainText_2;
     this.cKeyName       = cKeyName_3;
     this.outer_Consumer = paramouter_Consumer;
 }
Exemplo n.º 18
0
 public Anonymous_C4(DecryptorV2 paramouter_DecryptorV2,
                     net.named_data.jndn.encrypt.EncryptError.OnError onError_0, int nTriesLeft_1, DecryptorV2.ContentKey contentKey_2,
                     Name ckName_3)
 {
     this.onError           = onError_0;
     this.nTriesLeft        = nTriesLeft_1;
     this.contentKey        = contentKey_2;
     this.ckName            = ckName_3;
     this.outer_DecryptorV2 = paramouter_DecryptorV2;
 }
Exemplo n.º 19
0
        /// <summary>
        /// Decrypt the data packet.
        /// </summary>
        ///
        /// <param name="data">The data packet.</param>
        /// <param name="onPlainText_0"></param>
        /// <param name="onError_1">This calls onError.onError(errorCode, message) for an error.</param>
        internal void decryptContent(Data data, Consumer.OnPlainText onPlainText_0,
                                     net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
        {
            // Get the encrypted content.
            EncryptedContent dataEncryptedContent_2 = new EncryptedContent();

            try {
                dataEncryptedContent_2.wireDecode(data.getContent());
            } catch (EncodingException ex) {
                try {
                    onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.InvalidEncryptedFormat,
                                      ex.Message);
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
                }
                return;
            }
            Name cKeyName_3 = dataEncryptedContent_2.getKeyLocator().getKeyName();

            // Check if the content key is already in the store.
            Blob cKey = (Blob)ILOG.J2CsMapping.Collections.Collections.Get(cKeyMap_, cKeyName_3);

            if (cKey != null)
            {
                decrypt(dataEncryptedContent_2, cKey, onPlainText_0, onError_1);
            }
            else
            {
                // Retrieve the C-KEY Data from the network.
                Name interestName = new Name(cKeyName_3);
                interestName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_FOR)
                .append(groupName_);
                Interest interest_4 = new Interest(interestName);

                // Prepare the callback functions.
                OnData onData_5 = new Consumer.Anonymous_C4(this, cKeyName_3, dataEncryptedContent_2, onPlainText_0,
                                                            onError_1);

                OnTimeout onTimeout = new Consumer.Anonymous_C3(this, onError_1, interest_4, onData_5);

                // Express the Interest.
                try {
                    face_.expressInterest(interest_4, onData_5, onTimeout);
                } catch (IOException ex_6) {
                    try {
                        onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.IOException,
                                          "expressInterest error: " + ex_6.Message);
                    } catch (Exception exception_7) {
                        logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception_7);
                    }
                }
            }
        }
Exemplo n.º 20
0
            public EncryptorFixture(bool shouldPublishData, net.named_data.jndn.encrypt.EncryptError.OnError onError)
            {
                this.storage_ = new InMemoryStorageRetaining();
                // Include the code here from the NAC unit-tests class
                // EncryptorStaticDataEnvironment instead of making it a base class.
                if (shouldPublishData)
                {
                    publishData();
                }

                face_      = new InMemoryStorageFace(storage_);
                validator_ = new ValidatorNull();
                encryptor_ = new EncryptorV2(new Name(
                                                 "/access/policy/identity/NAC/dataset"), new Name(
                                                 "/some/ck/prefix"), new SigningInfo(
                                                 net.named_data.jndn.security.SigningInfo.SignerType.SHA256), onError, validator_,
                                             keyChain_, face_);
            }
Exemplo n.º 21
0
        /// <summary>
        /// Decode encryptedBlob as an EncryptedContent and decrypt using keyBits.
        /// </summary>
        ///
        /// <param name="encryptedBlob">The encoded EncryptedContent to decrypt.</param>
        /// <param name="keyBits">The key value.</param>
        /// <param name="onPlainText_0"></param>
        /// <param name="onError_1">This calls onError.onError(errorCode, message) for an error.</param>
        private static void decrypt(Blob encryptedBlob, Blob keyBits,
                                    Consumer.OnPlainText onPlainText_0, net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
        {
            EncryptedContent encryptedContent = new EncryptedContent();

            try {
                encryptedContent.wireDecode(encryptedBlob);
            } catch (EncodingException ex) {
                try {
                    onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.InvalidEncryptedFormat,
                                      ex.Message);
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
                }
                return;
            }

            decrypt(encryptedContent, keyBits, onPlainText_0, onError_1);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Encrypt the given content with the content key that covers timeSlot, and
        /// update the data packet with the encrypted content and an appropriate data
        /// name.
        /// </summary>
        ///
        /// <param name="data">An empty Data object which is updated.</param>
        /// <param name="timeSlot_0">The time slot as milliseconds since Jan 1, 1970 UTC.</param>
        /// <param name="content">The content to encrypt.</param>
        /// <param name="onError_1">better error handling the callback should catch and properly handle any exceptions.</param>
        public void produce(Data data, double timeSlot_0, Blob content,
                            net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
        {
            // Get a content key.
            Name contentKeyName = createContentKey(timeSlot_0, null, onError_1);
            Blob contentKey     = database_.getContentKey(timeSlot_0);

            // Produce data.
            Name dataName = new Name(namespace_);

            dataName.append(net.named_data.jndn.encrypt.Schedule.toIsoString(timeSlot_0));

            data.setName(dataName);
            EncryptParams paras = new EncryptParams(net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.AesCbc,
                                                    16);

            net.named_data.jndn.encrypt.algo.Encryptor
            .encryptData(data, content, contentKeyName, contentKey, paras);
            keyChain_.sign(data);
        }
Exemplo n.º 23
0
        /// <summary>
        /// This is called from an expressInterest timeout to update the state of
        /// keyRequest. Re-express the interest if the number of retrials is less than
        /// the max limit.
        /// </summary>
        ///
        /// <param name="interest">The timed-out interest.</param>
        /// <param name="timeSlot_0">The time slot as milliseconds since Jan 1, 1970 UTC.</param>
        /// <param name="onEncryptedKeys_1">encrypted content key Data packets. If onEncryptedKeys is null, this does not use it.</param>
        internal void handleTimeout(Interest interest, double timeSlot_0,
                                    Producer.OnEncryptedKeys onEncryptedKeys_1, net.named_data.jndn.encrypt.EncryptError.OnError onError_2)
        {
            double timeCount = Math.Round(timeSlot_0, MidpointRounding.AwayFromZero);

            Producer.KeyRequest keyRequest = (Producer.KeyRequest)ILOG.J2CsMapping.Collections.Collections.Get(keyRequests_, timeCount);

            Name interestName = interest.getName();

            if ((int)(Int32)ILOG.J2CsMapping.Collections.Collections.Get(keyRequest.repeatAttempts, interestName) < maxRepeatAttempts_)
            {
                // Increase the retrial count.
                ILOG.J2CsMapping.Collections.Collections.Put(keyRequest.repeatAttempts, interestName, (int)(Int32)ILOG.J2CsMapping.Collections.Collections.Get(keyRequest.repeatAttempts, interestName) + 1);
                sendKeyInterest(interest, timeSlot_0, onEncryptedKeys_1, onError_2);
            }
            else
            {
                // No more retrials.
                updateKeyRequest(keyRequest, timeCount, onEncryptedKeys_1);
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Express an Interest to fetch the content packet with contentName, and
        /// decrypt it, fetching keys as needed.
        /// </summary>
        ///
        /// <param name="contentName">The name of the content packet.</param>
        /// <param name="onConsumeComplete_0">contentData is the fetched Data packet and result is the decrypted plain text Blob. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onError_1">better error handling the callback should catch and properly handle any exceptions.</param>
        public void consume(Name contentName,
                            Consumer.OnConsumeComplete onConsumeComplete_0, net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
        {
            Interest interest_2 = new Interest(contentName);

            // Prepare the callback functions.
            OnData onData_3 = new Consumer.Anonymous_C6(this, onConsumeComplete_0, onError_1);

            OnTimeout onTimeout = new Consumer.Anonymous_C5(this, onError_1, interest_2, onData_3);

            // Express the Interest.
            try {
                face_.expressInterest(interest_2, onData_3, onTimeout);
            } catch (IOException ex) {
                try {
                    onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.IOException,
                                      "expressInterest error: " + ex.Message);
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Create an Interest for <access-prefix>/KEK to retrieve the
        /// <access-prefix>/KEK/<key-id> KEK Data packet, and set kekData_.
        /// </summary>
        ///
        /// <param name="onReady_0"></param>
        /// <param name="onError_1">error string.</param>
        /// <param name="nTriesLeft_2">The number of retries for expressInterest timeouts.</param>
        internal void fetchKekAndPublishCkData(IRunnable onReady_0,
                                               net.named_data.jndn.encrypt.EncryptError.OnError onError_1, int nTriesLeft_2)
        {
            logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "Fetching KEK: {0}",
                        new Name(accessPrefix_).append(NAME_COMPONENT_KEK));

            if (kekPendingInterestId_ > 0)
            {
                onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.General,
                                  "fetchKekAndPublishCkData: There is already a kekPendingInterestId_");
                return;
            }

            try {
                kekPendingInterestId_ = face_.expressInterest(new Interest(
                                                                  new Name(accessPrefix_).append(NAME_COMPONENT_KEK))
                                                              .setMustBeFresh(true).setCanBePrefix(true), new EncryptorV2.Anonymous_C2(this, onReady_0, onError_1), new EncryptorV2.Anonymous_C1(this, onReady_0, onError_1, nTriesLeft_2), new EncryptorV2.Anonymous_C0(this, nTriesLeft_2, onReady_0, onError_1));
            } catch (Exception ex) {
                onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.General,
                                  "expressInterest error: " + ex);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Create an EncryptorV2 with the given parameters. This uses the face to
        /// register to receive Interests for the prefix {ckPrefix}/CK.
        /// </summary>
        ///
        /// <param name="accessPrefix"></param>
        /// <param name="ckPrefix"></param>
        /// <param name="ckDataSigningInfo"></param>
        /// <param name="onError_0">onError.onError(errorCode, message) where errorCode is from the EncryptError.ErrorCode enum, and message is an error string. The encrypt method will continue trying to retrieve the KEK until success (with each attempt separated by RETRY_DELAY_KEK_RETRIEVAL_MS) and onError may be called multiple times. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="validator">The validation policy to ensure correctness of the KEK.</param>
        /// <param name="keyChain">The KeyChain used to sign Data packets.</param>
        /// <param name="face">The Face that will be used to fetch the KEK and publish CK data.</param>
        public EncryptorV2(Name accessPrefix, Name ckPrefix,
                           SigningInfo ckDataSigningInfo, net.named_data.jndn.encrypt.EncryptError.OnError onError_0,
                           Validator validator, KeyChain keyChain, Face face)
        {
            this.kekData_ = null;
            this.storage_ = new InMemoryStorageRetaining();
            this.kekPendingInterestId_ = 0;
            // Copy the Name.
            accessPrefix_             = new Name(accessPrefix);
            ckPrefix_                 = new Name(ckPrefix);
            ckBits_                   = new byte[AES_KEY_SIZE];
            ckDataSigningInfo_        = new SigningInfo(ckDataSigningInfo);
            isKekRetrievalInProgress_ = false;
            onError_                  = onError_0;
            keyChain_                 = keyChain;
            face_ = face;

            regenerateCk();

            ckRegisteredPrefixId_ = face_.registerPrefix(
                new Name(ckPrefix).append(NAME_COMPONENT_CK),
                new EncryptorV2.Anonymous_C6(this), new EncryptorV2.Anonymous_C5());
        }
Exemplo n.º 27
0
        /// <summary>
        /// Decrypt the data packet.
        /// </summary>
        ///
        /// <param name="data">The data packet. This does not verify the packet.</param>
        /// <param name="onPlainText_0"></param>
        /// <param name="onError_1">This calls onError.onError(errorCode, message) for an error.</param>
        internal void decryptContent(Data data, Consumer.OnPlainText onPlainText_0,
                                     net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
        {
            // Get the encrypted content.
            EncryptedContent dataEncryptedContent_2 = new EncryptedContent();

            try {
                dataEncryptedContent_2.wireDecode(data.getContent());
            } catch (EncodingException ex) {
                try {
                    onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.InvalidEncryptedFormat,
                                      ex.Message);
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
                }
                return;
            }
            Name cKeyName_3 = dataEncryptedContent_2.getKeyLocator().getKeyName();

            // Check if the content key is already in the store.
            Blob cKey = (Blob)ILOG.J2CsMapping.Collections.Collections.Get(cKeyMap_, cKeyName_3);

            if (cKey != null)
            {
                decrypt(dataEncryptedContent_2, cKey, onPlainText_0, onError_1);
            }
            else
            {
                // Retrieve the C-KEY Data from the network.
                Name interestName = new Name(cKeyName_3);
                interestName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_FOR)
                .append(groupName_);
                Interest interest = new Interest(interestName);
                sendInterest(interest, 1, cKeyLink_, new Consumer.Anonymous_C5(this, dataEncryptedContent_2, onError_1, onPlainText_0,
                                                                               cKeyName_3), onError_1);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Express the interest, call verifyData for the fetched Data packet and call
        /// onVerified if verify succeeds. If verify fails, call
        /// onError.onError(ErrorCode.Validation, "verifyData failed"). If the interest
        /// times out, re-express nRetrials times. If the interest times out nRetrials
        /// times, or for a network Nack, call
        /// onError.onError(ErrorCode.DataRetrievalFailure, interest.getName().toUri()).
        /// </summary>
        ///
        /// <param name="interest">The Interest to express.</param>
        /// <param name="nRetrials_0">The number of retrials left after a timeout.</param>
        /// <param name="link_1">zero, don't use it.</param>
        /// <param name="onVerified_2"></param>
        /// <param name="onError_3">This calls onError.onError(errorCode, message) for an error.</param>
        internal void sendInterest(Interest interest, int nRetrials_0,
                                   Link link_1, OnVerified onVerified_2, net.named_data.jndn.encrypt.EncryptError.OnError onError_3)
        {
            // Prepare the callback functions.
            OnData onData = new Consumer.Anonymous_C2(this, onError_3, onVerified_2);

            OnNetworkNack onNetworkNack = new Consumer.Anonymous_C1(onError_3);

            OnTimeout onTimeout = new Consumer.Anonymous_C0(this, onError_3, onVerified_2, link_1, nRetrials_0);

            Interest request;

            if (link_1.getDelegations().size() == 0)
            {
                // We can use the supplied interest without copying.
                request = interest;
            }
            else
            {
                // Copy the supplied interest and add the Link.
                request = new Interest(interest);
                // This will use a cached encoding if available.
                request.setLinkWireEncoding(link_1.wireEncode());
            }

            try {
                face_.expressInterest(request, onData, onTimeout, onNetworkNack);
            } catch (IOException ex) {
                try {
                    onError_3.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.IOException,
                                      "expressInterest error: " + ex.Message);
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
                }
            }
        }
Exemplo n.º 29
0
 public Anonymous_C0(DecryptorV2.ContentKey contentKey_0, net.named_data.jndn.encrypt.EncryptError.OnError onError_1)
 {
     this.contentKey = contentKey_0;
     this.onError    = onError_1;
 }
Exemplo n.º 30
0
            public Anonymous_C6(Consumer paramouter_Consumer,
						Consumer.OnConsumeComplete  onConsumeComplete_0, net.named_data.jndn.encrypt.EncryptError.OnError  onError_1)
            {
                this.onConsumeComplete = onConsumeComplete_0;
                    this.onError = onError_1;
                    this.outer_Consumer = paramouter_Consumer;
            }
Exemplo n.º 31
0
            public Anonymous_C2(Producer paramouter_Producer, double timeSlot_0,
						Producer.OnEncryptedKeys  onEncryptedKeys_1, net.named_data.jndn.encrypt.EncryptError.OnError  onError_2)
            {
                this.timeSlot = timeSlot_0;
                    this.onEncryptedKeys = onEncryptedKeys_1;
                    this.onError = onError_2;
                    this.outer_Producer = paramouter_Producer;
            }
Exemplo n.º 32
0
            public Anonymous_C5(Consumer paramouter_Consumer, Interest interest_0,
						OnData onData_1, net.named_data.jndn.encrypt.EncryptError.OnError  onError_2)
            {
                this.interest = interest_0;
                    this.onData = onData_1;
                    this.onError = onError_2;
                    this.outer_Consumer = paramouter_Consumer;
            }
Exemplo n.º 33
0
            public Anonymous_C0(Consumer.OnPlainText  callerOnPlainText_0,
					Blob encryptedPayloadBlob_1, net.named_data.jndn.encrypt.EncryptError.OnError  onError_2)
            {
                this.callerOnPlainText = callerOnPlainText_0;
                this.encryptedPayloadBlob = encryptedPayloadBlob_1;
                this.onError = onError_2;
            }
Exemplo n.º 34
0
        /// <summary>
        /// Get the content key from the database_ and encrypt it for the timeSlot
        /// using encryptionKey.
        /// </summary>
        ///
        /// <param name="encryptionKey">The encryption key value.</param>
        /// <param name="eKeyName">The key name for the EncryptedContent.</param>
        /// <param name="timeSlot_0">The time slot as milliseconds since Jan 1, 1970 UTC.</param>
        /// <param name="onEncryptedKeys_1">encrypted content key Data packets. If onEncryptedKeys is null, this does not use it.</param>
        /// <returns>True if encryption succeeds, otherwise false.</returns>
        private bool encryptContentKey(Blob encryptionKey, Name eKeyName,
                                       double timeSlot_0, Producer.OnEncryptedKeys onEncryptedKeys_1, net.named_data.jndn.encrypt.EncryptError.OnError onError_2)
        {
            double timeCount = Math.Round(timeSlot_0, MidpointRounding.AwayFromZero);

            Producer.KeyRequest keyRequest = (Producer.KeyRequest)ILOG.J2CsMapping.Collections.Collections.Get(keyRequests_, timeCount);

            Name keyName = new Name(namespace_);

            keyName.append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_C_KEY);
            keyName.append(net.named_data.jndn.encrypt.Schedule.toIsoString(getRoundedTimeSlot(timeSlot_0)));

            Blob contentKey = database_.getContentKey(timeSlot_0);

            Data cKeyData = new Data();

            cKeyData.setName(keyName);
            EncryptParams paras = new EncryptParams(net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.RsaOaep);

            try {
                net.named_data.jndn.encrypt.algo.Encryptor.encryptData(cKeyData, contentKey, eKeyName,
                                                                       encryptionKey, paras);
            } catch (Exception ex) {
                try {
                    onError_2.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.EncryptionFailure, ex.Message);
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
                }
                return(false);
            }

            keyChain_.sign(cKeyData);
            ILOG.J2CsMapping.Collections.Collections.Add(keyRequest.encryptedKeys, cKeyData);
            updateKeyRequest(keyRequest, timeCount, onEncryptedKeys_1);
            return(true);
        }
Exemplo n.º 35
0
            public Anonymous_C4(Consumer paramouter_Consumer, Name cKeyName_0,
						net.named_data.jndn.encrypt.EncryptError.OnError  onError_1, Consumer.OnPlainText  onPlainText_2,
						EncryptedContent dataEncryptedContent_3)
            {
                this.cKeyName = cKeyName_0;
                    this.onError = onError_1;
                    this.onPlainText = onPlainText_2;
                    this.dataEncryptedContent = dataEncryptedContent_3;
                    this.outer_Consumer = paramouter_Consumer;
            }
Exemplo n.º 36
0
            public Anonymous_C2(Consumer paramouter_Consumer, net.named_data.jndn.encrypt.EncryptError.OnError  onError_0,
						Consumer.OnPlainText  onPlainText_1, Name dKeyName_2,
						EncryptedContent cKeyEncryptedContent_3)
            {
                this.onError = onError_0;
                    this.onPlainText = onPlainText_1;
                    this.dKeyName = dKeyName_2;
                    this.cKeyEncryptedContent = cKeyEncryptedContent_3;
                    this.outer_Consumer = paramouter_Consumer;
            }