Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC-High Endpoints do not work #284

Open
dsavagevaaxa opened this issue Apr 21, 2023 · 32 comments
Open

GCC-High Endpoints do not work #284

dsavagevaaxa opened this issue Apr 21, 2023 · 32 comments
Labels
enhancement New feature or request

Comments

@dsavagevaaxa
Copy link

dsavagevaaxa commented Apr 21, 2023

Trying to get DavMail to work with Office 365 GCC-High endpoints. GCC-High uses outlook.office365.us rather than outlook.office365.com. I cannot seem to get this to function even after passing a valid token. The logs indicate that the program continues to target outlook.office365.com rather than the .us endpoint.

@esabol
Copy link

esabol commented Apr 21, 2023

What is the davmail.url setting in your ~/.davmail.properties file? I would guess it should be set to https://outlook.office365.us/EWS/Exchange.asmx. If that's set properly and you're still seeing it try to access outlook.office365.com, then that's pretty weird. See also issue #273 for other configuration tips.

@dsavagevaaxa
Copy link
Author

dsavagevaaxa commented Apr 22, 2023

After clearing everything out and trying a vanilla install and config in O365Interactive (with .us EWS), here is the log. Thunderbird which I am using for testing just sits there on "Sending login information" while DavMail status is < ******** then it times out eventually.

2023-04-22 06:34:59,620 DEBUG [JavaFX Application Thread] davmail.exchange.auth.O365InteractiveAuthenticatorFrame - Location starts with redirectUri, check code
2023-04-22 06:36:33,877 DEBUG [davmail.imap.ImapServer] davmail - Connection from /127.0.0.1 on port 1143
2023-04-22 06:36:33,878 INFO [davmail.imap.ImapServer] davmail.connection - CONNECT - 127.0.0.1:57830
2023-04-22 06:36:33,882 DEBUG [ImapConnection-57830] davmail.http.DavGatewaySSLSocketFactory - createSocket outlook.office365.us 443
2023-04-22 06:36:33,914 DEBUG [ImapConnection-57830] davmail.exchange.ExchangeSession - Test configuration status: 401
2023-04-22 06:36:33,914 DEBUG [ImapConnection-57830] davmail - > * OK [CAPABILITY IMAP4REV1 AUTH=LOGIN MOVE SPECIAL-USE] IMAP4rev1 DavMail 6.1.0-3423 server ready
2023-04-22 06:36:33,916 DEBUG [ImapConnection-57830] davmail - < 43 authenticate LOGIN
2023-04-22 06:36:33,916 DEBUG [ImapConnection-57830] davmail - > + VXNlcm5hbWU6
2023-04-22 06:36:33,917 DEBUG [ImapConnection-57830] davmail - < Token replaced
2023-04-22 06:36:33,917 DEBUG [ImapConnection-57830] davmail - > + UGFzc3dvcmQ6
2023-04-22 06:36:33,918 DEBUG [ImapConnection-57830] davmail - < ********
2023-04-22 06:39:54,033 ERROR [ImapConnection-57746] davmail.exchange.auth.O365InteractiveAuthenticator - Authentication failed Timed out waiting for interactive authentication
2023-04-22 06:39:54,033 INFO [ImapConnection-57746] davmail.connection - FAILED - 127.0.0.1:57746 [email protected]
2023-04-22 06:39:54,034 ERROR [ImapConnection-57746] davmail - Authentication failed Timed out waiting for interactive authentication

Then when trying in modern mode - in just fails as it immediately refers to login.microsoftonline.com instead of .us.

When trying in manual mode - I can get the auth code and submit it back to DavMail but then when it actually goes to login again the logs reflect that it is attempt to pass the token to login.microsoftonline.com again which fails

