@SuppressWarnings("unchecked") @Override public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException { LOG.log(POILogger.DEBUG, "select key"); if (null == keyInfo) { throw new KeySelectorException("no ds:KeyInfo present"); } List<XMLStructure> keyInfoContent = keyInfo.getContent(); certChain.clear(); for (XMLStructure keyInfoStructure : keyInfoContent) { if (!(keyInfoStructure instanceof X509Data)) { continue; } X509Data x509Data = (X509Data) keyInfoStructure; List<?> x509DataList = x509Data.getContent(); for (Object x509DataObject : x509DataList) { if (!(x509DataObject instanceof X509Certificate)) { continue; } X509Certificate certificate = (X509Certificate) x509DataObject; LOG.log(POILogger.DEBUG, "certificate", certificate.getSubjectX500Principal()); certChain.add(certificate); } } if (certChain.isEmpty()) { throw new KeySelectorException("No key found!"); } return this; }
/** * A utility function to suppress casting warnings. * @param ki * @return the content of a KeyInfo Object */ @SuppressWarnings("unchecked") public static List<XMLStructure> getContent(KeyInfo ki) { return ki.getContent(); }
public X509Data getX509Data() throws MarshalException { KeyInfo keyInfo = getKeyInfo(); if (keyInfo != null) { for (Object o1 : keyInfo.getContent()) { if (o1 instanceof X509Data) { return (X509Data) o1; } } } return null; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof KeyInfo)) { return false; } KeyInfo oki = (KeyInfo)o; boolean idsEqual = id == null ? oki.getId() == null : id.equals(oki.getId()); return keyInfoTypes.equals(oki.getContent()) && idsEqual; }
/** * Get the KeyValue object from the KeyInfo DOM element if it exists */ private KeyValue getKeyValue( Element keyInfoElement ) throws MarshalException { XMLStructure keyInfoStructure = new DOMStructure(keyInfoElement); KeyInfo keyInfo = keyInfoFactory.unmarshalKeyInfo(keyInfoStructure); List<?> list = keyInfo.getContent(); for (int i = 0; i < list.size(); i++) { XMLStructure xmlStructure = (XMLStructure) list.get(i); if (xmlStructure instanceof KeyValue) { return (KeyValue)xmlStructure; } } return null; }
/** * Get the KeyValue object from the KeyInfo DOM element if it exists */ private KeyValue getKeyValue( Element keyInfoElement ) throws MarshalException { XMLStructure keyInfoStructure = new DOMStructure(keyInfoElement); KeyInfo keyInfo = keyInfoFactory.unmarshalKeyInfo(keyInfoStructure); List<?> list = keyInfo.getContent(); for (int i = 0; i < list.size(); i++) { XMLStructure xmlStructure = (XMLStructure) list.get(i); if (xmlStructure instanceof KeyValue) { return (KeyValue)xmlStructure; } } return null; }
/** * Get the KeyValue object from the KeyInfo DOM element if it exists */ public static KeyValue getKeyValue(Element keyInfoElement, XMLSignatureFactory signatureFactory) throws MarshalException { XMLStructure keyInfoStructure = new DOMStructure(keyInfoElement); KeyInfoFactory keyInfoFactory = signatureFactory.getKeyInfoFactory(); KeyInfo keyInfo = keyInfoFactory.unmarshalKeyInfo(keyInfoStructure); List<?> list = keyInfo.getContent(); for (int i = 0; i < list.size(); i++) { XMLStructure xmlStructure = (XMLStructure) list.get(i); if (xmlStructure instanceof KeyValue) { return (KeyValue)xmlStructure; } } return null; }
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException { Iterator ki = keyInfo.getContent().iterator(); while (ki.hasNext()) { XMLStructure info = (XMLStructure) ki.next(); if (!(info instanceof X509Data)) continue; X509Data x509Data = (X509Data) info; Iterator xi = x509Data.getContent().iterator(); while (xi.hasNext()) { Object o = xi.next(); if (!(o instanceof X509Certificate)) continue; this.certificate = (X509Certificate) o; final PublicKey key = certificate.getPublicKey(); // Make sure the algorithm is compatible with the method. if (algEquals(method.getAlgorithm(), key.getAlgorithm())) return new KeySelectorResult() { public Key getKey() { return key; } }; } } throw new KeySelectorException("No key found!"); }
KeyInfo keyInfo = signature.getKeyInfo(); Iterator iter = keyInfo.getContent().iterator(); X509CertImpl certImpl = null; while (iter.hasNext()) {
public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException { Iterator ki = keyInfo.getContent().iterator(); while (ki.hasNext()) { XMLStructure info = (XMLStructure) ki.next(); if (!(info instanceof X509Data)) continue; X509Data x509Data = (X509Data) info; Iterator xi = x509Data.getContent().iterator(); while (xi.hasNext()) { Object o = xi.next(); if (!(o instanceof X509Certificate)) continue; final PublicKey key = ((X509Certificate)o).getPublicKey(); // Make sure the algorithm is compatible // with the method. if (algEquals(method.getAlgorithm(), key.getAlgorithm())) { return new KeySelectorResult() { public Key getKey() { return key; } }; } } } throw new KeySelectorException("No key found!"); }
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException { @SuppressWarnings("rawtypes") Iterator ki = keyInfo.getContent().iterator(); while (ki.hasNext()) { XMLStructure info = (XMLStructure) ki.next(); if (!(info instanceof X509Data)) continue; X509Data x509Data = (X509Data) info; @SuppressWarnings("rawtypes") Iterator xi = x509Data.getContent().iterator(); while (xi.hasNext()) { Object o = xi.next(); if (!(o instanceof X509Certificate)) continue; final PublicKey key = ((X509Certificate)o).getPublicKey(); // Make sure the algorithm is compatible // with the method. if (algEquals(method.getAlgorithm(), key.getAlgorithm())) { return new KeySelectorResult() { public Key getKey() { return key; } }; } } } throw new KeySelectorException("No key found!"); }
@Override public KeySelectorResult select(final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context) throws KeySelectorException { for (final Object object : keyInfo.getContent()) { final XMLStructure info = (XMLStructure) object; if (info instanceof X509Data) { final X509Data x509Data = (X509Data) info; for (final Object certificado : x509Data.getContent()) { if (certificado instanceof X509Certificate) { final X509Certificate x509Certificate = (X509Certificate) certificado; if (this.algEquals(method.getAlgorithm(), x509Certificate.getPublicKey().getAlgorithm())) { return x509Certificate::getPublicKey; } } } } } throw new KeySelectorException("Nao foi localizada a chave do certificado."); }
final XMLCryptoContext aContext) throws KeySelectorException for (final Object aKeyInfoElement : aKeyInfo.getContent ())
final XMLCryptoContext aContext) throws KeySelectorException for (final Object aKeyInfoElement : aKeyInfo.getContent ())
@SuppressWarnings("unchecked") @Override public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException { LOG.log(POILogger.DEBUG, "select key"); if (null == keyInfo) { throw new KeySelectorException("no ds:KeyInfo present"); } List<XMLStructure> keyInfoContent = keyInfo.getContent(); certChain.clear(); for (XMLStructure keyInfoStructure : keyInfoContent) { if (!(keyInfoStructure instanceof X509Data)) { continue; } X509Data x509Data = (X509Data) keyInfoStructure; List<?> x509DataList = x509Data.getContent(); for (Object x509DataObject : x509DataList) { if (!(x509DataObject instanceof X509Certificate)) { continue; } X509Certificate certificate = (X509Certificate) x509DataObject; LOG.log(POILogger.DEBUG, "certificate", certificate.getSubjectX500Principal()); certChain.add(certificate); } } if (certChain.isEmpty()) { throw new KeySelectorException("No key found!"); } return this; }
List<?> list = keyInfo.getContent();
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException { if (keyInfo == null) throw new KeySelectorException("Null KeyInfo model!"); SignatureMethod signMethod = (SignatureMethod) method; List list = keyInfo.getContent(); for (int i = 0; i < list.size(); i++) { XMLStructure xmlStructure = (XMLStructure) list.get(i); if (xmlStructure instanceof KeyValue) { PublicKey pk = null; try { pk = ((KeyValue)xmlStructure).getPublicKey(); } catch (KeyException ke) { throw new KeySelectorException(ke); } // Check if algorithm is compatible with Signature method if (algEquals(signMethod.getAlgorithm(), pk.getAlgorithm())) return new KeySelectorResultImpl(pk); } } throw new KeySelectorException("No KeyValue element found!"); }
public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException { if (keyInfo == null) { throw new KeySelectorException("Null KeyInfo object!"); } SignatureMethod sm = (SignatureMethod) method; List list = keyInfo.getContent(); for (int i = 0; i < list.size(); i++) { XMLStructure xmlStructure = (XMLStructure) list.get(i); if (xmlStructure instanceof KeyValue) { PublicKey pk = null; try { pk = ((KeyValue) xmlStructure).getPublicKey(); } catch (KeyException ke) { throw new KeySelectorException(ke); } // make sure algorithm is compatible with method if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) { return new SimpleKeySelectorResult(pk); } } } throw new KeySelectorException("No KeyValue element found!"); }
@Override public KeySelectorResult select ( final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context ) throws KeySelectorException { if ( keyInfo == null ) { throw new KeySelectorException ( "Null KeyInfo object!" ); } final SignatureMethod sm = (SignatureMethod)method; final List<?> list = keyInfo.getContent (); for ( final Object l : list ) { final XMLStructure xmlStructure = (XMLStructure)l; if ( xmlStructure instanceof X509Data ) { for ( final Object o : ( (X509Data)xmlStructure ).getContent () ) { KeySelectorResult result = null; if ( o instanceof X509Certificate ) { result = findPublicKey ( (X509Certificate)o, sm ); } if ( result != null ) { return result; } } } } throw new KeySelectorException ( "No KeyValue element found!" ); }
@Override public KeySelectorResult select ( final KeyInfo keyInfo, final KeySelector.Purpose purpose, final AlgorithmMethod method, final XMLCryptoContext context ) throws KeySelectorException { if ( keyInfo == null ) { throw new KeySelectorException ( "Null KeyInfo object!" ); } final SignatureMethod sm = (SignatureMethod)method; final List<?> list = keyInfo.getContent (); for ( final Object l : list ) { final XMLStructure xmlStructure = (XMLStructure)l; if ( xmlStructure instanceof X509Data ) { for ( final Object o : ( (X509Data)xmlStructure ).getContent () ) { KeySelectorResult result = null; if ( o instanceof X509Certificate ) { result = findPublicKey ( (X509Certificate)o, sm ); } if ( result != null ) { return result; } } } } throw new KeySelectorException ( "No KeyValue element found!" ); }