-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-6843] Integrating Signing Identity
This change-set does the following: - It integrates the SigningIdentity interface in the TransactionContext class. A SigningIdentity represents the capability of user to sign messages. Indeed, a SigningIdentity instance can be obtanied from an instance of the User interface. This will simplify the integration of different signing algorithms like those offered by idemix. Change-Id: I78eed75938601d42586ac4988040d92896d73e76 Signed-off-by: Angelo De Caro <adc@zurich.ibm.com> Signed-off-by: Manu Drijvers <mdr@zurich.ibm.com> Signed-off-by: Rafa Torres <rtm@zurich.ibm.com>
- Loading branch information
Showing
31 changed files
with
318 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,4 +174,4 @@ Idemix.Credential toProto() { | |
|
||
return builder.build(); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/hyperledger/fabric/sdk/identity/IdemixEnrollment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.hyperledger.fabric.sdk.identity; | ||
|
||
import java.security.KeyPair; | ||
import java.security.PrivateKey; | ||
|
||
import org.hyperledger.fabric.sdk.Enrollment; | ||
|
||
public class IdemixEnrollment implements Enrollment { | ||
|
||
private KeyPair key; | ||
private String cert; | ||
|
||
public IdemixEnrollment(KeyPair signingKeyPair, String signedPem) { | ||
this.key = signingKeyPair; | ||
this.cert = signedPem; | ||
} | ||
|
||
public PrivateKey getKey() { | ||
return key.getPrivate(); | ||
} | ||
|
||
public String getCert() { | ||
return cert; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/hyperledger/fabric/sdk/identity/IdentityFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.hyperledger.fabric.sdk.identity; | ||
|
||
import org.hyperledger.fabric.sdk.Enrollment; | ||
import org.hyperledger.fabric.sdk.User; | ||
import org.hyperledger.fabric.sdk.security.CryptoSuite; | ||
|
||
public class IdentityFactory { | ||
private IdentityFactory() { | ||
// private constructor for utility class | ||
} | ||
|
||
public static SigningIdentity getSigningIdentity(CryptoSuite cryptoSuite, User user) { | ||
Enrollment enrollment = user.getEnrollment(); | ||
|
||
if (enrollment instanceof X509Enrollment) { | ||
return new X509SigningIdentity(cryptoSuite, user); | ||
} | ||
|
||
throw new IllegalStateException("Invalid enrollment. Expected X509Enrollment. " + enrollment); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/org/hyperledger/fabric/sdk/identity/X509Enrollment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.hyperledger.fabric.sdk.identity; | ||
|
||
import java.io.Serializable; | ||
import java.security.KeyPair; | ||
import java.security.PrivateKey; | ||
|
||
import org.hyperledger.fabric.sdk.Enrollment; | ||
|
||
public class X509Enrollment implements Enrollment, Serializable { | ||
|
||
private PrivateKey key; | ||
private String cert; | ||
|
||
public X509Enrollment(KeyPair signingKeyPair, String signedPem) { | ||
key = signingKeyPair.getPrivate(); | ||
this.cert = signedPem; | ||
} | ||
|
||
public X509Enrollment(PrivateKey key, String signedPem) { | ||
this.key = key; | ||
this.cert = signedPem; | ||
} | ||
|
||
public PrivateKey getKey() { | ||
return key; | ||
} | ||
|
||
public String getCert() { | ||
return cert; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/hyperledger/fabric/sdk/identity/X509Identity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.hyperledger.fabric.sdk.identity; | ||
|
||
import org.hyperledger.fabric.protos.msp.Identities; | ||
import org.hyperledger.fabric.sdk.User; | ||
import org.hyperledger.fabric.sdk.transaction.ProtoUtils; | ||
|
||
public class X509Identity implements Identity { | ||
|
||
protected User user; | ||
|
||
public X509Identity(User user) { | ||
if (user == null) { | ||
throw new IllegalArgumentException("User is null"); | ||
} | ||
if (user.getEnrollment() == null) { | ||
throw new IllegalArgumentException("user.getEnrollment() is null"); | ||
} | ||
if (user.getEnrollment().getCert() == null) { | ||
throw new IllegalArgumentException("user.getEnrollment().getCert() is null"); | ||
} | ||
|
||
this.user = user; | ||
} | ||
|
||
@Override | ||
public Identities.SerializedIdentity createSerializedIdentity() { | ||
return ProtoUtils.createSerializedIdentity(user); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/hyperledger/fabric/sdk/identity/X509SigningIdentity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.hyperledger.fabric.sdk.identity; | ||
|
||
import org.hyperledger.fabric.sdk.User; | ||
import org.hyperledger.fabric.sdk.exception.CryptoException; | ||
import org.hyperledger.fabric.sdk.security.CryptoSuite; | ||
|
||
public class X509SigningIdentity extends X509Identity implements SigningIdentity { | ||
|
||
private CryptoSuite cryptoSuite; | ||
|
||
public X509SigningIdentity(CryptoSuite cryptoSuite, User user) { | ||
super(user); | ||
|
||
if (cryptoSuite == null) { | ||
throw new IllegalArgumentException("CryptoSuite is null"); | ||
} | ||
|
||
this.cryptoSuite = cryptoSuite; | ||
} | ||
|
||
@Override | ||
public byte[] sign(byte[] msg) throws CryptoException { | ||
return cryptoSuite.sign(super.user.getEnrollment().getKey(), msg); | ||
} | ||
|
||
@Override | ||
public boolean verifySignature(byte[] msg, byte[] sig) throws CryptoException { | ||
throw new CryptoException("Not Implemented yet!!!"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.