Skip to content

Commit fa84e59

Browse files
authored
Merge pull request #49 from Safeheron/dev
Added Deactivate API Key interfaces
2 parents aba85da + 16709c0 commit fa84e59

6 files changed

Lines changed: 140 additions & 6 deletions

File tree

.github/workflows/deploy.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Maven Central Repo Deployment
2+
3+
on:
4+
release:
5+
types: [ released ]
6+
7+
jobs:
8+
publish-central:
9+
runs-on: ubuntu-latest
10+
steps:
11+
12+
- name: Checkout Git Repo
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Apache Maven Central
16+
uses: actions/setup-java@v4
17+
with:
18+
distribution: 'zulu'
19+
java-version: '8'
20+
server-id: central
21+
server-username: SERVER_USERNAME
22+
server-password: SERVER_PASSWORD
23+
gpg-private-key: ${{ secrets.MAVEN_GPG_SECRET }}
24+
gpg-passphrase: GPG_PASSPHRASE
25+
26+
- name: Publish to Apache Maven Central
27+
run: mvn deploy -DskipTests
28+
env:
29+
SERVER_USERNAME: ${{ secrets.MAVEN_SERVER_USERNAME }}
30+
SERVER_PASSWORD: ${{ secrets.MAVEN_SERVER_PASSWORD }}
31+
GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSWORD }}

pom.xml

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,26 @@
66

77
<groupId>com.safeheron</groupId>
88
<artifactId>api-sdk-java</artifactId>
9-
<version>0.0.1</version>
9+
<version>1.0.2</version>
1010
<name>api-sdk-java</name>
11-
11+
<description>Java SDK for Safeheron API</description>
12+
<url>https://github.com/Safeheron/safeheron-api-sdk-java</url>
1213
<packaging>jar</packaging>
1314

15+
<licenses>
16+
<license>
17+
<name>The Apache Software License, Version 2.0</name>
18+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
19+
</license>
20+
</licenses>
21+
22+
<scm>
23+
<connection>https://github.com/Safeheron/safeheron-api-sdk-java.git</connection>
24+
<developerConnection>scm:git:ssh://git@github.com:Safeheron/safeheron-api-sdk-java.git
25+
</developerConnection>
26+
<url>https://github.com/Safeheron/safeheron-api-sdk-java</url>
27+
</scm>
28+
1429
<properties>
1530
<maven.compiler.source>8</maven.compiler.source>
1631
<maven.compiler.target>8</maven.compiler.target>
@@ -122,6 +137,16 @@
122137

