@@ -148,7 +148,7 @@ func factory(name string) geneos.Instance {
148
148
// `config/=config/file` means import file into config/ with no name
149
149
// change
150
150
var ssoagentFiles = []string {
151
- "conf/sso-agent.conf=conf/sso-agent.conf " ,
151
+ "conf" ,
152
152
}
153
153
154
154
// interface method set
@@ -279,46 +279,60 @@ func (s *SSOAgents) Rebuild(initial bool) (err error) {
279
279
}
280
280
}
281
281
282
- // rebuild the keystore (config/keystore.db) is certificate and
283
- // privatekey are defined. This is for client connections to the
284
- // sso-agent and will typically be a "real" certificate.
285
- if ssoconf .IsSet (config .Join ("server" , "key_store" , "location" )) && cf .IsSet ("privatekey" ) {
282
+ // (re)build the keystore (config/keystore.db) ensuring there is
283
+ // always an "ssokey".
284
+ if ssoconf .IsSet (config .Join ("server" , "key_store" , "location" )) {
285
+ var changed bool
286
+
286
287
keyStore := instance .Abs (s , ssoconf .GetString (config .Join ("server" , "key_store" , "location" )))
287
288
log .Debug ().Msgf ("%s: rebuilding keystore: %q" , s .String (), keyStore )
288
- cert , err := config .ParseCertificate (s .Host (), cf .GetString ("certificate" ))
289
- if err != nil {
290
- return err
291
- }
292
- key , err := config .ReadPrivateKey (s .Host (), cf .GetString ("privatekey" ))
293
- if err != nil {
294
- return err
295
- }
296
- chain := []* x509.Certificate {cert }
297
- if cf .IsSet ("certchain" ) {
298
- chain = append (chain , config .ReadCertificates (s .Host (), cf .GetString ("certchain" ))... )
299
- }
300
- keyStorePassword := ssoconf .GetPassword (config .Join ("server" , "key_store" , "password" ), config .Default ("changeit" ))
301
- k , err := geneos .ReadKeystore (s .Host (), keyStore , keyStorePassword )
289
+ ksPassword := ssoconf .GetPassword (config .Join ("server" , "key_store" , "password" ), config .Default ("changeit" ))
290
+ ks , err := geneos .ReadKeystore (s .Host (), keyStore , ksPassword )
302
291
if err != nil {
303
292
// new, empty keystore
304
- k = geneos.KeyStore {
293
+ ks = geneos.KeyStore {
305
294
KeyStore : keystore .New (),
306
295
}
296
+ changed = true
307
297
}
308
- if ! slices .Contains (k .Aliases (), "ssokey" ) {
298
+
299
+ if ! slices .Contains (ks .Aliases (), "ssokey" ) {
309
300
cert , key , err := genkeypair ()
310
301
if err != nil {
311
302
log .Fatal ().Err (err ).Msg ("" )
312
303
}
313
304
chain := []* x509.Certificate {cert }
314
- if err = k .AddKeystoreKey ("ssokey" , key , keyStorePassword , chain ); err != nil {
305
+ if err = ks .AddKeystoreKey ("ssokey" , key , ksPassword , chain ); err != nil {
315
306
log .Fatal ().Err (err ).Msg ("" )
316
307
}
308
+ changed = true
309
+ }
310
+
311
+ // If instance has certificate and private key set, then add
312
+ // this too. This is for client connections to the sso-agent and
313
+ // will typically be a "real" certificate.
314
+ if cf .IsSet ("certficate" ) && cf .IsSet ("privatekey" ) {
315
+ cert , err := config .ParseCertificate (s .Host (), cf .GetString ("certificate" ))
316
+ if err != nil {
317
+ return err
318
+ }
319
+ key , err := config .ReadPrivateKey (s .Host (), cf .GetString ("privatekey" ))
320
+ if err != nil {
321
+ return err
322
+ }
323
+ chain := []* x509.Certificate {cert }
324
+ if cf .IsSet ("certchain" ) {
325
+ chain = append (chain , config .ReadCertificates (s .Host (), cf .GetString ("certchain" ))... )
326
+ }
327
+ alias := geneos .ALL .Hostname ()
328
+ ks .DeleteEntry (alias )
329
+ ks .AddKeystoreKey (alias , key , ksPassword , chain )
330
+ changed = true
331
+ }
332
+
333
+ if changed {
334
+ err = ks .WriteKeystore (s .Host (), keyStore , ksPassword )
317
335
}
318
- alias := geneos .ALL .Hostname ()
319
- k .DeleteEntry (alias )
320
- k .AddKeystoreKey (alias , key , keyStorePassword , chain )
321
- err = k .WriteKeystore (s .Host (), keyStore , keyStorePassword )
322
336
}
323
337
return
324
338
}
@@ -351,8 +365,8 @@ func genkeypair() (cert *x509.Certificate, key *memguard.Enclave, err error) {
351
365
352
366
func (s * SSOAgents ) Command () (args , env []string , home string ) {
353
367
cf := s .Config ()
354
- base := instance .BaseVersion (s )
355
368
home = s .Home ()
369
+ base := instance .BaseVersion (s )
356
370
357
371
args = []string {
358
372
"-classpath" , home + "/conf:" + base + "/lib/*" ,
@@ -366,12 +380,13 @@ func (s *SSOAgents) Command() (args, env []string, home string) {
366
380
args = append (args , javaopts ... )
367
381
368
382
if truststorePath := cf .GetString ("truststore" ); truststorePath != "" {
369
- args = append (args , "-Djavax.net.ssl.trustStore=" + truststorePath )
370
- }
371
-
372
- // fetch password as string as it has to be exposed on the command line anyway
373
- if truststorePassword := cf .GetString ("truststore-password" ); truststorePassword != "" {
374
- args = append (args , "-Djavax.net.ssl.trustStorePassword=" + truststorePassword )
383
+ if _ , err := s .Host ().Stat (truststorePath ); err == nil {
384
+ args = append (args , "-Djavax.net.ssl.trustStore=" + truststorePath )
385
+ // fetch password as string as it has to be exposed on the command line anyway
386
+ if truststorePassword := cf .GetString ("truststore-password" ); truststorePassword != "" {
387
+ args = append (args , "-Djavax.net.ssl.trustStorePassword=" + truststorePassword )
388
+ }
389
+ }
375
390
}
376
391
377
392
// -jar must appear after all options are set otherwise they are
0 commit comments