Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base 076 2 #129

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DeOSS ( Decentralized Object Storage Service ) is a decentralized object-based mass storage service that provides low-cost, secure and scalable distributed data storage services for the web3 domain.

## 📝 Reporting a Vulnerability
If you find any system errors or you have better suggestions, please submit an issue or submit a pull request. You can also join the [CESS discord](https://discord.gg/mYHTMfBwNS) to communicate with us.
If you find any system errors or you have better suggestions, please submit an issue or PR, or join the [CESS discord](https://discord.gg/mYHTMfBwNS) to communicate with us.

## 📢 Announcement
### CESS test network rpc endpoints
Expand Down Expand Up @@ -89,15 +89,15 @@ service iptables restart
### Method one
Download the latest release of the binary application directly at:
```
wget https://github.com/CESSProject/DeOSS/releases/download/v0.3.3/DeOSS0.3.3.linux-amd64.tar.gz
wget https://github.com/CESSProject/DeOSS/releases/download/v0.3.4/DeOSS0.3.4.linux-amd64.tar.gz
```

### Method two
Compile the binary program from the DeOSS source code and follow the process as follows:

**1) install go**

DeOSS requires [Go 1.20](https://golang.org/dl/) or higher, See the [official Golang installation instructions](https://golang.org/doc/install).
DeOSS requires [Go 1.20](https://golang.org/dl/), See the [official Golang installation instructions](https://golang.org/doc/install).

Open go mod mode:
```
Expand Down Expand Up @@ -146,23 +146,23 @@ Use `deoss` to generate configuration file templates directly in the current dir
The contents of the configuration file template are as follows. The contents inside are the defaults and you will need to modify them as appropriate. By default, `deoss` uses `conf.yaml` in the current directory as the runtime configuration file. You can use `-c` or `-config` to specify the location of the configuration file.

```yaml
# The rpc endpoint of the chain node
# RPC endpoint of the chain node
Rpc:
# test network
- "wss://testnet-rpc0.cess.cloud/ws/"
- "wss://testnet-rpc1.cess.cloud/ws/"
- "wss://testnet-rpc2.cess.cloud/ws/"
# Bootstrap Nodes
# bootstrap nodes
Boot:
# test network
- "_dnsaddr.boot-kldr-testnet.cess.cloud"
# Account mnemonic
- "_dnsaddr.boot-bucket-testnet.cess.cloud"
# signature account mnemonic
Mnemonic: "xxx xxx ... xxx"
# Service workspace
# service workspace
Workspace: /
# P2P communication port
P2P_Port: 4001
# Service listening port
# service listening port
HTTP_Port: 8080
# Access mode: public / private
# In public mode, only users in Accounts can't access it.
Expand Down
4 changes: 3 additions & 1 deletion configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ const (

const FileCacheExpirationTime = 720

const MaxTrackThread = 10

// Time out waiting for transaction completion
const TimeOut_WaitBlock = time.Duration(time.Second * 15)
const TimeOut_WaitBlock = time.Duration(time.Second * 30)

const DefaultConfig = "conf.yaml"

Expand Down
2 changes: 1 addition & 1 deletion configs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
// Name space
NameSpace = Name
// version
Version = Name + " " + "v0.3.5"
Version = Name + " " + "v0.3.5 pre-release"
// description
Description = "Object storage service based on CESS network"
)
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ go 1.20

require (
github.com/AstaFrode/go-libp2p v0.26.4-0.20231113143058-912296254d44
github.com/CESSProject/cess-go-sdk v0.4.19
github.com/CESSProject/cess-go-sdk v0.4.22
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde
github.com/CESSProject/p2p-go v0.2.11
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/cbergoon/merkletree v0.2.0
github.com/centrifuge/go-substrate-rpc-client/v4 v4.2.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-contrib/cors v1.5.0
github.com/gin-gonic/gin v1.9.1
github.com/google/uuid v1.5.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ github.com/AstaFrode/go-peertaskqueue v0.8.2-0.20231108073729-990e433425a4 h1:fu
github.com/AstaFrode/go-peertaskqueue v0.8.2-0.20231108073729-990e433425a4/go.mod h1:0YcQDsyTRKBTK9yE22DQgiwQndGFvenqMvD6Spkxl28=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/CESSProject/cess-go-sdk v0.4.19 h1:p9BnqW18eJBT/E6yK9gUuum34X/ChxAjN/hDhlZZCS4=
github.com/CESSProject/cess-go-sdk v0.4.19/go.mod h1:IamF02Ng+FQvThFbQRtpEpPzmlPOXqQzgaF9YDE0YhY=
github.com/CESSProject/cess-go-sdk v0.4.22 h1:d9xnRHaaudntJEHy0cCXysuNfj+cfvfdOs3QsLnF21o=
github.com/CESSProject/cess-go-sdk v0.4.22/go.mod h1:IamF02Ng+FQvThFbQRtpEpPzmlPOXqQzgaF9YDE0YhY=
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde h1:5MDRjjtg6PEhqyVjupwaapN96cOZiddOGAYwKQeaTu0=
github.com/CESSProject/go-keyring v0.0.0-20220614131247-ee3a8da30fde/go.mod h1:RUXBd3ROP98MYepEEa0Y0l/T0vQlIKqFJxI/ocdnRLM=
github.com/CESSProject/p2p-go v0.2.11 h1:2o1YzM1YcJhVsZYLAuyWKJ4ib3WA3Qpt6pllVlmKzik=
Expand Down Expand Up @@ -106,8 +106,6 @@ github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5il
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
Expand Down
62 changes: 62 additions & 0 deletions inter/trackfile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright (C) CESS. All rights reserved.
Copyright (C) Cumulus Encrypted Storage System. All rights reserved.

SPDX-License-Identifier: Apache-2.0
*/

package inter

import (
"errors"
"sync"

"github.com/CESSProject/DeOSS/configs"
)

type TrackFile interface {
AddTrackFile(fid string) error
GetTrackFileNum() int
DelTrackFile(fid string)
}

type TrackFileType struct {
lock *sync.RWMutex
trackFiles map[string]struct{}
}

var _ TrackFile = (*TrackFileType)(nil)

func NewTeeRecord() TrackFile {
return &TrackFileType{
lock: new(sync.RWMutex),
trackFiles: make(map[string]struct{}, configs.MaxTrackThread),
}
}

func (t *TrackFileType) AddTrackFile(fid string) error {
t.lock.Lock()
defer t.lock.Unlock()
if len(t.trackFiles) >= configs.MaxTrackThread {
return errors.New("track queue is full")
}
_, ok := t.trackFiles[fid]
if ok {
return errors.New("already in track")
}
t.trackFiles[fid] = struct{}{}
return nil
}

func (t *TrackFileType) GetTrackFileNum() int {
t.lock.RLock()
result := len(t.trackFiles)
t.lock.RUnlock()
return result
}

func (t *TrackFileType) DelTrackFile(fid string) {
t.lock.Lock()
delete(t.trackFiles, fid)
t.lock.Unlock()
}
113 changes: 0 additions & 113 deletions node/authHandle.go

This file was deleted.

76 changes: 25 additions & 51 deletions node/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,49 @@ package node
import (
"encoding/hex"
"fmt"
"net/http"
"strings"

"github.com/CESSProject/DeOSS/configs"
sutils "github.com/CESSProject/cess-go-sdk/utils"
"github.com/CESSProject/go-keyring"
jwt "github.com/dgrijalva/jwt-go"
"github.com/mr-tron/base58"
"github.com/pkg/errors"
"github.com/vedhavyas/go-subkey/v2/sr25519"
)

// VerifyToken is used to parse and verify token
func (n *Node) verifyToken(token string, respmsg *RespMsg) (string, []byte, error) {
var (
ok bool
err error
claims *CustomClaims
jwttoken *jwt.Token
account string
)

if respmsg.Err != nil {
return account, nil, err
}

if token == "" {
respmsg.Code = http.StatusForbidden
respmsg.Err = errors.New(ERR_Authorization)
return account, nil, respmsg.Err
}

// parse token
jwttoken, err = jwt.ParseWithClaims(
token,
&CustomClaims{},
func(token *jwt.Token) (interface{}, error) {
return n.signkey, nil
})
if err != nil {
respmsg.Code = http.StatusForbidden
respmsg.Err = errors.New(ERR_Authorization)
return account, nil, respmsg.Err
func (n *Node) verifyAccountSignature(account, msg, signature string) ([]byte, error) {
var err error
var publicKey []byte
if account == "" {
return nil, errors.New("Account is missing in request header")
}

if claims, ok = jwttoken.Claims.(*CustomClaims); ok && jwttoken.Valid {
account = claims.Account
} else {
respmsg.Code = http.StatusForbidden
respmsg.Err = errors.New(ERR_NoPermission)
return account, nil, err
if msg == "" {
return nil, errors.New("Message is missing in request header")
}
pkey, err := sutils.ParsingPublickey(account)
if signature == "" {
return nil, errors.New("Signature is missing in request header")
}
publicKey, err = n.verifySignature(account, msg, signature)
if err == nil {
return publicKey, nil
}
publicKey, err = n.verifySR25519Signature(account, msg, signature)
if err == nil {
return publicKey, nil
}
publicKey, err = n.verifyJsSignatureHex(account, msg, signature)
if err == nil {
return publicKey, nil
}
publicKey, err = n.verifyJsSignatureBase58(account, msg, signature)
if err != nil {
respmsg.Code = http.StatusBadRequest
respmsg.Err = errors.New(ERR_InvalidToken)
return account, nil, err
return nil, errors.New("Signature verification failed")
}

respmsg.Code = http.StatusOK
respmsg.Err = nil
return account, pkey, nil
return publicKey, nil
}

// VerifyToken is used to parse and verify token
func (n *Node) verifySignature(account, message, signature string) ([]byte, error) {
if account == "" || signature == "" {
return nil, errors.New("no identity authentication information")
}
pkey, err := sutils.ParsingPublickey(account)
if err != nil {
return nil, err
Expand Down
Loading