-
-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
keychain/android: let client app access keychain from native code
This change extracts the Keychain related code into separate class which to be used by the client apps which would like to access it from the native side.
- Loading branch information
Showing
8 changed files
with
320 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.oblador.keychain; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
import com.oblador.keychain.exceptions.CryptoFailedException; | ||
import com.oblador.keychain.exceptions.EmptyParameterException; | ||
import com.oblador.keychain.exceptions.KeyStoreAccessException; | ||
|
||
/** | ||
* Keychain is an Keychain module which abstracts an encrypted the keychain related lookups and updates. | ||
* <p/> | ||
* <p> | ||
* The flow is the following: | ||
* <pre> | ||
* setGenericPassword(service1, "user1", "pass1") -> get service1 keys -> encrypt user/pass -> store user/pass. | ||
* </pre> | ||
* | ||
* @author Miroslav Genov <[email protected]> | ||
*/ | ||
public interface Keychain { | ||
/** | ||
* Gets the SecurityLevel of the Keychain, e.g software, hardware and etc. | ||
* @return the security level | ||
*/ | ||
SecurityLevel getSecurityLevel(); | ||
|
||
/** | ||
* Gets the {@link ServiceCredentials} associated with the provided service | ||
* | ||
* @param service the service to which credentials are associated | ||
* @return the service credentials associated with the provided service | ||
* @throws CryptoFailedException in case of crypto failure | ||
* @throws KeyStoreAccessException in case of error during accessing the keystore | ||
*/ | ||
@Nullable | ||
ServiceCredentials getGenericPasswordForOptions(String service) throws CryptoFailedException, KeyStoreAccessException; | ||
|
||
/** | ||
* Checks whether the provided credentials exists. | ||
* @param server the service id | ||
* @return true if credentials exists and false in other case | ||
*/ | ||
boolean hasInternetCredentialsForServer(@NonNull String server); | ||
|
||
/** | ||
* Sets new credentials of the provided service | ||
* @param service the name of the service | ||
* @param username the username value | ||
* @param password the password value | ||
* @param minimumSecurityLevel the minimum security level | ||
* @throws EmptyParameterException is password is empty | ||
* @throws CryptoFailedException in case of crypto failure | ||
*/ | ||
void setGenericPasswordForOptions(String service, String username, String password, String minimumSecurityLevel) throws EmptyParameterException, CryptoFailedException; | ||
|
||
/** | ||
* Resets credentials of a given service. | ||
* | ||
* @param service the service of which credentials to be reset | ||
* @throws KeyStoreAccessException in case of keystore access error | ||
*/ | ||
void resetGenericPasswordForOptions(String service) throws KeyStoreAccessException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.oblador.keychain; | ||
|
||
import android.content.Context; | ||
|
||
import com.oblador.keychain.cipherStorage.CipherStorage; | ||
import com.oblador.keychain.cipherStorage.CipherStorageFacebookConceal; | ||
import com.oblador.keychain.cipherStorage.CipherStorageKeystoreAESCBC; | ||
|
||
import java.util.LinkedHashMap; | ||
|
||
/** | ||
* Keychains is a factory class used to create Keychain objects used for storing of secrets. | ||
* | ||
* @author Miroslav Genov <[email protected]> | ||
*/ | ||
public final class Keychains { | ||
|
||
/** | ||
* Creates a new {@link Keychain} instance that is using shared preferences as storage. | ||
* | ||
* @param context the android context | ||
* @return the newly created Keychain instance | ||
*/ | ||
public static Keychain create(Context context) { | ||
final CipherStorage facebookConcealCipherStorage = new CipherStorageFacebookConceal(context); | ||
final CipherStorage keystoreCipherStorage = new CipherStorageKeystoreAESCBC(); | ||
|
||
return new SharedRefKeychain(context, new LinkedHashMap<String, CipherStorage>() {{ | ||
put(facebookConcealCipherStorage.getCipherStorageName(), facebookConcealCipherStorage); | ||
put(keystoreCipherStorage.getCipherStorageName(), keystoreCipherStorage); | ||
}}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.