123138
<build>
124139
<plugins>
140+
<plugin>
141+
<groupId>org.sonatype.central</groupId>
142+
<artifactId>central-publishing-maven-plugin</artifactId>
143+
<version>0.8.0</version>
144+
<extensions>true</extensions>
145+
<configuration>
146+
<publishingServerId>central</publishingServerId>
147+
<autoPublish>true</autoPublish>
148+
</configuration>
149+
</plugin>
125150
<plugin>
126151
<groupId>org.apache.maven.plugins</groupId>
127152
<artifactId>maven-compiler-plugin</artifactId>
@@ -131,6 +156,40 @@
131156
<target>1.8</target>
132157
</configuration>
133158
</plugin>
159+
<plugin>
160+
<groupId>org.apache.maven.plugins</groupId>
161+
<artifactId>maven-javadoc-plugin</artifactId>
162+
<version>2.9.1</version>
163+
<executions>
164+
<execution>
165+
<id>attach-javadocs</id>
166+
<goals>
167+
<goal>jar</goal>
168+
</goals>
169+
</execution>
170+
</executions>
171+
</plugin>
172+
<plugin>
173+
<groupId>org.apache.maven.plugins</groupId>
174+
<artifactId>maven-gpg-plugin</artifactId>
175+
<version>1.6</version>
176+
<inherited>false</inherited>
177+
<executions>
178+
<execution>
179+
<id>sign-artifacts</id>
180+
<phase>verify</phase>
181+
<goals>
182+
<goal>sign</goal>
183+
</goals>
184+
<configuration>
185+
<gpgArguments>
186+
<arg>--pinentry-mode</arg>
187+
<arg>loopback</arg>
188+
</gpgArguments>
189+
</configuration>
190+
</execution>
191+
</executions>
192+
</plugin>
134193
</plugins>
135194
</build>
136195

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.safeheron.client.api;
2+
3+
import com.safeheron.client.response.ResultResponse;
4+
import retrofit2.Call;
5+
import retrofit2.http.POST;
6+
7+
/**
8+
* @author safeheron
9+
*/
10+
public interface APIKeyManagementService {
11+
12+
/**
13+
* Deactivate API Key
14+
* This interface is used to apply to deactivate the currently used API Key (this can also be done in the Web Console). After the application is submitted, it will only take effect once a team administrator approves it in the Safeheron App. Once an API Key is deactivated, it will no longer be able to access any interfaces. For example, you can apply to deactivate an API Key in the following situations to protect your assets:
15+
*
16+
* The API Key is no longer in use and should be deactivated promptly to avoid risk;
17+
* The API Key's private key is suspected of being leaked, and it needs to be deactivated immediately to ensure fund security;
18+
* You receive an Illegal IP Request Event via Webhook and, after evaluation, need to deactivate the API Key (Event Type: ILLEGAL_IP_REQUEST);
19+
* To resume using it, you can submit an activation request through the Web Console. This will also require approval from a team administrator before the API Key can be reactivated.
20+
*
21+
* @return ResultResponse
22+
* @see ResultResponse
23+
*/
24+
@POST("/v1/apikey/disable")
25+
Call<ResultResponse> disableApikey();
26+
}

src/main/java/com/safeheron/client/cosigner/CoSignerConverter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public class CoSignerConverter {
4545
* @param approvalCallbackServicePrivateKey
4646
*/
4747
public CoSignerConverter(String coSignerPubKey, String approvalCallbackServicePrivateKey) {
48+
if (coSignerPubKey.contains("-----BEGIN PUBLIC KEY-----")) {
49+
coSignerPubKey = coSignerPubKey.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").replaceAll("\n", "");
50+
}
51+
if (approvalCallbackServicePrivateKey.contains("-----BEGIN PRIVATE KEY-----")) {
52+
approvalCallbackServicePrivateKey = approvalCallbackServicePrivateKey.replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "").replaceAll("\n", "");
53+
}
4854
this.coSignerPubKey = coSignerPubKey;
4955
this.approvalCallbackServicePrivateKey = approvalCallbackServicePrivateKey;
5056
}
@@ -74,13 +80,13 @@ public CoSignerBizContent requestConvert(CoSignerCallBack coSignerCallBack) thro
7480

7581
// Use your RSA private key to decrypt request's aesKey and aesIv
7682
RSATypeEnum rsaType = StringUtils.isNotEmpty(coSignerCallBack.getRsaType()) && RSATypeEnum.valueByCode(coSignerCallBack.getRsaType()) != null ? RSATypeEnum.valueByCode(coSignerCallBack.getRsaType()) : RSATypeEnum.RSA;
77-
byte[] aesSaltDecrypt = RsaUtil.decrypt(coSignerCallBack.getKey(), approvalCallbackServicePrivateKey,rsaType);
83+
byte[] aesSaltDecrypt = RsaUtil.decrypt(coSignerCallBack.getKey(), approvalCallbackServicePrivateKey, rsaType);
7884
byte[] aesKey = Arrays.copyOfRange(aesSaltDecrypt, 0, 32);
7985
byte[] iv = Arrays.copyOfRange(aesSaltDecrypt, 32, aesSaltDecrypt.length);
8086

