本文整理匯總了Golang中github.com/hyperledger/fabric/core/crypto/primitives.SetSecurityLevel函數的典型用法代碼示例。如果您正苦於以下問題:Golang SetSecurityLevel函數的具體用法?Golang SetSecurityLevel怎麽用?Golang SetSecurityLevel使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了SetSecurityLevel函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: initPeer
//initialize peer and start up. If security==enabled, login as vp
func initPeer(chainID string) (net.Listener, error) {
//start clean
finitPeer(nil)
var opts []grpc.ServerOption
if viper.GetBool("peer.tls.enabled") {
creds, err := credentials.NewServerTLSFromFile(viper.GetString("peer.tls.cert.file"), viper.GetString("peer.tls.key.file"))
if err != nil {
return nil, fmt.Errorf("Failed to generate credentials %v", err)
}
opts = []grpc.ServerOption{grpc.Creds(creds)}
}
grpcServer := grpc.NewServer(opts...)
viper.Set("peer.fileSystemPath", filepath.Join(os.TempDir(), "hyperledger", "production"))
peerAddress, err := peer.GetLocalAddress()
if err != nil {
return nil, fmt.Errorf("Error obtaining peer address: %s", err)
}
lis, err := net.Listen("tcp", peerAddress)
if err != nil {
return nil, fmt.Errorf("Error starting peer listener %s", err)
}
//initialize ledger
peer.MockInitialize()
getPeerEndpoint := func() (*pb.PeerEndpoint, error) {
return &pb.PeerEndpoint{ID: &pb.PeerID{Name: "testpeer"}, Address: peerAddress}, nil
}
// Install security object for peer
if viper.GetBool("security.enabled") {
//TODO: integrate new crypto / idp
securityLevel := viper.GetInt("security.level")
hashAlgorithm := viper.GetString("security.hashAlgorithm")
primitives.SetSecurityLevel(hashAlgorithm, securityLevel)
} else {
// the primitives need to be instantiated no matter what. Otherwise
// the escc code won't have a hash algorithm available to hash the proposal
primitives.SetSecurityLevel("SHA2", 256)
}
ccStartupTimeout := time.Duration(30000) * time.Millisecond
pb.RegisterChaincodeSupportServer(grpcServer, chaincode.NewChaincodeSupport(getPeerEndpoint, false, ccStartupTimeout))
chaincode.RegisterSysCCs()
if err = peer.MockCreateChain(chainID); err != nil {
closeListenerAndSleep(lis)
return nil, err
}
chaincode.DeploySysCCs(chainID)
go grpcServer.Serve(lis)
return lis, nil
}
示例2: TestGetValue_Clear_NullTCert
func TestGetValue_Clear_NullTCert(t *testing.T) {
primitives.SetSecurityLevel("SHA3", 256)
_, err := GetValueFrom("position", nil)
if err == nil {
t.Error(err)
}
}
示例3: TestGetValue_Clear_InvalidAttribute
func TestGetValue_Clear_InvalidAttribute(t *testing.T) {
primitives.SetSecurityLevel("SHA3", 256)
tcert, err := loadTCertClear()
if err != nil {
t.Error(err)
}
tcertder := tcert.Raw
/*
TODO: ##attributes-keys-pending This code have be redefined to avoid use of metadata field.
metadata := []byte{32, 64}
attributeMetadata, err := attributes.CreateAttributesMetadata(tcertder, metadata, prek0, attributeNames)
if err != nil {
t.Error(err)
}
stub := &chaincodeStubMock{callerCert: tcertder, metadata: attributeMetadata}*/
stub := &chaincodeStubMock{callerCert: tcertder}
handler, err := NewAttributesHandlerImpl(stub)
if err != nil {
t.Error(err)
}
value, err := handler.GetValue("age")
if value != nil || err == nil {
t.Fatalf("Test should fail [%v] \n", string(value))
}
}
示例4: main
func main() {
primitives.SetSecurityLevel("SHA3", 256)
err := shim.Start(new(AssetManagementChaincode))
if err != nil {
fmt.Printf("Error starting AssetManagementChaincode: %s", err)
}
}
示例5: TestSignatureVerifierSHA2_384
func TestSignatureVerifierSHA2_384(t *testing.T) {
// Create a signature
primitives.SetSecurityLevel("SHA2", 384)
cert, key, err := utils.NewSelfSignedCert()
if err != nil {
t.Fatal(err)
}
message := []byte("Hello World!")
signature, err := utils.ECDSASign(key, message)
if err != nil {
t.Fatal(err)
}
// Instantiate a new SignatureVerifier
sv := NewX509ECDSASignatureVerifier()
// Verify the signature
ok, err := sv.Verify(cert, signature, message)
if err != nil {
t.Fatal(err)
}
if !ok {
t.Fatal("Signature does not verify")
}
}
示例6: TestVerifyAttribute
func TestVerifyAttribute(t *testing.T) {
primitives.SetSecurityLevel("SHA3", 256)
/*
TODO: ##attributes-keys-pending This code have be redefined to avoid use of metadata field.
tcert, prek0, err := loadTCertAndPreK0() */
tcert, err := loadTCertClear()
if err != nil {
t.Error(err)
}
tcertder := tcert.Raw
/*
TODO: ##attributes-keys-pending This code have be redefined to avoid use of metadata field.
metadata := []byte{32, 64}
attributeMetadata, err := attributes.CreateAttributesMetadata(tcertder, metadata, prek0, attributeNames)
if err != nil {
t.Error(err)
}
stub := &chaincodeStubMock{callerCert: tcertder, metadata: attributeMetadata}*/
stub := &chaincodeStubMock{callerCert: tcertder}
handler, err := NewAttributesHandlerImpl(stub)
if err != nil {
t.Error(err)
}
isOk, err := handler.VerifyAttribute("position", []byte("Software Engineer"))
if err != nil {
t.Error(err)
}
if !isOk {
t.Fatal("Attribute not verified.")
}
}
示例7: TestMain
func TestMain(m *testing.M) {
// setup crypto algorithms
primitives.SetSecurityLevel("SHA2", 256)
// setup the MSP manager so that we can sign/verify
mspMgrConfigDir := "../../msp/sampleconfig/"
err := mspmgmt.LoadFakeSetupWithLocalMspAndTestChainMsp(mspMgrConfigDir)
if err != nil {
fmt.Printf("Could not initialize msp, err %s", err)
os.Exit(-1)
return
}
signer, err = mspmgmt.GetLocalMSP().GetDefaultSigningIdentity()
if err != nil {
fmt.Printf("Could not get signer")
os.Exit(-1)
return
}
signerSerialized, err = signer.Serialize()
if err != nil {
fmt.Printf("Could not serialize identity")
os.Exit(-1)
return
}
os.Exit(m.Run())
}
示例8: TestGetValue_Clear
func TestGetValue_Clear(t *testing.T) {
primitives.SetSecurityLevel("SHA3", 256)
tcert, err := loadTCertClear()
if err != nil {
t.Error(err)
}
tcertder := tcert.Raw
value, err := GetValueFrom("position", tcertder)
if err != nil {
t.Error(err)
}
if bytes.Compare(value, []byte("Software Engineer")) != 0 {
t.Fatalf("Value expected was [%v] and result was [%v].", []byte("Software Engineer"), value)
}
//Second time read from cache.
value, err = GetValueFrom("position", tcertder)
if err != nil {
t.Error(err)
}
if bytes.Compare(value, []byte("Software Engineer")) != 0 {
t.Fatalf("Value expected was [%v] and result was [%v].", []byte("Software Engineer"), value)
}
}
示例9: TestVerifyAttributes_InvalidHeader
func TestVerifyAttributes_InvalidHeader(t *testing.T) {
primitives.SetSecurityLevel("SHA3", 256)
/*
TODO: ##attributes-keys-pending This code have be redefined to avoid use of metadata field.
tcert, prek0, err := loadTCertAndPreK0() */
tcert, err := loadTCertClear()
if err != nil {
t.Error(err)
}
//Change header extensions
tcert.Raw[583] = tcert.Raw[583] + 124
tcertder := tcert.Raw
/*
TODO: ##attributes-keys-pending This code have be redefined to avoid use of metadata field.
metadata := []byte{32,64}
attributeMetadata, err := attributes.CreateAttributesMetadata(tcertder, metadata, prek0, attributeNames)
if err != nil {
t.Error(err)
}
stub := &chaincodeStubMock{callerCert: tcertder, metadata: attributeMetadata}*/
stub := &chaincodeStubMock{callerCert: tcertder}
handler, err := NewAttributesHandlerImpl(stub)
if err != nil {
t.Error(err)
}
_, err = handler.VerifyAttributes(&accesscontrol.Attribute{Name: "position", Value: []byte("Software Engineer")})
if err == nil {
t.Fatal("Error can't be nil.")
}
}
示例10: setupTestConfig
func setupTestConfig() {
primitives.SetSecurityLevel("SHA3", 256)
viper.AutomaticEnv()
viper.SetConfigName("ca_test") // name of config file (without extension)
viper.AddConfigPath("./") // path to look for the config file in
viper.AddConfigPath("./..") // path to look for the config file in
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
}
示例11: TestGetValue_BadHeaderTCert
func TestGetValue_BadHeaderTCert(t *testing.T) {
primitives.SetSecurityLevel("SHA3", 256)
tcert, err := loadTCertFromFile("./test_resources/tcert_bad.dump")
if err != nil {
t.Error(err)
}
tcertder := tcert.Raw
_, err = GetValueFrom("position", tcertder)
if err == nil {
t.Fatal("Test should be fail due TCert has an invalid header.")
}
}
示例12: TestMain
func TestMain(m *testing.M) {
var err error
primitives.SetSecurityLevel("SHA2", 256)
// setup the MSP manager so that we can sign/verify
mspMgrConfigDir := "../../msp/sampleconfig/"
mspmgmt.LoadFakeSetupWithLocalMspAndTestChainMsp(mspMgrConfigDir)
signer, err = mspmgmt.GetLocalMSP().GetDefaultSigningIdentity()
if err != nil {
os.Exit(-1)
fmt.Printf("Could not initialize msp/signer")
return
}
SetupTestConfig()
os.Exit(m.Run())
}
示例13: TestNewAttributesHandlerImpl_InvalidCertificate
func TestNewAttributesHandlerImpl_InvalidCertificate(t *testing.T) {
primitives.SetSecurityLevel("SHA3", 256)
tcert, _, err := loadTCertAndPreK0()
if err != nil {
t.Error(err)
}
tcertder := tcert.Raw
if err != nil {
t.Error(err)
}
tcertder[0] = tcertder[0] + 1
stub := &metadataErrorMock{callerCert: tcertder}
_, err = NewAttributesHandlerImpl(stub)
if err == nil {
t.Fatal("Error shouldn't be nil")
}
}
示例14: TestGetValue
func TestGetValue(t *testing.T) {
primitives.SetSecurityLevel("SHA3", 256)
/*
TODO: ##attributes-keys-pending This code have be redefined to avoid use of metadata field.
tcert, prek0, err := loadTCertAndPreK0() */
tcert, err := loadTCertClear()
if err != nil {
t.Error(err)
}
tcertder := tcert.Raw
/*
TODO: ##attributes-keys-pending This code have be redefined to avoid use of metadata field.
metadata := []byte{32, 64}
attributeMetadata, err := attributes.CreateAttributesMetadata(tcertder, metadata, prek0, attributeNames)
if err != nil {
t.Error(err)
}
stub := &chaincodeStubMock{callerCert: tcertder, metadata: attributeMetadata}*/
stub := &chaincodeStubMock{callerCert: tcertder}
handler, err := NewAttributesHandlerImpl(stub)
if err != nil {
t.Error(err)
}
value, err := handler.GetValue("position")
if err != nil {
t.Error(err)
}
if bytes.Compare(value, []byte("Software Engineer")) != 0 {
t.Fatalf("Value expected was [%v] and result was [%v].", []byte("Software Engineer"), value)
}
//Second time read from cache.
value, err = handler.GetValue("position")
if err != nil {
t.Error(err)
}
if bytes.Compare(value, []byte("Software Engineer")) != 0 {
t.Fatalf("Value expected was [%v] and result was [%v].", []byte("Software Engineer"), value)
}
}
示例15: TestNewAttributesHandlerImpl_NullCertificate
func TestNewAttributesHandlerImpl_NullCertificate(t *testing.T) {
primitives.SetSecurityLevel("SHA3", 256)
/*
TODO: ##attributes-keys-pending This code have be redefined to avoid use of metadata field.
tcert, prek0, err := loadTCertAndPreK0()
tcert, err := loadTCertClear()
if err != nil {
t.Error(err)
}
metadata := []byte{32, 64}
tcertder := tcert.Raw
attributeMetadata, err := attributes.CreateAttributesMetadata(tcertder, metadata, prek0, attributeNames)
if err != nil {
t.Error(err)
}
stub := &chaincodeStubMock{callerCert: nil, metadata: attributeMetadata}*/
stub := &chaincodeStubMock{callerCert: nil}
_, err := NewAttributesHandlerImpl(stub)
if err == nil {
t.Fatal("Error can't be nil.")
}
}