|
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.background.fxa; |
|
6 |
|
7 import java.io.UnsupportedEncodingException; |
|
8 import java.security.GeneralSecurityException; |
|
9 |
|
10 import org.json.simple.JSONObject; |
|
11 import org.mozilla.gecko.background.fxa.FxAccountClient10.CreateDelegate; |
|
12 import org.mozilla.gecko.sync.Utils; |
|
13 |
|
14 /** |
|
15 * An abstraction around providing an email and authorization token to the auth |
|
16 * server. |
|
17 */ |
|
18 public class FxAccount20LoginDelegate implements CreateDelegate { |
|
19 protected final byte[] emailUTF8; |
|
20 protected final byte[] authPW; |
|
21 |
|
22 public FxAccount20LoginDelegate(byte[] emailUTF8, byte[] quickStretchedPW) throws UnsupportedEncodingException, GeneralSecurityException { |
|
23 this.emailUTF8 = emailUTF8; |
|
24 this.authPW = FxAccountUtils.generateAuthPW(quickStretchedPW); |
|
25 } |
|
26 |
|
27 @SuppressWarnings("unchecked") |
|
28 @Override |
|
29 public JSONObject getCreateBody() throws FxAccountClientException { |
|
30 final JSONObject body = new JSONObject(); |
|
31 try { |
|
32 body.put("email", new String(emailUTF8, "UTF-8")); |
|
33 body.put("authPW", Utils.byte2Hex(authPW)); |
|
34 return body; |
|
35 } catch (UnsupportedEncodingException e) { |
|
36 throw new FxAccountClientException(e); |
|
37 } |
|
38 } |
|
39 } |