@@ -130,79 +130,76 @@ object FakeChainedKeyStore {
130130 val certInfo = new X509CertInfo ()
131131
132132 // Serial number and version
133- certInfo.set( X509CertInfo . SERIAL_NUMBER , new CertificateSerialNumber (new BigInteger (64 , new SecureRandom ())))
134- certInfo.set( X509CertInfo . VERSION , new CertificateVersion (CertificateVersion .V3 ))
133+ certInfo.setSerialNumber( new CertificateSerialNumber (new BigInteger (64 , new SecureRandom ())))
134+ certInfo.setVersion( new CertificateVersion (CertificateVersion .V3 ))
135135
136136 // Validity
137137 val validFrom = new Date ()
138138 val validTo = new Date (validFrom.getTime + 50L * 365L * 24L * 60L * 60L * 1000L )
139139 val validity = new CertificateValidity (validFrom, validTo)
140- certInfo.set( X509CertInfo . VALIDITY , validity)
140+ certInfo.setValidity( validity)
141141
142142 // Subject and issuer
143143 val certificateAuthorityName = new X500Name (CA .DistinguishedName )
144- certInfo.set( X509CertInfo . ISSUER , certificateAuthorityName)
144+ certInfo.setIssuer( certificateAuthorityName)
145145 val owner = new X500Name (User .DistinguishedName )
146- certInfo.set( X509CertInfo . SUBJECT , owner)
146+ certInfo.setSubject( owner)
147147
148148 // Key and algorithm
149- certInfo.set( X509CertInfo . KEY , new CertificateX509Key (userKeyPair.getPublic))
149+ certInfo.setKey( new CertificateX509Key (userKeyPair.getPublic))
150150 val algorithm = AlgorithmId .get(" SHA256WithRSA" )
151- certInfo.set( X509CertInfo . ALGORITHM_ID , new CertificateAlgorithmId (algorithm))
151+ certInfo.setAlgorithmId( new CertificateAlgorithmId (algorithm))
152152
153153 // Create a new certificate and sign it
154- val cert = new X509CertImpl (certInfo)
155- cert.sign(userKeyPair.getPrivate, KeystoreSettings .SignatureAlgorithmName )
154+ val cert = X509CertImpl .newSigned(certInfo, userKeyPair.getPrivate, KeystoreSettings .SignatureAlgorithmName )
156155
157156 // Since the signature provider may have a different algorithm ID to what we think it should be,
158157 // we need to reset the algorithm ID, and resign the certificate
159- val actualAlgorithm = cert.get( X509CertImpl . SIG_ALG ). asInstanceOf [ AlgorithmId ]
160- certInfo.set( CertificateAlgorithmId . NAME + " . " + CertificateAlgorithmId . ALGORITHM , actualAlgorithm)
161- val newCert = new X509CertImpl (certInfo)
162- newCert.sign( certificateAuthorityKeyPair.getPrivate, KeystoreSettings .SignatureAlgorithmName )
158+ val actualAlgorithm = cert.getSigAlg
159+ certInfo.setAlgorithmId( new CertificateAlgorithmId ( actualAlgorithm) )
160+ val newCert =
161+ X509CertImpl .newSigned(certInfo, certificateAuthorityKeyPair.getPrivate, KeystoreSettings .SignatureAlgorithmName )
163162 newCert
164163 }
165164
166165 @ deprecated(" Uses internal sun.security.x509 classes. Java 17 requires add-exports flags; Java 21 fails." , " 0.7.0" )
167166 private def createCertificateAuthority (keyPair : KeyPair ): X509Certificate = {
168167 val certInfo = new X509CertInfo ()
169168 // Serial number and version
170- certInfo.set( X509CertInfo . SERIAL_NUMBER , new CertificateSerialNumber (new BigInteger (64 , new SecureRandom ())))
171- certInfo.set( X509CertInfo . VERSION , new CertificateVersion (CertificateVersion .V3 ))
169+ certInfo.setSerialNumber( new CertificateSerialNumber (new BigInteger (64 , new SecureRandom ())))
170+ certInfo.setVersion( new CertificateVersion (CertificateVersion .V3 ))
172171
173172 // Validity
174173 val validFrom = new Date ()
175174 val validTo = new Date (validFrom.getTime + 50L * 365L * 24L * 60L * 60L * 1000L ) // 50 years
176175 val validity = new CertificateValidity (validFrom, validTo)
177- certInfo.set( X509CertInfo . VALIDITY , validity)
176+ certInfo.setValidity( validity)
178177
179178 // Subject and issuer
180179 val owner = new X500Name (CA .DistinguishedName )
181- certInfo.set( X509CertInfo . SUBJECT , owner)
182- certInfo.set( X509CertInfo . ISSUER , owner)
180+ certInfo.setSubject( owner)
181+ certInfo.setIssuer( owner)
183182
184183 // Key and algorithm
185- certInfo.set( X509CertInfo . KEY , new CertificateX509Key (keyPair.getPublic))
184+ certInfo.setKey( new CertificateX509Key (keyPair.getPublic))
186185 val algorithm = AlgorithmId .get(" SHA256WithRSA" )
187- certInfo.set( X509CertInfo . ALGORITHM_ID , new CertificateAlgorithmId (algorithm))
186+ certInfo.setAlgorithmId( new CertificateAlgorithmId (algorithm))
188187
189188 val caExtension = new CertificateExtensions
190- caExtension.set (
189+ caExtension.setExtension (
191190 BasicConstraintsExtension .NAME ,
192191 new BasicConstraintsExtension ( /* isCritical */ true , /* isCA */ true , 0 )
193192 )
194- certInfo.set( X509CertInfo . EXTENSIONS , caExtension)
193+ certInfo.setExtensions( caExtension)
195194
196195 // Create a new certificate and sign it
197- val cert = new X509CertImpl (certInfo)
198- cert.sign(keyPair.getPrivate, KeystoreSettings .SignatureAlgorithmName )
196+ val cert = X509CertImpl .newSigned(certInfo, keyPair.getPrivate, KeystoreSettings .SignatureAlgorithmName )
199197
200198 // Since the signature provider may have a different algorithm ID to what we think it should be,
201199 // we need to reset the algorithm ID, and resign the certificate
202- val actualAlgorithm = cert.get(X509CertImpl .SIG_ALG ).asInstanceOf [AlgorithmId ]
203- certInfo.set(CertificateAlgorithmId .NAME + " ." + CertificateAlgorithmId .ALGORITHM , actualAlgorithm)
204- val newCert = new X509CertImpl (certInfo)
205- newCert.sign(keyPair.getPrivate, KeystoreSettings .SignatureAlgorithmName )
200+ val actualAlgorithm = cert.getSigAlg
201+ certInfo.setAlgorithmId(new CertificateAlgorithmId (actualAlgorithm))
202+ val newCert = X509CertImpl .newSigned(certInfo, keyPair.getPrivate, KeystoreSettings .SignatureAlgorithmName )
206203 newCert
207204 }
208205
0 commit comments