コード例 #1
0
        /// <summary>
        /// Extract the signature information from the interest name.
        /// </summary>
        ///
        /// <param name="interest">The interest whose signature is needed.</param>
        /// <param name="wireFormat"></param>
        /// <returns>The Signature object, or null if can't decode.</returns>
        private static Signature extractSignature(Interest interest,
                                                  WireFormat wireFormat)
        {
            if (interest.getName().size() < 2)
            {
                return(null);
            }

            try {
                return(wireFormat.decodeSignatureInfoAndValue(interest.getName()
                                                              .get(-2).getValue().buf(), interest.getName().get(-1)
                                                              .getValue().buf(), false));
            } catch (EncodingException ex) {
                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Use wireFormat.decodeSignatureInfoAndValue to decode the last two name
        /// components of the signed interest. Look in the IdentityStorage for the
        /// public key with the name in the KeyLocator (if available) and use it to
        /// verify the interest. If the public key can't be found, call onVerifyFailed.
        /// </summary>
        ///
        /// <param name="interest">The interest with the signature to check.</param>
        /// <param name="stepCount"></param>
        /// <param name="onVerified">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="onVerifyFailed">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>
        /// <returns>null for no further step for looking up a certificate chain.</returns>
        public override ValidationRequest checkVerificationPolicy(Interest interest,
                                                                  int stepCount, OnVerifiedInterest onVerified,
                                                                  OnVerifyInterestFailed onVerifyFailed, WireFormat wireFormat)
        {
            // Decode the last two name components of the signed interest
            net.named_data.jndn.Signature signature;
            try {
                signature = wireFormat.decodeSignatureInfoAndValue(interest
                                                                   .getName().get(-2).getValue().buf(), interest.getName()
                                                                   .get(-1).getValue().buf());
            } catch (EncodingException ex) {
                logger_.log(
                    ILOG.J2CsMapping.Util.Logging.Level.INFO,
                    "Cannot decode the signed interest SignatureInfo and value",
                    ex);
                try {
                    onVerifyFailed.onVerifyInterestFailed(interest);
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onVerifyInterestFailed",
                                exception);
                }
                return(null);
            }

            // wireEncode returns the cached encoding if available.
            if (verify(signature, interest.wireEncode(wireFormat)))
            {
                try {
                    onVerified.onVerifiedInterest(interest);
                } catch (Exception ex_0) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onVerifiedInterest", ex_0);
                }
            }
            else
            {
                try {
                    onVerifyFailed.onVerifyInterestFailed(interest);
                } catch (Exception ex_1) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onVerifyInterestFailed", ex_1);
                }
            }

            // No more steps, so return a null ValidationRequest.
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Use wireFormat.decodeSignatureInfoAndValue to decode the last two name
        /// components of the signed interest. Look in the IdentityStorage or PibImpl for the
        /// public key with the name in the KeyLocator (if available) and use it to
        /// verify the interest. If the public key can't be found, call
        /// onValidationFailed.onInterestValidationFailed.
        /// </summary>
        ///
        /// <param name="interest">The interest with the signature to check.</param>
        /// <param name="stepCount"></param>
        /// <param name="onVerified">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="onValidationFailed">onValidationFailed.onInterestValidationFailed(interest, reason). 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>
        /// <returns>null for no further step for looking up a certificate chain.</returns>
        public override ValidationRequest checkVerificationPolicy(Interest interest,
                                                                  int stepCount, OnVerifiedInterest onVerified,
                                                                  OnInterestValidationFailed onValidationFailed, WireFormat wireFormat)
        {
            if (interest.getName().size() < 2)
            {
                try {
                    onValidationFailed.onInterestValidationFailed(interest,
                                                                  "The signed interest has less than 2 components: "
                                                                  + interest.getName().toUri());
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE,
                                "Error in onInterestValidationFailed", exception);
                }
                return(null);
            }

            // Decode the last two name components of the signed interest
            Signature signature;

            try {
                signature = wireFormat.decodeSignatureInfoAndValue(interest
                                                                   .getName().get(-2).getValue().buf(), interest.getName()
                                                                   .get(-1).getValue().buf(), false);
            } catch (EncodingException ex) {
                logger_.log(
                    ILOG.J2CsMapping.Util.Logging.Level.INFO,
                    "Cannot decode the signed interest SignatureInfo and value",
                    ex);
                try {
                    onValidationFailed.onInterestValidationFailed(interest,
                                                                  "Error decoding the signed interest signature: " + ex);
                } catch (Exception exception_0) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE,
                                "Error in onInterestValidationFailed", exception_0);
                }
                return(null);
            }

            String[] failureReason = new String[] { "unknown" };
            // wireEncode returns the cached encoding if available.
            if (verify(signature, interest.wireEncode(wireFormat), failureReason))
            {
                try {
                    onVerified.onVerifiedInterest(interest);
                } catch (Exception ex_1) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onVerifiedInterest", ex_1);
                }
            }
            else
            {
                try {
                    onValidationFailed.onInterestValidationFailed(interest,
                                                                  failureReason[0]);
                } catch (Exception ex_2) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE,
                                "Error in onInterestValidationFailed", ex_2);
                }
            }

            // No more steps, so return a null ValidationRequest.
            return(null);
        }