use of com.github.zhenwei.pkix.cmc.CMCException in project LinLong-Java by zhenwei1108.
the class ESTService method handleEnrollResponse.
/**
* Handles the enroll response, deals with status codes and setting of delays.
*
* @param resp The response.
* @return An EnrollmentResponse.
* @throws IOException
*/
protected EnrollmentResponse handleEnrollResponse(ESTResponse resp) throws IOException {
ESTRequest req = resp.getOriginalRequest();
Store<X509CertificateHolder> enrolled = null;
if (resp.getStatusCode() == 202) {
// Received but not ready.
String rt = resp.getHeader("Retry-After");
if (rt == null) {
throw new ESTException("Got Status 202 but not Retry-After header from: " + req.getURL().toString());
}
long notBefore = -1;
try {
notBefore = System.currentTimeMillis() + (Long.parseLong(rt) * 1000);
} catch (NumberFormatException nfe) {
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
notBefore = dateFormat.parse(rt).getTime();
} catch (Exception ex) {
throw new ESTException("Unable to parse Retry-After header:" + req.getURL().toString() + " " + ex.getMessage(), null, resp.getStatusCode(), resp.getInputStream());
}
}
return new EnrollmentResponse(null, notBefore, req, resp.getSource());
} else if (resp.getStatusCode() == 200) {
ASN1InputStream ain = new ASN1InputStream(resp.getInputStream());
SimplePKIResponse spkr = null;
try {
spkr = new SimplePKIResponse(ContentInfo.getInstance(ain.readObject()));
} catch (CMCException e) {
throw new ESTException(e.getMessage(), e.getCause());
}
enrolled = spkr.getCertificates();
return new EnrollmentResponse(enrolled, -1, null, resp.getSource());
}
throw new ESTException("Simple Enroll: " + req.getURL().toString(), null, resp.getStatusCode(), resp.getInputStream());
}
Aggregations