Skip to content

Commit

Permalink
* Fix deployment issues and add data-auth interfaces
Browse files Browse the repository at this point in the history
* Modify mysql configurations in rest-deploy

Signed-off-by: chaoxinhu <chaoxinhu@hotmail.com>
  • Loading branch information
chaoxinhu committed Mar 13, 2020
1 parent 4e6e72d commit ba7ef35
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 9 deletions.
18 changes: 18 additions & 0 deletions readthedocs/zh_CN/docs/weidentity-endpoint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ WeIdentity Endpoint Service

您可以参照 \ `RestService API <./weidentity-rest-api.html>`_\ 文档中的Endpoint Service API部分,了解如何查询和调用您注册的Endpoint信息。

基于Endpoint Service的数据授权
------------------------------------

WeIdentity提供依托于Endpoint Service而存在的数据授权。授权的详细信息会以可信可验证的凭证(Credential)方式展现,并由Endpoint Service服务端进行验证。

一个标准的数据授权凭证其CPT ID为101。它的Claim中包括以下内容:

- 授权发起者(fromWeId):表示这个凭证是由哪个WeID所发起的
- 必须和凭证的Issuer一致,且在链上存在
- 授权接收者(toWeId):表示这个凭证是由哪个WeID所接收的
- 授权时间(duration):表示此授权的持续时间,单位为毫秒
- 服务地址(serviceUrl):表示此授权的目的服务地址
- 只支持HTTP/HTTPS协议
- 必须是以标准URL形式存储,必须包括主机名、端口及路径
- 资源ID(resourceId):表示此授权所请求的资源ID,以UUID形式表示

简而言之,调用者必须传入一个CPT101授权凭证,此凭证中包含数据授权的主机地址、资源ID,由Endpoint Service的服务端进行查验,确认凭证合法且服务地址(serviceUrl)已在本服务端后台注册过。查验通过后,Endpoint Service会将请求以RPC请求的形式转向在本服务端注册的各端点后台,并由各后台根据传入的资源ID,返回资源信息。具体的调用方式可以查阅API文档。

技术细节
--------------

Expand Down
121 changes: 118 additions & 3 deletions readthedocs/zh_CN/docs/weidentity-rest-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1705,14 +1705,31 @@ POST /weid/api/encode 接口入参
"errorMessage": "success"
}
请注意,这个生成的CredentialPojo的签名值(proof中的signatureValue项)并没有经过私钥签名。因此,您还需要其经过Base64解码之后,再使用Issuer的私钥进行签名并Base64编码,就能得到一个正确的CredentialPojo了。
请注意,这个生成的CredentialPojo的签名值(proof中的signatureValue项)并没有经过私钥签名。正确的签名方式包括下面几步:
- base64解码,生成一个二进制字节数组
- 对解码的byte[]做一次secp256k1的hash
- 对完成hash过byte[],再做一次hash(如果您使用的是Java web3sdk的SignMessage(),这一步它替您完成了)
- 传入私钥,进行签名,得到r,s,v
- 对进行序列化
- 把序列化的byte进行base64编码发回RestService

使用ECDSA私钥进行签名和Base64编码的范例代码见下:
使用ECDSA私钥进行签名和Base64编码的范例代码见下(Java和Go)

.. code-block:: java
String signature = DataToolUtils.sign(new String(DataToolUtils.base64Decode(signatureValue)), privateKey);
.. code-block:: go
base64SignatureValue := credentialEncodeResponse.RespBody.Proof.SignatureValue
signatureValue, err3 := base64.StdEncoding.DecodeString(base64SignatureValue)
hashedMsg := Hash(signatureValue)
doubleHashedMsg := Hash(hashedMsg)
privateKeyBytes := ConvertPrivateKeyBigIntToPrivateKeyBytes(privateKeyBigInt)
signatureBytes, err4 := SignSignature(doubleHashedMsg, privateKeyBytes)
signatureBase64String := base64.StdEncoding.EncodeToString(signatureBytes)
WeIdentity Endpoint Service API
------------------------------------

