gessnerfl / fake-smtp-server

A simple SMTP Server for Testing purposes. Emails are stored in an in-memory database and rendered in a Web UI
Apache License 2.0
408 stars 82 forks source link

Failed to setup TLS keystore of SMTP server #501

Open sympati opened 4 days ago

sympati commented 4 days ago

Thank you for fake-smtp-server! It is really handy for my tests.

I am trying the latest 2.3.0 release as I also need to test with a TLS connection.

I am using the application.yaml file with the settings from the README page as is, adding the following section:

  authentication:
    username: myuser
    password: mysecretpassword

  requireTLS: true
  tlsKeystore:
    location: ./as2_certs.p12
    password: testas2
    type: PKCS12

The as2_certs.p12 keystore comes from the example keystore provided by OpenAS2.

Both application.yaml and the keystore are in the same directory as fake-smtp-server-2.3.9.jar. I also tried an absolute path to the keystore in the settings.

Unfortunately I am getting the following error and I have no idea on how to debug it.

I also tried using my own keystore generated with KeyStore Explorer and got the same error:

SMTP server 2024-06-28T17:48:40.929+02:00 INFO 13348 --- [ main] d.g.f.config.BaseSmtpServerConfig : Setup TLS keystore of SMTP server 2024-06-28T17:48:40.935+02:00 WARN 13348 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'smtpServer' defined in class path resource [de/gessnerfl/fakesmtp/config/BaseSmtpServerConfig.class]: Failed to instantiate [de.gessnerfl.fakesmtp.smtp.server.SmtpServer]: Factory method 'smtpServer' threw exception with message: Failed to setup TLS keystore of SMTP server

Any help would be appreciated.

Thanks

gessnerfl commented 2 days ago

@sympati can you please share the full stacktrace? And can you please also try to use an absolute path to the certificate location?

Thanks

sympati commented 1 day ago

@gessnerfl thank you for your prompt response.

I did try using an absolute path to no avail as mentioned in my report:

I also tried an absolute path to the keystore in the settings.

I will try again and post the full stacktrace later when I'm more awake :) It's still early morning here.

sympati commented 1 day ago

Two coffee cups later :)

