Example usage for javax.security.sasl SaslException SaslException

List of usage examples for javax.security.sasl SaslException SaslException

Introduction

In this page you can find the example usage for javax.security.sasl SaslException SaslException.

Prototype

public SaslException(String detail, Throwable ex) 

Source Link

Document

Constructs a new instance of SaslException with a detailed message and a root exception.

Usage

From source file:org.apache.hadoop.hbase.io.crypto.aes.CryptoAES.java

/**
 * Encrypts input data. The result composes of (msg, padding if needed, mac) and sequence num.
 * @param data the input byte array//from   w w  w  . jav  a  2s.co m
 * @param offset the offset in input where the input starts
 * @param len the input length
 * @return the new encrypted byte array.
 * @throws SaslException if error happens
 */
public byte[] wrap(byte[] data, int offset, int len) throws SaslException {
    // mac
    byte[] mac = integrity.getHMAC(data, offset, len);
    integrity.incMySeqNum();

    // encrypt
    byte[] encrypted = new byte[len + 10];
    try {
        int n = encryptor.update(data, offset, len, encrypted, 0);
        encryptor.update(mac, 0, 10, encrypted, n);
    } catch (ShortBufferException sbe) {
        // this should not happen
        throw new SaslException("Error happens during encrypt data", sbe);
    }

    // append seqNum used for mac
    byte[] wrapped = new byte[encrypted.length + 4];
    System.arraycopy(encrypted, 0, wrapped, 0, encrypted.length);
    System.arraycopy(integrity.getSeqNum(), 0, wrapped, encrypted.length, 4);

    return wrapped;
}

From source file:org.apache.hadoop.hbase.io.crypto.aes.CryptoAES.java

/**
 * Decrypts input data. The input composes of (msg, padding if needed, mac) and sequence num.
 * The result is msg.//from w w  w. j  av a  2s. co  m
 * @param data the input byte array
 * @param offset the offset in input where the input starts
 * @param len the input length
 * @return the new decrypted byte array.
 * @throws SaslException if error happens
 */
public byte[] unwrap(byte[] data, int offset, int len) throws SaslException {
    // get plaintext and seqNum
    byte[] decrypted = new byte[len - 4];
    byte[] peerSeqNum = new byte[4];
    try {
        decryptor.update(data, offset, len - 4, decrypted, 0);
    } catch (ShortBufferException sbe) {
        // this should not happen
        throw new SaslException("Error happens during decrypt data", sbe);
    }
    System.arraycopy(data, offset + decrypted.length, peerSeqNum, 0, 4);

    // get msg and mac
    byte[] msg = new byte[decrypted.length - 10];
    byte[] mac = new byte[10];
    System.arraycopy(decrypted, 0, msg, 0, msg.length);
    System.arraycopy(decrypted, msg.length, mac, 0, 10);

    // check mac integrity and msg sequence
    if (!integrity.compareHMAC(mac, peerSeqNum, msg, 0, msg.length)) {
        throw new SaslException("Unmatched MAC");
    }
    if (!integrity.comparePeerSeqNum(peerSeqNum)) {
        throw new SaslException("Out of order sequencing of messages. Got: " + integrity.byteToInt(peerSeqNum)
                + " Expected: " + integrity.peerSeqNum);
    }
    integrity.incPeerSeqNum();

    return msg;
}

From source file:org.globus.mds.gsi.jndi.SaslClientWrapper.java

public byte[] evaluateChallenge(byte[] challengeData) throws SaslException {
    try {/*from   www  . j a  v a  2  s  .  c  o m*/
        return this.client.evaluateChallenge(challengeData);
    } catch (com.sun.security.sasl.preview.SaslException e) {
        throw new SaslException("", e);
    }
}

From source file:org.globus.mds.gsi.jndi.SaslClientWrapper.java

public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException {
    try {/*  w ww  . j av a  2  s  .  com*/
        return this.client.wrap(outgoing, offset, len);
    } catch (com.sun.security.sasl.preview.SaslException e) {
        throw new SaslException("", e);
    }
}

From source file:org.globus.mds.gsi.jndi.SaslClientWrapper.java

public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException {
    try {//from w ww . j ava  2s.co  m
        return this.client.unwrap(incoming, offset, len);
    } catch (com.sun.security.sasl.preview.SaslException e) {
        throw new SaslException("", e);
    }
}

From source file:org.globus.mds.gsi.jndi.SaslClientWrapper.java

public void dispose() throws SaslException {
    try {//from   w  ww.ja  v  a 2 s  . c om
        this.client.dispose();
    } catch (com.sun.security.sasl.preview.SaslException e) {
        throw new SaslException("", e);
    }
}