Change some package structure
This commit is contained in:
@@ -31,6 +31,7 @@ import org.sufficientlysecure.keychain.Constants;
|
|||||||
import org.sufficientlysecure.keychain.securitytoken.Transport;
|
import org.sufficientlysecure.keychain.securitytoken.Transport;
|
||||||
import javax.smartcardio.CommandAPDU;
|
import javax.smartcardio.CommandAPDU;
|
||||||
import javax.smartcardio.ResponseAPDU;
|
import javax.smartcardio.ResponseAPDU;
|
||||||
|
import org.sufficientlysecure.keychain.securitytoken.usb.tpdu.T1ShortApduProtocol;
|
||||||
import org.sufficientlysecure.keychain.securitytoken.usb.tpdu.T1TpduProtocol;
|
import org.sufficientlysecure.keychain.securitytoken.usb.tpdu.T1TpduProtocol;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import org.bouncycastle.util.Arrays;
|
|||||||
import org.bouncycastle.util.encoders.Hex;
|
import org.bouncycastle.util.encoders.Hex;
|
||||||
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
|
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
|
||||||
|
|
||||||
public class Block {
|
class Block {
|
||||||
private static final int MAX_PAYLOAD_LEN = 254;
|
private static final int MAX_PAYLOAD_LEN = 254;
|
||||||
private static final int OFFSET_NAD = 0;
|
private static final int OFFSET_NAD = 0;
|
||||||
static final int OFFSET_PCB = 1;
|
static final int OFFSET_PCB = 1;
|
||||||
@@ -29,9 +29,9 @@ public class Block {
|
|||||||
private static final int OFFSET_DATA = 3;
|
private static final int OFFSET_DATA = 3;
|
||||||
|
|
||||||
private final byte[] blockData;
|
private final byte[] blockData;
|
||||||
private final BlockChecksumType checksumType;
|
private final BlockChecksumAlgorithm checksumType;
|
||||||
|
|
||||||
Block(BlockChecksumType checksumType, byte[] data) throws UsbTransportException {
|
Block(BlockChecksumAlgorithm checksumType, byte[] data) throws UsbTransportException {
|
||||||
this.checksumType = checksumType;
|
this.checksumType = checksumType;
|
||||||
this.blockData = data;
|
this.blockData = data;
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public class Block {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// /*
|
// /*
|
||||||
Block(BlockChecksumType checksumType, byte nad, byte pcb, byte[] apdu, int offset, int length)
|
Block(BlockChecksumAlgorithm checksumType, byte nad, byte pcb, byte[] apdu, int offset, int length)
|
||||||
throws UsbTransportException {
|
throws UsbTransportException {
|
||||||
this.checksumType = checksumType;
|
this.checksumType = checksumType;
|
||||||
if (length > MAX_PAYLOAD_LEN) {
|
if (length > MAX_PAYLOAD_LEN) {
|
||||||
@@ -100,7 +100,7 @@ public class Block {
|
|||||||
return Arrays.copyOfRange(blockData, blockData.length - checksumType.getLength(), blockData.length);
|
return Arrays.copyOfRange(blockData, blockData.length - checksumType.getLength(), blockData.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockChecksumType getChecksumType() {
|
public BlockChecksumAlgorithm getChecksumType() {
|
||||||
return checksumType;
|
return checksumType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ package org.sufficientlysecure.keychain.securitytoken.usb.tpdu;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
|
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
|
||||||
|
|
||||||
public enum BlockChecksumType {
|
enum BlockChecksumAlgorithm {
|
||||||
LRC(1), CRC(2);
|
LRC(1), CRC(2);
|
||||||
|
|
||||||
private int mLength;
|
private int mLength;
|
||||||
|
|
||||||
BlockChecksumType(int length) {
|
BlockChecksumAlgorithm(int length) {
|
||||||
mLength = length;
|
mLength = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Nikita Mikhailov <nikita.s.mikhailov@gmail.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.sufficientlysecure.keychain.securitytoken.usb.tpdu;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
|
|
||||||
|
|
||||||
public enum FrameType {
|
|
||||||
I_BLOCK(0b00000000, 0b10000000, 6, true), // Information
|
|
||||||
R_BLOCK(0b10000000, 0b11000000, 4, false), // Receipt ack
|
|
||||||
S_BLOCK(0b11000000, 0b11000000, -1, false); // System
|
|
||||||
|
|
||||||
private byte mValue;
|
|
||||||
private byte mMask;
|
|
||||||
private int mSequenceBit;
|
|
||||||
private boolean mChainingSupported;
|
|
||||||
|
|
||||||
FrameType(int value, int mask, int sequenceBit, boolean chaining) {
|
|
||||||
// Accept ints just to avoid cast in creation
|
|
||||||
this.mValue = (byte) value;
|
|
||||||
this.mMask = (byte) mask;
|
|
||||||
this.mSequenceBit = sequenceBit;
|
|
||||||
this.mChainingSupported = chaining;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static FrameType fromPCB(byte pcb) throws UsbTransportException {
|
|
||||||
for (final FrameType frameType : values()) {
|
|
||||||
if ((frameType.mMask & pcb) == frameType.mValue) {
|
|
||||||
return frameType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new UsbTransportException("Invalid PCB byte");
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSequenceBit() {
|
|
||||||
return mSequenceBit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isChainingSupported() {
|
|
||||||
return mChainingSupported;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,7 +28,7 @@ class IBlock extends Block {
|
|||||||
private static final byte BIT_SEQUENCE = 6;
|
private static final byte BIT_SEQUENCE = 6;
|
||||||
private static final byte BIT_CHAINING = 5;
|
private static final byte BIT_CHAINING = 5;
|
||||||
|
|
||||||
IBlock(BlockChecksumType checksumType, byte[] data) throws UsbTransportException {
|
IBlock(BlockChecksumAlgorithm checksumType, byte[] data) throws UsbTransportException {
|
||||||
super(checksumType, data);
|
super(checksumType, data);
|
||||||
|
|
||||||
if ((getPcb() & MASK_IBLOCK) != MASK_VALUE_IBLOCK) {
|
if ((getPcb() & MASK_IBLOCK) != MASK_VALUE_IBLOCK) {
|
||||||
@@ -36,7 +36,7 @@ class IBlock extends Block {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IBlock(BlockChecksumType checksumType, byte nad, byte sequence, boolean chaining, byte[] apdu, int offset,
|
IBlock(BlockChecksumAlgorithm checksumType, byte nad, byte sequence, boolean chaining, byte[] apdu, int offset,
|
||||||
int length)
|
int length)
|
||||||
throws UsbTransportException {
|
throws UsbTransportException {
|
||||||
super(checksumType, nad,
|
super(checksumType, nad,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class RBlock extends Block {
|
|||||||
|
|
||||||
private static final byte BIT_SEQUENCE = 4;
|
private static final byte BIT_SEQUENCE = 4;
|
||||||
|
|
||||||
RBlock(BlockChecksumType checksumType, byte[] data) throws UsbTransportException {
|
RBlock(BlockChecksumAlgorithm checksumType, byte[] data) throws UsbTransportException {
|
||||||
super(checksumType, data);
|
super(checksumType, data);
|
||||||
|
|
||||||
if ((getPcb() & MASK_RBLOCK) != MASK_VALUE_RBLOCK) {
|
if ((getPcb() & MASK_RBLOCK) != MASK_VALUE_RBLOCK) {
|
||||||
@@ -39,7 +39,7 @@ class RBlock extends Block {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RBlock(BlockChecksumType checksumType, byte nad, byte sequence)
|
RBlock(BlockChecksumAlgorithm checksumType, byte nad, byte sequence)
|
||||||
throws UsbTransportException {
|
throws UsbTransportException {
|
||||||
super(checksumType, nad, (byte) (MASK_VALUE_RBLOCK | ((sequence & 1) << BIT_SEQUENCE)), new byte[0], 0, 0);
|
super(checksumType, nad, (byte) (MASK_VALUE_RBLOCK | ((sequence & 1) << BIT_SEQUENCE)), new byte[0], 0, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class SBlock extends Block {
|
|||||||
static final byte MASK_SBLOCK = (byte) 0b11000000;
|
static final byte MASK_SBLOCK = (byte) 0b11000000;
|
||||||
static final byte MASK_VALUE_SBLOCK = (byte) 0b11000000;
|
static final byte MASK_VALUE_SBLOCK = (byte) 0b11000000;
|
||||||
|
|
||||||
SBlock(BlockChecksumType checksumType, byte[] data) throws UsbTransportException {
|
SBlock(BlockChecksumAlgorithm checksumType, byte[] data) throws UsbTransportException {
|
||||||
super(checksumType, data);
|
super(checksumType, data);
|
||||||
|
|
||||||
if ((getPcb() & MASK_SBLOCK) != MASK_VALUE_SBLOCK) {
|
if ((getPcb() & MASK_SBLOCK) != MASK_VALUE_SBLOCK) {
|
||||||
|
|||||||
@@ -15,15 +15,17 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.sufficientlysecure.keychain.securitytoken.usb;
|
package org.sufficientlysecure.keychain.securitytoken.usb.tpdu;
|
||||||
|
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
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.CcidTransceiver.CcidDataBlock;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.securitytoken.usb.CcidTransportProtocol;
|
||||||
|
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
|
||||||
|
|
||||||
class T1ShortApduProtocol implements CcidTransportProtocol {
|
public class T1ShortApduProtocol implements CcidTransportProtocol {
|
||||||
private CcidTransceiver ccidTransceiver;
|
private CcidTransceiver ccidTransceiver;
|
||||||
|
|
||||||
public void connect(@NonNull CcidTransceiver transceiver) throws UsbTransportException {
|
public void connect(@NonNull CcidTransceiver transceiver) throws UsbTransportException {
|
||||||
@@ -5,9 +5,9 @@ import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
|
|||||||
|
|
||||||
|
|
||||||
class T1TpduBlockFactory {
|
class T1TpduBlockFactory {
|
||||||
private BlockChecksumType checksumType;
|
private BlockChecksumAlgorithm checksumType;
|
||||||
|
|
||||||
T1TpduBlockFactory(BlockChecksumType checksumType) {
|
T1TpduBlockFactory(BlockChecksumAlgorithm checksumType) {
|
||||||
this.checksumType = checksumType;
|
this.checksumType = checksumType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class T1TpduProtocol implements CcidTransportProtocol {
|
|||||||
this.ccidTransceiver.iccPowerOn();
|
this.ccidTransceiver.iccPowerOn();
|
||||||
|
|
||||||
// TODO: set checksum from atr
|
// TODO: set checksum from atr
|
||||||
blockFactory = new T1TpduBlockFactory(BlockChecksumType.LRC);
|
blockFactory = new T1TpduBlockFactory(BlockChecksumAlgorithm.LRC);
|
||||||
|
|
||||||
performPpsExchange();
|
performPpsExchange();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user