Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-8883: Improve logging #390

Merged
merged 4 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}
Loading