private ASN1Encodable extractGeneralRepContent(PKIMessage response, String expectedType) throws Exception { PKIBody respBody = response.getBody(); int bodyType = respBody.getType(); if (PKIBody.TYPE_ERROR == bodyType) { ErrorMsgContent content = ErrorMsgContent.getInstance(respBody.getContent()); throw new Exception("Server returned PKIStatus: " + buildText(content.getPKIStatusInfo())); } else if (PKIBody.TYPE_GEN_REP != bodyType) { throw new Exception(String.format("unknown PKI body type %s instead the expected [%s, %s]", bodyType, PKIBody.TYPE_GEN_REP, PKIBody.TYPE_ERROR)); } GenRepContent genRep = GenRepContent.getInstance(respBody.getContent()); InfoTypeAndValue[] itvs = genRep.toInfoTypeAndValueArray(); InfoTypeAndValue itv = null; if (itvs != null && itvs.length > 0) { for (InfoTypeAndValue entry : itvs) { if (expectedType.equals(entry.getInfoType().getId())) { itv = entry; break; } } } if (itv == null) { throw new Exception("the response does not contain InfoTypeAndValue " + expectedType); } return itv.getInfoValue(); } // method extractGeneralRepContent
public static ErrorMsgContent getInstance(Object o) { if (o instanceof ErrorMsgContent) { return (ErrorMsgContent)o; } if (o != null) { return new ErrorMsgContent(ASN1Sequence.getInstance(o)); } return null; }
/** * <pre> * ErrorMsgContent ::= SEQUENCE { * pKIStatusInfo PKIStatusInfo, * errorCode INTEGER OPTIONAL, * -- implementation-specific error codes * errorDetails PKIFreeText OPTIONAL * -- implementation-specific error details * } * </pre> * @return a basic ASN.1 object representation. */ public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(pkiStatusInfo); addOptional(v, errorCode); addOptional(v, errorDetails); return new DERSequence(v); }
ErrorMsgContent emc = new ErrorMsgContent( new PKIStatusInfo(PKIStatus.rejection, new PKIFreeText(ex.getMessage()), new PKIFailureInfo(PKIFailureInfo.notAuthorized))); new org.xipki.security.cmp.PkiStatusInfo(errorMsgContent.getPKIStatusInfo());
return GenRepContent.getInstance(o); case TYPE_ERROR: return ErrorMsgContent.getInstance(o); case TYPE_CERT_CONFIRM: return CertConfirmContent.getInstance(o);
return GenRepContent.getInstance(o); case TYPE_ERROR: return ErrorMsgContent.getInstance(o); case TYPE_CERT_CONFIRM: return CertConfirmContent.getInstance(o);
ErrorMsgContent content = ErrorMsgContent.getInstance(respBody.getContent()); throw new Exception("Server returned PKIStatus: " + content.getPKIStatusInfo()); } else if (PKIBody.TYPE_REVOCATION_REP != bodyType) { throw new Exception(String.format(
public static ErrorMsgContent getInstance(Object o) { if (o instanceof ErrorMsgContent) { return (ErrorMsgContent)o; } if (o != null) { return new ErrorMsgContent(ASN1Sequence.getInstance(o)); } return null; }
/** * <pre> * ErrorMsgContent ::= SEQUENCE { * pKIStatusInfo PKIStatusInfo, * errorCode INTEGER OPTIONAL, * -- implementation-specific error codes * errorDetails PKIFreeText OPTIONAL * -- implementation-specific error details * } * </pre> * @return a basic ASN.1 object representation. */ public ASN1Primitive toASN1Primitive() { ASN1EncodableVector v = new ASN1EncodableVector(); v.add(pkiStatusInfo); addOptional(v, errorCode); addOptional(v, errorDetails); return new DERSequence(v); }
ErrorMsgContent content = ErrorMsgContent.getInstance(respBody.getContent()); throw new Exception("Server returned PKIStatus: " + buildText(content.getPKIStatusInfo())); } else if (resonseBodyType != bodyType) { throw new Exception(String.format("unknown PKI body type %s instead the expected [%s, %s]",
private static PKIBody buildErrorMsgPkiBody(PKIStatus pkiStatus, int failureInfo, String statusMessage) { PKIFreeText pkiStatusMsg = (statusMessage == null) ? null : new PKIFreeText(statusMessage); ErrorMsgContent emc = new ErrorMsgContent( new PKIStatusInfo(pkiStatus, pkiStatusMsg, new PKIFailureInfo(failureInfo))); return new PKIBody(PKIBody.TYPE_ERROR, emc); }
ErrorMsgContent content = ErrorMsgContent.getInstance(respBody.getContent()); throw new CmpClientException(CmpFailureUtil.formatPkiStatusInfo( content.getPKIStatusInfo())); } else if (PKIBody.TYPE_GEN_REP != bodyType) { throw new CmpClientException(String.format(
protected PKIMessage buildErrorPkiMessage(ASN1OctetString tid, PKIHeader requestHeader, int failureCode, String statusText) { GeneralName respRecipient = requestHeader.getSender(); PKIHeaderBuilder respHeader = new PKIHeaderBuilder( requestHeader.getPvno().getValue().intValue(), getSender(), respRecipient); respHeader.setMessageTime(new ASN1GeneralizedTime(new Date())); if (tid != null) { respHeader.setTransactionID(tid); } ASN1OctetString senderNonce = requestHeader.getSenderNonce(); if (senderNonce != null) { respHeader.setRecipNonce(senderNonce); } PKIStatusInfo status = generateRejectionStatus(failureCode, statusText); ErrorMsgContent error = new ErrorMsgContent(status); PKIBody body = new PKIBody(PKIBody.TYPE_ERROR, error); return new PKIMessage(respHeader.build(), body); } // method buildErrorPkiMessage
ErrorMsgContent content = ErrorMsgContent.getInstance(respBody.getContent()); throw new PkiErrorException(content.getPKIStatusInfo()); } else if (PKIBody.TYPE_GEN_REP != bodyType) { throw new CmpClientException(String.format(
new ErrorMsgContent(new PKIStatusInfo(PKIStatus.rejection, null, new PKIFailureInfo(PKIFailureInfo.systemFailure))));
ErrorMsgContent content = ErrorMsgContent.getInstance(respBody.getContent()); throw new PkiErrorException(content.getPKIStatusInfo()); } else if (PKIBody.TYPE_REVOCATION_REP != bodyType) { throw new CmpClientException(String.format(
private PKIMessage addProtection(PKIMessage pkiMessage, AuditEvent event, CmpRequestorInfo requestor) { CmpControl control = getCmpControl(); try { if (requestor.getCert() != null) { return CmpUtil.addProtection(pkiMessage, getSigner(), getSender(), control.isSendResponderCert()); } else { PBMParameter parameter = new PBMParameter(randomSalt(), control.getResponsePbmOwf(), control.getResponsePbmIterationCount(), control.getResponsePbmMac()); return CmpUtil.addProtection(pkiMessage, requestor.getPassword(), parameter, getSender(), requestor.getKeyId()); } } catch (Exception ex) { LogUtil.error(LOG, ex, "could not add protection to the PKI message"); PKIStatusInfo status = generateRejectionStatus( PKIFailureInfo.systemFailure, "could not sign the PKIMessage"); event.setLevel(AuditLevel.ERROR); event.setStatus(AuditStatus.FAILED); event.addEventData(CaAuditConstants.NAME_message, "could not sign the PKIMessage"); PKIBody body = new PKIBody(PKIBody.TYPE_ERROR, new ErrorMsgContent(status)); return new PKIMessage(pkiMessage.getHeader(), body); } } // method addProtection
ErrorMsgContent content = ErrorMsgContent.getInstance(respBody.getContent()); throw new PkiErrorException(content.getPKIStatusInfo()); } else if (expectedBodyType != bodyType) { throw new CmpClientException(String.format(
ErrorMsgContent emc = new ErrorMsgContent( new PKIStatusInfo(PKIStatus.rejection, new PKIFreeText("not all revDetails are of the same type"),