{"record":{"id":"9c6f092e04e1f9dd","repo":"hyperledger/fabric","slug":"could-not-unmarshal-mspidentityanonymity-from-prin","errorCode":null,"errorMessage":"could not unmarshal MSPIdentityAnonymity from principal","messagePattern":"could not unmarshal MSPIdentityAnonymity from principal","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"msp/mspimpl.go","lineNumber":595,"sourceCode":"\t\treturn errors.New(\"The identities do not match\")\n\tdefault:\n\t\treturn errors.Errorf(\"invalid principal type %d\", int32(principal.PrincipalClassification))\n\t}\n}\n\n// satisfiesPrincipalInternalV13 takes as arguments the identity and the principal.\n// The function returns an error if one occurred.\n// The function implements the additional behavior expected of an MSP starting from v1.3.\n// For pre-v1.3 functionality, the function calls the satisfiesPrincipalInternalPreV13.\nfunc (msp *bccspmsp) satisfiesPrincipalInternalV13(id Identity, principal *m.MSPPrincipal) error {\n\tswitch principal.PrincipalClassification {\n\tcase m.MSPPrincipal_COMBINED:\n\t\treturn errors.New(\"SatisfiesPrincipalInternal shall not be called with a CombinedPrincipal\")\n\tcase m.MSPPrincipal_ANONYMITY:\n\t\tanon := &m.MSPIdentityAnonymity{}\n\t\terr := proto.Unmarshal(principal.Principal, anon)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"could not unmarshal MSPIdentityAnonymity from principal\")\n\t\t}\n\t\tswitch anon.AnonymityType {\n\t\tcase m.MSPIdentityAnonymity_ANONYMOUS:\n\t\t\treturn errors.New(\"Principal is anonymous, but X.509 MSP does not support anonymous identities\")\n\t\tcase m.MSPIdentityAnonymity_NOMINAL:\n\t\t\treturn nil\n\t\tdefault:\n\t\t\treturn errors.Errorf(\"Unknown principal anonymity type: %d\", anon.AnonymityType)\n\t\t}\n\n\tdefault:\n\t\t// Use the pre-v1.3 function to check other principal types\n\t\treturn msp.satisfiesPrincipalInternalPreV13(id, principal)\n\t}\n}\n\n// satisfiesPrincipalInternalV142 takes as arguments the identity and the principal.\n// The function returns an error if one occurred.","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/msp/mspimpl.go#L577-L613","documentation":"For an ANONYMITY-classified principal, satisfiesPrincipalInternalV13 expects principal.Principal bytes to unmarshal as an MSPIdentityAnonymity proto message. When proto.Unmarshal fails, the principal payload is not a valid encoded MSPIdentityAnonymity and the MSP cannot determine the requested anonymity type, so it wraps and returns the unmarshal error.","triggerScenarios":"Passing an MSPPrincipal with PrincipalClassification=ANONYMITY whose Principal bytes are empty, nil, malformed, or actually an encoded string/role rather than a marshaled m.MSPIdentityAnonymity.","commonSituations":"Building the principal by putting a raw string or role spec into Principal while setting the ANONYMITY classification; a policy file edited by hand truncating the base64 payload; proto version mismatch producing incompatible encoded bytes.","solutions":["Construct the principal with a properly marshaled MSPIdentityAnonymity: proto.Marshal(&m.MSPIdentityAnonymity{AnonymityType: m.MSPIdentityAnonymity_NOMINAL}).","Verify the Principal bytes for ANONYMITY principals are not empty/nil before installing the policy.","If copying policies between environments, re-encode base64 payloads and confirm they decode to a valid MSPIdentityAnonymity message."],"exampleFix":"// before\nprincipal := &m.MSPPrincipal{PrincipalClassification: m.MSPPrincipal_ANONYMITY, Principal: []byte(\"nominal\")}\n// after\nanon, _ := proto.Marshal(&m.MSPIdentityAnonymity{AnonymityType: m.MSPIdentityAnonymity_NOMINAL})\nprincipal := &m.MSPPrincipal{PrincipalClassification: m.MSPPrincipal_ANONYMITY, Principal: anon}","handlingStrategy":"validation","validationCode":"if principal.PrincipalClassification == m.MSPPrincipal_ANONYMITY {\n\tanon := &m.MSPIdentityAnonymity{}\n\tif err := proto.Unmarshal(principal.Principal, anon); err != nil {\n\t\treturn fmt.Errorf(\"malformed anonymity principal: %w\", err)\n\t}\n}","typeGuard":"func isWellFormedAnonymityPrincipal(p *m.MSPPrincipal) bool {\n\tif p == nil || p.PrincipalClassification != m.MSPPrincipal_ANONYMITY || len(p.Principal) == 0 {\n\t\treturn false\n\t}\n\treturn proto.Unmarshal(p.Principal, &m.MSPIdentityAnonymity{}) == nil\n}","tryCatchPattern":null,"preventionTips":["Marshal MSPIdentityAnonymity with proto.Marshal when building ANONYMITY principals.","Reject empty Principal bytes for ANONYMITY classification during policy authoring.","Round-trip unmarshal policies as a pre-install sanity check."],"tags":["msp","proto","unmarshal","anonymity"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}