Skip to content

Commit 197cb08

Browse files
author
Andrey Fedorov
authored
IOS-8883: Improve logging (#390)
1 parent 1e78d57 commit 197cb08

File tree

5 files changed

+131
-5
lines changed

5 files changed

+131
-5
lines changed

Diff for: TangemSdk/TangemSdk/Common/APDU/ResponseApdu.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ public struct ResponseApdu {
6868

6969
extension ResponseApdu: CustomStringConvertible {
7070
public var description: String {
71-
return "<-- RECEIVED [\(data.count + 2) bytes]: \(data) \(sw1) \(sw2) (SW: \(statusWord))"
71+
return "<-- RECEIVED [\(data.count + 2) bytes]: *** \(sw1) \(sw2) (SW: \(statusWord))"
7272
}
7373
}

Diff for: TangemSdk/TangemSdk/Common/Core/CardSession.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ public class CardSession {
292292
completion(.failure(.sessionInactive))
293293
return
294294
}
295-
296-
Log.apdu("Not encrypted apdu: \(apdu)")
297-
295+
298296
reader.tag
299297
.filter { $0 != .none }
300298
.filter {[weak self] tag in

Diff for: TangemSdk/TangemSdk/Common/Log/TlvLogging.swift

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ protocol TlvLogging {
1414

1515
extension TlvLogging {
1616
func logTlv<T>(_ tlv: Tlv, _ value: T) {
17+
guard !tlv.tag.shouldMask else {
18+
logMasked(tlv)
19+
return
20+
}
21+
1722
var tlvString = "\(tlv)"
1823

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

2328
Log.tlv(tlvString)
2429
}
30+
31+
private func logMasked(_ tlv: Tlv) {
32+
let tagName = "\(tlv.tag)".capitalizingFirst()
33+
let tagFullName = "TAG_\(tagName)"
34+
35+
Log.tlv("\(tagFullName) [0x\(tlv.tagRaw):***]: ***")
36+
}
2537
}

Diff for: TangemSdk/TangemSdk/Common/NFC/NFCReader.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ extension NFCReader: CardReader {
321321
} //todo: handle tag lost
322322

323323
let requestTS = Date()
324-
Log.apdu("SEND --> \(apdu)")
324+
325325
return iso7816tag
326326
.sendCommandPublisher(cApdu: apdu)
327327
.combineLatest(self.cancellationPublisher)

Diff for: TangemSdk/TangemSdk/Common/TLV/TlvTag.swift

+116
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,120 @@ public enum TlvTag: Byte {
192192
return .data
193193
}
194194
}
195+
196+
var shouldMask: Bool {
197+
switch self {
198+
case .pin,
199+
.pin2,
200+
.newPin,
201+
.newPin2,
202+
.newPin3,
203+
.walletPublicKey,
204+
.walletPrivateKey:
205+
return true
206+
case .unknown,
207+
.cardId,
208+
.transactionOutHash,
209+
.transactionOutHashSize,
210+
.walletSignature,
211+
.walletRemainingSignatures,
212+
.walletSignedHashes,
213+
.pause,
214+
.flash,
215+
.issuerTxSignature,
216+
.status,
217+
.cardPublicKey,
218+
.cardSignature,
219+
.curveId,
220+
.hashAlgId,
221+
.signingMethod,
222+
.maxSignatures,
223+
.pauseBeforePin2,
224+
.settingsMask,
225+
.userSettingsMask,
226+
.cardData,
227+
.ndefData,
228+
.createWalletAtPersonalize,
229+
.health,
230+
.crExKey,
231+
.publicKeyChallenge,
232+
.publicKeySalt,
233+
.challenge,
234+
.salt,
235+
.validationCounter,
236+
.cvc,
237+
.sessionKeyA,
238+
.sessionKeyB,
239+
.uid,
240+
.manufacturerName,
241+
.manufacturerSignature,
242+
.issuerPublicKey,
243+
.issuerTransactionPublicKey,
244+
.issuerData,
245+
.issuerDataSignature,
246+
.issuerDataCounter,
247+
.isActivated,
248+
.activationSeed,
249+
.paymentFlowVersion,
250+
.userData,
251+
.userProtectedData,
252+
.userCounter,
253+
.userProtectedCounter,
254+
.resetPin,
255+
.codePageAddress,
256+
.codePageCount,
257+
.codeHash,
258+
.trOutRaw,
259+
.firmwareVersion,
260+
.batchId,
261+
.manufactureDateTime,
262+
.issuerName,
263+
.blockchainName,
264+
.manufacturerPublicKey,
265+
.cardIDManufacturerSignature,
266+
.tokenSymbol,
267+
.tokenContractAddress,
268+
.tokenDecimal,
269+
.tokenName,
270+
.denomination,
271+
.validatedBalance,
272+
.lastSignDate,
273+
.denominationText,
274+
.checkWalletCounter,
275+
.productMask,
276+
.isLinked,
277+
.terminalPublicKey,
278+
.terminalTransactionSignature,
279+
.legacyMode,
280+
.interactionMode,
281+
.offset,
282+
.size,
283+
.acquirerPublicKey,
284+
.pin2IsDefault,
285+
.pinIsDefault,
286+
.walletIndex,
287+
.walletsCount,
288+
.walletData,
289+
.cardWallet,
290+
.fileIndex,
291+
.fileSettings,
292+
.fileTypeName,
293+
.fileData,
294+
.fileSignature,
295+
.fileCounter,
296+
.fileOwnerIndex,
297+
.walletHDPath,
298+
.walletHDChain,
299+
.certificate,
300+
.backupStatus,
301+
.backupCount,
302+
.primaryCardLinkingKey,
303+
.backupCardLinkingKey,
304+
.backupCardLink,
305+
.backupAttestSignature,
306+
.backupCardPublicKey,
307+
.proof:
308+
return false
309+
}
310+
}
195311
}

0 commit comments

Comments
 (0)