Use Timber instead of Android.Log

This commit is contained in:
Vincent Breitmoser
2018-01-20 02:12:43 +01:00
parent 73b65bf50b
commit 22c65f2ab8
161 changed files with 782 additions and 947 deletions

View File

@@ -17,10 +17,7 @@
package org.sufficientlysecure.keychain.securitytoken;
import org.bouncycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
import org.sufficientlysecure.keychain.util.Log;
import java.nio.ByteBuffer;
import java.util.Arrays;

View File

@@ -31,6 +31,10 @@ import java.io.IOException;
import nordpol.IsoCard;
import nordpol.android.AndroidCard;
import timber.log.Timber;
import static org.bouncycastle.util.encoders.Hex.toHexString;
public class NfcTransport implements Transport {
// timeout is set to 100 seconds to avoid cancellation during calculation
@@ -60,12 +64,12 @@ public class NfcTransport implements Transport {
public ResponseApdu transceive(final CommandApdu data) throws IOException {
byte[] rawCommand = data.toBytes();
if (Constants.DEBUG) {
Log.d(Constants.TAG, "nfc out: " + Hex.toHexString(rawCommand));
Timber.d("nfc out: " + toHexString(rawCommand));
}
byte[] rawResponse = mIsoCard.transceive(rawCommand);
if (Constants.DEBUG) {
Log.d(Constants.TAG, "nfc in: " + Hex.toHexString(rawResponse));
Timber.d("nfc in: " + toHexString(rawResponse));
}
return ResponseApdu.fromBytes(rawResponse);

View File

@@ -27,11 +27,10 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo.TokenType;
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo.TransportType;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Passphrase;
import timber.log.Timber;
/**
@@ -256,7 +255,7 @@ public class SecurityTokenConnection {
secureMessaging = SCP11bSecureMessaging.establish(this, context, commandFactory);
} catch (SecureMessagingException e) {
secureMessaging = null;
Log.e(Constants.TAG, "failed to establish secure messaging", e);
Timber.e(e, "failed to establish secure messaging");
}
}
@@ -427,7 +426,7 @@ public class SecurityTokenConnection {
// Note: This should not happen, but happens with
// https://github.com/FluffyKaon/OpenPGP-Card, thus return an empty string for now!
Log.e(Constants.TAG, "Couldn't get holder name, returning empty string!", e);
Timber.e(e, "Couldn't get holder name, returning empty string!");
return "";
}
}

View File

@@ -25,10 +25,10 @@ import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransport;
import org.sufficientlysecure.keychain.ui.UsbEventReceiverActivity;
import org.sufficientlysecure.keychain.util.Log;
import timber.log.Timber;
public class UsbConnectionDispatcher {
private Activity mActivity;
@@ -50,7 +50,7 @@ public class UsbConnectionDispatcher {
boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,
false);
if (permission) {
Log.d(Constants.TAG, "Got permission for " + usbDevice.getDeviceName());
Timber.d("Got permission for " + usbDevice.getDeviceName());
sendUsbTransportDiscovered(usbDevice);
}
break;

View File

@@ -28,16 +28,14 @@ import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.bcpg.HashAlgorithmTags;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.securitytoken.CardException;
import org.sufficientlysecure.keychain.securitytoken.CommandApdu;
import org.sufficientlysecure.keychain.securitytoken.KeyFormat;
import org.sufficientlysecure.keychain.securitytoken.KeyType;
import org.sufficientlysecure.keychain.securitytoken.OpenPgpCapabilities;
import org.sufficientlysecure.keychain.securitytoken.RSAKeyFormat;
import org.sufficientlysecure.keychain.securitytoken.ResponseApdu;
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenConnection;
import org.sufficientlysecure.keychain.util.Log;
import timber.log.Timber;
public class SecurityTokenPsoSignTokenOp {
@@ -54,7 +52,7 @@ public class SecurityTokenPsoSignTokenOp {
private byte[] prepareDsi(byte[] hash, int hashAlgo) throws IOException {
byte[] dsi;
Log.i(Constants.TAG, "Hash: " + hashAlgo);
Timber.i("Hash: " + hashAlgo);
switch (hashAlgo) {
case HashAlgorithmTags.SHA1:
if (hash.length != 20) {

View File

@@ -27,13 +27,13 @@ import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.WorkerThread;
import android.util.Log;
import com.google.auto.value.AutoValue;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException.UsbCcidErrorException;
import timber.log.Timber;
import static org.bouncycastle.util.encoders.Hex.toHexString;
public class CcidTransceiver {
@@ -87,14 +87,14 @@ public class CcidTransceiver {
CcidDataBlock response = null;
for (CcidDescription.Voltage v : usbCcidDescription.getVoltages()) {
Log.v(Constants.TAG, "CCID: attempting to power on with voltage " + v.toString());
Timber.v("CCID: attempting to power on with voltage " + v.toString());
try {
response = iccPowerOnVoltage(v.powerOnValue);
} catch (UsbCcidErrorException e) {
if (e.getErrorResponse().getError() == 7) { // Power select error
Log.v(Constants.TAG, "CCID: failed to power on with voltage " + v.toString());
Timber.v("CCID: failed to power on with voltage " + v.toString());
iccPowerOff();
Log.v(Constants.TAG, "CCID: powered off");
Timber.v("CCID: powered off");
continue;
}
@@ -109,8 +109,8 @@ public class CcidTransceiver {
long elapsedTime = SystemClock.elapsedRealtime() - startTime;
Log.d(Constants.TAG, "Usb transport connected, took " + elapsedTime + "ms, ATR=" +
Hex.toHexString(response.getData()));
Timber.d("Usb transport connected, took " + elapsedTime + "ms, ATR=" +
toHexString(response.getData()));
return response;
}
@@ -176,7 +176,7 @@ public class CcidTransceiver {
CcidDataBlock ccidDataBlock = receiveDataBlock(sequenceNumber);
long elapsedTime = SystemClock.elapsedRealtime() - startTime;
Log.d(Constants.TAG, "USB XferBlock call took " + elapsedTime + "ms");
Timber.d("USB XferBlock call took " + elapsedTime + "ms");
return ccidDataBlock;
}
@@ -187,8 +187,7 @@ public class CcidTransceiver {
ignoredBytes = usbConnection.bulkTransfer(
usbBulkIn, inputBuffer, inputBuffer.length, DEVICE_SKIP_TIMEOUT_MILLIS);
if (ignoredBytes > 0) {
Log.e(Constants.TAG,
"Skipped " + ignoredBytes + " bytes: " + Hex.toHexString(inputBuffer, 0, ignoredBytes));
Timber.e("Skipped " + ignoredBytes + " bytes: " + toHexString(inputBuffer, 0, ignoredBytes));
}
} while (ignoredBytes > 0);
}

View File

@@ -31,7 +31,6 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Pair;
import org.bouncycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.securitytoken.CommandApdu;
import org.sufficientlysecure.keychain.securitytoken.ResponseApdu;
@@ -39,8 +38,10 @@ import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo;
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo.TokenType;
import org.sufficientlysecure.keychain.securitytoken.SecurityTokenInfo.TransportType;
import org.sufficientlysecure.keychain.securitytoken.Transport;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences;
import timber.log.Timber;
import static org.bouncycastle.util.encoders.Hex.toHexString;
/**
@@ -98,7 +99,7 @@ public class UsbTransport implements Transport {
usbConnection = null;
}
Log.d(Constants.TAG, "Usb transport disconnected");
Timber.d("Usb transport disconnected");
}
/**
@@ -158,7 +159,7 @@ public class UsbTransport implements Transport {
}
CcidDescription ccidDescription = CcidDescription.fromRawDescriptors(usbConnection.getRawDescriptors());
Log.d(Constants.TAG, "CCID Description: " + ccidDescription);
Timber.d("CCID Description: " + ccidDescription);
CcidTransceiver transceiver = new CcidTransceiver(usbConnection, usbBulkIn, usbBulkOut, ccidDescription);
ccidTransportProtocol = ccidDescription.getSuitableTransportProtocol();
@@ -175,12 +176,12 @@ public class UsbTransport implements Transport {
public ResponseApdu transceive(CommandApdu data) throws UsbTransportException {
byte[] rawCommand = data.toBytes();
if (Constants.DEBUG) {
Log.d(Constants.TAG, "USB >> " + Hex.toHexString(rawCommand));
Timber.d("USB >> " + toHexString(rawCommand));
}
byte[] rawResponse = ccidTransportProtocol.transceive(rawCommand);
if (Constants.DEBUG) {
Log.d(Constants.TAG, "USB << " + Hex.toHexString(rawResponse));
Timber.d("USB << " + toHexString(rawResponse));
}
return ResponseApdu.fromBytes(rawResponse);
@@ -252,7 +253,7 @@ public class UsbTransport implements Transport {
}
}
Log.d(Constants.TAG, "Unknown USB token. Vendor ID: " + usbDevice.getVendorId() + ", Product ID: " +
Timber.d("Unknown USB token. Vendor ID: " + usbDevice.getVendorId() + ", Product ID: " +
usbDevice.getProductId());
return null;
}

View File

@@ -21,12 +21,12 @@ package org.sufficientlysecure.keychain.securitytoken.usb.tpdu;
import android.support.annotation.NonNull;
import org.bouncycastle.util.Arrays;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.securitytoken.usb.CcidTransceiver;
import org.sufficientlysecure.keychain.securitytoken.usb.CcidTransceiver.CcidDataBlock;
import org.sufficientlysecure.keychain.securitytoken.usb.CcidTransportProtocol;
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
import org.sufficientlysecure.keychain.util.Log;
import timber.log.Timber;
/* T=1 Protocol, see http://www.icedev.se/proxmark3/docs/ISO-7816.pdf, Part 11 */
public class T1TpduProtocol implements CcidTransportProtocol {
@@ -94,10 +94,10 @@ public class T1TpduProtocol implements CcidTransportProtocol {
sentLength += len;
if (responseBlock instanceof SBlock) {
Log.d(Constants.TAG, "S-Block received " + responseBlock);
Timber.d("S-Block received " + responseBlock);
// just ignore
} else if (responseBlock instanceof RBlock) {
Log.d(Constants.TAG, "R-Block received " + responseBlock);
Timber.d("R-Block received " + responseBlock);
if (((RBlock) responseBlock).getError() != RBlock.RError.NO_ERROR) {
throw new UsbTransportException("R-Block reports error " + ((RBlock) responseBlock).getError());
}
@@ -123,7 +123,7 @@ public class T1TpduProtocol implements CcidTransportProtocol {
Block responseBlock = blockFactory.fromBytes(response.getData());
if (!(responseBlock instanceof IBlock)) {
Log.e(Constants.TAG, "Invalid response block received " + responseBlock);
Timber.e("Invalid response block received " + responseBlock);
throw new UsbTransportException("Response: invalid state - invalid block received");
}