2017-11-22 7 views
1

나는 봄 부팅에 HTTPS를 설정에 대한 다음 자습서를 수행하려고했습니다 :은 HTTPS는 (PKCS12 찾을 수 없음) 봄 부팅에서 작업 가져올 수 없습니다

하지만 이클립스에서 내 응용 프로그램을 시작할 때 예외가 발생합니다 : 자바 :

에 의해 발생합니다. io.IOException는 :/C : 파일 /Users/dbush/workspace/my_app/target/classes/keystore.p12 [PKCS12] 경로와 스토어 형로드 실패 인해 [PKCS12 찾을 수 없습니다]

주어진 파일 이름을 검사했는데 파일이 존재합니다. 나는 또한 keytool -list -keystore keystore.p12을 달았고 그것을 만드는 데 사용 된 암호를주고 난 후에 그것을 읽을 수있었습니다. 이것은 application.properties에 같은 암호입니다.

어떤 원인 일 수 있습니까?

또한 PKCS12 파일 대신 JKS 파일을 사용해 보았으며 "JKS를 찾을 수 없습니다"와 동일한 오류가 발생했습니다.

내 pom.xml 파일에는 다음이 포함

... 
    <dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
     <version>1.5.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.data</groupId> 
     <artifactId>spring-data-mongodb</artifactId> 
     <version>1.10.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId> org.springframework.security</groupId> 
     <artifactId>spring-security-core</artifactId> 
     <version>4.2.3.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.mongodb</groupId> 
     <artifactId>mongodb-driver</artifactId> 
     <version>3.4.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.json</groupId> 
     <artifactId>json</artifactId> 
     <version>20160810</version> 
    </dependency> 
    <dependency> 
     <groupId>org.jvnet.jaxb2_commons</groupId> 
     <artifactId>jaxb2-basics</artifactId> 
     <version>0.6.3</version> 
    </dependency> 
    </dependencies> 
.. 

내 주요 App.java :

package dbush; 

import org.apache.catalina.Context; 
import org.apache.catalina.connector.Connector; 
import org.apache.tomcat.util.descriptor.web.SecurityCollection; 
import org.apache.tomcat.util.descriptor.web.SecurityConstraint; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; 
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; 

@Configuration 
@EnableAutoConfiguration 
@ComponentScan 
@EnableMongoRepositories(basePackages = "dbush.repository") 
public class App { 

    public static void main(String[] args) { 
     SpringApplication.run(App.class, args); 
    } 

    @Bean 
    public EmbeddedServletContainerFactory servletContainer() { 
     TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() { 
      @Override 
      protected void postProcessContext(Context context) { 
      SecurityConstraint securityConstraint = new SecurityConstraint(); 
      securityConstraint.setUserConstraint("CONFIDENTIAL"); 
      SecurityCollection collection = new SecurityCollection(); 
      collection.addPattern("/*"); 
      securityConstraint.addCollection(collection); 
      context.addConstraint(securityConstraint); 
      } 
     }; 

     tomcat.addAdditionalTomcatConnectors(redirectConnector()); 
     return tomcat; 
    } 

    private Connector redirectConnector() { 
     Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); 
     connector.setScheme("http"); 
     connector.setPort(8080); 
     connector.setSecure(false); 
     connector.setRedirectPort(8443); 

     return connector; 
    }  

} 

내 application.properties :

security.require_ssl=true 

server.port=8443 
server.ssl.key-alias=tomcat 
server.ssl.key-password=changeit 
server.ssl.key-store=classpath:keystore.p12 
server.ssl.key-store-type=PKCS12 

전체 스택 추적 :

2017-11-22 16:38:09.554 ERROR 8556 --- [   main] org.apache.tomcat.util.net.SSLUtilBase : Failed to load keystore type [PKCS12 ] with path [file:/C:/Users/dbush/workspace/my_app/target/classes/keystore.p12] due to [PKCS12 not found] 

java.security.KeyStoreException: PKCS12 not found 
    at java.security.KeyStore.getInstance(KeyStore.java:851) ~[na:1.8.0_131] 
    at org.apache.tomcat.util.net.SSLUtilBase.getStore(SSLUtilBase.java:122) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.SSLHostConfigCertificate.getCertificateKeystore(SSLHostConfigCertificate.java:187) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.jsse.JSSEUtil.getKeyManagers(JSSEUtil.java:185) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:112) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:85) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:225) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:978) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:628) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:993) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:247) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:190) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at dbush.App.main(App.java:23) [classes/:na] 
Caused by: java.security.NoSuchAlgorithmException: PKCS12 KeyStore not available 
    at sun.security.jca.GetInstance.getInstance(GetInstance.java:159) ~[na:1.8.0_131] 
    at java.security.Security.getImpl(Security.java:695) ~[na:1.8.0_131] 
    at java.security.KeyStore.getInstance(KeyStore.java:848) ~[na:1.8.0_131] 
    ... 23 common frames omitted 

