/** * @return the key factory (thread-local) */ public KeyInfoFactory getKeyInfoFactory() { KeyInfoFactory keyFac = keyInfoFactory.get(); if (keyFac == null) { keyFac = KeyInfoFactory.getInstance("DOM", getProvider()); setKeyInfoFactory(keyFac); } return keyFac; }
@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; }
KeyValue keyValue; try { keyValue = keyInfoFactory.newKeyValue(signingCertificate.getPublicKey()); } catch (KeyException e) { throw new RuntimeException("key exception: " + e.getMessage(), e); x509DataObjects.add(keyInfoFactory.newX509IssuerSerial( signingCertificate.getIssuerX500Principal().toString(), signingCertificate.getSerialNumber())); X509Data x509Data = keyInfoFactory.newX509Data(x509DataObjects); keyInfoContent.add(x509Data); KeyInfo keyInfo = keyInfoFactory.newKeyInfo(keyInfoContent); DOMKeyInfo domKeyInfo = (DOMKeyInfo)keyInfo;
KeyValue kv = kif.newKeyValue(pub); KeyInfo ki = kif.newKeyInfo(Collections.singletonList(kv)); XMLSignature signature = fac.newXMLSignature(si, ki); signature.sign(dsc);
/** * 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; }
/** * 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 X509Certificate getX509Certificate() throws MarshalException { X509Data x509Data = getX509Data(); if (x509Data != null) { for (Object o1 : x509Data.getContent()) { if (o1 instanceof X509Certificate) { return (X509Certificate) o1; } } } return null; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof X509IssuerSerial)) { return false; } X509IssuerSerial ois = (X509IssuerSerial)obj; return issuerName.equals(ois.getIssuerName()) && serialNumber.equals(ois.getSerialNumber()); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof KeyName)) { return false; } KeyName okn = (KeyName)obj; return name.equals(okn.getName()); }
private static KeyInfo generateKeyInfo(PublicKey publicKey) throws GeneralSecurityException { KeyInfoFactory kif = new DOMKeyInfoFactory(); KeyValue kv = kif.newKeyValue(publicKey); return kif.newKeyInfo(Collections.singletonList(kv)); }
/** * 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; }
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; }
private void init() { // Try to install the Santuario Provider - fall back to the JDK provider if this does // not work try { signatureFactory = XMLSignatureFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { signatureFactory = XMLSignatureFactory.getInstance("DOM"); } try { keyInfoFactory = KeyInfoFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { keyInfoFactory = KeyInfoFactory.getInstance("DOM"); } }
/** * Marshals a {@link KeyName}. * * @param xwriter * @param keyName * @param dsPrefix */ public static void marshalKeyName(XmlWriter xwriter, KeyName keyName, String dsPrefix) { xwriter.writeTextElement(dsPrefix, "KeyName", XMLSignature.XMLNS, keyName.getName()); }
public SignatureProcessor() { // Try to install the Santuario Provider - fall back to the JDK provider if this does // not work try { signatureFactory = XMLSignatureFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { signatureFactory = XMLSignatureFactory.getInstance("DOM"); } try { keyInfoFactory = KeyInfoFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { keyInfoFactory = KeyInfoFactory.getInstance("DOM"); } }
public SignatureProcessor() { // Try to install the Santuario Provider - fall back to the JDK provider if this does // not work try { signatureFactory = XMLSignatureFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { signatureFactory = XMLSignatureFactory.getInstance("DOM"); } try { keyInfoFactory = KeyInfoFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { keyInfoFactory = KeyInfoFactory.getInstance("DOM"); } }
private void init() { // Try to install the Santuario Provider - fall back to the JDK provider if this does // not work try { signatureFactory = XMLSignatureFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { signatureFactory = XMLSignatureFactory.getInstance("DOM"); } try { keyInfoFactory = KeyInfoFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { keyInfoFactory = KeyInfoFactory.getInstance("DOM"); } }
private void init() { // Try to install the Santuario Provider - fall back to the JDK provider if this does // not work try { signatureFactory = XMLSignatureFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { signatureFactory = XMLSignatureFactory.getInstance("DOM"); } try { keyInfoFactory = KeyInfoFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { keyInfoFactory = KeyInfoFactory.getInstance("DOM"); } }
private void init() { // Try to install the Santuario Provider - fall back to the JDK provider if this does // not work try { signatureFactory = XMLSignatureFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { signatureFactory = XMLSignatureFactory.getInstance("DOM"); } try { keyInfoFactory = KeyInfoFactory.getInstance("DOM", "ApacheXMLDSig"); } catch (NoSuchProviderException ex) { keyInfoFactory = KeyInfoFactory.getInstance("DOM"); } }
/** * @return the key factory (thread-local) */ public KeyInfoFactory getKeyInfoFactory() { KeyInfoFactory keyFac = keyInfoFactory.get(); if (keyFac == null) { keyFac = KeyInfoFactory.getInstance("DOM", getProvider()); setKeyInfoFactory(keyFac); } return keyFac; }