Skip to content

Commit 5997aca

Browse files
author
Keith Smith
committed
[FAB-6466] Improve GetID to return unique ID
Change the implementation of the GetID function to return a value that will be unique across MSPs. It previously just returned the <subjectDN> (Distinquished Name) which is guaranteed to be unique for the CA that issued it. I'm changing it to return the base64 encoding of x509::<subjectDN>::<issuerDN> which is unique across CAs. This also means this ID will be the same even though its certificate is renewed with a different key-pair. An ID for an idemix identity will be of the form: idemix::<something unique for an idemix identity> Change-Id: Ie244460df1340d4facefc6b25f178df0733ee559 Signed-off-by: Keith Smith <bksmith@us.ibm.com>
1 parent 7f4f74d commit 5997aca

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

core/chaincode/lib/cid/cid.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ package cid
1818

1919
import (
2020
"crypto/x509"
21+
"crypto/x509/pkix"
2122
"encoding/asn1"
23+
"encoding/base64"
2224
"encoding/hex"
2325
"encoding/pem"
2426
"fmt"
@@ -95,10 +97,13 @@ func New(stub ChaincodeStubInterface) (ClientIdentity, error) {
9597
return c, nil
9698
}
9799

98-
// GetID returns the ID associated with the invoking identity. This ID
99-
// is guaranteed to be unique within the MSP.
100+
// GetID returns a unique ID associated with the invoking identity.
100101
func (c *clientIdentityImpl) GetID() (string, error) {
101-
return getDN(c.cert), nil
102+
// The leading "x509::" distinquishes this as an X509 certificate, and
103+
// the subject and issuer DNs uniquely identify the X509 certificate.
104+
// The resulting ID will remain the same if the certificate is renewed.
105+
id := fmt.Sprintf("x509::%s::%s", getDN(&c.cert.Subject), getDN(&c.cert.Issuer))
106+
return base64.StdEncoding.EncodeToString([]byte(id)), nil
102107
}
103108

104109
// GetMSPID returns the ID of the MSP associated with the identity that
@@ -180,12 +185,12 @@ func (c *clientIdentityImpl) getIdentity() (*msp.SerializedIdentity, error) {
180185
return sid, nil
181186
}
182187

183-
// Get the DN (distinquished name) associated with the subject of the certificate.
188+
// Get the DN (distinquished name) associated with a pkix.Name.
184189
// NOTE: This code is almost a direct copy of the String() function in
185190
// https://go-review.googlesource.com/c/go/+/67270/1/src/crypto/x509/pkix/pkix.go#26
186191
// which returns a DN as defined by RFC 2253.
187-
func getDN(cert *x509.Certificate) string {
188-
r := cert.Subject.ToRDNSequence()
192+
func getDN(name *pkix.Name) string {
193+
r := name.ToRDNSequence()
189194
s := ""
190195
for i := 0; i < len(r); i++ {
191196
rdn := r[len(r)-1-i]

0 commit comments

Comments
 (0)