2017-11-22 16:38:09.554 ERROR 8556 --- [   main] o.a.coyote.http11.Http11NioProtocol  : Failed to start end point associated with ProtocolHandler ["https-jsse-nio-8443"] 

java.lang.IllegalArgumentException: java.io.IOException: Failed to load keystore type [PKCS12 ] with path [file:/C:/Users/dbush/workspace/myapp/target/classes/keystore.p12] due to [PKCS12 not found] 
    at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:114) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:85) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:225) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:978) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:628) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:993) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) [tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:247) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:190) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at dbush.App.main(App.java:23) [classes/:na] 
Caused by: java.io.IOException: Failed to load keystore type [PKCS12 ] with path [file:/C:/Users/dbush/workspace/myapp/target/classes/keystore.p12] due to [PKCS12 not found] 
    at org.apache.tomcat.util.net.SSLUtilBase.getStore(SSLUtilBase.java:149) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.SSLHostConfigCertificate.getCertificateKeystore(SSLHostConfigCertificate.java:187) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.jsse.JSSEUtil.getKeyManagers(JSSEUtil.java:185) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:112) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    ... 19 common frames omitted 

2017-11-22 16:38:09.555 ERROR 8556 --- [   main] o.apache.catalina.core.StandardService : Failed to start connector [Connector[HTTP/1.1-8443]] 

org.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-8443]] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.addPreviouslyRemovedConnectors(TomcatEmbeddedServletContainer.java:247) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:190) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:297) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:145) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) [spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE] 
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] 
    at dbush.App.main(App.java:23) [classes/:na] 
Caused by: org.apache.catalina.LifecycleException: service.getName(): "Tomcat"; Protocol handler start failed 
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:1000) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    ... 13 common frames omitted 
Caused by: java.lang.IllegalArgumentException: java.io.IOException: Failed to load keystore type [PKCS12 ] with path [file:/C:/Users/dbush/workspace/myapp/target/classes/keystore.p12] due to [PKCS12 not found] 
    at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:114) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.AbstractJsseEndpoint.initialiseSsl(AbstractJsseEndpoint.java:85) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:225) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:978) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:628) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.catalina.connector.Connector.startInternal(Connector.java:993) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    ... 14 common frames omitted 
Caused by: java.io.IOException: Failed to load keystore type [PKCS12 ] with path [file:/C:/Users/dbush/workspace/myapp/target/classes/keystore.p12] due to [PKCS12 not found] 
    at org.apache.tomcat.util.net.SSLUtilBase.getStore(SSLUtilBase.java:149) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.SSLHostConfigCertificate.getCertificateKeystore(SSLHostConfigCertificate.java:187) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.jsse.JSSEUtil.getKeyManagers(JSSEUtil.java:185) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    at org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLContext(AbstractJsseEndpoint.java:112) ~[tomcat-embed-core-8.5.14.jar:8.5.14] 
    ... 19 common frames omitted 
+1

자바 8. @dur 나는 keystore.type.compat''설정해보십시오 않았다하지만 아무런 영향을 미치지 않습니다. PKCS12 파일 대신 JKS 파일을 사용해 보았는데 같은 오류가 발생했습니다. – dbush

+1

그래서 저는 이것으로 돌아와 PKCS12에서 JKS로 전환했습니다. 그리고 지금은 작동 중입니다. 원래 JKS 파일의 실패 원인을 정확히 알지 못합니다. – dbush

답변

0

당신은 HTTPS를 사용하도록 설정

server: 
    ssl: 
    enabled: ${SSL_ENABLED:true} 
    key-store: classpath:certificate.p12 
    key-store-password: edgepay123 
    key-store-type: PKCS12 
    key-alias: 1 

그것은 당신이 또한 봄 부트 보안

다음과 같은 의존성을 사용하는 server.ssl.key 매장-type 속성 누락 보인다 위해 application.yml에서 다음과 같은 속성을 추가 할 필요가 대신 당신이이 특성을 가진 키 스토어 당신은 위치를 추가
+1

실제로 server.ssl.key-store-type 속성을 포함 시켰습니다. 설정을 복사/붙여 넣을 때 나는 그 라인을 놓쳤습니다. 나는 반영하기 위해 편집했다. 또한 org.springframework.boot : org 대신 spring-boot-starter-security를 ​​시도했습니다.springframework.security : spring-security-core 그러나 같은 결과를 얻었습니다. – dbush

0

을 사용하는 봄 보안 의존성의
<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 

: server.ssl.key 매장 = 클래스 경로 : keystore.p12 봄 부팅 클래스 경로는 src/main/resources 폴더입니다. 아래 그림과 같이 폴더에 키를 입력하십시오.