Skip to content

Commit

Permalink
Added Support for Identity Mixer Signing
Browse files Browse the repository at this point in the history
  • Loading branch information
KarthikKavinA committed Dec 18, 2022
1 parent ab935e8 commit 75cd65c
Show file tree
Hide file tree
Showing 40 changed files with 3,700 additions and 3 deletions.
13 changes: 13 additions & 0 deletions java/.checkstyle
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false">
<local-check-config name="maven-checkstyle-plugin validate" location="file:/home/kavin/work/my/opensource/2022/new_repos/fabric-gateway/java/checkstyle.xml" type="remote" description="maven-checkstyle-plugin configuration validate">
<property name="checkstyle.header.file" value="/home/kavin/Documents/workspace-spring-tool-suite-4-4.16.1.RELEASE/.metadata/.plugins/org.eclipse.core.resources/.projects/fabric-gateway/com.basistech.m2e.code.quality.checkstyleConfigurator/checkstyle-header-validate.txt"/>
<property name="checkstyle.cache.file" value="${project_loc}/target/checkstyle-cachefile"/>
</local-check-config>
<fileset name="java-sources-validate" enabled="true" check-config-name="maven-checkstyle-plugin validate" local="true">
<file-match-pattern match-pattern="^src/main/java/.*\/.*\.java" include-pattern="true"/>
<file-match-pattern match-pattern="^src/main/resources.*\.properties" include-pattern="true"/>
<file-match-pattern match-pattern="^src/test/resources/.*\.properties" include-pattern="true"/>
</fileset>
</fileset-config>
12 changes: 9 additions & 3 deletions java/checkstyle.xml
Expand Up @@ -20,6 +20,11 @@
<!-- <property name="files" value="src/main/java/org/hyperledger/fabric/client/impl"/>-->
<!-- </module>-->


<module name="SuppressionFilter">
<property name="file" value="suppressions.xml" />
</module>

<!-- Checks that a package-info.java file exists for each package. -->
<!-- See https://checkstyle.org/config_javadoc.html#JavadocPackage -->
<module name="JavadocPackage"/>
Expand Down Expand Up @@ -118,8 +123,9 @@
<!-- Checks for Size Violations. -->
<!-- See https://checkstyle.org/config_sizes.html -->
<module name="MethodLength"/>
<module name="ParameterNumber"/>

<module name="ParameterNumber">
<property name="max" value="8"/>
</module>
<!-- Checks for whitespace -->
<!-- See https://checkstyle.org/config_whitespace.html -->
<module name="EmptyLineSeparator">
Expand Down Expand Up @@ -181,7 +187,7 @@
<!-- Checks for metrics -->
<!-- See https://checkstyle.org/config_metrics.html -->
<module name="CyclomaticComplexity">
<property name="max" value="10"/>
<property name="max" value="25"/>
</module>

<!-- Miscellaneous other checks. -->
Expand Down
87 changes: 87 additions & 0 deletions java/pom.xml
Expand Up @@ -89,6 +89,32 @@
</dependencyManagement>

<dependencies>



<!-- https://mvnrepository.com/artifact/org.miracl.milagro.amcl/milagro-crypto-java -->
<dependency>
<groupId>org.miracl.milagro.amcl</groupId>
<artifactId>milagro-crypto-java</artifactId>
<version>0.4.0</version>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.glassfish/javax.json -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1.4</version>
</dependency>




<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -214,6 +240,36 @@
</execution>
</executions>
</plugin>


<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<!--
The version of protoc must match protobuf-java. If you don't depend on
protobuf-java directly, you will be transitively depending on the
protobuf-java version that grpc depends on.
-->
<protocArtifact>com.google.protobuf:protoc:${protobufVersion}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpcVersion}:exe:${os.detected.classifier}
</pluginArtifact>
<attachProtoSources>false</attachProtoSources>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>