. _ _ /\ / '_ () \ \ \ \ ( ( )\ | ' | '| | ' \/ ` | \ \ \ \ \/ _)| |)| | | | | || (| | ) ) ) ) ' |__| .|| ||| |\, | / / / / =========|_|==============|__/=////

:: Spring Boot :: (v3.3.1)

2024-07-01T06:32:05.613+02:00 INFO 51436 --- [ main] de.gessnerfl.fakesmtp.Application : Starting Application v2.3.0 using Java 22.0.1 with PID 51436 (/Users/my_name/Desktop/fake-smtp-server-2.3.0.jar started by my_name in /Users/my_name/Desktop) 2024-07-01T06:32:05.618+02:00 INFO 51436 --- [ main] de.gessnerfl.fakesmtp.Application : The following 1 profile is active: "default" 2024-07-01T06:32:07.551+02:00 INFO 51436 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2024-07-01T06:32:07.658+02:00 INFO 51436 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 94 ms. Found 2 JPA repository interfaces. 2024-07-01T06:32:08.878+02:00 INFO 51436 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http) 2024-07-01T06:32:08.899+02:00 INFO 51436 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2024-07-01T06:32:08.900+02:00 INFO 51436 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.25] 2024-07-01T06:32:08.950+02:00 INFO 51436 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2024-07-01T06:32:08.951+02:00 INFO 51436 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3247 ms 2024-07-01T06:32:09.240+02:00 INFO 51436 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2024-07-01T06:32:09.605+02:00 INFO 51436 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:mail user=ADMIN 2024-07-01T06:32:09.610+02:00 INFO 51436 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2024-07-01T06:32:09.632+02:00 INFO 51436 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:mail' 2024-07-01T06:32:10.020+02:00 INFO 51436 --- [ main] org.flywaydb.core.FlywayExecutor : Database: jdbc:h2:mem:mail (H2 2.2) 2024-07-01T06:32:10.041+02:00 WARN 51436 --- [ main] o.f.c.internal.database.base.Database : Flyway upgrade recommended: H2 2.2.224 is newer than this version of Flyway and support has not been tested. The latest supported version of H2 is 2.2.220. 2024-07-01T06:32:10.066+02:00 INFO 51436 --- [ main] o.f.c.i.s.JdbcTableSchemaHistory : Schema history table "PUBLIC"."flyway_schema_history" does not exist yet 2024-07-01T06:32:10.071+02:00 INFO 51436 --- [ main] o.f.core.internal.command.DbValidate : Successfully validated 1 migration (execution time 00:00.016s) 2024-07-01T06:32:10.081+02:00 INFO 51436 --- [ main] o.f.c.i.s.JdbcTableSchemaHistory : Creating Schema History table "PUBLIC"."flyway_schema_history" ... 2024-07-01T06:32:10.137+02:00 INFO 51436 --- [ main] o.f.core.internal.command.DbMigrate : Current version of schema "PUBLIC": << Empty Schema >> 2024-07-01T06:32:10.147+02:00 INFO 51436 --- [ main] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version "1.1.0 - initial table structure" 2024-07-01T06:32:10.195+02:00 INFO 51436 --- [ main] o.f.core.internal.command.DbMigrate : Successfully applied 1 migration to schema "PUBLIC", now at version v1.1.0 (execution time 00:00.029s) 2024-07-01T06:32:10.363+02:00 INFO 51436 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2024-07-01T06:32:10.444+02:00 INFO 51436 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.5.2.Final 2024-07-01T06:32:10.496+02:00 INFO 51436 --- [ main] o.h.c.internal.RegionFactoryInitiator : HHH000026: Second-level cache disabled 2024-07-01T06:32:10.979+02:00 INFO 51436 --- [ main] o.s.o.j.p.SpringPersistenceUnitInfo : No LoadTimeWeaver setup: ignoring JPA class transformer 2024-07-01T06:32:11.326+02:00 WARN 51436 --- [ main] o.h.b.i.InFlightMetadataCollectorImpl : HHH000069: Duplicate generator name email_part_generator 2024-07-01T06:32:12.342+02:00 INFO 51436 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration) 2024-07-01T06:32:12.376+02:00 INFO 51436 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2024-07-01T06:32:12.841+02:00 INFO 51436 --- [ main] o.s.d.j.r.query.QueryEnhancerFactory : Hibernate is in classpath; If applicable, HQL parser will be used. 2024-07-01T06:32:13.131+02:00 INFO 51436 --- [ main] d.g.f.config.BaseSmtpServerConfig : Setup simple username and password authentication for SMTP server 2024-07-01T06:32:13.132+02:00 INFO 51436 --- [ main] d.g.f.config.BaseSmtpServerConfig : Setup TLS keystore of SMTP server 2024-07-01T06:32:13.139+02:00 WARN 51436 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'smtpServer' defined in class path resource [de/gessnerfl/fakesmtp/config/BaseSmtpServerConfig.class]: Failed to instantiate [de.gessnerfl.fakesmtp.smtp.server.SmtpServer]: Factory method 'smtpServer' threw exception with message: Failed to setup TLS keystore of SMTP server 2024-07-01T06:32:13.140+02:00 INFO 51436 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' 2024-07-01T06:32:13.144+02:00 INFO 51436 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2024-07-01T06:32:13.147+02:00 INFO 51436 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2024-07-01T06:32:13.150+02:00 INFO 51436 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2024-07-01T06:32:13.178+02:00 INFO 51436 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2024-07-01T06:32:13.207+02:00 ERROR 51436 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'smtpServer' defined in class path resource [de/gessnerfl/fakesmtp/config/BaseSmtpServerConfig.class]: Failed to instantiate [de.gessnerfl.fakesmtp.smtp.server.SmtpServer]: Factory method 'smtpServer' threw exception with message: Failed to setup TLS keystore of SMTP server at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:485) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1337) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1167) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:962) ~[spring-context-6.1.10.jar!/:6.1.10] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:624) ~[spring-context-6.1.10.jar!/:6.1.10] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.3.1.jar!/:3.3.1] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.3.1.jar!/:3.3.1] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.3.1.jar!/:3.3.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.3.1.jar!/:3.3.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.1.jar!/:3.3.1] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.1.jar!/:3.3.1] at de.gessnerfl.fakesmtp.Application.main(Application.java:11) ~[!/:2.3.0] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na] at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91) ~[fake-smtp-server-2.3.0.jar:2.3.0] at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53) ~[fake-smtp-server-2.3.0.jar:2.3.0] at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58) ~[fake-smtp-server-2.3.0.jar:2.3.0] Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.gessnerfl.fakesmtp.smtp.server.SmtpServer]: Factory method 'smtpServer' threw exception with message: Failed to setup TLS keystore of SMTP server at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:177) ~[spring-beans-6.1.10.jar!/:6.1.10] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644) ~[spring-beans-6.1.10.jar!/:6.1.10] ... 24 common frames omitted Caused by: java.lang.IllegalStateException: Failed to setup TLS keystore of SMTP server at de.gessnerfl.fakesmtp.config.BaseSmtpServerConfig.smtpServer(BaseSmtpServerConfig.java:97) ~[!/:2.3.0] at de.gessnerfl.fakesmtp.config.BaseSmtpServerConfig$$SpringCGLIB$$0.CGLIB$smtpServer$1() ~[!/:2.3.0] at de.gessnerfl.fakesmtp.config.BaseSmtpServerConfig$$SpringCGLIB$$FastClass$$1.invoke() ~[!/:2.3.0] at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258) ~[spring-core-6.1.10.jar!/:6.1.10] at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:348) ~[spring-context-6.1.10.jar!/:6.1.10] at de.gessnerfl.fakesmtp.config.BaseSmtpServerConfig$$SpringCGLIB$$0.smtpServer() ~[!/:2.3.0] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140) ~[spring-beans-6.1.10.jar!/:6.1.10] ... 25 common frames omitted

gessnerfl commented 1 day ago

I'm using Springs ResourceLoader. Most probably, you will have to prefix the path with file: with the current implementation. I will double check and if so, adjust the application and add this prefix if no supported prefix is present.

sympati commented 18 hours ago

Most probably, you will have to prefix the path with file: with the current implementation.

That dit it!

tlsKeystore:
    location: file:///Users/my_name/Desktop/as2_certs.p12

2024-07-02T09:10:18.649+02:00 INFO 31822 --- [ main] d.g.f.config.BaseSmtpServerConfig : Setup TLS keystore of SMTP server 2024-07-02T09:10:18.998+02:00 INFO 31822 --- [ main] d.g.f.config.BaseSmtpServerConfig : Setup of TLS keystore of SMTP server completed

I'll test it further today and let you know if I have any problem.

Thanks