diff --git a/jetbra-agent/src/main/java/win/novice/li/AgentMain.java b/jetbra-agent/src/main/java/win/novice/li/AgentMain.java index ce29191..b6c42fb 100644 --- a/jetbra-agent/src/main/java/win/novice/li/AgentMain.java +++ b/jetbra-agent/src/main/java/win/novice/li/AgentMain.java @@ -21,11 +21,19 @@ public class AgentMain { .visit(Advice.to(HttpClientAdvice.class) .on(ElementMatchers.named("openServer")))) .asTerminalTransformation() + .type(ElementMatchers.named("java.lang.System")) .transform((builder, typeDescription, classLoader, module, protectionDomain) -> builder .visit(Advice.to(SystemAdvice.class) .on(ElementMatchers.named("getProperty")))) .asTerminalTransformation() + + .type(ElementMatchers.named("java.net.Socket")) + .transform((builder, typeDescription, classLoader, module, protectionDomain) -> builder + .visit(Advice.to(SocketAdvice.class) + .on(ElementMatchers.named("connect")))) + .asTerminalTransformation() + .installOn(inst); agentBuilder.installOn(inst); diff --git a/jetbra-agent/src/main/java/win/novice/li/SocketAdvice.java b/jetbra-agent/src/main/java/win/novice/li/SocketAdvice.java new file mode 100644 index 0000000..ba12ef6 --- /dev/null +++ b/jetbra-agent/src/main/java/win/novice/li/SocketAdvice.java @@ -0,0 +1,20 @@ +package win.novice.li; + +import net.bytebuddy.asm.Advice; + +import java.net.ConnectException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketAddress; + +public class SocketAdvice { + @Advice.OnMethodExit + public static void intercept(@Advice.Argument(value = 0,readOnly = false) SocketAddress socketAddress) throws Exception { + if (socketAddress instanceof InetSocketAddress){ + InetAddress address = ((InetSocketAddress) socketAddress).getAddress(); + if (address.getHostAddress().equals("116.62.33.138")){ + throw new ConnectException("拒绝连接"); + } + } + } +} diff --git a/jetbra-server/src/main/java/win/novice/li/controller/LicenseController.java b/jetbra-server/src/main/java/win/novice/li/controller/LicenseController.java index 022f188..af874d9 100644 --- a/jetbra-server/src/main/java/win/novice/li/controller/LicenseController.java +++ b/jetbra-server/src/main/java/win/novice/li/controller/LicenseController.java @@ -13,14 +13,12 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import win.novice.li.model.License; -import java.io.FileInputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.security.*; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.Base64; -import java.util.HashMap; import java.util.Map; @RestController @@ -33,8 +31,6 @@ public class LicenseController { @PostMapping("/generateLicense") @SneakyThrows public Map generateLicense(@RequestBody @Validated License license) { - Map ans = new HashMap<>(); - String licenseId = generateLicenseId(); license.setLicenseId(licenseId); @@ -42,7 +38,6 @@ public class LicenseController { byte[] licensePartBytes = licensePart.getBytes(StandardCharsets.UTF_8); String licensePartBase64 = Base64.getEncoder().encodeToString(licensePartBytes); - Signature signature = Signature.getInstance("SHA1withRSA"); signature.initSign(PRIVATE_KEY); signature.update(licensePartBytes); @@ -51,8 +46,7 @@ public class LicenseController { String result = licenseId + "-" + licensePartBase64 + "-" + sigResultsBase64 + "-" + Base64.getEncoder().encodeToString(CRT.getEncoded()); - ans.put("license",result); - return ans; + return Map.of("license", result); }