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.utils.StartParams;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class EmailService {
|
||||
|
||||
private final FileService fileService;
|
||||
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) {
|
||||
log.error("Start email processing");
|
||||
if (!params.getEnableEmailScan()) {
|
||||
|
||||
Reference in New Issue
Block a user