mobile/android/base/background/fxa/FxAccount10CreateDelegate.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 package org.mozilla.gecko.background.fxa;
michael@0 6
michael@0 7 import java.io.UnsupportedEncodingException;
michael@0 8 import java.math.BigInteger;
michael@0 9 import java.security.NoSuchAlgorithmException;
michael@0 10
michael@0 11 import org.json.simple.JSONObject;
michael@0 12 import org.mozilla.gecko.background.fxa.FxAccountClient10.CreateDelegate;
michael@0 13 import org.mozilla.gecko.sync.Utils;
michael@0 14 import org.mozilla.gecko.sync.net.SRPConstants;
michael@0 15
michael@0 16 public class FxAccount10CreateDelegate implements CreateDelegate {
michael@0 17 protected final String email;
michael@0 18 protected final String mainSalt;
michael@0 19 protected final String srpSalt;
michael@0 20 protected final BigInteger v;
michael@0 21
michael@0 22 public FxAccount10CreateDelegate(String email, byte[] stretchedPWBytes, String mainSalt, String srpSalt) throws NoSuchAlgorithmException, UnsupportedEncodingException {
michael@0 23 this.email = email;
michael@0 24 this.mainSalt = mainSalt;
michael@0 25 this.srpSalt = srpSalt;
michael@0 26 byte[] srpSaltBytes = Utils.hex2Byte(srpSalt, FxAccountUtils.SALT_LENGTH_BYTES);
michael@0 27 this.v = FxAccountUtils.srpVerifierLowercaseV(email.getBytes("UTF-8"), stretchedPWBytes, srpSaltBytes, SRPConstants._2048.g, SRPConstants._2048.N);
michael@0 28 }
michael@0 29
michael@0 30 @SuppressWarnings("unchecked")
michael@0 31 @Override
michael@0 32 public JSONObject getCreateBody() throws FxAccountClientException {
michael@0 33 final JSONObject body = new JSONObject();
michael@0 34 try {
michael@0 35 body.put("email", FxAccountUtils.bytes(email));
michael@0 36 } catch (UnsupportedEncodingException e) {
michael@0 37 throw new FxAccountClientException(e);
michael@0 38 }
michael@0 39
michael@0 40 final JSONObject stretching = new JSONObject();
michael@0 41 stretching.put("type", "PBKDF2/scrypt/PBKDF2/v1");
michael@0 42 stretching.put("PBKDF2_rounds_1", 20000);
michael@0 43 stretching.put("scrypt_N", 65536);
michael@0 44 stretching.put("scrypt_r", 8);
michael@0 45 stretching.put("scrypt_p", 1);
michael@0 46 stretching.put("PBKDF2_rounds_2", 20000);
michael@0 47 stretching.put("salt", mainSalt);
michael@0 48 body.put("passwordStretching", stretching);
michael@0 49
michael@0 50 final JSONObject srp = new JSONObject();
michael@0 51 srp.put("type", "SRP-6a/SHA256/2048/v1");
michael@0 52 srp.put("verifier", FxAccountUtils.hexModN(v, SRPConstants._2048.N));
michael@0 53 srp.put("salt", srpSalt);
michael@0 54 body.put("srp", srp);
michael@0 55 return body;
michael@0 56 }
michael@0 57 }

mercurial