OfficeDev / ews-java-api

A java client library to access Exchange web services. The API works against Office 365 Exchange Online as well as on premises Exchange.
MIT License
870 stars 560 forks source link

Java 7 against https://outlook.office365.com/EWS/Exchange.asmx TLSv1.2 #754

Open dukeatfuture opened 2 years ago

dukeatfuture commented 2 years ago

Hello, Is there a way to force TLSv1.2 with Java 7?

My code is simply connect and read some calendar items. The code has always work with on-premise Microsoft Exchange Server 2010. Now I try to connect to outlook.office365.com and I get "Conenction reset" error. If I use jdk-13.0.1 the code run fine.

The environment that I'm in forced me to stick to jdk1.7.0_55. In my search for answers Java 7 by default is set to TLSv1 and it is proven by the trace. TLSv1.2 is the default in Java 8 onward and it looks like outlook.office365.com require TLSv1.2.

Error:

` Microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. The request failed. Connection reset at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74) at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:158) at microsoft.exchange.webservices.data.core.ExchangeService.syncFolderItems(ExchangeService.java:2376) ... main, WRITE: TLSv1 Handshake, length = 179 main, handling exception: java.net.SocketException: Connection reset main, SEND TLSv1 ALERT: fatal, description = unexpected_message main, WRITE: TLSv1 Alert, length = 2 main, Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error main, called closeSocket()

`

Connection : ` final ExchangeCredentials credentials = new WebCredentials(user, password, domain); if (this.isExchangeOnline) { service = new ExchangeService(this.exchangeVersion365); service.setUrl(new URI(this.ewsUrl365)); } else { service = new ExchangeService(this.exchangeVersion); service.setUrl(new URI(this.ewsUrl)); } service.setCredentials(credentials); service.setTraceEnabled(this.traceEws); service.setTraceListener(traceListener);

        final ImpersonatedUserId impersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress,
                impersonatedUserSMTPAddress);

        service.setImpersonatedUserId(impersonatedUserId);

`