别名mykey的SAML-Key没有私钥

时间:2016-05-25 03:53:10

标签: ssl java-ee spring-security spring-boot spring-saml

我正在尝试使用saml修改spring-boot安全性的示例程序。 https://github.com/vdenotaris/spring-boot-security-saml-sample。我从我的身份提供程序获得了证书(.crt),我尝试创建一个示例密钥库(.jks)来测试我的连接,然后再集成到我的应用程序中。 我按照以下步骤创建证书。

创建密钥库

keytool -keystore mykeystore.jks -genkey -alias saml

当我尝试列出我的密钥库时,我有一个私钥

列出密钥库

keytool -list -V -storepass changeit -keystore mykeystore.jks

我使用以下命令导入了IDP团队提供的证书。

keytool -import -file myidp.crt -storepass changeit -keystore mykeystore.jks

现在,当我列出我的jks文件时,我有两个私人条目。

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 2 entries

Alias name: saml
Creation date: May 24, 2016
Entry type: PrivateKeyEntry
XXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXX
*******************************************
*******************************************
Alias name: mykey
Creation date: May 24, 2016
Entry type: trustedCertEntry
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*******************************************
*******************************************

我修改了WebSecurityConfi.java类,在将crt导入密钥库时没有给出任何密码短语。我试图将别名保持为相同,但后来我遇到了错误。

keytool error: java.lang.Exception: **Public keys in reply and keystore don't match

  @Bean
    public KeyManager keyManager() {
        DefaultResourceLoader loader = new DefaultResourceLoader();
        Resource storeFile =   loader.getResource("classpath:/saml/myKeystore.jks");

        String storePass = "changeit";
        Map<String, String> passwords = new HashMap<>();
        passwords.put("changeit", "changeit");
        String defaultKey = "mykey";
        return new JKSKeyManager(storeFile, storePass, passwords, defaultKey);
    }

现在我遇到异常,我知道这是我的JKS创建的一些问题。您能否建议如何为我信任的商店添加私钥。我只从IDP提供商那里收到了.crt文件。我是否必须执行任何其他步骤才能为我信任的商店添加私钥?我检查过像Key with alias xxx doesn't have a private key with Spring SAML这样的帖子类似于我的问题,但我无法弄清楚证书创建的问题。

  

ERROR [http-nio-8080-exec-4](DirectJDKLog.java:182) - servlet [dispatcherServlet]的Servlet.service()在上下文中,路径[]引发了异常   java.lang.RuntimeException:带别名的密钥mykey没有私钥       在org.springframework.security.saml.metadata.MetadataGenerator.getServerKeyInfo(MetadataGenerator.java:209)       在org.springframework.security.saml.metadata.MetadataGenerator.buildSPSSODescriptor(MetadataGenerator.java:329)       在org.springframework.security.saml.metadata.MetadataGenerator.generateMetadata(MetadataGenerator.java:189)       在org.springframework.security.saml.metadata.MetadataGeneratorFilter.processMetadataInitialization(MetadataGeneratorFilter.java:127)       在org.springframework.security.saml.metadata.MetadataGeneratorFilter.doFilter(MetadataGeneratorFilter.java:86)       在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)       在org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)       在org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)       在org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)       在org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)       在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)       在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)       在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)       在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)       在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)       在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)       在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)       在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)       在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)       at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:674)       在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1500)       在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1456)       在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(TaskThread.java:61)       在java.lang.Thread.run(Thread.java:745)   DEBUG [http-nio-8080-exec-4](DispatcherServlet.java:861) - DispatcherServlet,名称为&#39; dispatcherServlet&#39;处理[/ error]的GET请求   DEBUG [http-nio-8080-exec-4](AbstractHandlerMethodMapping.java:318) - 查找路径/错误的处理程序方法   DEBUG [http-nio-8080-exec-4](AbstractHandlerMethodMapping.java:325) - 返回处理程序方法[public org.springframework.http.ResponseEntity&gt; org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)]   DEBUG [http-nio-8080-exec-4](AbstractBeanFactory.java:251) - 返回单例bean的缓存实例&#39; basicErrorController&#39;   DEBUG [http-nio-8080-exec-4](DispatcherServlet.java:947) - [/ error]的Last-Modified值为:-1   DEBUG [http-nio-8080-exec-4](AbstractMessageConverterMethodProcessor.java:225) - 写的[{timestamp = Tue May 24 19:12:00 IST 2016,status = 500,error = Internal Server Error,exception = java。 lang.RuntimeException,message =带别名的密钥mykey没有私钥,path = / favicon.ico}]&#34; application / json; charset = UTF-8&#34;使用[org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@380682cd]   DEBUG [http-nio-8080-exec-4](DispatcherServlet.java:1034) - Null ModelAndView返回DispatcherServlet,名称为&#39; dispatcherServlet&#39 ;:假设HandlerAdapter已完成请求处理

2 个答案:

答案 0 :(得分:0)

您需要使用与私钥相同的别名导入签名证书。

  

现在,当我列出我的jks文件时,我有两个条目,一个私人

你应该只有一个私人。

答案 1 :(得分:-1)

您的密钥库中可以包含任意数量的私钥条目...但是您只能配置一个私钥来弹出saml ...您的私钥应该是Entry type: PrivateKeyEntry类型..并更新您的弹簧-security.xml具有私钥的别名。例如。

<!-- Central storage of cryptographic keys -->
            <bean id="keyManager" class="org.springframework.security.saml.key.JKSKeyManager">
                <constructor-arg value="classpath:keycloak.jks"/>
                <constructor-arg type="java.lang.String" value="password"/>
                <constructor-arg>
                    <map>
                        <entry key="YOUR_ALIAS" value="password"/>
                    </map>
                </constructor-arg>
                <constructor-arg type="java.lang.String" value="YOUR_ALIAS"/>
            </bean>