Skip to content

Commit

Permalink
Merge pull request #139 from WeBankFinTech/feature/weid-auth
Browse files Browse the repository at this point in the history
Feature/add weid auth module
  • Loading branch information
yanggang-JV committed Mar 14, 2020
2 parents 58e69ef + 6e23e93 commit 046f39c
Show file tree
Hide file tree
Showing 19 changed files with 1,081 additions and 5 deletions.
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ targetCompatibility = 1.8
repositories {
if (!gradle.startParameter.isOffline()) {
mavenLocal()
maven { url "https://oss.sonatype.org/content/groups/public/" }
mavenCentral()
maven { url "https://dl.bintray.com/ethereum/maven/" }
} else {
Expand Down Expand Up @@ -133,6 +134,11 @@ dependencies {
if (!gradle.startParameter.isOffline()) {
compile logger, lombok, apache_commons, json, mysql_driver, zxing, rpc, pdfbox, protobuf, caffeine, oval
compile("com.webank:weid-contract-java:1.2.16") {
exclude group: "org.fisco-bcos", module: "web3sdk"
exclude group: "org.slf4j", module: "slf4j-log4j12"
}
compile("org.fisco-bcos:web3sdk:2.1.2-0312-SNAPSHOT"){
exclude group:"io.netty"
exclude group: "org.slf4j", module: "slf4j-log4j12"
}
compile files("lib/WeDPR-Java-SDK.jar")
Expand All @@ -149,6 +155,11 @@ dependencies {
testCompileOnly 'org.projectlombok:lombok:1.18.10'
compile logger, apache_commons, json, mysql_driver, zxing, rpc, pdfbox, protobuf, caffeine, oval
compile("com.webank:weid-contract-java:1.2.16") {
exclude group: "org.fisco-bcos", module: "web3sdk"
exclude group: "org.slf4j", module: "slf4j-log4j12"
}
compile("org.fisco-bcos:web3sdk:2.1.2-0312-SNAPSHOT"){
exclude group:"io.netty"
exclude group: "org.slf4j", module: "slf4j-log4j12"
}
compile files("lib/WeDPR-Java-SDK.jar")
Expand Down
33 changes: 30 additions & 3 deletions src/main/java/com/webank/weid/constant/AmopMsgType.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
import com.webank.weid.protocol.amop.GetEncryptKeyArgs;
import com.webank.weid.protocol.amop.GetPolicyAndChallengeArgs;
import com.webank.weid.protocol.amop.GetPolicyAndPreCredentialArgs;
import com.webank.weid.protocol.amop.GetWeIdAuthArgs;
import com.webank.weid.protocol.amop.IssueCredentialArgs;
import com.webank.weid.protocol.amop.RequestVerifyChallengeArgs;
import com.webank.weid.protocol.response.AmopNotifyMsgResult;
import com.webank.weid.protocol.response.AmopResponse;
import com.webank.weid.protocol.response.GetEncryptKeyResponse;
import com.webank.weid.protocol.response.GetPolicyAndChallengeResponse;
import com.webank.weid.protocol.response.GetWeIdAuthResponse;
import com.webank.weid.protocol.response.PolicyAndPreCredentialResponse;
import com.webank.weid.protocol.response.RequestIssueCredentialResponse;
import com.webank.weid.protocol.response.RequestVerifyChallengeResponse;
import com.webank.weid.rpc.callback.AmopCallback;
import com.webank.weid.service.impl.base.AmopCommonArgs;
import com.webank.weid.util.DataToolUtils;
Expand Down Expand Up @@ -67,7 +71,17 @@ public enum AmopMsgType {
/**
* 请求issuer签credential.
*/
REQUEST_SIGN_CREDENTIAL(6);
REQUEST_SIGN_CREDENTIAL(6),

/**
* 请求验证challenge的签名.
*/
REQUEST_VERIFY_CHALLENGE(7),

/**
* 请求weIdAuth.
*/
GET_WEID_AUTH(8);

private Integer value;

Expand Down Expand Up @@ -123,21 +137,34 @@ public String callOnPush(AmopCallback amopCallback, String messageId, String msg
break;
}
case GET_POLICY_AND_PRE_CREDENTIAL: {
// GET POLICY AND CHALLENGE
GetPolicyAndPreCredentialArgs args =
DataToolUtils.deserialize(msgBodyStr, GetPolicyAndPreCredentialArgs.class);
PolicyAndPreCredentialResponse result = amopCallback.onPush(args);
resultBodyStr = DataToolUtils.serialize(result);
break;
}
case REQUEST_SIGN_CREDENTIAL: {
// GET POLICY AND CHALLENGE
IssueCredentialArgs args =
DataToolUtils.deserialize(msgBodyStr, IssueCredentialArgs.class);
RequestIssueCredentialResponse result = amopCallback.onPush(args);
resultBodyStr = DataToolUtils.serialize(result);
break;
}
case GET_WEID_AUTH: {
GetWeIdAuthArgs args =
DataToolUtils.deserialize(msgBodyStr, GetWeIdAuthArgs.class);
GetWeIdAuthResponse result = amopCallback.onPush(args);
resultBodyStr = DataToolUtils.serialize(result);
break;
}

case REQUEST_VERIFY_CHALLENGE: {
RequestVerifyChallengeArgs args =
DataToolUtils.deserialize(msgBodyStr, RequestVerifyChallengeArgs.class);
RequestVerifyChallengeResponse result = amopCallback.onPush(args);
resultBodyStr = DataToolUtils.serialize(result);
break;
}
default:
break;
}
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/webank/weid/constant/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,16 @@ public enum ErrorCode {
*/
ENCRYPT_KEY_INVALID(100704, "the key is invalid."),

/**
* encrypt data failed.
*/
ENCRYPT_DATA_FAILED(100705, "encrypt data failed."),

/**
* decrypt data failed.
*/
DECRYPT_DATA_FAILED(100706, "decrypt data failed."),

/**
* transportation base error.
*/
Expand Down Expand Up @@ -664,6 +674,22 @@ public enum ErrorCode {
"cannot remove this WeID's owner or last public key without an available backup."
),

/**
* no permission of weIdAuth.
*/
WEID_AUTH_NO_PERMISSION(
100112,
"no permission of weIdAuth."
),

/**
* no permission of weIdAuth.
*/
WEID_AUTH_NO_CALLBACK(
100113,
"weIdAuth callback is not registered."
),

/**
* transaction timeout.
*/
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/webank/weid/constant/ParamKeyConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public final class ParamKeyConstant {
public static final String PROOF_NONCE = "nonce";
public static final String PROOF_VERIFICATIONREQUEST = "verificationRequest";
public static final String PROOF_ENCODEDVERIFICATIONRULE = "encodedVerificationRule";


/**
* 秘钥存储KEY.
Expand All @@ -86,6 +86,9 @@ public final class ParamKeyConstant {
public static final String MASTER_SECRET = "masterSecret";
public static final String BLINDING_FACTORS = "credentialSecretsBlindingFactors";

public static final String WEID_AUTH_OBJ = "weIdAuthObj";
public static final String WEID_AUTH_SIGN_DATA = "signData";
public static final String WEID_AUTH_CHALLENGE = "challenge";

public static final String TRNSACTION_RECEIPT_STATUS_SUCCESS = "0x0";
}
31 changes: 31 additions & 0 deletions src/main/java/com/webank/weid/protocol/amop/GetWeIdAuthArgs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.webank.weid.protocol.amop;

import lombok.Getter;
import lombok.Setter;

import com.webank.weid.protocol.amop.base.AmopBaseMsgArgs;
import com.webank.weid.protocol.base.Challenge;

/**
* args for getting weIdAuth object.
* @author tonychen 2020年3月10日
*/
@Getter
@Setter
public class GetWeIdAuthArgs extends AmopBaseMsgArgs {

/**
* self weId.
*/
private String weId;

/**
* the challenge.
*/
private Challenge challenge;

/**
* 0:single, 1:mutual.
*/
private Integer type;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.webank.weid.protocol.amop;

import lombok.Getter;
import lombok.Setter;

import com.webank.weid.protocol.amop.base.AmopBaseMsgArgs;
import com.webank.weid.protocol.base.Challenge;

/**
* args for verify challenge.
* @author tonychen 2020年3月12日
*/
@Getter
@Setter
public class RequestVerifyChallengeArgs extends AmopBaseMsgArgs {

private String channelId;
private String selfWeId;
private Challenge challenge;
private String signData;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.webank.weid.protocol.response;

import lombok.Getter;
import lombok.Setter;

/**
* get weIdAuth response.
* @author tonychen 2020年3月10日
*
*/
@Getter
@Setter
public class GetWeIdAuthResponse {

/**
* encrypt data, including challenge sign, weIdAuthObj.
*/
private byte[] data;

/**
* error code.
*/
private Integer errorCode;

/**
* error message.
*/
protected String errorMessage;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.webank.weid.protocol.response;

import lombok.Getter;
import lombok.Setter;

/**
* response for verifying challenge signature.
* @author tonychen 2020年3月12日
*
*/
@Setter
@Getter
public class RequestVerifyChallengeResponse {

/**
* error code.
*/
private Integer errorCode;

/**
* error message.
*/
protected String errorMessage;
}
25 changes: 25 additions & 0 deletions src/main/java/com/webank/weid/rpc/AmopService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@

import com.webank.weid.protocol.amop.GetEncryptKeyArgs;
import com.webank.weid.protocol.amop.GetPolicyAndPreCredentialArgs;
import com.webank.weid.protocol.amop.GetWeIdAuthArgs;
import com.webank.weid.protocol.amop.RequestIssueCredentialArgs;
import com.webank.weid.protocol.amop.RequestVerifyChallengeArgs;
import com.webank.weid.protocol.base.PolicyAndChallenge;
import com.webank.weid.protocol.response.AmopResponse;
import com.webank.weid.protocol.response.GetEncryptKeyResponse;
import com.webank.weid.protocol.response.GetWeIdAuthResponse;
import com.webank.weid.protocol.response.PolicyAndPreCredentialResponse;
import com.webank.weid.protocol.response.RequestIssueCredentialResponse;
import com.webank.weid.protocol.response.RequestVerifyChallengeResponse;
import com.webank.weid.protocol.response.ResponseData;
import com.webank.weid.rpc.callback.AmopCallback;
import com.webank.weid.service.impl.base.AmopCommonArgs;
Expand Down Expand Up @@ -61,4 +65,25 @@ ResponseData<RequestIssueCredentialResponse> requestIssueCredential(
RequestIssueCredentialArgs args
);

/**
* get weIdAuth object.
* @param toOrgId target organization id
* @param args random number
*/
ResponseData<GetWeIdAuthResponse> getWeIdAuth(
String toOrgId,
GetWeIdAuthArgs args
);


/**
* verify challenge signature.
* @param toOrgId target organization id
* @param args verify args
*/
ResponseData<RequestVerifyChallengeResponse> requestVerifyChallenge(
String toOrgId,
RequestVerifyChallengeArgs args
);

}
31 changes: 31 additions & 0 deletions src/main/java/com/webank/weid/rpc/callback/AmopCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
import com.webank.weid.protocol.amop.GetEncryptKeyArgs;
import com.webank.weid.protocol.amop.GetPolicyAndChallengeArgs;
import com.webank.weid.protocol.amop.GetPolicyAndPreCredentialArgs;
import com.webank.weid.protocol.amop.GetWeIdAuthArgs;
import com.webank.weid.protocol.amop.IssueCredentialArgs;
import com.webank.weid.protocol.amop.RequestVerifyChallengeArgs;
import com.webank.weid.protocol.response.AmopNotifyMsgResult;
import com.webank.weid.protocol.response.AmopResponse;
import com.webank.weid.protocol.response.GetEncryptKeyResponse;
import com.webank.weid.protocol.response.GetPolicyAndChallengeResponse;
import com.webank.weid.protocol.response.GetWeIdAuthResponse;
import com.webank.weid.protocol.response.PolicyAndPreCredentialResponse;
import com.webank.weid.protocol.response.RequestIssueCredentialResponse;
import com.webank.weid.protocol.response.RequestVerifyChallengeResponse;
import com.webank.weid.service.impl.base.AmopCommonArgs;

/**
Expand Down Expand Up @@ -122,4 +126,31 @@ public RequestIssueCredentialResponse onPush(IssueCredentialArgs args) {
return result;
}

/**
* 默认获取weIdAuthObj回调.
*
* @param args 获取weIdAuthObj需要的参数
* @return 返回weIdAuthObj的响应体
*/
public GetWeIdAuthResponse onPush(GetWeIdAuthArgs args) {

GetWeIdAuthResponse result = new GetWeIdAuthResponse();
result.setErrorCode(ErrorCode.AMOP_MSG_CALLBACK_SERVER_SIDE_NO_HANDLE.getCode());
result.setErrorMessage(ErrorCode.AMOP_MSG_CALLBACK_SERVER_SIDE_NO_HANDLE.getCodeDesc());
return result;
}

/**
* 默认获取weIdAuthObj回调.
*
* @param args 获取weIdAuthObj需要的参数
* @return 返回weIdAuthObj的响应体
*/
public RequestVerifyChallengeResponse onPush(RequestVerifyChallengeArgs args) {

RequestVerifyChallengeResponse result = new RequestVerifyChallengeResponse();
result.setErrorCode(ErrorCode.AMOP_MSG_CALLBACK_SERVER_SIDE_NO_HANDLE.getCode());
result.setErrorMessage(ErrorCode.AMOP_MSG_CALLBACK_SERVER_SIDE_NO_HANDLE.getCodeDesc());
return result;
}
}

0 comments on commit 046f39c

Please sign in to comment.