-
Notifications
You must be signed in to change notification settings - Fork 46
Replace AbstractSecretKeyLoader with ISecretKeyProvider, Fixes AB#3297746 #2666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
df9555d
add interface ISecretKeyLoader
p3dr0rv 0b256af
nits
p3dr0rv 1637d5c
nits
p3dr0rv baf65c7
nits
p3dr0rv e8a1f8f
fix interface error
p3dr0rv f644d7a
fix error
p3dr0rv 3e203d5
fix tests
p3dr0rv 53377dc
Merge branch 'dev' into pedroro/interface-for-secretkeyloader
p3dr0rv 6a96645
Update AndroidWrappedKeyLoader.java
p3dr0rv 56aeb2a
Refactor key generation to use a shared AES256SecretKeyGenerator inst…
p3dr0rv a4a3ed4
Merge branch 'dev' into pedroro/interface-for-secretkeyloader
p3dr0rv 32a1bba
Merge branch 'dev' into pedroro/interface-for-secretkeyloader
p3dr0rv e689c61
Merge branch 'dev' into pedroro/interface-for-secretkeyloader
p3dr0rv f994746
Merge branch 'dev' into pedroro/interface-for-secretkeyloader
p3dr0rv 5aea5bc
Refactor key loading mechanism to use ISecretKeyProvider interface, r…
p3dr0rv 2b56431
Remove keySize and keyAlgorithm properties from ISecretKeyGenerator a…
p3dr0rv cd2b17a
fix issues
p3dr0rv fe9d4f6
add changelog
p3dr0rv c2c8273
Refactor key management to implement ISecretKeyProvider interface, re…
p3dr0rv 37a9022
fix tests
p3dr0rv 4176ee0
Refactor key loader to key provider in encryption manager
p3dr0rv 0411dfb
Rename method to setIgnoreKeyProviderNotFoundError for consistency in…
p3dr0rv 1096d86
Rename key loader variable to key provider for consistency in Android…
p3dr0rv 866dd22
Add TODO comment for wrapCipher usage and simplify getKey method in P…
p3dr0rv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
76 changes: 76 additions & 0 deletions
76
common/src/main/java/com/microsoft/identity/common/crypto/AndroidWrappedKeyLoaderFactory.kt
This file contains hidden or 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,76 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // All rights reserved. | ||
| // | ||
| // This code is licensed under the MIT License. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files(the "Software"), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions : | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| package com.microsoft.identity.common.crypto | ||
|
|
||
| import com.microsoft.identity.common.java.crypto.key.ISecretKeyLoader | ||
| import com.microsoft.identity.common.java.flighting.CommonFlight | ||
| import com.microsoft.identity.common.java.flighting.CommonFlightsManager | ||
|
|
||
| /** | ||
| * Factory class for creating wrapped key loaders specific to the Android platform. | ||
| * | ||
| * This object is responsible for creating the appropriate implementation of [ISecretKeyLoader] | ||
| * based on feature flag. It abstracts away the details of which | ||
| * specific loader implementation should be used, allowing for runtime switching between | ||
| * different implementations without affecting client code. | ||
| */ | ||
| object AndroidWrappedKeyLoaderFactory { | ||
p3dr0rv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const val WRAPPED_KEY_KEY_IDENTIFIER: String = "A001" | ||
p3dr0rv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * Creates an appropriate wrapped key loader instance based on current feature flags. | ||
| * | ||
| * This method checks the [CommonFlight.ENABLE_NEW_ANDROID_WRAPPED_KEY_LOADER] feature flag | ||
| * to determine whether to use the new implementation or the legacy implementation of | ||
| * the Android wrapped key loader. | ||
| * | ||
| * @param keyIdentifier A unique identifier for the key being loaded | ||
| * @param fileName The name of the file where the wrapped key is stored | ||
| * @param context The Android application context needed for file and security operations | ||
| * @return An implementation of [ISecretKeyLoader] that can load the specified wrapped key | ||
| */ | ||
| fun createWrappedKeyLoader( | ||
| keyIdentifier: String, | ||
| fileName: String, | ||
| context: android.content.Context | ||
p3dr0rv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ): ISecretKeyLoader { | ||
| val useNewAndroidWrappedKeyLoader = | ||
| CommonFlightsManager | ||
| .getFlightsProvider() | ||
| .isFlightEnabled(CommonFlight.ENABLE_NEW_ANDROID_WRAPPED_KEY_LOADER) | ||
|
|
||
| return if (useNewAndroidWrappedKeyLoader) { | ||
| // TODO : Replace with the new loader on the next PR | ||
| AndroidWrappedKeyLoader( | ||
| keyIdentifier, | ||
| fileName, | ||
| context | ||
| ) | ||
| } else { | ||
| AndroidWrappedKeyLoader( | ||
| keyIdentifier, | ||
| fileName, | ||
| context | ||
| ) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.