ClientIdentity接口练习

学习/github.com/hyperledger/fabric-chaincode-go/pkg/cid/interfaces.go中的ClientIdentity接口,源码如下,比较简单:

源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// ClientIdentity represents information about the identity that submitted the
// transaction
// ClientIdentity表示提交交易的身份的信息
type ClientIdentity interface {

// GetID returns the ID associated with the invoking identity. This ID
// is guaranteed to be unique within the MSP.
// 返回与调用者身份关联的ID。该ID在MSP中保证是唯一的。
GetID() (string, error)

// Return the MSP ID of the client
// 获取客户端的MSP的ID
GetMSPID() (string, error)

// GetAttributeValue returns the value of the client's attribute named `attrName`.
// If the client possesses the attribute, `found` is true and `value` equals the
// value of the attribute.
// If the client does not possess the attribute, `found` is false and `value`
// equals "".
// 返回名为`attrName`的客户端的属性信息
// 如果客户端有这个属性,返回值`found`等于true并且返回值`value`等于这个属性。
// 如果这个客户端不拥有这个属性,`found`等于false并且`value`等于""。
GetAttributeValue(attrName string) (value string, found bool, err error)

// AssertAttributeValue verifies that the client has the attribute named `attrName`
// with a value of `attrValue`; otherwise, an error is returned.
// 验证客户端是否有名为`attrName`的属性,并且值为`attrValue`;如果没有或者值不一致则返回一个error
AssertAttributeValue(attrName, attrValue string) error

// GetX509Certificate returns the X509 certificate associated with the client,
// or nil if it was not identified by an X509 certificate.
// 返回与客户端关联的X509证书,如果没有被X509证书标识,则返回nil。
GetX509Certificate() (*x509.Certificate, error)
}

测试代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main

import (
"github.com/hyperledger/fabric-contract-api-go/contractapi"
"log"
)

// ClientIdentityPractice ClientIdentity接口提供的方法练习
func (s *SmartContract) ClientIdentityPractice(ctx contractapi.TransactionContextInterface) error {
log.Println("ClientIdentityPractice==================start=====================")
clientIdentity := ctx.GetClientIdentity()
id, err := clientIdentity.GetID()
if err != nil {
return err
}
log.Printf("clientIdentity.GetID()=%s", id)
mspid, err := clientIdentity.GetMSPID()
if err != nil {
return err
}
log.Printf("clientIdentity.GetMSPID()=%s", mspid)
certificate, err := clientIdentity.GetX509Certificate()
if err != nil {
return err
}
log.Printf("clientIdentity.GetX509Certificate()=%#v", certificate)
value, found, err := clientIdentity.GetAttributeValue("test")
if err != nil {
return err
}
if found {
log.Printf("clientIdentity.GetAttributeValue(\"test\")=%s", value)
}
if err := clientIdentity.AssertAttributeValue("test", "hello"); err != nil {
log.Printf("clientIdentity.AssertAttributeValue(\"test\", \"hello\") error!")
return err
}

log.Println("ClientIdentityPractice===================end======================")
return nil
}

测试日志

