private void testAndSetInvocation() throws XMLSecurityException { if (invoked) { throw new XMLSecurityException("stax.recursiveKeyReference"); } invoked = true; }
@Override protected InputStream handleXOPInclude(InputProcessorChain inputProcessorChain, EncryptedDataType encryptedDataType, String href, Cipher cipher, InboundSecurityToken inboundSecurityToken) throws XMLSecurityException { throw new XMLSecurityException("errorMessages.NotYetImplementedException"); }
@Override public void engineInitSign(Key signingKey) throws XMLSecurityException { try { mac.init(signingKey); } catch (InvalidKeyException e) { throw new XMLSecurityException(e); } }
@Override public void engineUpdate(byte[] input) throws XMLSecurityException { try { signature.update(input); } catch (SignatureException e) { throw new XMLSecurityException(e); } }
@Override public void engineInitSign(Key signingKey, AlgorithmParameterSpec algorithmParameterSpec) throws XMLSecurityException { try { signature.initSign((PrivateKey) signingKey); } catch (InvalidKeyException e) { throw new XMLSecurityException(e); } }
@Override public void engineUpdate(byte input) throws XMLSecurityException { try { signature.update(input); } catch (SignatureException e) { throw new XMLSecurityException(e); } }
@Override public void engineInitSign(Key signingKey, SecureRandom secureRandom) throws XMLSecurityException { try { mac.init(signingKey); } catch (InvalidKeyException e) { throw new XMLSecurityException(e); } }
@Override public void engineInitVerify(Key verificationKey) throws XMLSecurityException { try { mac.init(verificationKey); } catch (InvalidKeyException e) { throw new XMLSecurityException(e); } }
@Override public void engineInitSign(Key signingKey) throws XMLSecurityException { try { signature.initSign((PrivateKey) signingKey); } catch (InvalidKeyException e) { throw new XMLSecurityException(e); } }
@Override public void engineInitSign(Key signingKey, SecureRandom secureRandom) throws XMLSecurityException { try { signature.initSign((PrivateKey) signingKey, secureRandom); } catch (InvalidKeyException e) { throw new XMLSecurityException(e); } }
@Override public void engineInitVerify(Key verificationKey) throws XMLSecurityException { try { signature.initVerify((PublicKey) verificationKey); } catch (InvalidKeyException e) { throw new XMLSecurityException(e); } }
private byte[] generateDigest(byte[] inputBytes) throws XMLSecurityException { try { return MessageDigest.getInstance("SHA-1").digest(inputBytes); } catch (NoSuchAlgorithmException e) { throw new XMLSecurityException(e); } }
public static void createKeyValueTokenStructure(AbstractOutputProcessor abstractOutputProcessor, OutputProcessorChain outputProcessorChain, X509Certificate[] x509Certificates) throws XMLStreamException, XMLSecurityException { if (x509Certificates == null || x509Certificates.length == 0) { throw new XMLSecurityException("stax.signature.publicKeyOrCertificateMissing"); } X509Certificate x509Certificate = x509Certificates[0]; PublicKey publicKey = x509Certificate.getPublicKey(); createKeyValueTokenStructure(abstractOutputProcessor, outputProcessorChain, publicKey); }
@Override public void doFinal(InputProcessorChain inputProcessorChain) throws XMLStreamException, XMLSecurityException { if (!signatureElementFound && !encryptedDataElementFound) { throw new XMLSecurityException("stax.unsecuredMessage"); } super.doFinal(inputProcessorChain); }
@Override public void engineSetParameter(AlgorithmParameterSpec params) throws XMLSecurityException { try { signature.setParameter(params); } catch (InvalidAlgorithmParameterException e) { throw new XMLSecurityException(e); } } }
public FinalOutputProcessor(OutputStream outputStream, String encoding) throws XMLSecurityException { super(); setPhase(XMLSecurityConstants.Phase.POSTPROCESSING); try { xmlEventWriter = new XMLSecurityEventWriter(XMLSecurityConstants.xmlOutputFactory.createXMLStreamWriter(outputStream, encoding)); } catch (XMLStreamException e) { throw new XMLSecurityException(e); } }
@Override public void doFinal(OutputProcessorChain outputProcessorChain) throws XMLSecurityException { try { xmlEventWriter.flush(); xmlEventWriter.close(); } catch (XMLStreamException e) { throw new XMLSecurityException(e); } } }
public static void createKeyNameTokenStructure(AbstractOutputProcessor abstractOutputProcessor, OutputProcessorChain outputProcessorChain, String keyName) throws XMLStreamException, XMLSecurityException { if (keyName == null || keyName.isEmpty()) { throw new XMLSecurityException("stax.signature.keyNameMissing"); } abstractOutputProcessor.createStartElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_KeyName, true, null); abstractOutputProcessor.createCharactersAndOutputAsEvent(outputProcessorChain, keyName); abstractOutputProcessor.createEndElementAndOutputAsEvent(outputProcessorChain, XMLSecurityConstants.TAG_dsig_KeyName); } }
protected void compareDigest(byte[] calculatedDigest, ReferenceType referenceType) throws XMLSecurityException { if (LOG.isDebugEnabled()) { LOG.debug("Calculated Digest: {}", XMLUtils.encodeToString(calculatedDigest)); LOG.debug("Stored Digest: {}", XMLUtils.encodeToString(referenceType.getDigestValue())); } if (!MessageDigest.isEqual(referenceType.getDigestValue(), calculatedDigest)) { throw new XMLSecurityException( "signature.Verification.InvalidDigestOrReference", new Object[] {referenceType.getURI()}); } }
@Override protected void forwardSecurityEvent(SecurityEvent securityEvent) throws XMLSecurityException { if (!InboundSecurityContextImpl.allowMD5Algorithm && SecurityEventConstants.AlgorithmSuite.equals(securityEvent.getSecurityEventType())) { AlgorithmSuiteSecurityEvent algorithmSuiteSecurityEvent = (AlgorithmSuiteSecurityEvent)securityEvent; if (algorithmSuiteSecurityEvent.getAlgorithmURI().contains("md5") || algorithmSuiteSecurityEvent.getAlgorithmURI().contains("MD5")) { throw new XMLSecurityException("secureProcessing.AllowMD5Algorithm"); } } super.forwardSecurityEvent(securityEvent); }