phax / as2-lib

A generic Java AS2 library, servlet and server
107 stars 43 forks source link

java.lang.IllegalStateException: unable to create shared stream: java.io.FileNotFoundException: /tmp/as2-lib-res-16551011638687829143.tmp (No such file or directory) #135

Closed ihudedi closed 2 years ago

ihudedi commented 2 years ago

Hi @phax When sending AS2 message (signed,encrypted, no compress and request mdn) and there is an error from the server We should get mdn with the error from the server but when you create the MDN in the server there is an issue with temp file that isn't created when calculated the MIC. The issue only occur when AS2 message is encrypted nad the message isn't compressed When the message is encrypted and compressed everything is working fine. Attaching 2 log files - one is working and the other is n't working the working is - as2 is encrypted,sign,compress and request MDN the non working is - as2 is encrypted,sign,not compress and request MDN [AS2_notworking.txt](https://github.com/phax/as2-lib/files/7941384/AS2_notworking.txt) [AS2_working.txt](https://github.com/phax/as2-lib/files/7941385/AS2_working.txt) 2022-01-25 04:55:47,287 DEBUG [http-nio-10086-exec-4] (BCCryptoHelper:340) - Using encoding 'binary' for MIC calculation 2022-01-25 04:55:47,289 INFO [http-nio-10086-exec-4] (AS2Exception:94) - as2-lib 4.10.0 WrappedAS2Exception terminated: java.lang.IllegalStateException: unable to create shared stream: java.io.FileNotFoundException: /tmp/as2-lib-res-16551011638687829143.tmp (No such file or directory); source msg: [] java.lang.IllegalStateException: unable to create shared stream: java.io.FileNotFoundException: /tmp/as2-lib-res-16551011638687829143.tmp (No such file or directory) at org.bouncycastle.mail.smime.util.SharedFileInputStream.newStream(Unknown Source) ~[bcmail-fips-1.0.3.jar!/:1.0.3] at javax.mail.internet.MimeBodyPart.getContentStream(MimeBodyPart.java:590) ~[jakarta.mail-1.6.7.jar!/:1.6.7] at javax.mail.internet.MimePartDataSource.getInputStream(MimePartDataSource.java:76) ~[jakarta.mail-1.6.7.jar!/:1.6.7] at javax.activation.DataHandler.writeTo(DataHandler.java:288) ~[jakarta.activation-1.2.2.jar!/:1.2.2] at com.helger.as2lib.crypto.BCCryptoHelper.calculateMIC(BCCryptoHelper.java:346) ~[as2-lib-4.10.0.jar!/:4.10.0] at com.helger.as2lib.util.AS2Helper.createMDN(AS2Helper.java:331) ~[as2-lib-4.10.0.jar!/:4.10.0] at com.helger.as2lib.processor.receiver.net.AS2ReceiverHandler.sendMDN(AS2ReceiverHandler.java:415) [as2-lib-4.10.0.jar!/:4.10.0] at com.helger.as2lib.processor.receiver.net.AS2ReceiverHandler.handleIncomingMessage(AS2ReceiverHandler.java:710) [as2-lib-4.10.0.jar!/:4.10.0] at com.bmc.ctm.mft.b2b.hub.as2.handler.As2MftReceiverHandler.handleIncomingMessage(As2MftReceiverHandler.java:36) [classes!/:?] at com.helger.as2servlet.AbstractAS2ReceiveXServletHandler.handleIncomingMessage(AbstractAS2ReceiveXServletHandler.java:117) [as2-servlet-4.10.0.jar!/:4.10.0] at com.bmc.ctm.mft.b2b.hub.as2.servlet.AS2ServletCodeConfig.handleIncomingMessage(AS2ServletCodeConfig.java:62) [classes!/:?] at com.helger.as2servlet.AbstractAS2ReceiveBaseXServletHandler.onRequest(AbstractAS2ReceiveBaseXServletHandler.java:258) [as2-servlet-4.10.0.jar!/:4.10.0] at com.helger.xservlet.AbstractXServlet._invokeHandler(AbstractXServlet.java:345) [ph-xservlet-9.6.2.jar!/:9.6.2] at com.helger.xservlet.AbstractXServlet.service(AbstractXServlet.java:533) [ph-xservlet-9.6.2.jar!/:9.6.2] at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) [tomcat-embed-core-9.0.56.jar!/:?] at com.helger.xservlet.AbstractXServlet.service(AbstractXServlet.java:587) [ph-xservlet-9.6.2.jar!/:9.6.2] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.56.jar!/:?] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.56.jar!/:?] at com.bmc.ctm.mft.b2b.hub.configuration.http.RequestMethodFilter.doFilter(RequestMethodFilter.java:42) [classes!/:?] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.56.jar!/:?] at com.bmc.ctm.mft.b2b.hub.configuration.http.B2BEnabledFilter.doFilter(B2BEnabledFilter.java:134) [classes!/:?] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.56.jar!/:?] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:327) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:121) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:126) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:81) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:105) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:149) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:149) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) [spring-web-5.3.14.jar!/:5.3.14] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at com.bmc.ctm.mft.b2b.hub.configuration.http.B2BEnabledFilter.doFilter(B2BEnabledFilter.java:134) [classes!/:?] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at com.bmc.ctm.mft.b2b.hub.configuration.http.RequestMethodFilter.doFilter(RequestMethodFilter.java:42) [classes!/:?] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:89) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) [spring-web-5.3.14.jar!/:5.3.14] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:110) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) [spring-web-5.3.14.jar!/:5.3.14] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:211) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.debug.DebugFilter.invokeWithWrappedRequest(DebugFilter.java:90) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.debug.DebugFilter.doFilter(DebugFilter.java:78) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.security.web.debug.DebugFilter.doFilter(DebugFilter.java:67) [spring-security-web-5.5.4.jar!/:5.5.4] at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:354) [spring-web-5.3.14.jar!/:5.3.14] at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:267) [spring-web-5.3.14.jar!/:5.3.14] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.56.jar!/:?] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) [spring-web-5.3.14.jar!/:5.3.14] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) [spring-web-5.3.14.jar!/:5.3.14] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.56.jar!/:?] at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) [spring-web-5.3.14.jar!/:5.3.14] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) [spring-web-5.3.14.jar!/:5.3.14] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.56.jar!/:?] at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96) [spring-boot-actuator-2.5.8.jar!/:2.5.8] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) [spring-web-5.3.14.jar!/:5.3.14] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.56.jar!/:?] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.3.14.jar!/:5.3.14] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) [spring-web-5.3.14.jar!/:5.3.14] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1732) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.56.jar!/:?] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.56.jar!/:?] at java.lang.Thread.run(Unknown Source) [?:?] Do you know what is the issue Thanks, Itay

