Bug 1240919 - Part 1: Start culling old Firefox Accounts code. r=rnewman
authorNick Alexander <nalexander@mozilla.com>
Tue, 19 Jan 2016 13:22:53 -0800
changeset 303127 2cffe56c205e33399c7485b3660476ab4272c0dd
parent 303126 57327dc816470c156305f3cb0ac221fd5716d5eb
child 303128 d09ba092a9d28305247f9bdab4513602fab1785e
push id8978
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 14:05:32 +0000
treeherdermozilla-aurora@b9a803752a2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1240919
milestone46.0a1
Bug 1240919 - Part 1: Start culling old Firefox Accounts code. r=rnewman
mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccountClient.java
mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccountClient10.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccountClient.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccountClient.java
@@ -13,11 +13,9 @@ import org.mozilla.gecko.background.fxa.
 import org.mozilla.gecko.sync.ExtendedJSONObject;
 
 public interface FxAccountClient {
   public void createAccountAndGetKeys(final byte[] emailUTF8, final PasswordStretcher passwordStretcher, final Map<String, String> queryParameters, final RequestDelegate<LoginResponse> delegate);
   public void loginAndGetKeys(final byte[] emailUTF8, final PasswordStretcher passwordStretcher, final Map<String, String> queryParameters, final RequestDelegate<LoginResponse> requestDelegate);
   public void status(byte[] sessionToken, RequestDelegate<StatusResponse> requestDelegate);
   public void keys(byte[] keyFetchToken, RequestDelegate<TwoKeys> requestDelegate);
   public void sign(byte[] sessionToken, ExtendedJSONObject publicKey, long certificateDurationInMilliseconds, RequestDelegate<String> requestDelegate);
-  public void resendCode(byte[] sessionToken, RequestDelegate<Void> delegate);
-  public void resendUnlockCode(byte[] emailUTF8, RequestDelegate<Void> delegate);
 }
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccountClient10.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/background/fxa/FxAccountClient10.java
@@ -1,45 +1,46 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.background.fxa;
 
+import org.json.simple.JSONObject;
+import org.mozilla.gecko.background.fxa.FxAccountClientException
+        .FxAccountClientMalformedResponseException;
+import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException;
+import org.mozilla.gecko.fxa.FxAccountConstants;
+import org.mozilla.gecko.sync.ExtendedJSONObject;
+import org.mozilla.gecko.sync.Utils;
+import org.mozilla.gecko.sync.crypto.HKDF;
+import org.mozilla.gecko.sync.net.AuthHeaderProvider;
+import org.mozilla.gecko.sync.net.BaseResource;
+import org.mozilla.gecko.sync.net.BaseResourceDelegate;
+import org.mozilla.gecko.sync.net.HawkAuthHeaderProvider;
+import org.mozilla.gecko.sync.net.Resource;
+import org.mozilla.gecko.sync.net.SyncResponse;
+import org.mozilla.gecko.sync.net.SyncStorageResponse;
+
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URLEncoder;
 import java.security.GeneralSecurityException;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
 import java.util.Arrays;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.Executor;
 
 import javax.crypto.Mac;
 
-import org.json.simple.JSONObject;
-import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientMalformedResponseException;
-import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException;
-import org.mozilla.gecko.fxa.FxAccountConstants;
-import org.mozilla.gecko.sync.ExtendedJSONObject;
-import org.mozilla.gecko.sync.Utils;
-import org.mozilla.gecko.sync.crypto.HKDF;
-import org.mozilla.gecko.sync.net.AuthHeaderProvider;
-import org.mozilla.gecko.sync.net.BaseResource;
-import org.mozilla.gecko.sync.net.BaseResourceDelegate;
-import org.mozilla.gecko.sync.net.HawkAuthHeaderProvider;
-import org.mozilla.gecko.sync.net.Resource;
-import org.mozilla.gecko.sync.net.SyncResponse;
-import org.mozilla.gecko.sync.net.SyncStorageResponse;
-
 import ch.boye.httpclientandroidlib.HttpEntity;
 import ch.boye.httpclientandroidlib.HttpHeaders;
 import ch.boye.httpclientandroidlib.HttpResponse;
 import ch.boye.httpclientandroidlib.client.ClientProtocolException;
 import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase;
 import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient;
 
 /**
@@ -168,28 +169,16 @@ public class FxAccountClient10 {
     public JSONObject getAuthStartBody() throws FxAccountClientException;
     public void onAuthStartResponse(ExtendedJSONObject body) throws FxAccountClientException;
     public JSONObject getAuthFinishBody() throws FxAccountClientException;
 
     public byte[] getSharedBytes() throws FxAccountClientException;
   }
 
   /**
-   * Thin container for two access tokens.
-   */
-  public static class TwoTokens {
-    public final byte[] keyFetchToken;
-    public final byte[] sessionToken;
-    public TwoTokens(byte[] keyFetchToken, byte[] sessionToken) {
-      this.keyFetchToken = keyFetchToken;
-      this.sessionToken = sessionToken;
-    }
-  }
-
-  /**
    * Thin container for two cryptographic keys.
    */
   public static class TwoKeys {
     public final byte[] kA;
     public final byte[] wrapkB;
     public TwoKeys(byte[] kA, byte[] wrapkB) {
       this.kA = kA;
       this.wrapkB = wrapkB;
@@ -506,80 +495,16 @@ public class FxAccountClient10 {
           public void run() {
             delegate.handleFailure(e);
           }
         });
       }
     });
   }
 
