mirror of
https://github.com/etesync/android
synced 2024-12-23 15:18:14 +00:00
AccountSettings: Add a keypair setting.
This is used for storing the asymmetric key pair.
This commit is contained in:
parent
ae08510729
commit
43803b6d3e
@ -21,6 +21,9 @@ import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.etesync.syncadapter.journalmanager.Crypto;
|
||||
import com.etesync.syncadapter.utils.Base64;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@ -36,6 +39,8 @@ public class AccountSettings {
|
||||
KEY_URI = "uri",
|
||||
KEY_USERNAME = "user_name",
|
||||
KEY_TOKEN = "auth_token",
|
||||
KEY_ASYMMETRIC_PRIVATE_KEY = "asymmetric_private_key",
|
||||
KEY_ASYMMETRIC_PUBLIC_KEY = "asymmetric_public_key",
|
||||
KEY_WIFI_ONLY = "wifi_only", // sync on WiFi only (default: false)
|
||||
KEY_WIFI_ONLY_SSID = "wifi_only_ssid"; // restrict sync to specific WiFi SSID
|
||||
|
||||
@ -122,6 +127,23 @@ public class AccountSettings {
|
||||
accountManager.setUserData(account, KEY_TOKEN, token);
|
||||
}
|
||||
|
||||
|
||||
public Crypto.AsymmetricKeyPair getKeyPair() {
|
||||
if (accountManager.getUserData(account, KEY_ASYMMETRIC_PUBLIC_KEY) != null) {
|
||||
byte[] pubkey = Base64.decode(accountManager.getUserData(account, KEY_ASYMMETRIC_PUBLIC_KEY), Base64.NO_WRAP);
|
||||
byte[] privkey = Base64.decode(accountManager.getUserData(account, KEY_ASYMMETRIC_PRIVATE_KEY), Base64.NO_WRAP);
|
||||
|
||||
return new Crypto.AsymmetricKeyPair(privkey, pubkey);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setKeyPair(@NonNull Crypto.AsymmetricKeyPair keyPair) {
|
||||
accountManager.setUserData(account, KEY_ASYMMETRIC_PUBLIC_KEY, Base64.encodeToString(keyPair.getPublicKey(), Base64.NO_WRAP));
|
||||
accountManager.setUserData(account, KEY_ASYMMETRIC_PRIVATE_KEY, Base64.encodeToString(keyPair.getPrivateKey(), Base64.NO_WRAP));
|
||||
}
|
||||
|
||||
public String username() {
|
||||
return accountManager.getUserData(account, KEY_USERNAME);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user