From 4aa67dedb58d33f06fc26dc1d8f030e1f0b69d0c Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Sun, 28 Nov 2021 15:58:56 +0100 Subject: [PATCH] format. do not log keys --- .../dash/driver/comm/pair/KeyExchange.kt | 4 +- .../dash/driver/comm/session/Milenage.kt | 33 ++++--- .../state/OmnipodDashPodStateManagerImpl.kt | 94 +++++++++---------- .../dash/ui/OmnipodDashOverviewFragment.kt | 36 +++---- 4 files changed, 85 insertions(+), 82 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/KeyExchange.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/KeyExchange.kt index 28071a06fe..4015582ac1 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/KeyExchange.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/KeyExchange.kt @@ -80,13 +80,11 @@ class KeyExchange( pdmNonce + podNonce aesCmac(confKey, pdmConfData, pdmConf) - aapsLogger.debug(LTag.PUMPBTCOMM, "pdmConf: ${pdmConf.toHex()}") val podConfData = POD_CONF_MAGIC_PREFIX + podNonce + pdmNonce aesCmac(confKey, podConfData, podConf) - aapsLogger.debug(LTag.PUMPBTCOMM, "podConf: ${podConf.toHex()}") if (BuildConfig.DEBUG) { aapsLogger.debug(LTag.PUMPBTCOMM, "pdmPrivate: ${pdmPrivate.toHex()}") @@ -94,6 +92,8 @@ class KeyExchange( aapsLogger.debug(LTag.PUMPBTCOMM, "podPublic: ${podPublic.toHex()}") aapsLogger.debug(LTag.PUMPBTCOMM, "pdmNonce: ${pdmNonce.toHex()}") aapsLogger.debug(LTag.PUMPBTCOMM, "podNonce: ${podNonce.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "podConf: ${podConf.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "pdmConf: ${pdmConf.toHex()}") aapsLogger.debug(LTag.PUMPBTCOMM, "LTK, donna key: ${curveLTK.toHex()}") aapsLogger.debug(LTag.PUMPBTCOMM, "Intermediate key: ${intermediateKey.toHex()}") diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt index 6eab46d2c6..c0de0c515e 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Milenage.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.session import info.nightscout.androidaps.extensions.toHex import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag +import info.nightscout.androidaps.plugins.pump.omnipod.dash.BuildConfig import org.spongycastle.util.encoders.Hex import java.security.SecureRandom import javax.crypto.Cipher @@ -102,21 +103,23 @@ class Milenage( val receivedMacS = auts.copyOfRange(6, 14) init { - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage K: ${k.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage RAND: ${rand.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage SQN: ${sqn.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage CK: ${ck.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage AUTN: ${autn.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage RES: ${res.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage AK: ${ak.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage AK STAR: ${akStar.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage OPC: ${opc.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage FullMAC: ${macAFull.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage MacA: ${macA.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage MacS: ${macS.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage AUTS: ${auts.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage synchronizationSqn: ${synchronizationSqn.toHex()}") - aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage receivedMacS: ${receivedMacS.toHex()}") + if (BuildConfig.DEBUG) { + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage K: ${k.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage RAND: ${rand.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage SQN: ${sqn.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage CK: ${ck.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage AUTN: ${autn.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage RES: ${res.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage AK: ${ak.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage AK STAR: ${akStar.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage OPC: ${opc.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage FullMAC: ${macAFull.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage MacA: ${macA.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage MacS: ${macS.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage AUTS: ${auts.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage synchronizationSqn: ${synchronizationSqn.toHex()}") + aapsLogger.debug(LTag.PUMPBTCOMM, "Milenage receivedMacS: ${receivedMacS.toHex()}") + } } companion object { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt index fb3a8adcfb..f50a06312c 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/pod/state/OmnipodDashPodStateManagerImpl.kt @@ -677,7 +677,8 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( private fun store() { try { - val serialized = Gson().toJson(podState) + val cleanPodState = podState.copy(ltk = byteArrayOf()) // do not log ltk + val serialized = Gson().toJson(cleanPodState) logger.debug(LTag.PUMP, "Storing Pod state: $serialized") sharedPreferences.putString(R.string.key_omnipod_dash_pod_state, serialized) } catch (ex: Exception) { @@ -699,56 +700,55 @@ class OmnipodDashPodStateManagerImpl @Inject constructor( return PodState() } - class PodState : Serializable { - - var activationProgress: ActivationProgress = ActivationProgress.NOT_STARTED - var lastUpdatedSystem: Long = 0 - var lastStatusResponseReceived: Long = 0 + data class PodState( + var activationProgress: ActivationProgress = ActivationProgress.NOT_STARTED, + var lastUpdatedSystem: Long = 0, + var lastStatusResponseReceived: Long = 0, var bluetoothConnectionState: OmnipodDashPodStateManager.BluetoothConnectionState = - OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED - var connectionAttempts = 0 - var successfulConnections = 0 - var successfulConnectionAttemptsAfterRetries = 0 - var failedConnectionsAfterRetries = 0 - var messageSequenceNumber: Short = 0 - var sequenceNumberOfLastProgrammingCommand: Short? = null - var activationTime: Long? = null - var uniqueId: Long? = null - var bluetoothAddress: String? = null - var ltk: ByteArray? = null - var eapAkaSequenceNumber: Long = 1 - var timeZone: String? = null // TimeZone ID (e.g. "Europe/Amsterdam") - var timeZoneOffset: Int? = null - var timeZoneUpdated: Long? = null - var alarmSynced: Boolean = false - var suspendAlertsEnabled: Boolean = false + OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED, + var connectionAttempts: Int = 0, + var successfulConnections: Int = 0, + var successfulConnectionAttemptsAfterRetries: Int = 0, + var failedConnectionsAfterRetries: Int = 0, + var messageSequenceNumber: Short = 0, + var sequenceNumberOfLastProgrammingCommand: Short? = null, + var activationTime: Long? = null, + var uniqueId: Long? = null, + var bluetoothAddress: String? = null, + var ltk: ByteArray? = null, + var eapAkaSequenceNumber: Long = 1, + var timeZone: String? = null, // TimeZone ID (e.g. "Europe/Amsterdam") + var timeZoneOffset: Int? = null, + var timeZoneUpdated: Long? = null, + var alarmSynced: Boolean = false, + var suspendAlertsEnabled: Boolean = false, - var bleVersion: SoftwareVersion? = null - var firmwareVersion: SoftwareVersion? = null - var lotNumber: Long? = null - var podSequenceNumber: Long? = null - var pulseRate: Short? = null - var primePulseRate: Short? = null - var podLifeInHours: Short? = null - var firstPrimeBolusVolume: Short? = null - var secondPrimeBolusVolume: Short? = null + var bleVersion: SoftwareVersion? = null, + var firmwareVersion: SoftwareVersion? = null, + var lotNumber: Long? = null, + var podSequenceNumber: Long? = null, + var pulseRate: Short? = null, + var primePulseRate: Short? = null, + var podLifeInHours: Short? = null, + var firstPrimeBolusVolume: Short? = null, + var secondPrimeBolusVolume: Short? = null, - var expirationReminderEnabled: Boolean? = null - var expirationHours: Int? = null - var lowReservoirAlertEnabled: Boolean? = null - var lowReservoirAlertUnits: Int? = null + var expirationReminderEnabled: Boolean? = null, + var expirationHours: Int? = null, + var lowReservoirAlertEnabled: Boolean? = null, + var lowReservoirAlertUnits: Int? = null, - var pulsesDelivered: Short? = null - var pulsesRemaining: Short? = null - var podStatus: PodStatus? = null - var deliveryStatus: DeliveryStatus? = null - var minutesSinceActivation: Short? = null - var activeAlerts: EnumSet? = null - var alarmType: AlarmType? = null + var pulsesDelivered: Short? = null, + var pulsesRemaining: Short? = null, + var podStatus: PodStatus? = null, + var deliveryStatus: DeliveryStatus? = null, + var minutesSinceActivation: Short? = null, + var activeAlerts: EnumSet? = null, + var alarmType: AlarmType? = null, - var basalProgram: BasalProgram? = null - var tempBasal: OmnipodDashPodStateManager.TempBasal? = null - var activeCommand: OmnipodDashPodStateManager.ActiveCommand? = null + var basalProgram: BasalProgram? = null, + var tempBasal: OmnipodDashPodStateManager.TempBasal? = null, + var activeCommand: OmnipodDashPodStateManager.ActiveCommand? = null, var lastBolus: OmnipodDashPodStateManager.LastBolus? = null - } + ) : Serializable } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt index 42b35b8f77..3dbcd61952 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/ui/OmnipodDashOverviewFragment.kt @@ -267,7 +267,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { Color.RED connectionSuccessPercentage < 90 && podStateManager.successfulConnectionAttemptsAfterRetries > 50 -> Color.YELLOW - else -> + else -> Color.WHITE } bluetoothStatusBinding.omnipodDashBluetoothConnectionQuality.setTextColor(connectionStatsColor) @@ -333,9 +333,9 @@ class OmnipodDashOverviewFragment : DaggerFragment() { when { !podStateManager.sameTimeZone -> Color.MAGENTA - timeDeviationTooBig -> + timeDeviationTooBig -> Color.YELLOW - else -> + else -> Color.WHITE } ) @@ -348,11 +348,11 @@ class OmnipodDashOverviewFragment : DaggerFragment() { ?: PLACEHOLDER podInfoBinding.podExpiryDate.setTextColor( when { - expiresAt != null && ZonedDateTime.now().isAfter(expiresAt) -> + expiresAt != null && ZonedDateTime.now().isAfter(expiresAt) -> Color.RED expiresAt != null && ZonedDateTime.now().isAfter(expiresAt.minusHours(4)) -> Color.YELLOW - else -> + else -> Color.WHITE } ) @@ -430,21 +430,21 @@ class OmnipodDashOverviewFragment : DaggerFragment() { private fun translatedActiveAlert(alert: AlertType): String { val id = when (alert) { - AlertType.LOW_RESERVOIR -> + AlertType.LOW_RESERVOIR -> R.string.omnipod_common_alert_low_reservoir - AlertType.EXPIRATION -> + AlertType.EXPIRATION -> R.string.omnipod_common_alert_expiration_advisory AlertType.EXPIRATION_IMMINENT -> R.string.omnipod_common_alert_expiration AlertType.USER_SET_EXPIRATION -> R.string.omnipod_common_alert_expiration_advisory - AlertType.AUTO_OFF -> + AlertType.AUTO_OFF -> R.string.omnipod_common_alert_shutdown_imminent AlertType.SUSPEND_IN_PROGRESS -> R.string.omnipod_common_alert_delivery_suspended - AlertType.SUSPEND_ENDED -> + AlertType.SUSPEND_ENDED -> R.string.omnipod_common_alert_delivery_suspended - else -> + else -> R.string.omnipod_common_alert_unknown_alert } return rh.gs(id) @@ -457,7 +457,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { System.currentTimeMillis() - podStateManager.lastUpdatedSystem, - ) + ) ) val lastConnectionColor = if (omnipodDashPumpPlugin.isUnreachableAlertTimeoutExceeded(getPumpUnreachableTimeout().toMillis())) { @@ -506,9 +506,9 @@ class OmnipodDashOverviewFragment : DaggerFragment() { val podStatusColor = when { !podStateManager.isActivationCompleted || podStateManager.isPodKaput || podStateManager.isSuspended -> Color.RED - podStateManager.activeCommand != null -> + podStateManager.activeCommand != null -> Color.YELLOW - else -> + else -> Color.WHITE } podInfoBinding.podStatus.setTextColor(podStatusColor) @@ -603,7 +603,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { private fun updateRefreshStatusButton() { buttonBinding.buttonRefreshStatus.isEnabled = podStateManager.isUniqueIdSet && - isQueueEmpty() + isQueueEmpty() } private fun updateResumeDeliveryButton() { @@ -670,15 +670,15 @@ class OmnipodDashOverviewFragment : DaggerFragment() { val minutes = duration.toMinutes().toInt() val seconds = duration.seconds when { - seconds < 10 -> { + seconds < 10 -> { return rh.gs(R.string.omnipod_common_moments_ago) } - seconds < 60 -> { + seconds < 60 -> { return rh.gs(R.string.omnipod_common_less_than_a_minute_ago) } - seconds < 60 * 60 -> { // < 1 hour + seconds < 60 * 60 -> { // < 1 hour return rh.gs( R.string.omnipod_common_time_ago, rh.gq(R.plurals.omnipod_common_minutes, minutes, minutes) @@ -702,7 +702,7 @@ class OmnipodDashOverviewFragment : DaggerFragment() { ) } - else -> { + else -> { val days = hours / 24 val hoursLeft = hours % 24 if (hoursLeft > 0)