This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from admin-ch/feature/dev-debug-certpinning
Add debug option to disable/enable certificate pinning on DEV builds
- Loading branch information
Showing
15 changed files
with
236 additions
and
36 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
common/src/abn/java/ch/admin/bag/covidcertificate/common/debug/DebugFragment.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,25 @@ | ||
package ch.admin.bag.covidcertificate.common.debug | ||
/* | ||
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
import android.content.Context | ||
import androidx.fragment.app.Fragment | ||
|
||
open class DebugFragment : Fragment() { | ||
|
||
companion object { | ||
fun newInstance(): DebugFragment = DebugFragment() | ||
|
||
const val EXISTS = false | ||
|
||
fun initDebug(context: Context) {} | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
common/src/dev/java/ch/admin/bag/covidcertificate/common/debug/DebugFragment.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,67 @@ | ||
package ch.admin.bag.covidcertificate.common.debug | ||
/* | ||
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import ch.admin.bag.covidcertificate.common.databinding.FragmentDebugBinding | ||
import ch.admin.bag.covidcertificate.sdk.android.net.CertificatePinning | ||
|
||
open class DebugFragment : Fragment() { | ||
|
||
companion object { | ||
fun newInstance(): DebugFragment = DebugFragment() | ||
|
||
const val EXISTS = true | ||
|
||
fun initDebug(context: Context) { | ||
CertificatePinning.enabled = DebugSecureStorage.getInstance(context).isCertPinningEnabled | ||
} | ||
} | ||
|
||
private var _binding: FragmentDebugBinding? = null | ||
protected val binding get() = _binding!! | ||
|
||
private lateinit var debugSecureStorage: DebugSecureStorage | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
debugSecureStorage = DebugSecureStorage.getInstance(requireContext()) | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
_binding = FragmentDebugBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
binding.toolbar.setNavigationOnClickListener { | ||
parentFragmentManager.popBackStack() | ||
} | ||
|
||
binding.buttonToggleCertificatePinning.apply { | ||
isChecked = debugSecureStorage.isCertPinningEnabled | ||
|
||
setOnCheckedChangeListener { _, isChecked -> | ||
debugSecureStorage.isCertPinningEnabled = isChecked | ||
CertificatePinning.enabled = isChecked | ||
} | ||
} | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
common/src/dev/java/ch/admin/bag/covidcertificate/common/debug/DebugSecureStorage.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,31 @@ | ||
/* | ||
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package ch.admin.bag.covidcertificate.common.debug | ||
|
||
import android.content.Context | ||
import ch.admin.bag.covidcertificate.sdk.android.net.CertificatePinning | ||
import ch.admin.bag.covidcertificate.sdk.android.utils.EncryptedSharedPreferencesUtil | ||
import ch.admin.bag.covidcertificate.sdk.android.utils.SingletonHolder | ||
|
||
class DebugSecureStorage private constructor(context: Context) { | ||
|
||
companion object : SingletonHolder<DebugSecureStorage, Context>(::DebugSecureStorage) { | ||
private const val PREFERENCES = "DebugSecureStorage" | ||
private const val KEY_CERT_PINNING_ENABLED = "KEY_CERT_PINNING_ENABLED" | ||
} | ||
|
||
private val prefs = EncryptedSharedPreferencesUtil.initializeSharedPreferences(context, PREFERENCES) | ||
|
||
var isCertPinningEnabled: Boolean | ||
get() = prefs.getBoolean(KEY_CERT_PINNING_ENABLED, CertificatePinning.enabled) | ||
set(value) = prefs.edit().putBoolean(KEY_CERT_PINNING_ENABLED, value).apply() | ||
|
||
} |
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
25 changes: 25 additions & 0 deletions
25
common/src/prod/java/ch/admin/bag/covidcertificate/common/debug/DebugFragment.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,25 @@ | ||
package ch.admin.bag.covidcertificate.common.debug | ||
/* | ||
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
import android.content.Context | ||
import androidx.fragment.app.Fragment | ||
|
||
open class DebugFragment : Fragment() { | ||
|
||
companion object { | ||
fun newInstance(): DebugFragment = DebugFragment() | ||
|
||
const val EXISTS = false | ||
|
||
fun initDebug(context: Context) {} | ||
} | ||
|
||
} |
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
18 changes: 18 additions & 0 deletions
18
wallet/src/abn/java/ch/admin/bag/covidcertificate/wallet/debug/WalletDebugFragment.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,18 @@ | ||
package ch.admin.bag.covidcertificate.wallet.debug | ||
/* | ||
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
import ch.admin.bag.covidcertificate.common.debug.DebugFragment | ||
|
||
class WalletDebugFragment : DebugFragment() { | ||
companion object { | ||
fun newInstance(): DebugFragment = DebugFragment() | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
19 changes: 19 additions & 0 deletions
19
wallet/src/prod/java/ch/admin/bag/covidcertificate/wallet/debug/WalletDebugFragment.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,19 @@ | ||
package ch.admin.bag.covidcertificate.wallet.debug | ||
/* | ||
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
|
||
import ch.admin.bag.covidcertificate.common.debug.DebugFragment | ||
|
||
class WalletDebugFragment : DebugFragment() { | ||
companion object { | ||
fun newInstance(): DebugFragment = DebugFragment() | ||
} | ||
} |