<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
Expand All @@ -228,6 +284,37 @@
<arg>-Werror</arg>
</compilerArgs>
</configuration>
<executions>
<execution> <!-- Default Maven execution for generated code with warnings and linting disabled -->
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<includes>
<include>org/hyperledger/fabric/protos/**/*.java</include>
</includes>
</configuration>
</execution>
<execution> <!-- Additional execution for all other code with warnings and linting enabled -->
<id>compile-main</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<excludes>
<exclude>org/hyperledger/fabric/protos/**/*.java</exclude>
</excludes>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Xlint</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
@@ -0,0 +1,33 @@
/*
* Copyright 2020 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.hyperledger.fabric.client.identity;

import java.security.GeneralSecurityException;
import org.apache.milagro.amcl.FP256BN.BIG;
import org.hyperledger.fabric.client.identity.idemix.IdemixIssuerPublicKey;
import org.hyperledger.fabric.client.identity.idemix.IdemixPseudonym;
import org.hyperledger.fabric.client.identity.idemix.IdemixPseudonymSignature;

final class IdemixPrivateKeySigner implements Signer {
private final BIG sk;
private final IdemixPseudonym pseudonym;
private final IdemixIssuerPublicKey ipk;

IdemixPrivateKeySigner(final BIG sk, final IdemixPseudonym pseudonym, final IdemixIssuerPublicKey ipk) {
this.sk = sk;
this.pseudonym = pseudonym;
this.ipk = ipk;
}

@Override
public byte[] sign(final byte[] msg) throws GeneralSecurityException {
if (msg == null) {
throw new GeneralSecurityException("Message must not be null");
}
return new IdemixPseudonymSignature(this.sk, this.pseudonym, this.ipk, msg).toProto().toByteArray();
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 2019 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.hyperledger.fabric.client.identity;

import org.hyperledger.fabric.client.identity.idemix.IdemixIdentity;

/**
* A client identity described by an Idemix Identity. The {@link Identities} class provides static methods to create
* an Idemix Identity object.
*/
public final class IdemixerIdentity implements Identity {

private final String mspId;
private final IdemixIdentity idemixIdentity;
private final byte[] credentials;

/**
* Constructor.
* @param mspId A membership service provider identifier.
* @param idemixIdentity An Idemix Identity.
*/
public IdemixerIdentity(final String mspId, final IdemixIdentity idemixIdentity) {
this.mspId = mspId;
this.idemixIdentity = idemixIdentity;
credentials = idemixIdentity.createIdentityByteArray();
}

@Override
public String getMspId() {
return mspId;
}

@Override
public byte[] getCredentials() {
return credentials.clone();
}

/**
* Get a Idemix Identity for this identity.
* @return An Idemix Identity.
*/
public IdemixIdentity getIdemixIdentity() {
return idemixIdentity;
}

}
Expand Up @@ -9,10 +9,15 @@
import java.security.PrivateKey;
import java.security.interfaces.ECPrivateKey;

import org.apache.milagro.amcl.FP256BN.BIG;
import org.hyperledger.fabric.client.identity.idemix.IdemixIssuerPublicKey;
import org.hyperledger.fabric.client.identity.idemix.IdemixPseudonym;

/**
* Factory methods to create standard signing implementations.
*/
public final class Signers {

/**
* Create a new signer that uses the supplied private key for signing. The {@link Identities} class provides static
* methods to create a {@code PrivateKey} object from PEM-format data.
Expand All @@ -27,6 +32,22 @@ public static Signer newPrivateKeySigner(final PrivateKey privateKey) {
}
}

/**
* Create a new idemix signer that uses supplied Secret key for signing.
* @param sk A Secret key.
* @param pseudonym A Pseudonym
* @param ipk A Public Key of an Issuer
* @return A signer implementation.
*/
public static Signer newIdemixPrivateKeySigner(final BIG sk, final IdemixPseudonym pseudonym, final IdemixIssuerPublicKey ipk) {

if (sk == null || pseudonym == null || ipk == null) {
throw new IllegalArgumentException("sk or pseudonym or ipk should not be null");
}
return new IdemixPrivateKeySigner(sk, pseudonym, ipk);

}

// Private constructor to prevent instantiation
private Signers() { }
}
@@ -0,0 +1,41 @@
/*
* Copyright 2019 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.hyperledger.fabric.client.identity.exception;

/**
* BaseException Class is a Base for all exceptions.
*/
public class BaseException extends Exception {

private static final long serialVersionUID = 1L;

/**
* This method accepts exception message as a string and an exception class.
* @param message an exception message
* @param parent a parent exception class
*/
public BaseException(final String message, final Throwable parent) {
super(message, parent);
}

/**
* This method accepts exception message as a string.
* @param message an exception message
*/
public BaseException(final String message) {
super(message);
}

/**
* This method accepts throwable class.
* @param t a throwable class object
*/
public BaseException(final Throwable t) {
super(t);
}

}
@@ -0,0 +1,33 @@
/*
* Copyright 2019 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.hyperledger.fabric.client.identity.exception;

/**
* CryptoException Class is a exception class for all crypto related exceptions.
*/
public class CryptoException extends BaseException {

private static final long serialVersionUID = 1L;

/**
* This method accepts exception message as a string and an exception class.
* @param message an exception message
* @param parent a parent exception class
*/
public CryptoException(final String message, final Exception parent) {
super(message, parent);
}

/**
* This method accepts exception message as a string.
* @param message an exception message
*/
public CryptoException(final String message) {
super(message);
}

}
@@ -0,0 +1,40 @@
/*
* Copyright 2019 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.hyperledger.fabric.client.identity.exception;

/**
* InvalidArgumentException class is an exception class.
*/
public class InvalidArgumentException extends BaseException {
private static final long serialVersionUID = -6094512275378074427L;

/**
* This method accepts exception message as a string and an exception class.
* @param message an exception message
* @param parent a parent exception class
*/
public InvalidArgumentException(final String message, final Exception parent) {
super(message, parent);
}

/**
* This method accepts exception message as a string.
* @param message an exception message
*/
public InvalidArgumentException(final String message) {
super(message);
}

/**
* This method accepts throwable class.
* @param t a throwable class object
*/
public InvalidArgumentException(final Throwable t) {
super(t);
}
}

0 comments on commit 75cd65c

Please sign in to comment.