-  public void sessionCreate(byte[] authToken, final RequestDelegate<TwoTokens> delegate) {
-    final byte[] tokenId = new byte[32];
-    final byte[] reqHMACKey = new byte[32];
-    final byte[] requestKey = new byte[32];
-    try {
-      HKDF.deriveMany(authToken, new byte[0], FxAccountUtils.KW("authToken"), tokenId, reqHMACKey, requestKey);
-    } catch (Exception e) {
-      invokeHandleError(delegate, e);
-      return;
-    }
-
-    BaseResource resource;
-    try {
-      resource = getBaseResource("session/create");
-    } catch (URISyntaxException | UnsupportedEncodingException e) {
-      invokeHandleError(delegate, e);
-      return;
-    }
-
-    resource.delegate = new ResourceDelegate<TwoTokens>(resource, delegate, tokenId, reqHMACKey) {
-      @Override
-      public void handleSuccess(int status, HttpResponse response, ExtendedJSONObject body) {
-        try {
-          byte[] keyFetchToken = new byte[32];
-          byte[] sessionToken = new byte[32];
-          unbundleBody(body, requestKey, FxAccountUtils.KW("session/create"), keyFetchToken, sessionToken);
-          delegate.handleSuccess(new TwoTokens(keyFetchToken, sessionToken));
-          return;
-        } catch (Exception e) {
-          delegate.handleError(e);
-          return;
-        }
-      }
-    };
-    post(resource, null, delegate);
-  }
-
-  public void sessionDestroy(byte[] sessionToken, final RequestDelegate<Void> delegate) {
-    final byte[] tokenId = new byte[32];
-    final byte[] reqHMACKey = new byte[32];
-    try {
-      HKDF.deriveMany(sessionToken, new byte[0], FxAccountUtils.KW("sessionToken"), tokenId, reqHMACKey);
-    } catch (Exception e) {
-      invokeHandleError(delegate, e);
-      return;
-    }
-
-    BaseResource resource;
-    try {
-      resource = getBaseResource("session/destroy");
-    } catch (URISyntaxException | UnsupportedEncodingException e) {
-      invokeHandleError(delegate, e);
-      return;
-    }
-
-    resource.delegate = new ResourceDelegate<Void>(resource, delegate, tokenId, reqHMACKey) {
-      @Override
-      public void handleSuccess(int status, HttpResponse response, ExtendedJSONObject body) {
-        delegate.handleSuccess(null);
-      }
-    };
-    post(resource, null, delegate);
-  }
-
   /**
    * Don't call this directly. Use <code>unbundleBody</code> instead.
    */
   protected void unbundleBytes(byte[] bundleBytes, byte[] respHMACKey, byte[] respXORKey, byte[]... rest)
       throws InvalidKeyException, NoSuchAlgorithmException, FxAccountClientException {
     if (bundleBytes.length < 32) {
       throw new IllegalArgumentException("input bundle must include HMAC");
     }
@@ -767,93 +692,9 @@ public class FxAccountClient10 {
           delegate.handleError(new FxAccountClientException("cert must be a non-null string"));
           return;
         }
         delegate.handleSuccess(cert);
       }
     };
     post(resource, body, delegate);
   }
