Merge pull request #319 from meshplus/feat/modify-certificate-validation-method
feat(*): modify the certificate validation method
This commit is contained in:
commit
2c7b983f6a
|
@ -20,7 +20,7 @@ import (
|
|||
"github.com/meshplus/bitxhub-kit/crypto"
|
||||
"github.com/meshplus/bitxhub-kit/crypto/asym"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
|
@ -62,7 +62,7 @@ var caCMD = cli.Command{
|
|||
return err
|
||||
}
|
||||
|
||||
c, err := cert.GenerateCert(privKey, true, "Hyperchain")
|
||||
c, err := libp2pcert.GenerateCert(privKey, true, "Hyperchain")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/meshplus/bitxhub-kit/crypto"
|
||||
"github.com/meshplus/bitxhub-kit/crypto/asym"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
|
@ -80,7 +80,7 @@ func convertKey(ctx *cli.Context) error {
|
|||
return fmt.Errorf("read private key: %w", err)
|
||||
}
|
||||
|
||||
privKey, err := cert.ParsePrivateKey(data, crypto.Secp256k1)
|
||||
privKey, err := libp2pcert.ParsePrivateKey(data, crypto.Secp256k1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ func getAddress(ctx *cli.Context) error {
|
|||
return fmt.Errorf("read private key: %w", err)
|
||||
}
|
||||
|
||||
privKey, err := cert.ParsePrivateKey(data, crypto.Secp256k1)
|
||||
privKey, err := libp2pcert.ParsePrivateKey(data, crypto.Secp256k1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
6
go.mod
6
go.mod
|
@ -12,7 +12,7 @@ require (
|
|||
github.com/gobuffalo/envy v1.9.0 // indirect
|
||||
github.com/gobuffalo/packd v1.0.0
|
||||
github.com/gobuffalo/packr v1.30.1
|
||||
github.com/gogo/protobuf v1.3.1
|
||||
github.com/gogo/protobuf v1.3.2
|
||||
github.com/golang/mock v1.4.3
|
||||
github.com/google/btree v1.0.0
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
||||
|
@ -28,7 +28,8 @@ require (
|
|||
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210112105719-497a79914e4e
|
||||
github.com/meshplus/bitxhub-kit v1.1.2-0.20210112075018-319e668d6359
|
||||
github.com/meshplus/bitxhub-model v1.1.2-0.20210107045700-cee670a2e117
|
||||
github.com/meshplus/go-lightp2p v0.0.0-20210105060927-1c7850047415
|
||||
github.com/meshplus/go-libp2p-cert v0.0.0-20210120021632-1578cf63e06a
|
||||
github.com/meshplus/go-lightp2p v0.0.0-20210120082108-df5a536a6192
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/multiformats/go-multiaddr v0.2.2
|
||||
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6
|
||||
|
@ -52,7 +53,6 @@ require (
|
|||
go.uber.org/atomic v1.7.0
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
go.uber.org/zap v1.16.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392 // indirect
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
|
||||
google.golang.org/genproto v0.0.0-20201119123407-9b1e624d6bc4 // indirect
|
||||
google.golang.org/grpc v1.33.2
|
||||
|
|
30
go.sum
30
go.sum
|
@ -153,6 +153,8 @@ github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
|
|||
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/fjl/memsize v0.0.0-20180418122429-ca190fb6ffbc/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
|
||||
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6 h1:u/UEqS66A5ckRmS4yNpjmVH56sVtS/RfclBAYocb4as=
|
||||
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
|
||||
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
|
||||
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
|
||||
github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o=
|
||||
|
@ -191,6 +193,8 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV
|
|||
github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 h1:ZgQEtGgCBiWRM39fZuwSd1LwSqqSW0hOdXCYYDX0R3I=
|
||||
|
@ -369,6 +373,7 @@ github.com/karalabe/usb v0.0.0-20190919080040-51dc0efba356/go.mod h1:Od972xHfMJo
|
|||
github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
||||
github.com/klauspost/compress v1.9.8/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||
|
@ -421,6 +426,7 @@ github.com/libp2p/go-libp2p v0.5.0/go.mod h1:Os7a5Z3B+ErF4v7zgIJ7nBHNu2LYt8ZMLkT
|
|||
github.com/libp2p/go-libp2p v0.6.1/go.mod h1:CTFnWXogryAHjXAKEbOf1OWY+VeAP3lDMZkfEI5sT54=
|
||||
github.com/libp2p/go-libp2p v0.7.0/go.mod h1:hZJf8txWeCduQRDC/WSqBGMxaTHCOYHt2xSU1ivxn0k=
|
||||
github.com/libp2p/go-libp2p v0.7.4/go.mod h1:oXsBlTLF1q7pxr+9w6lqzS1ILpyHsaBPniVO7zIHGMw=
|
||||
github.com/libp2p/go-libp2p v0.8.1/go.mod h1:QRNH9pwdbEBpx5DTJYg+qxcVaDMAz3Ee/qDKwXujH5o=
|
||||
github.com/libp2p/go-libp2p v0.8.2/go.mod h1:NQDA/F/qArMHGe0J7sDScaKjW8Jh4y/ozQqBbYJ+BnA=
|
||||
github.com/libp2p/go-libp2p v0.8.3/go.mod h1:EsH1A+8yoWK+L4iKcbPYu6MPluZ+CHWI9El8cTaefiM=
|
||||
github.com/libp2p/go-libp2p v0.9.2 h1:5rViLwtjkaEWcIBbk6oII39cVjPTElo3F78SSLf9yho=
|
||||
|
@ -599,6 +605,7 @@ github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210112105719-497a79914e4e h1:gQf
|
|||
github.com/meshplus/bitxhub-core v0.1.0-rc1.0.20210112105719-497a79914e4e/go.mod h1:MHf0waxqnW4Qwfpq66jqvJP+FritN5OTs/8wlQcNlJY=
|
||||
github.com/meshplus/bitxhub-kit v1.0.0-rc1/go.mod h1:ra/AhOkPvpElI+wXrB9G6DjdcrdxFU3vMwA5MYKr9D0=
|
||||
github.com/meshplus/bitxhub-kit v1.0.0/go.mod h1:7cWyhXWZfrQ3+EaxkRoXfuiG3Y5R9DXYJomeZKkETW8=
|
||||
github.com/meshplus/bitxhub-kit v1.1.1/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
|
||||
github.com/meshplus/bitxhub-kit v1.1.2-0.20201021105954-468d0a9d7957/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
|
||||
github.com/meshplus/bitxhub-kit v1.1.2-0.20201023030558-9f36554d5d5d/go.mod h1:r4l4iqn0RPJreb/OmoYKfjCjQJrXpZX++6Qc31VG/1k=
|
||||
github.com/meshplus/bitxhub-kit v1.1.2-0.20201203072410-8a0383a6870d h1:J9tzTNf29mR0r97An3KoAtZQYlwpNhlMItWKyzKJLHU=
|
||||
|
@ -609,8 +616,12 @@ github.com/meshplus/bitxhub-model v1.0.0-rc3/go.mod h1:ZCctQIYTlE3vJ8Lhkrgs9bWwN
|
|||
github.com/meshplus/bitxhub-model v1.1.2-0.20201021152621-0b3c17c54b23/go.mod h1:4qWBZx5wv7WZzUqiuBsbkQqQ2Ju8aOFpsoNpBBNy8Us=
|
||||
github.com/meshplus/bitxhub-model v1.1.2-0.20210107045700-cee670a2e117 h1:q1FT1DYWg2Ntf6A6wWiEx2WIEaEGBVgaIE1gAIVJKeI=
|
||||
github.com/meshplus/bitxhub-model v1.1.2-0.20210107045700-cee670a2e117/go.mod h1:x3H+TL24wcByzHegenLfs+5PQkQGNsk8eCm31QJMa+Q=
|
||||
github.com/meshplus/go-libp2p-cert v0.0.0-20210120021632-1578cf63e06a h1:eg1BDjSOsz3cdH49kPE8c2XnIFlLTPEMJLqpofV/OEY=
|
||||
github.com/meshplus/go-libp2p-cert v0.0.0-20210120021632-1578cf63e06a/go.mod h1:rS4AYMqKypLn2IPEnHICP//V2v16SZo4CWUbwMdihl0=
|
||||
github.com/meshplus/go-lightp2p v0.0.0-20210105060927-1c7850047415 h1:LgKHkjzq+Vlf37gkQmw7qK89kJLohSSfl4nSpI8tM4A=
|
||||
github.com/meshplus/go-lightp2p v0.0.0-20210105060927-1c7850047415/go.mod h1:L3pEzDMouz+xcIVwG2fj+mAsM95GAkzoo7cEd2CzmCQ=
|
||||
github.com/meshplus/go-lightp2p v0.0.0-20210120082108-df5a536a6192 h1:DyNmWuI8Awrd+OUFIXmJitSmvzywwoPygpSqAPjr85M=
|
||||
github.com/meshplus/go-lightp2p v0.0.0-20210120082108-df5a536a6192/go.mod h1:56+jusXmfu7IVTJtani81emdHL5zwGnoXUgJIjw3Ijo=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
|
@ -886,6 +897,8 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
|
|||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
github.com/xtaci/kcp-go v5.4.20+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE=
|
||||
github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae/go.mod h1:gXtu8J62kEgmN++bm9BVICuT/e8yiLI2KFobd/TRFsE=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
|
@ -939,6 +952,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnk
|
|||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392 h1:xYJJ3S178yv++9zXV/hnr29plCAGO9vAFG9dorqaFQc=
|
||||
golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
|
@ -958,6 +973,9 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG
|
|||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
|
@ -979,6 +997,7 @@ golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200519113804-d87ec0cfa476/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200528225125-3c3fba18258b/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
|
@ -986,6 +1005,8 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrS
|
|||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
|
@ -997,6 +1018,8 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ
|
|||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
|
@ -1033,6 +1056,7 @@ golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
|
@ -1041,6 +1065,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
|
@ -1066,9 +1092,13 @@ golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtn
|
|||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200221224223-e1da425f72fd h1:hHkvGJK23seRCflePJnVa9IMv8fsuavSCWKd11kDQFs=
|
||||
golang.org/x/tools v0.0.0-20200221224223-e1da425f72fd/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
"github.com/meshplus/bitxhub/internal/ledger/mock_ledger"
|
||||
"github.com/meshplus/bitxhub/internal/model/events"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -236,7 +236,7 @@ func mockCommitEvent(blockNumber uint64, txs []*pb.Transaction) *pb.CommitEvent
|
|||
localList[i] = false
|
||||
}
|
||||
return &pb.CommitEvent{
|
||||
Block: block,
|
||||
Block: block,
|
||||
LocalList: localList,
|
||||
}
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ func createMockRepo(t *testing.T) *repo.Repo {
|
|||
BcNwjTDCxyxLNjFKQfMAc6sY6iJs+Ma59WZyC/4uhjE=
|
||||
-----END EC PRIVATE KEY-----`
|
||||
|
||||
privKey, err := cert.ParsePrivateKey([]byte(key), crypto.Secp256k1)
|
||||
privKey, err := libp2pcert.ParsePrivateKey([]byte(key), crypto.Secp256k1)
|
||||
require.Nil(t, err)
|
||||
|
||||
address, err := privKey.PublicKey().Address()
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
"github.com/meshplus/bitxhub-kit/types"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -851,7 +851,7 @@ func createMockRepo(t *testing.T) *repo.Repo {
|
|||
BcNwjTDCxyxLNjFKQfMAc6sY6iJs+Ma59WZyC/4uhjE=
|
||||
-----END EC PRIVATE KEY-----`
|
||||
|
||||
privKey, err := cert.ParsePrivateKey([]byte(key), crypto.Secp256k1)
|
||||
privKey, err := libp2pcert.ParsePrivateKey([]byte(key), crypto.Secp256k1)
|
||||
require.Nil(t, err)
|
||||
|
||||
address, err := privKey.PublicKey().Address()
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
package repo
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
)
|
||||
|
||||
type Certs struct {
|
||||
NodeCertData []byte
|
||||
AgencyCertData []byte
|
||||
CACertData []byte
|
||||
NodeCert *x509.Certificate
|
||||
AgencyCert *x509.Certificate
|
||||
CACert *x509.Certificate
|
||||
}
|
||||
|
||||
func loadCerts(repoRoot string) (*Certs, error) {
|
||||
nodeCert, nodeCertData, err := loadCert(filepath.Join(repoRoot, "certs/node.cert"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load node cert: %w", err)
|
||||
}
|
||||
|
||||
agencyCert, agencyCertData, err := loadCert(filepath.Join(repoRoot, "certs/agency.cert"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load agency cert: %w", err)
|
||||
}
|
||||
caCert, caCertData, err := loadCert(filepath.Join(repoRoot, "certs/ca.cert"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load ca cert: %w", err)
|
||||
}
|
||||
|
||||
return &Certs{
|
||||
NodeCertData: nodeCertData,
|
||||
AgencyCertData: agencyCertData,
|
||||
CACertData: caCertData,
|
||||
NodeCert: nodeCert,
|
||||
AgencyCert: agencyCert,
|
||||
CACert: caCert,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func loadCert(certPath string) (*x509.Certificate, []byte, error) {
|
||||
data, err := ioutil.ReadFile(certPath)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("read cert: %w", err)
|
||||
}
|
||||
|
||||
cert, err := cert.ParseCert(data)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("parse cert: %w", err)
|
||||
}
|
||||
|
||||
return cert, data, nil
|
||||
}
|
|
@ -8,7 +8,7 @@ import (
|
|||
crypto2 "github.com/meshplus/bitxhub-kit/crypto"
|
||||
"github.com/meshplus/bitxhub-kit/crypto/asym"
|
||||
"github.com/meshplus/bitxhub-kit/fileutil"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
)
|
||||
|
||||
type Key struct {
|
||||
|
@ -40,7 +40,7 @@ func loadPrivKey(repoRoot string) (*Key, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
privKey, err := cert.ParsePrivateKey(keyData, crypto2.Secp256k1)
|
||||
privKey, err := libp2pcert.ParsePrivateKey(keyData, crypto2.Secp256k1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func loadPrivKey(repoRoot string) (*Key, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
nodePrivKey, err := cert.ParsePrivateKey(nodeKeyData, crypto2.ECDSA_P256)
|
||||
nodePrivKey, err := libp2pcert.ParsePrivateKey(nodeKeyData, crypto2.ECDSA_P256)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
crypto2 "github.com/meshplus/bitxhub-kit/crypto"
|
||||
"github.com/meshplus/bitxhub-kit/types"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
"github.com/pelletier/go-toml"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -182,7 +182,7 @@ func GetPidFromPrivFile(privPath string) (string, error) {
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("read private key: %w", err)
|
||||
}
|
||||
privKey, err := cert.ParsePrivateKey(data, crypto2.ECDSA_P256)
|
||||
privKey, err := libp2pcert.ParsePrivateKey(data, crypto2.ECDSA_P256)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -4,13 +4,15 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
)
|
||||
|
||||
type Repo struct {
|
||||
Config *Config
|
||||
NetworkConfig *NetworkConfig
|
||||
Key *Key
|
||||
Certs *Certs
|
||||
Certs *libp2pcert.Certs
|
||||
}
|
||||
|
||||
func Load(repoRoot string) (*Repo, error) {
|
||||
|
@ -24,7 +26,7 @@ func Load(repoRoot string) (*Repo, error) {
|
|||
return nil, fmt.Errorf("load network config: %w", err)
|
||||
}
|
||||
|
||||
certs, err := loadCerts(repoRoot)
|
||||
certs, err := libp2pcert.LoadCerts(repoRoot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
100
pkg/cert/cert.go
100
pkg/cert/cert.go
|
@ -1,100 +0,0 @@
|
|||
package cert
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"crypto/x509"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
"github.com/meshplus/bitxhub-kit/crypto"
|
||||
ecdsa2 "github.com/meshplus/bitxhub-kit/crypto/asym/ecdsa"
|
||||
)
|
||||
|
||||
func VerifySign(subCert *x509.Certificate, caCert *x509.Certificate) error {
|
||||
if err := subCert.CheckSignatureFrom(caCert); err != nil {
|
||||
return fmt.Errorf("check sign: %w", err)
|
||||
}
|
||||
|
||||
if subCert.NotBefore.After(time.Now()) || subCert.NotAfter.Before(time.Now()) {
|
||||
return fmt.Errorf("cert expired")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ParsePrivateKey(data []byte, opt crypto.KeyType) (*ecdsa2.PrivateKey, error) {
|
||||
if data == nil {
|
||||
return nil, fmt.Errorf("empty data")
|
||||
}
|
||||
|
||||
block, _ := pem.Decode(data)
|
||||
if block == nil {
|
||||
return nil, fmt.Errorf("empty block")
|
||||
}
|
||||
|
||||
return ecdsa2.UnmarshalPrivateKey(block.Bytes, opt)
|
||||
}
|
||||
|
||||
func ParseCert(data []byte) (*x509.Certificate, error) {
|
||||
if data == nil {
|
||||
return nil, fmt.Errorf("empty data")
|
||||
}
|
||||
|
||||
block, _ := pem.Decode(data)
|
||||
if block == nil {
|
||||
return nil, fmt.Errorf("empty block")
|
||||
}
|
||||
|
||||
return x509.ParseCertificate(block.Bytes)
|
||||
}
|
||||
|
||||
func GenerateCert(privKey *ecdsa.PrivateKey, isCA bool, organization string) (*x509.Certificate, error) {
|
||||
sn, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
notBefore := time.Now().Add(-5 * time.Minute).UTC()
|
||||
|
||||
template := &x509.Certificate{
|
||||
SerialNumber: sn,
|
||||
NotBefore: notBefore,
|
||||
NotAfter: notBefore.Add(50 * 365 * 24 * time.Hour).UTC(),
|
||||
BasicConstraintsValid: true,
|
||||
IsCA: isCA,
|
||||
KeyUsage: x509.KeyUsageDigitalSignature |
|
||||
x509.KeyUsageKeyEncipherment | x509.KeyUsageCertSign |
|
||||
x509.KeyUsageCRLSign,
|
||||
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageAny},
|
||||
Subject: pkix.Name{
|
||||
Country: []string{"CN"},
|
||||
Locality: []string{"HangZhou"},
|
||||
Province: []string{"ZheJiang"},
|
||||
OrganizationalUnit: []string{"BitXHub"},
|
||||
Organization: []string{organization},
|
||||
StreetAddress: []string{"street", "address"},
|
||||
PostalCode: []string{"324000"},
|
||||
CommonName: "bitxhub.cn",
|
||||
},
|
||||
}
|
||||
template.SubjectKeyId = priKeyHash(privKey)
|
||||
|
||||
return template, nil
|
||||
}
|
||||
|
||||
func priKeyHash(priKey *ecdsa.PrivateKey) []byte {
|
||||
hash := sha256.New()
|
||||
|
||||
_, err := hash.Write(elliptic.Marshal(priKey.Curve, priKey.PublicKey.X, priKey.PublicKey.Y))
|
||||
if err != nil {
|
||||
fmt.Printf("Get private key hash: %s", err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
return hash.Sum(nil)
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package cert
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
crypto2 "github.com/meshplus/bitxhub-kit/crypto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParsePrivateKey(t *testing.T) {
|
||||
data, err := ioutil.ReadFile(filepath.Join("testdata", "ca.priv"))
|
||||
assert.Nil(t, err)
|
||||
privKey, err := ParsePrivateKey(data, crypto2.ECDSA_P256)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, privKey)
|
||||
}
|
||||
|
||||
func TestVerifySign(t *testing.T) {
|
||||
data, err := ioutil.ReadFile(filepath.Join("testdata", "ca.cert"))
|
||||
require.Nil(t, err)
|
||||
caCert, err := ParseCert(data)
|
||||
require.Nil(t, err)
|
||||
|
||||
subData, err := ioutil.ReadFile(filepath.Join("testdata", "agency.cert"))
|
||||
require.Nil(t, err)
|
||||
subCert, err := ParseCert(subData)
|
||||
require.Nil(t, err)
|
||||
err = VerifySign(subCert, caCert)
|
||||
require.Nil(t, err)
|
||||
|
||||
nodeData, err := ioutil.ReadFile(filepath.Join("testdata", "node.cert"))
|
||||
require.Nil(t, err)
|
||||
nodeCert, err := ParseCert(nodeData)
|
||||
require.Nil(t, err)
|
||||
err = VerifySign(nodeCert, subCert)
|
||||
require.Nil(t, err)
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICljCCAjygAwIBAgIDDM4TMAoGCCqGSM49BAMCMIGhMQswCQYDVQQGEwJDTjER
|
||||
MA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYDVQQJEwZz
|
||||
dHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEzARBgNVBAoT
|
||||
Ckh5cGVyY2hhaW4xEDAOBgNVBAsTB0JpdFhIdWIxEzARBgNVBAMTCmJpdHhodWIu
|
||||
Y24wIBcNMjAwMjE2MTA1OTEyWhgPMjA3MDAyMDMxMDU5MTJaMIGhMQswCQYDVQQG
|
||||
EwJDTjERMA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYD
|
||||
VQQJEwZzdHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEzAR
|
||||
BgNVBAoTCkh5cGVyY2hhaW4xEDAOBgNVBAsTB0JpdFhIdWIxEzARBgNVBAMTCmJp
|
||||
dHhodWIuY24wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARzSt8E8u1OUpi8Xtjn
|
||||
ZtYfNCzr49+MkvPpTkMNR6eeVu0Ojmg+1B3N5ACJ4IBdwyB98i2nJdEGWXnB8tQe
|
||||
EjeQo18wXTAOBgNVHQ8BAf8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAPBgNVHRMB
|
||||
Af8EBTADAQH/MCkGA1UdDgQiBCD4D+j//rrAmy9ONm16YVs2ME5F7V77r4jPUwhk
|
||||
BrzMNjAKBggqhkjOPQQDAgNIADBFAiB9EztiHPJCR27NAua9ym6o438y8rbgDxWk
|
||||
xgAUhD/kGQIhAPaDmeySLJ36nfhSB/1DB7UwH6Ft4zbNXlwXSF7WFDZc
|
||||
-----END CERTIFICATE-----
|
|
@ -1,5 +0,0 @@
|
|||
-----BEGIN EC PRIVATE KEY-----
|
||||
MHcCAQEEIK5aL/4xchh+S4V61eNe5pd39Q2Y6LQGUkF2DxZSrh1LoAoGCCqGSM49
|
||||
AwEHoUQDQgAEc0rfBPLtTlKYvF7Y52bWHzQs6+PfjJLz6U5DDUennlbtDo5oPtQd
|
||||
zeQAieCAXcMgffItpyXRBll5wfLUHhI3kA==
|
||||
-----END EC PRIVATE KEY-----
|
|
@ -1,16 +0,0 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICljCCAjygAwIBAgIDBw66MAoGCCqGSM49BAMCMIGhMQswCQYDVQQGEwJDTjER
|
||||
MA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYDVQQJEwZz
|
||||
dHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEzARBgNVBAoT
|
||||
Ckh5cGVyY2hhaW4xEDAOBgNVBAsTB0JpdFhIdWIxEzARBgNVBAMTCmJpdHhodWIu
|
||||
Y24wIBcNMjAwMjE2MTA1ODU2WhgPMjA3MDAyMDMxMDU4NTZaMIGhMQswCQYDVQQG
|
||||
EwJDTjERMA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYD
|
||||
VQQJEwZzdHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEzAR
|
||||
BgNVBAoTCkh5cGVyY2hhaW4xEDAOBgNVBAsTB0JpdFhIdWIxEzARBgNVBAMTCmJp
|
||||
dHhodWIuY24wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASaN7fk29koRjieizGU
|
||||
keMuKsgjKV/ETyyncf2tUKChie9xp50ZwNyWeNw1RkZwaq4VSgc3XO4PK1brMi/I
|
||||
ryrvo18wXTAOBgNVHQ8BAf8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAPBgNVHRMB
|
||||
Af8EBTADAQH/MCkGA1UdDgQiBCC1Q6sMZ1x2MoCnta2NNa1j/fXX9Ro67ifzzsju
|
||||
12EJ0TAKBggqhkjOPQQDAgNIADBFAiEAkuuL1IuOwsMPSGztyz2LWLMQWGGGtom9
|
||||
H3/P5l+mfmMCID7rXvAaGLPy+E2o0mbeT5+/xe8Rz2WWbW1WKS512eWV
|
||||
-----END CERTIFICATE-----
|
|
@ -1,5 +0,0 @@
|
|||
-----BEGIN EC PRIVATE KEY-----
|
||||
MHcCAQEEICm0b8dBl2nUDWN/tWomSiEWHFrInXdCMSr4So1XJH16oAoGCCqGSM49
|
||||
AwEHoUQDQgAEmje35NvZKEY4nosxlJHjLirIIylfxE8sp3H9rVCgoYnvcaedGcDc
|
||||
lnjcNUZGcGquFUoHN1zuDytW6zIvyK8q7w==
|
||||
-----END EC PRIVATE KEY-----
|
|
@ -1,17 +0,0 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIICwTCCAmegAwIBAgIDDiTiMAoGCCqGSM49BAMCMIGhMQswCQYDVQQGEwJDTjER
|
||||
MA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYDVQQJEwZz
|
||||
dHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxEzARBgNVBAoT
|
||||
Ckh5cGVyY2hhaW4xEDAOBgNVBAsTB0JpdFhIdWIxEzARBgNVBAMTCmJpdHhodWIu
|
||||
Y24wIBcNMjAwMjE2MTA1OTIwWhgPMjA3MDAyMDMxMDU5MjBaMIGdMQswCQYDVQQG
|
||||
EwJDTjERMA8GA1UECBMIWmhlSmlhbmcxETAPBgNVBAcTCEhhbmdaaG91MR8wDQYD
|
||||
VQQJEwZzdHJlZXQwDgYDVQQJEwdhZGRyZXNzMQ8wDQYDVQQREwYzMjQwMDAxDzAN
|
||||
BgNVBAoTBkFnZW5jeTEQMA4GA1UECxMHQml0WEh1YjETMBEGA1UEAxMKYml0eGh1
|
||||
Yi5jbjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABHdBYo//anaFE6mWJ1OPSB7C
|
||||
vRxUVaU5v/wnerThPBNJZK5xYBP4Ss2Pdu9dia+MZEgfbADJgKXYl27tNrvyxeej
|
||||
gY0wgYowDgYDVR0PAQH/BAQDAgGmMA8GA1UdJQQIMAYGBFUdJQAwDwYDVR0TAQH/
|
||||
BAUwAwEB/zApBgNVHQ4EIgQgSfHyXM1Dz06eSwdHAEfntUOZtkXMQ6c+naNwHQ8s
|
||||
McwwKwYDVR0jBCQwIoAg+A/o//66wJsvTjZtemFbNjBORe1e+6+Iz1MIZAa8zDYw
|
||||
CgYIKoZIzj0EAwIDSAAwRQIgSIEexoEAMc0Mp0jbhT0hzY4ejCDArxqiWRXcMynM
|
||||
YiQCIQDBZhgf9db9jgE/NUV4BQjK4SX+yz1zWrlgcF67calOJw==
|
||||
-----END CERTIFICATE-----
|
|
@ -1,5 +0,0 @@
|
|||
-----BEGIN EC PRIVATE KEY-----
|
||||
MHcCAQEEILrm8HS7M1yMOKRYPhNCbZM1AYI0vcGb8NaEPzy0K8UEoAoGCCqGSM49
|
||||
AwEHoUQDQgAEd0Fij/9qdoUTqZYnU49IHsK9HFRVpTm//Cd6tOE8E0lkrnFgE/hK
|
||||
zY92712Jr4xkSB9sAMmApdiXbu02u/LF5w==
|
||||
-----END EC PRIVATE KEY-----
|
|
@ -21,10 +21,10 @@ import (
|
|||
"github.com/meshplus/bitxhub/internal/ledger/mock_ledger"
|
||||
"github.com/meshplus/bitxhub/internal/model/events"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
"github.com/meshplus/bitxhub/pkg/order"
|
||||
"github.com/meshplus/bitxhub/pkg/peermgr"
|
||||
"github.com/meshplus/bitxhub/pkg/peermgr/mock_peermgr"
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -39,7 +39,7 @@ func TestNode_Start(t *testing.T) {
|
|||
var ID uint64 = 1
|
||||
nodes := make(map[uint64]*pb.VpInfo)
|
||||
vpInfo := &pb.VpInfo{
|
||||
Id: ID,
|
||||
Id: ID,
|
||||
Account: types.NewAddressByStr("000000000000000000000000000000000000000a").String(),
|
||||
}
|
||||
nodes[ID] = vpInfo
|
||||
|
@ -250,7 +250,7 @@ func newSwarms(t *testing.T, peerCnt int) ([]*peermgr.Swarm, map[uint64]*pb.VpIn
|
|||
caData, err := ioutil.ReadFile("testdata/ca.cert")
|
||||
require.Nil(t, err)
|
||||
|
||||
cert, err := cert.ParseCert(caData)
|
||||
cert, err := libp2pcert.ParseCert(caData)
|
||||
require.Nil(t, err)
|
||||
|
||||
for i := 0; i < peerCnt; i++ {
|
||||
|
@ -261,7 +261,7 @@ func newSwarms(t *testing.T, peerCnt int) ([]*peermgr.Swarm, map[uint64]*pb.VpIn
|
|||
N: uint64(peerCnt),
|
||||
ID: uint64(ID),
|
||||
},
|
||||
Certs: &repo.Certs{
|
||||
Certs: &libp2pcert.Certs{
|
||||
NodeCertData: nodeData,
|
||||
AgencyCertData: agencyData,
|
||||
CACert: cert,
|
||||
|
@ -282,7 +282,7 @@ func newSwarms(t *testing.T, peerCnt int) ([]*peermgr.Swarm, map[uint64]*pb.VpIn
|
|||
address, err := privKeys[i].PublicKey().Address()
|
||||
require.Nil(t, err)
|
||||
vpInfo := &pb.VpInfo{
|
||||
Id: uint64(ID),
|
||||
Id: uint64(ID),
|
||||
Account: address.String(),
|
||||
}
|
||||
nodes[uint64(ID)] = vpInfo
|
||||
|
|
|
@ -18,8 +18,8 @@ import (
|
|||
"github.com/meshplus/bitxhub-model/pb"
|
||||
"github.com/meshplus/bitxhub/internal/ledger/mock_ledger"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
"github.com/meshplus/bitxhub/pkg/peermgr"
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -28,7 +28,7 @@ func TestStateSyncer_SyncCFTBlocks(t *testing.T) {
|
|||
swarms := NewSwarms(t, peerCnt)
|
||||
|
||||
for swarms[0].CountConnectedPeers() != 2 {
|
||||
time.Sleep(100*time.Millisecond)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
otherPeers := swarms[0].OtherPeers()
|
||||
peerIds := make([]uint64, 0)
|
||||
|
@ -61,7 +61,7 @@ func TestStateSyncer_SyncBFTBlocks(t *testing.T) {
|
|||
swarms := NewSwarms(t, peerCnt)
|
||||
|
||||
for swarms[0].CountConnectedPeers() != 3 {
|
||||
time.Sleep(100*time.Millisecond)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
otherPeers := swarms[0].OtherPeers()
|
||||
peerIds := make([]uint64, 0)
|
||||
|
@ -169,7 +169,7 @@ func NewSwarms(t *testing.T, peerCnt int) []*peermgr.Swarm {
|
|||
caData, err := ioutil.ReadFile("testdata/ca.cert")
|
||||
require.Nil(t, err)
|
||||
|
||||
cert, err := cert.ParseCert(caData)
|
||||
cert, err := libp2pcert.ParseCert(caData)
|
||||
require.Nil(t, err)
|
||||
|
||||
for i := 0; i < peerCnt; i++ {
|
||||
|
@ -179,13 +179,12 @@ func NewSwarms(t *testing.T, peerCnt int) []*peermgr.Swarm {
|
|||
N: uint64(peerCnt),
|
||||
ID: uint64(i + 1),
|
||||
},
|
||||
Certs: &repo.Certs{
|
||||
Certs: &libp2pcert.Certs{
|
||||
NodeCertData: nodeData,
|
||||
AgencyCertData: agencyData,
|
||||
CACert: cert,
|
||||
},
|
||||
Config: &repo.Config{
|
||||
},
|
||||
Config: &repo.Config{},
|
||||
}
|
||||
|
||||
idx := strings.LastIndex(addrs[i], "/p2p/")
|
||||
|
|
|
@ -2,7 +2,6 @@ package peermgr
|
|||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
@ -12,7 +11,6 @@ import (
|
|||
"github.com/meshplus/bitxhub/internal/executor/contracts"
|
||||
"github.com/meshplus/bitxhub/internal/model"
|
||||
"github.com/meshplus/bitxhub/internal/model/events"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
network "github.com/meshplus/go-lightp2p"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -146,18 +144,6 @@ func (swarm *Swarm) handleFetchCertMessage(s network.Stream) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func verifyCerts(nodeCert *x509.Certificate, agencyCert *x509.Certificate, caCert *x509.Certificate) error {
|
||||
if err := cert.VerifySign(agencyCert, caCert); err != nil {
|
||||
return fmt.Errorf("verify agency cert: %w", err)
|
||||
}
|
||||
|
||||
if err := cert.VerifySign(nodeCert, agencyCert); err != nil {
|
||||
return fmt.Errorf("verify node cert: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (swarm *Swarm) handleFetchBlockSignMessage(s network.Stream, data []byte) {
|
||||
handle := func(data []byte) ([]byte, error) {
|
||||
height, err := strconv.ParseUint(string(data), 10, 64)
|
||||
|
|
|
@ -8,15 +8,8 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/meshplus/bitxhub/internal/model/events"
|
||||
|
||||
"github.com/meshplus/bitxhub/internal/executor/contracts"
|
||||
|
||||
"github.com/Rican7/retry"
|
||||
"github.com/Rican7/retry/strategy"
|
||||
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
crypto2 "github.com/libp2p/go-libp2p-core/crypto"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
|
@ -25,8 +18,11 @@ import (
|
|||
"github.com/meshplus/bitxhub-kit/crypto/asym/ecdsa"
|
||||
"github.com/meshplus/bitxhub-kit/log"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
"github.com/meshplus/bitxhub/internal/executor/contracts"
|
||||
"github.com/meshplus/bitxhub/internal/ledger/mock_ledger"
|
||||
"github.com/meshplus/bitxhub/internal/model/events"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -120,7 +116,7 @@ func NewSwarms(t *testing.T, peerCnt int) []*Swarm {
|
|||
caData, err := ioutil.ReadFile("testdata/ca.cert")
|
||||
require.Nil(t, err)
|
||||
|
||||
cert, err := cert.ParseCert(caData)
|
||||
cert, err := libp2pcert.ParseCert(caData)
|
||||
require.Nil(t, err)
|
||||
|
||||
for i := 0; i < peerCnt; i++ {
|
||||
|
@ -130,7 +126,7 @@ func NewSwarms(t *testing.T, peerCnt int) []*Swarm {
|
|||
N: uint64(peerCnt),
|
||||
ID: uint64(i + 1),
|
||||
},
|
||||
Certs: &repo.Certs{
|
||||
Certs: &libp2pcert.Certs{
|
||||
NodeCertData: nodeData,
|
||||
AgencyCertData: agencyData,
|
||||
CACert: cert,
|
||||
|
@ -164,7 +160,7 @@ func TestSwarm_Send(t *testing.T) {
|
|||
swarms := NewSwarms(t, peerCnt)
|
||||
|
||||
for swarms[0].CountConnectedPeers() != 3 {
|
||||
time.Sleep(100*time.Millisecond)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
msg := &pb.Message{
|
||||
|
@ -214,8 +210,6 @@ func TestSwarm_Send(t *testing.T) {
|
|||
require.Nil(t, err)
|
||||
require.Equal(t, 1, len(getBlocksRes.Blocks))
|
||||
|
||||
|
||||
|
||||
getBlockHeadersReq := pb.GetBlockHeadersRequest{
|
||||
Start: 1,
|
||||
End: 1,
|
||||
|
@ -243,7 +237,6 @@ func TestSwarm_Send(t *testing.T) {
|
|||
require.Nil(t, err)
|
||||
require.Equal(t, 1, len(getBlockHeaderssRes.BlockHeaders))
|
||||
|
||||
|
||||
fetchBlockSignMsg := &pb.Message{
|
||||
Type: pb.Message_FETCH_BLOCK_SIGN,
|
||||
Data: []byte("1"),
|
||||
|
@ -301,7 +294,7 @@ func TestSwarm_AsyncSend(t *testing.T) {
|
|||
swarms := NewSwarms(t, peerCnt)
|
||||
|
||||
for swarms[0].CountConnectedPeers() != 3 {
|
||||
time.Sleep(100*time.Millisecond)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
orderMsgCh := make(chan events.OrderMessageEvent)
|
||||
|
|
|
@ -13,10 +13,9 @@ import (
|
|||
"github.com/libp2p/go-libp2p-core/protocol"
|
||||
"github.com/meshplus/bitxhub-model/pb"
|
||||
"github.com/meshplus/bitxhub/internal/ledger"
|
||||
"github.com/meshplus/bitxhub/internal/model"
|
||||
"github.com/meshplus/bitxhub/internal/model/events"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
network "github.com/meshplus/go-lightp2p"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -69,6 +68,11 @@ func New(repoConfig *repo.Repo, logger logrus.FieldLogger, ledger ledger.Ledger)
|
|||
multiAddrs[id] = node
|
||||
}
|
||||
|
||||
tpt, err := libp2pcert.New(repoConfig.Key.Libp2pPrivKey, repoConfig.Certs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create transport: %w", err)
|
||||
}
|
||||
|
||||
notifiee := newNotifiee(routers, logger)
|
||||
p2p, err := network.New(
|
||||
network.WithLocalAddr(repoConfig.NetworkConfig.LocalAddr),
|
||||
|
@ -78,6 +82,8 @@ func New(repoConfig *repo.Repo, logger logrus.FieldLogger, ledger ledger.Ledger)
|
|||
// enable discovery
|
||||
network.WithBootstrap(bootstrap),
|
||||
network.WithNotify(notifiee),
|
||||
network.WithTransportId(libp2pcert.ID),
|
||||
network.WithTransport(tpt),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create p2p: %w", err)
|
||||
|
@ -127,17 +133,6 @@ func (swarm *Swarm) Start() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := swarm.verifyCertOrDisconnect(id); err != nil {
|
||||
if attempt != 0 && attempt%5 == 0 {
|
||||
swarm.logger.WithFields(logrus.Fields{
|
||||
"node": id,
|
||||
"error": err,
|
||||
}).Error("Verify cert")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
swarm.logger.WithFields(logrus.Fields{
|
||||
"node": id,
|
||||
}).Info("Connect successfully")
|
||||
|
@ -165,15 +160,6 @@ func (swarm *Swarm) Stop() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (swarm *Swarm) verifyCertOrDisconnect(id uint64) error {
|
||||
if err := swarm.verifyCert(id); err != nil {
|
||||
if err = swarm.p2p.Disconnect(swarm.routers[id].Pid); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (swarm *Swarm) Ping() {
|
||||
ticker := time.NewTicker(swarm.pingTimeout)
|
||||
for {
|
||||
|
@ -302,46 +288,6 @@ func (swarm *Swarm) SubscribeOrderMessage(ch chan<- events.OrderMessageEvent) ev
|
|||
return swarm.orderMessageFeed.Subscribe(ch)
|
||||
}
|
||||
|
||||
func (swarm *Swarm) verifyCert(id uint64) error {
|
||||
if _, err := swarm.findPeer(id); err != nil {
|
||||
return fmt.Errorf("check id: %w", err)
|
||||
}
|
||||
|
||||
msg := &pb.Message{
|
||||
Type: pb.Message_FETCH_CERT,
|
||||
}
|
||||
|
||||
ret, err := swarm.Send(id, msg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("sync send: %w", err)
|
||||
}
|
||||
|
||||
certs := &model.CertsMessage{}
|
||||
if err := certs.Unmarshal(ret.Data); err != nil {
|
||||
return fmt.Errorf("unmarshal certs: %w", err)
|
||||
}
|
||||
|
||||
nodeCert, err := cert.ParseCert(certs.NodeCert)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse node cert: %w", err)
|
||||
}
|
||||
|
||||
agencyCert, err := cert.ParseCert(certs.AgencyCert)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse agency cert: %w", err)
|
||||
}
|
||||
|
||||
if err := verifyCerts(nodeCert, agencyCert, swarm.repo.Certs.CACert); err != nil {
|
||||
err = swarm.p2p.Disconnect(swarm.routers[id].Pid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("disconnect peer: %w", err)
|
||||
}
|
||||
return fmt.Errorf("verify certs: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (swarm *Swarm) findPeer(id uint64) (string, error) {
|
||||
if swarm.routers[id] != nil {
|
||||
return swarm.routers[id].Pid, nil
|
||||
|
|
|
@ -18,8 +18,8 @@ import (
|
|||
"github.com/meshplus/bitxhub-model/pb"
|
||||
"github.com/meshplus/bitxhub/internal/ledger"
|
||||
"github.com/meshplus/bitxhub/internal/repo"
|
||||
"github.com/meshplus/bitxhub/pkg/cert"
|
||||
"github.com/meshplus/bitxhub/pkg/vm"
|
||||
libp2pcert "github.com/meshplus/go-libp2p-cert"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/wasmerio/go-ext-wasm/wasmer"
|
||||
|
@ -366,7 +366,7 @@ func createMockRepo(t *testing.T) *repo.Repo {
|
|||
BcNwjTDCxyxLNjFKQfMAc6sY6iJs+Ma59WZyC/4uhjE=
|
||||
-----END EC PRIVATE KEY-----`
|
||||
|
||||
privKey, err := cert.ParsePrivateKey([]byte(key), crypto.Secp256k1)
|
||||
privKey, err := libp2pcert.ParsePrivateKey([]byte(key), crypto.Secp256k1)
|
||||
require.Nil(t, err)
|
||||
|
||||
address, err := privKey.PublicKey().Address()
|
||||
|
|
Loading…
Reference in New Issue