2023-04-22 07:17:36,970 DEBUG [ImapConnection-59996] org.apache.http.impl.execchain.MainClientExec - Opening connection {s}->https://login.microsoftonline.com:443
2023-04-22 07:17:36,971 DEBUG [ImapConnection-59996] org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to login.microsoftonline.com/20.190.190.129:443
2023-04-22 07:17:36,971 DEBUG [ImapConnection-59996] org.apache.http.conn.ssl.SSLConnectionSocketFactory - Connecting socket to login.microsoftonline.com/20.190.190.129:443 with timeout 10000
2023-04-22 07:17:37,015 DEBUG [ImapConnection-59996] davmail.http.DavGatewaySSLSocketFactory - createSocket login.microsoftonline.com 443
2023-04-22 07:17:37,016 DEBUG [ImapConnection-59996] org.apache.http.conn.ssl.SSLConnectionSocketFactory - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
2023-04-22 07:17:37,016 DEBUG [ImapConnection-59996] org.apache.http.conn.ssl.SSLConnectionSocketFactory - Enabled cipher suites:[TLS_AES_256_GCM_SHA384, TLS_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
2023-04-22 07:17:37,016 DEBUG [ImapConnection-59996] org.apache.http.conn.ssl.SSLConnectionSocketFactory - Starting handshake
2023-04-22 07:17:37,128 DEBUG [ImapConnection-59996] org.apache.http.conn.ssl.SSLConnectionSocketFactory - Secure session established
2023-04-22 07:17:37,128 DEBUG [ImapConnection-59996] org.apache.http.conn.ssl.SSLConnectionSocketFactory - negotiated protocol: TLSv1.2
2023-04-22 07:17:37,128 DEBUG [ImapConnection-59996] org.apache.http.conn.ssl.SSLConnectionSocketFactory - negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
2023-04-22 07:17:37,128 DEBUG [ImapConnection-59996] org.apache.http.conn.ssl.SSLConnectionSocketFactory - peer principal: CN=stamp2.login.microsoftonline.com, O=Microsoft Corporation, L=Redmond, ST=Washington, C=US
2023-04-22 07:17:37,128 DEBUG [ImapConnection-59996] org.apache.http.conn.ssl.SSLConnectionSocketFactory - peer alternative names: [stamp2.login.microsoftonline.com, login.microsoftonline-int.com, login.microsoftonline-p.com, login.microsoftonline.com, login2.microsoftonline-int.com, login2.microsoftonline.com, loginex.microsoftonline-int.com, loginex.microsoftonline.com, stamp2.login.microsoftonline-int.com]
2023-04-22 07:17:37,128 DEBUG [ImapConnection-59996] org.apache.http.conn.ssl.SSLConnectionSocketFactory - issuer principal: CN=DigiCert SHA2 Secure Server CA, O=DigiCert Inc, C=US
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connection established 10.0.1.5:60008<->20.190.190.129:443
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-4: set socket timeout to 120000
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.impl.execchain.MainClientExec - Executing request POST /eb7d944f-e9ad-49de-b45d-f7863338a4fe/oauth2/token HTTP/1.1
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.headers - http-outgoing-4 >> POST /eb7d944f-e9ad-49de-b45d-f7863338a4fe/oauth2/token HTTP/1.1
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.headers - http-outgoing-4 >> Content-Length: 1673
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.headers - http-outgoing-4 >> Content-Type: application/x-www-form-urlencoded; charset=UTF-8
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.headers - http-outgoing-4 >> Host: login.microsoftonline.com
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.headers - http-outgoing-4 >> Connection: Keep-Alive
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.headers - http-outgoing-4 >> User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.49
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.headers - http-outgoing-4 >> Accept-Encoding: gzip,deflate
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 >> "POST /eb7d944f-e9ad-49de-b45d-f7863338a4fe/oauth2/token HTTP/1.1[\r][\n]"
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 >> "Content-Length: 1673[\r][\n]"
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 >> "Content-Type: application/x-www-form-urlencoded; charset=UTF-8[\r][\n]"
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 >> "Host: login.microsoftonline.com[\r][\n]"
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 >> "Connection: Keep-Alive[\r][\n]"
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 >> "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.49[\r][\n]"
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 >> "[\r][\n]"
2023-04-22 07:17:37,129 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 >> "grant_type=refresh_token&refresh_token=tokenremoved&redirect_uri=https%3A%2F%2Flogin.microsoftonline.us%2Fcommon%2Foauth2%2Fnativeclient&client_id=1c080934-f0ec-422f-8da8-b46cd37004d8&resource=https%3A%2F%2Foutlook.office365.com%2F"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "HTTP/1.1 400 Bad Request[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "Cache-Control: no-store, no-cache[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "Pragma: no-cache[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "Content-Type: application/json; charset=utf-8[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "Expires: -1[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "Strict-Transport-Security: max-age=31536000; includeSubDomains[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "X-Content-Type-Options: nosniff[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "P3P: CP="DSP CUR OTPi IND OTRi ONL FIN"[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "x-ms-request-id: 8338adf3-0cd0-48c6-be5b-b28cbaad3a00[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "x-ms-ests-server: 2.1.15175.8 - SCUS ProdSlices[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "report-to: {"group":"network-errors","max_age":86400,"endpoints":[{"url":"https://identity.nel.measure.office.net/api/report?catId=GW+estsfd+wst"}]}[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "nel: {"report_to":"network-errors","max_age":86400,"success_fraction":0.001,"failure_fraction":1.0}[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "Referrer-Policy: strict-origin-when-cross-origin[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "X-XSS-Protection: 0[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "Set-Cookie: fpc=AgmY6dS-v89PkUeRVeDoTmc; expires=Mon, 22-May-2023 11:17:37 GMT; path=/; secure; HttpOnly; SameSite=None[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "Set-Cookie: x-ms-gateway-slice=estsfd; path=/; secure; samesite=none; httponly[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "Set-Cookie: stsservicecookie=estsfd; path=/; secure; samesite=none; httponly[\r][\n]"
2023-04-22 07:17:37,415 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "Date: Sat, 22 Apr 2023 11:17:37 GMT[\r][\n]"
2023-04-22 07:17:37,416 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "Content-Length: 987[\r][\n]"
2023-04-22 07:17:37,416 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "[\r][\n]"
2023-04-22 07:17:37,416 DEBUG [ImapConnection-59996] org.apache.http.wire - http-outgoing-4 << "{"error":"invalid_request","error_description":"AADSTS900434: National Cloud request processing failed: CallNationalCloud: http request failed with errorcode: BadRequest, Content:{"error":"invalid_grant","error_description":"AADSTS70000: Provided grant is invalid or malformed.\r\nTrace ID: 20fe3f66-4542-4fd8-8b74-e435d8587500\r\nCorrelation ID: 855a5547-d6a0-458f-9710-e71bbd22a333\r\nTimestamp: 2023-04-22 11:17:37Z","error_codes":[70000],"timestamp":"2023-04-22 11:17:37Z","trace_id":"20fe3f66-4542-4fd8-8b74-e435d8587500","correlation_id":"855a5547-d6a0-458f-9710-e71bbd22a333","error_uri":"https://login.microsoftonline.us/error?code=70000\"}.\r\nTrace ID: 8338adf3-0cd0-48c6-be5b-b28cbaad3a00\r\nCorrelation ID: 855a5547-d6a0-458f-9710-e71bbd22a333\r\nTimestamp: 2023-04-22 11:17:37Z","error_codes":[900434],"timestamp":"2023-04-22 11:17:37Z","trace_id":"8338adf3-0cd0-48c6-be5b-b28cbaad3a00","correlation_id":"855a5547-d6a0-458f-9710-e71bbd22a333"}"

@esabol
Copy link

esabol commented Apr 22, 2023

@dsavagevaaxa, do you have a setting for davmail.oauth.redirectUri in your ~/.davmail.properties file? (If so, what is it?) That setting defaults to

davmail.oauth.redirectUri=https://login.microsoftonline.com/common/oauth2/nativeclient

I recommend that you try changing that setting, if you're not already doing so.

I also recommend that you keep using O365Manual for now and only look at trying other modes once you get O365Manual working.

That said, I do see places in the code where login.microsoftonline.com is used, so I could see how there might be problems if you need to use a different server name.

Do you feel up to compiling your own version of DavMail?

@mguessan
Copy link
Owner

mguessan commented Jun 4, 2023

I wasn"t aware of the https://outlook.office365.us endpoint so the default .com suffix is hardcoded for O365 in some places.

=> need to review code to make it compatible with non standard tenants

@mguessan mguessan added the enhancement New feature or request label Sep 22, 2023
@mguessan
Copy link
Owner

At least two urls are hardcoded:

  • login.microsoftonline.com
  • outlook.office365.com

Can you confirm those would be the same but with .us suffix ?

@pawankukreja01
Copy link

it seems that Office 365 GCC-High endpoints use outlook.office365.us instead of outlook.office365.com. You can find a list of Office 365 U.S.

It is possible that the program is using a default endpoint configuration. You may need to modify the configuration file to include the correct endpoint. I suggest checking the documentation for DavMail.

@lhindir
Copy link

lhindir commented Jan 12, 2024

@mguessan recent commits, like 99a4944, look relevant to this issue. I tried searching the web for “davmail gcc high”, as well as the SourceForge discussions and mailing list, but I didn’t find anything. Is someone paying you to implement it now? Is the “audit” mentioned in other recent commits related to the GCC High support work? Just curious. Thanks for your work on this project in any case!

@mguessan
Copy link
Owner

@lhindir indeed this comment is related to GCC High (non .com), I refactored the code to regroup all reference to actual O365 urls in a single place (getO365LoginUrl)

Of course I don't have an actual US gov O365 mailbox so I can't confirm changes are working as expected.

The - yet to be documented - way to try this is to set a new property in davmail.properties:

davmail.tld=us

@RickyDoug

This comment was marked as resolved.

@mguessan
Copy link
Owner

@RickyDoug looks good, just please repost without the code= value, this is a sensitive token.
It's probably expired by now, but we can't leave confidential tokens public

@RickyDoug
Copy link

Thanks. Hard to tell what does and doesn't need to be sanitized. It's been cleaned up.

@mguessan
Copy link
Owner

mguessan commented Jan 18, 2024

So do you have anything after check code ?
We expect a request to https://login.microsoftonline.us
Then Authenticated username:
=> would mean we obtained a token

@lhindir
Copy link

lhindir commented Jan 20, 2024

A user’s organization needs to allow Davmail’s client ID via portal.azure.us for OAuth2 to work before this can be tested, right?

@mguessan
Copy link
Owner

With default DavMail clientid and redirecturi yes, with Microsoft native application clientId no, see #273

@RickyDoug
Copy link

RickyDoug commented Jan 27, 2024

Sorry I haven't gotten to test this yet, but i managed to hurt my back and haven't been able to get back to the machine...but nothing after the check code. Also, I managed to get Outlook's Client ID and that used to work fine with the normal .com... no admin changes needed. Hopefully next week I'll be able to get back to this.

And should this still be hitting a .com URL?

@kenh
Copy link

kenh commented Feb 6, 2024

I believe I am running into the same issue; I tried a trunk release and set davmail.tld=us, but that did not work. If a debug log would help I'd be glad to provide one.

@esabol
Copy link

esabol commented Feb 6, 2024

@kenh wrote:

If a debug log would help I'd be glad to provide one.

Well, it wouldn't hurt. 🙂 I recommend creating a wire debug log using a build of the latest GitHub master branch, as described here:

https://davmail.sourceforge.net/faq.html#Feedback

If you prefer to edit your properties file yourself, put the following line in your properties file:

log4j.logger.httpclient.wire=DEBUG
log4j.logger.org.apache.http.wire=DEBUG

Quit and restart the DavMail application. Then have your mail program connect to DavMail and try to authenticate again. DavMail will then create a detailed log of what it is doing. This log will be stored in a davmail.log file. By default, it will be located in DavMail's current working directory on Linux and Windows or in ~/Library/Logs/DavMail/davmail.log on macOS. (The location of this file can be customized with the Log File Path setting.) This log file might include information like your password and other account details that you should not share online. If you are confident you can remove those things from the davmail.log file, feel free to post the sanitized file here. Otherwise, send the log file to [email protected] along with the URL of this GitHub issue. I hope this helps!

@mguessan
Copy link
Owner

In addition to the above I would suggest you try with Outlook clientId:

davmail.oauth.clientId=d3590ed6-52b3-4102-aeff-aad2292ab01c
davmail.oauth.redirectUri=urn:ietf:wg:oauth:2.0:oob

The default DavMail clientId is registered on main O365/EntraID infrastructure, and of cours I can't create one on .us tld

@HoneyBadgerMatt
Copy link

HoneyBadgerMatt commented Jun 18, 2024

I am able to get this to work (version 6.0.1-3390) with my organization which is using GCC-High. I have to edit the domains to .us in these files before compiling:
src/test/davmail/http/TestHttpClientAdapter.java
src/test/davmail/http/TestHttpClient4.java
src/test/davmail/http/TestURIBuilder.java
src/java/davmail/exchange/auth/O365InteractiveAuthenticatorFrame.java
src/java/davmail/Settings.java

In my config file, I have to specify the tenantId and use this pair (for Gnome Evolution):
davmail.oauth.clientId=20460e5d-ce91-49af-a3a5-70b6be7486d1
davmail.oauth.redirectUri=https://login.microsoftonline.com/common/oauth2/nativeclient
davmail.url=https://outlook.office365.us/EWS/Exchange.asmx.

If I try these:
davmail.oauth.clientId=d3590ed6-52b3-4102-aeff-aad2292ab01c
davmail.oauth.redirectUri=urn:ietf:wg:oauth:2.0:oob

the link I get to obtain the token url redirects me to a page with this error: "AADSTS165000: Invalid Request: The request tokens do not match the user context."

The 6.2.2 versions work, but I keep getting asked to open a browser to get a new token every day and once for each service (except imap & smtp-- those only need the token updated once).

@SethRobertson
Copy link

Still does not work in 6.2.2 -- though possibly only for clients that use third party authentication sites. When I observe the wire traffic, I still see an office365.com URL bumming around. I blame:

.addParameter("resource", Settings.OUTLOOK_URL);
OR
parameters.add(new BasicNameValuePair("resource", Settings.OUTLOOK_URL));

I edited source to fix all .com to .us and did not try to confirm my assumption above. This also included changing graph.microsoft.com to graph.microsoft.us since I don't know what it is used for and you cannot change it via property...I was incredibly frustrated by this time (mostly due to java stupidities). There is a graph.microsoft.us variant hostname so I assume it should be usable if it is used in my/someone's configuration.

I set all of the following properties before resorting to changing the source. I have not tried to delete the urls to see if the tls would obviate the need to change some of them.

davmail.loginUrl=https://login.microsoftonline.us/
davmail.url=https://outlook.office365.us/EWS/Exchange.asmx
davmail.tls=us
davmail.oauth.redirectUri=urn:ietf:wg:oauth:2.0:oob

@esabol
Copy link

esabol commented Dec 28, 2024

davmail.tls=us

Is that exactly what you had set, @SethRobertson ?

Because that should have been davmail.tld=us. Typo?

I think you may also need to set davmail.outlookUrl=https://outlook.office365.us (or whatever it's supposed to be). That's what Settings.OUTLOOK_URL is referencing, I think.

@mguessan
Copy link
Owner

I have a few commits post release on this, please make sure you get the latest trunk build from github home page.

In addition this is still considered experimental, I have no way to actually test GCC high endpoints.

@SethRobertson
Copy link

I am essentially up to date on trunk/master (I don't have the CRLF=>LF change).

I did mess up tls instead of tld, but AFAIK the Settings.OUTLOOK_URL does not reflect those changes. So the lines identified by this grep will NOT change:

rg '^[^/]*(OUTLOOK|O365)_URL' src/java

I am 99% sure that the "resource" lines are absolutely wrong--when I snooped the traffic in the logs I saw resource in a web request with a .com address. The O365_URL and other OUTLOOK_URL ones I am only extremely suspicious of.

@esabol
Copy link

esabol commented Jan 4, 2025

Ah, yes, I see what you mean, @SethRobertson.

I have opened PR #380 to change the instances of Settings.OUTLOOK_URL to something that references the davmail.outlookUrl or davmail.tld properties when either are set.

Would you be willing to test the changes in 919ec03 ?

As @mguessan has said, he has no way of testing GCC high endpoints (and neither do I!), so you are our best hope to finally get this issue resolved. Would you be willing to compile davmail from source?

There are two cases to test. One case is only setting davmail.tld=us (remove the other davmail.*Url properties entirely) and the other is setting davmail.outlookUrl=https://outlook.office365.us in conjunction with davmail.loginUrl=https://login.microsoftonline.us/ (remove the davmail.tld property).

@esabol
Copy link

esabol commented Jan 4, 2025

@mguessan : I see Settings.O365_URL used in src/java/davmail/exchange/ExchangeSessionFactory.java, src/java/davmail/exchange/auth/O365Authenticator.java, src/test/davmail/http/TestGetRequest.java, and src/test/davmail/http/TestPostRequest.java. Should any of those instances be changed to use Settings.getO365Url() as well? I suspect at least the first two. I've made that change in e6443a4. @SethRobertson, please include this commit in your test build as well, unless @mguessan disagrees.

@SethRobertson
Copy link

I tested commit e6443a4. In all cases I had the davmail.oath.redirectUri set to "urn:ietf:wg:oauth:2.0:oob"

With the following properties set, it WORKED.

davmail.loginUrl=https://login.microsoftonline.us/
davmail.outlookUrl=https://outlook.office365.us
davmail.url=https://outlook.office365.us/EWS/Exchange.asmx

Without davmail.url set, it did NOT work.

2025-01-07 04:14:47,283 ERROR [ImapConnection-38090] davmail - Invalid URL: null
davmail.exception.DavMailException: Invalid URL: null
at davmail.exchange.ExchangeSessionFactory.checkConfig(ExchangeSessionFactory.java:306)
at davmail.imap.ImapConnection.run(ImapConnection.java:97)
2025-01-07 04:14:47,285 DEBUG [ImapConnection-38090] davmail - > * BAD unable to handle request: Invalid URL: null

With only davmail.tld set, it did NOT work.

davmail.exception.DavMailException: Invalid URL: null
at davmail.exchange.ExchangeSessionFactory.checkConfig(ExchangeSessionFactory.java:306)
at davmail.imap.ImapConnection.run(ImapConnection.java:97)
2025-01-07 04:16:09,258 DEBUG [ImapConnection-49068] davmail - > * BAD unable to handle request: Invalid URL: null

With davmail.tld and davmail.url set, it DID work:

davmail.tld=us
davmail.url=https://outlook.office365.us/EWS/Exchange.asmx

I went back to the .tld-only configuration and entered the settings page.

The URL was grayed out and I could only see the end of the Exchange URL. However the end looked good:

ok.office365.us/EWS/Exchange.asmx

@esabol
Copy link

esabol commented Jan 7, 2025

Thanks, @SethRobertson ! I think we're getting pretty close here. Would you be willing to try one more change to Settings.java? I've committed the change here: 6e9f4fd

That should change the default value of the davmail.url property to be based on the settings of davmail.tld and/or davmail.outlookUrl, which should mean you no longer need to set davmail.url when either of those other two properties are set.

@lhindir
Copy link

lhindir commented Jan 10, 2025

Hi @esabol, thanks for taking a look at this. There seem to be numerous additional direct references to the properties for which your PR (#380) introduces high-level accessors. I think I got most of the critical ones (ignoring tests, as well as GRAPH_URL) here:

Expand diff
---
 src/java/davmail/Settings.java                              | 1 +
 src/java/davmail/exchange/ExchangeSessionFactory.java       | 6 +++---
 src/java/davmail/exchange/auth/O365Authenticator.java       | 2 +-
 .../davmail/exchange/auth/O365InteractiveAuthenticator.java | 2 +-
 src/java/davmail/exchange/auth/O365ManualAuthenticator.java | 2 +-
 .../davmail/exchange/auth/O365StoredTokenAuthenticator.java | 2 +-
 src/java/davmail/ldap/LdapConnection.java                   | 2 +-
 src/java/davmail/ui/SettingsFrame.java                      | 6 +++---
 8 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/java/davmail/Settings.java b/src/java/davmail/Settings.java
index dccce122..11a59a10 100644
--- a/src/java/davmail/Settings.java
+++ b/src/java/davmail/Settings.java
@@ -44,6 +44,7 @@ public final class Settings {
     public static final String OUTLOOK_URL = "https://outlook.office365.com";
     public static final String O365_URL = OUTLOOK_URL+"/EWS/Exchange.asmx";

+    // FIXME
     public static final String GRAPH_URL = "https://graph.microsoft.com";

     public static final String O365_LOGIN_URL = "https://login.microsoftonline.com/";
diff --git a/src/java/davmail/exchange/ExchangeSessionFactory.java b/src/java/davmail/exchange/ExchangeSessionFactory.java
index de3e45cf..fc2d3958 100644
--- a/src/java/davmail/exchange/ExchangeSessionFactory.java
+++ b/src/java/davmail/exchange/ExchangeSessionFactory.java
@@ -88,7 +88,7 @@ public final class ExchangeSessionFactory {
      * @throws IOException on error
      */
     public static ExchangeSession getInstance(String userName, String password) throws IOException {
-        String baseUrl = Settings.getProperty("davmail.url");
+        String baseUrl = Settings.getO365Url();
         if (Settings.getBooleanProperty("davmail.server")) {
             return getInstance(baseUrl, userName, password);
         } else {
@@ -277,7 +277,7 @@ public final class ExchangeSessionFactory {
             if (session.isExpired()) {
                 ExchangeSession.LOGGER.debug("Session " + session + " expired, trying to open a new one");
                 session = null;
-                String baseUrl = Settings.getProperty("davmail.url");
+                String baseUrl = Settings.getO365Url();
                 PoolKey poolKey = new PoolKey(baseUrl, userName, password);
                 // expired session, remove from cache
                 synchronized (LOCK) {
@@ -301,7 +301,7 @@ public final class ExchangeSessionFactory {
      * @throws IOException if unable to access Exchange server
      */
     public static void checkConfig() throws IOException {
-        String url = Settings.getProperty("davmail.url");
+        String url = Settings.getO365Url();
         if (url == null || (!url.startsWith("http://") && !url.startsWith("https://"))) {
             throw new DavMailException("LOG_INVALID_URL", url);
         }
diff --git a/src/java/davmail/exchange/auth/O365Authenticator.java b/src/java/davmail/exchange/auth/O365Authenticator.java
index b7348c64..e738b037 100644
--- a/src/java/davmail/exchange/auth/O365Authenticator.java
+++ b/src/java/davmail/exchange/auth/O365Authenticator.java
@@ -123,7 +123,7 @@ public class O365Authenticator implements ExchangeAuthenticator {
         // common DavMail client id
         String clientId = Settings.getProperty("davmail.oauth.clientId", "facd6cff-a294-4415-b59f-c5b01937d7bd");
         // standard native app redirectUri
-        String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.O365_LOGIN_URL+"common/oauth2/nativeclient");
+        String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.getO365LoginUrl()+"common/oauth2/nativeclient");
         // company tenantId or common
         tenantId = Settings.getProperty("davmail.oauth.tenantId", "common");

diff --git a/src/java/davmail/exchange/auth/O365InteractiveAuthenticator.java b/src/java/davmail/exchange/auth/O365InteractiveAuthenticator.java
index 2c729e16..82980016 100644
--- a/src/java/davmail/exchange/auth/O365InteractiveAuthenticator.java
+++ b/src/java/davmail/exchange/auth/O365InteractiveAuthenticator.java
@@ -101,7 +101,7 @@ public class O365InteractiveAuthenticator implements ExchangeAuthenticator {
         // common DavMail client id
         final String clientId = Settings.getProperty("davmail.oauth.clientId", "facd6cff-a294-4415-b59f-c5b01937d7bd");
         // standard native app redirectUri
-        final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.O365_LOGIN_URL+"common/oauth2/nativeclient");
+        final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.getO365LoginUrl()+"common/oauth2/nativeclient");
         // company tenantId or common
         String tenantId = Settings.getProperty("davmail.oauth.tenantId", "common");

diff --git a/src/java/davmail/exchange/auth/O365ManualAuthenticator.java b/src/java/davmail/exchange/auth/O365ManualAuthenticator.java
index 1fcdef9c..1bbe2ce9 100644
--- a/src/java/davmail/exchange/auth/O365ManualAuthenticator.java
+++ b/src/java/davmail/exchange/auth/O365ManualAuthenticator.java
@@ -88,7 +88,7 @@ public class O365ManualAuthenticator implements ExchangeAuthenticator {
         // common DavMail client id
         final String clientId = Settings.getProperty("davmail.oauth.clientId", "facd6cff-a294-4415-b59f-c5b01937d7bd");
         // standard native app redirectUri
-        final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.O365_LOGIN_URL+"common/oauth2/nativeclient");
+        final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.getO365LoginUrl()+"common/oauth2/nativeclient");
         // company tenantId or common
         String tenantId = Settings.getProperty("davmail.oauth.tenantId", "common");

diff --git a/src/java/davmail/exchange/auth/O365StoredTokenAuthenticator.java b/src/java/davmail/exchange/auth/O365StoredTokenAuthenticator.java
index 05b2e745..bf08f838 100644
--- a/src/java/davmail/exchange/auth/O365StoredTokenAuthenticator.java
+++ b/src/java/davmail/exchange/auth/O365StoredTokenAuthenticator.java
@@ -63,7 +63,7 @@ public class O365StoredTokenAuthenticator implements ExchangeAuthenticator {
         // common DavMail client id
         final String clientId = Settings.getProperty("davmail.oauth.clientId", "facd6cff-a294-4415-b59f-c5b01937d7bd");
         // standard native app redirectUri
-        final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.O365_LOGIN_URL+"common/oauth2/nativeclient");
+        final String redirectUri = Settings.getProperty("davmail.oauth.redirectUri", Settings.getO365LoginUrl()+"common/oauth2/nativeclient");
         // company tenantId or common
         String tenantId = Settings.getProperty("davmail.oauth.tenantId", "common");

diff --git a/src/java/davmail/ldap/LdapConnection.java b/src/java/davmail/ldap/LdapConnection.java
index aab33e0b..6058d2e4 100644
--- a/src/java/davmail/ldap/LdapConnection.java
+++ b/src/java/davmail/ldap/LdapConnection.java
@@ -943,7 +943,7 @@ public class LdapConnection extends AbstractConnection {
         objectClasses.add("organizationalUnit");
         Map<String, Object> attributes = new HashMap<>();
         attributes.put("objectClass", objectClasses);
-        attributes.put("description", "DavMail Gateway LDAP for " + Settings.getProperty("davmail.url"));
+        attributes.put("description", "DavMail Gateway LDAP for " + Settings.getO365Url());
         sendEntry(currentMessageId, BASE_CONTEXT, attributes);
     }

diff --git a/src/java/davmail/ui/SettingsFrame.java b/src/java/davmail/ui/SettingsFrame.java
index 5a743764..e89f7ca1 100644
--- a/src/java/davmail/ui/SettingsFrame.java
+++ b/src/java/davmail/ui/SettingsFrame.java
@@ -173,12 +173,12 @@ public class SettingsFrame extends JFrame {
             modeComboBox.setToolTipText(BundleMessage.format("UI_"+selectedItem+"_HELP"));
             if (selectedItem != null && selectedItem.startsWith("O365")) {
                 urlField.setEnabled(false);
-                urlField.setText(Settings.O365_URL);
+                urlField.setText(Settings.getO365Url());
             } else {
                 urlField.setEnabled(true);
             }
         });
-        urlField = new JTextField(Settings.getProperty("davmail.url"), 20);
+        urlField = new JTextField(Settings.getO365Url(), 20);
         popPortField = new JTextField(Settings.getProperty("davmail.popPort"), 4);
         popPortCheckBox = new JCheckBox();
         popNoSSLCheckBox = new JCheckBox(BundleMessage.format("UI_NO_SSL"), Settings.getBooleanProperty("davmail.ssl.nosecurepop"));
@@ -596,7 +596,7 @@ public class SettingsFrame extends JFrame {
      */
     public void reload() {
         // reload settings in form
-        urlField.setText(Settings.getProperty("davmail.url"));
+        urlField.setText(Settings.getO365Url());
         popPortField.setText(Settings.getProperty("davmail.popPort"));
         popPortCheckBox.setSelected(Settings.getProperty("davmail.popPort") != null && !Settings.getProperty("davmail.popPort").isEmpty());
         popNoSSLCheckBox.setSelected(Settings.getBooleanProperty("davmail.ssl.nosecurepop"));
--
2.47.1

With that, tld alone should be sufficient for GCC-High users, I think?

But it would be better to modify the internal Settings API so that consumers cannot access Settings.O365_URL and friends directly, nor with Settings.getProperty, rather than trying to manually ensure there are no direct references. I haven’t thought too hard about this but maybe you and @mguessan have better ideas.

@esabol
Copy link

esabol commented Jan 10, 2025

I think I got most of those in my PR, @lhindir, but I'll double-check. I'm not sure the instances in SettingsFrame.java need to be changed? I think they're just providing the default values for the GUI?

Do you think a Settings.getGraphUrl() is needed which takes into account davmail.tld as well?

@lhindir
Copy link

lhindir commented Jan 10, 2025

I think I got most of those in my PR, @lhindir, but I'll double-check.

I generated that diff after checking out esabol@6e9f4fd and making changes, so there shouldn’t be overlap.

I'm not sure the instances in SettingsFrame.java need to be changed? I think they're just providing the default values for the GUI?

There’s no reason not to change them and leave the door open for the UI to misrepresent the application state, I think. Like I said, we shouldn’t be mixing raw references to the properties with the new accessors, and maybe there is a way to prevent this at compile time. Ideally @mguessan can chime in with his thoughts so you don’t waste too much effort on an implementation that won’t be merged.

Do you think a Settings.getGraphUrl() is needed which takes into account davmail.tld as well?

No idea honestly. I’m not sure what the graph server is used for. But I would bet that whatever is using it is broken for GCC High if we don’t handle it like we do the other URLs.

Thanks!

@esabol
Copy link

esabol commented Jan 11, 2025

@lhindir wrote:

I generated that diff after checking out esabol@6e9f4fd and making changes, so there shouldn’t be overlap.

Oh, OK. Thanks!

Do you think a Settings.getGraphUrl() is needed which takes into account davmail.tld as well?

No idea honestly. I’m not sure what the graph server is used for.

It's some new Microsoft-proprietary API for interacting with Microsoft Cloud services, basically retrieving mail and stuff, I think. I don't think DavMail currently fully supports it (because the API may not support everything DavMail needs?), but it's in the works.... What I'm not clear on is if GCC High supports this API or not, but it probably does, if I had to guess. Fwiw, graph.microsoft.us exists, but graph.microsoft.cn doesn't.

@lhindir
Copy link

lhindir commented Jan 11, 2025

Ah, thanks. I would guess GCC High supports it and if it doesn’t now it probably will in future. I just threw it in there since I figured as long as we’re getting away from hardcoding URLs, we might as well fix them all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants