use of org.xipki.scep.client.exception.ScepClientException in project xipki by xipki.
the class Client method retrieveNextCaAuthorityCertStore.
private AuthorityCertStore retrieveNextCaAuthorityCertStore(ScepHttpResponse httpResp) throws ScepClientException {
String ct = httpResp.getContentType();
if (!ScepConstants.CT_X509_NEXT_CA_CERT.equalsIgnoreCase(ct)) {
throw new ScepClientException("invalid Content-Type '" + ct + "'");
}
CMSSignedData cmsSignedData;
try {
cmsSignedData = new CMSSignedData(httpResp.getContentBytes());
} catch (CMSException ex) {
throw new ScepClientException("invalid SignedData message: " + ex.getMessage(), ex);
} catch (IllegalArgumentException ex) {
throw new ScepClientException("invalid SignedData message: " + ex.getMessage(), ex);
}
DecodedNextCaMessage resp;
try {
resp = DecodedNextCaMessage.decode(cmsSignedData, responseSignerCerts);
} catch (MessageDecodingException ex) {
throw new ScepClientException("could not decode response: " + ex.getMessage(), ex);
}
if (resp.getFailureMessage() != null) {
throw new ScepClientException("Error: " + resp.getFailureMessage());
}
Boolean bo = resp.isSignatureValid();
if (bo != null && !bo.booleanValue()) {
throw new ScepClientException("Signature is invalid");
}
Date signingTime = resp.getSigningTime();
long maxSigningTimeBias = getMaxSigningTimeBiasInMs();
if (maxSigningTimeBias > 0) {
if (signingTime == null) {
throw new ScepClientException("CMS signingTime attribute is not present");
}
long now = System.currentTimeMillis();
long diff = now - signingTime.getTime();
if (diff < 0) {
diff = -1 * diff;
}
if (diff > maxSigningTimeBias) {
throw new ScepClientException("CMS signingTime is out of permitted period");
}
}
if (!resp.getSignatureCert().equals(authorityCertStore.getSignatureCert())) {
throw new ScepClientException("the signature certificate must not be trusted");
}
return resp.getAuthorityCertStore();
}
use of org.xipki.scep.client.exception.ScepClientException in project xipki by xipki.
the class ScepHttpResponse method getContentBytes.
public byte[] getContentBytes() throws ScepClientException {
if (content == null) {
return null;
}
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
int readed = 0;
byte[] buffer = new byte[2048];
while ((readed = content.read(buffer)) != -1) {
bout.write(buffer, 0, readed);
}
return bout.toByteArray();
} catch (IOException ex) {
throw new ScepClientException(ex);
} finally {
if (content != null) {
try {
content.close();
} catch (IOException ex) {
LOG.error("could not close stream: {}", ex.getMessage());
}
}
}
}
use of org.xipki.scep.client.exception.ScepClientException in project xipki by xipki.
the class ScepClient method httpGet.
@Override
protected ScepHttpResponse httpGet(String url) throws ScepClientException {
ScepUtil.requireNonNull("url", url);
try {
HttpURLConnection httpConn = openHttpConn(new URL(url));
httpConn.setRequestMethod("GET");
return parseResponse(httpConn);
} catch (IOException ex) {
throw new ScepClientException(ex);
}
}
Aggregations