-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge "Orderer Signer MSP-based implementation"
- Loading branch information
Showing
12 changed files
with
282 additions
and
48 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 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,28 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package crypto | ||
|
||
import cb "github.com/hyperledger/fabric/protos/common" | ||
|
||
// LocalSigner is a temporary stub interface which will be implemented by the local MSP | ||
type LocalSigner interface { | ||
// NewSignatureHeader creates a SignatureHeader with the correct signing identity and a valid nonce | ||
NewSignatureHeader() (*cb.SignatureHeader, error) | ||
|
||
// Sign a message which should embed a signature header created by NewSignatureHeader | ||
Sign(message []byte) ([]byte, error) | ||
} |
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,75 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package localmsp | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hyperledger/fabric/core/crypto/primitives" | ||
"github.com/hyperledger/fabric/common/crypto" | ||
cb "github.com/hyperledger/fabric/protos/common" | ||
"github.com/hyperledger/fabric/core/peer/msp" | ||
) | ||
|
||
type mspSigner struct { | ||
} | ||
|
||
// New returns a new instance of the msp-based LocalSigner. | ||
// It assumes that the local msp has been already initialized. | ||
// Look at mspmgmt.LoadLocalMsp for further information. | ||
func NewSigner() crypto.LocalSigner { | ||
return &mspSigner{} | ||
} | ||
|
||
// NewSignatureHeader creates a SignatureHeader with the correct signing identity and a valid nonce | ||
func (s *mspSigner) NewSignatureHeader() (*cb.SignatureHeader, error) { | ||
signer, err := mspmgmt.GetLocalMSP().GetDefaultSigningIdentity() | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed getting MSP-based signer [%s]", err) | ||
} | ||
|
||
creatorIdentityRaw, err := signer.Serialize() | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed serializing creator public identity [%s]", err) | ||
} | ||
|
||
nonce, err := primitives.GetRandomNonce() | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed creating nonce [%s]", err) | ||
} | ||
|
||
sh := &cb.SignatureHeader{} | ||
sh.Creator = creatorIdentityRaw | ||
sh.Nonce = nonce | ||
|
||
return sh, nil | ||
} | ||
|
||
// Sign a message which should embed a signature header created by NewSignatureHeader | ||
func (s *mspSigner) Sign(message []byte) ([]byte, error) { | ||
signer, err := mspmgmt.GetLocalMSP().GetDefaultSigningIdentity() | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed getting MSP-based signer [%s]", err) | ||
} | ||
|
||
signature, err := signer.Sign(message) | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed generating signature [%s]", err) | ||
} | ||
|
||
return signature, nil | ||
} |
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,84 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package localmsp | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric/core/crypto/primitives" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/hyperledger/fabric/core/peer/msp" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
// 1. Determine MSP configuration | ||
var mspMgrConfigDir string | ||
var alternativeCfgPath = os.Getenv("ORDERER_CFG_PATH") | ||
if alternativeCfgPath != "" { | ||
mspMgrConfigDir = alternativeCfgPath + "/msp/sampleconfig/" | ||
} else if _, err := os.Stat("./msp/sampleconfig/"); err == nil { | ||
mspMgrConfigDir = "./msp/sampleconfig/" | ||
} else { | ||
mspMgrConfigDir = os.Getenv("GOPATH") + "/src/github.com/hyperledger/fabric/msp/sampleconfig/" | ||
} | ||
|
||
if err := mspmgmt.LoadLocalMsp(mspMgrConfigDir); err != nil { | ||
os.Exit(-1) | ||
} | ||
|
||
os.Exit(m.Run()) | ||
} | ||
|
||
func TestNewSigner(t *testing.T) { | ||
signer := NewSigner() | ||
assert.NotNil(t, signer, "Signer must be differentr from nil.") | ||
} | ||
|
||
func TestMspSigner_NewSignatureHeader(t *testing.T) { | ||
signer := NewSigner() | ||
|
||
sh, err := signer.NewSignatureHeader() | ||
if err != nil { | ||
t.Fatalf("Failed creting signature header [%s]", err) | ||
} | ||
|
||
assert.NotNil(t, sh, "SignatureHeader must be different from nil") | ||
assert.Len(t, sh.Nonce, primitives.NonceSize, "SignatureHeader.Nonce must be of length %d", primitives.NonceSize) | ||
|
||
mspIdentity, err := mspmgmt.GetLocalMSP().GetDefaultSigningIdentity() | ||
assert.NoError(t, err, "Failed getting default MSP Identity") | ||
publicIdentity := mspIdentity.GetPublicVersion() | ||
assert.NotNil(t, publicIdentity, "Failed getting default public identity. It must be different from nil.") | ||
publicIdentityRaw, err := publicIdentity.Serialize() | ||
assert.NoError(t, err, "Failed serializing default public identity") | ||
assert.Equal(t, publicIdentityRaw, sh.Creator, "Creator must be local default signer identity") | ||
} | ||
|
||
func TestMspSigner_Sign(t *testing.T) { | ||
signer := NewSigner() | ||
|
||
msg := []byte("Hello World") | ||
sigma, err := signer.Sign(msg) | ||
assert.NoError(t, err, "FAiled generating signature") | ||
|
||
// Verify signature | ||
mspIdentity, err := mspmgmt.GetLocalMSP().GetDefaultSigningIdentity() | ||
assert.NoError(t, err, "Failed getting default MSP Identity") | ||
err = mspIdentity.Verify(msg, sigma) | ||
assert.NoError(t, err, "Failed verifiing signature") | ||
} |
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,7 +1,8 @@ | ||
FROM hyperledger/fabric-runtime:_TAG_ | ||
ENV ORDERER_CFG_PATH /etc/hyperledger/fabric | ||
RUN mkdir -p /var/hyperledger/db /etc/hyperledger/fabric | ||
ENV ORDERER_CFG_PATH /etc/hyperledger/fabric/orderer | ||
RUN mkdir -p /var/hyperledger/db /etc/hyperledger/fabric/orderer | ||
COPY payload/orderer /usr/local/bin | ||
COPY payload/orderer.yaml $ORDERER_CFG_PATH | ||
ADD payload/msp-sampleconfig.tar.bz2 $ORDERER_CFG_PATH/../ | ||
COPY payload/orderer.yaml $ORDERER_CFG_PATH/ | ||
EXPOSE 7050 | ||
CMD orderer |
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
Oops, something went wrong.