Skip to content

Commit 460e78b

Browse files
committed
identity service: protobuf protocol verion
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent bc02815 commit 460e78b

File tree

10 files changed

+178
-112
lines changed

10 files changed

+178
-112
lines changed

token/services/identity/idemix/crypto/config.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type (
2626

2727
const (
2828
ExtraPathElement = "msp"
29+
30+
ProtobufProtocolVersionV1 uint64 = 1
2931
)
3032

3133
// SignerConfig contains the crypto material to set up an idemix signing identity
@@ -162,13 +164,19 @@ func NewConfigFromRaw(issuerPublicKey []byte, configRaw []byte) (*Config, error)
162164
if !bytes.Equal(issuerPublicKey, config.Ipk) {
163165
return nil, errors.Errorf("public key does not match [%s]=[%s]", hash.Hashable(config.Ipk), hash.Hashable(issuerPublicKey))
164166
}
167+
// match version, supported are: ProtobufProtocolVersionV1
168+
if config.Version != ProtobufProtocolVersionV1 {
169+
return nil, errors.Errorf("unsupported protocol version: %d", config.Version)
170+
}
171+
165172
return config, nil
166173
}
167174

168175
func assembleConfig(issuerPublicKey []byte, signer *config.IdemixSignerConfig) (*Config, error) {
169176
idemixConfig := &config.IdemixConfig{
170-
Ipk: issuerPublicKey,
171-
Signer: signer,
177+
Version: ProtobufProtocolVersionV1,
178+
Ipk: issuerPublicKey,
179+
Signer: signer,
172180
}
173181
return idemixConfig, nil
174182
}

token/services/identity/idemix/crypto/protos-go/config/idemix_config.pb.go

Lines changed: 58 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/services/identity/idemix/crypto/protos/idemix_config.proto

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,26 @@ message SerializedIdemixIdentity {
2525
}
2626

2727
message IdemixConfig {
28+
// Version indicates message protocol version
29+
uint64 version = 1;
30+
2831
// Name holds the identifier of the
29-
string name = 1;
32+
string name = 2;
3033

3134
// ipk represents the (serialized) issuer public key
32-
bytes ipk = 2;
35+
bytes ipk = 3;
3336

3437
// signer may contain crypto material to configure a default signer
35-
IdemixSignerConfig signer = 3;
38+
IdemixSignerConfig signer = 4;
3639

3740
// revocation_pk is the public key used for revocation of credentials
38-
bytes revocation_pk = 4;
41+
bytes revocation_pk = 5;
3942

4043
// epoch represents the current epoch (time interval) used for revocation
41-
int64 epoch = 5;
44+
int64 epoch = 6;
4245

4346
// curve_id indicates which Elliptic Curve should be used
44-
string curve_id = 6;
47+
string curve_id = 7;
4548
}
4649

4750
// IdemixSignerConfig contains the crypto material to set up an idemix signing identity
@@ -68,5 +71,5 @@ message IdemixSignerConfig {
6871
string revocation_handle = 7;
6972

7073
// is the identifier of the secret key sk
71-
bytes ski = 9;
74+
bytes ski = 8;
7275
}

token/services/identity/idemix/km.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func NewKeyManager(conf *crypto2.Config, signerService SignerService, sigType bc
4747
if conf == nil {
4848
return nil, errors.New("no idemix config provided")
4949
}
50+
if conf.Version != crypto2.ProtobufProtocolVersionV1 {
51+
return nil, errors.Errorf("unsupported protocol version [%d]", conf.Version)
52+
}
53+
5054
logger.Debugf("setting up Idemix key manager instance %s", conf.Name)
5155

5256
// Import Issuer Public Key

token/services/identity/idemix/km_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ func testNewKeyManager(t *testing.T, configPath string, curveID math.CurveID, ar
4545
cryptoProvider, err := crypto2.NewBCCSP(keyStore, curveID, aries)
4646
assert.NoError(t, err)
4747

48+
// check that version is enforced
49+
config.Version = 0
50+
_, err = NewKeyManager(config, sigService, types.EidNymRhNym, cryptoProvider)
51+
assert.Error(t, err)
52+
assert.EqualError(t, err, "unsupported protocol version [0]")
53+
config.Version = crypto2.ProtobufProtocolVersionV1
54+
4855
// new key manager loaded from file
4956
assert.Empty(t, config.Signer.Ski)
5057
keyManager, err := NewKeyManager(config, sigService, types.EidNymRhNym, cryptoProvider)

token/services/identity/idemix/kmp_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111

1212
math "github.com/IBM/mathlib"
13+
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/proto"
1314
"github.com/hyperledger-labs/fabric-token-sdk/token"
1415
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/driver"
1516
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/idemix/crypto"
@@ -87,6 +88,17 @@ func testNewKeyManagerProvider(t *testing.T, configPath string, curveID math.Cur
8788
signAndVerify(t, km)
8889
checkRawContent(t, config.Ipk, idConfig.Raw)
8990
assert.Equal(t, configRaw, idConfig.Raw)
91+
92+
// change the version in the configuration, it must fail now
93+
config2, err := crypto.NewConfigFromRaw(config.Ipk, idConfig.Raw)
94+
assert.NoError(t, err)
95+
config2.Version = 0
96+
config2Raw, err := proto.Marshal(config2)
97+
assert.NoError(t, err)
98+
idConfig.Raw = config2Raw
99+
_, err = kmp.Get(idConfig)
100+
assert.Error(t, err)
101+
assert.EqualError(t, err, "unsupported protocol version: 0")
90102
}
91103

92104
func signAndVerify(t *testing.T, km membership.KeyManager) {

token/services/identity/x509/crypto/configbuilder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const (
1818
SignCertsDirName = "signcerts"
1919
KeyStoreDirName = "keystore"
2020
PrivSKFileName = "priv_sk"
21+
22+
ProtobufProtocolVersionV1 uint64 = 1
2123
)
2224

2325
func LoadConfig(dir string, keyStoreDirName string) (*Config, error) {
@@ -49,6 +51,7 @@ func LoadConfig(dir string, keyStoreDirName string) (*Config, error) {
4951

5052
func LoadConfigWithIdentityInfo(signingIdentityInfo *SigningIdentityInfo) (*Config, error) {
5153
config := &Config{
54+
Version: ProtobufProtocolVersionV1,
5255
SigningIdentity: signingIdentityInfo,
5356
CryptoConfig: &CryptoConfig{
5457
SignatureHashFamily: bccsp.SHA2,

0 commit comments

Comments
 (0)