Skip to content

Commit

Permalink
Add single user key
Browse files Browse the repository at this point in the history
  • Loading branch information
BoThe1K committed Jan 7, 2025
1 parent d564291 commit 2b6acb1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
10 changes: 0 additions & 10 deletions config/sds.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"crypto/rand"
"encoding/hex"
"fmt"

Expand All @@ -14,8 +13,6 @@ type Sds struct {
Enabled bool
// PrivateKey is the secret that will be used to sign uploading file to SDS (hex value, 0x not required)
PrivateKey string
// SUMKey (Spfs user management key) is a secret for folder hashing for user management
SUMKey string
// RPC for pp node (where it will be uploaded/dowloaded), multiaddr format
RPC string
}
Expand Down Expand Up @@ -53,16 +50,9 @@ func sdsConfig() Sds {
w, _ := fwsecp256k1.GenerateKey()
pkStr := "0x" + hex.EncodeToString(w.Bytes())

secret := make([]byte, 32)
_, err := rand.Read(secret)
if err != nil {
panic("failed to create secret for SUMKey")
}
sumKey := hex.EncodeToString(secret)
return Sds{
Enabled: false,
PrivateKey: pkStr,
SUMKey: sumKey,
RPC: "/ip4/127.0.0.1/tcp/18281/http",
}
}
6 changes: 3 additions & 3 deletions core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func spfsCreateUserFolder(cfg *config.Config, req *cmds.Request, root *mfs.Root,
if cfg.Sds.Enabled {
userId, _ := req.Options[sds.OptionSpfsUserId].(string)
if userId != "" {
dir := sds.GenerateUserMFSHash(userId, cfg.Sds.SUMKey)
dir := sds.GenerateUserMFSHash(userId, "sds")
err := mfs.Mkdir(root, "/"+dir, mfs.MkdirOpts{
Mkparents: false,
Flush: flush,
Expand All @@ -174,7 +174,7 @@ func spfsIsAllowed(cfg *config.Config, req *cmds.Request, path string) bool {
if len(spltPath) == 0 {
return true
}
uPath := sds.GenerateUserMFSHash(userId, cfg.Sds.SUMKey)
uPath := sds.GenerateUserMFSHash(userId, "sds")
if strings.Contains(spltPath[0], uPath) {
return false
}
Expand All @@ -187,7 +187,7 @@ func spfsPath(cfg *config.Config, req *cmds.Request, path string) string {
if cfg.Sds.Enabled {
userId, _ := req.Options[sds.OptionSpfsUserId].(string)
if userId != "" {
dir := sds.GenerateUserMFSHash(userId, cfg.Sds.SUMKey)
dir := sds.GenerateUserMFSHash(userId, "sds")
path = fmt.Sprintf("/%s%s", dir, strings.TrimRight(path, "/"))
}
}
Expand Down

0 comments on commit 2b6acb1

Please sign in to comment.