public void verifyInterest(Interest interest, OnVerifiedInterest onVerified, OnVerifyInterestFailed onVerifyFailed, int stepCount) { ILOG.J2CsMapping.Util.Logging.Logger.getLogger(this.GetType().FullName).log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "Enter Verify"); if (policyManager_.requireVerify(interest)) { ValidationRequest nextStep = policyManager_ .checkVerificationPolicy(interest, stepCount, onVerified, onVerifyFailed); if (nextStep != null) { KeyChain.VerifyCallbacksForVerifyInterest callbacks = new KeyChain.VerifyCallbacksForVerifyInterest( this, nextStep, nextStep.retry_, onVerifyFailed, interest); try { face_.expressInterest(nextStep.interest_, callbacks, callbacks); } catch (IOException ex) { try { onVerifyFailed.onVerifyInterestFailed(interest); } catch (Exception exception) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onVerifyInterestFailed", exception); } } } } else if (policyManager_.skipVerifyAndTrust(interest)) { 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); } } }
/// <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); }