Bug 724328 - misc Sync cleaning.

This commit is contained in:
Richard Newman 2012-02-15 22:05:52 -08:00
parent fe7de3f087
commit 5edc5fc33d
10 changed files with 20 additions and 27 deletions

View File

@ -58,7 +58,6 @@ import org.mozilla.gecko.sync.net.SyncStorageRecordRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequest;
import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate;
import org.mozilla.gecko.sync.net.SyncStorageResponse;
import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
import org.mozilla.gecko.sync.stage.AndroidBrowserBookmarksServerSyncStage;
import org.mozilla.gecko.sync.stage.AndroidBrowserHistoryServerSyncStage;
import org.mozilla.gecko.sync.stage.CheckPreconditionsStage;
@ -71,12 +70,11 @@ import org.mozilla.gecko.sync.stage.GlobalSyncStage;
import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage;
import org.mozilla.gecko.sync.stage.NoSuchStageException;
import ch.boye.httpclientandroidlib.HttpResponse;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import ch.boye.httpclientandroidlib.HttpResponse;
public class GlobalSession implements CredentialsSource, PrefsSource {
private static final String LOG_TAG = "GlobalSession";

View File

@ -39,7 +39,6 @@ package org.mozilla.gecko.sync;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
import org.json.simple.parser.ParseException;
@ -48,7 +47,6 @@ import org.mozilla.gecko.sync.repositories.RepositorySessionBundle;
import android.os.Bundle;
public class SynchronizerConfigurations {
private static final int CONFIGURATION_VERSION = 1;
private HashMap<String, SynchronizerConfiguration> engines;
protected HashMap<String, SynchronizerConfiguration> enginesMapFromBundleV1(Bundle engineBundle) throws IOException, ParseException, NonObjectJSONException {

View File

@ -41,13 +41,13 @@ package org.mozilla.gecko.sync;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.HashMap;
import org.mozilla.apache.commons.codec.binary.Base32;
import org.mozilla.apache.commons.codec.binary.Base64;
import org.mozilla.gecko.sync.crypto.Cryptographer;
import android.content.Context;
import android.content.SharedPreferences;
@ -211,10 +211,20 @@ public class Utils {
return (long)(decimal * 1000);
}
public static byte[] sha1(String utf8)
throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
return sha1.digest(utf8.getBytes("UTF-8"));
}
public static String sha1Base32(String utf8)
throws NoSuchAlgorithmException, UnsupportedEncodingException {
return new Base32().encodeAsString(sha1(utf8)).toLowerCase();
}
public static String getPrefsPath(String username, String serverURL)
throws NoSuchAlgorithmException, UnsupportedEncodingException {
return "sync.prefs." + Cryptographer.sha1Base32(serverURL + ":" + username);
return "sync.prefs." + sha1Base32(serverURL + ":" + username);
}
public static SharedPreferences getSharedPreferences(Context context, String username, String serverURL) throws NoSuchAlgorithmException, UnsupportedEncodingException {

View File

@ -38,9 +38,8 @@
package org.mozilla.gecko.sync.crypto;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
@ -53,10 +52,8 @@ import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.mozilla.apache.commons.codec.binary.Base32;
import org.mozilla.apache.commons.codec.binary.Base64;
import org.mozilla.gecko.sync.Utils;
import java.security.InvalidKeyException;
/*
* Implements the basic required cryptography options.
@ -222,13 +219,4 @@ public class Cryptographer {
Mac hmacHasher = HKDF.makeHMACHasher(bundle.getKeys().getHMACKey());
return hmacHasher.doFinal(Base64.encodeBase64(bundle.getMessage()));
}
public static byte[] sha1(String utf8) throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
return sha1.digest(utf8.getBytes("UTF-8"));
}
public static String sha1Base32(String utf8) throws NoSuchAlgorithmException, UnsupportedEncodingException {
return new Base32().encodeAsString(sha1(utf8)).toLowerCase();
}
}

View File

@ -75,7 +75,7 @@ public class KeyBundle {
if (account.matches("^[A-Za-z0-9._-]+$")) {
return account;
}
return Cryptographer.sha1Base32(account);
return Utils.sha1Base32(account);
}
// If we encounter characters not allowed by the API (as found for

View File

@ -44,7 +44,8 @@ import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
import java.util.Random;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Timer;
import java.util.TimerTask;
@ -75,8 +76,6 @@ import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase;
import ch.boye.httpclientandroidlib.entity.StringEntity;
import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient;
import ch.boye.httpclientandroidlib.message.BasicHeader;
import java.security.NoSuchAlgorithmException;
import java.security.InvalidKeyException;
public class JPakeClient implements JPakeRequestDelegate {
private static String LOG_TAG = "JPakeClient";
@ -107,6 +106,7 @@ public class JPakeClient implements JPakeRequestDelegate {
private String myEtag;
private String mySignerId;
@SuppressWarnings("unused")
private String theirEtag;
private String theirSignerId;
private String jpakeServer;

View File

@ -43,7 +43,6 @@ import java.util.HashMap;
import org.json.simple.JSONArray;
import org.mozilla.gecko.sync.Logger;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.repositories.BookmarkNeedsReparentingException;
import org.mozilla.gecko.sync.repositories.NoGuidForIdException;
import org.mozilla.gecko.sync.repositories.NullCursorException;
import org.mozilla.gecko.sync.repositories.ParentNotFoundException;

View File

@ -274,6 +274,7 @@ public class AccountActivity extends AccountAuthenticatorActivity {
return intent;
}
@SuppressWarnings("unused")
private void authFailure() {
enableCredEntry(true);
Intent intent = new Intent(mContext, SetupFailureActivity.class);

View File

@ -49,6 +49,7 @@ import android.view.View;
import android.widget.TextView;
public class SetupSuccessActivity extends Activity {
@SuppressWarnings("unused")
private final static String LOG_TAG = "SetupSuccessActivity";
private TextView setupSubtitle;
private Context mContext;

View File

@ -39,7 +39,6 @@
package org.mozilla.gecko.sync.syncadapter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.TimeUnit;
@ -51,7 +50,6 @@ import org.mozilla.gecko.sync.SyncConfiguration;
import org.mozilla.gecko.sync.SyncConfigurationException;
import org.mozilla.gecko.sync.SyncException;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.crypto.Cryptographer;
import org.mozilla.gecko.sync.crypto.KeyBundle;
import org.mozilla.gecko.sync.delegates.GlobalSessionCallback;
import org.mozilla.gecko.sync.setup.Constants;