Skip to content

Commit

Permalink
Added telemetry for logins key regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
lougeniaC64 committed Nov 3, 2022
1 parent c39be3a commit afd3ac1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Storage/Rust/RustLogins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import Foundation
import Shared
import Glean
@_exported import MozillaAppServices

private let log = Logger.syncLogger
Expand Down Expand Up @@ -493,6 +494,21 @@ public class RustLoginEncryptionKeys {
}
}

public enum KeyRegenerationEventReason {
case lost, corrupt, other
}

func recordKeyRegenerationEvent(reason: KeyRegenerationEventReason) {
switch reason {
case .lost:
GleanMetrics.LoginsStoreKeyRegneration.lost.record()
case .corrupt:
GleanMetrics.LoginsStoreKeyRegneration.corrupt.record()
case .other:
GleanMetrics.LoginsStoreKeyRegneration.other.record()
}
}

public class LoginRecordError: MaybeErrorType {
public let description: String
public init(description: String) {
Expand Down Expand Up @@ -908,6 +924,7 @@ public class RustLogins {
return key!
} else {
SentryIntegration.shared.sendWithStacktrace(message: "Logins key was corrupted, new one generated", tag: SentryTag.rustLogins, severity: .warning)
recordKeyRegenerationEvent(reason: KeyRegenerationEventReason.corrupt)
_ = self.wipeLocalEngine()
return try rustKeys.createAndStoreKey()
}
Expand All @@ -918,6 +935,7 @@ public class RustLogins {
// The key is present, but we didn't expect it to be there.
do {
SentryIntegration.shared.sendWithStacktrace(message: "Logins key lost due to storage malfunction, new one generated", tag: SentryTag.rustLogins, severity: .warning)
recordKeyRegenerationEvent(reason: KeyRegenerationEventReason.other)
_ = self.wipeLocalEngine()
return try rustKeys.createAndStoreKey()
} catch let err as NSError {
Expand All @@ -927,6 +945,7 @@ public class RustLogins {
// We expected the key to be present, but it's gone missing on us.
do {
SentryIntegration.shared.sendWithStacktrace(message: "Logins key lost, new one generated", tag: SentryTag.rustLogins, severity: .warning)
recordKeyRegenerationEvent(reason: KeyRegenerationEventReason.lost)
_ = self.wipeLocalEngine()
return try rustKeys.createAndStoreKey()
} catch let err as NSError {
Expand Down
49 changes: 49 additions & 0 deletions Storage/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,52 @@ history:
- [email protected]
- [email protected]
expires: never

logins_store_key_regneration:
# These track when we need to regenerate the encryption key which causes all
# local data to be lost
lost:
type: event
description: >
The encryption key was regenerated because it was lost
bugs:
- https://github.com/mozilla/application-services/issues/5221
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/12306
data_sensitivity:
- technical
notification_emails:
- [email protected]
- [email protected]
expires: never

corrupt:
type: event
description: >
The encryption key was regenerated because it didn't match the encrypted
data
bugs:
- https://github.com/mozilla/application-services/issues/5221
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/12306
data_sensitivity:
- technical
notification_emails:
- [email protected]
- [email protected]
expires: never

other:
type: event
description: >
The encryption key was regenerated for an unknown reason
bugs:
- https://github.com/mozilla/application-services/issues/5221
data_reviews:
- https://github.com/mozilla-mobile/firefox-ios/pull/12306
data_sensitivity:
- technical
notification_emails:
- [email protected]
- [email protected]
expires: never

0 comments on commit afd3ac1

Please sign in to comment.