@Override
public void call(ByteBuffer buffer) throws SSLException
{
ByteSource chunk = ByteSource.wrap(buffer.array()).slice(buffer.arrayOffset(), buffer.position());
ByteSource source = (data == null) ? chunk : ByteSource.concat(data, chunk);
try {
PKCS10CertificationRequest csr = new PKCS10CertificationRequest(source.read());
ProxyRequestOptions options = new ProxyRequestOptions(credential.getCertificateChain(), csr);
options.setLimited(isDelegationLimited);
X509Certificate[] chain = ProxyGenerator.generate(options, credential.getKey());
send(ByteBuffer.wrap(chain[0].getEncoded()));
} catch (EOFException f) {
try {
ByteSource copy = ByteSource.wrap(chunk.read());
data = (data == null) ? copy : ByteSource.concat(data, copy);
receive(this);
} catch (IOException e) {
f.addSuppressed(e);
}
} catch (CertificateParsingException | NoSuchAlgorithmException | NoSuchProviderException | SignatureException | CertificateEncodingException | InvalidKeyException | IOException e) {
throw new SSLException("GSI delegation failed: " + e.toString(), e);
}
}
}