Expand Down Expand Up @@ -1799,7 +1816,7 @@ WeIdentity Endpoint Service API
- 以```分隔的多个传入服务端用于执行API的参数
- Y

接口入参
接口入参示例

.. code-block:: java
Expand Down Expand Up @@ -1832,3 +1849,101 @@ WeIdentity Endpoint Service API
"ErrorMessage": "success",
"respBody": "did:weid:0x1Ae5b88d37327830307ab8da0ec5D8E8692A35D3",
}
WeIdentity 数据授权 API
------------------------------------

调用接口:

.. list-table::
:header-rows: 1
:widths: 30 50

* - 标题
- 描述
* - 接口名
- weid/api/authorize/fetch-data
* - Method
- POST
* - Content-Type
- application/json


接口入参:

.. list-table::
:header-rows: 1
:widths: 30 60 20

* - Key
- Value
- Required
* - authToken
- CPT101数据授权凭证
- Y
* - signedNonce
- 签名的Nonce值(当前暂不校验,可任意填入)
- Y

接口入参示例:

.. code-block:: java
{
"authToken": {
"claim": {
"duration": 360000,
"fromWeId": "did:weid:101:0x69cd071e4be5fd878e1519ff476563dc2f4c6168",
"resourceId": "4b077c17-9612-42ee-9e36-3a3d46b27e81",
"serviceUrl": "http://127.0.0.1:6010/fetch-data",
"toWeId": "did:weid:101:0x68bedb2cbe55b4c8e3473faa63f121c278f6dba9"
},
"context": "https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1",
"cptId": 101,
"expirationDate": 1581347039,
"id": "48b75424-9411-4d22-b925-4e730b445a31",
"issuanceDate": 1580987039,
"issuer": "did:weid:101:0x69cd071e4be5fd878e1519ff476563dc2f4c6168",
"proof": {
"created": 1580987039,
"creator": "did:weid:101:0x69cd071e4be5fd878e1519ff476563dc2f4c6168#keys-0",
"salt": {
"duration": "fmk5A",
"fromWeId": "DEvFy",
"resourceId": "ugVeN",
"serviceUrl": "nVdeE",
"toWeId": "93Z1E"
},
"signatureValue": "HCZwyTzGst87cjCDaUEzPrO8QRlsPvCYXvRTUVBUTDKRSoGDgu4h4HLrMZ+emDacRnmQ/yke38u1jBnilNnCh6c=",
"type": "Secp256k1"
},
"type": ["VerifiableCredential", "hashTree"]
},
"signedNonce": "123123"
}
接口返回: application/json

.. list-table::
:header-rows: 1
:widths: 30 50

* - Key
- Value
* - ErrorCode
- 错误码,0表示成功
* - ErrorMessage
- 错误信息
* - respBody
- SDK侧的返回值,String

接口返回:

.. code-block:: java
{
"ErrorCode": 0,
"ErrorMessage": "success",
"respBody": "sample data",
}
13 changes: 7 additions & 6 deletions readthedocs/zh_CN/docs/weidentity-rest-deploy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,27 @@ Server 的环境要求与 WeIdentity-Java-SDK 的 `环境要求 <./weidentity-in
evidence.contractaddress=0xddddd42da68a40784f5f63ada7ead9b36a38d2e3
specificissuer.contractaddress=0x215d5c4b8867ce9f52d1a599c9dfef190201c263
区块链节点信息修改示例:更新 ``dist/conf/weidentity.properties.tpl`` 中 ``nodes`` 项的值,注意每一条信息都应包含区块链用户、节点IP、节点channel端口地址;多于一个区块链节点,请用 “,” 半角逗号分隔。

区块链节点信息修改示例:更新 ``dist/conf/weidentity.properties`` 中 ``nodes`` 项的值,注意每一条信息都应包含区块链用户、节点IP、节点channel端口地址;多于一个区块链节点,请用 “,” 半角逗号分隔。

.. code-block:: xml
nodes=WeIdentity@127.0.0.1:8812,WeIdentity@127.0.0.1:8900
nodes=127.0.0.1:8812,127.0.0.1:8900
* 拷贝您 WeIdentity 合约部署者的私钥到 ``keys/priv`` 目录下,并重命名为 ``ecdsa_key``。如果您使用部署工具部署了 WeIdentity 合约,这个文件在 ``output/admin/`` 目录。如果您使用源码部署,这个文件在源代码根目录下。

* 修改 ``dist/conf/application.properties`` ,填入需要打开的监听端口地址(用于 RestServer 监听外来的 HTTP/HTTPS RESTful 请求,默认为 6000/6001,不可被其他程序占用)。同时,请确认用来调用默认合约部署者私钥的暗语;由于此暗语可直接调用 WeIdentity 合约部署者的私钥,权限较高(详见 \ `RestService API 说明文档 <./weidentity-rest-api.html>`_\ ),因此请您务必对其进行修改。
* 修改 ``dist/conf/application.properties`` ,填入需要打开的监听端口地址(用于 RestServer 监听外来的 HTTP/HTTPS RESTful 请求,默认为 6001/6000,不可被其他程序占用;HTTPS接口默认不开放)。同时,请确认用来调用默认合约部署者私钥的暗语;由于此暗语可直接调用 WeIdentity 合约部署者的私钥,权限较高(详见 \ `RestService API 说明文档 <./weidentity-rest-api.html>`_\ ),因此请您务必对其进行修改。

.. code-block:: bash
# HTTPS请求端口
server.port=6001
# HTTP请求端口
server.port=6001
# HTTPS请求端口,默认不开放
server.http.port=6000
# 合约部署者私钥暗语
default.passphrase=ecdsa_key
* 如果您需要连接使用MySQL,则需要在``dist/conf/weidentity.properties``内修改关于datasource相关的MySQL配置。

2. Server 使用说明
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit ba7ef35

Please sign in to comment.