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/. */ 4 5 package org.mozilla.gecko.fxa.login; 6 7 import org.mozilla.gecko.browserid.BrowserIDKeyPair; 8 import org.mozilla.gecko.sync.ExtendedJSONObject; 9 import org.mozilla.gecko.sync.Utils; 10 11 public abstract class TokensAndKeysState extends State { 12 protected final byte[] sessionToken; 13 protected final byte[] kA; 14 protected final byte[] kB; 15 protected final BrowserIDKeyPair keyPair; 16 TokensAndKeysState(StateLabel stateLabel, String email, String uid, byte[] sessionToken, byte[] kA, byte[] kB, BrowserIDKeyPair keyPair)17 public TokensAndKeysState(StateLabel stateLabel, String email, String uid, byte[] sessionToken, byte[] kA, byte[] kB, BrowserIDKeyPair keyPair) { 18 super(stateLabel, email, uid, true); 19 Utils.throwIfNull(sessionToken, kA, kB, keyPair); 20 this.sessionToken = sessionToken; 21 this.kA = kA; 22 this.kB = kB; 23 this.keyPair = keyPair; 24 } 25 26 @Override toJSONObject()27 public ExtendedJSONObject toJSONObject() { 28 ExtendedJSONObject o = super.toJSONObject(); 29 // Fields are non-null by constructor. 30 o.put("sessionToken", Utils.byte2Hex(sessionToken)); 31 o.put("kA", Utils.byte2Hex(kA)); 32 o.put("kB", Utils.byte2Hex(kB)); 33 o.put("keyPair", keyPair.toJSONObject()); 34 return o; 35 } 36 getSessionToken()37 public byte[] getSessionToken() { 38 return sessionToken; 39 } 40 41 @Override getNeededAction()42 public Action getNeededAction() { 43 return Action.None; 44 } 45 } 46