Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
sidecar
Commits
e86d2fae
Commit
e86d2fae
authored
Oct 22, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
😋
remove old cryptor and latest cryptor
parent
f918c4bc
Pipeline
#8153
canceled with stages
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
86 deletions
+46
-86
sidecar.go
internal/app/sidecar.go
+2
-2
appchain.go
internal/appchain/appchain.go
+4
-2
cryptor.go
internal/txcrypto/cryptor.go
+36
-14
relay_cryptor.go
internal/txcrypto/relay_cryptor.go
+0
-64
txcrypto.go
internal/txcrypto/txcrypto.go
+3
-3
error.go
tool/error.go
+1
-1
No files found.
internal/app/sidecar.go
View file @
e86d2fae
...
...
@@ -59,8 +59,8 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
clients
:=
plugins
.
CreateClients
(
config
.
Appchains
,
nil
)
persister
:=
manger
.
NewPersister
(
addr
.
String
(),
store
,
loggers
.
Logger
(
loggers
.
Manger
))
appchainMgr
:=
appchainmgr
.
New
(
persister
)
cryptor
,
err
:=
txcrypto
.
NewDirectCryptor
(
appchainMgr
,
privateKey
)
tool
.
Asset
(
err
)
// TODO hub client
cryptor
:=
txcrypto
.
NewCryptor
(
nil
,
appchainMgr
,
privateKey
)
clientPort
:=
appchain
.
NewPorts
(
clients
,
cryptor
,
logger
)
r
.
Adds
(
clientPort
)
mg
,
err
:=
manger
.
NewManager
(
addr
.
String
(),
pm
,
appchainMgr
,
loggers
.
Logger
(
loggers
.
Manger
))
...
...
internal/appchain/appchain.go
View file @
e86d2fae
...
...
@@ -12,6 +12,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/link33/sidecar/internal/port"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/internal/txcrypto"
"github.com/link33/sidecar/model/pb"
"github.com/link33/sidecar/pkg/plugins"
...
...
@@ -150,7 +151,8 @@ func (a *appChain) applyReceiptIBTP(ibtp *pb.IBTP) error {
var
err
error
if
pd
.
Encrypted
{
contentByte
,
err
=
a
.
cryptor
.
Decrypt
(
contentByte
,
ibtp
.
To
)
// TODO
contentByte
,
err
=
a
.
cryptor
.
Decrypt
(
contentByte
,
ibtp
.
To
,
repo
.
DirectMode
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"decrypt ibtp payload content: %w"
,
err
)
}
...
...
@@ -340,7 +342,7 @@ func (a *appChain) encryption(ibtp *pb.IBTP) error {
return
nil
}
ctb
,
err
:=
a
.
cryptor
.
Encrypt
(
pld
.
Content
,
ibtp
.
To
)
ctb
,
err
:=
a
.
cryptor
.
Encrypt
(
pld
.
Content
,
ibtp
.
To
,
repo
.
DirectMode
)
if
err
!=
nil
{
return
err
}
...
...
internal/txcrypto/
direct_
cryptor.go
→
internal/txcrypto/cryptor.go
View file @
e86d2fae
...
...
@@ -8,45 +8,67 @@ import (
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/meshplus/bitxhub-kit/crypto/ecdh"
"github.com/meshplus/bitxhub-kit/crypto/sym"
rpcx
"github.com/link33/sidecar/hub/client"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/model/constant"
)
type
DirectCryptor
struct
{
mgr
appchainmgr
.
AppchainMgr
type
cryptor
struct
{
client
rpcx
.
Client
mgr
appchainmgr
.
AppchainMgr
privKey
crypto
.
PrivateKey
keyMap
map
[
string
][]
byte
}
func
New
DirectCryptor
(
mgr
appchainmgr
.
AppchainMgr
,
privKey
crypto
.
PrivateKey
)
(
Cryptor
,
error
)
{
func
New
Cryptor
(
client
rpcx
.
Client
,
mgr
appchainmgr
.
AppchainMgr
,
privKey
crypto
.
PrivateKey
)
Cryptor
{
keyMap
:=
make
(
map
[
string
][]
byte
)
return
&
DirectCryptor
{
mgr
:
mgr
,
return
&
cryptor
{
client
:
client
,
mgr
:
mgr
,
privKey
:
privKey
,
keyMap
:
keyMap
,
}
,
nil
}
}
func
(
d
*
DirectCryptor
)
Encrypt
(
content
[]
byte
,
address
string
)
([]
byte
,
error
)
{
des
,
err
:=
d
.
getDesKey
(
address
)
func
(
d
*
cryptor
)
Encrypt
(
content
[]
byte
,
address
string
,
mode
string
)
([]
byte
,
error
)
{
des
,
err
:=
d
.
getDesKey
(
address
,
mode
)
if
err
!=
nil
{
return
nil
,
err
}
return
des
.
Encrypt
(
content
)
}
func
(
d
*
DirectCryptor
)
Decrypt
(
content
[]
byte
,
address
string
)
([]
byte
,
error
)
{
des
,
err
:=
d
.
getDesKey
(
address
)
func
(
d
*
cryptor
)
Decrypt
(
content
[]
byte
,
address
string
,
mode
string
)
([]
byte
,
error
)
{
des
,
err
:=
d
.
getDesKey
(
address
,
mode
)
if
err
!=
nil
{
return
nil
,
err
}
return
des
.
Decrypt
(
content
)
}
func
(
d
*
DirectCryptor
)
getDesKey
(
address
string
)
(
crypto
.
SymmetricKey
,
error
)
{
func
(
d
*
cryptor
)
getDesKey
(
address
string
,
mode
string
)
(
crypto
.
SymmetricKey
,
error
)
{
pubKey
,
ok
:=
d
.
keyMap
[
address
]
if
!
ok
{
get
,
ret
:=
d
.
mgr
.
GetPubKeyByChainID
(
address
)
if
!
get
{
return
nil
,
fmt
.
Errorf
(
"cannot find the public key"
)
var
(
ret
[]
byte
get
bool
)
if
mode
==
repo
.
DirectMode
{
get
,
ret
=
d
.
mgr
.
GetPubKeyByChainID
(
address
)
if
!
get
{
return
nil
,
fmt
.
Errorf
(
"cannot find the public key"
)
}
}
if
mode
==
repo
.
RelayMode
{
rp
,
err
:=
d
.
client
.
InvokeBVMContract
(
constant
.
AppchainMgrContractAddr
.
Address
(),
"GetPubKeyByChainID"
,
nil
,
rpcx
.
String
(
address
))
if
err
!=
nil
{
return
nil
,
err
}
ret
=
rp
.
Ret
}
d
.
keyMap
[
address
]
=
ret
pubKey
=
ret
...
...
internal/txcrypto/relay_cryptor.go
deleted
100644 → 0
View file @
f918c4bc
package
txcrypto
import
(
"github.com/meshplus/bitxhub-kit/crypto"
"github.com/meshplus/bitxhub-kit/crypto/asym/ecdsa"
"github.com/meshplus/bitxhub-kit/crypto/ecdh"
"github.com/meshplus/bitxhub-kit/crypto/sym"
rpcx
"github.com/link33/sidecar/hub/client"
"github.com/link33/sidecar/model/constant"
)
type
RelayCryptor
struct
{
client
rpcx
.
Client
privKey
crypto
.
PrivateKey
keyMap
map
[
string
][]
byte
}
func
NewRelayCryptor
(
client
rpcx
.
Client
,
privKey
crypto
.
PrivateKey
)
(
Cryptor
,
error
)
{
keyMap
:=
make
(
map
[
string
][]
byte
)
return
&
RelayCryptor
{
client
:
client
,
privKey
:
privKey
,
keyMap
:
keyMap
,
},
nil
}
func
(
c
*
RelayCryptor
)
Encrypt
(
content
[]
byte
,
address
string
)
([]
byte
,
error
)
{
des
,
err
:=
c
.
getDesKey
(
address
)
if
err
!=
nil
{
return
nil
,
err
}
return
des
.
Encrypt
(
content
)
}
func
(
c
*
RelayCryptor
)
Decrypt
(
content
[]
byte
,
address
string
)
([]
byte
,
error
)
{
des
,
err
:=
c
.
getDesKey
(
address
)
if
err
!=
nil
{
return
nil
,
err
}
return
des
.
Decrypt
(
content
)
}
func
(
c
*
RelayCryptor
)
getDesKey
(
address
string
)
(
crypto
.
SymmetricKey
,
error
)
{
pubKey
,
ok
:=
c
.
keyMap
[
address
]
if
!
ok
{
ret
,
err
:=
c
.
client
.
InvokeBVMContract
(
constant
.
AppchainMgrContractAddr
.
Address
(),
"GetPubKeyByChainID"
,
nil
,
rpcx
.
String
(
address
))
if
err
!=
nil
{
return
nil
,
err
}
c
.
keyMap
[
address
]
=
ret
.
Ret
pubKey
=
ret
.
Ret
}
ke
,
err
:=
ecdh
.
NewEllipticECDH
(
ecdsa
.
S256
())
if
err
!=
nil
{
return
nil
,
err
}
secret
,
err
:=
ke
.
ComputeSecret
(
c
.
privKey
,
pubKey
)
if
err
!=
nil
{
return
nil
,
err
}
return
sym
.
GenerateSymKey
(
crypto
.
ThirdDES
,
secret
)
}
internal/txcrypto/txcrypto.go
View file @
e86d2fae
...
...
@@ -2,9 +2,9 @@ package txcrypto
//go:generate mockgen -destination mock_txcrypto/mock_txcrypto.go -package mock_txcrypto -source txcrypto.go
type
Cryptor
interface
{
// encrypt can encrypt the content in IBTP
Encrypt
(
content
[]
byte
,
address
string
)
([]
byte
,
error
)
// encrypt can encrypt the content in IBTP
for mode: dirct、relay
Encrypt
(
content
[]
byte
,
address
string
,
mode
string
)
([]
byte
,
error
)
// decrypt can decrypt the content in IBTP
Decrypt
(
content
[]
byte
,
address
string
)
([]
byte
,
error
)
Decrypt
(
content
[]
byte
,
address
string
,
mode
string
)
([]
byte
,
error
)
}
tool/error.go
View file @
e86d2fae
...
...
@@ -4,7 +4,7 @@ import (
"fmt"
"runtime"
"github.com/hashicorp/go-multierror"
multierror
"github.com/hashicorp/go-multierror"
"github.com/juju/errors"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment