1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/background/fxa/FxAccount10CreateDelegate.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 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.background.fxa; 1.9 + 1.10 +import java.io.UnsupportedEncodingException; 1.11 +import java.math.BigInteger; 1.12 +import java.security.NoSuchAlgorithmException; 1.13 + 1.14 +import org.json.simple.JSONObject; 1.15 +import org.mozilla.gecko.background.fxa.FxAccountClient10.CreateDelegate; 1.16 +import org.mozilla.gecko.sync.Utils; 1.17 +import org.mozilla.gecko.sync.net.SRPConstants; 1.18 + 1.19 +public class FxAccount10CreateDelegate implements CreateDelegate { 1.20 + protected final String email; 1.21 + protected final String mainSalt; 1.22 + protected final String srpSalt; 1.23 + protected final BigInteger v; 1.24 + 1.25 + public FxAccount10CreateDelegate(String email, byte[] stretchedPWBytes, String mainSalt, String srpSalt) throws NoSuchAlgorithmException, UnsupportedEncodingException { 1.26 + this.email = email; 1.27 + this.mainSalt = mainSalt; 1.28 + this.srpSalt = srpSalt; 1.29 + byte[] srpSaltBytes = Utils.hex2Byte(srpSalt, FxAccountUtils.SALT_LENGTH_BYTES); 1.30 + this.v = FxAccountUtils.srpVerifierLowercaseV(email.getBytes("UTF-8"), stretchedPWBytes, srpSaltBytes, SRPConstants._2048.g, SRPConstants._2048.N); 1.31 + } 1.32 + 1.33 + @SuppressWarnings("unchecked") 1.34 + @Override 1.35 + public JSONObject getCreateBody() throws FxAccountClientException { 1.36 + final JSONObject body = new JSONObject(); 1.37 + try { 1.38 + body.put("email", FxAccountUtils.bytes(email)); 1.39 + } catch (UnsupportedEncodingException e) { 1.40 + throw new FxAccountClientException(e); 1.41 + } 1.42 + 1.43 + final JSONObject stretching = new JSONObject(); 1.44 + stretching.put("type", "PBKDF2/scrypt/PBKDF2/v1"); 1.45 + stretching.put("PBKDF2_rounds_1", 20000); 1.46 + stretching.put("scrypt_N", 65536); 1.47 + stretching.put("scrypt_r", 8); 1.48 + stretching.put("scrypt_p", 1); 1.49 + stretching.put("PBKDF2_rounds_2", 20000); 1.50 + stretching.put("salt", mainSalt); 1.51 + body.put("passwordStretching", stretching); 1.52 + 1.53 + final JSONObject srp = new JSONObject(); 1.54 + srp.put("type", "SRP-6a/SHA256/2048/v1"); 1.55 + srp.put("verifier", FxAccountUtils.hexModN(v, SRPConstants._2048.N)); 1.56 + srp.put("salt", srpSalt); 1.57 + body.put("srp", srp); 1.58 + return body; 1.59 + } 1.60 +}