#2742 CMC: CMC request are available on the CA Agent page even after Rejected status in Audit logs
Closed: fixed Opened by mharmsen.

CMC request are lying in the CA Agent page even after Rejected status in Audit
logs. In this case we try to approve such request from CA Agent page it gives
NPE.

CMC request can failed due to many reasons:

1. Connectivity break
2. AES key wrapping used in place of encryption
3. KRA is not reachable due key archival .

Easy way to reproduce is:

1. Don't add cmc.token cs.cfg while testing User-signed CMC request Without POP
(Encrypted POP / Decrypted POP)
2. Or while doing key archival in last HTTPClient stop KRA.

Steps to Reproduce:

1.Use the setup mentioned in https://pki.fedoraproject.org/wiki/PKI_10.4_CMC_Fe
ature_Update_(RFC5272)#User-signed_CMC_request_Without_POP_.28Encrypted_POP_.2F
_Decrypted_POP.29

Actual results:

All the failed request can still seen in enrollment pending queue of CA Agent
page.

Expected results:

Such failed request should either moved to rejected
Additional info:
CA Agent page :
=============
#       Status  Assigned to     Subject
34      pending         unassigned
CN=geetika, UID=gkapoor2
35      pending         unassigned
UID=test10, CN=test10, O=example.org
59      pending         unassigned
UID=test10, CN=test10, O=example.org
60      pending         unassigned
Audit logs:
============
[root@pki1 signedAudit]# grep "ReqID=34" ca_audit
0.http-bio-25443-exec-23 - [12/Jun/2017:01:23:52 EDT] [14] [6] [AuditEvent=PROF
ILE_CERT_REQUEST][SubjectID=test10][Outcome=Success][ReqID=34][ProfileID=caFull
CMCSelfSignedCert][CertSubject=CN=geetika,UID=gkapoor2] certificate request
made with certificate profiles
0.http-bio-25443-exec-20 - [14/Jun/2017:12:13:39 EDT] [14] [6] [AuditEvent=CERT
_REQUEST_PROCESSED][SubjectID=caadmin][Outcome=Failure][ReqID=34][InfoName=cert
ificate][InfoValue=<null>] certificate request processed
[root@pki1 signedAudit]# grep "ReqID=60" ca_audit
0.http-bio-25443-exec-10 - [04/Dec/2017:15:29:10 EST] [14] [6] [AuditEvent=PROF
ILE_CERT_REQUEST][SubjectID=test10][Outcome=Success][ReqID=60][ProfileID=caFull
CMCUserSignedCert][CertSubject=UID=test10,CN=test10,O=example.org] certificate
request made with certificate profiles
0.http-bio-25443-exec-10 - [04/Dec/2017:15:29:10 EST] [14] [6] [AuditEvent=CERT
_REQUEST_PROCESSED][SubjectID=test10][Outcome=Failure][ReqID=60][InfoName=rejec
tReason][InfoValue=Server Internal Error] certificate request processed
=========================================================================
NPE of CA Page if we try to approve it:
SEVERE: Servlet.service() for servlet [Resteasy] in context with path [/ca]
threw exception
org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
        at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(
ExceptionHandler.java:76)
        at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHa
ndler.java:212)
        at org.jboss.resteasy.core.SynchronousDispatcher.writeException(Synchro
nousDispatcher.java:149)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDisp
atcher.java:372)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDisp
atcher.java:179)
        at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher
.service(ServletContainerDispatcher.java:220)
        at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.serv
ice(HttpServletDispatcher.java:56)
        at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.serv
ice(HttpServletDispatcher.java:51)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        at sun.reflect.GeneratedMethodAccessor40.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
ssorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:288)
        at
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:285)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAsPrivileged(Subject.java:549)
        at
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:320)
        at
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:175)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
licationFilterChain.java:297)
        at org.apache.catalina.core.ApplicationFilterChain.access$000(Applicati
onFilterChain.java:55)
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFil
terChain.java:191)
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFil
terChain.java:187)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
FilterChain.java:186)
        at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
ssorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:288)
        at
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:285)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAsPrivileged(Subject.java:549)
        at
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:320)
        at
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:260)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
licationFilterChain.java:237)
        at org.apache.catalina.core.ApplicationFilterChain.access$000(Applicati
onFilterChain.java:55)
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFil
terChain.java:191)
        at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFil
