-
-
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
288 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,32 @@ | ||
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]> | ||
*/ | ||
interface Keychain { | ||
SecurityLevel getSecurityLevel(); | ||
|
||
@Nullable | ||
ServiceCredentials getGenericPasswordForOptions(String service) throws CryptoFailedException, KeyStoreAccessException; | ||
|
||
boolean hasInternetCredentialsForServer(@NonNull String server); | ||
|
||
void setGenericPasswordForOptions(String service, String username, String password, String minimumSecurityLevel) throws EmptyParameterException, CryptoFailedException; | ||
|
||
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
18 changes: 18 additions & 0 deletions
18
android/src/main/java/com/oblador/keychain/ServiceCredentials.java
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,18 @@ | ||
package com.oblador.keychain; | ||
|
||
/** | ||
* ServiceCredentials is representing a single pair (user/pass) of credentials stored in the Keychain. | ||
* | ||
* @author Miroslav Genov <[email protected]> | ||
*/ | ||
public final class ServiceCredentials { | ||
public final String service; | ||
public final String username; | ||
public final String password; | ||
|
||
public ServiceCredentials(String service, String username, String password) { | ||
this.service = service; | ||
this.username = username; | ||
this.password = password; | ||
} | ||
} |
Oops, something went wrong.