Search in sources :

Example 1 with VerifyException

use of com.adaptris.security.exc.VerifyException in project interlok by adaptris.

the class StdSecurityService method verify.

/**
 * @see SecurityService#verify(byte[], Alias, Alias)
 */
public Output verify(byte[] payload, Alias receiver, Alias sender) throws AdaptrisSecurityException {
    StdOutput target = null;
    PrivateKey pk = null;
    CertificateHandler them = null;
    if (alg == null) {
        throw new VerifyException("Decrypt / Verify requires an " + "EncryptionAlgorithm object");
    }
    pk = getPrivateKey(receiver.getAlias(), receiver.getAliasPassword());
    them = createCertificateHandler(getCertificate(sender.getAlias()));
    target = decrypt(payload, pk);
    if (!verify(target, them)) {
        throw new VerifyException("Payload signature could not be verified");
    }
    return target;
}
Also used : PrivateKey(java.security.PrivateKey) VerifyException(com.adaptris.security.exc.VerifyException) CertificateHandler(com.adaptris.security.certificate.CertificateHandler)

Example 2 with VerifyException

use of com.adaptris.security.exc.VerifyException in project interlok by adaptris.

the class StdSecurityService method verify.

private boolean verify(StdOutput target, CertificateHandler ch) throws AdaptrisSecurityException {
    boolean rc = false;
    try {
        if (target.getSignature() != null) {
            Signature sig = getSignatureInstance(ch);
            sig.initVerify(ch.getPublicKey());
            sig.update(target.getDecryptedData(true));
            rc = sig.verify(target.getSignature());
        } else {
            rc = true;
        }
    } catch (Exception e) {
        throw new VerifyException("Exception during signature verfication", e);
    }
    return rc;
}
Also used : VerifyException(com.adaptris.security.exc.VerifyException) Signature(java.security.Signature) KeystoreException(com.adaptris.security.exc.KeystoreException) CertException(com.adaptris.security.exc.CertException) VerifyException(com.adaptris.security.exc.VerifyException) EncryptException(com.adaptris.security.exc.EncryptException) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DecryptException(com.adaptris.security.exc.DecryptException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 3 with VerifyException

use of com.adaptris.security.exc.VerifyException in project interlok by adaptris.

the class StdOutput method split.

/**
 * This splits our full data message into it's constituent parts.
 * <p>
 * This output defines the encrypted payload be a base64 payload containing,
 * in order
 * <ul>
 * <li>InitialisationVector.length</li>
 * <li>InitialisationVector</li>
 * <li>SessionKey.length</li>
 * <li>SessionKey</li>
 * <li>Data.length</li>
 * <li>Data</li>
 * <li>Signature.length</li>
 * <li>Signature</li>
 * </ul>
 * </p>
 *
 * @param fullMessage the data to be treated as an encrypted message
 * @throws AdaptrisSecurityException if an error occurs
 */
void split(byte[] fullMessage) throws AdaptrisSecurityException {
    try {
        message = fullMessage;
        this.split();
    } catch (Exception e) {
        throw new VerifyException("Cannot parse payload", e);
    }
}
Also used : VerifyException(com.adaptris.security.exc.VerifyException) VerifyException(com.adaptris.security.exc.VerifyException) IOException(java.io.IOException) EncryptException(com.adaptris.security.exc.EncryptException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException)

Aggregations

VerifyException (com.adaptris.security.exc.VerifyException)3 AdaptrisSecurityException (com.adaptris.security.exc.AdaptrisSecurityException)2 EncryptException (com.adaptris.security.exc.EncryptException)2 CertificateHandler (com.adaptris.security.certificate.CertificateHandler)1 CertException (com.adaptris.security.exc.CertException)1 DecryptException (com.adaptris.security.exc.DecryptException)1 KeystoreException (com.adaptris.security.exc.KeystoreException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 PrivateKey (java.security.PrivateKey)1 Signature (java.security.Signature)1