mobile/android/base/fxa/login/Engaged.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.fxa.login;
michael@0 6
michael@0 7 import java.security.NoSuchAlgorithmException;
michael@0 8
michael@0 9 import org.mozilla.gecko.background.fxa.FxAccountClient10.TwoKeys;
michael@0 10 import org.mozilla.gecko.background.fxa.FxAccountUtils;
michael@0 11 import org.mozilla.gecko.browserid.BrowserIDKeyPair;
michael@0 12 import org.mozilla.gecko.fxa.FxAccountConstants;
michael@0 13 import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine.ExecuteDelegate;
michael@0 14 import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.AccountVerified;
michael@0 15 import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.LocalError;
michael@0 16 import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.LogMessage;
michael@0 17 import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.RemoteError;
michael@0 18 import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.Transition;
michael@0 19 import org.mozilla.gecko.sync.ExtendedJSONObject;
michael@0 20 import org.mozilla.gecko.sync.Utils;
michael@0 21
michael@0 22 public class Engaged extends State {
michael@0 23 private static final String LOG_TAG = Engaged.class.getSimpleName();
michael@0 24
michael@0 25 protected final byte[] sessionToken;
michael@0 26 protected final byte[] keyFetchToken;
michael@0 27 protected final byte[] unwrapkB;
michael@0 28
michael@0 29 public Engaged(String email, String uid, boolean verified, byte[] unwrapkB, byte[] sessionToken, byte[] keyFetchToken) {
michael@0 30 super(StateLabel.Engaged, email, uid, verified);
michael@0 31 Utils.throwIfNull(unwrapkB, sessionToken, keyFetchToken);
michael@0 32 this.unwrapkB = unwrapkB;
michael@0 33 this.sessionToken = sessionToken;
michael@0 34 this.keyFetchToken = keyFetchToken;
michael@0 35 }
michael@0 36
michael@0 37 @Override
michael@0 38 public ExtendedJSONObject toJSONObject() {
michael@0 39 ExtendedJSONObject o = super.toJSONObject();
michael@0 40 // Fields are non-null by constructor.
michael@0 41 o.put("unwrapkB", Utils.byte2Hex(unwrapkB));
michael@0 42 o.put("sessionToken", Utils.byte2Hex(sessionToken));
michael@0 43 o.put("keyFetchToken", Utils.byte2Hex(keyFetchToken));
michael@0 44 return o;
michael@0 45 }
michael@0 46
michael@0 47 @Override
michael@0 48 public void execute(final ExecuteDelegate delegate) {
michael@0 49 BrowserIDKeyPair theKeyPair;
michael@0 50 try {
michael@0 51 theKeyPair = delegate.generateKeyPair();
michael@0 52 } catch (NoSuchAlgorithmException e) {
michael@0 53 delegate.handleTransition(new LocalError(e), new Doghouse(email, uid, verified));
michael@0 54 return;
michael@0 55 }
michael@0 56 final BrowserIDKeyPair keyPair = theKeyPair;
michael@0 57
michael@0 58 delegate.getClient().keys(keyFetchToken, new BaseRequestDelegate<TwoKeys>(this, delegate) {
michael@0 59 @Override
michael@0 60 public void handleSuccess(TwoKeys result) {
michael@0 61 byte[] kB;
michael@0 62 try {
michael@0 63 kB = FxAccountUtils.unwrapkB(unwrapkB, result.wrapkB);
michael@0 64 if (FxAccountConstants.LOG_PERSONAL_INFORMATION) {
michael@0 65 FxAccountConstants.pii(LOG_TAG, "Fetched kA: " + Utils.byte2Hex(result.kA));
michael@0 66 FxAccountConstants.pii(LOG_TAG, "And wrapkB: " + Utils.byte2Hex(result.wrapkB));
michael@0 67 FxAccountConstants.pii(LOG_TAG, "Giving kB : " + Utils.byte2Hex(kB));
michael@0 68 }
michael@0 69 } catch (Exception e) {
michael@0 70 delegate.handleTransition(new RemoteError(e), new Separated(email, uid, verified));
michael@0 71 return;
michael@0 72 }
michael@0 73 Transition transition = verified
michael@0 74 ? new LogMessage("keys succeeded")
michael@0 75 : new AccountVerified();
michael@0 76 delegate.handleTransition(transition, new Cohabiting(email, uid, sessionToken, result.kA, kB, keyPair));
michael@0 77 }
michael@0 78 });
michael@0 79 }
michael@0 80
michael@0 81 @Override
michael@0 82 public Action getNeededAction() {
michael@0 83 if (!verified) {
michael@0 84 return Action.NeedsVerification;
michael@0 85 }
michael@0 86 return Action.None;
michael@0 87 }
michael@0 88
michael@0 89 public byte[] getSessionToken() {
michael@0 90 return sessionToken;
michael@0 91 }
michael@0 92 }

mercurial