mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-28 15:45:04 +08:00
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <dev@sola.love>}
|
||||
*/
|
||||
public class Cortana {
|
||||
|
||||
public static List<Compiled> 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<String, Rule> rules;
|
||||
|
||||
public RawConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 <dev@sola.love>}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package love.sola.netsupport.config;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Sola {@literal <dev@sola.love>}
|
||||
*/
|
||||
public class CortanaTest {
|
||||
|
||||
@Test
|
||||
public void load() throws Exception {
|
||||
Cortana.load();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <dev@sola.love>}
|
||||
*/
|
||||
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"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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'
|
||||
Reference in New Issue
Block a user