Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
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/. */
5 package org.mozilla.gecko.background.fxa;
7 import java.io.UnsupportedEncodingException;
8 import java.math.BigInteger;
9 import java.security.NoSuchAlgorithmException;
11 import org.json.simple.JSONObject;
12 import org.mozilla.gecko.background.fxa.FxAccountClient10.CreateDelegate;
13 import org.mozilla.gecko.sync.Utils;
14 import org.mozilla.gecko.sync.net.SRPConstants;
16 public class FxAccount10CreateDelegate implements CreateDelegate {
17 protected final String email;
18 protected final String mainSalt;
19 protected final String srpSalt;
20 protected final BigInteger v;
22 public FxAccount10CreateDelegate(String email, byte[] stretchedPWBytes, String mainSalt, String srpSalt) throws NoSuchAlgorithmException, UnsupportedEncodingException {
23 this.email = email;
24 this.mainSalt = mainSalt;
25 this.srpSalt = srpSalt;
26 byte[] srpSaltBytes = Utils.hex2Byte(srpSalt, FxAccountUtils.SALT_LENGTH_BYTES);
27 this.v = FxAccountUtils.srpVerifierLowercaseV(email.getBytes("UTF-8"), stretchedPWBytes, srpSaltBytes, SRPConstants._2048.g, SRPConstants._2048.N);
28 }
30 @SuppressWarnings("unchecked")
31 @Override
32 public JSONObject getCreateBody() throws FxAccountClientException {
33 final JSONObject body = new JSONObject();
34 try {
35 body.put("email", FxAccountUtils.bytes(email));
36 } catch (UnsupportedEncodingException e) {
37 throw new FxAccountClientException(e);
38 }
40 final JSONObject stretching = new JSONObject();
41 stretching.put("type", "PBKDF2/scrypt/PBKDF2/v1");
42 stretching.put("PBKDF2_rounds_1", 20000);
43 stretching.put("scrypt_N", 65536);
44 stretching.put("scrypt_r", 8);
45 stretching.put("scrypt_p", 1);
46 stretching.put("PBKDF2_rounds_2", 20000);
47 stretching.put("salt", mainSalt);
48 body.put("passwordStretching", stretching);
50 final JSONObject srp = new JSONObject();
51 srp.put("type", "SRP-6a/SHA256/2048/v1");
52 srp.put("verifier", FxAccountUtils.hexModN(v, SRPConstants._2048.N));
53 srp.put("salt", srpSalt);
54 body.put("srp", srp);
55 return body;
56 }
57 }