ihudedi commented 2 years ago

Hi @phax See my updated description. I added 2 log files that one is working ( encrypt,sign,compress and reciept) and one is not working ( encrypt,sign,reciept and not compress) When there is an error from the server like we throw AS2DispositionException and we use ( encrypt,sign,compress and reciept) we fail with the above stack trace. When there isn't an error and we send the AS2 message with ( encrypt,sign,compress and reciept) everything is OK. Seems there is an issue when exception is thrown and trying to create MDN to send to client and message isn;t compressed the calulation of MIC is correupted due to issue that I wrote above. Thanks, Itay

ihudedi commented 2 years ago

Hi @phax Do you have any updates? Thanks, Itay

phax commented 2 years ago

Nope, not yet - sorry. Edit: one thing I noted: you are using the FIPS version of BouncyCastle: "bcmail-fips-1.0.3" - maybe it is an error in there???

ihudedi commented 2 years ago

Hi @phax I found the issue. In AS2ReceiverHandler::handleIncomingMessage You have this line: try (final AS2ResourceHelper aResHelper = new AS2ResourceHelper ()) this close all temporary file when the try finished. In case there isn't any excpetion the mdn is sendind in the try block but when there is an exception in the try block all resources that created in decrypt method and verify are deleted in the ending of the try block But in the catch when you try to send mdn and calculate MIC you get an exception that the file is not exist. Please close all reources in the finally block as you did for TempSharedFileInputStream Thanks, Itay

phax commented 2 years ago

@ihudedi I tried to improve the execution order and building version 4.10.1. Let me know if that helps.

ihudedi commented 2 years ago

Hi @phax Issue was resolved because recourses was closed after all code and not in the code - after catch/suceess. Thanks a lot, Itay

phax commented 2 years ago

@ihudedi Thanks for the conformation and happy AS2'ing 😄