21
21
import org .jboss .netty .handler .ssl .util .SelfSignedCertificate ;
22
22
import org .slf4j .Logger ;
23
23
import org .slf4j .LoggerFactory ;
24
+ import org .springframework .beans .factory .annotation .Value ;
24
25
import org .springframework .stereotype .Service ;
25
- import org .springframework .util .Base64Utils ;
26
26
27
27
import java .io .ByteArrayInputStream ;
28
28
import java .io .File ;
@@ -54,6 +54,9 @@ public class GatewayKeystoreService {
54
54
private static final String BEGIN_KEY = "-----BEGIN PRIVATE KEY-----" ;
55
55
private static final String END_KEY = "-----END PRIVATE KEY-----" ;
56
56
57
+ @ Value ("${gatewaykeystore.password}" )
58
+ private String password ;
59
+
57
60
public void createSelfSigned () throws Exception {
58
61
if (log .isInfoEnabled ()) {
59
62
log .info ("***generateSelfSigned keys and cert - BEGIN***" );
@@ -74,18 +77,18 @@ public void createSelfSigned() throws Exception {
74
77
.replaceAll (System .lineSeparator (), "" )
75
78
.replace (END_KEY , "" );
76
79
77
- byte [] encoded = Base64Utils . decodeFromString (privateKeyPEM );
80
+ byte [] encoded = Base64 . getDecoder (). decode (privateKeyPEM );
78
81
79
82
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec (encoded );
80
83
KeyFactory kf = KeyFactory .getInstance ("RSA" );
81
84
PrivateKey privKey = kf .generatePrivate (spec );
82
85
83
86
KeyStore keyStore = KeyStore .getInstance ("PKCS12" , "BC" );
84
87
keyStore .load (null , null );
85
- keyStore .setKeyEntry (ICommonConstants .OPENKIM_SERVER_KEYSTORE_ALIAS , privKey , ICommonConstants . OPENKIM_SERVER_KEYSTORE_PWD .toCharArray (), chain );
88
+ keyStore .setKeyEntry (ICommonConstants .OPENKIM_SERVER_KEYSTORE_ALIAS , privKey , password .toCharArray (), chain );
86
89
keyStore .store (
87
90
new FileOutputStream (new File (ICommonConstants .BASE_DIR + ICommonConstants .OPENKIM_SERVER_KEYSTORE_FILENAME )),
88
- ICommonConstants . OPENKIM_SERVER_KEYSTORE_PWD .toCharArray ()
91
+ password .toCharArray ()
89
92
);
90
93
91
94
if (log .isInfoEnabled ()) {
@@ -122,10 +125,10 @@ public void create(GatewayKeystoreData eldixSmtpKeystoreData) throws Exception {
122
125
//write to keystore
123
126
KeyStore keyStore = KeyStore .getInstance ("PKCS12" , "BC" );
124
127
keyStore .load (null , null );
125
- keyStore .setKeyEntry (ICommonConstants .OPENKIM_SERVER_KEYSTORE_ALIAS , privKey , ICommonConstants . OPENKIM_SERVER_KEYSTORE_PWD .toCharArray (), certChain );
128
+ keyStore .setKeyEntry (ICommonConstants .OPENKIM_SERVER_KEYSTORE_ALIAS , privKey , password .toCharArray (), certChain );
126
129
keyStore .store (
127
130
new FileOutputStream (new File (ICommonConstants .BASE_DIR + ICommonConstants .OPENKIM_SERVER_KEYSTORE_FILENAME )),
128
- ICommonConstants . OPENKIM_SERVER_KEYSTORE_PWD .toCharArray ()
131
+ password .toCharArray ()
129
132
);
130
133
131
134
if (log .isInfoEnabled ()) {
0 commit comments