17
17
package org .springframework .boot .autoconfigure .security .saml2 ;
18
18
19
19
import java .io .InputStream ;
20
- import java .security .cert . CertificateFactory ;
20
+ import java .security .PrivateKey ;
21
21
import java .security .cert .X509Certificate ;
22
22
import java .security .interfaces .RSAPrivateKey ;
23
23
import java .util .Collection ;
32
32
import org .springframework .boot .autoconfigure .security .saml2 .Saml2RelyingPartyProperties .Registration ;
33
33
import org .springframework .boot .autoconfigure .security .saml2 .Saml2RelyingPartyProperties .Registration .Signing ;
34
34
import org .springframework .boot .context .properties .PropertyMapper ;
35
+ import org .springframework .boot .ssl .pem .PemContent ;
35
36
import org .springframework .context .annotation .Bean ;
36
37
import org .springframework .context .annotation .Conditional ;
37
38
import org .springframework .context .annotation .Configuration ;
38
39
import org .springframework .core .io .Resource ;
39
- import org .springframework .security .converter .RsaKeyConverters ;
40
40
import org .springframework .security .saml2 .core .Saml2X509Credential ;
41
41
import org .springframework .security .saml2 .core .Saml2X509Credential .Saml2X509CredentialType ;
42
42
import org .springframework .security .saml2 .provider .service .registration .AssertingPartyMetadata ;
57
57
* @author Moritz Halbritter
58
58
* @author Lasse Lindqvist
59
59
* @author Lasse Wulff
60
+ * @author Scott Frederick
60
61
*/
61
62
@ Configuration (proxyBeanMethods = false )
62
63
@ Conditional (RegistrationConfiguredCondition .class )
@@ -172,7 +173,11 @@ private RSAPrivateKey readPrivateKey(Resource location) {
172
173
Assert .state (location != null , "No private key location specified" );
173
174
Assert .state (location .exists (), () -> "Private key location '" + location + "' does not exist" );
174
175
try (InputStream inputStream = location .getInputStream ()) {
175
- return RsaKeyConverters .pkcs8 ().convert (inputStream );
176
+ PemContent pemContent = PemContent .load (inputStream );
177
+ PrivateKey privateKey = pemContent .getPrivateKey ();
178
+ Assert .isInstanceOf (RSAPrivateKey .class , privateKey ,
179
+ "PrivateKey in resource '" + location + "' must be an RSAPrivateKey" );
180
+ return (RSAPrivateKey ) privateKey ;
176
181
}
177
182
catch (Exception ex ) {
178
183
throw new IllegalArgumentException (ex );
@@ -183,7 +188,9 @@ private X509Certificate readCertificate(Resource location) {
183
188
Assert .state (location != null , "No certificate location specified" );
184
189
Assert .state (location .exists (), () -> "Certificate location '" + location + "' does not exist" );
185
190
try (InputStream inputStream = location .getInputStream ()) {
186
- return (X509Certificate ) CertificateFactory .getInstance ("X.509" ).generateCertificate (inputStream );
191
+ PemContent pemContent = PemContent .load (inputStream );
192
+ List <X509Certificate > certificates = pemContent .getCertificates ();
193
+ return certificates .get (0 );
187
194
}
188
195
catch (Exception ex ) {
189
196
throw new IllegalArgumentException (ex );
0 commit comments