1
2
3
4
5
2021/01/25 03:42:33 ClientIdentityPractice==================start=====================
2021/01/25 03:42:33 clientIdentity.GetID()=eDUwOTo6Q049QWRtaW5AczIuc3VwcGx5LmNvbSxMPVNhbiBGcmFuY2lzY28sU1Q9Q2FsaWZvcm5pYSxDPVVTOjpDTj1jYS5zMi5zdXBwbHkuY29tLE89czIuc3VwcGx5LmNvbSxMPVNhbiBGcmFuY2lzY28sU1Q9Q2FsaWZvcm5pYSxDPVVT
2021/01/25 03:42:33 clientIdentity.GetMSPID()=GylSOrg2MSP
2021/01/25 03:42:33 clientIdentity.GetX509Certificate()=&x509.Certificate{Raw:[]uint8{0x30, 0x82, 0x2, 0x11, 0x30, 0x82, 0x1, 0xb7, 0xa0, 0x3, 0x2, 0x1, 0x2, 0x2, 0x11, 0x0, 0x9c, 0x36, 0x61, 0x42, 0xa4, 0x9b, 0x22, 0xae, 0xb0, 0x61, 0xe6, 0xdf, 0x70, 0xfb, 0x2e, 0x19, 0x30, 0xa, 0x6, 0x8, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x4, 0x3, 0x2, 0x30, 0x6d, 0x31, 0xb, 0x30, 0x9, 0x6, 0x3, 0x55, 0x4, 0x6, 0x13, 0x2, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x6, 0x3, 0x55, 0x4, 0x8, 0x13, 0xa, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61, 0x31, 0x16, 0x30, 0x14, 0x6, 0x3, 0x55, 0x4, 0x7, 0x13, 0xd, 0x53, 0x61, 0x6e, 0x20, 0x46, 0x72, 0x61, 0x6e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x31, 0x16, 0x30, 0x14, 0x6, 0x3, 0x55, 0x4, 0xa, 0x13, 0xd, 0x73, 0x32, 0x2e, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x31, 0x19, 0x30, 0x17, 0x6, 0x3, 0x55, 0x4, 0x3, 0x13, 0x10, 0x63, 0x61, 0x2e, 0x73, 0x32, 0x2e, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0xd, 0x32, 0x31, 0x30, 0x31, 0x30, 0x37, 0x30, 0x38, 0x33, 0x31, 0x30, 0x30, 0x5a, 0x17, 0xd, 0x33, 0x31, 0x30, 0x31, 0x30, 0x35, 0x30, 0x38, 0x33, 0x31, 0x30, 0x30, 0x5a, 0x30, 0x58, 0x31, 0xb, 0x30, 0x9, 0x6, 0x3, 0x55, 0x4, 0x6, 0x13, 0x2, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x6, 0x3, 0x55, 0x4, 0x8, 0x13, 0xa, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61, 0x31, 0x16, 0x30, 0x14, 0x6, 0x3, 0x55, 0x4, 0x7, 0x13, 0xd, 0x53, 0x61, 0x6e, 0x20, 0x46, 0x72, 0x61, 0x6e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x31, 0x1c, 0x30, 0x1a, 0x6, 0x3, 0x55, 0x4, 0x3, 0xc, 0x13, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x40, 0x73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 0x3, 0x2, 0x3, 0x48, 0x0, 0x30, 0x45, 0x2, 0x21, 0x0, 0x91, 0x4, 0x2f, 0xee, 0x17, 0xca, 0x28, 0x68, 0xb4, 0x33, 0x48, 0x3a, 0x3a, 0x7b, 0x9f, 0xb8, 0x51, 0xb0, 0x6a, 0x8d, 0x28, 0xb9, 0x31, 0x4c, 0xb7, 0x21, 0x87, 0xd5, 0xac, 0xce, 0x6d, 0x1d, 0x2, 0x20, 0x68, 0x61, 0xca, 0x5d, 0xc2, 0x99, 0x63, 0xba, 0xb4, 0x4f, 0x1b, 0x3a, 0x2e, 0xc6, 0xed, 0x6b, 0x25, 0xba, 0x91, 0x63, 0xce, 0x1, 0xe7, 0xba, 0x67, 0x55, 0xbc, 0xb6, 0x8a, 0x76, 0x54, 0x37}, RawTBSCertificate:[]uint8{0x30, 0x82, 0x1, 0xb7, 0xa0, 0x3, 0x2, 0x1, 0x2, 0x2, 0x11, 0x0, 0x9c, 0x36, 0x61, 0x42, 0xa4, 0x9b, 0x22, 0xae, 0xb0, 0x61, 0xe6, 0xdf, 0x70, 0xfb, 0x2e, 0x19, 0x30, 0xa, 0x6, 0x8, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x4, 0x3, 0x2, 0x30, 0x6d, 0x31, 0xb, 0x30, 0x9, 0x6, 0x3, 0x55, 0x4, 0x6, 0x13, 0x2, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x6, 0x3, 0x55, 0x4, 0x8, 0x13, 0xa, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61, 0x31, 0x16, 0x30, 0x14, 0x6, 0x3, 0x55, 0x4, 0x7, 0x13, 0xd, 0x53, 0x61, 0x6e, 0x20, 0x46, 0x72, 0x61, 0x6e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x31, 0x16, 0x30, 0x14, 0x6, 0x3, 0x55, 0x4, 0xa, 0x13, 0xd, 0x73, 0x32, 0x2e, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x31, 0x19, 0x30, 0x17, 0x6, 0x3, 0x55, 0x4, 0x3, 0x13, 0x10, 0x63, 0x61, 0x2e, 0x73, 0x32, 0x2e, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x1e, 0x17, 0xd, 0x32, 0x31, 0x30, 0x31, 0x30, 0x37, 0x30, 0x38, 0x33, 0x31, 0x30, 0x30, 0x5a, 0x17, 0xd, 0x33, 0x31, 0x30, 0x31, 0x30, 0x35, 0x30, 0x38, 0x33, 0x31, 0x30, 0x30, 0x5a, 0x30, 0x58, 0x31, 0xb, 0x30, 0x9, 0x6, 0x3, 0x55, 0x4, 0x6, 0x13, 0x2, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x6, 0x3, 0x55, 0x4, 0x8, 0x13, 0xa, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61, 0x31, 0x16, 0x30, 0x14, 0x6, 0x3, 0x55, 0x4, 0x7, 0x13, 0xd, 0x53, 0x61, 0x6e, 0x20, 0x46, 0x72, 0x61, 0x6e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x31, 0x1c, 0x30, 0x1a, 0x6, 0x3, 0x55, 0x4, 0x3, 0xc, 0x13, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x40, 0x73, 0x32, 0x2e, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x59, 0x30, 0x13, 0x6, 0x7, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x2, 0x1, 0x6, 0x8, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x3, 0x1, 0x7, 0x3, 0x42, 0x0, 0x4, 0x9e, 0x80, 0x9f, 0x9b, 0xc7, 0x9a, 0xe8, 0x35, 0x60, 0x12, 0x14, 0x5c, 0xab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x91, 0x26, 0x5f, 0x5, 0x65, 0xc7, 0x0, 0x8e, 0x2a, 0x97, 0xea, 0x28, 0xea, 0xf5, 0x5d, 0xd9, 0x34, 0xd, 0x63, 0x25, 0x1, 0x3, 0xd0, 0x23, 0x17, 0x97, 0x92, 0xd7, 0x55, 0x4, 0x9c, 0x45, 0x73, 0x82}, RawSubject:[]uint8{0x30, 0x58, 0x31, 0xb, 0x30, 0x9, 0x6, 0x3, 0x55, 0x4, 0x6, 0x13, 0x2, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x6, 0x3, 0x55, 0x4, 0x8, 0x13, 0xa, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61, 0x31, 0x16, 0x30, 0x14, 0x6, 0x3, 0x55, 0x4, 0x7, 0x13, 0xd, 0x53, 0x61, 0x6e, 0x20, 0x46, 0x72, 0x61, 0x6e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x31, 0x1c, 0x30, 0x1a, 0x6, 0x3, 0x55, 0x4, 0x3, 0xc, 0x13, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x40, 0x73, 0x32, 0x2e, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x2e, 0x63, 0x6f, 0x6d}, RawIssuer:[]uint8{0x30, 0x6d, 0x31, 0xb, 0x30, 0x9, 0x6, 0x3, 0x55, 0x4, 0x6, 0x13, 0x2, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x6, 0x3, 0x55, 0x4, 0x8, 0x13, 0xa, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61, 0x31, 0x16, 0x30, 0x14, 0x6, 0x3, 0x55, 0x4, 0x7, 0x13, 0xd, 0x53, 0x61, 0x6e, 0x20, 0x46, 0x72, 0x61, 0x6e, 0x63, 0x69, 0x73, 0x63, 0x6f, 0x31, 0x16, 0x30, 0x14, 0x6, 0x3, 0x55, 0x4, 0xa, 0x13, 0xd, 0x73, 0x32, 0x2e, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x31, 0x19, 0x30, 0x17, 0x6, 0x3, 0x55, 0x4, 0x3, 0x13, 0x10, 0x63, 0x61, 0x2e, 0x73, 0x32, 0x2e, 0x73, 0x75, 0x70, 0x70, 0x6c, 0x79, 0x2e, 0x63, 0x6f, 0x6d}, Signature:[]uint8{0x30, 0x45, 0x2, 0x21, 0x0, 0x91, 0x4, 0x2f, 0xee, 0x17, 0xca, 0x28, 0x68, 0xb4, 0x33, 0x48, 0x3a, 0x3a, 0x7b, 0x9f, 0xb8, 0x51, 0xb0, 0x6a, 0x8d, 0x28, 0xb9, 0x31, 0x4c, 0xb7, 0x21, 0x87, 0xd5, 0xac, 0xce, 0x6d, 0x1d, 0x2, 0x20, 0x68, 0x61, 0xca, 0x5d, 0xc2, 0x99, 0x63, 0xba, 0xb4, 0x4f, 0x1b, 0x3a, 0x2e, 0xc6, 0xed, 0x6b, 0x25, 0xba, 0x91, 0x63, 0xce, 0x1, 0xe7, 0xba, 0x67, 0x55, 0xbc, 0xb6, 0x8a, 0x76, 0x54, 0x37}, SignatureAlgorithm:10, PublicKeyAlgorithm:3, PublicKey:(*ecdsa.PublicKey)(0xc0003f4980), Version:3, SerialNumber:207641924046541125914056390919893757465, Issuer:pkix.Name{Country:[]string{"US"}, Organization:[]string{"s2.supply.com"}, OrganizationalUnit:[]string(nil), Locality:[]string{"San Francisco"}, Province:[]string{"California"}, StreetAddress:[]string(nil), PostalCode:[]string(nil), SerialNumber:"", CommonName:"ca.s2.supply.com", Names:[]pkix.AttributeTypeAndValue{pkix.AttributeTypeAndValue{Type:asn1.ObjectIdentifier{2, 5, 4, 6}, Value:"US"}, pkix.AttributeTypeAndValue{Type:asn1.ObjectIdentifier{2, 5, 4, 8}, Value:"California"}, pkix.AttributeTypeAndValue{Type:asn1.ObjectIdentifier{2, 5, 4, 7}, Value:"San Francisco"}, pkix.AttributeTypeAndValue{Type:asn1.ObjectIdentifier{2, 5, 4, 10}, Value:"s2.supply.com"}, pkix.AttributeTypeAndValue{Type:asn1.ObjectIdentifier{2, 5, 4, 3}, Value:"ca.s2.supply.com"}}, ExtraNames:[]pkix.AttributeTypeAndValue(nil)}, Subject:pkix.Name{Country:[]string{"US"}, Organization:[]string(nil), OrganizationalUnit:[]string(nil), Locality:[]string{"San Francisco"}, Province:[]string{"California"}, StreetAddress:[]string(nil), PostalCode:[]string(nil), SerialNumber:"", CommonName:"Admin@s2.supply.com", Names:[]pkix.AttributeTypeAndValue{pkix.AttributeTypeAndValue{Type:asn1.ObjectIdentifier{2, 5, 4, 6}, Value:"US"}, pkix.AttributeTypeAndValue{Type:asn1.ObjectIdentifier{2, 5, 4, 8}, Value:"California"}, pkix.AttributeTypeAndValue{Type:asn1.ObjectIdentifier{2, 5, 4, 7}, Value:"San Francisco"}, pkix.AttributeTypeAndValue{Type:asn1.ObjectIdentifier{2, 5, 4, 3}, Value:"Admin@s2.supply.com"}}, ExtraNames:[]pkix.AttributeTypeAndValue(nil)}, NotBefore:time.Time{wall:0x0, ext:63745605060, loc:(*time.Location)(nil)}, NotAfter:time.Time{wall:0x0, ext:64060965060, loc:(*time.Location)(nil)}, KeyUsage:1, Extensions:[]pkix.Extension{pkix.Extension{Id:asn1.ObjectIdentifier{2, 5, 29, 15}, Critical:true, Value:[]uint8{0x3, 0x2, 0x7, 0x80}}, pkix.Extension{Id:asn1.ObjectIdentifier{2, 5, 29, 19}, Critical:true, Value:[]uint8{0x30, 0x0}}, pkix.Extension{Id:asn1.ObjectIdentifier{2, 5, 29, 35}, Critical:false, Value:[]uint8{0x30, 0x22, 0x80, 0x20, 0x63, 0xbd, 0xab, 0x9a, 0x9c, 0xa7, 0x4f, 0x3d, 0x8b, 0xb6, 0xc3, 0xab, 0xc, 0xb1, 0x45, 0x87, 0x60, 0x69, 0x7e, 0xb9, 0x6, 0xfb, 0x38, 0x5f, 0x9c, 0x2, 0xb1, 0x75, 0x9b, 0xc6, 0x3d, 0xfb}}}, ExtraExtensions:[]pkix.Extension(nil), UnhandledCriticalExtensions:[]asn1.ObjectIdentifier(nil), ExtKeyUsage:[]x509.ExtKeyUsage(nil), UnknownExtKeyUsage:[]asn1.ObjectIdentifier(nil), BasicConstraintsValid:true, IsCA:false, MaxPathLen:-1, MaxPathLenZero:false, SubjectKeyId:[]uint8(nil), AuthorityKeyId:[]uint8{0x63, 0xbd, 0xab, 0x9a, 0x9c, 0xa7, 0x4f, 0x3d, 0x8b, 0xb6, 0xc3, 0xab, 0xc, 0xb1, 0x45, 0x87, 0x60, 0x69, 0x7e, 0xb9, 0x6, 0xfb, 0x38, 0x5f, 0x9c, 0x2, 0xb1, 0x75, 0x9b, 0xc6, 0x3d, 0xfb}, OCSPServer:[]string(nil), IssuingCertificateURL:[]string(nil), DNSNames:[]string(nil), EmailAddresses:[]string(nil), IPAddresses:[]net.IP(nil), URIs:[]*url.URL(nil), PermittedDNSDomainsCritical:false, PermittedDNSDomains:[]string(nil), ExcludedDNSDomains:[]string(nil), PermittedIPRanges:[]*net.IPNet(nil), ExcludedIPRanges:[]*net.IPNet(nil), PermittedEmailAddresses:[]string(nil), ExcludedEmailAddresses:[]string(nil), PermittedURIDomains:[]string(nil), ExcludedURIDomains:[]string(nil), CRLDistributionPoints:[]string(nil), PolicyIdentifiers:[]asn1.ObjectIdentifier(nil)}
2021/01/25 03:42:33 clientIdentity.AssertAttributeValue("test", "hello") error!

测试日志分析

clientIdentity.GetID()

源码
1
2
id := fmt.Sprintf("x509::%s::%s", getDN(&c.cert.Subject), getDN(&c.cert.Issuer))
return base64.StdEncoding.EncodeToString([]byte(id)), nil

解码日志输出的base64编码的内容eDUwOTo6Q049QWRtaW5AczIuc3VwcGx5LmNvbSxMPVNhbiBGcmFuY2lzY28sU1Q9Q2FsaWZvcm5pYSxDPVVTOjpDTj1jYS5zMi5zdXBwbHkuY29tLE89czIuc3VwcGx5LmNvbSxMPVNhbiBGcmFuY2lzY28sU1Q9Q2FsaWZvcm5pYSxDPVVT结果如下,主要是证书里面的摘要信息:

1
x509::CN=Admin@s2.supply.com,L=San Francisco,ST=California,C=US::CN=ca.s2.supply.com,O=s2.supply.com,L=San Francisco,ST=California,C=US

clientIdentity.GetAttributeValue(“test”)

log.Printf("clientIdentity.GetAttributeValue(\"test\")=%s", value)这行日志没有打印,是因为没有查询到这个属性。