manifest.java

来自「Mobile 应用程序使用 Java Micro Edition (Java M」· Java 代码 · 共 560 行 · 第 1/2 页

JAVA
560
字号
    * @see com.sun.org.apache.xml.internal.security.signature.Reference#verify    * @see com.sun.org.apache.xml.internal.security.signature.SignedInfo#verify(boolean)    * @see com.sun.org.apache.xml.internal.security.signature.MissingResourceFailureException    * @throws XMLSecurityException    */   public boolean verifyReferences(boolean followManifests)           throws MissingResourceFailureException, XMLSecurityException {      if (_referencesEl==null) {        this._referencesEl =              XMLUtils.selectDsNodes(this._constructionElement.getFirstChild(),                         Constants._TAG_REFERENCE);      }   	  if (true) {   	  	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "verify " +_referencesEl.length + " References");        if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "I am " + (followManifests                           ? ""                           : "not") + " requested to follow nested Manifests");      }      boolean verify = true;      if (_referencesEl.length==0) {         throw new XMLSecurityException("empty");      }      this.verificationResults =         new boolean[_referencesEl.length];      for (int i =              0; i < this._referencesEl.length; i++) {         Reference currentRef =            new Reference(_referencesEl[i], this._baseURI, this);         this._references.set(i, currentRef);         /* if only one item does not verify, the whole verification fails */         try {            boolean currentRefVerified = currentRef.verify();            this.setVerificationResult(i, currentRefVerified);            if (!currentRefVerified) {               verify = false;            }            if (true)            	if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "The Reference has Type " + currentRef.getType());            // was verification successful till now and do we want to verify the Manifest?            if (verify && followManifests                    && currentRef.typeIsReferenceToManifest()) {               if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "We have to follow a nested Manifest");                try {                  XMLSignatureInput signedManifestNodes =                    currentRef.dereferenceURIandPerformTransforms(null);                  Set nl = signedManifestNodes.getNodeSet();                  Manifest referencedManifest = null;                  Iterator nlIterator = nl.iterator();                  findManifest: while (nlIterator.hasNext()) {                     Node n = (Node) nlIterator.next();                     if ((n.getNodeType() == Node.ELEMENT_NODE) && ((Element) n)                             .getNamespaceURI()                             .equals(Constants.SignatureSpecNS) && ((Element) n)                             .getLocalName().equals(Constants._TAG_MANIFEST)) {                        try {                           referencedManifest =                              new Manifest((Element) n,                                           signedManifestNodes.getSourceURI());                           break findManifest;                        } catch (XMLSecurityException ex) {                           // Hm, seems not to be a ds:Manifest                        }                     }                  }                  if (referencedManifest == null) {                     // The Reference stated that it points to a ds:Manifest                     // but we did not find a ds:Manifest in the signed area                     throw new MissingResourceFailureException("empty",                                                               currentRef);                  }                  referencedManifest._perManifestResolvers =                     this._perManifestResolvers;                  referencedManifest._resolverProperties =                     this._resolverProperties;                  boolean referencedManifestValid =                     referencedManifest.verifyReferences(followManifests);                  if (!referencedManifestValid) {                     verify = false;                     log.log(java.util.logging.Level.WARNING, "The nested Manifest was invalid (bad)");                  } else {                     if (log.isLoggable(java.util.logging.Level.FINE))                                     log.log(java.util.logging.Level.FINE, "The nested Manifest was valid (good)");                  }               } catch (IOException ex) {                  throw new ReferenceNotInitializedException("empty", ex);               } catch (ParserConfigurationException ex) {                  throw new ReferenceNotInitializedException("empty", ex);               } catch (SAXException ex) {                  throw new ReferenceNotInitializedException("empty", ex);               }            }         } catch (ReferenceNotInitializedException ex) {            Object exArgs[] = { currentRef.getURI() };            throw new MissingResourceFailureException(               "signature.Verification.Reference.NoInput", exArgs, ex,               currentRef);         }      }      return verify;   }   /**    * Method setVerificationResult    *    * @param index    * @param verify    */   private void setVerificationResult(int index, boolean verify)   {      if (this.verificationResults == null) {         this.verificationResults = new boolean[this.getLength()];      }      this.verificationResults[index] = verify;   }   /**    * After verifying a {@link Manifest} or a {@link SignedInfo} using the    * {@link Manifest#verifyReferences()} or {@link SignedInfo#verify()} methods,    * the individual results can be retrieved with this method.    *    * @param index an index of into a {@link Manifest} or a {@link SignedInfo}    * @return the results of reference validation at the specified index    * @throws XMLSecurityException    */   public boolean getVerificationResult(int index) throws XMLSecurityException {      if ((index < 0) || (index > this.getLength() - 1)) {         Object exArgs[] = { Integer.toString(index),                             Integer.toString(this.getLength()) };         Exception e =            new IndexOutOfBoundsException(I18n               .translate("signature.Verification.IndexOutOfBounds", exArgs));         throw new XMLSecurityException("generic.EmptyMessage", e);      }      if (this.verificationResults == null) {         try {            this.verifyReferences();         } catch (Exception ex) {            throw new XMLSecurityException("generic.EmptyMessage", ex);         }      }      return this.verificationResults[index];   }   /**    * Adds Resource Resolver for retrieving resources at specified <code>URI</code> attribute in <code>reference</code> element    *    * @param resolver {@link ResourceResolver} can provide the implemenatin subclass of {@link ResourceResolverSpi} for retrieving resource.    */   public void addResourceResolver(ResourceResolver resolver) {      if (resolver != null) {         this._perManifestResolvers.add(resolver);      }   }   /**    * Adds Resource Resolver for retrieving resources at specified <code>URI</code> attribute in <code>reference</code> element    *    * @param resolverSpi the implemenatin subclass of {@link ResourceResolverSpi} for retrieving resource.    */   public void addResourceResolver(ResourceResolverSpi resolverSpi) {      if (resolverSpi != null) {         this._perManifestResolvers.add(new ResourceResolver(resolverSpi));      }   }   /**    * Used to pass parameters like proxy servers etc to the ResourceResolver    * implementation.    *    * @param key the key    * @param value the value    */   public void setResolverProperty(String key, String value) {      this._resolverProperties.put(key, value);   }   /**    * Returns the value at specified key    *    * @param key the key    * @return the value    */   public String getResolverProperty(String key) {      return (String) this._resolverProperties.get(key);   }   /**    * Method getSignedContentItem    *    * @param i    * @return The signed content of the i reference.    *    * @throws XMLSignatureException    */   public byte[] getSignedContentItem(int i) throws XMLSignatureException {      try {         return this.getReferencedContentAfterTransformsItem(i).getBytes();      } catch (IOException ex) {         throw new XMLSignatureException("empty", ex);      } catch (CanonicalizationException ex) {         throw new XMLSignatureException("empty", ex);      } catch (InvalidCanonicalizerException ex) {         throw new XMLSignatureException("empty", ex);      } catch (XMLSecurityException ex) {         throw new XMLSignatureException("empty", ex);      }   }   /**    * Method getReferencedContentPriorTransformsItem    *    * @param i    * @return The contents before transformation of the reference i.    * @throws XMLSecurityException    */   public XMLSignatureInput getReferencedContentBeforeTransformsItem(int i)           throws XMLSecurityException {      return this.item(i).getContentsBeforeTransformation();   }   /**    * Method getReferencedContentAfterTransformsItem    *    * @param i    * @return The contents after transformation of the reference i.    * @throws XMLSecurityException    */   public XMLSignatureInput getReferencedContentAfterTransformsItem(int i)           throws XMLSecurityException {      return this.item(i).getContentsAfterTransformation();   }   /**    * Method getSignedContentLength    *    * @return The nu,ber of references contained in this reference.    */   public int getSignedContentLength() {      return this.getLength();   }   /**    * Method getBaseLocalName    *    * @inheritDoc    */   public String getBaseLocalName() {      return Constants._TAG_MANIFEST;   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?