format. do not log keys

This commit is contained in:
Andrei Vereha 2021-11-28 15:58:56 +01:00
parent 7374ff2eb1
commit 4aa67dedb5
4 changed files with 85 additions and 82 deletions

View file

@ -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()}")

View file

@ -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 {

View file

@ -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<AlertType>? = 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<AlertType>? = 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
}

View file

@ -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)