1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/fxa/login/Cohabiting.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,46 @@ 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.fxa.login; 1.9 + 1.10 +import org.mozilla.gecko.browserid.BrowserIDKeyPair; 1.11 +import org.mozilla.gecko.browserid.JSONWebTokenUtils; 1.12 +import org.mozilla.gecko.fxa.FxAccountConstants; 1.13 +import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine.ExecuteDelegate; 1.14 +import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.LogMessage; 1.15 +import org.mozilla.gecko.sync.ExtendedJSONObject; 1.16 + 1.17 +public class Cohabiting extends TokensAndKeysState { 1.18 + private static final String LOG_TAG = Cohabiting.class.getSimpleName(); 1.19 + 1.20 + public Cohabiting(String email, String uid, byte[] sessionToken, byte[] kA, byte[] kB, BrowserIDKeyPair keyPair) { 1.21 + super(StateLabel.Cohabiting, email, uid, sessionToken, kA, kB, keyPair); 1.22 + } 1.23 + 1.24 + @Override 1.25 + public void execute(final ExecuteDelegate delegate) { 1.26 + delegate.getClient().sign(sessionToken, keyPair.getPublic().toJSONObject(), delegate.getCertificateDurationInMilliseconds(), 1.27 + new BaseRequestDelegate<String>(this, delegate) { 1.28 + @Override 1.29 + public void handleSuccess(String certificate) { 1.30 + if (FxAccountConstants.LOG_PERSONAL_INFORMATION) { 1.31 + try { 1.32 + FxAccountConstants.pii(LOG_TAG, "Fetched certificate: " + certificate); 1.33 + ExtendedJSONObject c = JSONWebTokenUtils.parseCertificate(certificate); 1.34 + if (c != null) { 1.35 + FxAccountConstants.pii(LOG_TAG, "Header : " + c.getObject("header")); 1.36 + FxAccountConstants.pii(LOG_TAG, "Payload : " + c.getObject("payload")); 1.37 + FxAccountConstants.pii(LOG_TAG, "Signature: " + c.getString("signature")); 1.38 + } else { 1.39 + FxAccountConstants.pii(LOG_TAG, "Could not parse certificate!"); 1.40 + } 1.41 + } catch (Exception e) { 1.42 + FxAccountConstants.pii(LOG_TAG, "Could not parse certificate!"); 1.43 + } 1.44 + } 1.45 + delegate.handleTransition(new LogMessage("sign succeeded"), new Married(email, uid, sessionToken, kA, kB, keyPair, certificate)); 1.46 + } 1.47 + }); 1.48 + } 1.49 +}