Skip to content

Commit a553ce2

Browse files
xingzhang-suseBinX-Suse
authored andcommitted
NVSHAS-9788: Refine algorithm for generating certificate
1 parent ae41edd commit a553ce2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

admin/src/main/scala/com/neu/core/MySslConfiguration.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import javax.net.ssl.{
2727
TrustManagerFactory
2828
}
2929
import scala.jdk.CollectionConverters.*
30+
import java.security.SecureRandom
3031

3132
object NoOperationSSLContext {
3233
def init(): Unit = {
@@ -156,7 +157,11 @@ trait MySslConfiguration extends LazyLogging {
156157

157158
private def loadCertificateAndKey(fCert: File, fKey: File, context: SSLContext): SSLContext = {
158159

159-
val password = Array('n', 'e', 'u', 'v', 'e', 'c', 't', 'o', 'r')
160+
val secureRandom = new SecureRandom()
161+
val randomBytes = new Array[Byte](20)
162+
secureRandom.nextBytes(randomBytes)
163+
val encoded = Base64.getEncoder.encodeToString(randomBytes)
164+
val password: Array[Char] = encoded.toCharArray
160165
val cf: CertificateFactory = CertificateFactory.getInstance("X.509")
161166
val trustManagerFactory = TrustManagerFactory.getInstance("PKIX")
162167
val keyManagerFactory = KeyManagerFactory.getInstance("PKIX")

0 commit comments

Comments
 (0)