This commit is contained in:
insanity 2018-07-02 20:37:23 +09:00
parent 29629b144f
commit d9576bf275
2 changed files with 16 additions and 15 deletions

View File

@ -27,6 +27,8 @@ import com.loafle.overflow.service.central.probe.ProbeHostService;
import com.loafle.overflow.service.central.probe.ProbeService; import com.loafle.overflow.service.central.probe.ProbeService;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -36,7 +38,6 @@ import inet.ipaddr.IPAddressString;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID;
import javax.transaction.Transactional; import javax.transaction.Transactional;
@ -156,7 +157,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail); DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail);
Probe probe = new Probe(); Probe probe = new Probe();
probe.setEncryptionKey(UUID.randomUUID().toString() + UUID.randomUUID().toString()); probe.setEncryptionKey(RandomStringUtils.randomAlphanumeric(8));
probe.setProbeKey(GenerateKey.getKey()); probe.setProbeKey(GenerateKey.getKey());
probe.setDomain(new Domain(apiKey.getDomain().getId())); probe.setDomain(new Domain(apiKey.getDomain().getId()));
probe.setAuthorizeMember(new Member(domainMember.getMember().getId())); probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));

View File

@ -69,15 +69,16 @@ public class CentralSensorConfigService {
} }
private String toEncryptString(SensorConfig sensorConfig, String encryptKey) throws OverflowException { private String toEncryptString(SensorConfig sensorConfig, String encryptKey) throws OverflowException {
try { try {
String sensorConfigJsonStr = this.objectMapper.writeValueAsString(sensorConfig); String sensorConfigJsonStr = this.objectMapper.writeValueAsString(sensorConfig);
// gzip // gzip
ByteArrayOutputStream obj = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(obj); GZIPOutputStream gzip = new GZIPOutputStream(bos);
gzip.write(sensorConfigJsonStr.getBytes("UTF-8")); gzip.write(sensorConfigJsonStr.getBytes("UTF-8"));
gzip.flush(); gzip.flush();
gzip.close(); gzip.close();
byte[] compressedByte = obj.toByteArray(); byte[] compressedByte = bos.toByteArray();
// DES encryption // DES encryption
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
@ -98,14 +99,13 @@ public class CentralSensorConfigService {
/* /*
* private String testDecrypt(String encryptKey, String encrypted) throws * private String testDecrypt(String encryptKey, String encrypted) throws
* OverflowException { try { byte[] inputBytes = * OverflowException { try { byte[] inputBytes =
* Base64.getDecoder().decode(encrypted.getBytes()); * Base64.getDecoder().decode(encrypted);
* *
* Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); SecretKeyFactory * Cipher cipher = Cipher.getInstance("DES"); SecretKeyFactory keyFactory =
* keyFactory = SecretKeyFactory.getInstance("DES"); DESKeySpec desKeySpec = new * SecretKeyFactory.getInstance("DES"); DESKeySpec desKeySpec = new
* DESKeySpec(encryptKey.getBytes()); cipher.init(Cipher.DECRYPT_MODE, * DESKeySpec(encryptKey.getBytes()); cipher.init(Cipher.DECRYPT_MODE,
* keyFactory.generateSecret(desKeySpec)); * keyFactory.generateSecret(desKeySpec)); byte[] outputBytes =
* * cipher.doFinal(inputBytes);
* byte[] outputBytes = cipher.doFinal(inputBytes);
* *
* GZIPInputStream gis = new GZIPInputStream(new * GZIPInputStream gis = new GZIPInputStream(new
* ByteArrayInputStream(outputBytes)); BufferedReader bf = new * ByteArrayInputStream(outputBytes)); BufferedReader bf = new