mobile/android/base/background/fxa/FxAccount20CreateDelegate.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/background/fxa/FxAccount20CreateDelegate.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,55 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +package org.mozilla.gecko.background.fxa;
     1.9 +
    1.10 +import java.io.UnsupportedEncodingException;
    1.11 +import java.security.GeneralSecurityException;
    1.12 +
    1.13 +import org.json.simple.JSONObject;
    1.14 +import org.mozilla.gecko.background.fxa.FxAccountClient10.CreateDelegate;
    1.15 +import org.mozilla.gecko.sync.Utils;
    1.16 +
    1.17 +public class FxAccount20CreateDelegate implements CreateDelegate {
    1.18 +  protected final byte[] emailUTF8;
    1.19 +  protected final byte[] authPW;
    1.20 +  protected final boolean preVerified;
    1.21 +
    1.22 +  /**
    1.23 +   * Make a new "create account" delegate.
    1.24 +   *
    1.25 +   * @param emailUTF8
    1.26 +   *          email as UTF-8 bytes.
    1.27 +   * @param quickStretchedPW
    1.28 +   *          quick stretched password as bytes.
    1.29 +   * @param preVerified
    1.30 +   *          true if account should be marked already verified; only effective
    1.31 +   *          for non-production auth servers.
    1.32 +   * @throws UnsupportedEncodingException
    1.33 +   * @throws GeneralSecurityException
    1.34 +   */
    1.35 +  public FxAccount20CreateDelegate(byte[] emailUTF8, byte[] quickStretchedPW, boolean preVerified) throws UnsupportedEncodingException, GeneralSecurityException {
    1.36 +    this.emailUTF8 = emailUTF8;
    1.37 +    this.authPW = FxAccountUtils.generateAuthPW(quickStretchedPW);
    1.38 +    this.preVerified = preVerified;
    1.39 +  }
    1.40 +
    1.41 +  @SuppressWarnings("unchecked")
    1.42 +  @Override
    1.43 +  public JSONObject getCreateBody() throws FxAccountClientException {
    1.44 +    final JSONObject body = new JSONObject();
    1.45 +    try {
    1.46 +      body.put("email", new String(emailUTF8, "UTF-8"));
    1.47 +      body.put("authPW", Utils.byte2Hex(authPW));
    1.48 +      if (preVerified) {
    1.49 +        // Production endpoints do not allow preVerified; this assumes we only
    1.50 +        // set it when it's okay to send it.
    1.51 +        body.put("preVerified", preVerified);
    1.52 +      }
    1.53 +      return body;
    1.54 +    } catch (UnsupportedEncodingException e) {
    1.55 +      throw new FxAccountClientException(e);
    1.56 +    }
    1.57 +  }
    1.58 +}

mercurial