Remove profiles endpoint and textures signing mechanism

This commit is contained in:
ErickSkrauch
2024-06-11 04:35:46 +02:00
parent 62b6ac8083
commit 716ec8bd37
11 changed files with 1 additions and 823 deletions

View File

@@ -12,7 +12,6 @@ func New() (*di.Container, error) {
loggerDiOptions,
mojangDiOptions,
profilesDiOptions,
securityDiOptions,
serverDiOptions,
)
}

View File

@@ -17,13 +17,11 @@ import (
const ModuleSkinsystem = "skinsystem"
const ModuleProfiles = "profiles"
const ModuleSigner = "signer"
var handlersDiOptions = di.Options(
di.Provide(newHandlerFactory, di.As(new(http.Handler))),
di.Provide(newSkinsystemHandler, di.WithName(ModuleSkinsystem)),
di.Provide(newProfilesApiHandler, di.WithName(ModuleProfiles)),
di.Provide(newSignerApiHandler, di.WithName(ModuleSigner)),
)
func newHandlerFactory(
@@ -65,26 +63,6 @@ func newHandlerFactory(
mount(router, "/api/profiles", profilesApiRouter)
}
if slices.Contains(enabledModules, ModuleSigner) {
var signerApiRouter *mux.Router
if err := container.Resolve(&signerApiRouter, di.Name(ModuleSigner)); err != nil {
return nil, err
}
var authenticator Authenticator
if err := container.Resolve(&authenticator); err != nil {
return nil, err
}
authMiddleware := NewAuthenticationMiddleware(authenticator, security.SignScope)
conditionalAuth := NewConditionalMiddleware(func(req *http.Request) bool {
return req.Method != "GET"
}, authMiddleware)
signerApiRouter.Use(conditionalAuth)
mount(router, "/api/signer", signerApiRouter)
}
// Resolve health checkers last, because all the services required by the application
// must first be initialized and each of them can publish its own checkers
var healthCheckers []*namedHealthChecker
@@ -107,14 +85,12 @@ func newHandlerFactory(
func newSkinsystemHandler(
config *viper.Viper,
profilesProvider ProfilesProvider,
texturesSigner SignerService,
) (*mux.Router, error) {
config.SetDefault("textures.extra_param_name", "chrly")
config.SetDefault("textures.extra_param_value", "how do you tame a horse in Minecraft?")
skinsystem, err := NewSkinsystemApi(
profilesProvider,
texturesSigner,
config.GetString("textures.extra_param_name"),
config.GetString("textures.extra_param_value"),
)
@@ -134,15 +110,6 @@ func newProfilesApiHandler(profilesManager ProfilesManager) (*mux.Router, error)
return profilesApi.Handler(), nil
}
func newSignerApiHandler(signer Signer) (*mux.Router, error) {
signerApi, err := NewSignerApi(signer)
if err != nil {
return nil, err
}
return signerApi.Handler(), nil
}
func mount(router *mux.Router, path string, handler http.Handler) {
router.PathPrefix(path).Handler(
http.StripPrefix(

View File

@@ -1,59 +0,0 @@
package di
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"errors"
"log/slog"
"ely.by/chrly/internal/client/signer"
"ely.by/chrly/internal/http"
"ely.by/chrly/internal/security"
"github.com/defval/di"
"github.com/spf13/viper"
)
var securityDiOptions = di.Options(
di.Provide(newSigner,
di.As(new(http.Signer)),
di.As(new(signer.Signer)),
),
di.Provide(newSignerService),
)
func newSigner(config *viper.Viper) (*security.Signer, error) {
var privateKey *rsa.PrivateKey
var err error
keyStr := config.GetString("chrly.signing.key")
if keyStr == "" {
privateKey, err = rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return nil, err
}
slog.Warn("A private signing key has been generated. To make it permanent, specify the valid RSA private key in the config parameter chrly.signing.key")
} else {
keyBytes := []byte(keyStr)
rawPem, _ := pem.Decode(keyBytes)
if rawPem == nil {
return nil, errors.New("unable to decode pem key")
}
privateKey, err = x509.ParsePKCS1PrivateKey(rawPem.Bytes)
if err != nil {
return nil, err
}
}
return security.NewSigner(privateKey), nil
}
func newSignerService(s signer.Signer) http.SignerService {
return &signer.LocalSigner{
Signer: s,
}
}