terChain.java:187)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
FilterChain.java:186)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapper
Valve.java:218)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContext
Valve.java:110)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentic
atorBase.java:615)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVa
lve.java:116)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHtt
p11Processor.java:1087)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
(AbstractProtocol.java:637)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoi
nt.java:316)
        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskT
hread.java:61)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
        at
java.util.ListResourceBundle.handleGetObject(ListResourceBundle.java:133)
        at java.util.ResourceBundle.getObject(ResourceBundle.java:441)
        at java.util.ResourceBundle.getString(ResourceBundle.java:407)
        at com.netscape.certsrv.base.MessageFormatter.getLocalizedString(Messag
eFormatter.java:97)
        at
com.netscape.certsrv.base.EBaseException.toString(EBaseException.java:160)
        at
com.netscape.certsrv.base.EBaseException.toString(EBaseException.java:149)
        at java.lang.String.valueOf(String.java:2994)
        at java.lang.StringBuilder.append(StringBuilder.java:131)
        at org.dogtagpki.server.ca.rest.CertRequestService.changeRequestState(C
ertRequestService.java:230)
        at org.dogtagpki.server.ca.rest.CertRequestService.approveRequest(CertR
equestService.java:182)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
ssorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at
org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(Resourc
eMethodInvoker.java:280)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodI
nvoker.java:234)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodI
nvoker.java:221)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDisp
atcher.java:356)
        ... 51 more

Metadata Update from @mharmsen:
- Custom field component adjusted to General
- Custom field feature adjusted to ''
- Custom field origin adjusted to Community
- Custom field proposedmilestone adjusted to ''
- Custom field proposedpriority adjusted to ''
- Custom field reviewer adjusted to ''
- Custom field rhbz adjusted to https://bugzilla.redhat.com/show_bug.cgi?id=1461528
- Custom field type adjusted to defect
- Custom field version adjusted to ''
- Issue priority set to: critical

Metadata Update from @mharmsen:
- Issue set to the milestone: 10.5 (was: 10.4)

Metadata Update from @cfu:
- Issue assigned to cfu

commit 304d198ec21bb4d4f598d2f1876ff47fcdefeb64
Author: Christina Fu cfu@redhat.com
Date: Fri Aug 11 13:29:30 2017 -0700

Ticket #2742 CMC: CMC request are available on the CA Agent page even after Rejected status in Audit logs
This patch fixes the issue that when CMC DecryptedPOP request fails, error was not reflected into CMC response and missed updating the reject status of the request.
The main three problems addressed were
1. in CAEnrollProfile.java, after kraConnector.send(request), the code assumed that getLocale(request) is not null (when in fact it was null for the cases I tested), and therefore caused NPE in subsequence references; This patch adds a check for getLocale(request) != null.
2. in ProfileSubmitCMCServlet.java, in case of DecryptedPOP (privedReq not null), a generic Exception (that would be hit by the NPE from above error) called CMCOutputTemplate createFullResponse instead of the proper createFullResponseWithFailedStatus(). This patch makes sure the proper call is being made to produce the expected CMC response.
3. When the DecryptedPOP was rejected for any reason, the original request remained in the CA's request repository.  This patch makes sure that as long as the processing of the 2nd trip (DecryptedPOP) request gets to unmarshal and verify the requestID the request will be marked rejected if it is the case.
This patch was tested with wrong KRA transport cert to trigger the issue.
Change-Id: I74fe3810193a521c19e8ba74cb6f7eb09413b789

Metadata Update from @cfu:
- Issue close_status updated to: fixed
- Issue status updated to: Closed (was: Open)

Metadata Update from @mharmsen:
- Issue set to the milestone: 10.5.0 (was: 10.5)

Metadata Update from @mharmsen:
- Custom field fixedinversion adjusted to pki-core-10.5.0-1.fc27

Dogtag PKI is moving from Pagure issues to GitHub issues. This means that existing or new
issues will be reported and tracked through Dogtag PKI's GitHub Issue tracker.

This issue has been cloned to GitHub and is available here:
https://github.com/dogtagpki/pki/issues/2862

If you want to receive further updates on the issue, please navigate to the
GitHub issue and click on Subscribe button.

Thank you for understanding, and we apologize for any inconvenience.

Metadata