Skip to content

How to search Crashlytics iOS events by user barcode

Ettore Pasquini edited this page Mar 22, 2022 · 1 revision

Overview

SimplyE and Open eBooks report error and informational events to Firebase / Crashlytics. Sometimes it is useful to search the database by user ID / barcode to extract all the events and logs associated with that user activity. This document explains how to do that.

Privacy Considerations

When a user signs in and an error condition happens, we attach a one-way hash of the barcode to the event we send to Firebase. This makes it impossible for us to derive the original value from the hashed value logged in Firebase. However, if we are in possession of the barcode we can hash it the same way we hash it inside the app, and then search Firebase for that hashed value.

Methodology

Open Xcode and add the following code to a Playground:

extension String {
  public func md5() -> Data {
    let messageData = self.data(using:.utf8)!
    var digestData = Data(count: Int(CC_MD5_DIGEST_LENGTH))

    _ = digestData.withUnsafeMutableBytes { digestBytes in
      messageData.withUnsafeBytes { messageBytes in
        CC_MD5(messageBytes.baseAddress, CC_LONG(messageData.count),
               digestBytes.bindMemory(to: UInt8.self).baseAddress)
      }
    }

    return digestData
  }

  public func md5hex() -> String {
    return md5().map { String(format: "%02hhx", $0) }.joined()
  }
}

Incidentally, this is the same code that the app uses to hash the barcode before logging it to Firebase.

Then, simply call the md5hex function on the barcode string, as such:

"23305012991242".md5hex()

The value you obtain can then be plugged into the "Search by User ID" button in the Crashlytics home page:

Screen Shot 2022-03-22 at 3 57 19 PM

That's it!

Clone this wiki locally