Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add v2 with github.com/hyperledger/fabric-protos-go-apiv2 #48

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bin
.idea
225 changes: 225 additions & 0 deletions v2/audit_aries_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
/*
Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package idemix

import (
"testing"

bccsp "github.com/IBM/idemix/bccsp/types"
im "github.com/IBM/idemix/v2/idemixmsp"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
)

func TestAuditAries(t *testing.T) {
msp, err := NewIdemixMspAries(MSPv1_3)
assert.NoError(t, err)

// fixtures in testdata/aries/EidRH were generated by running:
// idemixgen ca-keygen --aries
// idemixgen signerconfig --aries --ca-input=./idemix-config/ --enrollmentId=my-enrollment-id --revocationHandle=my-revocation-handle --org-unit=my-ou

conf, err := GetIdemixMspConfigWithType("testdata/aries/EidRH", "EidRH", IDEMIX_ARIES)
assert.NoError(t, err)

err = msp.Setup(conf)
assert.NoError(t, err)

id, err := msp.GetDefaultSigningIdentity()
assert.NoError(t, err)

idemixSigner := id.(*IdemixSigningIdentity)

config := &im.IdemixMSPConfig{}
err = proto.Unmarshal(conf.Config, config)
assert.NoError(t, err)

idemixMsp := msp.(*Idemixmsp)
csp := idemixMsp.csp

msg := []byte("Lost forever, now and ever\nTo this magical sound that I hear")

// STEP 1: Sign and Verify normally

signature, err := csp.Sign(
idemixSigner.UserKey,
msg,
&bccsp.IdemixSignerOpts{
Credential: idemixSigner.Cred,
Nym: idemixSigner.NymKey,
IssuerPK: idemixMsp.ipk,
Attributes: []bccsp.IdemixAttribute{
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
},
RhIndex: AttributeIndexRevocationHandle,
EidIndex: AttributeIndexEnrollmentId,
Epoch: 0,
CRI: config.Signer.CredentialRevocationInformation,
},
)
assert.NoError(t, err)

valid, err := csp.Verify(
idemixMsp.ipk,
signature,
msg,
&bccsp.IdemixSignerOpts{
RevocationPublicKey: idemixMsp.revocationPK,
Attributes: []bccsp.IdemixAttribute{
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
},
RhIndex: AttributeIndexRevocationHandle,
EidIndex: AttributeIndexEnrollmentId,
Epoch: 0,
VerificationType: bccsp.BestEffort,
},
)
assert.NoError(t, err)
assert.True(t, valid)

// STEP 2: Sign by also generating a commitment to the EID (and Verify)

sOpts := &bccsp.IdemixSignerOpts{
SigType: bccsp.EidNym,
Credential: idemixSigner.Cred,
Nym: idemixSigner.NymKey,
IssuerPK: idemixMsp.ipk,
Attributes: []bccsp.IdemixAttribute{
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
},
RhIndex: AttributeIndexRevocationHandle,
EidIndex: AttributeIndexEnrollmentId,
Epoch: 0,
CRI: config.Signer.CredentialRevocationInformation,
}

signature, err = csp.Sign(
idemixSigner.UserKey,
msg,
sOpts,
)
assert.NoError(t, err)

valid, err = csp.Verify(
idemixMsp.ipk,
signature,
msg,
&bccsp.IdemixSignerOpts{
RevocationPublicKey: idemixMsp.revocationPK,
Attributes: []bccsp.IdemixAttribute{
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
},
RhIndex: AttributeIndexRevocationHandle,
EidIndex: AttributeIndexEnrollmentId,
Epoch: 0,
VerificationType: bccsp.ExpectEidNym,
},
)
assert.NoError(t, err)
assert.True(t, valid)

// STEP 3: audit of the nym eid
valid, err = csp.Verify(
idemixMsp.ipk,
signature,
msg,
&bccsp.EidNymAuditOpts{
EidIndex: AttributeIndexEnrollmentId,
EnrollmentID: config.Signer.EnrollmentId,
RNymEid: sOpts.Metadata.EidNymAuditData.Rand,
},
)
assert.NoError(t, err)
assert.True(t, valid)

// STEP 4: Sign by also generating a commitment to the EID and to the RH (and Verify)

sOpts = &bccsp.IdemixSignerOpts{
SigType: bccsp.EidNymRhNym,
Credential: idemixSigner.Cred,
Nym: idemixSigner.NymKey,
IssuerPK: idemixMsp.ipk,
Attributes: []bccsp.IdemixAttribute{
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
},
RhIndex: AttributeIndexRevocationHandle,
EidIndex: AttributeIndexEnrollmentId,
Epoch: 0,
CRI: config.Signer.CredentialRevocationInformation,
}

signature, err = csp.Sign(
idemixSigner.UserKey,
msg,
sOpts,
)
assert.NoError(t, err)

valid, err = csp.Verify(
idemixMsp.ipk,
signature,
msg,
&bccsp.IdemixSignerOpts{
RevocationPublicKey: idemixMsp.revocationPK,
Attributes: []bccsp.IdemixAttribute{
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
{Type: bccsp.IdemixHiddenAttribute},
},
RhIndex: AttributeIndexRevocationHandle,
EidIndex: AttributeIndexEnrollmentId,
Epoch: 0,
VerificationType: bccsp.ExpectEidNymRhNym,
},
)
assert.NoError(t, err)
assert.True(t, valid)

// STEP 5: audit of the nym eid
valid, err = csp.Verify(
idemixMsp.ipk,
signature,
msg,
&bccsp.EidNymAuditOpts{
EidIndex: AttributeIndexEnrollmentId,
EnrollmentID: config.Signer.EnrollmentId,
RNymEid: sOpts.Metadata.EidNymAuditData.Rand,
},
)
assert.NoError(t, err)
assert.True(t, valid)

// STEP 6: audit of the rh
valid, err = csp.Verify(
idemixMsp.ipk,
signature,
msg,
&bccsp.RhNymAuditOpts{
RhIndex: AttributeIndexRevocationHandle,
RevocationHandle: config.Signer.RevocationHandle,
RNymRh: sOpts.Metadata.RhNymAuditData.Rand,
},
)
assert.NoError(t, err)
assert.True(t, valid)
}
Loading