8187
// Use AES to decrypt bizContent
8288
AESTypeEnum aesType = StringUtils.isNotEmpty(coSignerCallBack.getAesType()) && AESTypeEnum.valueByCode(coSignerCallBack.getAesType()) != null ? AESTypeEnum.valueByCode(coSignerCallBack.getAesType()) : AESTypeEnum.CBC;
83-
String decrypt = AesUtil.decrypt(coSignerCallBack.getBizContent(), aesKey, iv,aesType);
89+
String decrypt = AesUtil.decrypt(coSignerCallBack.getBizContent(), aesKey, iv, aesType);
8490
ObjectMapper mapper = JsonUtil.getObjectMapper();
8591

8692
//Data conversion

src/main/java/com/safeheron/client/utils/ServiceCreator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public class ServiceCreator {
2020
private static volatile Map<String, Retrofit> retrofitMap = new HashMap<>();
2121

2222
public static <S> S create(Class<S> serviceClass, SafeheronConfig config) {
23+
if (config.getSafeheronRsaPublicKey().contains("-----BEGIN PUBLIC KEY-----")) {
24+
config.setSafeheronRsaPublicKey(config.getSafeheronRsaPublicKey().replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").replaceAll("\n", ""));
25+
}
26+
if (config.getRsaPrivateKey().contains("-----BEGIN PRIVATE KEY-----")) {
27+
config.setRsaPrivateKey(config.getRsaPrivateKey().replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "").replaceAll("\n", ""));
28+
}
2329
Retrofit instance = getRetrofit(config);
2430
return instance.create(serviceClass);
2531
}

src/main/java/com/safeheron/client/webhook/WebhookConverter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public class WebhookConverter {
3939
* @param webHookRsaPrivateKey
4040
*/
4141
public WebhookConverter(String safeheronWebHookRsaPublicKey, String webHookRsaPrivateKey) {
42+
if (safeheronWebHookRsaPublicKey.contains("-----BEGIN PUBLIC KEY-----")) {
43+
safeheronWebHookRsaPublicKey = safeheronWebHookRsaPublicKey.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").replaceAll("\n", "");
44+
}
45+
if (webHookRsaPrivateKey.contains("-----BEGIN PRIVATE KEY-----")) {
46+
webHookRsaPrivateKey = webHookRsaPrivateKey.replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "").replaceAll("\n", "");
47+
}
4248
this.safeheronWebHookRsaPublicKey = safeheronWebHookRsaPublicKey;
4349
this.webHookRsaPrivateKey = webHookRsaPrivateKey;
4450
}
@@ -68,13 +74,13 @@ public WebHookBizContent convert(WebHook webHook) throws Exception {
6874

6975
// Use your RSA private key to decrypt response's aesKey and aesIv
7076
RSATypeEnum rsaType = StringUtils.isNotEmpty(webHook.getRsaType()) && RSATypeEnum.valueByCode(webHook.getRsaType()) != null ? RSATypeEnum.valueByCode(webHook.getRsaType()) : RSATypeEnum.RSA;
71-
byte[] aesSaltDecrypt = RsaUtil.decrypt(webHook.getKey(), webHookRsaPrivateKey,rsaType);
77+
byte[] aesSaltDecrypt = RsaUtil.decrypt(webHook.getKey(), webHookRsaPrivateKey, rsaType);
7278
byte[] aesKey = Arrays.copyOfRange(aesSaltDecrypt, 0, 32);
7379
byte[] iv = Arrays.copyOfRange(aesSaltDecrypt, 32, aesSaltDecrypt.length);
7480

7581
// Use AES to decrypt bizContent
7682
AESTypeEnum aesType = StringUtils.isNotEmpty(webHook.getAesType()) && AESTypeEnum.valueByCode(webHook.getAesType()) != null ? AESTypeEnum.valueByCode(webHook.getAesType()) : AESTypeEnum.CBC;
77-
String decrypt = AesUtil.decrypt(webHook.getBizContent(), aesKey, iv,aesType);
83+
String decrypt = AesUtil.decrypt(webHook.getBizContent(), aesKey, iv, aesType);
7884
ObjectMapper mapper = JsonUtil.getObjectMapper();
7985

8086
//Data conversion

0 commit comments

Comments
 (0)