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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial