add trust to gov certs
This commit is contained in:
@@ -5,20 +5,53 @@ import com.pledge.torgi.model.Emails;
|
|||||||
import com.pledge.torgi.repositories.EmailsRepository;
|
import com.pledge.torgi.repositories.EmailsRepository;
|
||||||
import com.pledge.torgi.utils.StartParams;
|
import com.pledge.torgi.utils.StartParams;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.net.ssl.*;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
|
||||||
public class EmailService {
|
public class EmailService {
|
||||||
|
|
||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
private final EmailsRepository emailsRepository;
|
private final EmailsRepository emailsRepository;
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public EmailService(FileService fileService, EmailsRepository emailsRepository) {
|
||||||
|
this.emailsRepository = emailsRepository;
|
||||||
|
this.fileService = fileService;
|
||||||
|
|
||||||
|
TrustManager[] trustAllCerts = new TrustManager[] {
|
||||||
|
new X509TrustManager() {
|
||||||
|
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
||||||
|
// Ничего не проверяем
|
||||||
|
}
|
||||||
|
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
||||||
|
// Ничего не проверяем
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SSLContext sc = SSLContext.getInstance("TLS");
|
||||||
|
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||||
|
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||||
|
|
||||||
|
HostnameVerifier allHostsValid = new HostnameVerifier() {
|
||||||
|
public boolean verify(String hostname, SSLSession session) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
|
||||||
|
}
|
||||||
|
|
||||||
public void processEmails(StartParams params) {
|
public void processEmails(StartParams params) {
|
||||||
log.error("Start email processing");
|
log.error("Start email processing");
|
||||||
if (!params.getEnableEmailScan()) {
|
if (!params.getEnableEmailScan()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user