@@ -73,12 +73,10 @@ final class FileWatcherCertificateProvider extends CertificateProvider implement
7373 this .scheduledExecutorService =
7474 checkNotNull (scheduledExecutorService , "scheduledExecutorService" );
7575 this .timeProvider = checkNotNull (timeProvider , "timeProvider" );
76- checkArgument (((certFile != null ) == (keyFile != null )),
77- "certFile and keyFile must be both set or both unset" );
78- this .certFile = certFile == null ? null : Paths .get (certFile );
79- this .keyFile = keyFile == null ? null : Paths .get (keyFile );
80- checkArgument ((trustFile != null || spiffeTrustMapFile != null || keyFile != null ),
81- "must be watching either root or identity certificates" );
76+ this .certFile = Paths .get (checkNotNull (certFile , "certFile" ));
77+ this .keyFile = Paths .get (checkNotNull (keyFile , "keyFile" ));
78+ checkArgument ((trustFile != null || spiffeTrustMapFile != null ),
79+ "either trustFile or spiffeTrustMapFile must be present" );
8280 if (spiffeTrustMapFile != null ) {
8381 this .spiffeTrustMapFile = Paths .get (spiffeTrustMapFile );
8482 this .trustFile = null ;
@@ -115,26 +113,23 @@ private synchronized void scheduleNextRefreshCertificate(long delayInSeconds) {
115113 void checkAndReloadCertificates () {
116114 try {
117115 try {
118- if (certFile != null && keyFile != null ) {
119- FileTime currentCertTime = Files .getLastModifiedTime (certFile );
120- FileTime currentKeyTime = Files .getLastModifiedTime (keyFile );
121- if (!currentCertTime .equals (lastModifiedTimeCert )
122- && !currentKeyTime .equals (lastModifiedTimeKey )) {
123- byte [] certFileContents = Files .readAllBytes (certFile );
124- byte [] keyFileContents = Files .readAllBytes (keyFile );
125- FileTime currentCertTime2 = Files .getLastModifiedTime (certFile );
126- FileTime currentKeyTime2 = Files .getLastModifiedTime (keyFile );
127- if (currentCertTime2 .equals (currentCertTime )
128- && currentKeyTime2 .equals (currentKeyTime )) {
129- try (ByteArrayInputStream certStream = new ByteArrayInputStream (certFileContents );
130- ByteArrayInputStream keyStream = new ByteArrayInputStream (keyFileContents )) {
131- PrivateKey privateKey = CertificateUtils .getPrivateKey (keyStream );
132- X509Certificate [] certs = CertificateUtils .toX509Certificates (certStream );
133- getWatcher ().updateCertificate (privateKey , Arrays .asList (certs ));
134- }
135- lastModifiedTimeCert = currentCertTime ;
136- lastModifiedTimeKey = currentKeyTime ;
116+ FileTime currentCertTime = Files .getLastModifiedTime (certFile );
117+ FileTime currentKeyTime = Files .getLastModifiedTime (keyFile );
118+ if (!currentCertTime .equals (lastModifiedTimeCert )
119+ && !currentKeyTime .equals (lastModifiedTimeKey )) {
120+ byte [] certFileContents = Files .readAllBytes (certFile );
121+ byte [] keyFileContents = Files .readAllBytes (keyFile );
122+ FileTime currentCertTime2 = Files .getLastModifiedTime (certFile );
123+ FileTime currentKeyTime2 = Files .getLastModifiedTime (keyFile );
124+ if (currentCertTime2 .equals (currentCertTime ) && currentKeyTime2 .equals (currentKeyTime )) {
125+ try (ByteArrayInputStream certStream = new ByteArrayInputStream (certFileContents );
126+ ByteArrayInputStream keyStream = new ByteArrayInputStream (keyFileContents )) {
127+ PrivateKey privateKey = CertificateUtils .getPrivateKey (keyStream );
128+ X509Certificate [] certs = CertificateUtils .toX509Certificates (certStream );
129+ getWatcher ().updateCertificate (privateKey , Arrays .asList (certs ));
137130 }
131+ lastModifiedTimeCert = currentCertTime ;
132+ lastModifiedTimeKey = currentKeyTime ;
138133 }
139134 }
140135 } catch (Throwable t ) {
0 commit comments