-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [feature/#845] security module * [feature/#845] SecurityExt * [feature/#845] cryptoManager 적용 * [feature/#845] spotlessApply * [feature/#845] EncryptedContent data class * [feature/#845] SharedPreference get, set 함수 확장함수화 및 DEBUG 모드에서만 암호화 적용 * [feature/#845] getOrCreateSecretKey -> getSecretKey * [feature/#845] cipher 객체 지역변수화 * [feature/#845] key값 수정 * [feature/#845] KEY_ALIAS 변경 * [feature/#845] KEY_ALIAS 변경으로 인한 merge builder, PR builder 수정 * [feature/#845] backup_rules.xml (sharedpref backup에서 제외) * [feature/#845] CryptoManager 예외 처리 * [feature/#845] CryptoManager object화 * [feature/#845] hilt 재적용 * [feature/#845] DataStore가 CryptoManager를 알지 못하도록 수정 * [feature/#845] CryptoManagerTest * [feature/#845] SoptDataStore 기본 값 수정 * [feature/#845] CryproManagerTest AndroidTest로 변경 * [feature/#845] testCryptoSuccess 추가 및 로직 수정 * [feature/#845] spotlessApply
- Loading branch information
1 parent
17e17d8
commit f616a8f
Showing
15 changed files
with
407 additions
and
18 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
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
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
37 changes: 37 additions & 0 deletions
37
core/common/src/main/java/org/sopt/official/common/util/SecurityExt.kt
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,37 @@ | ||
/* | ||
* MIT License | ||
* Copyright 2024 SOPT - Shout Our Passion Together | ||
* | ||
* 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. | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 org.sopt.official.common.util | ||
|
||
import org.sopt.official.common.BuildConfig | ||
import org.sopt.official.security.util.getDecryptedDataOrDefault | ||
import org.sopt.official.security.util.getEncryptedDataOrDefault | ||
|
||
fun String.encryptInReleaseMode(keyAlias: String) = if (BuildConfig.DEBUG) this else this.getEncryptedDataOrDefault(keyAlias = keyAlias) | ||
|
||
fun String.decryptInReleaseMode(keyAlias: String, initializationVectorSize: Int = 12) = | ||
if (BuildConfig.DEBUG) this else this.getDecryptedDataOrDefault( | ||
keyAlias = keyAlias, | ||
initializationVectorSize = initializationVectorSize | ||
) |
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 @@ | ||
/build |
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 @@ | ||
/* | ||
* MIT License | ||
* Copyright 2024 SOPT - Shout Our Passion Together | ||
* | ||
* 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. | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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. | ||
*/ | ||
plugins { | ||
sopt("feature") | ||
sopt("test") | ||
} | ||
|
||
android { | ||
namespace = "org.sopt.official.security" | ||
} |
82 changes: 82 additions & 0 deletions
82
core/security/src/androidTest/java/org/sopt/official/security/CryptoManagerTest.kt
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,82 @@ | ||
/* | ||
* MIT License | ||
* Copyright 2024 SOPT - Shout Our Passion Together | ||
* | ||
* 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. | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 org.sopt.official.security | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.Arguments | ||
import org.junit.jupiter.params.provider.MethodSource | ||
import org.sopt.official.security.util.getDecryptedDataOrDefault | ||
import org.sopt.official.security.util.getEncryptedDataOrDefault | ||
|
||
class CryptoManagerTest { | ||
|
||
@ParameterizedTest | ||
@MethodSource("generateEncryptedTestData") | ||
@DisplayName("keyAlias와 암호화 할 데이터를 입력하면 암호화를 진행한다") | ||
fun testEncryptSuccess(keyAlias: String, bytes: ByteArray) { | ||
// when | ||
val encryptedResult = CryptoManager.encrypt(keyAlias = keyAlias, bytes = bytes) | ||
|
||
// then | ||
assertTrue(encryptedResult.isSuccess, "암호화가 성공적으로 진행되었습니다.") | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("generateCryptoTestData") | ||
@DisplayName("keyAlias와 데이터를 입력하면 암호화, 복호화를 순차적으로 진행해 기존의 데이터를 반환한다") | ||
fun testCryptoSuccess(keyAlias: String, data: String) { | ||
// given | ||
val encryptedData = data.getEncryptedDataOrDefault(keyAlias = keyAlias) | ||
|
||
// when | ||
val decryptedData = encryptedData.getDecryptedDataOrDefault(keyAlias = keyAlias) | ||
|
||
// then | ||
assertThat(decryptedData).isEqualTo(data) | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun generateEncryptedTestData() = listOf( | ||
Arguments.of("ACCESS_TOKEN", "accessToken".toByteArray()), | ||
Arguments.of("REFRESH_TOKEN", "refreshToken".toByteArray()), | ||
Arguments.of("PLAYGROUND_TOKEN", "playgroundToken".toByteArray()), | ||
Arguments.of("USER_STATUS", "userStatus".toByteArray()), | ||
Arguments.of("PUSH_TOKEN", "pushToken".toByteArray()) | ||
) | ||
|
||
@JvmStatic | ||
fun generateCryptoTestData() = listOf( | ||
Arguments.of("ACCESS_TOKEN", "accessToken"), | ||
Arguments.of("REFRESH_TOKEN", "refreshToken"), | ||
Arguments.of("PLAYGROUND_TOKEN", "playgroundToken"), | ||
Arguments.of("USER_STATUS", "userStatus"), | ||
Arguments.of("PUSH_TOKEN", "pushToken") | ||
) | ||
} | ||
} |
Oops, something went wrong.