diff --git a/src/main/java/love/sola/netsupport/api/Login.java b/src/main/java/love/sola/netsupport/api/Login.java index 96afe93..ff26262 100644 --- a/src/main/java/love/sola/netsupport/api/Login.java +++ b/src/main/java/love/sola/netsupport/api/Login.java @@ -28,7 +28,6 @@ import love.sola.netsupport.sql.SQLCore; import love.sola.netsupport.sql.TableOperator; import love.sola.netsupport.sql.TableUser; import love.sola.netsupport.util.Crypto; -import love.sola.netsupport.util.RSAUtil; import love.sola.netsupport.wechat.Command; import javax.servlet.ServletException; @@ -73,7 +72,7 @@ public class Login extends HttpServlet { else if (op.getAccess() >= Access.NO_LOGIN) return Error.PERMISSION_DENIED; - if (!Crypto.check(bypass ? password : RSAUtil.decrypt(password), op.getPassword())) { + if (!Crypto.check(password, op.getPassword())) { return Error.WRONG_PASSWORD; } diff --git a/src/main/java/love/sola/netsupport/config/Cortana.java b/src/main/java/love/sola/netsupport/config/Cortana.java deleted file mode 100644 index 2277a38..0000000 --- a/src/main/java/love/sola/netsupport/config/Cortana.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of WechatTicketSystem. - * - * WechatTicketSystem is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * WechatTicketSystem is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with WechatTicketSystem. If not, see . - */ - -package love.sola.netsupport.config; - -import org.yaml.snakeyaml.Yaml; - -import java.io.InputStream; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; - -/** - * @author Sola {@literal } - */ -public class Cortana { - - public static List entries; - - public static void load() { - InputStream in = Lang.class.getClassLoader().getResourceAsStream("cortana.yml"); - RawConfig root = new Yaml().loadAs(in, RawConfig.class); - } - - static class Compiled { - Pattern[] patterns; - String[] replies; - } - - public static class Rule { - String[] regexp; - String[] replies; - - public Rule() { - } - } - - public static class RawConfig { - Map rules; - - public RawConfig() { - } - } - -} diff --git a/src/main/java/love/sola/netsupport/util/RSAUtil.java b/src/main/java/love/sola/netsupport/util/RSAUtil.java deleted file mode 100644 index fb248dc..0000000 --- a/src/main/java/love/sola/netsupport/util/RSAUtil.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of WechatTicketSystem. - * - * WechatTicketSystem is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * WechatTicketSystem is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with WechatTicketSystem. If not, see . - */ - -package love.sola.netsupport.util; - -import org.apache.commons.codec.binary.Base64; - -import javax.crypto.Cipher; -import java.nio.charset.StandardCharsets; -import java.security.Key; -import java.security.KeyPair; -import java.security.KeyPairGenerator; - -/** - * @author Sola {@literal } - */ -public class RSAUtil { - - - public static Key publicKey; - public static Key privateKey; - public static String publicKey_s; - public static String privateKey_s; - - static { - genKeyPair(); - } - - public static void genKeyPair() { - try { - KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); - kpg.initialize(1024); - KeyPair kp = kpg.genKeyPair(); - publicKey = kp.getPublic(); - privateKey = kp.getPrivate(); - publicKey_s = Base64.encodeBase64String(publicKey.getEncoded()); - privateKey_s = Base64.encodeBase64String(privateKey.getEncoded()); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static String encrypt(String value) { - try { - Cipher cipher = Cipher.getInstance("RSA"); - cipher.init(Cipher.ENCRYPT_MODE, publicKey); - byte[] encrypted = cipher.doFinal(value.getBytes(StandardCharsets.UTF_8)); - return Base64.encodeBase64String(encrypted); - } catch (Exception ex) { - ex.printStackTrace(); - } - return null; - } - - public static String decrypt(String encrypted) { - try { - Cipher cipher = Cipher.getInstance("RSA"); - cipher.init(Cipher.DECRYPT_MODE, privateKey); - byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted)); - return new String(original, StandardCharsets.UTF_8); - } catch (Exception ex) { - ex.printStackTrace(); - } - return null; - } - -} \ No newline at end of file diff --git a/src/main/resources/cortana.yml b/src/main/resources/cortana.yml deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/java/love/sola/netsupport/config/CortanaTest.java b/src/test/java/love/sola/netsupport/config/CortanaTest.java deleted file mode 100644 index c0ea555..0000000 --- a/src/test/java/love/sola/netsupport/config/CortanaTest.java +++ /dev/null @@ -1,15 +0,0 @@ -package love.sola.netsupport.config; - -import org.junit.Test; - -/** - * @author Sola {@literal } - */ -public class CortanaTest { - - @Test - public void load() throws Exception { - Cortana.load(); - } - -} \ No newline at end of file diff --git a/src/test/java/love/sola/netsupport/util/EncryptTest.java b/src/test/java/love/sola/netsupport/util/EncryptTest.java deleted file mode 100644 index 40900ab..0000000 --- a/src/test/java/love/sola/netsupport/util/EncryptTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package love.sola.netsupport.util; - -import org.apache.commons.codec.binary.Base64; -import org.junit.Test; -import org.mindrot.jbcrypt.BCrypt; - -import java.security.KeyFactory; -import java.security.NoSuchAlgorithmException; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.X509EncodedKeySpec; - -/** - * @author Sola {@literal } - */ -public class EncryptTest { - - @Test - public void testBCrypt() { - String hash = BCrypt.hashpw("mypasswordhere", BCrypt.gensalt()); - assert BCrypt.checkpw("mypasswordhere", hash); - } - - @Test - public void testRSA() { - assert "Hello World".equals(RSAUtil.decrypt(RSAUtil.encrypt("Hello World"))); - assert "Encrypt".equals(RSAUtil.decrypt(RSAUtil.encrypt("Encrypt"))); - } - - // @Test - public void testRSASpecKey() throws NoSuchAlgorithmException, InvalidKeySpecException { - System.out.println("RSAUtil.privateKey_s = " + RSAUtil.privateKey_s); - System.out.println("RSAUtil.publicKey_s = " + RSAUtil.publicKey_s); -// String pkey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCA0qyARvHSCIUQ6YM6K+e/QgiZ+dc/MpVz5DIFwQab5iiifruQiaoA74ilHOOiq5i0ToR1VxNhCUZcAy2saHNifoYKTauMOUSV6IoP4X5jp691PlI9yxNx328mSlPNM9+7BgOzrUP1pR71d+T4LDn0o4J6Ad82vVIe7yWszzF4qQIDAQAB"; - String pkey = RSAUtil.publicKey_s; - KeyFactory keyFactory = KeyFactory.getInstance("RSA"); - X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.decodeBase64(pkey)); - RSAUtil.publicKey = keyFactory.generatePublic(keySpec); - System.out.println("RSAUtil.encrypt(\"233\") = " + RSAUtil.encrypt("233")); - } - -} diff --git a/src/test/resources/cortana.yml b/src/test/resources/cortana.yml deleted file mode 100644 index 8535f8e..0000000 --- a/src/test/resources/cortana.yml +++ /dev/null @@ -1,16 +0,0 @@ -rules: - rule1: - regexp: - - 'single test' - replies: - - 'single test' - rule2: - regexp: ['inline test', 'inline test'] - replies: ['inline test', 'inline test'] - rule3: - regexp: - - 'multi line test' - - 'multi line test' - replies: - - 'multi line test' - - 'multi line test'