you can use fabric-ca. Fabric-ca provides several apis for user management. You may register, revoke, enroll, reenroll users by fabric-ca. And the documents for fabric-ca is here.
After you setup your fabric-ca server, you can interactive with fabric-ca server with SDK (currently node-sdk and java-sdk) or fabric-ca client. A sample for java-sdk is here. A sample for node-sdk is here.
And on chaincode side, you can read the cert when each time the user call invoke or query from client. The following is a sample code.
import(
"crypto/x509"
"encoding/pem"
"bytes"
"strings"
"github.com/hyperledger/fabric/core/chaincode/shim"
)
func parseCert(stub){
creator, err := identityService.Stub.GetCreator()
if err != nil {
logger.Debug("Error received on GetCreator", err)
vm.PushErrorObjectVa(duktape.ErrError, "%s", err.Error())
vm.Throw()
return
}
certStart := bytes.IndexAny(creator, "----BEGIN CERTIFICATE-----")
if certStart == -1 {
logger.Debug("No certificate found")
return
}
certText := creator[certStart:]
block, _ := pem.Decode(certText)
if block == nil {
logger.Debug("Error received on pem.Decode of certificate", certText)
return
}
ucert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
logger.Debug("Error received on ParseCertificate", err)
return
}
logger.Debug("Common Name", ucert.Subject.CommonName)
}