SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}")
ENDFOREACH(flag)
-#SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -finstrument-functions")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -finstrument-functions")
#SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
#SET(CMAKE_C_FLAGS_RELEASE "-O2")
-#SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -finstrument-functions -std=c++0x")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -finstrument-functions -std=c++0x")
#SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
#SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
namespace smartcard_service_api
{
ClientChannel::ClientChannel(void *context, Session *session,
- int channelNum, ByteArray selectResponse, void *handle)
+ int channelNum, const ByteArray &selectResponse, void *handle)
: Channel(session)
{
this->channelNum = -1;
if (callback != NULL) {
callback(response.getBuffer(),
- response.getLength(),
+ response.size(),
result, param->user_param);
}
msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
syncLock();
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
rv = waitTimedCondition(0);
if (rv < 0)
msg.callback = (void *)callback;
msg.userParam = userParam;
- if (ClientIPC::getInstance().sendMessage(&msg) == false)
+ if (ClientIPC::getInstance().sendMessage(msg) == false)
{
_ERR("sendMessage failed");
result = SCARD_ERROR_IPC_FAILED;
return result;
}
- int ClientChannel::transmitSync(ByteArray command, ByteArray &result)
+ int ClientChannel::transmitSync(const ByteArray &command, ByteArray &result)
throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
ErrorIllegalParameter &, ErrorSecurity &)
{
msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
syncLock();
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
rv = waitTimedCondition(0);
if (rv >= 0)
return rv;
}
- int ClientChannel::transmit(ByteArray command, transmitCallback callback, void *userParam)
+ int ClientChannel::transmit(const ByteArray &command, transmitCallback callback, void *userParam)
{
int result;
msg.callback = (void *)callback;
msg.userParam = userParam;
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
result = SCARD_ERROR_OK;
}
transmitCallback cb = (transmitCallback)msg->callback;
/* async call */
- cb(msg->data.getBuffer(), msg->data.getLength(), msg->error, msg->userParam);
+ cb(msg->data.getBuffer(),
+ msg->data.size(),
+ msg->error,
+ msg->userParam);
}
}
break;
break;
default:
- _DBG("Unknown message : %s", msg->toString());
+ _DBG("Unknown message : %s", msg->toString().c_str());
break;
}
CHANNEL_EXTERN_BEGIN;
ByteArray temp;
- temp.setBuffer(command, length);
+ temp.assign(command, length);
result = channel->transmit(temp, (transmitCallback)callback, userParam);
CHANNEL_EXTERN_END;
CHANNEL_EXTERN_BEGIN;
ByteArray temp, resp;
- temp.setBuffer(command, cmd_len);
+ temp.assign(command, cmd_len);
try
{
result = channel->transmitSync(temp, resp);
- if (resp.getLength() > 0)
+ if (resp.size() > 0)
{
- *resp_len = resp.getLength();
+ *resp_len = resp.size();
*response = (unsigned char *)calloc(1, *resp_len);
memcpy(*response, resp.getBuffer(), *resp_len);
}
unsigned int result = 0;
CHANNEL_EXTERN_BEGIN;
- result = channel->getSelectResponse().getLength();
+ result = channel->getSelectResponse().size();
CHANNEL_EXTERN_END;
return result;
ByteArray response;
response = channel->getSelectResponse();
- if (response.getLength() > 0)
+ if (response.size() > 0)
{
- memcpy(buffer, response.getBuffer(), MIN(length, response.getLength()));
+ memcpy(buffer, response.getBuffer(), MIN(length, response.size()));
result = true;
}
CHANNEL_EXTERN_END;
case Message::MSG_REQUEST_READERS :
case Message::MSG_REQUEST_SHUTDOWN :
{
- DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+ DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
if (msg->isSynchronousCall() == false)
{
/* Reader requests */
case Message::MSG_REQUEST_OPEN_SESSION :
{
- DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+ DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
if (msg->isSynchronousCall() == false)
{
case Message::MSG_REQUEST_CLOSE_SESSION :
case Message::MSG_REQUEST_GET_CHANNEL_COUNT :
{
- DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+ DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
if (msg->isSynchronousCall() == false)
{
case Message::MSG_REQUEST_TRANSMIT :
case Message::MSG_REQUEST_CLOSE_CHANNEL :
{
- DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+ DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
if (msg->isSynchronousCall() == false)
{
for (item = mapSESerivces.begin(); item != mapSESerivces.end(); item++)
{
- DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+ DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
tempMsg->caller = item->second;
for (item = mapSESerivces.begin(); item != mapSESerivces.end(); item++)
{
- DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+ DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
tempMsg->caller = item->second;
tempMsg->error = -1;
namespace smartcard_service_api
{
- ClientIPC::ClientIPC():IPCHelper()
+ ClientIPC::ClientIPC() : IPCHelper()
{
#ifdef USE_AUTOSTART
_launch_daemon();
if ((error = security_server_request_cookie(buffer, length))
== SECURITY_SERVER_API_SUCCESS)
{
- cookie.setBuffer(buffer, length);
+ cookie.assign(buffer, length);
- _DBG("cookie : %s", cookie.toString());
+ _DBG("cookie : %s", cookie.toString().c_str());
}
else
{
}
#endif
- bool ClientIPC::sendMessage(Message *msg)
+ bool ClientIPC::sendMessage(const Message &msg)
{
ByteArray stream;
unsigned int length;
return false;
#ifdef SECURITY_SERVER
- stream = cookie + msg->serialize();
+ stream = cookie + msg.serialize();
#else
- stream = msg->serialize();
+ stream = msg.serialize();
#endif
- length = stream.getLength();
+ length = stream.size();
_DBG(">>>[SEND]>>> socket [%d], msg [%d], length [%d]",
- ipcSocket, msg->message, stream.getLength());
+ ipcSocket, msg.message, stream.size());
return IPCHelper::sendMessage(ipcSocket, stream);
}
msg = retrieveMessage();
if (msg != NULL)
{
- DispatcherMsg dispMsg(msg);
+ DispatcherMsg dispMsg(*msg);
/* set peer socket */
dispMsg.setPeerSocket(ipcSocket);
Reader::Reader(void *context, const char *name, void *handle) :
ReaderHelper(), context(context), handle(handle)
{
- unsigned int length = 0;
-
_BEGIN();
if (context == NULL || name == NULL || strlen(name) == 0 || handle == NULL)
this->handle = handle;
this->context = context;
-
- length = strlen(name);
- length = (length < sizeof(this->name)) ? length : sizeof(this->name);
- memcpy(this->name, name, length);
-
+ this->name = name;
#ifdef USE_GDBUS
/* initialize client */
if (!g_thread_supported())
msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
syncLock();
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
rv = waitTimedCondition(0);
if (rv != 0)
msg.callback = (void *)callback;
msg.userParam = userData;
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
result = SCARD_ERROR_OK;
}
break;
default:
- _DBG("unknown [%s]", msg->toString());
+ _DBG("unknown [%s]", msg->toString().c_str());
break;
}
msg.caller = (void *)this;
msg.callback = (void *)NULL;
- if (ClientIPC::getInstance().sendMessage(&msg) == false)
+ if (ClientIPC::getInstance().sendMessage(msg) == false)
{
_ERR("time over");
}
msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
syncLock();
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
int rv;
msg.caller = (void *)this;
msg.userParam = context;
- result = clientIPC->sendMessage(&msg);
+ result = clientIPC->sendMessage(msg);
}
#endif
_END();
return true;
}
#endif
- bool SEService::parseReaderInformation(unsigned int count, ByteArray data)
+ bool SEService::parseReaderInformation(unsigned int count, const ByteArray &data)
{
size_t i;
unsigned int offset = 0;
Reader *reader = NULL;
char name[100];
- for (i = 0; i < count && offset < data.getLength(); i++)
+ for (i = 0; i < count && offset < data.size(); i++)
{
memset(name, 0, sizeof(name));
break;
default :
- _DBG("unknown message [%s]", msg->toString());
+ _DBG("unknown message [%s]", msg->toString().c_str());
break;
}
}
if (callback != NULL) {
- callback(atr.getBuffer(), atr.getLength(), result, param->user_param);
+ callback(atr.getBuffer(),
+ atr.size(), result, param->user_param);
}
delete param;
delete param;
}
#endif
- ByteArray Session::getATRSync()
+ const ByteArray Session::getATRSync()
throw (ExceptionBase &, ErrorIO &, ErrorSecurity &,
ErrorIllegalState &, ErrorIllegalParameter &)
{
msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
syncLock();
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
rv = waitTimedCondition(0);
if (rv != 0)
msg.callback = (void *)callback;
msg.userParam = userData;
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
result = SCARD_ERROR_OK;
}
result = SCARD_ERROR_OK;
/* TODO : invoke callback directly */
- callback(atr.getBuffer(), atr.getLength(), 0, userData);
+ callback(atr.getBuffer(),
+ atr.size(), 0, userData);
}
}
else
msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
syncLock();
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
rv = waitTimedCondition(0);
msg.callback = (void *)callback;
msg.userParam = userData;
- if (ClientIPC::getInstance().sendMessage(&msg) == false)
+ if (ClientIPC::getInstance().sendMessage(msg) == false)
{
_ERR("sendMessage failed");
result = SCARD_ERROR_IPC_FAILED;
msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
syncLock();
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
rv = waitTimedCondition(0);
if (rv != 0)
msg.callback = (void *)callback;
msg.userParam = userData;
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
result = SCARD_ERROR_OK;
}
return result;
}
- Channel *Session::openChannelSync(int id, ByteArray &aid)
+ Channel *Session::openChannelSync(int id, const ByteArray &aid)
throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &,
ErrorIllegalParameter &, ErrorSecurity &)
{
msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
syncLock();
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
rv = waitTimedCondition(0);
if (rv != 0)
return (Channel *)channel;
}
- int Session::openChannel(int id, ByteArray &aid, openChannelCallback callback, void *userData)
+ int Session::openChannel(int id, const ByteArray &aid, openChannelCallback callback, void *userData)
{
int result;
msg.callback = (void *)callback;
msg.userParam = userData;
- if (ClientIPC::getInstance().sendMessage(&msg) == true)
+ if (ClientIPC::getInstance().sendMessage(msg) == true)
{
result = SCARD_ERROR_OK;
}
return result;
}
- Channel *Session::openBasicChannelSync(ByteArray &aid)
+ Channel *Session::openBasicChannelSync(const ByteArray &aid)
throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
return openChannelSync(0, aid);
}
- Channel *Session::openBasicChannelSync(unsigned char *aid, unsigned int length)
+ Channel *Session::openBasicChannelSync(const unsigned char *aid, unsigned int length)
throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
ByteArray temp(aid, length);
return openBasicChannelSync(temp);
}
- int Session::openBasicChannel(ByteArray &aid, openChannelCallback callback, void *userData)
+ int Session::openBasicChannel(const ByteArray &aid, openChannelCallback callback, void *userData)
{
return openChannel(0, aid, callback, userData);
}
- int Session::openBasicChannel(unsigned char *aid, unsigned int length,
+ int Session::openBasicChannel(const unsigned char *aid, unsigned int length,
openChannelCallback callback, void *userData)
{
ByteArray temp(aid, length);
return openBasicChannel(temp, callback, userData);
}
- Channel *Session::openLogicalChannelSync(ByteArray &aid)
+ Channel *Session::openLogicalChannelSync(const ByteArray &aid)
throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
return openChannelSync(1, aid);
}
- Channel *Session::openLogicalChannelSync(unsigned char *aid, unsigned int length)
+ Channel *Session::openLogicalChannelSync(const unsigned char *aid, unsigned int length)
throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
ByteArray temp(aid, length);
return openLogicalChannelSync(temp);
}
- int Session::openLogicalChannel(ByteArray &aid, openChannelCallback callback, void *userData)
+ int Session::openLogicalChannel(const ByteArray &aid, openChannelCallback callback, void *userData)
{
return openChannel(1, aid, callback, userData);
}
- int Session::openLogicalChannel(unsigned char *aid, unsigned int length,
+ int Session::openLogicalChannel(const unsigned char *aid, unsigned int length,
openChannelCallback callback, void *userData)
{
ByteArray temp(aid, length);
getATRCallback cb = (getATRCallback)msg->callback;
/* async call */
- cb(msg->data.getBuffer(), msg->data.getLength(), msg->error, msg->userParam);
+ cb(msg->data.getBuffer(),
+ msg->data.size(),
+ msg->error,
+ msg->userParam);
}
}
break;
break;
default :
- _DBG("unknown message : %s", msg->toString());
+ _DBG("unknown message : %s", msg->toString().c_str());
break;
}
SESSION_EXTERN_BEGIN;
temp = session->getATRSync();
- if (temp.getLength() > 0)
+ if (temp.size() > 0)
{
- *length = temp.getLength();
+ *length = temp.size();
*buffer = (unsigned char *)calloc(1, *length);
memcpy(*buffer, temp.getBuffer(), *length);
ByteArray response;
#endif
ClientChannel(void *context, Session *session, int channelNum,
- ByteArray selectResponse, void *handle);
+ const ByteArray &selectResponse, void *handle);
~ClientChannel();
#ifdef USE_GDBUS
#endif
public:
int close(closeChannelCallback callback, void *userParam);
- int transmit(ByteArray command, transmitCallback callback,
+ int transmit(const ByteArray &command, transmitCallback callback,
void *userParam);
void closeSync()
throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
ErrorSecurity &, ErrorIllegalParameter &);
- int transmitSync(ByteArray command, ByteArray &result)
+ int transmitSync(const ByteArray &command, ByteArray &result)
throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
ErrorIllegalParameter &, ErrorSecurity &);
public:
static ClientIPC &getInstance();
- bool sendMessage(Message *msg);
+ bool sendMessage(const Message &msg);
};
} /* namespace open_mobile_api */
SEService();
void addReader(unsigned int handle, const char *name);
- bool parseReaderInformation(unsigned int count, ByteArray data);
+ bool parseReaderInformation(unsigned int count, const ByteArray &data);
#ifdef USE_GDBUS
bool parseReaderInformation(GVariant *variant);
#else
Session(void *context, Reader *reader, void *handle);
~Session();
- int openChannel(int id, ByteArray &aid, openChannelCallback callback, void *userData);
- Channel *openChannelSync(int id, ByteArray &aid)
+ int openChannel(int id, const ByteArray &aid, openChannelCallback callback, void *userData);
+ Channel *openChannelSync(int id, const ByteArray &aid)
throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
ErrorIllegalParameter &, ErrorSecurity &);
#ifdef USE_GDBUS
int getATR(getATRCallback callback, void *userData);
int close(closeSessionCallback callback, void *userData);
- int openBasicChannel(ByteArray &aid, openChannelCallback callback, void *userData);
- int openBasicChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData);
- int openLogicalChannel(ByteArray &aid, openChannelCallback callback, void *userData);
- int openLogicalChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData);
+ int openBasicChannel(const ByteArray &aid, openChannelCallback callback, void *userData);
+ int openBasicChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData);
+ int openLogicalChannel(const ByteArray &aid, openChannelCallback callback, void *userData);
+ int openLogicalChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData);
int getChannelCount(getChannelCountCallback callback, void * userData);
- ByteArray getATRSync()
+ const ByteArray getATRSync()
throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
ErrorIllegalState &, ErrorIllegalParameter &);
throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
ErrorIllegalState &, ErrorIllegalParameter &);
- Channel *openBasicChannelSync(ByteArray &aid)
+ Channel *openBasicChannelSync(const ByteArray &aid)
throw(ErrorIO &, ErrorIllegalState &,
ErrorIllegalParameter &, ErrorSecurity &);
- Channel *openBasicChannelSync(unsigned char *aid, unsigned int length)
+ Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length)
throw(ErrorIO &, ErrorIllegalState &,
ErrorIllegalParameter &, ErrorSecurity &);
- Channel *openLogicalChannelSync(ByteArray &aid)
+ Channel *openLogicalChannelSync(const ByteArray &aid)
throw(ErrorIO &, ErrorIllegalState &,
ErrorIllegalParameter &, ErrorSecurity &);
- Channel *openLogicalChannelSync(unsigned char *aid, unsigned int length)
+ Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length)
throw(ErrorIO &, ErrorIllegalState &,
ErrorIllegalParameter &, ErrorSecurity &);
namespace smartcard_service_api
{
/* ResponseHelper class */
- ResponseHelper::ResponseHelper()
- : status(0)
+ ResponseHelper::ResponseHelper() : status(0)
{
}
{
bool result = false;
status = SCARD_ERROR_UNKNOWN;
- dataField.releaseBuffer();
+ dataField.clear();
this->response = response;
- if (response.getLength() >= 2)
+ if (response.size() >= 2)
{
- sw[0] = response.getReverseAt(1);
- sw[1] = response.getReverseAt(0);
+ sw[0] = response.reverseAt(1);
+ sw[1] = response.reverseAt(0);
status = parseStatusWord(sw);
- if (response.getLength() > 2)
+ if (response.size() > 2)
{
- dataField.setBuffer(response.getBuffer(),
- response.getLength() - 2);
+ dataField.assign(response.getBuffer(),
+ response.size() - 2);
}
result = true;
return result;
}
- int ResponseHelper::parseStatusWord(unsigned char *sw)
+ int ResponseHelper::parseStatusWord(const unsigned char *sw)
{
int result = sw[0] << 8 | sw[1];
return result;
}
- int ResponseHelper::getStatus()
- {
- return status;
- }
-
int ResponseHelper::getStatus(const ByteArray &response)
{
int status = 0;
- if (response.getLength() >= 2)
+ if (response.size() >= 2)
{
- status = ResponseHelper::parseStatusWord(response.getBuffer((response.getLength() - 2)));
+ status = ResponseHelper::parseStatusWord(response.getBuffer((response.size() - 2)));
}
return status;
}
- unsigned char ResponseHelper::getSW1()
- {
- return sw[0];
- }
-
- unsigned char ResponseHelper::getSW2()
- {
- return sw[1];
- }
-
- ByteArray ResponseHelper::getDataField()
- {
- return dataField;
- }
-
- ByteArray ResponseHelper::getDataField(const ByteArray &response)
+ const ByteArray ResponseHelper::getDataField(const ByteArray &response)
{
ByteArray result;
- if (response.getLength() > 2)
+ if (response.size() > 2)
{
- result.setBuffer(response.getBuffer(), response.getLength() - 2);
+ result.assign(response.getBuffer(), response.size() - 2);
}
return result;
{
}
- bool APDUCommand::setCommand(unsigned char cla, unsigned char ins, unsigned char p1,
- unsigned char p2, ByteArray commandData, unsigned int maxResponseSize)
+ bool APDUCommand::setCommand(unsigned char cla, unsigned char ins,
+ unsigned char p1, unsigned char p2,
+ const ByteArray &commandData,
+ unsigned int maxResponseSize)
{
setCLA(cla);
setINS(ins);
uint32_t offset = 0;
uint32_t lengthSize = 1;
- if (command.getLength() < sizeof(header))
+ if (command.size() < sizeof(header))
{
return false;
}
lengthSize = 2;
}
- if (command.getLength() - offset > lengthSize)
+ if (command.size() - offset > lengthSize)
{
unsigned int length = 0;
}
else
{
- length = command.getAt(offset);
+ length = command.at(offset);
offset += 1;
}
offset += length;
}
- if (command.getLength() - offset == lengthSize)
+ if (command.size() - offset == lengthSize)
{
if (isExtendedLength)
{
unsigned int temp;
- temp = command.getAt(offset) << 8;
- temp |= command.getAt(offset + 1);
+ temp = command.at(offset) << 8;
+ temp |= command.at(offset + 1);
if (temp == 0)
setMaxResponseSize(APDUCommand::LE_MAX);
}
else
{
- if (command.getAt(offset) == 0)
+ if (command.at(offset) == 0)
setMaxResponseSize(APDUCommand::LE_MAX);
else
- setMaxResponseSize(command.getAt(offset));
+ setMaxResponseSize(command.at(offset));
offset += 1;
}
}
- if (command.getLength() == offset)
+ if (command.size() == offset)
{
result = true;
}
else
{
- _ERR("command stream is not correct, command.getLength() [%d], offset [%d]", command.getLength(), offset);
+ _ERR("command stream is not correct, command.size() [%d], offset [%d]", command.size(), offset);
}
return result;
header.cla = cla;
}
- unsigned char APDUCommand::getCLA()
+ unsigned char APDUCommand::getCLA() const
{
return header.cla;
}
header.ins = ins;
}
- unsigned char APDUCommand::getINS()
+ unsigned char APDUCommand::getINS() const
{
return header.ins;
}
header.param[0] = p1;
}
- unsigned char APDUCommand::getP1()
+ unsigned char APDUCommand::getP1() const
{
return header.param[0];
}
header.param[1] = p2;
}
- unsigned char APDUCommand::getP2()
+ unsigned char APDUCommand::getP2() const
{
return header.param[1];
}
commandData = data;
}
- ByteArray APDUCommand::getCommandData()
+ const ByteArray APDUCommand::getCommandData() const
{
return commandData;
}
this->maxResponseSize = maxResponseSize;
}
- unsigned int APDUCommand::getMaxResponseSize()
+ unsigned int APDUCommand::getMaxResponseSize() const
{
return maxResponseSize;
}
- bool APDUCommand::getBuffer(ByteArray &array)
+ bool APDUCommand::getBuffer(ByteArray &array) const
{
unsigned char *temp_buffer = NULL;
unsigned int temp_len = 0;
temp_len += sizeof(header);
/* calculate lc length */
- if (commandData.getLength() > 0)
+ if (commandData.size() > 0)
{
- if (isExtendedLength/*commandData.getLength() > 255*/)
+ if (isExtendedLength/*commandData.size() > 255*/)
{
- lc[1] = (commandData.getLength() >> 8) & 0x000000FF;
- lc[2] = commandData.getLength() & 0x000000FF;
+ lc[1] = (commandData.size() >> 8) & 0x000000FF;
+ lc[2] = commandData.size() & 0x000000FF;
lc_len = 3;
}
else
{
- lc[0] = commandData.getLength() & 0x000000FF;
+ lc[0] = commandData.size() & 0x000000FF;
lc_len = 1;
}
temp_len += lc_len;
/* add command data length */
- temp_len += commandData.getLength();
+ temp_len += commandData.size();
/* calculate le length */
if (maxResponseSize > 0)
{
- if (isExtendedLength/*commandData.getLength() > 255*/)
+ if (isExtendedLength/*commandData.size() > 255*/)
{
if (maxResponseSize < 65536)
{
memcpy(temp_buffer + offset, &header, sizeof(header));
offset += sizeof(header);
- if (commandData.getLength() > 0)
+ if (commandData.size() > 0)
{
memcpy(temp_buffer + offset, &lc, lc_len);
offset += lc_len;
- memcpy(temp_buffer + offset, commandData.getBuffer(), commandData.getLength());
- offset += commandData.getLength();
+ memcpy(temp_buffer + offset, commandData.getBuffer(), commandData.size());
+ offset += commandData.size();
}
if (maxResponseSize > 0)
offset += le_len;
}
- array.setBuffer(temp_buffer, temp_len);
+ array.assign(temp_buffer, temp_len);
delete []temp_buffer;
return true;
}
/* APDUHelper class */
- ByteArray APDUHelper::generateAPDU(int command, int channel, ByteArray data)
+ const ByteArray APDUHelper::generateAPDU(int command,
+ int channel, const ByteArray &data)
{
ByteArray result;
APDUCommand apdu;
listFilters.push_back(item);
}
- bool AccessRule::isAuthorizedAPDUAccess(const ByteArray &command)
+ bool AccessRule::isAuthorizedAPDUAccess(const ByteArray &command) const
{
bool result = false;
- if (command.getLength() < 4) /* apdu header size */
+ if (command.size() < 4) /* apdu header size */
return false;
if (listFilters.size() > 0)
{
unsigned int cmd, mask, rule;
- vector<pair<ByteArray, ByteArray> >::iterator item;
+ vector<pair<ByteArray, ByteArray> >::const_iterator item;
cmd = *(unsigned int *)command.getBuffer();
for (item = listFilters.begin(); item != listFilters.end(); item++)
return result;
}
- void AccessRule::printAccessRules()
+ void AccessRule::printAccessRules() const
{
if (listFilters.size() > 0)
{
- vector<pair<ByteArray, ByteArray> >::iterator item;
+ vector<pair<ByteArray, ByteArray> >::const_iterator item;
_DBG(" +---- Granted APDUs");
for (item = listFilters.begin(); item != listFilters.end(); item++)
{
- _DBG(" +----- APDU : %s, Mask : %s", item->first.toString(), item->second.toString());
+ _DBG(" +----- APDU : %s, Mask : %s", item->first.toString().c_str(), item->second.toString().c_str());
}
}
else
_DBG(" +---- NFC Access ALLOW : %s", nfcRule ? "ALWAYS" : "NEVER");
}
- bool AccessRule::isAuthorizedNFCAccess(void)
+ bool AccessRule::isAuthorizedNFCAccess(void) const
{
return nfcRule;
}
return result;
}
+ const AccessRule *AccessCondition::getAccessRule(const ByteArray &certHash) const
+ {
+ const AccessRule *result = NULL;
+ map<ByteArray, AccessRule>::const_iterator item;
+
+ item = mapRules.find(certHash);
+ if (item != mapRules.end()) {
+ result = &item->second;
+ }
+
+ return result;
+ }
+
void AccessCondition::addAccessRule(const ByteArray &hash)
{
AccessRule rule;
mapRules.insert(item);
}
- bool AccessCondition::isAuthorizedAccess(const ByteArray &certHash)
+ bool AccessCondition::isAuthorizedAccess(const ByteArray &certHash) const
{
- bool result = false;
- map<ByteArray, AccessRule>::iterator item;
+ bool result = permission;
+ const AccessRule *rule = getAccessRule(certHash);
- item = mapRules.find(certHash);
- if (item != mapRules.end())
- {
+ if (rule != NULL) {
result = true;
}
- else
- {
- /* TODO */
- result = permission;
- }
return result;
}
- void AccessCondition::printAccessConditions()
+ void AccessCondition::printAccessConditions() const
{
_DBG(" +-- Access Condition");
if (mapRules.size() > 0)
{
- map<ByteArray, AccessRule>::iterator item;
+ map<ByteArray, AccessRule>::const_iterator item;
for (item = mapRules.begin(); item != mapRules.end(); item++)
{
ByteArray temp = item->first;
- _DBG(" +--- hash : %s", (temp == AccessControlList::ALL_DEVICE_APPS) ? "All device applications" : temp.toString());
+ _DBG(" +--- hash : %s", (temp == AccessControlList::ALL_DEVICE_APPS) ? "All device applications" : temp.toString().c_str());
item->second.printAccessRules();
}
}
void AccessCondition::addAPDUAccessRule(const ByteArray &certHash,
const ByteArray &rule)
{
- if (rule.getLength() != 8)
+ if (rule.size() != 8)
return;
addAPDUAccessRule(certHash, rule.sub(0, 4), rule.sub(4, 4));
}
bool AccessCondition::isAuthorizedAPDUAccess(const ByteArray &certHash,
- const ByteArray &command)
+ const ByteArray &command) const
{
bool result = false;
- AccessRule *access = getAccessRule(certHash);
+ const AccessRule *rule = getAccessRule(certHash);
- if (access != NULL) {
- result = access->isAuthorizedAPDUAccess(command);
+ if (rule != NULL) {
+ result = rule->isAuthorizedAPDUAccess(command);
}
return result;
}
- bool AccessCondition::isAuthorizedNFCAccess(const ByteArray &certHash)
+ bool AccessCondition::isAuthorizedNFCAccess(const ByteArray &certHash) const
{
bool result = false;
- AccessRule *access = getAccessRule(certHash);
+ const AccessRule *rule = getAccessRule(certHash);
- if (access != NULL) {
- result = access->isAuthorizedNFCAccess();
+ if (rule != NULL) {
+ result = rule->isAuthorizedNFCAccess();
}
return result;
return item->second;
}
- AccessRule *AccessControlList::findAccessRule(const ByteArray &aid,
- const ByteArray &hash)
+ const AccessRule *AccessControlList::findAccessRule(const ByteArray &aid,
+ const ByteArray &hash) const
{
- AccessRule *result = NULL;
- map<ByteArray, AccessCondition>::iterator item;
+ const AccessRule *result = NULL;
+ map<ByteArray, AccessCondition>::const_iterator item;
item = mapConditions.find(aid);
if (item != mapConditions.end()) {
return result;
}
- bool AccessControlList::isAuthorizedAccess(ByteArray &aid,
- ByteArray &certHash)
+ bool AccessControlList::isAuthorizedAccess(const ByteArray &aid,
+ const ByteArray &certHash) const
{
vector<ByteArray> hashes;
return isAuthorizedAccess(aid, hashes);
}
- bool AccessControlList::isAuthorizedAccess(unsigned char *aidBuffer,
- unsigned int aidLength, unsigned char *certHashBuffer,
- unsigned int certHashLength)
+ bool AccessControlList::isAuthorizedAccess(const unsigned char *aidBuffer,
+ unsigned int aidLength, const unsigned char *certHashBuffer,
+ unsigned int certHashLength) const
{
ByteArray aid(aidBuffer, aidLength);
ByteArray certHash(certHashBuffer, certHashLength);
return isAuthorizedAccess(aid, certHash);
}
- bool AccessControlList::isAuthorizedAccess(ByteArray &aid,
- vector<ByteArray> &certHashes)
+ bool AccessControlList::isAuthorizedAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const
{
return isAuthorizedAccess(aid, certHashes, ByteArray::EMPTY);
}
- bool AccessControlList::isAuthorizedAccess(ByteArray &aid,
- vector<ByteArray> &certHashes, ByteArray &command)
+ bool AccessControlList::isAuthorizedAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes, const ByteArray &command) const
{
bool result = allGranted;
- vector<ByteArray>::reverse_iterator item;
- AccessRule *rule = NULL;
+ vector<ByteArray>::const_reverse_iterator item;
+ const AccessRule *rule = NULL;
if (result == true) {
goto END;
} else {
result = rule->isAuthorizedAPDUAccess(command);
}
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), (*item).toString());
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), (*item).toString().c_str());
goto END;
}
}
} else {
result = rule->isAuthorizedAPDUAccess(command);
}
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), ALL_DEVICE_APPS.toString());
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), ALL_DEVICE_APPS.toString().c_str());
goto END;
}
} else {
result = rule->isAuthorizedAPDUAccess(command);
}
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString());
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString().c_str());
goto END;
}
}
return result;
}
- bool AccessControlList::isAuthorizedNFCAccess(ByteArray &aid,
- vector<ByteArray> &certHashes)
+ bool AccessControlList::isAuthorizedNFCAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const
{
bool result = allGranted;
- vector<ByteArray>::reverse_iterator item;
- AccessRule *rule = NULL;
+ vector<ByteArray>::const_reverse_iterator item;
+ const AccessRule *rule = NULL;
if (result == true) {
goto END;
rule = findAccessRule(aid, *item);
if (rule != NULL) {
result = rule->isAuthorizedNFCAccess();
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), (*item).toString());
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), (*item).toString().c_str());
goto END;
}
}
rule = findAccessRule(aid, ALL_DEVICE_APPS);
if (rule != NULL) {
result = rule->isAuthorizedNFCAccess();
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), "All device applications");
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), "All device applications");
goto END;
}
rule = findAccessRule(ALL_SE_APPS, *item);
if (rule != NULL) {
result = rule->isAuthorizedNFCAccess();
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString());
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString().c_str());
goto END;
}
}
return result;
}
- void AccessControlList::printAccessControlList()
+ void AccessControlList::printAccessControlList() const
{
ByteArray temp;
- map<ByteArray, AccessCondition>::iterator iterMap;
+ map<ByteArray, AccessCondition>::const_iterator iterMap;
_DBG("================ Access Control Rules ==================");
for (iterMap = mapConditions.begin(); iterMap != mapConditions.end(); iterMap++)
{
temp = iterMap->first;
- _DBG("+ aid : %s", (temp == DEFAULT_SE_APP) ? "Default Application" : (temp == ALL_SE_APPS) ? "All SE Applications" : temp.toString());
+ _DBG("+ aid : %s", (temp == DEFAULT_SE_APP) ? "Default Application" : (temp == ALL_SE_APPS) ? "All SE Applications" : temp.toString().c_str());
iterMap->second.printAccessConditions();
}
*/
/* standard library header */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
+#include <cstdio>
+#include <cstring>
+#include <cerrno>
+#include <sstream>
/* SLP library header */
{
ByteArray ByteArray::EMPTY = ByteArray();
- ByteArray::ByteArray()
+ ByteArray::ByteArray() : buffer(NULL), length(0)
{
- buffer = NULL;
- length = 0;
}
- ByteArray::ByteArray(uint8_t *array, uint32_t bufferLen)
+ ByteArray::ByteArray(const uint8_t *array, size_t size) :
+ buffer(NULL), length(0)
{
- buffer = NULL;
- length = 0;
-
- setBuffer(array, bufferLen);
+ assign(array, size);
}
- ByteArray::ByteArray(const ByteArray &T)
+ ByteArray::ByteArray(const ByteArray &T) : buffer(NULL), length(0)
{
- buffer = NULL;
- length = 0;
-
- setBuffer(T.buffer, T.length);
+ assign(T.buffer, T.length);
}
ByteArray::~ByteArray()
{
- releaseBuffer();
+ clear();
}
- bool ByteArray::setBuffer(uint8_t *array, uint32_t bufferLen)
+ bool ByteArray::assign(const uint8_t *array, size_t size)
{
- if (array == NULL || bufferLen == 0)
+ if (array == NULL || size == 0)
{
return false;
}
- releaseBuffer();
+ clear();
- buffer = new uint8_t[bufferLen];
+ buffer = new uint8_t[size];
if (buffer == NULL)
{
_ERR("alloc failed");
return false;
}
- memcpy(buffer, array, bufferLen);
- length = bufferLen;
+ memcpy(buffer, array, size);
+ length = size;
return true;
}
- bool ByteArray::_setBuffer(uint8_t *array, uint32_t bufferLen)
+ bool ByteArray::_assign(uint8_t *array, size_t size)
{
- if (array == NULL || bufferLen == 0)
+ if (array == NULL || size == 0)
{
return false;
}
- releaseBuffer();
+ clear();
buffer = array;
- length = bufferLen;
+ length = size;
return true;
}
- uint32_t ByteArray::getLength() const
+ size_t ByteArray::size() const
{
return length;
}
- uint8_t *ByteArray::getBuffer() const
+ uint8_t *ByteArray::getBuffer()
{
return getBuffer(0);
}
- uint8_t *ByteArray::getBuffer(uint32_t offset) const
+ uint8_t *ByteArray::getBuffer(size_t offset)
{
if (length == 0)
return NULL;
return buffer + offset;
}
- uint8_t ByteArray::getAt(uint32_t index) const
+ uint8_t ByteArray::at(size_t index) const
{
if (index >= length)
{
_ERR("buffer overflow, index [%d], length [%d]", index, length);
- return buffer[length -1];
+ if (length > 0)
+ {
+ return buffer[length - 1];
+ }
+ else
+ {
+ return 0;
+ }
}
return buffer[index];
}
- uint8_t ByteArray::getReverseAt(uint32_t index) const
+ uint8_t ByteArray::reverseAt(size_t index) const
{
if (index >= length)
{
_ERR("buffer underflow, index [%d], length [%d]", index, length);
- return buffer[0];
+ if (length > 0)
+ {
+ return buffer[0];
+ }
+ else
+ {
+ return 0;
+ }
}
return buffer[length - index - 1];
}
- uint32_t ByteArray::copyFromArray(uint8_t *array, uint32_t bufferLen) const
+ size_t ByteArray::extract(uint8_t *array, size_t size) const
{
uint32_t min_len = 0;
- if (array == NULL || bufferLen == 0)
+ if (array == NULL || size == 0)
{
- _ERR("invaild param");
- return false;
+ _ERR("invalid param");
+ return min_len;
}
- min_len = (bufferLen < length) ? bufferLen : length;
+ min_len = (size < length) ? size : length;
memcpy(array, buffer, min_len);
return min_len;
}
- ByteArray ByteArray::sub(uint32_t offset, uint32_t size) const
+ const ByteArray ByteArray::sub(size_t offset, size_t size) const
{
- ByteArray newArray;
-
if (length == 0 || offset >= length || (offset + size) > length)
{
_DBG("length is zero");
- return newArray;
+ return ByteArray();
}
- newArray.setBuffer(buffer + offset, size);
-
- return newArray;
+ return ByteArray(buffer + offset, size);
}
- void ByteArray::releaseBuffer()
+ void ByteArray::clear()
{
if (buffer != NULL)
{
/* operator overloading */
ByteArray ByteArray::operator +(const ByteArray &T)
{
- uint32_t newLen;
+ size_t newLen;
uint8_t *newBuffer;
ByteArray newArray;
memcpy(newBuffer, buffer, length);
memcpy(newBuffer + length, T.buffer, T.length);
- newArray._setBuffer(newBuffer, newLen);
+ newArray._assign(newBuffer, newLen);
return newArray;
}
{
if (this != &T)
{
- setBuffer(T.buffer, T.length);
+ assign(T.buffer, T.length);
}
return *this;
return (memcmp(buffer, T.buffer, (length < T.length) ? length : T.length) > 0);
}
- uint8_t &ByteArray::operator [](uint32_t index) const
+ uint8_t ByteArray::operator [](size_t index) const
{
if (index >= length)
{
_ERR("buffer overflow, index [%d], length [%d]", index, length);
- return buffer[length -1];
+ if (length > 0)
+ {
+ return buffer[length -1];
+ }
+ else
+ {
+ return 0;
+ }
}
return buffer[index];
}
-
- const char *ByteArray::toString()
+ const string ByteArray::toString() const
{
- memset(strBuffer, 0, sizeof(strBuffer));
+ stringstream ss;
- if (length == 0)
- {
- snprintf(strBuffer, sizeof(strBuffer), "buffer is empty");
- }
- else
+ if (length > 0)
{
+ char temp[20];
int count;
- int i, offset = 0;
+ int i = 0;
bool ellipsis = false;
count = length;
ellipsis = true;
}
- snprintf(strBuffer + offset, sizeof(strBuffer) - offset, "{ ");
- offset += 2;
+ ss << "{ ";
for (i = 0; i < count; i++)
{
- snprintf(strBuffer + offset, sizeof(strBuffer) - offset, "%02X ", buffer[i]);
- offset += 3;
+ snprintf(temp, sizeof(temp), "%02X ", buffer[i]);
+ ss << temp;
}
if (ellipsis)
{
- snprintf(strBuffer + offset, sizeof(strBuffer) - offset, "... }");
- }
- else
- {
- snprintf(strBuffer + offset, sizeof(strBuffer) - offset, "}");
+ ss << "... ";
}
+
+ ss << "}";
+ }
+ else
+ {
+ ss << "buffer is empty";
}
- return (const char *)strBuffer;
+ return ss.str();
}
void ByteArray::save(const char *filePath)
{
fwrite(buffer, 1, length, file);
fflush(file);
-
fclose(file);
}
else
SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}")
ENDFOREACH(flag)
-#SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -finstrument-functions")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -finstrument-functions")
#SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
#SET(CMAKE_C_FLAGS_RELEASE "-O2")
-#SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -finstrument-functions -std=c++0x")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -finstrument-functions -std=c++0x")
#SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
#SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
}
}
- void DispatcherHelper::pushMessage(DispatcherMsg *msg)
+ void DispatcherHelper::pushMessage(const DispatcherMsg &msg)
{
DispatcherMsg *pushMsg = new DispatcherMsg(msg);
{
}
- EFDIR::EFDIR(Channel *channel, ByteArray selectResponse) :
+ EFDIR::EFDIR(Channel *channel, const ByteArray &selectResponse) :
FileObject(channel, selectResponse)
{
}
return ret;
}
- ByteArray EFDIR::parseRecord(Record &record, ByteArray &aid)
+ const ByteArray EFDIR::parseRecord(const Record &record, const ByteArray &aid)
{
bool matched = false;
ByteArray result;
if (matched == true)
{
- _DBG("Found!! : path %s", result.toString());
+ _DBG("Found!! : path %s", result.toString().c_str());
}
else
{
- result.setBuffer(NULL, 0);
+ result.clear();
}
}
return result;
}
- ByteArray EFDIR::getPathByAID(ByteArray &aid)
+ const ByteArray EFDIR::getPathByAID(const ByteArray &aid)
{
ByteArray result;
Record record;
if (status >= 0)
{
result = parseRecord(record, aid);
- if (result.getLength() > 0)
+ if (result.size() > 0)
break;
}
}
*/
/* standard library header */
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
+#include <sstream>
/* SLP library header */
resetMemberVar();
}
- FCP::FCP(ByteArray &array)
+ FCP::FCP(const ByteArray &array)
{
resetMemberVar();
lcs = FCI::INFO_NOT_AVAILABLE;
}
- bool FCP::setFCP(ByteArray array)
+ bool FCP::setFCP(const ByteArray &array)
{
bool result = false;
SimpleTLV tlv;
releaseFCP();
- if (array.getLength() == 0)
+ if (array.size() == 0)
return false;
fcpBuffer = array;
}
/* parse... */
- tlv.setTLVBuffer(fcpBuffer.getBuffer(), fcpBuffer.getLength());
+ tlv.setTLVBuffer(fcpBuffer.getBuffer(), fcpBuffer.size());
if (tlv.decodeTLV())
{
{
case 0x80 : /* file length without structural information */
{
- _DBG("0x%02X : file length without structural information : %s", tlv.getTag(), tlv.getValue().toString());
- if (tlv.getLength() > 0)
+ _DBG("0x%02X : file length without structural information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
+ if (tlv.size() > 0)
{
fileSize = NumberStream::getBigEndianNumber(tlv.getValue());
}
case 0x81 : /* file length with structural information */
{
- _DBG("0x%02X : file length with structural information : %s", tlv.getTag(), tlv.getValue().toString());
- if (tlv.getLength() > 0)
+ _DBG("0x%02X : file length with structural information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
+ if (tlv.size() > 0)
{
maxRecordSize = NumberStream::getBigEndianNumber(tlv.getValue());
}
case 0x82 : /* file descriptor bytes */
{
- _DBG("0x%02X : file descriptor bytes : %s", tlv.getTag(), tlv.getValue().toString());
+ _DBG("0x%02X : file descriptor bytes : %s", tlv.getTag(), tlv.getValue().toString().c_str());
// ByteArray value = tlv.getValue();
}
break;
case 0x83 : /* file identifier */
{
- _DBG("0x%02X : file identifier : %s", tlv.getTag(), tlv.getValue().toString());
- if (tlv.getLength() > 0)
+ _DBG("0x%02X : file identifier : %s", tlv.getTag(), tlv.getValue().toString().c_str());
+ if (tlv.size() > 0)
{
ByteArray value = tlv.getValue();
fid = 0;
- memcpy(&fid, value.getBuffer(), value.getLength());
+ memcpy(&fid, value.getBuffer(), value.size());
}
}
break;
case 0x84 : /* DF name */
{
- SCARD_DEBUG("0x%02X : DF name : %s", tlv.getTag(), tlv.getValue().toString());
// ByteArray value = tlv.getValue();
}
break;
case 0x85 : /* proprietary information not encoded in BER-TLV */
{
- _DBG("0x%02X : proprietary information not encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString());
+ _DBG("0x%02X : proprietary information not encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString().c_str());
// ByteArray value = tlv.getValue();
}
break;
case 0x86 : /* Security attribute in proprietary format */
{
- SCARD_DEBUG("0x%02X : Security attribute in proprietary format : %s", tlv.getTag(), tlv.getValue().toString());
// ByteArray value = tlv.getValue();
}
break;
case 0x87 : /* Identifier of an EF containing an extension of the file control information */
{
- _DBG("0x%02X : Identifier of an EF containing an extension of the file control information : %s", tlv.getTag(), tlv.getValue().toString());
+ _DBG("0x%02X : Identifier of an EF containing an extension of the file control information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
// ByteArray value = tlv.getValue();
}
break;
case 0x88 : /* Short EF identifier */
{
- _DBG("0x%02X : Short EF identifier : %s", tlv.getTag(), tlv.getValue().toString());
+ _DBG("0x%02X : Short EF identifier : %s", tlv.getTag(), tlv.getValue().toString().c_str());
- if (tlv.getLength() > 0)
+ if (tlv.size() > 0)
{
ByteArray value = tlv.getValue();
sfi = 0;
- memcpy(&sfi, value.getBuffer(), value.getLength());
+ memcpy(&sfi, value.getBuffer(), value.size());
}
}
break;
case 0x8A : /* life cycle status byte */
{
- _DBG("0x%02X : life cycle status byte : %s", tlv.getTag(), tlv.getValue().toString());
- if (tlv.getLength() > 0)
+ _DBG("0x%02X : life cycle status byte : %s", tlv.getTag(), tlv.getValue().toString().c_str());
+ if (tlv.size() > 0)
{
ByteArray value = tlv.getValue();
lcs = 0;
- memcpy(&lcs, value.getBuffer(), value.getLength());
+ memcpy(&lcs, value.getBuffer(), value.size());
}
}
break;
case 0x8B : /* Security attribute referencing the expanded format */
{
- SCARD_DEBUG("0x%02X : Security attribute referencing the expanded format : %s", tlv.getTag(), tlv.getValue().toString());
// ByteArray value = tlv.getValue();
}
break;
case 0x8C : /* Security attribute in compact format */
{
- SCARD_DEBUG("0x%02X : Security attribute in compact format : %s", tlv.getTag(), tlv.getValue().toString());
// ByteArray value = tlv.getValue();
}
break;
case 0x8D : /* Identifier of an EF containing security environment templates */
{
- SCARD_DEBUG("0x%02X : Identifier of an EF containing security environment templates : %s", tlv.getTag(), tlv.getValue().toString());
// ByteArray value = tlv.getValue();
}
break;
case 0x8E : /* Channel security attribute */
{
- SCARD_DEBUG("0x%02X : Channel security attribute : %s", tlv.getTag(), tlv.getValue().toString());
// ByteArray value = tlv.getValue();
}
break;
case 0xA0 : /* Security attribute template for data objects */
{
- SCARD_DEBUG("0x%02X : Security attribute template for data objects : %s", tlv.getTag(), tlv.getValue().toString());
// ByteArray value = tlv.getValue();
}
break;
case 0xA1 : /* Security attribute template in proprietary format */
{
- SCARD_DEBUG("0x%02X : Security attribute template in proprietary format : %s", tlv.getTag(), tlv.getValue().toString());
// ByteArray value = tlv.getValue();
}
break;
case 0xA2 : /* Template consisting of one or more pairs of data objects */
{
- _DBG("0x%02X : Template consisting of one or more pairs of data objects : %s", tlv.getTag(), tlv.getValue().toString());
+ _DBG("0x%02X : Template consisting of one or more pairs of data objects : %s", tlv.getTag(), tlv.getValue().toString().c_str());
// ByteArray value = tlv.getValue();
}
break;
case 0xA5 : /* proprietary information encoded in BER-TLV */
{
- _DBG("0x%02X : proprietary information encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString());
+ _DBG("0x%02X : proprietary information encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString().c_str());
// ByteArray value = tlv.getValue();
}
break;
case 0xAB : /* Security attribute template in expanded format */
{
- SCARD_DEBUG("0x%02X : Security attribute template in expanded format : %s", tlv.getTag(), tlv.getValue().toString());
// ByteArray value = tlv.getValue();
}
break;
case 0xAC : /* Cryptographic mechanism identifier template */
{
- _DBG("0x%02X : Cryptographic mechanism identifier template : %s", tlv.getTag(), tlv.getValue().toString());
+ _DBG("0x%02X : Cryptographic mechanism identifier template : %s", tlv.getTag(), tlv.getValue().toString().c_str());
// ByteArray value = tlv.getValue();
}
break;
case 0xC6 : /* PIN status template DO */
{
- SCARD_DEBUG("0x%02X : PIN status template DO : %s", tlv.getTag(), tlv.getValue().toString());
// ByteArray value = tlv.getValue();
}
break;
default :
{
- _DBG("0x%02X : unknown : %s", tlv.getTag(), tlv.getValue().toString());
+ _DBG("0x%02X : unknown : %s", tlv.getTag(), tlv.getValue().toString().c_str());
}
break;
}
return result;
}
- ByteArray FCP::getFCP()
+ const ByteArray FCP::getFCP() const
{
return fcpBuffer;
}
void FCP::releaseFCP()
{
- fcpBuffer.releaseBuffer();
+ fcpBuffer.clear();
resetMemberVar();
}
- unsigned int FCP::getFileSize()
+ int FCP::getFileSize() const
{
return fileSize;
}
- unsigned int FCP::getTotalFileSize()
+ int FCP::getTotalFileSize() const
{
return totalFileSize;
}
- unsigned int FCP::getFID()
+ int FCP::getFID() const
{
return fid;
}
- unsigned int FCP::getSFI()
+ int FCP::getSFI() const
{
return sfi;
}
- unsigned int FCP::getMaxRecordSize()
+ int FCP::getMaxRecordSize() const
{
return maxRecordSize;
}
- unsigned int FCP::getNumberOfRecord()
+ int FCP::getNumberOfRecord() const
{
return numberOfRecord;
}
- unsigned int FCP::getFileType()
+ int FCP::getFileType() const
{
return fileType;
}
- unsigned int FCP::getFileStructure()
+ int FCP::getFileStructure() const
{
return fileStructure;
}
- unsigned int FCP::getLCS()
+ int FCP::getLCS() const
{
return lcs;
}
- const char *FCP::toString()
+ const string FCP::toString() const
{
- memset(strBuffer, 0, sizeof(strBuffer));
+ stringstream ss;
- snprintf(strBuffer, sizeof(strBuffer), "size [%d], total size [%d], fid [%x], sfi [%x], max rec [%d], n of rec [%d], type [%d], struct [%d], lcs [%d]",
- getFileSize(), getTotalFileSize(), getFID(), getSFI(), getMaxRecordSize(), getNumberOfRecord(), getFileType(), getFileStructure(), getLCS());
+ if (fileSize != FCI::INFO_NOT_AVAILABLE)
+ ss << "size [" << fileSize << "], ";
- return (const char *)strBuffer;
+ if (totalFileSize != FCI::INFO_NOT_AVAILABLE)
+ ss << "total size [" << totalFileSize << "], ";
+
+ if (fid != FCI::INFO_NOT_AVAILABLE)
+ ss << "fid [" << fid << "], ";
+
+ if (sfi != FCI::INFO_NOT_AVAILABLE)
+ ss << "sfi [" << sfi << "], ";
+
+ if (maxRecordSize != FCI::INFO_NOT_AVAILABLE)
+ ss << "max rec. [" << maxRecordSize << "], ";
+
+ if (numberOfRecord != FCI::INFO_NOT_AVAILABLE)
+ ss << "n of rec [" << numberOfRecord << "], ";
+
+ if (fileType != FCI::INFO_NOT_AVAILABLE)
+ ss << "type [" << fileType << "], ";
+
+ if (fileStructure != FCI::INFO_NOT_AVAILABLE)
+ ss << "struct [" << fileStructure << "], ";
+
+ if (lcs != FCI::INFO_NOT_AVAILABLE)
+ ss << "lcs [" << lcs << "], ";
+
+ return ss.str();
}
{
}
- bool FCI::setFCIBuffer(ByteArray array)
+ bool FCI::setFCIBuffer(const ByteArray &array)
{
bool result = false;
void FileObject::close()
{
opened = false;
- selectResponse.releaseBuffer();
+ selectResponse.clear();
}
bool FileObject::setSelectResponse(const ByteArray &response)
{
bool result = false;
- if (response.getLength() >= 2)
+ if (response.size() >= 2)
{
ResponseHelper resp(response);
selectResponse = response;
fcp.setFCP(resp.getDataField());
- _DBG("FCP : %s", fcp.toString());
+ _DBG("FCP : %s", fcp.toString().c_str());
opened = true;
result = true;
else
{
_ERR("select apdu is failed, rv [%d], length [%d]",
- ret, result.getLength());
+ ret, result.size());
ret = ERROR_ILLEGAL_STATE;
}
{
ByteArray temp(path);
- if (path.getLength() > 2 && path[0] == 0x3f && path[1] == 0x00) /* check MF */
+ if (path.size() > 2 && path[0] == 0x3f && path[1] == 0x00) /* check MF */
{
/* remove MF from path */
- temp.setBuffer(path.getBuffer(2), path.getLength() - 2);
+ temp.assign(path.getBuffer(2), path.size() - 2);
}
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_PATH, 0, temp);
return ret;
}
- FCI *FileObject::getFCI()
+ const FCI *FileObject::getFCI() const
{
return NULL;
}
- FCP *FileObject::getFCP()
+ const FCP *FileObject::getFCP() const
{
return &fcp;
}
apdu.getBuffer(command);
ret = channel->transmitSync(command, response);
- if (ret == 0 && response.getLength() >= 2)
+ if (ret == 0 && response.size() >= 2)
{
ResponseHelper resp(response);
ret = resp.getStatus();
if (ret >= 0)
{
- _DBG("response [%d] : %s", response.getLength(), response.toString());
+ _DBG("response [%d] : %s", response.size(), response.toString().c_str());
result = Record(recordId, resp.getDataField());
}
}
else
{
- _ERR("select apdu is failed, rv [%d], length [%d]", ret, response.getLength());
+ _ERR("select apdu is failed, rv [%d], length [%d]", ret, response.size());
}
return ret;
apdu.getBuffer(command);
ret = channel->transmitSync(command, response);
- if (ret == 0 && response.getLength() >= 2)
+ if (ret == 0 && response.size() >= 2)
{
ResponseHelper resp(response);
if (resp.getStatus() >= 0)
{
- _DBG("response [%d] : %s", response.getLength(), response.toString());
+ _DBG("response [%d] : %s", response.size(), response.toString().c_str());
result = resp.getDataField();
}
else
{
- _ERR("select apdu is failed, rv [%d], length [%d]", ret, response.getLength());
+ _ERR("select apdu is failed, rv [%d], length [%d]", ret, response.size());
}
return ret;
apdu.getBuffer(command);
ret = channel->transmitSync(command, response);
- if (ret == 0 && response.getLength() >= 2)
+ if (ret == 0 && response.size() >= 2)
{
ResponseHelper resp(response);
if (resp.getStatus() >= 0)
{
- _DBG("response [%d] : %s", response.getLength(), response.toString());
+ _DBG("response [%d] : %s", response.size(), response.toString().c_str());
ret = SUCCESS;
}
}
else
{
- _ERR("select apdu is failed, rv [%d], length [%d]", ret, response.getLength());
+ _ERR("select apdu is failed, rv [%d], length [%d]", ret, response.size());
}
return ret;
namespace smartcard_service_api
{
- GDBusHelper::GDBusHelper()
- {
- }
-
- GDBusHelper::~GDBusHelper()
- {
- }
-
void GDBusHelper::convertVariantToByteArray(GVariant *var,
ByteArray &array)
{
g_variant_iter_free(iter);
- array.setBuffer((uint8_t *)buf, (uint32_t)i);
+ array.assign((uint8_t *)buf, (uint32_t)i);
g_free(buf);
}
g_variant_builder_init(&builder, G_VARIANT_TYPE("a(y)"));
- for (i = 0; i < array.getLength(); i++)
+ for (i = 0; i < array.size(); i++)
g_variant_builder_add(&builder, "(y)", array[i]);
return g_variant_builder_end(&builder);
return result;
}
- bool GPACE::isAuthorizedAccess(ByteArray &aid,
- ByteArray &certHash)
+ bool GPACE::isAuthorizedAccess(const ByteArray &aid,
+ const ByteArray &certHash) const
{
return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHash) : false;
}
- bool GPACE::isAuthorizedAccess(unsigned char *aidBuffer,
- unsigned int aidLength, unsigned char *certHashBuffer,
- unsigned int certHashLength)
+ bool GPACE::isAuthorizedAccess(const unsigned char *aidBuffer,
+ unsigned int aidLength, const unsigned char *certHashBuffer,
+ unsigned int certHashLength) const
{
return (acl != NULL) ? acl->isAuthorizedAccess(aidBuffer, aidLength, certHashBuffer, certHashLength) : false;
}
- bool GPACE::isAuthorizedAccess(ByteArray &aid,
- vector<ByteArray> &certHashes)
+ bool GPACE::isAuthorizedAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const
{
return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHashes) : false;
}
- bool GPACE::isAuthorizedAccess(ByteArray &aid,
- vector<ByteArray> &certHashes, ByteArray &command)
+ bool GPACE::isAuthorizedAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes,
+ const ByteArray &command) const
{
return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHashes, command) : false;
}
- bool GPACE::isAuthorizedNFCAccess(ByteArray &aid,
- vector<ByteArray> &certHashes)
+ bool GPACE::isAuthorizedNFCAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const
{
return (acl != NULL) ? acl->isAuthorizedNFCAccess(aid, certHashes) : false;
}
if (tlv.decodeTLV() == true) {
switch (tlv.getTag()) {
case DO_TAG_AID_REF :
- if (tlv.getLength() > 0) {
+ if (tlv.size() > 0) {
result = tlv.getValue();
} else {
result = AccessControlList::ALL_SE_APPS;
break;
default :
- _ERR("decodeTLV failed, %s", tlv.toString());
+ _ERR("decodeTLV failed, %s", tlv.toString().c_str());
break;
}
} else {
- _ERR("decodeTLV failed, %s", tlv.toString());
+ _ERR("decodeTLV failed, %s", tlv.toString().c_str());
}
_END();
if (tlv.decodeTLV() == true &&
tlv.getTag() == DO_TAG_HASH_REF) {
- if (tlv.getLength() > 0) {
+ if (tlv.size() > 0) {
result = tlv.getValue();
} else {
result = AccessControlList::ALL_DEVICE_APPS;
}
} else {
- _ERR("decodeTLV failed, %s", tlv.toString());
+ _ERR("decodeTLV failed, %s", tlv.toString().c_str());
}
_END();
hash = getHash(tlv);
tlv.returnToParentTLV();
- _DBG("aid : %s, hash : %s", aid.toString(), hash.toString());
+ _DBG("aid : %s, hash : %s", aid.toString().c_str(), hash.toString().c_str());
} else {
- _ERR("unknown tag : %s", tlv.toString());
+ _ERR("unknown tag : %s", tlv.toString().c_str());
result = SCARD_ERROR_ILLEGAL_PARAM;
}
if (tlv.decodeTLV() == true && tlv.getTag() == DO_TAG_AR) {
tlv.enterToValueTLV();
while (tlv.decodeTLV() == true) {
- int length = tlv.getLength();
+ int length = tlv.size();
switch (tlv.getTag()) {
case DO_TAG_APDU_AR :
ByteArray temp;
for (i = 0; i < length; i += 8) {
- temp.setBuffer(tlv.getValue().getBuffer(i), 8);
- _DBG("apdu rule[%d] : %s", temp.getLength(), temp.toString());
+ temp.assign(tlv.getValue().getBuffer(i), 8);
+ _DBG("apdu rule[%d] : %s", temp.size(), temp.toString().c_str());
apduRule.push_back(temp);
}
} else if (length == 1){
- _DBG("apdu rule : %s", tlv.getValue().toString());
+ _DBG("apdu rule : %s", tlv.getValue().toString().c_str());
apduRule.push_back(tlv.getValue());
} else {
- _ERR("invalid rule, %s", tlv.toString());
+ _ERR("invalid rule, %s", tlv.toString().c_str());
}
break;
case DO_TAG_NFC_AR :
nfcRule = tlv.getValue();
- _DBG("nfc rule : %s", tlv.getValue().toString());
+ _DBG("nfc rule : %s", tlv.getValue().toString().c_str());
break;
default :
if (apduRule.size() > 0) {
if (apduRule.size() == 1 &&
- apduRule[0].getLength() == 1) {
+ apduRule[0].size() == 1) {
/* apdu grant/deny */
if (apduRule[0][0] == 1) {
condition.setAPDUAccessRule(hash, true);
}
}
- if (nfcRule.getLength() == 1) {
+ if (nfcRule.size() == 1) {
if (nfcRule[0] == 1) {
condition.setNFCAccessRule(hash, true);
} else {
_END();
}
- int GPARAACL::updateRule(ByteArray &data)
+ int GPARAACL::updateRule(const ByteArray &data)
{
int result = SCARD_ERROR_OK;
SimpleTLV tlv(data);
return result;
}
- static bool _isAuthorizedAccess(ByteArray &data, ByteArray &command)
+ static bool _isAuthorizedAccess(const ByteArray &data, const ByteArray &command)
{
vector<ByteArray> apduRule;
ByteArray nfcRule;
if (parseARDO(tlv, apduRule, nfcRule) >= SCARD_ERROR_OK) {
if (apduRule.size() > 0) {
if (apduRule.size() > 1 ||
- apduRule[0].getLength() != 1) {
- if (command.getLength() > 0) {
+ apduRule[0].size() != 1) {
+ if (command.size() > 0) {
/* TODO : check apdu rule */
} else {
/* check hash only */
result = (apduRule[0][0] == 1 ? true : false);
}
} else {
- _ERR("unknown data : %s", tlv.toString());
+ _ERR("unknown data : %s", tlv.toString().c_str());
}
} else {
- _ERR("parseARDO failed : %s", tlv.toString());
+ _ERR("parseARDO failed : %s", tlv.toString().c_str());
}
return result;
}
- static bool _isAuthorizedNFCAccess(ByteArray &data)
+ static bool _isAuthorizedNFCAccess(const ByteArray &data)
{
vector<ByteArray> apduRule;
ByteArray nfcRule;
bool result = false;
if (parseARDO(tlv, apduRule, nfcRule) >= SCARD_ERROR_OK) {
- if (nfcRule.getLength() == 1) {
+ if (nfcRule.size() == 1) {
result = (nfcRule[0] == 1 ? true : false);
} else {
- _ERR("unknown data : %s", nfcRule.toString());
+ _ERR("unknown data : %s", nfcRule.toString().c_str());
}
} else {
- _ERR("parseARDO failed : %s", tlv.toString());
+ _ERR("parseARDO failed : %s", tlv.toString().c_str());
}
return result;
}
- bool GPARAACL::isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
- ByteArray &certHash)
+ bool GPARAACL::isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+ const ByteArray &certHash) const
{
vector<ByteArray> hashes;
return isAuthorizedAccess(aram, aid, hashes, ByteArray::EMPTY);
}
- bool GPARAACL::isAuthorizedAccess(GPARAM &aram, unsigned char *aidBuffer,
- unsigned int aidLength, unsigned char *certHashBuffer,
- unsigned int certHashLength)
+ bool GPARAACL::isAuthorizedAccess(GPARAM &aram,
+ const unsigned char *aidBuffer,
+ unsigned int aidLength,
+ const unsigned char *certHashBuffer,
+ unsigned int certHashLength) const
{
ByteArray aid(aidBuffer, aidLength);
ByteArray hash(certHashBuffer, certHashLength);
return isAuthorizedAccess(aram, aid, hash);
}
- bool GPARAACL::isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
- vector<ByteArray> &certHashes)
+ bool GPARAACL::isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const
{
return isAuthorizedAccess(aram, aid, certHashes, ByteArray::EMPTY);
}
- bool GPARAACL::isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
- vector<ByteArray> &certHashes, ByteArray &command)
+ bool GPARAACL::isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+ const vector<ByteArray> &certHashes, const ByteArray &command) const
{
bool result = allGranted;
ByteArray data;
- vector<ByteArray>::reverse_iterator item;
+ vector<ByteArray>::const_reverse_iterator item;
if (aram.isClosed() == true)
return result;
result == false && item != certHashes.rend();
item++) {
if (aram.getDataSpecific(aid, *item, data)
- >= SCARD_ERROR_OK && data.getLength() > 0) {
+ >= SCARD_ERROR_OK && data.size() > 0) {
result = _isAuthorizedAccess(data, command);
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), (*item).toString());
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), (*item).toString().c_str());
goto END;
}
}
/* Step B, find with aid and ALL_DEVICES_APPS */
if (aram.getDataSpecific(aid, ByteArray::EMPTY, data)
- >= SCARD_ERROR_OK && data.getLength() > 0) {
+ >= SCARD_ERROR_OK && data.size() > 0) {
result = _isAuthorizedAccess(data, command);
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), "All device applications");
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), "All device applications");
goto END;
}
result == false && item != certHashes.rend();
item++) {
if (aram.getDataSpecific(ByteArray::EMPTY, *item, data)
- >= SCARD_ERROR_OK && data.getLength() > 0) {
+ >= SCARD_ERROR_OK && data.size() > 0) {
result = _isAuthorizedAccess(data, command);
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString());
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString().c_str());
goto END;
}
}
/* Step D, find with ALL_SE_APPS and ALL_DEVICES_APPS */
if (aram.getDataSpecific(ByteArray::EMPTY, ByteArray::EMPTY, data)
- >= SCARD_ERROR_OK && data.getLength() > 0) {
+ >= SCARD_ERROR_OK && data.size() > 0) {
result = _isAuthorizedAccess(data, command);
_INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", "All device applications");
goto END;
return result;
}
- bool GPARAACL::isAuthorizedNFCAccess(GPARAM &aram, ByteArray &aid,
- vector<ByteArray> &certHashes)
+ bool GPARAACL::isAuthorizedNFCAccess(GPARAM &aram, const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const
{
bool result = allGranted;
ByteArray data;
- vector<ByteArray>::reverse_iterator item;
+ vector<ByteArray>::const_reverse_iterator item;
if (aram.isClosed() == true)
return result;
result == false && item != certHashes.rend();
item++) {
if (aram.getDataSpecific(aid, *item, data)
- >= SCARD_ERROR_OK && data.getLength() > 0) {
+ >= SCARD_ERROR_OK && data.size() > 0) {
result = _isAuthorizedNFCAccess(data);
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), (*item).toString());
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), (*item).toString().c_str());
goto END;
}
}
/* Step B, find with aid and ALL_DEVICES_APPS */
if (aram.getDataSpecific(aid, ByteArray::EMPTY, data)
- >= SCARD_ERROR_OK && data.getLength() > 0) {
+ >= SCARD_ERROR_OK && data.size() > 0) {
result = _isAuthorizedNFCAccess(data);
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), "All device applications");
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), "All device applications");
goto END;
}
result == false && item != certHashes.rend();
item++) {
if (aram.getDataSpecific(ByteArray::EMPTY, *item, data)
- >= SCARD_ERROR_OK && data.getLength() > 0) {
+ >= SCARD_ERROR_OK && data.size() > 0) {
result = _isAuthorizedNFCAccess(data);
- _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString());
+ _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString().c_str());
goto END;
}
}
/* Step D, find with ALL_SE_APPS and ALL_DEVICES_APPS */
if (aram.getDataSpecific(ByteArray::EMPTY, ByteArray::EMPTY, data)
- >= SCARD_ERROR_OK && data.getLength() > 0) {
+ >= SCARD_ERROR_OK && data.size() > 0) {
result = _isAuthorizedNFCAccess(data);
_INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", "All device applications");
goto END;
result = ResponseHelper::getStatus(resp);
if (result >= SCARD_ERROR_OK) {
response = ResponseHelper::getDataField(resp);
- _DBG("response[%d] : %s", response.getLength(), response.toString());
+ _DBG("response[%d] : %s", response.size(), response.toString().c_str());
} else {
_ERR("transmit returns error, [%d]", result);
}
helper.getBuffer(cmd);
- _DBG("command[%d] : %s", cmd.getLength(), cmd.toString());
+ _DBG("command[%d] : %s", cmd.size(), cmd.toString().c_str());
result = doTransmit(channel, cmd, response);
if (tlv.decodeTLV() == true &&
tlv.getTag() == ARAM_TAG_ALL_AR) {
- unsigned int length = tlv.getLength();
+ unsigned int length = tlv.size();
if (length > 0){
data = tlv.getValue();
- while (length > data.getLength()) {
+ while (length > data.size()) {
result = doCommand(channel, GET_DATA_NEXT, response);
if (result >= SCARD_ERROR_OK) {
data += response;
} else {
_ERR("generateCommand failed, [%d]", result);
- data.releaseBuffer();
+ data.clear();
break;
}
}
- _DBG("data[%d] : %s", data.getLength(), data.toString());
+ _DBG("data[%d] : %s", data.size(), data.toString().c_str());
} else {
_INFO("Response-ALL-AR-DO is empty");
- data.releaseBuffer();
+ data.clear();
}
} else {
- _ERR("decodeTLV failed, %s", response.toString());
+ _ERR("decodeTLV failed, %s", response.toString().c_str());
result = SCARD_ERROR_ILLEGAL_PARAM;
}
} else {
temp += SimpleTLV::encode(DO_TAG_HASH_REF, hash);
refDo = SimpleTLV::encode(DO_TAG_REF, temp);
- _DBG("encoded Ref DO : %s", refDo.toString());
+ _DBG("encoded Ref DO : %s", refDo.toString().c_str());
return SCARD_ERROR_OK;
}
if (tlv.decodeTLV() == true &&
tlv.getTag() == ARAM_TAG_AR) {
- unsigned int length = tlv.getLength();
+ unsigned int length = tlv.size();
if (length > 0){
data = tlv.getValue();
- while (length > data.getLength()) {
+ while (length > data.size()) {
result = doCommand(channel, GET_DATA_NEXT, response);
if (result >= SCARD_ERROR_OK) {
data += response;
} else {
_ERR("generateCommand failed, [%d]", result);
- data.releaseBuffer();
+ data.clear();
break;
}
}
- _DBG("data[%d] : %s", data.getLength(), data.toString());
+ _DBG("data[%d] : %s", data.size(), data.toString().c_str());
} else {
_INFO("Response-ALL-AR-DO is empty");
- data.releaseBuffer();
+ data.clear();
}
} else {
- _ERR("decodeTLV failed, %s", response.toString());
+ _ERR("decodeTLV failed, %s", response.toString().c_str());
result = SCARD_ERROR_ILLEGAL_PARAM;
}
} else {
if (tlv.decodeTLV() == true &&
tlv.getTag() == ARAM_TAG_REFRESH &&
- tlv.getLength() == 8) {
+ tlv.size() == 8) {
tag = tlv.getValue();
result = SCARD_ERROR_OK;
- _DBG("refreshTag[%d] : %s", tag.getLength(), tag.toString());
+ _DBG("refreshTag[%d] : %s", tag.size(), tag.toString().c_str());
} else {
- _ERR("decodeTLV failed, %s", response.toString());
+ _ERR("decodeTLV failed, %s", response.toString().c_str());
result = SCARD_ERROR_ILLEGAL_PARAM;
}
} else {
ByteArray data;
FileObject file(channel);
- _DBG("oid path : %s", path.toString());
+ _DBG("oid path : %s", path.toString().c_str());
file.select(NumberStream::getLittleEndianNumber(path));
file.readBinary(0, 0, file.getFCP()->getFileSize(), data);
- _DBG("data : %s", data.toString());
+ _DBG("data : %s", data.toString().c_str());
/* PKCS #15 and DODF OID exists. apply access control rule!! */
allGranted = false;
ByteArray refreshTag;
refreshTag = SimpleTLV::getOctetString(tlv);
- _DBG("current refresh tag : %s", refreshTag.toString());
+ _DBG("current refresh tag : %s", refreshTag.toString().c_str());
if (this->refreshTag != refreshTag) /* need to update access control list */
{
/* OCTET STRING */
path = SimpleTLV::getOctetString(tlv.getValue());
- _DBG("access control rule path : %s", path.toString());
+ _DBG("access control rule path : %s", path.toString().c_str());
if (loadRules(channel, path) == 0)
{
file.select(NumberStream::getLittleEndianNumber(path));
file.readBinary(0, 0, file.getFCP()->getFileSize(), data);
- _DBG("data : %s", data.toString());
+ _DBG("data : %s", data.toString().c_str());
SimpleTLV tlv(data);
break;
}
- _DBG("aid : %s", aid.toString());
+ _DBG("aid : %s", aid.toString().c_str());
/* access condition path */
if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Path */
/* OCTET STRING */
path = SimpleTLV::getOctetString(tlv.getValue());
- _DBG("path : %s", path.toString());
+ _DBG("path : %s", path.toString().c_str());
if (loadAccessConditions(channel, aid, path) == 0)
{
value = tlv.getValue();
- _DBG("APDU rule : %s", value.toString());
+ _DBG("APDU rule : %s", value.toString().c_str());
- if (value.getLength() == 8) /* apdu 4 bytes + mask 4 bytes */
+ if (value.size() == 8) /* apdu 4 bytes + mask 4 bytes */
{
- apdu.setBuffer(value.getBuffer(), 4);
- mask.setBuffer(value.getBuffer(4), 4);
+ apdu.assign(value.getBuffer(), 4);
+ mask.assign(value.getBuffer(4), 4);
rule->addAPDUAccessRule(apdu, mask);
}
else
{
- _ERR("Invalid APDU rule : %s", value.toString());
+ _ERR("Invalid APDU rule : %s", value.toString().c_str());
}
}
else
static void loadAccessCondition(AccessCondition &condition, const ByteArray &data)
{
- if (data.getLength() > 0)
+ if (data.size() > 0)
{
SimpleTLV tlv(data);
ByteArray hash;
while (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE */
{
- if (tlv.getLength() > 0)
+ if (tlv.size() > 0)
{
/* access granted for specific applications */
tlv.enterToValueTLV();
switch (tlv.getTag())
{
case 0x04 : /* OCTET STRING : CertHash */
- _DBG("aid : %s, hash : %s", condition.getAID().toString(), tlv.getValue().toString());
+ _DBG("aid : %s, hash : %s", condition.getAID().toString().c_str(), tlv.getValue().toString().c_str());
hash = tlv.getValue();
condition.addAccessRule(tlv.getValue());
}
else
{
- _INFO("access denied for all applications, aid : %s", condition.getAID().toString());
+ _INFO("access denied for all applications, aid : %s", condition.getAID().toString().c_str());
condition.setAccessCondition(false);
break;
}
else
{
- _INFO("access denied for all applications, aid : %s", condition.getAID().toString());
+ _INFO("access denied for all applications, aid : %s", condition.getAID().toString().c_str());
condition.setAccessCondition(false);
}
file.select(NumberStream::getLittleEndianNumber(path));
file.readBinary(0, 0, file.getFCP()->getFileSize(), data);
- _DBG("data : %s", data.toString());
+ _DBG("data : %s", data.toString().c_str());
AccessCondition condition;
}
}
- bool IPCHelper::sendMessage(int socket, Message *msg)
+ bool IPCHelper::sendMessage(int socket, const Message &msg)
{
ByteArray stream;
unsigned int length = 0;
- stream = msg->serialize();
- length = stream.getLength();
+ stream = msg.serialize();
+ length = stream.size();
_DBG(">>>[SEND]>>> socket [%d], msg [%d], length [%d]",
- socket, msg->message, stream.getLength());
+ socket, msg.message, stream.size());
return sendMessage(socket, stream);
}
- bool IPCHelper::sendMessage(int socket, ByteArray &buffer)
+ bool IPCHelper::sendMessage(int socket, const ByteArray &buffer)
{
bool result = false;
unsigned int length = 0;
- length = buffer.getLength();
+ length = buffer.size();
if (length > 0)
{
_BEGIN();
buffer = retrieveBuffer(socket);
- if (buffer.getLength() > 0)
+ if (buffer.size() > 0)
{
msg = new Message();
if (msg != NULL)
return msg;
}
- ByteArray IPCHelper::retrieveBuffer(int socket)
+ const ByteArray IPCHelper::retrieveBuffer(int socket)
{
ByteArray buffer;
unsigned int length = 0;
_DBG("<<<[RETRIEVE]<<< socket [%d], msg_length [%d]", socket, length);
- buffer.setBuffer(temp, length);
+ buffer.assign(temp, length);
delete []temp;
}
namespace smartcard_service_api
{
- ISO7816BERTLV::ISO7816BERTLV()
- : TLVHelper()
+ ISO7816BERTLV::ISO7816BERTLV() : TLVHelper(), firstByte(0), tagClass(0),
+ encoding(0)
{
- tagClass = 0;
- encoding = 0;
}
- ISO7816BERTLV::ISO7816BERTLV(TLVHelper *parent)
- : TLVHelper(parent)
+ ISO7816BERTLV::ISO7816BERTLV(TLVHelper *parent) : TLVHelper(parent),
+ firstByte(0), tagClass(0), encoding(0)
{
- parentTLV = parent;
-
- tagClass = 0;
- encoding = 0;
}
- ISO7816BERTLV::ISO7816BERTLV(const ByteArray &array)
- : TLVHelper(array)
+ ISO7816BERTLV::ISO7816BERTLV(const ByteArray &array) : TLVHelper(array),
+ firstByte(0), tagClass(0), encoding(0)
{
- tagClass = 0;
- encoding = 0;
}
- ISO7816BERTLV::ISO7816BERTLV(const ByteArray &array, TLVHelper *parent)
- : TLVHelper(array, parent)
+ ISO7816BERTLV::ISO7816BERTLV(const ByteArray &array, TLVHelper *parent) :
+ TLVHelper(array, parent), firstByte(0), tagClass(0), encoding(0)
{
- parentTLV = parent;
-
- tagClass = 0;
- encoding = 0;
}
ISO7816BERTLV::~ISO7816BERTLV()
}
}
- int ISO7816BERTLV::decodeTag(unsigned char *buffer)
+ int ISO7816BERTLV::decodeTag(const unsigned char *buffer)
{
/* 0x00 is invalid tag value */
if (buffer[0] == 0x00)
return 2;
}
- int ISO7816BERTLV::decodeLength(unsigned char *buffer)
+ int ISO7816BERTLV::decodeLength(const unsigned char *buffer)
{
if (buffer[0] & 0x80)
{
}
}
- int ISO7816BERTLV::decodeValue(unsigned char *buffer)
+ int ISO7816BERTLV::decodeValue(const unsigned char *buffer)
{
if (currentL == 0)
return 0;
- currentV.setBuffer(buffer, currentL);
+ currentV.assign(buffer, currentL);
return currentL;
}
- unsigned int ISO7816BERTLV::getClass()
+ unsigned int ISO7816BERTLV::getClass() const
{
return tagClass;
}
- unsigned int ISO7816BERTLV::getEncoding()
+ unsigned int ISO7816BERTLV::getEncoding() const
{
return encoding;
}
- ByteArray ISO7816BERTLV::encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, ByteArray buffer)
+ const ByteArray ISO7816BERTLV::encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, const ByteArray &buffer)
{
unsigned char temp_tag[3] = { 0, };
unsigned char temp_tag_len = 0;
total_len += temp_tag_len;
/* add length's length */
- if (buffer.getLength() < 128)
+ if (buffer.size() < 128)
{
- temp_len[0] = buffer.getLength();
+ temp_len[0] = buffer.size();
temp_len_len = 1;
}
temp_len[0] = 0x80;
temp_len_len = 1;
- if (buffer.getLength() > 0x00FFFFFF)
+ if (buffer.size() > 0x00FFFFFF)
{
- temp_len[4] = (buffer.getLength() & 0xFF000000) >> 24;
+ temp_len[4] = (buffer.size() & 0xFF000000) >> 24;
temp_len_len++;
}
- if (buffer.getLength() > 0x0000FFFF)
+ if (buffer.size() > 0x0000FFFF)
{
- temp_len[3] = (buffer.getLength() & 0x00FF0000) >> 16;
+ temp_len[3] = (buffer.size() & 0x00FF0000) >> 16;
temp_len_len++;
}
- if (buffer.getLength() > 0x000000FF)
+ if (buffer.size() > 0x000000FF)
{
- temp_len[2] = (buffer.getLength() & 0x0000FF00) >> 8;
+ temp_len[2] = (buffer.size() & 0x0000FF00) >> 8;
temp_len_len++;
}
- temp_len[1] = buffer.getLength() & 0x000000FF;
+ temp_len[1] = buffer.size() & 0x000000FF;
temp_len_len++;
temp_len[0] |= temp_len_len;
}
/* add buffer's length */
- total_len += buffer.getLength();
+ total_len += buffer.size();
/* alloc new buffer */
temp_buffer = new unsigned char[total_len];
current += temp_len_len;
/* fill value */
- if (buffer.getLength() > 0)
- memcpy(temp_buffer + current, buffer.getBuffer(), buffer.getLength());
+ if (buffer.size() > 0)
+ memcpy(temp_buffer + current, buffer.getBuffer(), buffer.size());
- result.setBuffer(temp_buffer, total_len);
+ result.assign(temp_buffer, total_len);
delete []temp_buffer;
return result;
}
- ByteArray ISO7816BERTLV::encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, unsigned char *buffer, unsigned int length)
+ const ByteArray ISO7816BERTLV::encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, unsigned char *buffer, unsigned int length)
{
return encode(tagClass, encoding, tag, ByteArray(buffer, length));
}
- TLVHelper *ISO7816BERTLV::getChildTLV(ByteArray data)
+ TLVHelper *ISO7816BERTLV::getChildTLV(const ByteArray &data)
{
if (childTLV != NULL)
{
#ifndef USE_GDBUS
/* standard library header */
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
+#include <sstream>
/* SLP library header */
{
}
- ByteArray Message::serialize()
+ const ByteArray Message::serialize() const
{
ByteArray result;
unsigned int length = 0;
unsigned char *buffer = NULL;
length = sizeof(message) + sizeof(param1) + sizeof(param2) + sizeof(error) + sizeof(caller) + sizeof(callback) + sizeof(userParam);
- if (data.getLength() > 0)
+ if (data.size() > 0)
{
- dataLength = data.getLength();
- length += sizeof(dataLength) + data.getLength();
+ dataLength = data.size();
+ length += sizeof(dataLength) + data.size();
}
buffer = new unsigned char[length];
memcpy(buffer + current, &userParam, sizeof(userParam));
current += sizeof(userParam);
- if (data.getLength() > 0)
+ if (data.size() > 0)
{
memcpy(buffer + current, &dataLength, sizeof(dataLength));
current += sizeof(dataLength);
memcpy(buffer + current, data.getBuffer(), dataLength);
- current += data.getLength();
+ current += data.size();
}
- result.setBuffer(buffer, length);
+ result.assign(buffer, length);
delete []buffer;
}
return result;
}
- void Message::deserialize(ByteArray buffer)
+ void Message::deserialize(const ByteArray &buffer)
{
- deserialize(buffer.getBuffer(), buffer.getLength());
+ deserialize(buffer.getBuffer(), buffer.size());
}
- void Message::deserialize(unsigned char *buffer, unsigned int length)
+ void Message::deserialize(const unsigned char *buffer, unsigned int length)
{
unsigned int current = 0;
unsigned int dataLength = 0;
// _DBG("dataLength [%d]", dataLength);
- data.setBuffer(buffer + current, dataLength);
+ data.assign(buffer + current, dataLength);
current += dataLength;
}
}
- const char *Message::toString()
+ const string Message::toString() const
{
+ stringstream ss;
const char *msg = NULL;
- memset(&text, 0, sizeof(text));
-
switch (message)
{
case MSG_REQUEST_READERS :
break;
}
- snprintf(text, sizeof(text), "Message [%s, %d], param1 [%d], param2 [%d], error [%d], caller [%p], callback [%p], userParam [%p], data length [%d]", msg, message, param1, param2, error, caller, callback, userParam, data.getLength());
+ ss << "Message [" << msg << ", " << message << "], param1 [" << param1 << "], param2 [" << param2 << "], error [" << error << "], caller [" << "], callback [" << callback << "], userParam [" << userParam << "], data length [" << data.size() << "]";
- return (const char *)text;
+ return ss.str();
}
} /* namespace smartcard_service_api */
{
NumberStream::NumberStream(const ByteArray &T)
{
- setBuffer(T.getBuffer(), T.getLength());
+ assign(T.getBuffer(), T.size());
}
- unsigned int NumberStream::getBigEndianNumber()
+ unsigned int NumberStream::getBigEndianNumber() const
{
return getBigEndianNumber(*this);
}
- unsigned int NumberStream::getLittleEndianNumber()
+ unsigned int NumberStream::getLittleEndianNumber() const
{
return getLittleEndianNumber(*this);
}
{
if (this != &T)
{
- setBuffer(T.getBuffer(), T.getLength());
+ assign(T.getBuffer(), T.size());
}
return *this;
{
if (this != &T)
{
- setBuffer(T.getBuffer(), T.getLength());
+ assign(T.getBuffer(), T.size());
}
return *this;
int i, len;
unsigned int result = 0;
- len = (T.getLength() < 4) ? T.getLength() : 4;
+ len = (T.size() < 4) ? T.size() : 4;
for (i = 0; i < len; i++)
{
- result = (result << 8) | T.getAt(i);
+ result = (result << 8) | T.at(i);
}
return result;
int i, len;
unsigned int result = 0;
- len = (T.getLength() < 4) ? T.getLength() : 4;
+ len = (T.size() < 4) ? T.size() : 4;
for (i = 0; i < len; i++)
{
- result = result | (T.getAt(i) << (i * 8));
+ result = result | (T.at(i) << (i * 8));
}
return result;
BUF_MEM *bptr;
BIO *b64, *bmem;
- if (buffer.getLength() == 0)
+ if (buffer.size() == 0)
{
return ret;
}
b64 = BIO_push(b64, bmem);
- BIO_write(b64, buffer.getBuffer(), buffer.getLength());
+ BIO_write(b64, buffer.getBuffer(), buffer.size());
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
- result.setBuffer((unsigned char *)bptr->data, bptr->length);
+ result.assign((unsigned char *)bptr->data, bptr->length);
BIO_free_all(b64);
{
ByteArray temp;
- temp.setBuffer((unsigned char *)buffer, strlen(buffer));
+ temp.assign((unsigned char *)buffer, strlen(buffer));
return decodeBase64String(temp, result, newLineChar);
}
unsigned int length = 0;
char *temp;
- if (buffer.getBuffer() == NULL || buffer.getLength() == 0)
+ if (buffer.getBuffer() == NULL || buffer.size() == 0)
{
return ret;
}
- length = buffer.getLength();
+ length = buffer.size();
temp = new char[length];
if (temp != NULL)
memset(temp, 0, length);
b64 = BIO_new(BIO_f_base64());
- bmem = BIO_new_mem_buf(buffer.getBuffer(), length);
+ bmem = BIO_new_mem_buf((void *)buffer.getBuffer(), length);
if (newLineChar == false)
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
bmem = BIO_push(b64, bmem);
BIO_free_all(bmem);
- result.setBuffer((unsigned char *)temp, length);
+ result.assign((unsigned char *)temp, length);
delete []temp;
return ret;
}
- bool OpensslHelper::digestBuffer(const char *algorithm, const uint8_t *buffer, const uint32_t length, ByteArray &result)
+ bool OpensslHelper::digestBuffer(const char *algorithm,
+ const uint8_t *buffer, uint32_t length, ByteArray &result)
{
- ByteArray temp((uint8_t *)buffer, (uint32_t)length);
+ ByteArray temp(buffer, length);
return digestBuffer(algorithm, temp, result);
}
- bool OpensslHelper::digestBuffer(const char *algorithm, const ByteArray &buffer, ByteArray &result)
+ bool OpensslHelper::digestBuffer(const char *algorithm,
+ const ByteArray &buffer, ByteArray &result)
{
const EVP_MD *md;
bool ret = false;
- if (algorithm == NULL || buffer.getLength() == 0)
+ if (algorithm == NULL || buffer.size() == 0)
{
return ret;
}
if (EVP_DigestInit(&mdCtx, md) > 0)
{
- if (EVP_DigestUpdate(&mdCtx, buffer.getBuffer(), buffer.getLength()) == 0)
+ if (EVP_DigestUpdate(&mdCtx, buffer.getBuffer(), buffer.size()) == 0)
{
_ERR("EVP_DigestUpdate failed");
}
if (EVP_DigestFinal(&mdCtx, temp, &resultLen) > 0 &&
resultLen > 0)
{
- result.setBuffer(temp, resultLen);
+ result.assign(temp, resultLen);
ret = true;
}
}
ret = PKCS15Object::select(PKCS15::PKCS15_AID);
if (ret >= SCARD_ERROR_OK)
{
- _DBG("response : %s", selectResponse.toString());
+ _DBG("response : %s", selectResponse.toString().c_str());
}
else if (ret == ResponseHelper::ERROR_FILE_NOT_FOUND)
{
ret = selectFromEFDIR();
if (ret >= SCARD_ERROR_OK)
{
- _DBG("response : %s", selectResponse.toString());
+ _DBG("response : %s", selectResponse.toString().c_str());
}
else
{
if (ret >= SCARD_ERROR_OK)
{
path = dir.getPathByAID(PKCS15_AID);
- if (path.getLength() > 0)
+ if (path.size() > 0)
{
ret = PKCS15Object::select(path, false);
if (ret < SCARD_ERROR_OK)
{
ByteArray dodfData, extra;
- _DBG("response : %s", selectResponse.toString());
+ _DBG("response : %s", selectResponse.toString().c_str());
if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
{
- _DBG("odfData : %s", dodfData.toString());
+ _DBG("odfData : %s", dodfData.toString().c_str());
parseData(dodfData);
}
}
}
- PKCS15DODF::PKCS15DODF(ByteArray path, Channel *channel) :
+ PKCS15DODF::PKCS15DODF(const ByteArray &path, Channel *channel) :
PKCS15Object(channel)
{
int ret = 0;
{
ByteArray dodfData, extra;
- _DBG("response : %s", selectResponse.toString());
+ _DBG("response : %s", selectResponse.toString().c_str());
if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
{
- _DBG("dodfData : %s", dodfData.toString());
+ _DBG("dodfData : %s", dodfData.toString().c_str());
parseData(dodfData);
}
{
}
- bool PKCS15DODF::parseData(ByteArray data)
+ bool PKCS15DODF::parseData(const ByteArray &data)
{
bool result = false;
SimpleTLV tlv(data);
break;
default :
- _DBG("Unknown tlv : t [%X], l [%d], v %s", tlv.getTag(), tlv.getLength(), tlv.getValue().toString());
+ _DBG("Unknown tlv : t [%X], l [%d], v %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
break;
}
}
return result;
}
- int PKCS15DODF::searchOID(ByteArray oid, ByteArray &data)
+ int PKCS15DODF::searchOID(const ByteArray &oid, ByteArray &data) const
{
int result = -1;
- map<ByteArray, PKCS15OID>::iterator item;
+ map<ByteArray, PKCS15OID>::const_iterator item;
item = mapOID.find(oid);
if (item != mapOID.end())
{
ByteArray odfData, extra;
- _DBG("response : %s", selectResponse.toString());
+ _DBG("response : %s", selectResponse.toString().c_str());
if ((ret = readBinary(0, 0, getFCP()->getFileSize(), odfData)) == 0)
{
- _DBG("odfData : %s", odfData.toString());
+ _DBG("odfData : %s", odfData.toString().c_str());
parseData(odfData);
}
}
}
- PKCS15ODF::PKCS15ODF(Channel *channel, ByteArray selectResponse) :
+ PKCS15ODF::PKCS15ODF(Channel *channel, const ByteArray &selectResponse) :
PKCS15Object(channel, selectResponse), dodf(NULL)
{
int ret = 0;
if ((ret = readBinary(0, 0, 0, odfData)) == 0)
{
- _DBG("odfData : %s", odfData.toString());
+ _DBG("odfData : %s", odfData.toString().c_str());
parseData(odfData);
}
}
}
- bool PKCS15ODF::parseData(ByteArray data)
+ bool PKCS15ODF::parseData(const ByteArray &data)
{
bool result = false;
SimpleTLV tlv(data);
dodf = PKCS15Object::getOctetStream(tlv.getValue());
- _DBG("path : %s", dodf.toString());
+ _DBG("path : %s", dodf.toString().c_str());
pair<unsigned int, ByteArray> newPair(tlv.getTag(), dodf);
dataList.insert(newPair);
tokeninfo = PKCS15Object::getOctetStream(tlv.getValue());
- _DBG("path : %s", tokeninfo.toString());
+ _DBG("path : %s", tokeninfo.toString().c_str());
pair<unsigned int, ByteArray> newPair(tlv.getTag(), tokeninfo);
dataList.insert(newPair);
default :
_DBG("Unknown tlv : t [%X], l [%d], v %s",
- tlv.getTag(), tlv.getLength(), tlv.getValue().toString());
+ tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
break;
}
namespace smartcard_service_api
{
- PKCS15OID::PKCS15OID(ByteArray data)
+ PKCS15OID::PKCS15OID(const ByteArray &data)
{
parseOID(data);
}
{
}
- bool PKCS15OID::parseOID(ByteArray data)
+ bool PKCS15OID::parseOID(const ByteArray &data)
{
bool result = false;
SimpleTLV tlv(data);
switch (tlv.getTag())
{
case PKCS15::TAG_SEQUENCE :
- if (tlv.getLength() > 0)
+ if (tlv.size() > 0)
{
/* common object attribute */
tlv.enterToValueTLV();
if (tlv.decodeTLV() == true && tlv.getTag() == 0x0C) /* ?? */
{
name = tlv.getValue();
- SCARD_DEBUG("name : %s", name.toString());
}
tlv.returnToParentTLV();
}
{
oid = tlv.getValue();
- _DBG("oid : %s", oid.toString());
+ _DBG("oid : %s", oid.toString().c_str());
}
else
{
{
path = SimpleTLV::getOctetString(tlv.getValue());
- _DBG("path : %s", path.toString());
+ _DBG("path : %s", path.toString().c_str());
result = true;
}
return result;
}
-
- ByteArray PKCS15OID::getOID()
- {
- return oid;
- }
-
- ByteArray PKCS15OID::getName()
- {
- return name;
- }
-
- ByteArray PKCS15OID::getPath()
- {
- return path;
- }
-
} /* namespace smartcard_service_api */
// {
// }
- PKCS15Object::PKCS15Object(Channel *channel):FileObject(channel)
+ PKCS15Object::PKCS15Object(Channel *channel) : FileObject(channel)
{
}
- PKCS15Object::PKCS15Object(Channel *channel, ByteArray selectResponse):FileObject(channel, selectResponse)
+ PKCS15Object::PKCS15Object(Channel *channel,
+ const ByteArray &selectResponse) :
+ FileObject(channel, selectResponse)
{
}
{
}
- ByteArray PKCS15Object::getOctetStream(const ByteArray &data)
+ const ByteArray PKCS15Object::getOctetStream(const ByteArray &data)
{
ByteArray result;
SimpleTLV tlv(data);
namespace smartcard_service_api
{
- PKCS15Path::PKCS15Path()
+ PKCS15Path::PKCS15Path() : index(-1), length(0)
+ {
+ }
+
+ PKCS15Path::PKCS15Path(const ByteArray &data) : index(-1), length(0)
+ {
+ parseData(data);
+ }
+
+ PKCS15Path::PKCS15Path(const ByteArray &path, int index) :
+ path(path), index(index), length(0)
+ {
+ }
+
+ PKCS15Path::PKCS15Path(const unsigned char *path,
+ size_t length, int index) :
+ path(path, length), index(index), length(0)
{
}
{
}
-// PKCS15Path(ByteArray &data);
-// PKCS15Path(ByteArray path, int index);
-// PKCS15Path(unsigned char *path, unsigned int length, int index);
-// ~PKCS15Path();
-//
-// bool PKCS15Path::parseData(ByteArray &data)
-// {
+ bool PKCS15Path::parseData(const ByteArray &data)
+ {
+ /* TODO */
// SimpleTLV tlv(data);
//
// if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE */
// path = tlv.getOctetString();
//
// if (tlv.decodeTLV())
-// index = t
-//
// }
-// }
-//
-// int getPath(ByteArray &path);
-// bool hasIndexLength();
-// int getIndex();
-// unsigned int getLength();
-// int encode(ByteArray &result);
+ return true;
+ }
+
+ int PKCS15Path::encode(ByteArray &result) const
+ {
+ /* TODO */
+ return 0;
+ }
} /* namespace smartcard_service_api */
namespace smartcard_service_api
{
- PKCS15TokenInfo::PKCS15TokenInfo(Channel *channel):PKCS15Object(channel)
+ PKCS15TokenInfo::PKCS15TokenInfo(Channel *channel) :
+ PKCS15Object(channel)
{
}
+++ /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 "Debug.h"
-#include "ProviderHelper.h"
-
-namespace smartcard_service_api
-{
-// ProviderHelper::ProviderHelper()
-// {
-// }
-
- ProviderHelper::ProviderHelper(Channel *channel)
- {
- this->channel = NULL;
-
- if (channel == NULL)
- {
- _ERR("invalid channel");
- return;
- }
-
- this->channel = channel;
- }
-
- ProviderHelper::~ProviderHelper()
- {
- }
-
- Channel *ProviderHelper::getChannel()
- {
- return channel;
- }
-
-} /* namespace smartcard_service_api */
+++ /dev/null
-/*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 */
-#include <stdio.h>
-#include <string.h>
-
-/* SLP library header */
-
-/* local header */
-#include "Debug.h"
-#include "ReaderHelper.h"
-
-namespace smartcard_service_api
-{
- ReaderHelper::ReaderHelper() : seService(NULL), present(false)
- {
- memset(name, 0, sizeof(name));
- }
-} /* namespace smartcard_service_api */
+++ /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 */
-#include <stdio.h>
-
-/* SLP library header */
-
-/* local header */
-#include "Debug.h"
-#include "SEServiceHelper.h"
-
-namespace smartcard_service_api
-{
- SEServiceHelper::~SEServiceHelper()
- {
- _BEGIN();
- _END();
- }
-
-} /* namespace smartcard_service_api */
+++ /dev/null
-/*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 "ReaderHelper.h"
-
-namespace smartcard_service_api
-{
- SessionHelper::SessionHelper(ReaderHelper *reader) :
- closed(true)
- {
- this->reader = reader;
- }
-} /* namespace smartcard_service_api */
*/
/* standard library header */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstring>
+#include <cstdlib>
#include <unistd.h>
#include <list>
#include <string>
return aul_app_get_pkgname_bypid(pid, package, length);
}
- ByteArray SignatureHelper::getCertificationHash(const char *packageName)
+ const ByteArray SignatureHelper::getCertificationHash(const char *packageName)
{
ByteArray result;
int ret = 0;
if (value != NULL && strlen(value) > 0)
{
OpensslHelper::decodeBase64String(value, result, false);
- if (result.getLength() > 0)
+ if (result.size() > 0)
{
- _DBG("type [%d] hash [%d] : %s", type, result.getLength(), result.toString());
+ _DBG("type [%d] hash [%d] : %s", type, result.size(), result.toString().c_str());
break;
}
}
return result;
}
- ByteArray SignatureHelper::getCertificationHash(int pid)
+ const ByteArray SignatureHelper::getCertificationHash(int pid)
{
ByteArray result;
int error = 0;
ByteArray decodeValue, hash;
OpensslHelper::decodeBase64String(value, decodeValue, false);
- if (decodeValue.getLength() > 0)
+ if (decodeValue.size() > 0)
{
- OpensslHelper::digestBuffer("sha1", decodeValue.getBuffer(), decodeValue.getLength(), hash);
- if(hash.getLength() > 0)
+ OpensslHelper::digestBuffer("sha1", decodeValue.getBuffer(), decodeValue.size(), hash);
+ if(hash.size() > 0)
{
- _DBG("type [%d] hash [%d] : %s", type, hash.getLength(), hash.toString());
+ _DBG("type [%d] hash [%d] : %s", type, hash.size(), hash.toString().c_str());
certHashes.push_back(hash);
}
}
if ((tmp = (certiHash *)calloc(1, sizeof(certiHash))) == NULL)
goto ERROR;
- tmp->length = (*item).getLength();
+ tmp->length = (*item).size();
if ((tmp->value = (uint8_t *)calloc(tmp->length, sizeof(uint8_t))) == NULL)
{
namespace smartcard_service_api
{
- SimpleTLV::SimpleTLV():TLVHelper()
+ SimpleTLV::SimpleTLV() : TLVHelper()
{
}
- SimpleTLV::SimpleTLV(TLVHelper *parent):TLVHelper(parent)
+ SimpleTLV::SimpleTLV(TLVHelper *parent) : TLVHelper(parent)
{
- parentTLV = parent;
}
- SimpleTLV::SimpleTLV(const ByteArray &array):TLVHelper(array)
+ SimpleTLV::SimpleTLV(const ByteArray &array) : TLVHelper(array)
{
}
- SimpleTLV::SimpleTLV(const ByteArray &array, TLVHelper *parent):TLVHelper(array, parent)
+ SimpleTLV::SimpleTLV(const ByteArray &array, TLVHelper *parent) :
+ TLVHelper(array, parent)
{
- parentTLV = parent;
}
SimpleTLV::~SimpleTLV()
}
}
- int SimpleTLV::decodeTag(unsigned char *buffer)
+ int SimpleTLV::decodeTag(const unsigned char *buffer)
{
/* 0x00 or 0xFF is invalid tag value */
if (buffer[0] == 0x00 || buffer[0] == 0xFF)
return 1;
}
- int SimpleTLV::decodeLength(unsigned char *buffer)
+ int SimpleTLV::decodeLength(const unsigned char *buffer)
{
int count = 0;
return count;
}
- int SimpleTLV::decodeValue(unsigned char *buffer)
+ int SimpleTLV::decodeValue(const unsigned char *buffer)
{
if (currentL == 0)
return 0;
- currentV.setBuffer(buffer, currentL);
+ currentV.assign(buffer, currentL);
return currentL;
}
- ByteArray SimpleTLV::encode(unsigned int tag, ByteArray buffer)
+ const ByteArray SimpleTLV::encode(unsigned int tag, const ByteArray &buffer)
{
bool isLongBuffer = false;
ByteArray result;
total_len += 1;
/* add length's length */
- if (buffer.getLength() < 255)
+ if (buffer.size() < 255)
{
total_len += 1;
}
- else if (buffer.getLength() < 65536)
+ else if (buffer.size() < 65536)
{
total_len += 3;
isLongBuffer = true;
}
/* add buffer's length */
- total_len += buffer.getLength();
+ total_len += buffer.size();
/* alloc new buffer */
temp_buffer = new unsigned char[total_len];
if (isLongBuffer == true)
{
temp_buffer[current++] = (unsigned char)(0xFF);
- temp_buffer[current++] = (unsigned char)(buffer.getLength() >> 8);
- temp_buffer[current++] = (unsigned char)(buffer.getLength());
+ temp_buffer[current++] = (unsigned char)(buffer.size() >> 8);
+ temp_buffer[current++] = (unsigned char)(buffer.size());
}
else
{
- temp_buffer[current++] = (unsigned char)(buffer.getLength());
+ temp_buffer[current++] = (unsigned char)(buffer.size());
}
/* fill value */
- if (buffer.getLength() > 0)
- memcpy(temp_buffer + current, buffer.getBuffer(), buffer.getLength());
+ if (buffer.size() > 0)
+ memcpy(temp_buffer + current, buffer.getBuffer(), buffer.size());
- result.setBuffer(temp_buffer, total_len);
+ result.assign(temp_buffer, total_len);
delete []temp_buffer;
return result;
}
- ByteArray SimpleTLV::encode(unsigned int tag, unsigned char *buffer, unsigned int length)
+ const ByteArray SimpleTLV::encode(unsigned int tag, unsigned char *buffer, unsigned int length)
{
return encode(tag, ByteArray(buffer, length));
}
- TLVHelper *SimpleTLV::getChildTLV(ByteArray data)
+ TLVHelper *SimpleTLV::getChildTLV(const ByteArray &data)
{
if (childTLV != NULL)
{
return (TLVHelper *)childTLV;
}
- ByteArray SimpleTLV::getOctetString(const ByteArray &array)
+ const ByteArray SimpleTLV::getOctetString(const ByteArray &array)
{
SimpleTLV tlv(array);
return SimpleTLV::getOctetString(tlv);
}
- ByteArray SimpleTLV::getOctetString(SimpleTLV &tlv)
+ const ByteArray SimpleTLV::getOctetString(SimpleTLV &tlv)
{
ByteArray result;
if (tlv.decodeTLV() == true && tlv.getTag() == 0x80) /* BOOLEAN */
{
- if (tlv.getValue().getAt(0) == 0)
+ if (tlv.getValue().at(0) == 0)
result = false;
else
result = true;
*/
/* standard library header */
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
+#include <sstream>
/* SLP library header */
namespace smartcard_service_api
{
- void TLVHelper::initialize(TLVHelper *parent)
+ TLVHelper::TLVHelper() : currentTLV(this), parentTLV(NULL),
+ childTLV(NULL), offset(0), currentT(0), currentL(0)
{
- parentTLV = parent;
- childTLV = NULL;
- currentTLV = this;
- offset = 0;
- currentT = 0;
- currentL = 0;
- }
-
- TLVHelper::TLVHelper()
- {
- initialize();
}
- TLVHelper::TLVHelper(TLVHelper *parent)
+ TLVHelper::TLVHelper(TLVHelper *parent) : currentTLV(this),
+ parentTLV(parent), childTLV(NULL),
+ offset(0), currentT(0), currentL(0)
{
- initialize(parent);
}
- TLVHelper::TLVHelper(const ByteArray &array)
+ TLVHelper::TLVHelper(const ByteArray &array) : currentTLV(this),
+ parentTLV(NULL), childTLV(NULL),
+ offset(0), currentT(0), currentL(0)
{
setTLVBuffer(array);
}
- TLVHelper::TLVHelper(const ByteArray &array, TLVHelper *parent)
+ TLVHelper::TLVHelper(const ByteArray &array, TLVHelper *parent) :
+ currentTLV(this), parentTLV(NULL), childTLV(NULL),
+ offset(0), currentT(0), currentL(0)
{
setTLVBuffer(array, parent);
}
bool TLVHelper::setTLVBuffer(const ByteArray &array, TLVHelper *parent)
{
- initialize(parent);
-
- if (array.getLength() == 0)
+ if (array.size() == 0)
return false;
tlvBuffer = array;
return true;
}
- bool TLVHelper::setTLVBuffer(unsigned char *buffer, unsigned int length, TLVHelper *parent)
+ bool TLVHelper::setTLVBuffer(const unsigned char *buffer, unsigned int length, TLVHelper *parent)
{
return setTLVBuffer(ByteArray(buffer, length), parent);
}
currentT = 0;
currentL = 0;
- currentV.releaseBuffer();
+ currentV.clear();
if (isEndOfBuffer())
return false;
if (currentL > 0)
{
- if (currentL > (tlvBuffer.getLength() - (offset + temp)))
+ if (currentL > (tlvBuffer.size() - (offset + temp)))
return false;
/* V */
return true;
}
- const char *TLVHelper::toString()
+ const string TLVHelper::toString() const
{
- memset(strBuffer, 0, sizeof(strBuffer));
+ stringstream ss;
- if (currentL == 0)
- {
- snprintf(strBuffer, sizeof(strBuffer), "T [%X], L [%d]", getTag(), getLength());
- }
- else
+ ss << "T [" << getTag() << "], L [" << size() << "]";
+ if (currentL > 0)
{
- snprintf(strBuffer, sizeof(strBuffer), "T [%X], L [%d], V %s", getTag(), getLength(), getValue().toString());
+ ss << ", V " << getValue().toString();
}
- return strBuffer;
+ return ss.str();
}
TLVHelper *TLVHelper::getParentTLV()
bool result = false;
TLVHelper *temp = NULL;
- if (getLength() >= 2)
+ if (size() >= 2)
{
temp = currentTLV->getChildTLV(getValue());
int status;
ByteArray dataField;
- static int parseStatusWord(unsigned char *sw);
+ static int parseStatusWord(const unsigned char *sw);
public:
static const int SUCCESS = 0;
~ResponseHelper();
bool setResponse(const ByteArray &response);
- int getStatus();
- unsigned char getSW1();
- unsigned char getSW2();
+ inline int getStatus() const { return status; }
+ inline unsigned char getSW1() const { return sw[0]; }
+ inline unsigned char getSW2() const { return sw[1]; }
// char *getErrorString();
- ByteArray getDataField();
+ inline const ByteArray getDataField() const { return dataField; }
static int getStatus(const ByteArray &response);
- static ByteArray getDataField(const ByteArray &response);
+ static const ByteArray getDataField(const ByteArray &response);
// static char *getErrorString();
};
~APDUCommand();
bool setCommand(unsigned char cla, unsigned char ins, unsigned char p1,
- unsigned char p2, ByteArray commandData, unsigned int maxResponseSize);
+ unsigned char p2, const ByteArray &commandData, unsigned int maxResponseSize);
bool setCommand(const ByteArray &command);
bool setChannel(int type, int channelNum);
void setCLA(unsigned char cla);
- unsigned char getCLA();
+ unsigned char getCLA() const;
void setINS(unsigned char ins);
- unsigned char getINS();
+ unsigned char getINS() const;
void setP1(unsigned char p1);
- unsigned char getP1();
+ unsigned char getP1() const;
void setP2(unsigned char p2);
- unsigned char getP2();
+ unsigned char getP2() const;
void setCommandData(const ByteArray &data);
- ByteArray getCommandData();
+ const ByteArray getCommandData() const;
void setMaxResponseSize(unsigned int maxResponseSize);
- unsigned int getMaxResponseSize();
+ unsigned int getMaxResponseSize() const;
- bool getBuffer(ByteArray &array);
+ bool getBuffer(ByteArray &array) const;
};
class APDUHelper
static const int COMMAND_WRITE_BINARY = 10;
static const int COMMAND_WRITE_RECORD = 11;
- static ByteArray generateAPDU(int command, int channel, ByteArray data);
+ static const ByteArray generateAPDU(int command,
+ int channel, const ByteArray &data);
};
} /* namespace smartcard_service_api */
bool nfcRule;
vector<pair<ByteArray, ByteArray> > listFilters;
- void printAccessRules();
+ void printAccessRules() const;
public :
- AccessRule() : apduRule(true), nfcRule(true)
- {
- }
+ AccessRule() : apduRule(true), nfcRule(true) {}
inline void setAPDUAccessRule(bool rule) { apduRule = rule; }
inline void setNFCAccessRule(bool rule) { nfcRule = rule; }
void addAPDUAccessRule(const ByteArray &apdu,
const ByteArray &mask);
- inline bool isAuthorizedAccess(void)
+ inline bool isAuthorizedAccess(void) const
{
return (apduRule || (listFilters.size() > 0));
}
- bool isAuthorizedAPDUAccess(const ByteArray &command);
- bool isAuthorizedNFCAccess(void);
+ bool isAuthorizedAPDUAccess(const ByteArray &command) const;
+ bool isAuthorizedNFCAccess(void) const;
friend class AccessCondition;
};
ByteArray aid;
map<ByteArray, AccessRule> mapRules;
- void printAccessConditions();
+ void printAccessConditions() const;
public :
- AccessCondition() : permission(false)
- {
- }
+ AccessCondition() : permission(false) {}
inline void setAID(const ByteArray &aid) { this->aid = aid; }
- inline ByteArray getAID() { return aid; }
+ inline const ByteArray getAID() const { return aid; }
inline void setAccessCondition(bool rule) { permission = rule; }
void addAccessRule(const ByteArray &hash);
- AccessCondition *getAccessCondition(const ByteArray &hash);
void setAPDUAccessRule(const ByteArray &certHash, bool rule);
void addAPDUAccessRule(const ByteArray &certHash,
void setNFCAccessRule(const ByteArray &certHash, bool rule);
- bool isAuthorizedAccess(const ByteArray &certHash);
+ bool isAuthorizedAccess(const ByteArray &certHash) const;
bool isAuthorizedAPDUAccess(const ByteArray &certHash,
- const ByteArray &command);
- bool isAuthorizedNFCAccess(const ByteArray &certHash);
+ const ByteArray &command) const;
+ bool isAuthorizedNFCAccess(const ByteArray &certHash) const;
AccessRule *getAccessRule(const ByteArray &certHash);
+ const AccessRule *getAccessRule(const ByteArray &certHash) const;
+
friend class AccessControlList;
};
map<ByteArray, AccessCondition> mapConditions;
bool allGranted;
- AccessRule *findAccessRule(const ByteArray &aid,
- const ByteArray &hash);
+ const AccessRule *findAccessRule(const ByteArray &aid,
+ const ByteArray &hash) const;
AccessCondition &getAccessCondition(const ByteArray &aid);
- void printAccessControlList();
+ void printAccessControlList() const;
public:
static ByteArray ALL_SE_APPS;
int updateACL(Channel *channel) { return loadACL(channel); }
void releaseACL();
- virtual bool isAuthorizedAccess(ByteArray &aid,
- ByteArray &certHash);
- virtual bool isAuthorizedAccess(unsigned char *aidBuffer,
- unsigned int aidLength, unsigned char *certHashBuffer,
- unsigned int certHashLength);
- virtual bool isAuthorizedAccess(ByteArray &aid,
- vector<ByteArray> &certHashes);
- virtual bool isAuthorizedAccess(ByteArray &aid,
- vector<ByteArray> &certHashes, ByteArray &command);
- virtual bool isAuthorizedNFCAccess(ByteArray &aid,
- vector<ByteArray> &certHashes);
+ virtual bool isAuthorizedAccess(const ByteArray &aid,
+ const ByteArray &certHash) const;
+ virtual bool isAuthorizedAccess(const unsigned char *aidBuffer,
+ unsigned int aidLength, const unsigned char *certHashBuffer,
+ unsigned int certHashLength) const;
+ virtual bool isAuthorizedAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const;
+ virtual bool isAuthorizedAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes, const ByteArray &command) const;
+ virtual bool isAuthorizedNFCAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const;
};
} /* namespace smartcard_service_api */
#define BYTEARRAY_H_
/* standard library header */
+#include <string>
#include <stdint.h>
+#include <stddef.h>
/* SLP library header */
#define ARRAY_AND_SIZE(x) (uint8_t *)(&x), sizeof(x)
+using namespace std;
+
namespace smartcard_service_api
{
class ByteArray //: public Serializable
{
protected:
uint8_t *buffer;
- uint32_t length;
- char strBuffer[100];
+ size_t length;
- bool _setBuffer(uint8_t *array, uint32_t bufferLen);
+ bool _assign(uint8_t *array, size_t size);
void save(const char *filePath);
public:
static ByteArray EMPTY;
ByteArray();
- ByteArray(uint8_t *array, uint32_t bufferLen);
+ ByteArray(const uint8_t *array, size_t size);
ByteArray(const ByteArray &T);
~ByteArray();
// ByteArray serialize();
// void deserialize(ByteArray buffer);
- bool setBuffer(uint8_t *array, uint32_t bufferLen);
- void releaseBuffer();
+ bool assign(const uint8_t *array, size_t size);
+ inline bool setBuffer(const uint8_t *array, size_t size) { return assign(array, size); }
+ void clear();
- uint32_t getLength() const;
- uint8_t *getBuffer() const;
- uint8_t *getBuffer(uint32_t offset) const;
+ size_t size() const;
+ inline size_t getLength() const { return size(); }
+ uint8_t *getBuffer();
+ inline const uint8_t *getBuffer() const { return getBuffer(); }
+ uint8_t *getBuffer(size_t offset);
+ inline const uint8_t *getBuffer(size_t offset) const { return getBuffer(offset); }
- uint8_t getAt(uint32_t index) const;
- uint8_t getReverseAt(uint32_t index) const;
+ uint8_t at(size_t index) const;
+ uint8_t reverseAt(size_t index) const;
- uint32_t copyFromArray(uint8_t *array, uint32_t bufferLen) const;
+ size_t extract(uint8_t *array, size_t size) const;
- ByteArray sub(uint32_t offset, uint32_t size) const;
+ const ByteArray sub(size_t offset, size_t size) const;
/* operator overloading */
ByteArray &operator =(const ByteArray &T);
bool operator !=(const ByteArray &T) const;
bool operator <(const ByteArray &T) const;
bool operator >(const ByteArray &T) const;
- uint8_t &operator [](uint32_t index) const;
+ uint8_t operator [](size_t index) const;
inline bool isEmpty() const { return (buffer == (void *)0 || length == 0); }
- const char *toString();
+ const string toString() const;
};
} /* namespace smartcard_service_api */
{
class SessionHelper; /* explicit declaration */
- typedef void (*transmitCallback)(unsigned char *buffer, unsigned int length,
- int error, void *userParam);
+ typedef void (*transmitCallback)(unsigned char *buffer,
+ unsigned int length, int error, void *userParam);
typedef void (*closeChannelCallback)(int error, void *userParam);
class Channel : public Synchronous
Channel() : session(NULL), channelNum(-1) {}
Channel(SessionHelper *session) : session(session), channelNum(-1) {}
- inline void setSelectResponse(ByteArray response) { selectResponse = response; }
+ inline void setSelectResponse(const ByteArray &response) { selectResponse = response; }
public :
virtual ~Channel() {};
inline bool isBasicChannel() const throw() { return (channelNum == 0); }
inline bool isClosed() const throw() { return (channelNum < 0); }
- inline ByteArray getSelectResponse() const throw() { return selectResponse; }
+ inline const ByteArray getSelectResponse() const throw() { return selectResponse; }
inline SessionHelper *getSession() const throw() { return session; }
virtual int close(closeChannelCallback callback, void *userParam) = 0;
- virtual int transmit(ByteArray command, transmitCallback callback, void *userData) = 0;
+ virtual int transmit(const ByteArray &command, transmitCallback callback, void *userData) = 0;
virtual void closeSync()
throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
ErrorIllegalState &, ErrorIllegalParameter &) = 0;
- virtual int transmitSync(ByteArray command, ByteArray &result)
+ virtual int transmitSync(const ByteArray &command, ByteArray &result)
throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
ErrorIllegalParameter &, ErrorSecurity &) = 0;
};
#define DEBUG_H_
/* standard library header */
+#include <iostream>
/* SLP library header */
#include "dlog.h"
#ifndef DISPATCHERHELPER_H_
#define DISPATCHERHELPER_H_
-
+#ifndef USE_GDBUS
/* standard library header */
#include <queue>
#include <pthread.h>
public:
DispatcherHelper();
- ~DispatcherHelper();
+ virtual ~DispatcherHelper();
void clearQueue();
- void pushMessage(DispatcherMsg *msg);
+ void pushMessage(const DispatcherMsg &msg);
void processMessage(DispatcherMsg *msg);
bool runDispatcherThread();
};
} /* namespace smartcard_service_api */
+#endif
#endif /* DISPATCHERHELPER_H_ */
namespace smartcard_service_api
{
- class DispatcherMsg: public Message
+ class DispatcherMsg : public Message
{
private:
int peerSocket;
public:
- DispatcherMsg():Message()
+ DispatcherMsg() : Message()
{
peerSocket = -1;
}
- DispatcherMsg(Message *msg):Message()
+ DispatcherMsg(const Message &msg) : Message()
{
peerSocket = -1;
- message = msg->message;
- param1 = msg->param1;
- param2 = msg->param2;
- error = msg->error;
- data = msg->data;
- caller = msg->caller;
- callback = msg->callback;
- userParam = msg->userParam;
+ message = msg.message;
+ param1 = msg.param1;
+ param2 = msg.param2;
+ error = msg.error;
+ data = msg.data;
+ caller = msg.caller;
+ callback = msg.callback;
+ userParam = msg.userParam;
}
- DispatcherMsg(DispatcherMsg *msg):Message()
+ DispatcherMsg(const DispatcherMsg &msg) : Message()
{
- peerSocket = msg->peerSocket;
- message = msg->message;
- param1 = msg->param1;
- param2 = msg->param2;
- error = msg->error;
- data = msg->data;
- caller = msg->caller;
- callback = msg->callback;
- userParam = msg->userParam;
+ peerSocket = msg.peerSocket;
+ message = msg.message;
+ param1 = msg.param1;
+ param2 = msg.param2;
+ error = msg.error;
+ data = msg.data;
+ caller = msg.caller;
+ callback = msg.callback;
+ userParam = msg.userParam;
}
- DispatcherMsg(Message *msg, int socket):Message()
+ DispatcherMsg(const Message &msg, int socket) : Message()
{
peerSocket = socket;
- message = msg->message;
- param1 = msg->param1;
- param2 = msg->param2;
- error = msg->error;
- data = msg->data;
- caller = msg->caller;
- callback = msg->callback;
- userParam = msg->userParam;
+ message = msg.message;
+ param1 = msg.param1;
+ param2 = msg.param2;
+ error = msg.error;
+ data = msg.data;
+ caller = msg.caller;
+ callback = msg.callback;
+ userParam = msg.userParam;
}
~DispatcherMsg() {}
- inline int getPeerSocket() { return peerSocket; }
+ inline int getPeerSocket() const { return peerSocket; }
inline void setPeerSocket(int socket) { peerSocket = socket; }
};
class EFDIR : public FileObject
{
private:
- ByteArray parseRecord(Record &record, ByteArray &aid);
+ const ByteArray parseRecord(const Record &record, const ByteArray &aid);
public:
EFDIR(Channel *channel);
- EFDIR(Channel *channel, ByteArray selectResponse);
+ EFDIR(Channel *channel, const ByteArray &selectResponse);
~EFDIR();
int select();
- ByteArray getPathByAID(ByteArray &aid);
+ const ByteArray getPathByAID(const ByteArray &aid);
};
} /* namespace smartcard_service_api */
#endif /* EFDIR_H_ */
#define FCI_H_
/* standard library header */
+#include <string>
/* SLP library header */
private:
ByteArray fcpBuffer;
- char strBuffer[400];
-
- unsigned int fileSize;
- unsigned int totalFileSize;
- unsigned int fid;
- unsigned int sfi;
- unsigned int maxRecordSize;
- unsigned int numberOfRecord;
- unsigned int fileType;
- unsigned int fileStructure;
- unsigned int lcs;
+ int fileSize;
+ int totalFileSize;
+ int fid;
+ int sfi;
+ int maxRecordSize;
+ int numberOfRecord;
+ int fileType;
+ int fileStructure;
+ int lcs;
void resetMemberVar();
public:
FCP();
- FCP(ByteArray &array);
+ FCP(const ByteArray &array);
~FCP();
- bool setFCP(ByteArray array);
- ByteArray getFCP();
+ bool setFCP(const ByteArray &array);
+ const ByteArray getFCP() const;
void releaseFCP();
- unsigned int getFileSize();
- unsigned int getTotalFileSize();
- unsigned int getFID();
- unsigned int getSFI();
- unsigned int getMaxRecordSize();
- unsigned int getNumberOfRecord();
- unsigned int getFileType();
- unsigned int getFileStructure();
- unsigned int getLCS();
-
- const char *toString();
+ int getFileSize() const;
+ int getTotalFileSize() const;
+ int getFID() const;
+ int getSFI() const;
+ int getMaxRecordSize() const;
+ int getNumberOfRecord() const;
+ int getFileType() const;
+ int getFileStructure() const;
+ int getLCS() const;
+
+ const string toString() const;
};
class FCM
FCI();
~FCI();
- bool setFCIBuffer(ByteArray array);
+ bool setFCIBuffer(const ByteArray &array);
};
} /* namespace smartcard_service_api */
~FileObject();
void close();
- inline bool isClosed() { return (opened == false); }
+ inline bool isClosed() const { return (opened == false); }
int select(const ByteArray &aid);
int select(const ByteArray &path, bool fromCurrentDF);
int select(unsigned int fid);
int selectParent();
- inline ByteArray getSelectResponse() { return selectResponse; }
+ inline const ByteArray getSelectResponse() const { return selectResponse; }
- FCI *getFCI();
- FCP *getFCP();
+ const FCI *getFCI() const;
+ const FCP *getFCP() const;
int readRecord(unsigned int sfi, unsigned int recordId, Record &result);
int writeRecord(unsigned int sfi, const Record &record);
class GDBusHelper
{
public :
- GDBusHelper();
- ~GDBusHelper();
-
static void convertVariantToByteArray(GVariant *var,
ByteArray &array);
int loadACL(Channel *channel);
- bool isAuthorizedAccess(ByteArray &aid,
- ByteArray &certHash);
- bool isAuthorizedAccess(unsigned char *aidBuffer,
- unsigned int aidLength, unsigned char *certHashBuffer,
- unsigned int certHashLength);
- bool isAuthorizedAccess(ByteArray &aid,
- vector<ByteArray> &certHashes);
- bool isAuthorizedAccess(ByteArray &aid,
- vector<ByteArray> &certHashes, ByteArray &command);
- bool isAuthorizedNFCAccess(ByteArray &aid,
- vector<ByteArray> &certHashes);
+ bool isAuthorizedAccess(const ByteArray &aid,
+ const ByteArray &certHash) const;
+ bool isAuthorizedAccess(const unsigned char *aidBuffer,
+ unsigned int aidLength,
+ const unsigned char *certHashBuffer,
+ unsigned int certHashLength) const;
+ bool isAuthorizedAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const;
+ bool isAuthorizedAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes,
+ const ByteArray &command) const;
+ bool isAuthorizedNFCAccess(const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const;
};
} /* namespace smartcard_service_api */
void addCondition(const ByteArray &aid, const ByteArray &hash,
const vector<ByteArray> &apduRule, const ByteArray &nfcRule);
- int updateRule(ByteArray &data);
+ int updateRule(const ByteArray &data);
public:
GPARAACL();
int loadACL(Channel *channel);
int loadACL(GPARAM &aram);
- bool isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
- ByteArray &certHash);
- bool isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
- ByteArray &certHash, ByteArray &command);
- bool isAuthorizedAccess(GPARAM &aram, unsigned char *aidBuffer,
- unsigned int aidLength, unsigned char *certHashBuffer,
- unsigned int certHashLength);
- bool isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
- vector<ByteArray> &certHashes);
- bool isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
- vector<ByteArray> &certHashes, ByteArray &command);
- bool isAuthorizedNFCAccess(GPARAM &aram, ByteArray &aid,
- vector<ByteArray> &certHashes);
+ bool isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+ const ByteArray &certHash) const;
+ bool isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+ const ByteArray &certHash,
+ const ByteArray &command) const;
+ bool isAuthorizedAccess(GPARAM &aram,
+ const unsigned char *aidBuffer,
+ unsigned int aidLength,
+ const unsigned char *certHashBuffer,
+ unsigned int certHashLength) const;
+ bool isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const;
+ bool isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+ const vector<ByteArray> &certHashes,
+ const ByteArray &command) const;
+ bool isAuthorizedNFCAccess(GPARAM &aram, const ByteArray &aid,
+ const vector<ByteArray> &certHashes) const;
};
} /* namespace smartcard_service_api */
void destroyListenSocket();
void destroyConnectSocket();
- bool sendMessage(int socket, Message *msg);
- bool sendMessage(int socket, ByteArray &buffer);
+ bool sendMessage(int socket, const Message &msg);
+ bool sendMessage(int socket, const ByteArray &buffer);
Message *retrieveMessage();
- ByteArray retrieveBuffer(int socket);
+ const ByteArray retrieveBuffer(int socket);
Message *retrieveMessage(int socket);
void setDispatcher(DispatcherHelper *dispatcher);
namespace smartcard_service_api
{
- class ISO7816BERTLV: public TLVHelper
+ class ISO7816BERTLV : public TLVHelper
{
private:
-// ISO7816BERTLV child;
-
unsigned char firstByte;
unsigned int tagClass;
unsigned int encoding;
ISO7816BERTLV(TLVHelper *parent);
ISO7816BERTLV(const ByteArray &array, TLVHelper *parent);
- int decodeTag(unsigned char *buffer);
- int decodeLength(unsigned char *buffer);
- int decodeValue(unsigned char *buffer);
+ int decodeTag(const unsigned char *buffer);
+ int decodeLength(const unsigned char *buffer);
+ int decodeValue(const unsigned char *buffer);
- TLVHelper *getChildTLV(ByteArray data);
+ TLVHelper *getChildTLV(const ByteArray &data);
public:
ISO7816BERTLV();
ISO7816BERTLV(const ByteArray &array);
~ISO7816BERTLV();
- unsigned int getClass();
- unsigned int getEncoding();
+ unsigned int getClass() const;
+ unsigned int getEncoding() const;
- static ByteArray encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, ByteArray buffer);
- static ByteArray encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, unsigned char *buffer, unsigned int length);
+ static const ByteArray encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, const ByteArray &buffer);
+ static const ByteArray encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, unsigned char *buffer, unsigned int length);
};
} /* namespace smartcard_service_api */
#define MESSAGE_H_
#ifndef USE_GDBUS
/* standard library header */
+#include <string>
/* SLP library header */
/* local header */
#include "Serializable.h"
+using namespace std;
+
namespace smartcard_service_api
{
- class Message: public Serializable
+ class Message : public Serializable
{
private:
- char text[200];
-
public:
static const int MSG_REQUEST_READERS = 0x80;
static const int MSG_REQUEST_SHUTDOWN = 0x81;
void *userParam;
Message();
- ~Message();
+ virtual ~Message();
- ByteArray serialize();
- void deserialize(unsigned char *buffer, unsigned int length);
- void deserialize(ByteArray buffer);
+ const ByteArray serialize() const;
+ void deserialize(const unsigned char *buffer, unsigned int length);
+ void deserialize(const ByteArray &buffer);
- inline bool isSynchronousCall() { return (caller == callback); }
+ inline bool isSynchronousCall() const { return (caller == callback); }
- const char *toString();
+ const string toString() const;
};
} /* namespace smartcard_service_api */
namespace smartcard_service_api
{
- class NumberStream: public ByteArray
+ class NumberStream : public ByteArray
{
public:
NumberStream(const ByteArray &T);
- unsigned int getBigEndianNumber();
- unsigned int getLittleEndianNumber();
+ unsigned int getBigEndianNumber() const;
+ unsigned int getLittleEndianNumber() const;
static unsigned int getBigEndianNumber(const ByteArray &T);
static unsigned int getLittleEndianNumber(const ByteArray &T);
{
public:
/* base64 method */
- static bool encodeBase64String(const ByteArray &buffer, ByteArray &result, bool newLineChar = false);
- static bool decodeBase64String(const char *buffer, ByteArray &result, bool newLineChar = true);
- static bool decodeBase64String(const ByteArray &buffer, ByteArray &result, bool newLineChar = true);
+ static bool encodeBase64String(const ByteArray &buffer,
+ ByteArray &result, bool newLineChar = false);
+ static bool decodeBase64String(const char *buffer,
+ ByteArray &result, bool newLineChar = true);
+ static bool decodeBase64String(const ByteArray &buffer,
+ ByteArray &result, bool newLineChar = true);
/* digest method */
- static bool digestBuffer(const char *algorithm, const uint8_t *buffer, const uint32_t length, ByteArray &result);
- static bool digestBuffer(const char *algorithm, const ByteArray &buffer, ByteArray &result);
+ static bool digestBuffer(const char *algorithm,
+ const uint8_t *buffer, uint32_t length,
+ ByteArray &result);
+ static bool digestBuffer(const char *algorithm,
+ const ByteArray &buffer, ByteArray &result);
};
} /* namespace smartcard_service_api */
int select();
PKCS15ODF *getODF();
- int getTokenInfo(ByteArray &path);
+ int getTokenInfo(ByteArray &path) const;
};
} /* namespace smartcard_service_api */
private:
map<ByteArray, PKCS15OID> mapOID;
- bool parseData(ByteArray data);
+ bool parseData(const ByteArray &data);
public:
PKCS15DODF(unsigned int fid, Channel *channel);
- PKCS15DODF(ByteArray path, Channel *channel);
+ PKCS15DODF(const ByteArray &path, Channel *channel);
~PKCS15DODF();
- int searchOID(ByteArray oid, ByteArray &data);
+ int searchOID(const ByteArray &oid, ByteArray &data) const;
};
} /* namespace smartcard_service_api */
class PKCS15ODF : public PKCS15Object
{
private:
- bool parseData(ByteArray data);
+ bool parseData(const ByteArray &data);
PKCS15DODF *dodf;
public:
// PKCS15ODF();
PKCS15ODF(Channel *channel);
- PKCS15ODF(Channel *channel, ByteArray selectResponse);
+ PKCS15ODF(Channel *channel, const ByteArray &selectResponse);
~PKCS15ODF();
int getPuKDFPath(ByteArray &path);
ByteArray name;
ByteArray path;
- bool parseOID(ByteArray data);
+ bool parseOID(const ByteArray &data);
public:
- PKCS15OID(ByteArray data);
+ PKCS15OID(const ByteArray &data);
~PKCS15OID();
- ByteArray getOID();
- ByteArray getName();
- ByteArray getPath();
-
+ inline const ByteArray getOID() const { return oid; }
+ inline const ByteArray getName() const { return name; }
+ inline const ByteArray getPath() const { return path; }
};
} /* namespace smartcard_service_api */
namespace smartcard_service_api
{
- class PKCS15Object: public FileObject
+ class PKCS15Object : public FileObject
{
protected:
map<unsigned int, ByteArray> dataList;
static const unsigned int TAG_SEQUENCE = (unsigned int)0x30;
static const unsigned int TAG_OCTET_STREAM = (unsigned int)0x04;
-// PKCS15Object();
PKCS15Object(Channel *channel);
- PKCS15Object(Channel *channel, ByteArray selectResponse);
+ PKCS15Object(Channel *channel, const ByteArray &selectResponse);
~PKCS15Object();
- int decodePath(ByteArray path, PKCS15Path &result);
- int getPath(unsigned int type, PKCS15Path &result);
- int getPaths(vector<PKCS15Path> &paths);
+ int decodePath(const ByteArray &path, PKCS15Path &result);
+ int getPath(unsigned int type, PKCS15Path &result) const;
+ int getPaths(vector<PKCS15Path> &paths) const;
- static ByteArray getOctetStream(const ByteArray &data);
+ static const ByteArray getOctetStream(const ByteArray &data);
};
} /* namespace smartcard_service_api */
private :
ByteArray path;
int index;
- int length;
+ size_t length;
- bool parseData(ByteArray &data);
+ bool parseData(const ByteArray &data);
public:
PKCS15Path();
- PKCS15Path(ByteArray &data);
- PKCS15Path(ByteArray path, int index);
- PKCS15Path(unsigned char *path, unsigned int length, int index);
+ PKCS15Path(const ByteArray &data);
+ PKCS15Path(const ByteArray &path, int index);
+ PKCS15Path(const unsigned char *path,
+ size_t length, int index);
~PKCS15Path();
- int getPath(ByteArray &path);
- bool hasIndexLength();
- int getIndex();
- unsigned int getLength();
- int encode(ByteArray &result);
+ inline const ByteArray getPath() const { return path; }
+ inline bool hasIndexLength() const { return (length != 0); }
+ inline int getIndex() const { return index; }
+ inline size_t size() const { return length; }
+ int encode(ByteArray &result) const;
};
} /* namespace smartcard_service_api */
namespace smartcard_service_api
{
- class PKCS15TokenInfo: public PKCS15Object
+ class PKCS15TokenInfo : public PKCS15Object
{
public:
PKCS15TokenInfo(Channel *channel);
protected:
Channel *channel;
-// ProviderHelper();
-
public:
- ProviderHelper(Channel *channel);
- ~ProviderHelper();
+ ProviderHelper(Channel *channel) : channel(channel) {}
+ virtual ~ProviderHelper() {}
- Channel *getChannel();
+ inline Channel *getChannel() { return channel; }
};
} /* namespace smartcard_service_api */
/* standard library header */
#include <vector>
+#include <string>
/* SLP library header */
class ReaderHelper : public Synchronous
{
protected:
- char name[30];
+ string name;
vector<SessionHelper *> sessions;
SEServiceHelper *seService;
bool present;
- ReaderHelper();
+ ReaderHelper() : seService(NULL), present(false) {}
virtual ~ReaderHelper() {}
public:
- inline const char *getName() { return name; }
- inline SEServiceHelper *getSEService() { return seService; }
- inline bool isSecureElementPresent() { return present; }
+ inline const char *getName() const { return name.c_str(); }
+ inline SEServiceHelper *getSEService() const { return seService; }
+ inline bool isSecureElementPresent() const { return present; }
virtual void closeSessions()
throw(ErrorIO &, ErrorIllegalState &) = 0;
public:
Record() : id(0) {}
- Record(unsigned int id, ByteArray buffer)
- : id(id), data(buffer) {};
+ Record(unsigned int id, const ByteArray &buffer) : id(id),
+ data(buffer) {};
~Record() {}
- inline unsigned int getID() { return id; }
- inline ByteArray getData() { return data; }
+ inline unsigned int getID() const { return id; }
+ inline const ByteArray getData() const { return data; }
};
} /* namespace smartcard_service_api */
public:
SEServiceHelper() : connected(false) {}
- virtual ~SEServiceHelper();
+ virtual ~SEServiceHelper() {}
vector<ReaderHelper *> getReaders() { return readers; }
bool isConnected() { return connected; }
{
class Serializable
{
- virtual ByteArray serialize() = 0;
- virtual void deserialize(ByteArray buffer) = 0;
+ virtual const ByteArray serialize() const = 0;
+ virtual void deserialize(const ByteArray &buffer) = 0;
};
} /* namespace smartcard_service_api */
bool closed;
public:
- SessionHelper(ReaderHelper *reader);
+ SessionHelper(ReaderHelper *reader) :
+ reader(reader), closed(true) {}
virtual ~SessionHelper() {}
ReaderHelper *getReader() const throw() { return reader; }
virtual int getATR(getATRCallback callback, void *userData) = 0;
virtual int close(closeSessionCallback callback, void *userData) = 0;
- virtual int openBasicChannel(ByteArray &aid, openChannelCallback callback, void *userData) = 0;
- virtual int openBasicChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData) = 0;
- virtual int openLogicalChannel(ByteArray &aid, openChannelCallback callback, void *userData) = 0;
- virtual int openLogicalChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData) = 0;
+ virtual int openBasicChannel(const ByteArray &aid, openChannelCallback callback, void *userData) = 0;
+ virtual int openBasicChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData) = 0;
+ virtual int openLogicalChannel(const ByteArray &aid, openChannelCallback callback, void *userData) = 0;
+ virtual int openLogicalChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData) = 0;
- virtual ByteArray getATRSync()
+ virtual const ByteArray getATRSync()
throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
ErrorIllegalState &, ErrorIllegalParameter &) = 0;
throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
ErrorIllegalState &, ErrorIllegalParameter &) = 0;
- virtual Channel *openBasicChannelSync(ByteArray &aid)
+ virtual Channel *openBasicChannelSync(const ByteArray &aid)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
- virtual Channel *openBasicChannelSync(unsigned char *aid, unsigned int length)
+ virtual Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
- virtual Channel *openLogicalChannelSync(ByteArray &aid)
+ virtual Channel *openLogicalChannelSync(const ByteArray &aid)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
- virtual Channel *openLogicalChannelSync(unsigned char *aid, unsigned int length)
+ virtual Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
};
SimpleTLV(TLVHelper *parent);
SimpleTLV(const ByteArray &array, TLVHelper *parent);
- int decodeTag(unsigned char *buffer);
- int decodeLength(unsigned char *buffer);
- int decodeValue(unsigned char *buffer);
+ int decodeTag(const unsigned char *buffer);
+ int decodeLength(const unsigned char *buffer);
+ int decodeValue(const unsigned char *buffer);
- TLVHelper *getChildTLV(ByteArray data);
+ TLVHelper *getChildTLV(const ByteArray &data);
public:
SimpleTLV();
SimpleTLV(const ByteArray &array);
~SimpleTLV();
- static ByteArray getOctetString(const ByteArray &array);
+ static const ByteArray getOctetString(const ByteArray &array);
static bool getBoolean(const ByteArray &array);
static int getInteger(const ByteArray &array);
- static ByteArray getOctetString(SimpleTLV &tlv);
+ static const ByteArray getOctetString(SimpleTLV &tlv);
static bool getBoolean(SimpleTLV &tlv);
static int getInteger(SimpleTLV &tlv);
- static ByteArray encode(unsigned int tag, ByteArray buffer);
- static ByteArray encode(unsigned int tag, unsigned char *buffer, unsigned int length);
+ static const ByteArray encode(unsigned int tag, const ByteArray &buffer);
+ static const ByteArray encode(unsigned int tag, unsigned char *buffer, unsigned int length);
};
} /* namespace smartcard_service_api */
TLVHelper *parentTLV;
TLVHelper *childTLV;
- char strBuffer[200];
ByteArray tlvBuffer;
unsigned int offset;
unsigned int currentL;
ByteArray currentV;
- void initialize(TLVHelper *parent = NULL);
TLVHelper(TLVHelper *parent);
TLVHelper(const ByteArray &array, TLVHelper *parent);
- virtual int decodeTag(unsigned char *buffer) = 0;
- virtual int decodeLength(unsigned char *buffer) = 0;
- virtual int decodeValue(unsigned char *buffer) = 0;
+ virtual int decodeTag(const unsigned char *buffer) = 0;
+ virtual int decodeLength(const unsigned char *buffer) = 0;
+ virtual int decodeValue(const unsigned char *buffer) = 0;
- virtual TLVHelper *getChildTLV(ByteArray data) = 0;
+ virtual TLVHelper *getChildTLV(const ByteArray &data) = 0;
TLVHelper *getParentTLV();
bool setTLVBuffer(const ByteArray &array, TLVHelper *parent);
- bool setTLVBuffer(unsigned char *buffer, unsigned int length, TLVHelper *parent);
+ bool setTLVBuffer(const unsigned char *buffer, unsigned int length, TLVHelper *parent);
- bool _isEndOfBuffer() { return offset >= tlvBuffer.getLength(); }
+ inline bool _isEndOfBuffer() const { return offset >= tlvBuffer.size(); }
bool _decodeTLV();
- unsigned int _getTag() { return currentT; }
- unsigned int _getLength() { return currentL; }
- ByteArray _getValue() { return currentV; }
+ inline unsigned int _getTag() const { return currentT; }
+ inline unsigned int _size() const { return currentL; }
+ inline const ByteArray _getValue() const { return currentV; }
public:
TLVHelper();
TLVHelper(const ByteArray &array);
- ~TLVHelper();
+ virtual ~TLVHelper();
bool setTLVBuffer(const ByteArray &array) { return setTLVBuffer(array, NULL); }
- bool setTLVBuffer(unsigned char *buffer, unsigned int length) { return setTLVBuffer(buffer, length, NULL); }
+ bool setTLVBuffer(const unsigned char *buffer, unsigned int length) { return setTLVBuffer(buffer, length, NULL); }
- bool isEndOfBuffer() { return currentTLV->_isEndOfBuffer(); }
- bool decodeTLV() { return currentTLV->_decodeTLV(); }
+ inline bool isEndOfBuffer() const { return currentTLV->_isEndOfBuffer(); }
+ inline bool decodeTLV() { return currentTLV->_decodeTLV(); }
- unsigned int getTag() { return currentTLV->_getTag(); }
- unsigned int getLength() { return currentTLV->_getLength(); }
- ByteArray getValue() { return currentTLV->_getValue(); }
+ unsigned int getTag() const { return currentTLV->_getTag(); }
+ unsigned int size() const { return currentTLV->_size(); }
+ const ByteArray getValue() const { return currentTLV->_getValue(); }
- const char *toString();
+ const string toString() const;
bool enterToValueTLV();
bool returnToParentTLV();
namespace smartcard_service_api
{
- typedef void (*terminalNotificationCallback)(void *terminal, int event, int error, void *user_param);
+ typedef void (*terminalNotificationCallback)(const void *terminal, int event, int error, void *user_param);
- typedef void (*terminalTransmitCallback)(unsigned char *buffer, unsigned int length, int error, void *userParam);
- typedef void (*terminalGetATRCallback)(unsigned char *buffer, unsigned int length, int error, void *userParam);
+ typedef void (*terminalTransmitCallback)(const unsigned char *buffer, unsigned int length, int error, void *userParam);
+ typedef void (*terminalGetATRCallback)(const unsigned char *buffer, unsigned int length, int error, void *userParam);
class Terminal : public Synchronous
{
virtual bool initialize() = 0;
virtual void finalize() = 0;
- inline bool isInitialized() { return initialized; }
+ inline bool isInitialized() const { return initialized; }
- inline char *getName() { return name; }
+ inline const char *getName() const { return name; }
inline void setStatusCallback(terminalNotificationCallback callback) { statusCallback = callback; }
- virtual bool isSecureElementPresence() = 0;
+ virtual bool isSecureElementPresence() const = 0;
- virtual int transmitSync(ByteArray command, ByteArray &result) = 0;
+ virtual int transmitSync(const ByteArray &command, ByteArray &result) = 0;
virtual int getATRSync(ByteArray &atr) = 0;
- virtual int transmit(ByteArray command, terminalTransmitCallback callback, void *userData) = 0;
+ virtual int transmit(const ByteArray &command, terminalTransmitCallback callback, void *userData) = 0;
virtual int getATR(terminalGetATRCallback callback, void *userData) = 0;
};
# FOR COMMENTING DEFINITION, MUST USE %% instead of %
%global use_autostart "-DUSE_AUTOSTART=1"
%global use_gdbus "-DUSE_GDBUS=1"
-%global test_client "-DTEST_CLIENT=1"
+#%%global test_client "-DTEST_CLIENT=1"
Name: smartcard-service
Summary: Smartcard Service FW
MESSAGE("CHECK MODULE in ${PROJECT_NAME} ${pkgs_server_LDFLAGS}")
-SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden -std=c++0x")
-SET(ARM_CXXFLAGS "${ARM_CXXLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}")
-SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
-
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden -std=c++0x")
+SET(ARM_CXXFLAGS "${ARM_CXXLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}")
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
+
FIND_PROGRAM(UNAME NAMES uname)
EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
IF("${ARCH}" MATCHES "^arm.*")
}
#ifndef USE_GDBUS
- bool ClientInstance::sendMessageToAllServices(int socket, Message &msg)
+ bool ClientInstance::sendMessageToAllServices(int socket, const Message &msg)
{
bool result = true;
- map<unsigned int, ServiceInstance *>::iterator item;
+ map<unsigned int, ServiceInstance *>::const_iterator item;
for (item = mapServices.begin(); item != mapServices.end(); item++)
{
- if (ServerIPC::getInstance()->sendMessage(socket, &msg) == false)
+ if (ServerIPC::getInstance()->sendMessage(socket, msg) == false)
result = false;
}
APDUHelper apdu;
int rv;
- if (isBasicChannel() == false)
+ if (isClosed() == false && isBasicChannel() == false)
{
/* close channel */
command = apdu.generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
rv = terminal->transmitSync(command, result);
- if (rv == 0 && result.getLength() >= 2)
+ if (rv == 0 && result.size() >= 2)
{
ResponseHelper resp(result);
}
else
{
- _ERR("select apdu is failed, rv [%d], length [%d]", rv, result.getLength());
+ _ERR("select apdu is failed, rv [%d], length [%d]", rv, result.size());
}
- }
- channelNum = -1;
+ channelNum = -1;
+ }
}
- int ServerChannel::transmitSync(ByteArray command, ByteArray &result)
+ int ServerChannel::transmitSync(const ByteArray &command, ByteArray &result)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
int ret = -1;
APDUCommand helper;
+ ByteArray cmd;
if (isClosed() == true)
{
helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
(helper.getINS() == APDUCommand::INS_MANAGE_CHANNEL))
{
- return -4; /* security reason */
+ return SCARD_ERROR_SECURITY_NOT_ALLOWED;
}
}
/* TODO : insert channel ID using atr information */
helper.setChannel(APDUCommand::CLA_CHANNEL_STANDARD, channelNum);
- helper.getBuffer(command);
+ helper.getBuffer(cmd);
- _DBG("command [%d] : %s", command.getLength(), command.toString());
+ _DBG("command [%d] : %s", cmd.size(), cmd.toString().c_str());
- ret = terminal->transmitSync(command, result);
+ ret = terminal->transmitSync(cmd, result);
return ret;
}
}
/* response to client */
- ServerIPC::getInstance()->sendMessage(socket, &response);
+ ServerIPC::getInstance()->sendMessage(socket, response);
}
break;
resource->removeService(socket, msg->param1);
/* response to client */
- ServerIPC::getInstance()->sendMessage(socket, &response);
+ ServerIPC::getInstance()->sendMessage(socket, response);
}
break;
response.param1 = handle;
/* response to client */
- ServerIPC::getInstance()->sendMessage(socket, &response);
+ ServerIPC::getInstance()->sendMessage(socket, response);
}
break;
}
/* response to client */
- ServerIPC::getInstance()->sendMessage(socket, &response);
+ ServerIPC::getInstance()->sendMessage(socket, response);
}
break;
response.param1 = IntegerHandle::INVALID_HANDLE;
response.param2 = 0;
- response.data.releaseBuffer();
+ response.data.clear();
try
{
}
/* response to client */
- ServerIPC::getInstance()->sendMessage(socket, &response);
+ ServerIPC::getInstance()->sendMessage(socket, response);
}
break;
response.param1 = resource->getChannelCount(socket, msg->error/* service context */, msg->param1);
/* response to client */
- ServerIPC::getInstance()->sendMessage(socket, &response);
+ ServerIPC::getInstance()->sendMessage(socket, response);
}
break;
}
/* response to client */
- ServerIPC::getInstance()->sendMessage(socket, &response);
+ ServerIPC::getInstance()->sendMessage(socket, response);
}
break;
}
/* response to client */
- ServerIPC::getInstance()->sendMessage(socket, &response);
+ ServerIPC::getInstance()->sendMessage(socket, response);
}
break;
}
/* response to client */
- ServerIPC::getInstance()->sendMessage(socket, &response);
+ ServerIPC::getInstance()->sendMessage(socket, response);
}
break;
break;
default :
- _DBG("unknown message [%s], socket [%d]", msg->toString(), socket);
+ _DBG("unknown message [%s], socket [%d]", msg->toString().c_str(), socket);
break;
}
namespace smartcard_service_api
{
- ServerIPC::ServerIPC():IPCHelper()
+ ServerIPC::ServerIPC() : IPCHelper()
{
_BEGIN();
ByteArray cookie;
int result, gid;
- if (buffer.getLength() < 20)
+ if (buffer.size() < 20)
return msg;
- cookie.setBuffer(buffer.getBuffer(), 20);
+ cookie.assign(buffer.getBuffer(), 20);
gid = security_server_get_gid("smartcard-daemon");
if ((result = security_server_check_privilege(cookie.getBuffer(), gid)) != SECURITY_SERVER_API_SUCCESS)
dispMsg.setPeerSocket(peerSocket);
/* push to dispatcher */
- ServerDispatcher::getInstance()->pushMessage(&dispMsg);
+ ServerDispatcher::getInstance()->pushMessage(dispMsg);
}
_END();
/* read message */
if ((msg = retrieveMessage(peerSocket)) != NULL)
{
- DispatcherMsg dispMsg(msg, peerSocket);
+ DispatcherMsg dispMsg(*msg, peerSocket);
/* push to dispatcher */
- ServerDispatcher::getInstance()->pushMessage(&dispMsg);
+ ServerDispatcher::getInstance()->pushMessage(dispMsg);
result = TRUE;
namespace smartcard_service_api
{
- ServerReader::ServerReader(ServerSEService *seService, char *name, Terminal *terminal) :
- ReaderHelper()
+ ServerReader::ServerReader(ServerSEService *seService,
+ const char *name, Terminal *terminal) : ReaderHelper()
{
- unsigned int length = 0;
-
- acList = NULL;
-
- if (seService == NULL || name == NULL || strlen(name) == 0 || terminal == NULL)
+ if (seService == NULL || name == NULL ||
+ strlen(name) == 0 || terminal == NULL)
{
_ERR("invalid param");
this->terminal = terminal;
this->seService = seService;
-
- length = strlen(name);
- length = (length < sizeof(this->name)) ? length : sizeof(this->name);
- memcpy(this->name, name, length);
-
- /* open admin channel */
- adminChannel = new ServerChannel(NULL, NULL, 0, terminal);
- if (adminChannel == NULL)
- {
- _ERR("alloc failed");
- }
+ this->name = name;
}
ServerReader::~ServerReader()
{
closeSessions();
-
- if (acList != NULL)
- {
- delete acList;
- acList = NULL;
- }
-
- if (adminChannel != NULL)
- {
- delete adminChannel;
- adminChannel = NULL;
- }
}
void ServerReader::closeSessions()
sessions.clear();
}
- AccessControlList *ServerReader::getAccessControlList()
- {
- if (acList == NULL)
- {
- /* load access control */
- acList = new GPACE();
- if (acList != NULL)
- {
- acList->loadACL(adminChannel);
- }
- else
- {
- _ERR("alloc failed");
- }
- }
-
- return acList;
- }
-
ServerSession *ServerReader::openSessionSync()
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
return openSessionSync(temp, NULL);
}
- ServerSession *ServerReader::openSessionSync(vector<ByteArray> &certHashes, void *caller)
+ ServerSession *ServerReader::openSessionSync(const vector<ByteArray> &certHashes, void *caller)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
ServerSession *session = NULL;
mapClients.clear();
}
- int ServerResource::getClientCount()
+ int ServerResource::getClientCount() const
{
return (int)mapClients.size();
}
}
}
#else
- bool ServerResource::createClient(void *ioChannel, int socket, int watchID, int state, int pid)
+ bool ServerResource::createClient(void *ioChannel, int socket,
+ int watchID, int state, int pid)
{
bool result = false;
if (getClient(socket) == NULL)
{
- ClientInstance *instance = new ClientInstance(ioChannel, socket, watchID, state, pid);
+ ClientInstance *instance = new ClientInstance(ioChannel,
+ socket, watchID, state, pid);
if (instance != NULL)
{
mapClients.insert(make_pair(socket, instance));
return result;
}
+ const ClientInstance *ServerResource::getClient(int socket) const
+ {
+ const ClientInstance *result = NULL;
+ map<int, ClientInstance *>::const_iterator item;
+
+ if ((item = mapClients.find(socket)) != mapClients.end())
+ {
+ result = item->second;
+ }
+
+ return result;
+ }
+
void ServerResource::setPID(int socket, int pid)
{
map<int, ClientInstance *>::iterator item;
mapClients.clear();
}
- int ServerResource::getClientCount()
+ int ServerResource::getClientCount() const
{
return (int)mapClients.size();
}
}
}
- unsigned int ServerResource::createSession(int socket, unsigned int handle, unsigned int readerID, vector<ByteArray> &certHashes, void *caller)
+ unsigned int ServerResource::createSession(int socket, unsigned int handle, unsigned int readerID, const vector<ByteArray> &certHashes, void *caller)
{
unsigned int result = -1;
Terminal *temp = NULL;
}
}
- unsigned int ServerResource::createChannel(int socket, unsigned int handle, unsigned int sessionID, int channelType, ByteArray aid)
+ unsigned int ServerResource::createChannel(int socket, unsigned int handle, unsigned int sessionID, int channelType, const ByteArray &aid)
throw(ExceptionBase &)
{
unsigned int result = -1;
return result;
}
+ const Terminal *ServerResource::getTerminal(unsigned int terminalID) const
+ {
+ const Terminal *result = NULL;
+ map<unsigned int, Terminal *>::const_iterator item;
+
+ if ((item = mapTerminals.find(terminalID)) != mapTerminals.end())
+ {
+ result = item->second;
+ }
+ else
+ {
+ _ERR("Terminal doesn't exist [%d]", terminalID);
+ }
+
+ return result;
+ }
+
Terminal *ServerResource::getTerminal(const char *name)
{
Terminal *result = NULL;
return result;
}
- Terminal *ServerResource::getTerminalByIndex(int index)
+ Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID)
{
- int count = 0;
Terminal *result = NULL;
- map<unsigned int, Terminal *>::iterator item;
+ map<unsigned int, unsigned int>::iterator item;
- for (item = mapTerminals.begin(), count = 0; item != mapTerminals.end(); item++, count++) {
- if (count == index) {
- result = item->second;
- break;
- }
+ if ((item = mapReaders.find(readerID)) != mapReaders.end())
+ {
+ result = getTerminal(item->second);
+ }
+ else
+ {
+ _ERR("Terminal doesn't exist, reader ID [%d]", readerID);
}
return result;
}
- Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID)
+ const Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID) const
{
- Terminal *result = NULL;
- map<unsigned int, unsigned int>::iterator item;
+ const Terminal *result = NULL;
+ map<unsigned int, unsigned int>::const_iterator item;
if ((item = mapReaders.find(readerID)) != mapReaders.end())
{
return result;
}
- unsigned int ServerResource::getTerminalID(const char *name)
+ unsigned int ServerResource::getTerminalID(const char *name) const
{
unsigned int result = IntegerHandle::INVALID_HANDLE;
- map<unsigned int, Terminal *>::iterator item;
+ map<unsigned int, Terminal *>::const_iterator item;
- for (item = mapTerminals.begin(); item != mapTerminals.end(); item++)
+ for (item = mapTerminals.begin();
+ item != mapTerminals.end(); item++)
{
- if (strncmp(name, item->second->getName(), strlen(name)) == 0)
+ if (strncmp(name, item->second->getName(),
+ strlen(name)) == 0)
{
result = item->first;
break;
return result;
}
- bool ServerResource::_isAuthorizedAccess(ServerChannel *channel, ByteArray aid, vector<ByteArray> &hashes)
+ bool ServerResource::_isAuthorizedAccess(ServerChannel *channel,
+ const ByteArray aid, const vector<ByteArray> &hashes)
{
bool result = true;
AccessControlList *acList = NULL;
/* open channel */
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_OPEN_LOGICAL_CHANNEL, 0, ByteArray::EMPTY);
rv = terminal->transmitSync(command, response);
- if (rv == 0 && response.getLength() >= 2)
+ if (rv == 0 && response.size() >= 2)
{
ResponseHelper resp(response);
}
else
{
- _ERR("transmitSync failed, rv [%d], length [%d]", rv, response.getLength());
+ _ERR("transmitSync failed, rv [%d], length [%d]", rv, response.size());
}
return result;
/* open channel */
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
rv = terminal->transmitSync(command, response);
- if (rv == 0 && response.getLength() >= 2)
+ if (rv == 0 && response.size() >= 2)
{
ResponseHelper resp(response);
}
else
{
- _ERR("select apdu is failed, rv [%d], length [%d]", rv, response.getLength());
+ _ERR("select apdu is failed, rv [%d], length [%d]", rv, response.size());
}
return result;
}
- unsigned int ServerResource::_createChannel(Terminal *terminal, ServiceInstance *service, int channelType, unsigned int sessionID, ByteArray aid)
+ unsigned int ServerResource::_createChannel(Terminal *terminal,
+ ServiceInstance *service, int channelType,
+ unsigned int sessionID, const ByteArray &aid)
throw(ExceptionBase &)
{
unsigned int result = IntegerHandle::INVALID_HANDLE;
}
}
- bool ServerResource::isValidReaderHandle(unsigned int reader)
+ bool ServerResource::isValidReaderHandle(unsigned int reader) const
{
return (getTerminalByReaderID(reader) != NULL);
}
- void ServerResource::getReaders(vector<pair<unsigned int, string> > &readers)
+ void ServerResource::getReaders(vector<pair<unsigned int, string> > &readers) const
{
- Terminal *terminal;
- map<unsigned int, unsigned int>::iterator item;
+ const Terminal *terminal;
+ map<unsigned int, unsigned int>::const_iterator item;
readers.clear();
}
}
- int ServerResource::getReadersInformation(ByteArray &info)
+ int ServerResource::getReadersInformation(ByteArray &info) const
{
int result = 0;
unsigned char *buffer = NULL;
if (mapReaders.size() > 0)
{
- Terminal *terminal = NULL;
- map<unsigned int, unsigned int>::iterator item;
+ const Terminal *terminal = NULL;
+ map<unsigned int, unsigned int>::const_iterator item;
for (item = mapReaders.begin(); item != mapReaders.end(); item++)
{
}
}
- info.setBuffer(buffer, length);
+ info.assign(buffer, length);
delete []buffer;
}
else
}
#ifndef USE_GDBUS
- bool ServerResource::sendMessageToAllClients(Message &msg)
+ bool ServerResource::sendMessageToAllClients(const Message &msg)
{
bool result = true;
- map<int, ClientInstance *>::iterator item;
+ map<int, ClientInstance *>::const_iterator item;
- for (item = mapClients.begin(); item != mapClients.end(); item++)
+ for (item = mapClients.begin();
+ item != mapClients.end(); item++)
{
- if (item->second->sendMessageToAllServices(item->second->getSocket(), msg) == false)
+ if (item->second->sendMessageToAllServices(
+ item->second->getSocket(), msg) == false)
result = false;
}
}
#endif
- void ServerResource::terminalCallback(void *terminal, int event, int error, void *user_param)
+ void ServerResource::terminalCallback(const void *terminal, int event,
+ int error, void *user_param)
{
_DBG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
/* send all client to refresh reader */
msg.message = msg.MSG_NOTIFY_SE_INSERTED;
msg.param1 = readerID;
- msg.data.setBuffer((unsigned char *)terminal, strlen((char *)terminal) + 1);
+ msg.data.assign((uint8_t *)terminal,
+ strlen((char *)terminal) + 1);
instance.sendMessageToAllClients(msg);
#endif
readerID = instance.getReaderID((char *)terminal);
#ifdef USE_GDBUS
- ServerGDBus::getInstance().emitReaderRemoved(readerID, (const char *)terminal);
+ ServerGDBus::getInstance().emitReaderRemoved(
+ readerID, (const char *)terminal);
#else
Message msg;
/* send all client to refresh reader */
msg.message = msg.MSG_NOTIFY_SE_REMOVED;
msg.param1 = readerID;
- msg.data.setBuffer((unsigned char *)terminal, strlen((char *)terminal) + 1);
+ msg.data.assign((uint8_t *)terminal,
+ strlen((char *)terminal) + 1);
instance.sendMessageToAllClients(msg);
#endif
return result;
}
- unsigned int ServerResource::getReaderID(const char *name)
+ unsigned int ServerResource::getReaderID(const char *name) const
{
- unsigned int result = IntegerHandle::INVALID_HANDLE, terminalID = IntegerHandle::INVALID_HANDLE;
+ unsigned int result = IntegerHandle::INVALID_HANDLE,
+ terminalID = IntegerHandle::INVALID_HANDLE;
terminalID = getTerminalID(name);
if (terminalID != IntegerHandle::INVALID_HANDLE)
{
- map<unsigned int, unsigned int>::iterator item;
+ map<unsigned int, unsigned int>::const_iterator item;
- for (item = mapReaders.begin(); item != mapReaders.end(); item++)
+ for (item = mapReaders.begin();
+ item != mapReaders.end(); item++)
{
if (item->second == terminalID)
{
}
}
- bool ServerResource::isAuthorizedNFCAccess(Terminal *terminal, ByteArray &aid, vector<ByteArray> &hashes)
+ bool ServerResource::isAuthorizedNFCAccess(Terminal *terminal,
+ const ByteArray &aid, const vector<ByteArray> &hashes)
{
bool result = false;
libraries.push_back(libHandle);
- pair<char *, Terminal *> newPair(terminal->getName(), terminal);
+ pair<string, Terminal *> newPair(terminal->getName(), terminal);
mapTerminals.insert(newPair);
if (terminal->isSecureElementPresence() == true)
}
/* response to client */
- ServerIPC::getInstance()->sendMessage(socket, &response);
+ ServerIPC::getInstance()->sendMessage(socket, response);
#endif
return false;
}
- void ServerSEService::terminalCallback(void *terminal, int event, int error, void *user_param)
+ void ServerSEService::terminalCallback(const void *terminal, int event, int error, void *user_param)
{
switch (event)
{
/* send all client to refresh reader */
msg.message = msg.MSG_NOTIFY_SE_INSERTED;
- msg.data.setBuffer((unsigned char *)terminal,
+ msg.data.assign((unsigned char *)terminal,
strlen((char *)terminal) + 1);
ServerResource::getInstance().sendMessageToAllClients(msg);
/* send all client to refresh reader */
msg.message = msg.MSG_NOTIFY_SE_REMOVED;
- msg.data.setBuffer((unsigned char *)terminal,
+ msg.data.assign((unsigned char *)terminal,
strlen((char *)terminal) + 1);
ServerResource::getInstance().sendMessageToAllClients(msg);
namespace smartcard_service_api
{
ServerSession::ServerSession(ServerReader *reader,
- vector<ByteArray> &certHashes,
+ const vector<ByteArray> &certHashes,
void *caller, Terminal *terminal) : SessionHelper(reader)
{
this->terminal = NULL;
closeSync();
}
- ByteArray ServerSession::getATRSync()
+ const ByteArray ServerSession::getATRSync()
throw(ErrorIO &, ErrorIllegalState &)
{
/* call get atr to terminal */
+ if (atr.isEmpty()) {
+ if (terminal != NULL) {
+ int error = terminal->getATRSync(atr);
+
+ if (error < SCARD_ERROR_OK) {
+ _ERR("getATRSync failed, [%d]", error);
+ }
+ } else {
+ _ERR("terminal is null.");
+ }
+ }
+
return atr;
}
channels.clear();
}
- Channel *ServerSession::openBasicChannelSync(ByteArray &aid)
+ Channel *ServerSession::openBasicChannelSync(const ByteArray &aid)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
return openBasicChannelSync(aid, NULL);
}
- Channel *ServerSession::openBasicChannelSync(ByteArray &aid, void *caller)
+ Channel *ServerSession::openBasicChannelSync(const ByteArray &aid, void *caller)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
ServerChannel *channel = NULL;
return channel;
}
- Channel *ServerSession::openBasicChannelSync(unsigned char *aid, unsigned int length)
+ Channel *ServerSession::openBasicChannelSync(const unsigned char *aid, unsigned int length)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
ByteArray temp(aid, length);
return openBasicChannelSync(temp);
}
- Channel *ServerSession::openBasicChannelSync(unsigned char *aid, unsigned int length, void *caller)
+ Channel *ServerSession::openBasicChannelSync(const unsigned char *aid, unsigned int length, void *caller)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
ByteArray temp(aid, length);
return openBasicChannelSync(temp, caller);
}
- Channel *ServerSession::openLogicalChannelSync(ByteArray &aid)
+ Channel *ServerSession::openLogicalChannelSync(const ByteArray &aid)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
return openLogicalChannelSync(aid, NULL);
}
- Channel *ServerSession::openLogicalChannelSync(ByteArray &aid, void *caller)
+ Channel *ServerSession::openLogicalChannelSync(const ByteArray &aid, void *caller)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
ServerChannel *channel = NULL;
return channel;
}
- Channel *ServerSession::openLogicalChannelSync(unsigned char *aid, unsigned int length)
+ Channel *ServerSession::openLogicalChannelSync(const unsigned char *aid, unsigned int length)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
ByteArray temp(aid, length);
return openLogicalChannelSync(temp, NULL);
}
- Channel *ServerSession::openLogicalChannelSync(unsigned char *aid, unsigned int length, void *caller)
+ Channel *ServerSession::openLogicalChannelSync(const unsigned char *aid, unsigned int length, void *caller)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
ByteArray temp(aid, length);
}
}
- unsigned int ServiceInstance::openSession(Terminal *terminal, vector<ByteArray> &certHashes, void *caller)
+ unsigned int ServiceInstance::openSession(Terminal *terminal, const vector<ByteArray> &certHashes, void *caller)
{
unsigned int handle = IntegerHandle::assignHandle();
mapSessions.clear();
}
- unsigned int ServiceInstance::openChannel(unsigned int session, int channelNum, ByteArray response)
+ unsigned int ServiceInstance::openChannel(unsigned int session, int channelNum, const ByteArray &response)
{
Terminal *terminal = getTerminal(session);
ServerChannel *channel = NULL;
void removeService(unsigned int handle);
void removeServices();
#ifndef USE_GDBUS
- bool sendMessageToAllServices(int socket, Message &msg);
+ bool sendMessageToAllServices(int socket, const Message &msg);
#endif
void generateCertificationHashes();
protected:
void closeSync()
throw(ErrorIO &, ErrorIllegalState &);
- int transmitSync(ByteArray command, ByteArray &result)
+ int transmitSync(const ByteArray &command, ByteArray &result)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
public:
Terminal *getTerminal() { return terminal; }
int close(closeChannelCallback callback, void *userParam) { return -1; }
- int transmit(ByteArray command, transmitCallback callback, void *userParam) { return -1; };
+ int transmit(const ByteArray &command, transmitCallback callback, void *userParam) { return -1; };
friend class ServerReader;
friend class ServerSession;
{
private:
Terminal *terminal;
- ServerChannel *adminChannel;
- AccessControlList *acList;
- ServerReader(ServerSEService *seService, char *name, Terminal *terminal);
+ ServerReader(ServerSEService *seService, const char *name, Terminal *terminal);
~ServerReader();
int openSession(openSessionCallback callback, void *userData) { return -1; }
void closeSessions()
throw(ErrorIO &, ErrorIllegalState &);
- AccessControlList *getAccessControlList();
-
ServerSession *openSessionSync()
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
- ServerSession *openSessionSync(vector<ByteArray> &certHashes, void *caller)
+ ServerSession *openSessionSync(const vector<ByteArray> &certHashes, void *caller)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
friend class ServerSEService;
bool appendSELibrary(char *library);
void clearSELibraries();
- static void terminalCallback(void *terminal, int event, int error, void *user_param);
+ static void terminalCallback(const void *terminal, int event, int error, void *user_param);
int _openLogicalChannel(Terminal *terminal);
int _closeLogicalChannel(Terminal *terminal, int channelNum);
- bool _isAuthorizedAccess(ServerChannel *channel, ByteArray aid, vector<ByteArray> &hashes);
- unsigned int _createChannel(Terminal *terminal, ServiceInstance *service, int channelType, unsigned int sessionID, ByteArray aid)
+ bool _isAuthorizedAccess(ServerChannel *channel, const ByteArray &aid, const vector<ByteArray> &hashes);
+ unsigned int _createChannel(Terminal *terminal, ServiceInstance *service, int channelType, unsigned int sessionID, const ByteArray &aid)
throw(ExceptionBase &);
public:
void unloadSecureElements();
Terminal *getTerminal(unsigned int terminalID);
+ const Terminal *getTerminal(unsigned int terminalID) const;
Terminal *getTerminal(const char *name);
- Terminal *getTerminalByIndex(int index);
Terminal *getTerminalByReaderID(unsigned int readerID);
- unsigned int getTerminalID(const char *name);
- int getReadersInformation(ByteArray &info);
- void getReaders(vector<pair<unsigned int, string> > &readers);
- bool isValidReaderHandle(unsigned int reader);
+ const Terminal *getTerminalByReaderID(unsigned int readerID) const;
+ unsigned int getTerminalID(const char *name) const;
+ int getReadersInformation(ByteArray &info) const;
+ void getReaders(vector<pair<unsigned int, string> > &readers) const;
+ bool isValidReaderHandle(unsigned int reader) const;
unsigned int createReader(unsigned int terminalID);
- unsigned int getReaderID(const char *name);
+ unsigned int getReaderID(const char *name) const;
void removeReader(unsigned int readerID);
#ifdef USE_GDBUS
ClientInstance *getClient(const char *name);
void removeClient(const char *name);
void removeClients();
- int getClientCount();
+ int getClientCount() const;
ServiceInstance *createService(const char *name);
ServiceInstance *getService(const char *name, unsigned int handle);
bool createClient(void *ioChannel, int socket, int watchID, int state, int pid);
bool createClient(int pid);
ClientInstance *getClient(int socket);
+ const ClientInstance *getClient(int socket) const;
void setPID(int socket, int pid);
void removeClient(int socket);
void removeClients();
- int getClientCount();
+ int getClientCount() const;
ServiceInstance *createService(int socket);
ServiceInstance *getService(int socket, unsigned int handle);
void removeService(int socket, unsigned int handle);
void removeServices(int socket);
- unsigned int createSession(int socket, unsigned int handle, unsigned int readerID, vector<ByteArray> &certHashes, void *caller);
+ unsigned int createSession(int socket, unsigned int handle, unsigned int readerID, const vector<ByteArray> &certHashes, void *caller);
ServerSession *getSession(int socket, unsigned int handle, unsigned int sessionID);
unsigned int getChannelCount(int socket, unsigned int handle, unsigned int sessionID);
void removeSession(int socket, unsigned int handle, unsigned int session);
bool isValidSessionHandle(int socket, unsigned int handle, unsigned int sessionID);
unsigned int createChannel(int socket, unsigned int handle,
- unsigned int sessionID, int channelType, ByteArray aid)
+ unsigned int sessionID, int channelType, const ByteArray &aid)
throw(ExceptionBase &);
Channel *getChannel(int socket, unsigned int handle, unsigned int channelID);
void removeChannel(int socket, unsigned int handle, unsigned int channelID);
AccessControlList *getAccessControlList(Terminal *terminal);
AccessControlList *getAccessControlList(ServerChannel *channel);
#ifndef USE_GDBUS
- bool sendMessageToAllClients(Message &msg);
+ bool sendMessageToAllClients(const Message &msg);
#endif
- bool isAuthorizedNFCAccess(Terminal *terminal, ByteArray &aid,
- vector<ByteArray> &hashes);
+ bool isAuthorizedNFCAccess(Terminal *terminal, const ByteArray &aid,
+ const vector<ByteArray> &hashes);
friend void terminalCallback(void *terminal, int event, int error, void *user_param);
};
{
private:
vector<void *> libraries;
- map<char *, Terminal *> mapTerminals;
+ map<string, Terminal *> mapTerminals;
ServerSEService();
~ServerSEService();
int openSELibraries();
void closeSELibraries();
- static void terminalCallback(void *terminal, int event, int error, void *user_param);
+ static void terminalCallback(const void *terminal, int event, int error, void *user_param);
static bool dispatcherCallback(void *message, int socket);
public:
void shutdown() {}
void shutdownSync() {}
- friend void terminalCallback(char *name, int event, int error, void *user_param);
+
+ friend void terminalCallback(const void *name, int event, int error, void *user_param);
friend bool dispatcherCallback(void *message, int socket);
friend class ServerDispatcher;
};
Terminal *terminal;
vector<ByteArray> certHashes;
- ServerSession(ServerReader *reader, vector<ByteArray> &certHashes, void *caller, Terminal *terminal);
+ ServerSession(ServerReader *reader,
+ const vector<ByteArray> &certHashes,
+ void *caller, Terminal *terminal);
- int getATR(getATRCallback callback, void *userData){ return -1; }
- int close(closeSessionCallback callback, void *userData){ return -1; }
+ int getATR(getATRCallback callback, void *userData) { return -1; }
+ int close(closeSessionCallback callback, void *userData) { return -1; }
- int openBasicChannel(ByteArray &aid, openChannelCallback callback, void *userData){ return -1; }
- int openBasicChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData){ return -1; }
- int openLogicalChannel(ByteArray &aid, openChannelCallback callback, void *userData){ return -1; }
- int openLogicalChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData){ return -1; }
+ int openBasicChannel(const ByteArray &aid, openChannelCallback callback, void *userData){ return -1; }
+ int openBasicChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData){ return -1; }
+ int openLogicalChannel(const ByteArray &aid, openChannelCallback callback, void *userData){ return -1; }
+ int openLogicalChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData){ return -1; }
public:
~ServerSession();
- ByteArray getATRSync()
+ const ByteArray getATRSync()
throw(ErrorIO &, ErrorIllegalState &);
void closeSync()
throw(ErrorIO &, ErrorIllegalState &);
void closeChannels()
throw(ErrorIO &, ErrorIllegalState &);
- Channel *openBasicChannelSync(ByteArray &aid)
+ Channel *openBasicChannelSync(const ByteArray &aid)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
- Channel *openBasicChannelSync(unsigned char *aid, unsigned int length)
+ Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
- Channel *openBasicChannelSync(ByteArray &aid, void *caller)
+ Channel *openBasicChannelSync(const ByteArray &aid, void *caller)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
- Channel *openBasicChannelSync(unsigned char *aid, unsigned int length, void *caller)
+ Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length, void *caller)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
- Channel *openLogicalChannelSync(ByteArray &aid)
+ Channel *openLogicalChannelSync(const ByteArray &aid)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
- Channel *openLogicalChannelSync(unsigned char *aid, unsigned int length)
+ Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
- Channel *openLogicalChannelSync(ByteArray &aid, void *caller)
+ Channel *openLogicalChannelSync(const ByteArray &aid, void *caller)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
- Channel *openLogicalChannelSync(unsigned char *aid, unsigned int length, void *caller)
+ Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length, void *caller)
throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
friend class ServerReader;
inline bool isVaildChannelHandle(unsigned int handle) { return (mapChannels.find(handle) != mapChannels.end()); }
inline ClientInstance *getParent() { return parent; }
- unsigned int openSession(Terminal *terminal, vector<ByteArray> &certHashes, void *caller);
+ unsigned int openSession(Terminal *terminal, const vector<ByteArray> &certHashes, void *caller);
ServerSession *getSession(unsigned int session);
void closeSession(unsigned int session);
void closeSessions();
Terminal *getTerminal(unsigned int session);
- unsigned int openChannel(unsigned int session, int channelNum, ByteArray response = ByteArray::EMPTY);
+ unsigned int openChannel(unsigned int session, int channelNum, const ByteArray &response = ByteArray::EMPTY);
ServerChannel *getChannel(/*unsigned int session, */unsigned int channel);
unsigned int getChannelCountBySession(unsigned int session);
{
_ERR("exception....");
}
- _DBG("atr[%d] : %s", temp.getLength(), temp.toString());
+ _DBG("atr[%d] : %s", temp.size(), temp.toString().c_str());
ByteArray aid;
- aid.setBuffer(buffer, sizeof(buffer));
+ aid.assign(buffer, sizeof(buffer));
try
{
ClientChannel *channel = (ClientChannel *)session->openLogicalChannelSync(aid);
int fid = 0x00003150;
response = channel->getSelectResponse();
- _INFO("response : %s", response.toString());
+ _INFO("response : %s", response.toString().c_str());
_DBG("isBasicChannel() = %s", channel->isBasicChannel() ? "Basic" : "Logical");
_DBG("isClosed() = %s", channel->isClosed() ? "Closed" : "Opened");
- data.setBuffer((unsigned char *)&fid, 2);
+ data.assign((unsigned char *)&fid, 2);
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_ID, 0, data);
int error = channel->transmitSync(command, response);
- _INFO("error : %d, response : %s", error, response.toString());
+ _INFO("error : %d, response : %s", error, response.toString().c_str());
channel->closeSync();
}
response = channel->getSelectResponse();
- _INFO("response : %s", response.toString());
+ _INFO("response : %s", response.toString().c_str());
_DBG("isBasicChannel() = %s", channel->isBasicChannel() ? "Basic" : "Logical");
_DBG("isClosed() = %s", channel->isClosed() ? "Closed" : "Opened");
- data.setBuffer((unsigned char *)&fid, 2);
+ data.assign((unsigned char *)&fid, 2);
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_ID, 0, data);
context->clientChannel->transmit(command, testTransmitCallback, userData);
}
ByteArray aid, result(atr, length);
user_context_t *context = (user_context_t *)userData;
- _DBG("atr[%d] : %s", result.getLength(), result.toString());
+ _DBG("atr[%d] : %s", result.size(), result.toString().c_str());
- aid.setBuffer(MF, sizeof(MF));
+ aid.assign(MF, sizeof(MF));
context->clientSession->openLogicalChannel(aid, testOpenChannelCallback, userData);
}