-
-  /**
-   * Request a verification link be sent to the account email, given a valid session token.
-   *
-   * @param sessionToken
-   *          to authenticate with.
-   * @param delegate
-   *          to invoke callbacks.
-   */
-  public void resendCode(byte[] sessionToken, final RequestDelegate<Void> delegate) {
-    final byte[] tokenId = new byte[32];
-    final byte[] reqHMACKey = new byte[32];
-    final byte[] requestKey = new byte[32];
-    try {
-      HKDF.deriveMany(sessionToken, new byte[0], FxAccountUtils.KW("sessionToken"), tokenId, reqHMACKey, requestKey);
-    } catch (Exception e) {
-      invokeHandleError(delegate, e);
-      return;
-    }
-
-    BaseResource resource;
-    try {
-      resource = getBaseResource("recovery_email/resend_code");
-    } catch (URISyntaxException | UnsupportedEncodingException e) {
-      invokeHandleError(delegate, e);
-      return;
-    }
-
-    resource.delegate = new ResourceDelegate<Void>(resource, delegate, tokenId, reqHMACKey) {
-      @Override
-      public void handleSuccess(int status, HttpResponse response, ExtendedJSONObject body) {
-        try {
-          delegate.handleSuccess(null);
-          return;
-        } catch (Exception e) {
-          delegate.handleError(e);
-          return;
-        }
-      }
-    };
-    post(resource, new JSONObject(), delegate);
-  }
-
-  /**
-   * Request a fresh unlock code be sent to the account email.
-   * <p>
-   * Since the account can be locked before the device can connect to it, the
-   * only reasonable identifier is the account email. Since the account is
-   * locked out, this request is un-authenticated.
-   *
-   * @param emailUTF8
-   *          identifying account.
-   * @param delegate
-   *          to invoke callbacks.
-   */
-  @SuppressWarnings("unchecked")
-  public void resendUnlockCode(final byte[] emailUTF8, final RequestDelegate<Void> delegate) {
-    final BaseResource resource;
-    final JSONObject body = new JSONObject();
-    try {
-      resource = getBaseResource("account/unlock/resend_code");
-      body.put("email", new String(emailUTF8, "UTF-8"));
-    } catch (URISyntaxException e) {
-      invokeHandleError(delegate, e);
-      return;
-    } catch (UnsupportedEncodingException e) {
-      invokeHandleError(delegate, e);
-      return;
-    }
-
-    resource.delegate = new ResourceDelegate<Void>(resource, delegate) {
-      @Override
-      public void handleSuccess(int status, HttpResponse response, ExtendedJSONObject body) {
-        try {
-          delegate.handleSuccess(null);
-          return;
-        } catch (Exception e) {
-          delegate.handleError(e);
-          return;
-        }
-      }
-    };
-    post(resource, body, delegate);
-  }
 }
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java
@@ -166,38 +166,12 @@ public class MockFxAccountClient impleme
       String certificate = mockMyIdTokenFactory.createMockMyIDCertificate(RSACryptoImplementation.createPublicKey(publicKey), "test", iat, exp);
       requestDelegate.handleSuccess(certificate);
     } catch (Exception e) {
       requestDelegate.handleError(e);
     }
   }
 
   @Override
-  public void resendCode(byte[] sessionToken, RequestDelegate<Void> requestDelegate) {
-    String email = sessionTokens.get(Utils.byte2Hex(sessionToken));
-    User user = users.get(email);
-    if (email == null || user == null) {
-      handleFailure(requestDelegate, HttpStatus.SC_UNAUTHORIZED, FxAccountRemoteError.INVALID_AUTHENTICATION_TOKEN, "invalid sessionToken");
-      return;
-    }
-    requestDelegate.handleSuccess(null);
-  }
-
-  @Override
-  public void resendUnlockCode(byte[] emailUTF8, RequestDelegate<Void> requestDelegate) {
-    User user;
-    try {
-      user = users.get(new String(emailUTF8, "UTF-8"));
-    } catch (UnsupportedEncodingException e) {
-      user = null;
-    }
-    if (user == null) {
-      handleFailure(requestDelegate, HttpStatus.SC_BAD_REQUEST, FxAccountRemoteError.ATTEMPT_TO_ACCESS_AN_ACCOUNT_THAT_DOES_NOT_EXIST, "invalid emailUTF8");
-      return;
-    }
-    requestDelegate.handleSuccess(null);
-  }
-
-  @Override
   public void createAccountAndGetKeys(byte[] emailUTF8, PasswordStretcher passwordStretcher, final Map<String, String> queryParameters, RequestDelegate<LoginResponse> delegate) {
     delegate.handleError(new RuntimeException("Not yet implemented"));
   }
 }