-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add crpto interface as repare for #127 Signed-off-by: Sam Yuan <[email protected]> * adding Worker interface for #56 and decouple Assembler and Integrator Signed-off-by: Sam Yuan <[email protected]> * refactor for worker interface Signed-off-by: Sam Yuan <[email protected]> * package structure Signed-off-by: Sam Yuan <[email protected]> * fix up Signed-off-by: Sam Yuan <[email protected]> * package refactor Signed-off-by: Sam Yuan <[email protected]> * fix up Signed-off-by: Sam Yuan <[email protected]> * fix up Signed-off-by: Sam Yuan <[email protected]> * remove Envelope from elements Signed-off-by: Sam Yuan <[email protected]> * add memeory free Signed-off-by: Sam Yuan <[email protected]> * remove Proposal from Elements Signed-off-by: Sam Yuan <[email protected]> * fix up Signed-off-by: Sam Yuan <[email protected]> * move start time to ctx Signed-off-by: Sam Yuan <[email protected]>
- Loading branch information
1 parent
75069de
commit 1c4569b
Showing
32 changed files
with
848 additions
and
640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package basic_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestBasic(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Basic Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package infra | ||
package basic | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package basic | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
"crypto/rand" | ||
"crypto/sha256" | ||
"crypto/x509" | ||
"encoding/asn1" | ||
"math/big" | ||
|
||
"tape/internal/fabric/bccsp/utils" | ||
"tape/internal/fabric/common/crypto" | ||
|
||
"github.com/hyperledger/fabric-protos-go/common" | ||
) | ||
|
||
type CryptoConfig struct { | ||
MSPID string | ||
PrivKey string | ||
SignCert string | ||
TLSCACerts []string | ||
} | ||
|
||
type ECDSASignature struct { | ||
R, S *big.Int | ||
} | ||
|
||
type CryptoImpl struct { | ||
Creator []byte | ||
PrivKey *ecdsa.PrivateKey | ||
SignCert *x509.Certificate | ||
} | ||
|
||
func (s *CryptoImpl) Sign(message []byte) ([]byte, error) { | ||
ri, si, err := ecdsa.Sign(rand.Reader, s.PrivKey, digest(message)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
si, _, err = utils.ToLowS(&s.PrivKey.PublicKey, si) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return asn1.Marshal(ECDSASignature{ri, si}) | ||
} | ||
|
||
func (s *CryptoImpl) Serialize() ([]byte, error) { | ||
return s.Creator, nil | ||
} | ||
|
||
func (s *CryptoImpl) NewSignatureHeader() (*common.SignatureHeader, error) { | ||
creator, err := s.Serialize() | ||
if err != nil { | ||
return nil, err | ||
} | ||
nonce, err := crypto.GetRandomNonce() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &common.SignatureHeader{ | ||
Creator: creator, | ||
Nonce: nonce, | ||
}, nil | ||
} | ||
|
||
func digest(in []byte) []byte { | ||
h := sha256.New() | ||
h.Write(in) | ||
return h.Sum(nil) | ||
} |
Oops, something went wrong.