token: send expected result size as Le

This is a different take on 1c8cc99c68,
sending the expected result size. It's not what the spec says, but it's
what GnuPG does, so it should achieve good compatibility.
This commit is contained in:
Vincent Breitmoser
2018-03-22 17:09:16 +01:00
parent 1e7ed06698
commit 52c8824969
4 changed files with 12 additions and 6 deletions

View File

@@ -135,8 +135,9 @@ public class OpenPgpCommandApduFactory {
}
@NonNull
public CommandApdu createDecipherCommand(byte[] data) {
return CommandApdu.create(CLA, INS_PERFORM_SECURITY_OPERATION, P1_PSO_DECIPHER, P2_PSO_DECIPHER, data);
public CommandApdu createDecipherCommand(byte[] data, int expectedLength) {
return CommandApdu.create(CLA, INS_PERFORM_SECURITY_OPERATION, P1_PSO_DECIPHER, P2_PSO_DECIPHER, data,
expectedLength);
}
@NonNull

View File

@@ -85,9 +85,10 @@ public class PsoDecryptTokenOp {
}
private byte[] decryptSessionKeyRsa(byte[] encryptedSessionKeyMpi) throws IOException {
int mpiLength = getMpiLength(encryptedSessionKeyMpi);
byte[] psoDecipherPayload = getRsaOperationPayload(encryptedSessionKeyMpi);
CommandApdu command = connection.getCommandFactory().createDecipherCommand(psoDecipherPayload);
CommandApdu command = connection.getCommandFactory().createDecipherCommand(psoDecipherPayload, mpiLength);
ResponseApdu response = connection.communicate(command);
if (!response.isSuccess()) {
@@ -139,7 +140,8 @@ public class PsoDecryptTokenOp {
}
psoDecipherPayload = Arrays.concatenate(Hex.decode("A6"), dataLen, psoDecipherPayload);
CommandApdu command = connection.getCommandFactory().createDecipherCommand(psoDecipherPayload);
CommandApdu command = connection.getCommandFactory().createDecipherCommand(
psoDecipherPayload, encryptedPoint.length);
ResponseApdu response = connection.communicate(command);
if (!response.isSuccess()) {