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

Back-end changes for Google XOAUTH2 #1747

Merged
merged 5 commits into from Dec 12, 2016
Merged

Back-end changes for Google XOAUTH2 #1747

merged 5 commits into from Dec 12, 2016

Conversation

philipwhiuk
Copy link
Contributor

Splitting out from #1295

Copy link
Contributor

@Valodim Valodim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lookin' good! Probably the most important PR we have currently, thanks for working on this 👍

@@ -82,4 +84,10 @@ public static String computeCramMd5(String username, String password, String b64
throw new MessagingException("Something went wrong during CRAM-MD5 computation", e);
}
}

public static String computeXoauth(String username, String authToken) throws UnsupportedEncodingException {
return new String(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is packed with logic, a couple of intermediate steps probably couldn't hurt

public static boolean shouldRetry(String response, String host) {
String decodedResponse = Base64.decode(response);

Log.v(LOG_TAG, "Challenge response: "+ decodedResponse);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a candidate for if (K9.DEBUG)


try {
JSONObject json = new JSONObject(decodedResponse);
if(!json.getString("status").equals(BAD_RESPONSE)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code style :)

also, CONSTANT.equals(variable) avoids NPEs

return false;
}
} catch (JSONException jsonException) {
Log.i(LOG_TAG, "Error decoding JSON response from:"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be Log.e?

@@ -322,6 +329,14 @@ private void startTLS() throws IOException, MessagingException, GeneralSecurityE
@SuppressWarnings("EnumSwitchStatementWhichMissesCases")
private void authenticate() throws MessagingException, IOException {
switch (settings.getAuthType()) {
case XOAUTH2:
if (hasCapability(Capabilities.AUTH_XOAUTH2) && hasCapability(Capabilities.SASL_IR)
&& oauthTokenProvider != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case where oauthTokenProvider is null here and it's not a bug? Either way it should probably be handled in an exception of its own, since the error message below is wrong in this case.

try {
attemptXOAuth2();
} catch (NegativeImapResponseException e) {
//We couldn't login with the token so invalidate it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointless comment :)

response.getString(0), settings.getHost());
}

if(response.isContinuationRequested()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you try to be more careful about trivial style errors like this? android studio can do this for you (and us)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was me I'd have a commit that fixed all the errors and made the build fail if new ones were added but nobody's a fan of that :(

I'll fix it.

@@ -635,6 +719,31 @@ protected String getLogId() {
return responseParser.readStatusResponse(tag, commandToLog, getLogId(), untaggedHandler);
}

public String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive)
throws IOException, MessagingException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

@@ -109,7 +109,7 @@ private void readTaggedResponse(ImapResponseCallback callback) throws IOExceptio
continue;
}

if (untaggedHandler != null) {
if (response.getTag() == null && untaggedHandler != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pointing out this might be a significant change in behavior, please double-check this doesn't break anything :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it only didn't fail a test because the test was badly written. I wrote some better tests for it and I think it should have failed. To me it looked like faulty logic and I browsed the spec a bit.

I'll keep using it on my device though.

}

private CommandResponse executeSimpleCommandWithResponse(String command, boolean sensitive) throws IOException, MessagingException {
List<String> results = new ArrayList<String>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diamond operator~

@philipwhiuk philipwhiuk added the type: security Issues related to security vulnerabilities label Nov 16, 2016

import java.util.List;

public interface OAuth2TokenProvider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this interface actually implemented? don't see it in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not. This is just the back-end changes. That's an interface for the front-end to implement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah OK, makes sense, was confused because OAuth2TokenProvider sounds like back-end functionality. Does only authorizeAPI() need user interaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the expectation, yes.

An (imperfect) implementation that supports GMail only is here: https://github.com/philipwhiuk/k-9/commit/7bd0f52c6d24ba1696620c4109c30d1f06aa770f#diff-4e75c10b7bac153fec6888b448a738ea

@cketti cketti merged commit 15ca924 into master Dec 12, 2016
@cketti cketti deleted the xoauth2Backend branch December 12, 2016 02:15
@HLFH
Copy link

HLFH commented Dec 12, 2016

Thanks for that great work!

I hope we'll get a release soon to try this great feature.

@sivaraam
Copy link

sivaraam commented Jun 4, 2018

I came here after some time of searching for open issues about Gmail OAuth logins. It's been around 1.5 years and as far as I could see I've not found OAuth support for logging into Gmail in the app. What's the current progress of this?

@Robert-Ernst
Copy link

@sivaraam Don't worry. Nothing has changed since your last message until now.

@wiktor-k
Copy link
Contributor

Actually there is a PR #3804 that enables Gmail OAuth login.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: security Issues related to security vulnerabilities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants