42 lines
881 B
Go
42 lines
881 B
Go
package admin
|
|
|
|
import (
|
|
"context"
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/integration"
|
|
"forge.cadoles.com/cadoles/bouncer/internal/jwk"
|
|
"github.com/pkg/errors"
|
|
"gitlab.com/wpetit/goweb/logger"
|
|
)
|
|
|
|
func (s *Server) initPrivateKey(ctx context.Context) error {
|
|
localKey, err := jwk.LoadOrGenerate(string(s.serverConfig.Auth.PrivateKey), jwk.DefaultKeySize)
|
|
if err != nil {
|
|
return errors.WithStack(err)
|
|
}
|
|
|
|
ctx = integration.WithPrivateKey(ctx, localKey)
|
|
|
|
key, err := integration.RunOnKeyLoad(ctx, s.integrations)
|
|
if err != nil {
|
|
return errors.WithStack(err)
|
|
}
|
|
|
|
if key != nil {
|
|
s.privateKey = key
|
|
} else {
|
|
s.privateKey = localKey
|
|
}
|
|
|
|
logger.Info(ctx, "using private key", logger.F("keyID", s.privateKey.KeyID()))
|
|
|
|
publicKeys, err := jwk.PublicKeySet(s.privateKey)
|
|
if err != nil {
|
|
return errors.WithStack(err)
|
|
}
|
|
|
|
s.publicKeys = publicKeys
|
|
|
|
return nil
|
|
}
|