michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.fxa.login; michael@0: michael@0: import org.mozilla.gecko.browserid.BrowserIDKeyPair; michael@0: import org.mozilla.gecko.browserid.JSONWebTokenUtils; michael@0: import org.mozilla.gecko.fxa.FxAccountConstants; michael@0: import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine.ExecuteDelegate; michael@0: import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.LogMessage; michael@0: import org.mozilla.gecko.sync.ExtendedJSONObject; michael@0: michael@0: public class Cohabiting extends TokensAndKeysState { michael@0: private static final String LOG_TAG = Cohabiting.class.getSimpleName(); michael@0: michael@0: public Cohabiting(String email, String uid, byte[] sessionToken, byte[] kA, byte[] kB, BrowserIDKeyPair keyPair) { michael@0: super(StateLabel.Cohabiting, email, uid, sessionToken, kA, kB, keyPair); michael@0: } michael@0: michael@0: @Override michael@0: public void execute(final ExecuteDelegate delegate) { michael@0: delegate.getClient().sign(sessionToken, keyPair.getPublic().toJSONObject(), delegate.getCertificateDurationInMilliseconds(), michael@0: new BaseRequestDelegate(this, delegate) { michael@0: @Override michael@0: public void handleSuccess(String certificate) { michael@0: if (FxAccountConstants.LOG_PERSONAL_INFORMATION) { michael@0: try { michael@0: FxAccountConstants.pii(LOG_TAG, "Fetched certificate: " + certificate); michael@0: ExtendedJSONObject c = JSONWebTokenUtils.parseCertificate(certificate); michael@0: if (c != null) { michael@0: FxAccountConstants.pii(LOG_TAG, "Header : " + c.getObject("header")); michael@0: FxAccountConstants.pii(LOG_TAG, "Payload : " + c.getObject("payload")); michael@0: FxAccountConstants.pii(LOG_TAG, "Signature: " + c.getString("signature")); michael@0: } else { michael@0: FxAccountConstants.pii(LOG_TAG, "Could not parse certificate!"); michael@0: } michael@0: } catch (Exception e) { michael@0: FxAccountConstants.pii(LOG_TAG, "Could not parse certificate!"); michael@0: } michael@0: } michael@0: delegate.handleTransition(new LogMessage("sign succeeded"), new Married(email, uid, sessionToken, kA, kB, keyPair, certificate)); michael@0: } michael@0: }); michael@0: } michael@0: }