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

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 package org.mozilla.gecko.background.fxa;
     7 import java.io.UnsupportedEncodingException;
     8 import java.security.GeneralSecurityException;
    10 import org.json.simple.JSONObject;
    11 import org.mozilla.gecko.background.fxa.FxAccountClient10.CreateDelegate;
    12 import org.mozilla.gecko.sync.Utils;
    14 public class FxAccount20CreateDelegate implements CreateDelegate {
    15   protected final byte[] emailUTF8;
    16   protected final byte[] authPW;
    17   protected final boolean preVerified;
    19   /**
    20    * Make a new "create account" delegate.
    21    *
    22    * @param emailUTF8
    23    *          email as UTF-8 bytes.
    24    * @param quickStretchedPW
    25    *          quick stretched password as bytes.
    26    * @param preVerified
    27    *          true if account should be marked already verified; only effective
    28    *          for non-production auth servers.
    29    * @throws UnsupportedEncodingException
    30    * @throws GeneralSecurityException
    31    */
    32   public FxAccount20CreateDelegate(byte[] emailUTF8, byte[] quickStretchedPW, boolean preVerified) throws UnsupportedEncodingException, GeneralSecurityException {
    33     this.emailUTF8 = emailUTF8;
    34     this.authPW = FxAccountUtils.generateAuthPW(quickStretchedPW);
    35     this.preVerified = preVerified;
    36   }
    38   @SuppressWarnings("unchecked")
    39   @Override
    40   public JSONObject getCreateBody() throws FxAccountClientException {
    41     final JSONObject body = new JSONObject();
    42     try {
    43       body.put("email", new String(emailUTF8, "UTF-8"));
    44       body.put("authPW", Utils.byte2Hex(authPW));
    45       if (preVerified) {
    46         // Production endpoints do not allow preVerified; this assumes we only
    47         // set it when it's okay to send it.
    48         body.put("preVerified", preVerified);
    49       }
    50       return body;
    51     } catch (UnsupportedEncodingException e) {
    52       throw new FxAccountClientException(e);
    53     }
    54   }
    55 }

mercurial