namespace smartcard_service_api
{
- FileObject::FileObject(Channel *channel):ProviderHelper(channel)
+ FileObject::FileObject(Channel *channel)
+ : ProviderHelper(channel)
{
opened = false;
}
- FileObject::FileObject(Channel *channel, ByteArray selectResponse):ProviderHelper(channel)
+ FileObject::FileObject(Channel *channel, ByteArray selectResponse)
+ : ProviderHelper(channel)
{
opened = false;
setSelectResponse(selectResponse);
}
else
{
- SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
+ SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]",
+ resp.getStatus(), resp.getSW1(), resp.getSW2());
}
}
else
ret = channel->transmitSync(command, result);
if (ret == 0)
{
- if (setSelectResponse(result) == true)
+ ResponseHelper resp(result);
+
+ if (resp.getStatus() == 0)
{
- ret = SUCCESS;
+ if (setSelectResponse(result) == true)
+ {
+ ret = SUCCESS;
+ }
+ else
+ {
+ ret = ERROR_ILLEGAL_STATE;
+ }
}
- else
+ else if (resp.getStatus() == ResponseHelper::ERROR_FILE_NOT_FOUND)
{
- ret = ERROR_ILLEGAL_STATE;
+ ret = ResponseHelper::ERROR_FILE_NOT_FOUND;
}
}
else
{
- SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", ret, result.getLength());
+ SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]",
+ ret, result.getLength());
ret = ERROR_ILLEGAL_STATE;
}
/* make apdu command */
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_DF_NAME, 0, aid);
- SCARD_DEBUG("command : %s", command.toString());
ret = _select(command);
}
else
{
- command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_PATH, 0, path);
+ ByteArray temp(path);
+
+ if (path.getLength() > 2 && path[0] == 0x3f && path[1] == 0x00) /* check MF */
+ {
+ /* remove MF from path */
+ temp.setBuffer(path.getBuffer(2), path.getLength() - 2);
+ }
+
+ command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_PATH, 0, temp);
}
- SCARD_DEBUG("command : %s", command.toString());
ret = _select(command);
/* make apdu command */
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_ID, 0, fidData);
- SCARD_DEBUG("command : %s", command.toString());
ret = _select(command);
/* make apdu command */
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_PARENT_DF, 0, ByteArray::EMPTY);
- SCARD_DEBUG("command : %s", command.toString());
ret = _select(command);
APDUCommand apdu;
int ret;
- apdu.setCommand(0, APDUCommand::INS_READ_RECORD, recordId, 4, ByteArray::EMPTY, 0);
+ apdu.setCommand(0, APDUCommand::INS_READ_RECORD, recordId, 4, ByteArray::EMPTY, APDUCommand::LE_MAX);
apdu.getBuffer(command);
- SCARD_DEBUG("command : %s", command.toString());
ret = channel->transmitSync(command, response);
if (ret == 0 && response.getLength() >= 2)
{
ResponseHelper resp(response);
- if (resp.getStatus() == 0)
+ ret = resp.getStatus();
+ if (ret == 0)
{
SCARD_DEBUG("response [%d] : %s", response.getLength(), response.toString());
-// result = resp.getDataField();
-
- ret = SUCCESS;
+ result = Record(recordId, resp.getDataField());
}
else
{
apdu.setCommand(0, APDUCommand::INS_READ_BINARY, offset, 0, ByteArray::EMPTY, length);
apdu.getBuffer(command);
- SCARD_DEBUG("command : %s", command.toString());
ret = channel->transmitSync(command, response);
if (ret == 0 && response.getLength() >= 2)
apdu.setCommand(0, APDUCommand::INS_WRITE_BINARY, offset, 0, data, 0);
apdu.getBuffer(command);
- SCARD_DEBUG("command : %s", command.toString());
ret = channel->transmitSync(command, response);
if (ret == 0 && response.getLength() >= 2)
/* local header */
#include "Debug.h"
+#include "APDUHelper.h"
+#include "EFDIR.h"
#include "PKCS15.h"
namespace smartcard_service_api
{
- static unsigned char aid[] = { 0xA0, 0x00, 0x00, 0x00, 0x63, 0x50, 0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 };
+ static unsigned char aid[] = { 0xA0, 0x00, 0x00, 0x00, 0x63, 0x50,
+ 0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 };
ByteArray PKCS15::PKCS15_AID(ARRAY_AND_SIZE(aid));
- PKCS15::PKCS15(Channel *channel):PKCS15Object(channel), odf(NULL)
+ PKCS15::PKCS15(Channel *channel)
+ : PKCS15Object(channel), odf(NULL)
{
- int ret = 0;
+ int ret;
- if ((ret = select(PKCS15::PKCS15_AID)) == 0)
+ ret = select(PKCS15::PKCS15_AID);
+ if (ret == FileObject::SUCCESS)
{
SCARD_DEBUG("response : %s", selectResponse.toString());
}
+ else if (ret == ResponseHelper::ERROR_FILE_NOT_FOUND)
+ {
+ SCARD_DEBUG_ERR("PKCS15 AID not found, search in EF DIR");
+
+ if (selectFromEFDIR() == true)
+ {
+ SCARD_DEBUG("response : %s", selectResponse.toString());
+ }
+ else
+ {
+ SCARD_DEBUG_ERR("PKCS15 select failed, [%d]", ret);
+ }
+ }
else
{
- SCARD_DEBUG_ERR("select failed, [%d]", ret);
+ SCARD_DEBUG_ERR("PKCS15 select failed, [%d]", ret);
}
}
- PKCS15::PKCS15(Channel *channel, ByteArray selectResponse):PKCS15Object(channel, selectResponse), odf(NULL)
+ PKCS15::PKCS15(Channel *channel, ByteArray selectResponse)
+ : PKCS15Object(channel, selectResponse), odf(NULL)
{
}
}
}
+ bool PKCS15::selectFromEFDIR()
+ {
+ bool result = false;
+ ByteArray path;
+ EFDIR dir(channel);
+
+ path = dir.getPathByAID(PKCS15_AID);
+ if (path.getLength() > 0)
+ {
+ int ret;
+
+ ret = select(path, false);
+ if (ret == FileObject::SUCCESS)
+ {
+ result = true;
+ }
+ else
+ {
+ SCARD_DEBUG_ERR("path select failed, [%d]", ret);
+ }
+ }
+ else
+ {
+ SCARD_DEBUG_ERR("PKCS15 not found");
+ }
+
+ return result;
+ }
+
PKCS15ODF *PKCS15::getODF()
{
if (odf == NULL)
return odf;
}
-
} /* namespace smartcard_service_api */
namespace smartcard_service_api
{
-// PKCS15ODF::PKCS15ODF():PKCS15Object()
-// {
-//
-// }
-
- PKCS15ODF::PKCS15ODF(Channel *channel):PKCS15Object(channel), dodf(NULL)
+ PKCS15ODF::PKCS15ODF(Channel *channel)
+ : PKCS15Object(channel), dodf(NULL)
{
int ret = 0;
}
}
- PKCS15ODF::PKCS15ODF(Channel *channel, ByteArray selectResponse):PKCS15Object(channel, selectResponse), dodf(NULL)
+ PKCS15ODF::PKCS15ODF(Channel *channel, ByteArray selectResponse)
+ : PKCS15Object(channel, selectResponse), dodf(NULL)
{
int ret = 0;
ByteArray odfData;
break;
default :
- SCARD_DEBUG("Unknown tlv : t [%X], l [%d], v %s", tlv.getTag(), tlv.getLength(), tlv.getValue().toString());
+ SCARD_DEBUG("Unknown tlv : t [%X], l [%d], v %s",
+ tlv.getTag(), tlv.getLength(), tlv.getValue().toString());
break;
}
+++ /dev/null
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* standard library header */
-
-/* SLP library header */
-
-/* local header */
-#include "Record.h"
-
-namespace smartcard_service_api
-{
- Record::Record()
- {
- }
-
- Record::~Record()
- {
- }
-
-} /* namespace smartcard_service_api */
bool TLVHelper::_decodeTLV()
{
int result;
+ int temp = 0;
currentT = 0;
currentL = 0;
return false;
/* T */
- if ((result = decodeTag(tlvBuffer.getBuffer(offset))) < 0)
+ if ((result = decodeTag(tlvBuffer.getBuffer(offset + temp))) < 0)
return false;
- offset += result;
+ temp += result;
/* L */
- if ((result = decodeLength(tlvBuffer.getBuffer(offset))) < 0)
+ if ((result = decodeLength(tlvBuffer.getBuffer(offset + temp))) < 0)
return false;
- offset += result;
+ temp += result;
if (currentL > 0)
{
+ if (currentL > (tlvBuffer.getLength() - (offset + temp)))
+ return false;
+
/* V */
- if ((result = decodeValue(tlvBuffer.getBuffer(offset))) < 0)
+ if ((result = decodeValue(tlvBuffer.getBuffer(offset + temp))) < 0)
return false;
- offset += result;
+ temp += result;
}
+ offset += temp;
+
return true;
}
static const int ERROR_IO = -6;
static const int ERROR_UNKNOWN = -99;
+ static const unsigned int MF_FID = 0x003F;
+
FileObject(Channel *channel);
FileObject(Channel *channel, ByteArray selectResponse);
~FileObject();
map<unsigned int, ByteArray> recordElement;
PKCS15ODF *odf;
+ bool selectFromEFDIR();
+
public:
static ByteArray PKCS15_AID;
class Record
{
private:
- ByteArray data;
unsigned int id;
+ ByteArray data;
public:
- Record();
- Record(unsigned int id, ByteArray buffer);
- ~Record();
+ Record() : id(0) {}
+ Record(unsigned int id, ByteArray buffer)
+ : id(id), data(buffer) {};
+ ~Record() {}
- unsigned int getID();
- int getData(ByteArray &buffer);
+ inline unsigned int getID() { return id; }
+ inline ByteArray getData() { return data; }
};
} /* namespace smartcard_service_api */