From 195f3436080a80b4736335bfe7d3514896d67204 Mon Sep 17 00:00:00 2001 From: xydkj Date: Wed, 27 May 2026 16:37:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9PCBAgent2G?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openapi-sdk/pom.xml | 8 +++ .../cn/com/infosec/netsign/agent/Main.java | 3 +- .../com/infosec/netsign/agent/PBCAgent2G.java | 61 ++++++++++--------- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/openapi-sdk/pom.xml b/openapi-sdk/pom.xml index d6805c9..cdefae1 100644 --- a/openapi-sdk/pom.xml +++ b/openapi-sdk/pom.xml @@ -49,6 +49,14 @@ + + + org.slf4j + slf4j-api + 2.0.17 + provided + + diff --git a/openapi-sdk/src/main/java/cn/com/infosec/netsign/agent/Main.java b/openapi-sdk/src/main/java/cn/com/infosec/netsign/agent/Main.java index 7aed8c6..7daede4 100644 --- a/openapi-sdk/src/main/java/cn/com/infosec/netsign/agent/Main.java +++ b/openapi-sdk/src/main/java/cn/com/infosec/netsign/agent/Main.java @@ -8,8 +8,9 @@ public class Main public static void main(String[] args) { PBCAgent2G signClient = new PBCAgent2G(); + String dn = "C=CN,ST=Beijing,L=Beijing,O=Initial Org,OU=Initial OU,CN=Initial Entity"; try { - signClient.rawSign("test".getBytes(StandardCharsets.UTF_8), "dn"); + signClient.dettachedSign("test".getBytes(StandardCharsets.UTF_8), dn); } catch (Exception e) { System.out.println("签名失败:" + e.getMessage()); diff --git a/openapi-sdk/src/main/java/cn/com/infosec/netsign/agent/PBCAgent2G.java b/openapi-sdk/src/main/java/cn/com/infosec/netsign/agent/PBCAgent2G.java index 77ce955..5a10b03 100644 --- a/openapi-sdk/src/main/java/cn/com/infosec/netsign/agent/PBCAgent2G.java +++ b/openapi-sdk/src/main/java/cn/com/infosec/netsign/agent/PBCAgent2G.java @@ -7,6 +7,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import okhttp3.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.security.cert.X509Certificate; @@ -19,8 +21,8 @@ public class PBCAgent2G{ private static final MediaType JSON_MEDIA_TYPE = MediaType.parse("application/json; charset=utf-8"); + private static final Logger logger = LoggerFactory.getLogger(PBCAgent2G.class); - private static final String baseUrl = "http://127.0.0.1:8080/api/v1/openapi"; private static final String apiKey = "key"; private static final String rawSignPath = "/rawSign"; @@ -91,8 +93,7 @@ public class PBCAgent2G{ }; public String rawSign(byte[] origBytes, String dn) { - - System.out.println("调用rawSign, dn:" + dn); + logger.info("调用rawSign, dn:" + dn); String sessionId = UUID.randomUUID().toString().replace("-", ""); if (origBytes == null) { @@ -138,9 +139,9 @@ public class PBCAgent2G{ .build(); - System.out.println("准备连接签名服务器"); + logger.info("准备连接签名服务器"); try (Response response = okHttpClient.newCall(request).execute()) { - System.out.println("连接成功,并收到响应"); + logger.info("连接成功,并收到响应"); String responseBody = response.body() == null ? "" : response.body().string(); JsonNode root = objectMapper.readTree(responseBody); int code = root.get("code").asInt(); @@ -159,16 +160,16 @@ public class PBCAgent2G{ } } catch (IOException e) { - System.err.println("连接签名服务器异常" + e.getMessage()); + logger.info("连接签名服务器异常" + e.getMessage()); throw new RuntimeException("调用rawSign异常:" + e.getMessage(), e); } finally { - System.out.println("请求结束, 连接资源已释放"); + logger.info("请求结束, 连接资源已释放"); } } public boolean rawVerify(byte[] origBytes, String certStr, String dn) { - System.out.println("调用rawVerify, dn:" + dn); + logger.info("调用rawVerify, dn:" + dn + " , certStr:" + certStr); String sessionId = UUID.randomUUID().toString().replace("-", ""); if (origBytes == null) { @@ -219,9 +220,9 @@ public class PBCAgent2G{ .addHeader("X-API-Key", apiKey) .build(); - System.out.println("准备连接签名服务器"); + logger.info("准备连接签名服务器"); try (Response response = okHttpClient.newCall(request).execute()) { - System.out.println("连接成功,并收到响应"); + logger.info("连接成功,并收到响应"); String responseBody = response.body() == null ? "" : response.body().string(); JsonNode root = objectMapper.readTree(responseBody); int code = root.get("code").asInt(); @@ -239,16 +240,16 @@ public class PBCAgent2G{ } } catch (IOException e) { - System.err.println("连接签名服务器异常" + e.getMessage()); + logger.info("连接签名服务器异常" + e.getMessage()); throw new RuntimeException("调用rawVerify异常", e); } finally { - System.out.println("请求结束, 连接资源已释放"); + logger.info("请求结束, 连接资源已释放"); } } public String dettachedSign(byte[] origBytes, String dn) { - System.out.println("调用dettachedSign, dn:" + dn); + logger.info("调用dettachedSign, dn:" + dn); String sessionId = UUID.randomUUID().toString().replace("-", ""); if (origBytes == null) { @@ -290,9 +291,9 @@ public class PBCAgent2G{ .build(); - System.out.println("准备连接签名服务器"); + logger.info("准备连接签名服务器"); try (Response response = okHttpClient.newCall(request).execute()) { - System.out.println("连接成功,并收到响应"); + logger.info("连接成功,并收到响应"); String responseBody = response.body() == null ? "" : response.body().string(); JsonNode root = objectMapper.readTree(responseBody); int code = root.get("code").asInt(); @@ -310,10 +311,10 @@ public class PBCAgent2G{ } } catch (IOException e) { - System.err.println("连接签名服务器异常" + e.getMessage()); + logger.info("连接签名服务器异常" + e.getMessage()); throw new RuntimeException("调用dettachedSign异常", e); } finally { - System.out.println("请求结束, 连接资源已释放"); + logger.info("请求结束, 连接资源已释放"); } } @@ -361,13 +362,13 @@ public class PBCAgent2G{ .addHeader("X-API-Key", apiKey) .build(); - System.out.println("准备连接签名服务器"); + logger.info("准备连接签名服务器"); try (Response response = okHttpClient.newCall(request).execute()) { - System.out.println("连接成功,并收到响应"); + logger.info("连接成功,并收到响应"); String responseBody = response.body() == null ? "" : response.body().string(); JsonNode root = objectMapper.readTree(responseBody); int code = root.get("code").asInt(); - System.out.println(root.toPrettyString()); + logger.info(root.toPrettyString()); if (code == 200){ DettachedVerifyResponse data = objectMapper.treeToValue(root.get("data"), DettachedVerifyResponse.class); return data.getGenericCertificate(); @@ -383,10 +384,10 @@ public class PBCAgent2G{ } } catch (IOException e) { - System.err.println("连接签名服务器异常" + e.getMessage()); + logger.info("连接签名服务器异常" + e.getMessage()); throw new RuntimeException("调用dettachedVerify异常", e); } finally { - System.out.println("请求结束, 连接资源已释放"); + logger.info("请求结束, 连接资源已释放"); } } @@ -435,9 +436,9 @@ public class PBCAgent2G{ .addHeader("X-API-Key", apiKey) .build(); - System.out.println("准备连接签名服务器"); + logger.info("准备连接签名服务器"); try (Response response = okHttpClient.newCall(request).execute()) { - System.out.println("连接成功,并收到响应"); + logger.info("连接成功,并收到响应"); String responseBody = response.body() == null ? "" : response.body().string(); JsonNode root = objectMapper.readTree(responseBody); int code = root.get("code").asInt(); @@ -455,10 +456,10 @@ public class PBCAgent2G{ } } catch (IOException e) { - System.err.println("连接签名服务器异常" + e.getMessage()); + logger.info("连接签名服务器异常" + e.getMessage()); throw new RuntimeException("调用dettachedVerifySimple异常", e); } finally { - System.out.println("请求结束, 连接资源已释放"); + logger.info("请求结束, 连接资源已释放"); } } @@ -501,9 +502,9 @@ public class PBCAgent2G{ .addHeader("X-API-Key", apiKey) .build(); - System.out.println("准备连接签名服务器"); + logger.info("准备连接签名服务器"); try (Response response = okHttpClient.newCall(request).execute()) { - System.out.println("连接成功,并收到响应"); + logger.info("连接成功,并收到响应"); String responseBody = response.body() == null ? "" : response.body().string(); JsonNode root = objectMapper.readTree(responseBody); int code = root.get("code").asInt(); @@ -521,10 +522,10 @@ public class PBCAgent2G{ } } catch (IOException e) { - System.err.println("连接签名服务器异常" + e.getMessage()); + logger.info("连接签名服务器异常" + e.getMessage()); throw new RuntimeException("调用uploadCert异常", e); } finally { - System.out.println("请求结束, 连接资源已释放"); + logger.info("请求结束, 连接资源已释放"); } } From f1fa2dedd93edb814d39baab5b94af63b742cbf0 Mon Sep 17 00:00:00 2001 From: xydkj Date: Wed, 27 May 2026 16:52:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9PCBAgent2G?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- openapi-sdk/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/openapi-sdk/pom.xml b/openapi-sdk/pom.xml index cdefae1..953388f 100644 --- a/openapi-sdk/pom.xml +++ b/openapi-sdk/pom.xml @@ -54,7 +54,6 @@ org.slf4j slf4j-api 2.0.17 - provided