Skip to content

Commit

Permalink
IOS-8883: Improve logging (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Fedorov committed Dec 27, 2024
1 parent f09ed00 commit acaabe1
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 5 deletions.
2 changes: 1 addition & 1 deletion TangemSdk/TangemSdk/Common/APDU/ResponseApdu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public struct ResponseApdu {

extension ResponseApdu: CustomStringConvertible {
public var description: String {
return "<-- RECEIVED [\(data.count + 2) bytes]: \(data) \(sw1) \(sw2) (SW: \(statusWord))"
return "<-- RECEIVED [\(data.count + 2) bytes]: *** \(sw1) \(sw2) (SW: \(statusWord))"
}
}
4 changes: 1 addition & 3 deletions TangemSdk/TangemSdk/Common/Core/CardSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@ public class CardSession {
completion(.failure(.sessionInactive))
return
}

Log.apdu("Not encrypted apdu: \(apdu)")


reader.tag
.filter { $0 != .none }
.filter {[weak self] tag in
Expand Down
12 changes: 12 additions & 0 deletions TangemSdk/TangemSdk/Common/Log/TlvLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ protocol TlvLogging {

extension TlvLogging {
func logTlv<T>(_ tlv: Tlv, _ value: T) {
guard !tlv.tag.shouldMask else {
logMasked(tlv)
return
}

var tlvString = "\(tlv)"

if tlv.tag.valueType != .data && tlv.tag.valueType != .hexString {
Expand All @@ -22,4 +27,11 @@ extension TlvLogging {

Log.tlv(tlvString)
}

private func logMasked(_ tlv: Tlv) {
let tagName = "\(tlv.tag)".capitalizingFirst()
let tagFullName = "TAG_\(tagName)"

Log.tlv("\(tagFullName) [0x\(tlv.tagRaw):***]: ***")
}
}
2 changes: 1 addition & 1 deletion TangemSdk/TangemSdk/Common/NFC/NFCReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ extension NFCReader: CardReader {
} //todo: handle tag lost

let requestTS = Date()
Log.apdu("SEND --> \(apdu)")

return iso7816tag
.sendCommandPublisher(cApdu: apdu)
.combineLatest(self.cancellationPublisher)
Expand Down
116 changes: 116 additions & 0 deletions TangemSdk/TangemSdk/Common/TLV/TlvTag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,120 @@ public enum TlvTag: Byte {
return .data
}
}

var shouldMask: Bool {
switch self {
case .pin,
.pin2,
.newPin,
.newPin2,
.newPin3,
.walletPublicKey,
.walletPrivateKey:
return true
case .unknown,
.cardId,
.transactionOutHash,
.transactionOutHashSize,
.walletSignature,
.walletRemainingSignatures,
.walletSignedHashes,
.pause,
.flash,
.issuerTxSignature,
.status,
.cardPublicKey,
.cardSignature,
.curveId,
.hashAlgId,
.signingMethod,
.maxSignatures,
.pauseBeforePin2,
.settingsMask,
.userSettingsMask,
.cardData,
.ndefData,
.createWalletAtPersonalize,
.health,
.crExKey,
.publicKeyChallenge,
.publicKeySalt,
.challenge,
.salt,
.validationCounter,
.cvc,
.sessionKeyA,
.sessionKeyB,
.uid,
.manufacturerName,
.manufacturerSignature,
.issuerPublicKey,
.issuerTransactionPublicKey,
.issuerData,
.issuerDataSignature,
.issuerDataCounter,
.isActivated,
.activationSeed,
.paymentFlowVersion,
.userData,
.userProtectedData,
.userCounter,
.userProtectedCounter,
.resetPin,
.codePageAddress,
.codePageCount,
.codeHash,
.trOutRaw,
.firmwareVersion,
.batchId,
.manufactureDateTime,
.issuerName,
.blockchainName,
.manufacturerPublicKey,
.cardIDManufacturerSignature,
.tokenSymbol,
.tokenContractAddress,
.tokenDecimal,
.tokenName,
.denomination,
.validatedBalance,
.lastSignDate,
.denominationText,
.checkWalletCounter,
.productMask,
.isLinked,
.terminalPublicKey,
.terminalTransactionSignature,
.legacyMode,
.interactionMode,
.offset,
.size,
.acquirerPublicKey,
.pin2IsDefault,
.pinIsDefault,
.walletIndex,
.walletsCount,
.walletData,
.cardWallet,
.fileIndex,
.fileSettings,
.fileTypeName,
.fileData,
.fileSignature,
.fileCounter,
.fileOwnerIndex,
.walletHDPath,
.walletHDChain,
.certificate,
.backupStatus,
.backupCount,
.primaryCardLinkingKey,
.backupCardLinkingKey,
.backupCardLink,
.backupAttestSignature,
.backupCardPublicKey,
.proof:
return false
}
}
}

0 comments on commit acaabe1

Please sign in to comment.