summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjh8801.jung <jh8801.jung@samsung.com>2017-09-13 08:34:28 +0900
committerJihoon Jung <jh8801.jung@samsung.com>2017-09-13 23:30:28 +0000
commit445e2ca54b98e34f955f33c25cffd63f453a40ca (patch)
tree34fb1b593efaa2271921e22b9f954742787c3466
parent2e34dbbc203e9cc3404ff4d7222905dba61b86db (diff)
downloadsmartcard-service-tizen_4.0.tar.gz
smartcard-service-tizen_4.0.tar.bz2
smartcard-service-tizen_4.0.zip
Signed-off-by: jh8801.jung <jh8801.jung@samsung.com> Change-Id: I3b214abab5231d8fcc75b5dae7e518f1e2fcd5e8
-rw-r--r--common/APDUHelper.cpp69
-rw-r--r--common/AccessCondition.cpp43
-rw-r--r--common/ByteArray.cpp37
-rw-r--r--common/EFDIR.cpp7
-rw-r--r--common/FCI.cpp7
-rw-r--r--common/FileObject.cpp73
-rw-r--r--common/GPARAACL.cpp4
-rw-r--r--common/GPARFACL.cpp149
-rw-r--r--common/ISO7816BERTLV.cpp31
-rw-r--r--common/OpensslHelper.cpp39
-rw-r--r--common/PKCS15.cpp35
-rw-r--r--common/PKCS15CDF.cpp29
-rw-r--r--common/PKCS15DODF.cpp37
-rw-r--r--common/PKCS15ODF.cpp48
-rw-r--r--common/PKCS15OID.cpp31
-rw-r--r--common/PKCS15Object.cpp14
-rw-r--r--common/SignatureHelper.cpp79
-rw-r--r--common/SimpleTLV.cpp49
-rw-r--r--common/Synchronous.cpp7
-rw-r--r--common/TLVHelper.cpp7
-rw-r--r--common/include/ByteArray.h2
-rwxr-xr-xpackaging/smartcard-service.spec2
-rw-r--r--server/ClientInstance.cpp7
-rw-r--r--server/ServerChannel.cpp17
-rwxr-xr-xserver/ServerGDBus.cpp4
-rw-r--r--server/ServerResource.cpp354
-rw-r--r--server/ServerSEService.cpp55
-rwxr-xr-xserver/ServerSession.cpp64
-rwxr-xr-xserver/ServiceInstance.cpp8
-rw-r--r--server/private/PKCS15CDFACL.cpp19
-rw-r--r--test-client/test-client-sync.cpp24
-rw-r--r--test-client/test-client.cpp29
32 files changed, 406 insertions, 974 deletions
diff --git a/common/APDUHelper.cpp b/common/APDUHelper.cpp
index d962e21..fafb581 100644
--- a/common/APDUHelper.cpp
+++ b/common/APDUHelper.cpp
@@ -210,37 +210,30 @@ namespace smartcard_service_api
uint32_t offset = 0;
uint32_t lengthSize = 1;
- if (command.size() < sizeof(header))
- {
+ if (command.size() < sizeof(header)) {
return false;
}
buffer = command.getBuffer(offset);
- if(buffer == NULL)
- {
+ if(buffer == NULL) {
return false;
}
memcpy(&header, buffer, sizeof(header));
offset += sizeof(header);
- if (isExtendedLength)
- {
+ if (isExtendedLength) {
lengthSize = 2;
}
- if (command.size() - offset > lengthSize)
- {
+ if (command.size() - offset > lengthSize) {
unsigned int length = 0;
/* data exist */
- if (isExtendedLength)
- {
+ if (isExtendedLength) {
/* TODO */
offset += 2;
- }
- else
- {
+ } else {
length = command.at(offset);
if (length == 0) {
length = 256;
@@ -252,10 +245,8 @@ namespace smartcard_service_api
offset += length;
}
- if (command.size() - offset == lengthSize)
- {
- if (isExtendedLength)
- {
+ if (command.size() - offset == lengthSize) {
+ if (isExtendedLength) {
unsigned int temp;
temp = command.at(offset) << 8;
@@ -267,9 +258,7 @@ namespace smartcard_service_api
setMaxResponseSize(temp);
offset += 2;
- }
- else
- {
+ } else {
if (command.at(offset) == 0)
setMaxResponseSize(256);
else
@@ -279,12 +268,9 @@ namespace smartcard_service_api
}
}
- if (command.size() == offset)
- {
+ if (command.size() == offset) {
result = true;
- }
- else
- {
+ } else {
_ERR("command stream is not correct, command.size() [%d], offset [%d]", command.size(), offset);
}
@@ -432,17 +418,13 @@ namespace smartcard_service_api
temp_len += sizeof(header);
/* calculate lc length */
- if (commandData.size() > 0)
- {
- if (isExtendedLength/*commandData.size() > 255*/)
- {
+ if (commandData.size() > 0) {
+ if (isExtendedLength/*commandData.size() > 255*/) {
lc[1] = (commandData.size() >> 8) & 0x000000FF;
lc[2] = commandData.size() & 0x000000FF;
lc_len = 3;
- }
- else
- {
+ } else {
lc[0] = commandData.size() & 0x000000FF;
lc_len = 1;
@@ -455,24 +437,17 @@ namespace smartcard_service_api
temp_len += commandData.size();
/* calculate le length */
- if (maxResponseSize > 0)
- {
- if (isExtendedLength/*commandData.size() > 255*/)
- {
- if (maxResponseSize < 65536)
- {
+ if (maxResponseSize > 0) {
+ if (isExtendedLength/*commandData.size() > 255*/) {
+ if (maxResponseSize < 65536) {
le[1] = (maxResponseSize >> 8) & 0x000000FF;
le[2] = maxResponseSize & 0x000000FF;
le_len = 3;
- }
- else if (maxResponseSize == 65536)
- {
+ } else if (maxResponseSize == 65536) {
le_len = 2;
}
- }
- else
- {
+ } else {
if (maxResponseSize < 256)
le[0] = maxResponseSize & 0x000000FF;
@@ -492,8 +467,7 @@ namespace smartcard_service_api
memcpy(temp_buffer + offset, &header, sizeof(header));
offset += sizeof(header);
- if (commandData.size() > 0)
- {
+ if (commandData.size() > 0) {
memcpy(temp_buffer + offset, &lc, lc_len);
offset += lc_len;
@@ -501,8 +475,7 @@ namespace smartcard_service_api
offset += commandData.size();
}
- if (maxResponseSize > 0)
- {
+ if (maxResponseSize > 0) {
memcpy(temp_buffer + offset, &le, le_len);
offset += le_len;
}
diff --git a/common/AccessCondition.cpp b/common/AccessCondition.cpp
index 86819b0..58e2a73 100644
--- a/common/AccessCondition.cpp
+++ b/common/AccessCondition.cpp
@@ -45,35 +45,30 @@ namespace smartcard_service_api
if (command.getBuffer() == NULL)
return false;
- if (listFilters.size() > 0)
- {
+ if (listFilters.size() > 0) {
unsigned int cmd, mask, rule;
vector<pair<ByteArray, ByteArray> >::const_iterator item;
cmd = *(unsigned int *)command.getBuffer();
- for (item = listFilters.begin(); item != listFilters.end(); item++)
- {
+ for (item = listFilters.begin(); item != listFilters.end(); item++) {
unsigned int *temp1 = NULL;
unsigned int *temp2 = NULL;
temp1 = (unsigned int *)item->second.getBuffer();
temp2 = (unsigned int *)item->first.getBuffer();
- if(temp1 == NULL || temp2 == NULL)
+ if (temp1 == NULL || temp2 == NULL)
continue;
mask = *temp1;
rule = *temp2;
- if ((cmd & mask) == rule)
- {
+ if ((cmd & mask) == rule) {
result = true;
break;
}
}
- }
- else
- {
+ } else {
/* no filter entry. if permission is true, all access will be granted, if not, all access will be denied */
result = apduRule;
}
@@ -83,23 +78,19 @@ namespace smartcard_service_api
void AccessRule::printAccessRules() const
{
- if (listFilters.size() > 0)
- {
+ if (listFilters.size() > 0) {
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().c_str(), item->second.toString().c_str());
+ for (item = listFilters.begin(); item != listFilters.end(); item++) {
+ _DBG(" +----- APDU: %s, Mask: %s", item->first.toString().c_str(), item->second.toString().c_str());
}
- }
- else
- {
- _DBG(" +---- APDU Access ALLOW : %s", apduRule ? "ALWAYS" : "NEVER");
+ } else {
+ _DBG(" +---- APDU Access ALLOW: %s", apduRule ? "ALWAYS": "NEVER");
}
- _DBG(" +---- NFC Access ALLOW : %s", nfcRule ? "ALWAYS" : "NEVER");
+ _DBG(" +---- NFC Access ALLOW: %s", nfcRule ? "ALWAYS": "NEVER");
}
bool AccessRule::isAuthorizedNFCAccess(void) const
@@ -174,20 +165,16 @@ namespace smartcard_service_api
{
_DBG(" +-- Access Condition");
- if (mapRules.size() > 0)
- {
+ if (mapRules.size() > 0) {
map<ByteArray, AccessRule>::const_iterator item;
- for (item = mapRules.begin(); item != mapRules.end(); 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().c_str());
+ _DBG(" +--- hash: %s", (temp == AccessControlList::ALL_DEVICE_APPS) ? "All device applications": temp.toString().c_str());
item->second.printAccessRules();
}
- }
- else
- {
+ } else {
_DBG(" +--- no rule found");
}
}
diff --git a/common/ByteArray.cpp b/common/ByteArray.cpp
index 95ac12b..e30941a 100644
--- a/common/ByteArray.cpp
+++ b/common/ByteArray.cpp
@@ -135,12 +135,9 @@ namespace smartcard_service_api
if (index >= length)
{
_ERR("buffer overflow, index [%d], length [%d]", index, length);
- if (length > 0)
- {
+ if (length > 0) {
return buffer[length - 1];
- }
- else
- {
+ } else {
return 0;
}
}
@@ -153,12 +150,9 @@ namespace smartcard_service_api
if (index >= length)
{
_ERR("buffer underflow, index [%d], length [%d]", index, length);
- if (length > 0)
- {
+ if (length > 0) {
return buffer[0];
- }
- else
- {
+ } else {
return 0;
}
}
@@ -283,17 +277,14 @@ namespace smartcard_service_api
return (memcmp(buffer, T.buffer, (length < T.length) ? length : T.length) > 0);
}
- uint8_t ByteArray::operator [](size_t index) const
+ uint8_t ByteArray::operator[](size_t index) const
{
if (index >= length)
{
_ERR("buffer overflow, index [%d], length [%d]", index, length);
- if (length > 0)
- {
+ if (length > 0) {
return buffer[length -1];
- }
- else
- {
+ } else {
return 0;
}
}
@@ -314,8 +305,7 @@ namespace smartcard_service_api
{
stringstream ss;
- if (length > 0)
- {
+ if (length > 0) {
char temp[20];
int count;
int i = 0;
@@ -342,9 +332,7 @@ namespace smartcard_service_api
}
ss << "}";
- }
- else
- {
+ } else {
ss << "buffer is empty";
}
@@ -358,16 +346,13 @@ namespace smartcard_service_api
if (filePath == NULL || buffer == NULL || length == 0)
return;
- if ((file = fopen(filePath, "w")) != NULL)
- {
+ if ((file = fopen(filePath, "w")) != NULL) {
fwrite(buffer, 1, length, file);
fflush(file);
fclose(file);
SECURE_LOGD("file has written, file [%s], length[%d]", filePath, length);
- }
- else
- {
+ } else {
_ERR("file open failed, [%d]", errno);
}
}
diff --git a/common/EFDIR.cpp b/common/EFDIR.cpp
index e6035e5..152aa06 100644
--- a/common/EFDIR.cpp
+++ b/common/EFDIR.cpp
@@ -84,12 +84,9 @@ namespace smartcard_service_api
}
tlv.returnToParentTLV();
- if (matched == true)
- {
+ if (matched == true) {
_DBG("Found!! : path %s", result.toString().c_str());
- }
- else
- {
+ } else {
result.clear();
}
}
diff --git a/common/FCI.cpp b/common/FCI.cpp
index 253f05e..643a6a9 100644
--- a/common/FCI.cpp
+++ b/common/FCI.cpp
@@ -83,8 +83,7 @@ namespace smartcard_service_api
/* parse... */
tlv.setTLVBuffer(fcpBuffer);
- if (tlv.decodeTLV())
- {
+ if (tlv.decodeTLV()) {
tlv.enterToValueTLV();
while (tlv.decodeTLV())
@@ -274,9 +273,7 @@ namespace smartcard_service_api
}
}
tlv.returnToParentTLV();
- }
- else
- {
+ } else {
_ERR("tlv.decodeTLV failed");
}
diff --git a/common/FileObject.cpp b/common/FileObject.cpp
index efbc110..ce1c1fc 100644
--- a/common/FileObject.cpp
+++ b/common/FileObject.cpp
@@ -55,13 +55,11 @@ namespace smartcard_service_api
{
bool result = false;
- if (response.size() >= 2)
- {
+ if (response.size() >= 2) {
ResponseHelper resp(response);
selectResponse = response;
- if (resp.getStatus() >= 0)
- {
+ if (resp.getStatus() >= 0) {
fcp.releaseFCP();
fcp.setFCP(resp.getDataField());
@@ -70,15 +68,11 @@ namespace smartcard_service_api
opened = true;
result = true;
- }
- else
- {
+ } else {
_ERR("status word [ %02X %02X ]",
resp.getSW1(), resp.getSW2());
}
- }
- else
- {
+ } else {
_ERR("invalid response");
}
@@ -100,16 +94,13 @@ namespace smartcard_service_api
close();
ret = channel->transmitSync(command, result);
- if (ret == 0)
- {
+ if (ret == 0) {
ResponseHelper resp(result);
ret = resp.getStatus();
setSelectResponse(result);
- }
- else
- {
+ } else {
_ERR("select apdu is failed, rv [%d], length [%d]",
ret, result.size());
@@ -138,16 +129,12 @@ namespace smartcard_service_api
ByteArray command;
/* make apdu command */
- if (fromCurrentDF == true)
- {
+ if (fromCurrentDF == true) {
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_PATH_FROM_CURRENT_DF, 0, path);
- }
- else
- {
+ } else {
ByteArray temp(path);
- if (path.size() > 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.assign(path.getBuffer(2), path.size() - 2);
}
@@ -206,24 +193,18 @@ namespace smartcard_service_api
apdu.getBuffer(command);
ret = channel->transmitSync(command, response);
- if (ret == 0 && response.size() >= 2)
- {
+ if (ret == 0 && response.size() >= 2) {
ResponseHelper resp(response);
ret = resp.getStatus();
- if (ret >= 0)
- {
+ if (ret >= 0) {
_DBG("response [%d] : %s", response.size(), response.toString().c_str());
result = Record(recordId, resp.getDataField());
- }
- else
- {
+ } else {
_ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
}
- }
- else
- {
+ } else {
_ERR("select apdu is failed, rv [%d], length [%d]", ret, response.size());
}
@@ -256,25 +237,19 @@ namespace smartcard_service_api
apdu.getBuffer(command);
ret = channel->transmitSync(command, response);
- if (ret == 0 && response.size() >= 2)
- {
+ if (ret == 0 && response.size() >= 2) {
ResponseHelper resp(response);
- if (resp.getStatus() >= 0)
- {
+ if (resp.getStatus() >= 0) {
_DBG("response [%d] : %s", response.size(), response.toString().c_str());
result = resp.getDataField();
ret = SUCCESS;
- }
- else
- {
+ } else {
_ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
}
- }
- else
- {
+ } else {
_ERR("select apdu is failed, rv [%d], length [%d]", ret, response.size());
}
@@ -308,23 +283,17 @@ namespace smartcard_service_api
apdu.getBuffer(command);
ret = channel->transmitSync(command, response);
- if (ret == 0 && response.size() >= 2)
- {
+ if (ret == 0 && response.size() >= 2) {
ResponseHelper resp(response);
- if (resp.getStatus() >= 0)
- {
+ if (resp.getStatus() >= 0) {
_DBG("response [%d] : %s", response.size(), response.toString().c_str());
ret = SUCCESS;
- }
- else
- {
+ } else {
_ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
}
- }
- else
- {
+ } else {
_ERR("select apdu is failed, rv [%d], length [%d]", ret, response.size());
}
diff --git a/common/GPARAACL.cpp b/common/GPARAACL.cpp
index 95a9f65..cf37f80 100644
--- a/common/GPARAACL.cpp
+++ b/common/GPARAACL.cpp
@@ -287,9 +287,7 @@ namespace smartcard_service_api
} else {
_ERR("getDataAll failed, [%x]", result);
}
- }
- else
- {
+ } else {
_INFO("access rules are not changed. skip update");
}
diff --git a/common/GPARFACL.cpp b/common/GPARFACL.cpp
index 84b3938..f4457f3 100644
--- a/common/GPARFACL.cpp
+++ b/common/GPARFACL.cpp
@@ -50,8 +50,7 @@ namespace smartcard_service_api
_BEGIN();
- if (channel == NULL)
- {
+ if (channel == NULL) {
return SCARD_ERROR_ILLEGAL_PARAM;
}
@@ -66,25 +65,19 @@ namespace smartcard_service_api
#endif
result = pkcs15.select();
- if (result >= SCARD_ERROR_OK)
- {
+ if (result >= SCARD_ERROR_OK) {
PKCS15ODF *odf;
result = SCARD_ERROR_OK;
- if ((odf = pkcs15.getODF()) != NULL)
- {
+ if ((odf = pkcs15.getODF()) != NULL) {
PKCS15DODF *dodf;
- if ((dodf = odf->getDODF()) != NULL)
- {
+ if ((dodf = odf->getDODF()) != NULL) {
result = loadAccessControl(channel, dodf);
- if (result == SCARD_ERROR_OK)
- {
+ if (result == SCARD_ERROR_OK) {
printAccessControlList();
- }
- else
- {
+ } else {
#if 1 /* FOR ORANGE */
_ERR("loadAccessControl failed, every request will be denied.");
#else
@@ -92,27 +85,21 @@ namespace smartcard_service_api
#endif
result = SCARD_ERROR_OK;
}
- }
- else
- {
+ } else {
#if 1 /* FOR ORANGE */
_ERR("dodf null, every request will be denied.");
#else
_INFO("dodf null, every request will be accepted.");
#endif
}
- }
- else
- {
+ } else {
#if 1 /* FOR ORANGE */
_ERR("odf null, every request will be denied.");
#else
_INFO("odf null, every request will be accepted.");
#endif
}
- }
- else
- {
+ } else {
#if 1 /* FOR ORANGE */
_ERR("failed to open PKCS#15, every request will be denied.");
#else
@@ -130,8 +117,7 @@ namespace smartcard_service_api
int result = -1;
ByteArray path;
- if ((result = dodf->searchOID(OID_GLOBALPLATFORM, path)) == 0)
- {
+ if ((result = dodf->searchOID(OID_GLOBALPLATFORM, path)) == 0) {
ByteArray data;
FileObject file(channel);
@@ -147,8 +133,7 @@ namespace smartcard_service_api
SimpleTLV tlv(data);
- if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : AccessControlMainFile */
- {
+ if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : AccessControlMainFile */ {
tlv.enterToValueTLV();
/* refresh Tag */
@@ -157,15 +142,13 @@ namespace smartcard_service_api
refreshTag = SimpleTLV::getOctetString(tlv);
_DBG("current refresh tag : %s", refreshTag.toString().c_str());
- if (this->refreshTag != refreshTag) /* need to update access control list */
- {
+ if (this->refreshTag != refreshTag) /* need to update access control list */ {
this->refreshTag = refreshTag;
releaseACL();
/* access control rule path */
- if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Path */
- {
+ if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Path */ {
/* TODO : parse path */
ByteArray path;
@@ -173,29 +156,20 @@ namespace smartcard_service_api
path = SimpleTLV::getOctetString(tlv.getValue());
_DBG("access control rule path : %s", path.toString().c_str());
- if (loadRules(channel, path) == 0)
- {
+ if (loadRules(channel, path) == 0) {
_DBG("loadRules success");
- }
- else
- {
+ } else {
_ERR("loadRules failed");
}
}
- }
- else
- {
+ } else {
_INFO("access rules are not changed. skip update");
}
tlv.returnToParentTLV();
- }
- else
- {
+ } else {
_ERR("tlv.decodeTLV failed");
}
- }
- else
- {
+ } else {
_ERR("OID not found");
}
@@ -214,14 +188,11 @@ namespace smartcard_service_api
SimpleTLV tlv(data);
- while (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Rule */
- {
+ while (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Rule */ {
tlv.enterToValueTLV();
- if (tlv.decodeTLV() == true)
- {
+ if (tlv.decodeTLV() == true) {
/* target */
- switch (tlv.getTag())
- {
+ switch (tlv.getTag()) {
case 0xA0 : /* CHOICE 0 : EXPLICIT AID */
/* OCTET STRING */
aid = SimpleTLV::getOctetString(tlv.getValue());
@@ -239,30 +210,22 @@ namespace smartcard_service_api
_DBG("aid : %s", aid.toString().c_str());
/* access condition path */
- if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Path */
- {
+ if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Path */ {
ByteArray path;
/* OCTET STRING */
path = SimpleTLV::getOctetString(tlv.getValue());
_DBG("path : %s", path.toString().c_str());
- if (loadAccessConditions(channel, aid, path) == 0)
- {
+ if (loadAccessConditions(channel, aid, path) == 0) {
_DBG("loadCertHashes success");
- }
- else
- {
+ } else {
_ERR("loadCertHashes failed");
}
- }
- else
- {
+ } else {
_ERR("decodeTLV failed");
}
- }
- else
- {
+ } else {
_ERR("decodeTLV failed");
}
tlv.returnToParentTLV();
@@ -280,40 +243,31 @@ namespace smartcard_service_api
return;
}
- if (tlv.decodeTLV() == true)
- {
- switch (tlv.getTag())
- {
+ if (tlv.decodeTLV() == true) {
+ switch (tlv.getTag()) {
case 0xA0 : /* CHOICE 0 : APDUPermission */
rule->setAPDUAccessRule(SimpleTLV::getBoolean(tlv.getValue()));
break;
case 0xA1 : /* CHOICE 1 : APDUFilters */
tlv.enterToValueTLV();
- while (tlv.decodeTLV() == true)
- {
- if (tlv.getTag() == 0x04) /* OCTET STRING */
- {
+ while (tlv.decodeTLV() == true) {
+ if (tlv.getTag() == 0x04) /* OCTET STRING */ {
ByteArray apdu, mask, value;
value = tlv.getValue();
_DBG("APDU rule : %s", value.toString().c_str());
- if (value.size() == 8) /* apdu 4 bytes + mask 4 bytes */
- {
+ if (value.size() == 8) /* apdu 4 bytes + mask 4 bytes */ {
apdu.assign(value.getBuffer(), 4);
mask.assign(value.getBuffer(4), 4);
rule->addAPDUAccessRule(apdu, mask);
- }
- else
- {
+ } else {
_ERR("Invalid APDU rule : %s", value.toString().c_str());
}
- }
- else
- {
+ } else {
_ERR("Unknown tag : 0x%02X", tlv.getTag());
}
}
@@ -339,21 +293,16 @@ namespace smartcard_service_api
static void loadAccessCondition(AccessCondition &condition, const ByteArray &data)
{
- if (data.size() > 0)
- {
+ if (data.size() > 0) {
SimpleTLV tlv(data);
ByteArray hash;
- while (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE */
- {
- if (tlv.size() > 0)
- {
+ while (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE */ {
+ if (tlv.size() > 0) {
/* access granted for specific applications */
tlv.enterToValueTLV();
- if (tlv.decodeTLV())
- {
- switch (tlv.getTag())
- {
+ if (tlv.decodeTLV()) {
+ switch (tlv.getTag()) {
case 0x04 : /* OCTET STRING : CertHash */
_DBG("aid : %s, hash : %s", condition.getAID().toString().c_str(), tlv.getValue().toString().c_str());
@@ -363,16 +312,14 @@ namespace smartcard_service_api
case 0xA0 : /* CHOICE 0 : AccessRules */
tlv.enterToValueTLV();
- if (tlv.decodeTLV())
- {
+ if (tlv.decodeTLV()) {
AccessRule *rule = condition.getAccessRule(hash);
if (rule == NULL) {
condition.addAccessRule(hash);
rule = condition.getAccessRule(hash);
}
- switch (tlv.getTag())
- {
+ switch (tlv.getTag()) {
case 0xA0 : /* CHOICE 0 : APDUAccessRule */
loadAPDUAccessRule(rule, tlv.getValue());
break;
@@ -385,9 +332,7 @@ namespace smartcard_service_api
_ERR("Unknown tag : 0x%02X", tlv.getTag());
break;
}
- }
- else
- {
+ } else {
_ERR("tlv.decodeTLV failed");
}
tlv.returnToParentTLV();
@@ -397,15 +342,11 @@ namespace smartcard_service_api
_ERR("Unknown tag : 0x%02X", tlv.getTag());
break;
}
- }
- else
- {
+ } else {
_ERR("tlv.decodeTLV failed");
}
tlv.returnToParentTLV();
- }
- else
- {
+ } else {
/* empty rule, it means allow for all application */
_INFO("access allowed for all applications, aid : %s", condition.getAID().toString().c_str());
@@ -413,9 +354,7 @@ namespace smartcard_service_api
break;
}
}
- }
- else
- {
+ } else {
/* empty file, it means deny for all application */
_INFO("access denied for all applications, aid : %s", condition.getAID().toString().c_str());
diff --git a/common/ISO7816BERTLV.cpp b/common/ISO7816BERTLV.cpp
index afe1933..7e7731f 100644
--- a/common/ISO7816BERTLV.cpp
+++ b/common/ISO7816BERTLV.cpp
@@ -98,8 +98,7 @@ namespace smartcard_service_api
offset++;
- if (count & 0x80)
- {
+ if (count & 0x80) {
uint8_t i;
count &= ~0x80;
@@ -108,8 +107,7 @@ namespace smartcard_service_api
if (count > 4)
return -1;
- for (i = 0; i < count; i++)
- {
+ for (i = 0; i < count; i++) {
/* if big endian */
currentL = (currentL << 8) | buffer[offset + i];
@@ -118,9 +116,7 @@ namespace smartcard_service_api
}
offset += i;
- }
- else
- {
+ } else {
currentL = count;
}
@@ -164,23 +160,17 @@ namespace smartcard_service_api
temp_tag[0] = (tagClass << 6) | (encoding << 5);
- if (tag < 0x1F)
- {
+ if (tag < 0x1F) {
temp_tag[0] |= tag;
temp_tag_len = 1;
- }
- else
- {
+ } else {
temp_tag[0] |= 0x1F;
- if (tag < 0x80)
- {
+ if (tag < 0x80) {
temp_tag[1] = tag;
temp_tag_len = 2;
- }
- else
- {
+ } else {
temp_tag[1] = (tag & 0x000000FF);
temp_tag[2] = (tag & 0x0000FF00);
@@ -191,14 +181,11 @@ namespace smartcard_service_api
total_len += temp_tag_len;
/* add length's length */
- if (buffer.size() < 128)
- {
+ if (buffer.size() < 128) {
temp_len[0] = buffer.size();
temp_len_len = 1;
- }
- else
- {
+ } else {
temp_len[0] = 0x80;
temp_len_len = 1;
diff --git a/common/OpensslHelper.cpp b/common/OpensslHelper.cpp
index 9712d60..6a032c6 100644
--- a/common/OpensslHelper.cpp
+++ b/common/OpensslHelper.cpp
@@ -80,23 +80,20 @@ namespace smartcard_service_api
unsigned int length = 0;
char *temp;
- if (buffer.getBuffer() == NULL || buffer.size() == 0)
- {
+ if (buffer.getBuffer() == NULL || buffer.size() == 0) {
return ret;
}
length = buffer.size();
temp = new char[length];
- if (temp != NULL)
- {
+ if (temp != NULL) {
BIO *b64, *bmem;
memset(temp, 0, length);
b64 = BIO_new(BIO_f_base64());
- if(b64 == NULL)
- {
+ if(b64 == NULL) {
delete []temp;
return false;
}
@@ -109,20 +106,15 @@ namespace smartcard_service_api
length = BIO_read(bmem, temp, length);
BIO_free_all(bmem);
- if(length > 0)
- {
+ if(length > 0) {
result.assign((unsigned char *)temp, length);
ret = true;
- }
- else
- {
+ } else {
ret = false;
}
delete []temp;
- }
- else
- {
+ } else {
_ERR("alloc failed");
}
@@ -143,36 +135,29 @@ namespace smartcard_service_api
const EVP_MD *md;
bool ret = false;
- if (algorithm == NULL || buffer.size() == 0)
- {
+ if (algorithm == NULL || buffer.size() == 0) {
return ret;
}
OpenSSL_add_all_digests();
- if ((md = EVP_get_digestbyname(algorithm)) != NULL)
- {
+ if ((md = EVP_get_digestbyname(algorithm)) != NULL) {
uint8_t temp[EVP_MAX_MD_SIZE] = { 0, };
EVP_MD_CTX mdCtx;
unsigned int resultLen = 0;
- if (EVP_DigestInit(&mdCtx, md) > 0)
- {
- if (EVP_DigestUpdate(&mdCtx, buffer.getBuffer(), buffer.size()) == 0)
- {
+ if (EVP_DigestInit(&mdCtx, md) > 0) {
+ if (EVP_DigestUpdate(&mdCtx, buffer.getBuffer(), buffer.size()) == 0) {
_ERR("EVP_DigestUpdate failed");
}
if (EVP_DigestFinal(&mdCtx, temp, &resultLen) > 0 &&
- resultLen > 0)
- {
+ resultLen > 0) {
result.assign(temp, resultLen);
ret = true;
}
}
- }
- else
- {
+ } else {
_ERR("EVP_get_digestbyname(\"%s\") returns NULL", algorithm);
}
diff --git a/common/PKCS15.cpp b/common/PKCS15.cpp
index 613e58a..849d142 100644
--- a/common/PKCS15.cpp
+++ b/common/PKCS15.cpp
@@ -54,26 +54,18 @@ namespace smartcard_service_api
int ret;
ret = PKCS15Object::select(PKCS15_AID);
- if (ret >= SCARD_ERROR_OK)
- {
+ if (ret >= SCARD_ERROR_OK) {
_DBG("response : %s", selectResponse.toString().c_str());
- }
- else if (ret == ResponseHelper::ERROR_FILE_NOT_FOUND)
- {
+ } else if (ret == ResponseHelper::ERROR_FILE_NOT_FOUND) {
_ERR("PKCS15 AID not found, search in EF DIR");
ret = selectFromEFDIR();
- if (ret >= SCARD_ERROR_OK)
- {
+ if (ret >= SCARD_ERROR_OK) {
_DBG("response : %s", selectResponse.toString().c_str());
- }
- else
- {
+ } else {
_ERR("PKCS15 select failed, [%d]", ret);
}
- }
- else
- {
+ } else {
_ERR("PKCS15 select failed, [%d]", ret);
}
@@ -87,25 +79,18 @@ namespace smartcard_service_api
EFDIR dir(channel);
ret = dir.select();
- if (ret >= SCARD_ERROR_OK)
- {
+ if (ret >= SCARD_ERROR_OK) {
path = dir.getPathByAID(PKCS15_AID);
- if (path.size() > 0)
- {
+ if (path.size() > 0) {
ret = PKCS15Object::select(path, false);
- if (ret < SCARD_ERROR_OK)
- {
+ if (ret < SCARD_ERROR_OK) {
_ERR("PKCS15 select failed, [%d]", ret);
}
- }
- else
- {
+ } else {
_ERR("PKCS15 path is not found");
ret = SCARD_ERROR_NOT_SUPPORTED;
}
- }
- else
- {
+ } else {
_ERR("select EFDIR failed, [%x]", -ret);
}
diff --git a/common/PKCS15CDF.cpp b/common/PKCS15CDF.cpp
index 7664d0d..9b02d7b 100644
--- a/common/PKCS15CDF.cpp
+++ b/common/PKCS15CDF.cpp
@@ -31,26 +31,20 @@ namespace smartcard_service_api
{
int ret = 0;
- if ((ret = select(fid)) >= SCARD_ERROR_OK)
- {
+ if ((ret = select(fid)) >= SCARD_ERROR_OK) {
ByteArray cdfData, extra;
_DBG("response : %s", selectResponse.toString().c_str());
ret = readBinaryAll(0, cdfData);
- if (ret == SCARD_ERROR_OK)
- {
+ if (ret == SCARD_ERROR_OK) {
_DBG("cdfData : %s", cdfData.toString().c_str());
parseData(cdfData);
- }
- else
- {
+ } else {
_ERR("readBinary failed, [%d]", ret);
}
- }
- else
- {
+ } else {
_ERR("select failed, [%d]", ret);
}
}
@@ -60,26 +54,20 @@ namespace smartcard_service_api
{
int ret = 0;
- if ((ret = select(path)) >= SCARD_ERROR_OK)
- {
+ if ((ret = select(path)) >= SCARD_ERROR_OK) {
ByteArray cdfData, extra;
_DBG("response : %s", selectResponse.toString().c_str());
ret = readBinaryAll(0, cdfData);
- if (ret == SCARD_ERROR_OK)
- {
+ if (ret == SCARD_ERROR_OK) {
_DBG("cdfData : %s", cdfData.toString().c_str());
parseData(cdfData);
- }
- else
- {
+ } else {
_ERR("readBinary failed, [%d]", ret);
}
- }
- else
- {
+ } else {
_ERR("select failed, [%d]", ret);
}
}
@@ -238,7 +226,6 @@ namespace smartcard_service_api
} else {
_ERR("select failed, [%x]", result);
}
-
}
tlv.returnToParentTLV();
}
diff --git a/common/PKCS15DODF.cpp b/common/PKCS15DODF.cpp
index ea1cde6..0ec55c0 100644
--- a/common/PKCS15DODF.cpp
+++ b/common/PKCS15DODF.cpp
@@ -30,25 +30,19 @@ namespace smartcard_service_api
{
int ret = 0;
- if ((ret = select(fid)) >= SCARD_ERROR_OK)
- {
+ if ((ret = select(fid)) >= SCARD_ERROR_OK) {
ByteArray dodfData, extra;
_DBG("response : %s", selectResponse.toString().c_str());
- if ((ret = readBinaryAll(0, dodfData)) == 0)
- {
+ if ((ret = readBinaryAll(0, dodfData)) == 0) {
_DBG("dodfData : %s", dodfData.toString().c_str());
parseData(dodfData);
- }
- else
- {
+ } else {
_ERR("readBinary failed, [%d]", ret);
}
- }
- else
- {
+ } else {
_ERR("select failed, [%d]", ret);
}
}
@@ -58,25 +52,19 @@ namespace smartcard_service_api
{
int ret = 0;
- if ((ret = select(path)) >= SCARD_ERROR_OK)
- {
+ if ((ret = select(path)) >= SCARD_ERROR_OK) {
ByteArray dodfData, extra;
_DBG("response : %s", selectResponse.toString().c_str());
- if ((ret = readBinaryAll(0, dodfData)) == 0)
- {
+ if ((ret = readBinaryAll(0, dodfData)) == 0) {
_DBG("dodfData : %s", dodfData.toString().c_str());
parseData(dodfData);
- }
- else
- {
+ } else {
_ERR("readBinary failed, [%d]", ret);
}
- }
- else
- {
+ } else {
_ERR("select failed, [%d]", ret);
}
}
@@ -90,10 +78,8 @@ namespace smartcard_service_api
bool result = false;
SimpleTLV tlv(data);
- while (tlv.decodeTLV())
- {
- switch (tlv.getTag())
- {
+ while (tlv.decodeTLV()) {
+ switch (tlv.getTag()) {
case (unsigned int)0xA1 : /* CHOICE 1 : OidDO */
{
PKCS15OID oid(tlv.getValue());
@@ -121,8 +107,7 @@ namespace smartcard_service_api
map<ByteArray, PKCS15OID>::const_iterator item;
item = mapOID.find(oid);
- if (item != mapOID.end())
- {
+ if (item != mapOID.end()) {
data = item->second.getPath();
result = 0;
}
diff --git a/common/PKCS15ODF.cpp b/common/PKCS15ODF.cpp
index 53ff3d7..a16b695 100644
--- a/common/PKCS15ODF.cpp
+++ b/common/PKCS15ODF.cpp
@@ -36,25 +36,19 @@ namespace smartcard_service_api
{
int ret = 0;
- if ((ret = select(ODF_FID)) >= SCARD_ERROR_OK)
- {
+ if ((ret = select(ODF_FID)) >= SCARD_ERROR_OK) {
ByteArray odfData, extra;
_DBG("response : %s", selectResponse.toString().c_str());
- if ((ret = readBinaryAll(0, odfData)) == 0)
- {
+ if ((ret = readBinaryAll(0, odfData)) == 0) {
_DBG("odfData : %s", odfData.toString().c_str());
parseData(odfData);
- }
- else
- {
+ } else {
_ERR("readBinary failed, [%d]", ret);
}
- }
- else
- {
+ } else {
_ERR("select failed, [%d]", ret);
}
}
@@ -65,14 +59,11 @@ namespace smartcard_service_api
int ret = 0;
ByteArray odfData;
- if ((ret = readBinaryAll(0, odfData)) == 0)
- {
+ if ((ret = readBinaryAll(0, odfData)) == 0) {
_DBG("odfData : %s", odfData.toString().c_str());
parseData(odfData);
- }
- else
- {
+ } else {
_ERR("readBinary failed, [%d]", ret);
}
}
@@ -130,7 +121,6 @@ namespace smartcard_service_api
tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
break;
}
-
}
_INFO("dataList.size() = %d", dataList.size());
@@ -142,27 +132,22 @@ namespace smartcard_service_api
{
map<unsigned int, ByteArray>::iterator item;
- if (dodf == NULL)
- {
+ if (dodf == NULL) {
item = dataList.find(TAG_DODF);
- if (item != dataList.end())
- {
+ if (item != dataList.end()) {
NumberStream num(item->second);
unsigned int fid = num.getLittleEndianNumber();
_DBG("dodf fid [%X]", fid);
dodf = new PKCS15DODF(fid, channel);
- if (dodf != NULL && dodf->isClosed() == true)
- {
+ if (dodf != NULL && dodf->isClosed() == true) {
_ERR("failed to open DODF");
delete dodf;
dodf = NULL;
}
- }
- else
- {
+ } else {
_ERR("[%02X] is not found. total [%d]", TAG_DODF, dataList.size());
}
}
@@ -176,27 +161,22 @@ namespace smartcard_service_api
{
map<unsigned int, ByteArray>::iterator item;
- if (cdf == NULL)
- {
+ if (cdf == NULL) {
item = dataList.find(TAG_CDF);
- if (item != dataList.end())
- {
+ if (item != dataList.end()) {
NumberStream num(item->second);
unsigned int fid = num.getLittleEndianNumber();
_DBG("cdf fid [%X]", fid);
cdf = new PKCS15CDF(fid, channel);
- if (cdf != NULL && cdf->isClosed() == true)
- {
+ if (cdf != NULL && cdf->isClosed() == true) {
_ERR("failed to open CDF");
delete cdf;
cdf = NULL;
}
- }
- else
- {
+ } else {
_ERR("[%02X] is not found. total [%d]", TAG_CDF, dataList.size());
}
}
diff --git a/common/PKCS15OID.cpp b/common/PKCS15OID.cpp
index 2c46c24..57db41e 100644
--- a/common/PKCS15OID.cpp
+++ b/common/PKCS15OID.cpp
@@ -47,19 +47,15 @@ namespace smartcard_service_api
switch (tlv.getTag())
{
case PKCS15::TAG_SEQUENCE :
- if (tlv.size() > 0)
- {
+ if (tlv.size() > 0) {
/* common object attribute */
tlv.enterToValueTLV();
- if (tlv.decodeTLV() == true && tlv.getTag() == 0x0C) /* ?? */
- {
+ if (tlv.decodeTLV() == true && tlv.getTag() == 0x0C) /* ?? */ {
name = tlv.getValue();
SECURE_LOGD("name : %s", name.toString().c_str());
}
tlv.returnToParentTLV();
- }
- else
- {
+ } else {
/* common object attribute */
/* if you want to use this value, add member variable and parse here */
// _ERR("common object attribute is empty");
@@ -74,40 +70,31 @@ namespace smartcard_service_api
tlv.enterToValueTLV();
/* attribute */
- if (tlv.decodeTLV() == true && tlv.getTag() == PKCS15::TAG_SEQUENCE)
- {
+ if (tlv.decodeTLV() == true && tlv.getTag() == PKCS15::TAG_SEQUENCE) {
tlv.enterToValueTLV();
/* oid */
- if (tlv.decodeTLV() == true && tlv.getTag() == (unsigned int)0x06) /* ?? */
- {
+ if (tlv.decodeTLV() == true && tlv.getTag() == (unsigned int)0x06) /* ?? */ {
oid = tlv.getValue();
_DBG("oid : %s", oid.toString().c_str());
- }
- else
- {
+ } else {
_ERR("oid is empty");
}
/* path */
- if (tlv.decodeTLV() == true && tlv.getTag() == PKCS15::TAG_SEQUENCE)
- {
+ if (tlv.decodeTLV() == true && tlv.getTag() == PKCS15::TAG_SEQUENCE) {
path = SimpleTLV::getOctetString(tlv.getValue());
_DBG("path : %s", path.toString().c_str());
result = true;
- }
- else
- {
+ } else {
_ERR("sequence is empty");
}
tlv.returnToParentTLV();
- }
- else
- {
+ } else {
_ERR("common dataobject attribute is empty");
}
tlv.returnToParentTLV();
diff --git a/common/PKCS15Object.cpp b/common/PKCS15Object.cpp
index 6c4c790..283d958 100644
--- a/common/PKCS15Object.cpp
+++ b/common/PKCS15Object.cpp
@@ -48,22 +48,16 @@ namespace smartcard_service_api
ByteArray result;
SimpleTLV tlv(data);
- if (tlv.decodeTLV() && tlv.getTag() == TAG_SEQUENCE)
- {
+ if (tlv.decodeTLV() && tlv.getTag() == TAG_SEQUENCE) {
tlv.enterToValueTLV();
- if (tlv.decodeTLV() && tlv.getTag() == TAG_OCTET_STREAM)
- {
+ if (tlv.decodeTLV() && tlv.getTag() == TAG_OCTET_STREAM) {
result = tlv.getValue();
- }
- else
- {
+ } else {
_ERR("TAG_OCTET_STREAM not found");
}
tlv.returnToParentTLV();
- }
- else
- {
+ } else {
_ERR("TAG_SEQUENCE not found");
}
diff --git a/common/SignatureHelper.cpp b/common/SignatureHelper.cpp
index 62bdc1e..e3d44ba 100644
--- a/common/SignatureHelper.cpp
+++ b/common/SignatureHelper.cpp
@@ -77,29 +77,22 @@ namespace smartcard_service_api
{
const char *value = NULL;
- if ((ret = pkgmgrinfo_pkginfo_get_cert_value(handle, (pkgmgrinfo_cert_type)type, &value)) == 0)
- {
- if (value != NULL && strlen(value) > 0)
- {
+ if ((ret = pkgmgrinfo_pkginfo_get_cert_value(handle, (pkgmgrinfo_cert_type)type, &value)) == 0) {
+ if (value != NULL && strlen(value) > 0) {
OpensslHelper::decodeBase64String(value, result, false);
- if (result.size() > 0)
- {
+ if (result.size() > 0) {
_DBG("type [%d] hash [%d] : %s", type, result.size(), result.toString().c_str());
break;
}
}
}
}
- }
- else
- {
+ } else {
_ERR("pkgmgr_pkginfo_load_certinfo failed [%d]", ret);
}
pkgmgrinfo_pkginfo_destroy_certinfo(handle);
- }
- else
- {
+ } else {
_ERR("pkgmgr_pkginfo_create_certinfo failed [%d]", ret);
}
@@ -112,12 +105,9 @@ namespace smartcard_service_api
int error = 0;
char pkgName[256] = { 0, };
- if ((error = aul_app_get_pkgname_bypid(pid, pkgName, sizeof(pkgName))) == 0)
- {
+ if ((error = aul_app_get_pkgname_bypid(pid, pkgName, sizeof(pkgName))) == 0) {
result = getCertificationHash(pkgName);
- }
- else
- {
+ } else {
_ERR("aul_app_get_pkgname_bypid failed [%d]", error);
}
@@ -130,12 +120,9 @@ namespace smartcard_service_api
int error = 0;
char pkgName[256] = { 0, };
- if ((error = aul_app_get_pkgname_bypid(pid, pkgName, sizeof(pkgName))) == 0)
- {
+ if ((error = aul_app_get_pkgname_bypid(pid, pkgName, sizeof(pkgName))) == 0) {
result = getCertificationHashes(pkgName, certHashes);
- }
- else
- {
+ } else {
_ERR("aul_app_get_pkgname_bypid failed [%d]", error);
}
@@ -150,14 +137,12 @@ namespace smartcard_service_api
pkgmgrinfo_appinfo_h handle_appinfo;
char *pkgid = NULL;
- if (pkgmgrinfo_appinfo_get_appinfo(packageName, &handle_appinfo) != PMINFO_R_OK)
- {
+ if (pkgmgrinfo_appinfo_get_appinfo(packageName, &handle_appinfo) != PMINFO_R_OK) {
_ERR("pkgmgrinfo_appinfo_get_appinfo fail");
return result;
}
- if (pkgmgrinfo_appinfo_get_pkgid(handle_appinfo, &pkgid) != PMINFO_R_OK)
- {
+ if (pkgmgrinfo_appinfo_get_pkgid(handle_appinfo, &pkgid) != PMINFO_R_OK) {
pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo);
_ERR("pkgmgrinfo_appinfo_get_pkgid fail");
return result;
@@ -165,28 +150,21 @@ namespace smartcard_service_api
SECURE_LOGD("package name : %s, package id : %s", packageName, pkgid);
- if ((ret = pkgmgrinfo_pkginfo_create_certinfo(&handle)) == 0)
- {
- if (0)
- {
+ if ((ret = pkgmgrinfo_pkginfo_create_certinfo(&handle)) == 0) {
+ if (0) {
int type;
- for (type = (int)PMINFO_AUTHOR_ROOT_CERT; type <= (int)PMINFO_DISTRIBUTOR2_SIGNER_CERT; type++)
- {
+ for (type = (int)PMINFO_AUTHOR_ROOT_CERT; type <= (int)PMINFO_DISTRIBUTOR2_SIGNER_CERT; type++) {
const char *value = NULL;
- if ((ret = pkgmgrinfo_pkginfo_get_cert_value(handle, (pkgmgrinfo_cert_type)type, &value)) == 0)
- {
- if (value != NULL && strlen(value) > 0)
- {
+ if ((ret = pkgmgrinfo_pkginfo_get_cert_value(handle, (pkgmgrinfo_cert_type)type, &value)) == 0) {
+ if (value != NULL && strlen(value) > 0) {
ByteArray decodeValue, hash;
OpensslHelper::decodeBase64String(value, decodeValue, false);
- if (decodeValue.size() > 0)
- {
+ if (decodeValue.size() > 0) {
OpensslHelper::digestBuffer("sha1", decodeValue.getBuffer(), decodeValue.size(), hash);
- if(hash.size() > 0)
- {
+ if(hash.size() > 0) {
_DBG("type [%d] hash [%d] : %s", type, hash.size(), hash.toString().c_str());
certHashes.push_back(hash);
}
@@ -196,18 +174,14 @@ namespace smartcard_service_api
}
result = true;
- }
- else
- {
+ } else {
_ERR("pkgmgr_pkginfo_load_certinfo failed [%d]", ret);
}
pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo);
pkgmgrinfo_pkginfo_destroy_certinfo(handle);
- }
- else
- {
+ } else {
_ERR("pkgmgr_pkginfo_create_certinfo failed [%d]", ret);
}
@@ -235,15 +209,13 @@ certiHash *__signature_helper_vector_to_linked_list(vector<ByteArray> &certHashe
tmp->length = (*item).size();
- if ((tmp->value = (uint8_t *)calloc(tmp->length, sizeof(uint8_t))) == NULL)
- {
+ if ((tmp->value = (uint8_t *)calloc(tmp->length, sizeof(uint8_t))) == NULL) {
free(tmp);
goto ERROR;
}
buffer = (*item).getBuffer();
- if(buffer == NULL)
- {
+ if(buffer == NULL) {
free(tmp->value);
free(tmp);
continue;
@@ -252,12 +224,9 @@ certiHash *__signature_helper_vector_to_linked_list(vector<ByteArray> &certHashe
memcpy(tmp->value, buffer, tmp->length);
tmp->next = NULL;
- if (head == NULL)
- {
+ if (head == NULL) {
head = tail = tmp;
- }
- else
- {
+ } else {
tail->next = tmp;
tail = tmp;
}
diff --git a/common/SimpleTLV.cpp b/common/SimpleTLV.cpp
index e9500b9..6980062 100644
--- a/common/SimpleTLV.cpp
+++ b/common/SimpleTLV.cpp
@@ -69,14 +69,11 @@ namespace smartcard_service_api
{
int count = 0;
- if (buffer[0] == 0xFF)
- {
+ if (buffer[0] == 0xFF) {
/* 3 bytes length */
currentL = (buffer[1] << 8) | buffer[2];
count = 3;
- }
- else
- {
+ } else {
/* 1 byte length */
currentL = buffer[0];
count = 1;
@@ -107,17 +104,12 @@ namespace smartcard_service_api
total_len += 1;
/* add length's length */
- if (buffer.size() < 255)
- {
+ if (buffer.size() < 255) {
total_len += 1;
- }
- else if (buffer.size() < 65536)
- {
+ } else if (buffer.size() < 65536) {
total_len += 3;
isLongBuffer = true;
- }
- else
- {
+ } else {
return result;
}
@@ -126,8 +118,7 @@ namespace smartcard_service_api
/* alloc new buffer */
temp_buffer = new unsigned char[total_len];
- if (temp_buffer == NULL)
- {
+ if (temp_buffer == NULL) {
return result;
}
memset(temp_buffer, 0, total_len);
@@ -136,14 +127,11 @@ namespace smartcard_service_api
temp_buffer[current++] = (unsigned char)tag;
/* fill length */
- if (isLongBuffer == true)
- {
+ if (isLongBuffer == true) {
temp_buffer[current++] = (unsigned char)(0xFF);
temp_buffer[current++] = (unsigned char)(buffer.size() >> 8);
temp_buffer[current++] = (unsigned char)(buffer.size());
- }
- else
- {
+ } else {
temp_buffer[current++] = (unsigned char)(buffer.size());
}
@@ -186,12 +174,9 @@ namespace smartcard_service_api
{
ByteArray result;
- if (tlv.decodeTLV() == true && tlv.getTag() == 0x04) /* OCTET STRING */
- {
+ if (tlv.decodeTLV() == true && tlv.getTag() == 0x04) /* OCTET STRING */ {
result = tlv.getValue();
- }
- else
- {
+ } else {
_ERR("getOctetString failed (0x%02X)", tlv.getTag());
}
@@ -209,15 +194,12 @@ namespace smartcard_service_api
{
bool result = false;
- if (tlv.decodeTLV() == true && tlv.getTag() == 0x80) /* BOOLEAN */
- {
+ if (tlv.decodeTLV() == true && tlv.getTag() == 0x80) /* BOOLEAN */ {
if (tlv.getValue().at(0) == 0)
result = false;
else
result = true;
- }
- else
- {
+ } else {
_ERR("getBoolean failed (0x%02X)", tlv.getTag());
}
@@ -235,11 +217,8 @@ namespace smartcard_service_api
{
int result = 0;
- if (tlv.decodeTLV() == true && tlv.getTag() == 0x80) /* TODO : INTEGER */
- {
- }
- else
- {
+ if (tlv.decodeTLV() == true && tlv.getTag() == 0x80) /* TODO : INTEGER */ {
+ } else {
_ERR("getInteger failed (0x%02X)", tlv.getTag());
}
diff --git a/common/Synchronous.cpp b/common/Synchronous.cpp
index 03ff05c..79c8bfe 100644
--- a/common/Synchronous.cpp
+++ b/common/Synchronous.cpp
@@ -47,16 +47,13 @@ namespace smartcard_service_api
struct timespec ts;
int result;
- if (second > 0)
- {
+ if (second > 0) {
gettimeofday(&now, NULL);
ts.tv_sec = now.tv_sec + second;
ts.tv_nsec = now.tv_usec * 1000;
result = pthread_cond_timedwait(&syncCondition, &syncMutex, &ts);
- }
- else
- {
+ } else {
result = pthread_cond_wait(&syncCondition, &syncMutex);
}
diff --git a/common/TLVHelper.cpp b/common/TLVHelper.cpp
index 85406dd..048d549 100644
--- a/common/TLVHelper.cpp
+++ b/common/TLVHelper.cpp
@@ -160,12 +160,9 @@ namespace smartcard_service_api
{
bool result = true;
- if (currentTLV->getParentTLV() != NULL)
- {
+ if (currentTLV->getParentTLV() != NULL) {
currentTLV = currentTLV->getParentTLV();
- }
- else
- {
+ } else {
/* top tlv */
}
diff --git a/common/include/ByteArray.h b/common/include/ByteArray.h
index 84a8c8f..986fc60 100644
--- a/common/include/ByteArray.h
+++ b/common/include/ByteArray.h
@@ -79,7 +79,7 @@ namespace smartcard_service_api
bool operator !=(const ByteArray &T) const;
bool operator <(const ByteArray &T) const;
bool operator >(const ByteArray &T) const;
- uint8_t operator [](size_t index) const;
+ uint8_t operator[](size_t index) const;
inline bool isEmpty() const { return (buffer == (void *)0 || length == 0); }
const string toString(bool entire) const;
diff --git a/packaging/smartcard-service.spec b/packaging/smartcard-service.spec
index 4ff1378..d431a90 100755
--- a/packaging/smartcard-service.spec
+++ b/packaging/smartcard-service.spec
@@ -8,7 +8,7 @@
################################################################################
Name: smartcard-service
Summary: Smartcard Service FW
-Version: 0.1.53
+Version: 0.1.54
Release: 0
Group: Network & Connectivity
Requires: %{name}-common = %{version}-%{release}
diff --git a/server/ClientInstance.cpp b/server/ClientInstance.cpp
index 4e60be7..8f91315 100644
--- a/server/ClientInstance.cpp
+++ b/server/ClientInstance.cpp
@@ -32,12 +32,9 @@ namespace smartcard_service_api
ServiceInstance *result = NULL;
result = new ServiceInstance(this);
- if (result != NULL)
- {
+ if (result != NULL) {
mapServices.insert(make_pair(result->getHandle(), result));
- }
- else
- {
+ } else {
_ERR("alloc failed");
}
diff --git a/server/ServerChannel.cpp b/server/ServerChannel.cpp
index 07842de..295adac 100644
--- a/server/ServerChannel.cpp
+++ b/server/ServerChannel.cpp
@@ -48,8 +48,7 @@ namespace smartcard_service_api
APDUHelper apdu;
int rv;
- if (isClosed() == false && isBasicChannel() == false)
- {
+ if (isClosed() == false && isBasicChannel() == false) {
/* close channel */
command = apdu.generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
@@ -57,21 +56,15 @@ namespace smartcard_service_api
rv = terminal->transmitSync(command, result);
- if (rv == 0 && result.size() >= 2)
- {
+ if (rv == 0 && result.size() >= 2) {
ResponseHelper resp(result);
- if (resp.getStatus() >= 0)
- {
+ if (resp.getStatus() >= 0) {
_DBG("close success");
- }
- else
- {
+ } else {
_ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
}
- }
- else
- {
+ } else {
_ERR("select apdu is failed, rv [%d], length [%d]", rv, result.size());
}
diff --git a/server/ServerGDBus.cpp b/server/ServerGDBus.cpp
index 8a10dd4..f40ac58 100755
--- a/server/ServerGDBus.cpp
+++ b/server/ServerGDBus.cpp
@@ -449,7 +449,6 @@ namespace smartcard_service_api
/* create service */
service = resource.createService(name);
if (service != NULL) {
-
handle = service->getHandle();
resource.getReaders(list);
@@ -1057,8 +1056,7 @@ namespace smartcard_service_api
resp = temp->getSelectResponse();
channelNum = temp->getChannelNumber();
result = SCARD_ERROR_OK;
- }
- else{
+ } else {
_ERR("getChannel is failed");
result = SCARD_ERROR_UNAVAILABLE;
}
diff --git a/server/ServerResource.cpp b/server/ServerResource.cpp
index d33d4c5..5e9f68b 100644
--- a/server/ServerResource.cpp
+++ b/server/ServerResource.cpp
@@ -61,7 +61,6 @@ namespace smartcard_service_api
}
result = setHandles.insert(newHandle);
-
}
while (!result.second);
}
@@ -104,21 +103,15 @@ namespace smartcard_service_api
{
bool result = false;
- if (getClient(name) == NULL)
- {
+ if (getClient(name) == NULL) {
ClientInstance *instance = new ClientInstance(name, pid);
- if (instance != NULL)
- {
+ if (instance != NULL) {
mapClients.insert(make_pair(name, instance));
result = true;
- }
- else
- {
+ } else {
_ERR("alloc failed");
}
- }
- else
- {
+ } else {
_ERR("client already exist, name [%s]", name);
}
@@ -142,13 +135,10 @@ namespace smartcard_service_api
{
map<string, ClientInstance *>::iterator item;
- if ((item = mapClients.find(name)) != mapClients.end())
- {
+ if ((item = mapClients.find(name)) != mapClients.end()) {
delete item->second;
mapClients.erase(item);
- }
- else
- {
+ } else {
_DBG("client removed already, name [%s]", name);
}
}
@@ -175,15 +165,11 @@ namespace smartcard_service_api
ServiceInstance *result = NULL;
ClientInstance *instance = NULL;
- if ((instance = getClient(name)) != NULL)
- {
- if ((result = instance->createService()) == NULL)
- {
+ if ((instance = getClient(name)) != NULL) {
+ if ((result = instance->createService()) == NULL) {
_ERR("ClientInstance::createService failed [%d]", name);
}
- }
- else
- {
+ } else {
_ERR("client doesn't exist, name [%s]", name);
}
@@ -195,12 +181,9 @@ namespace smartcard_service_api
ServiceInstance *result = NULL;
ClientInstance *instance = NULL;
- if ((instance = getClient(name)) != NULL)
- {
+ if ((instance = getClient(name)) != NULL) {
result = instance->getService(handle);
- }
- else
- {
+ } else {
_ERR("client doesn't exist, name [%s]", name);
}
@@ -211,17 +194,13 @@ namespace smartcard_service_api
{
ClientInstance *instance = NULL;
- if ((instance = getClient(name)) != NULL)
- {
+ if ((instance = getClient(name)) != NULL) {
instance->removeService(handle);
if (instance->getServiceCounts() == 0) {
-
/* remove client instance */
removeClient(name);
}
- }
- else
- {
+ } else {
_ERR("client doesn't exist, name [%s]", name);
}
}
@@ -230,15 +209,12 @@ namespace smartcard_service_api
{
ClientInstance *instance = NULL;
- if ((instance = getClient(name)) != NULL)
- {
+ if ((instance = getClient(name)) != NULL) {
instance->removeServices();
/* remove client instance */
removeClient(name);
- }
- else
- {
+ } else {
_ERR("client doesn't exist, name [%s]", name);
}
}
@@ -249,15 +225,11 @@ namespace smartcard_service_api
Terminal *temp = NULL;
ServiceInstance *instance = NULL;
- if ((instance = getService(name, handle)) != NULL)
- {
- if ((temp = getTerminalByReaderID(readerID)) != NULL)
- {
+ if ((instance = getService(name, handle)) != NULL) {
+ if ((temp = getTerminalByReaderID(readerID)) != NULL) {
result = instance->openSession(temp, certHashes, caller);
}
- }
- else
- {
+ } else {
_ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
}
@@ -269,12 +241,9 @@ namespace smartcard_service_api
ServerSession *result = NULL;
ServiceInstance *instance = NULL;
- if ((instance = getService(name, handle)) != NULL)
- {
+ if ((instance = getService(name, handle)) != NULL) {
result = instance->getSession(sessionID);
- }
- else
- {
+ } else {
_ERR("Session doesn't exist : name [%s], handle [%d], handle [%d]", name, handle, sessionID);
}
@@ -300,12 +269,9 @@ namespace smartcard_service_api
unsigned int result = -1;
ServiceInstance *instance = NULL;
- if ((instance = getService(name, handle)) != NULL)
- {
+ if ((instance = getService(name, handle)) != NULL) {
result = instance->getChannelCountBySession(sessionID);
- }
- else
- {
+ } else {
_ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
}
@@ -316,12 +282,9 @@ namespace smartcard_service_api
{
ServiceInstance *instance = NULL;
- if ((instance = getService(name, handle)) != NULL)
- {
+ if ((instance = getService(name, handle)) != NULL) {
instance->closeSession(sessionID);
- }
- else
- {
+ } else {
_ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
}
}
@@ -332,21 +295,17 @@ namespace smartcard_service_api
unsigned int result = -1;
ServiceInstance *service = NULL;
- if ((service = getService(name, handle)) != NULL)
- {
- if (service->isVaildSessionHandle(sessionID) == true)
- {
+ if ((service = getService(name, handle)) != NULL) {
+ if (service->isVaildSessionHandle(sessionID) == true) {
ServerSession *session = NULL;
Terminal *terminal = NULL;
terminal = service->getTerminal(sessionID);
session = service->getSession(sessionID);
- if (terminal != NULL && session != NULL)
- {
+ if (terminal != NULL && session != NULL) {
if (terminal->open() == true) {
result = _createChannel(terminal, service, channelType, sessionID, aid);
- if (result == IntegerHandle::INVALID_HANDLE)
- {
+ if (result == IntegerHandle::INVALID_HANDLE) {
_ERR("create channel failed [%d]", sessionID);
terminal->close();
@@ -355,21 +314,15 @@ namespace smartcard_service_api
_ERR("terminal open failed");
throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
}
- }
- else
- {
+ } else {
_ERR("session is invalid [%d]", sessionID);
throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
}
- }
- else
- {
+ } else {
_ERR("session is invalid [%d]", sessionID);
throw ExceptionBase(SCARD_ERROR_ILLEGAL_STATE);
}
- }
- else
- {
+ } else {
_ERR("getService is failed, name [%s], handle [%d]", name, handle);
throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
}
@@ -382,12 +335,9 @@ namespace smartcard_service_api
Channel *result = NULL;
ServiceInstance *instance = NULL;
- if ((instance = getService(name, handle)) != NULL)
- {
+ if ((instance = getService(name, handle)) != NULL) {
result = instance->getChannel(channelID);
- }
- else
- {
+ } else {
_ERR("Channel doesn't exist : name [%s], handle [%d], handle [%d]", name, handle, channelID);
}
@@ -398,8 +348,7 @@ namespace smartcard_service_api
{
ServiceInstance *instance = NULL;
- if ((instance = getService(name, handle)) != NULL)
- {
+ if ((instance = getService(name, handle)) != NULL) {
ServerChannel *channel;
Terminal *terminal = NULL;
@@ -413,9 +362,7 @@ namespace smartcard_service_api
if (terminal != NULL) {
terminal->close();
}
- }
- else
- {
+ } else {
_ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
}
}
@@ -425,12 +372,9 @@ namespace smartcard_service_api
Terminal *result = NULL;
map<unsigned int, Terminal *>::iterator item;
- if ((item = mapTerminals.find(terminalID)) != mapTerminals.end())
- {
+ if ((item = mapTerminals.find(terminalID)) != mapTerminals.end()) {
result = item->second;
- }
- else
- {
+ } else {
_ERR("Terminal doesn't exist [%d]", terminalID);
}
@@ -442,12 +386,9 @@ namespace smartcard_service_api
const Terminal *result = NULL;
map<unsigned int, Terminal *>::const_iterator item;
- if ((item = mapTerminals.find(terminalID)) != mapTerminals.end())
- {
+ if ((item = mapTerminals.find(terminalID)) != mapTerminals.end()) {
result = item->second;
- }
- else
- {
+ } else {
_ERR("Terminal doesn't exist [%d]", terminalID);
}
@@ -476,12 +417,9 @@ namespace smartcard_service_api
Terminal *result = NULL;
map<unsigned int, unsigned int>::iterator item;
- if ((item = mapReaders.find(readerID)) != mapReaders.end())
- {
+ if ((item = mapReaders.find(readerID)) != mapReaders.end()) {
result = getTerminal(item->second);
- }
- else
- {
+ } else {
_ERR("Terminal doesn't exist, reader ID [%d]", readerID);
}
@@ -493,12 +431,9 @@ namespace smartcard_service_api
const Terminal *result = NULL;
map<unsigned int, unsigned int>::const_iterator item;
- if ((item = mapReaders.find(readerID)) != mapReaders.end())
- {
- result = getTerminal(item->second);
- }
- else
- {
+ if ((item = mapReaders.find(readerID)) != mapReaders.end()) {
+ result = getTerminal(item->second);
+ } else {
_ERR("Terminal doesn't exist, reader ID [%d]", readerID);
}
@@ -531,38 +466,28 @@ namespace smartcard_service_api
AccessControlList *acList = NULL;
/* request open channel sequence */
- if ((acList = getAccessControlList(channel)) == NULL)
- {
+ if ((acList = getAccessControlList(channel)) == NULL) {
/* load access control defined by Global Platform */
GPACE *acl = new GPACE();
- if (acl != NULL)
- {
+ if (acl != NULL) {
int ret;
ret = acl->loadACL(channel);
- if (ret >= SCARD_ERROR_OK)
- {
+ if (ret >= SCARD_ERROR_OK) {
acList = acl;
addAccessControlList(channel, acList);
- }
- else
- {
+ } else {
_ERR("unknown error, 0x%x", -ret);
delete acl;
}
- }
- else
- {
+ } else {
_ERR("alloc failed");
}
- }
- else
- {
+ } else {
acList->loadACL(channel);
}
- if (acList != NULL)
- {
+ if (acList != NULL) {
result = acList->isAuthorizedAccess(aid, hashes);
}
@@ -582,21 +507,15 @@ namespace smartcard_service_api
_DBG("command [%d] : %s", command.size(), command.toString().c_str());
rv = terminal->transmitSync(command, response);
- if (rv == 0 && response.size() >= 2)
- {
+ if (rv == 0 && response.size() >= 2) {
ResponseHelper resp(response);
- if (resp.getStatus() >= 0)
- {
+ if (resp.getStatus() >= 0) {
result = resp.getDataField()[0];
- }
- else
- {
+ } else {
result = resp.getStatus();
}
- }
- else
- {
+ } else {
_ERR("transmitSync failed, rv [%d], length [%d]", rv, response.size());
}
@@ -616,22 +535,16 @@ namespace smartcard_service_api
_DBG("command [%d] : %s", command.size(), command.toString().c_str());
rv = terminal->transmitSync(command, response);
- if (rv == 0 && response.size() >= 2)
- {
+ if (rv == 0 && response.size() >= 2) {
ResponseHelper resp(response);
- if (resp.getStatus() >= 0)
- {
+ if (resp.getStatus() >= 0) {
_DBG("channel closed [%d]", channelNum);
result = SCARD_ERROR_OK;
- }
- else
- {
+ } else {
_ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
}
- }
- else
- {
+ } else {
_ERR("select apdu is failed, rv [%d], length [%d]", rv, response.size());
}
@@ -648,15 +561,11 @@ namespace smartcard_service_api
ServerChannel *channel = NULL;
/* open logical channel */
- if (channelType == 1)
- {
+ if (channelType == 1) {
channelNum = _openLogicalChannel(terminal);
- if (channelNum > 0)
- {
+ if (channelNum > 0) {
_DBG("channelNum [%d]", channelNum);
- }
- else
- {
+ } else {
_ERR("_openLogicalChannel failed [%d]", channelNum);
throw ExceptionBase(SCARD_ERROR_NOT_ENOUGH_RESOURCE);
}
@@ -688,49 +597,37 @@ namespace smartcard_service_api
If you need the Access control in your target, please remove this comment.*/
/*
if (_isAuthorizedAccess(channel, aid,
- service->getParent()->getCertificationHashes()) == true)
- {
+ service->getParent()->getCertificationHashes()) == true) {
int rv = 0;
- if (aid == PKCS15::PKCS15_AID)
- {
+ if (aid == PKCS15::PKCS15_AID) {
PKCS15 pkcs15(channel);
rv = pkcs15.select();
- if (rv >= SCARD_ERROR_OK)
- {
+ if (rv >= SCARD_ERROR_OK) {
channel->unsetPrivilegeMode();
channel->setSelectResponse(pkcs15.getSelectResponse());
- }
- else
- {
+ } else {
_ERR("select failed, [%x]", -rv);
service->closeChannel(result);
throw ExceptionBase(SCARD_ERROR_IO_FAILED);
}
- }
- else
- {
+ } else {
FileObject file(channel);
rv = file.select(aid);
- if (rv >= SCARD_ERROR_OK)
- {
+ if (rv >= SCARD_ERROR_OK) {
channel->unsetPrivilegeMode();
channel->setSelectResponse(file.getSelectResponse());
- }
- else
- {
+ } else {
_ERR("select failed [%x]", -rv);
service->closeChannel(result);
throw ExceptionBase(SCARD_ERROR_IO_FAILED);
}
}
- }
- else
- {
+ } else {
_ERR("unauthorized access");
service->closeChannel(result);
@@ -744,12 +641,9 @@ namespace smartcard_service_api
{
map<Terminal *, AccessControlList *>::iterator item;
- if ((item = mapACL.find(terminal)) == mapACL.end())
- {
+ if ((item = mapACL.find(terminal)) == mapACL.end()) {
mapACL.insert(make_pair(terminal, acl));
- }
- else
- {
+ } else {
item->second = acl;
}
}
@@ -758,12 +652,9 @@ namespace smartcard_service_api
{
map<Terminal *, AccessControlList *>::iterator item;
- if ((item = mapACL.find(channel->getTerminal())) == mapACL.end())
- {
+ if ((item = mapACL.find(channel->getTerminal())) == mapACL.end()) {
mapACL.insert(make_pair(channel->getTerminal(), acl));
- }
- else
- {
+ } else {
item->second = acl;
}
}
@@ -801,20 +692,14 @@ namespace smartcard_service_api
/* create se instance */
createInstance = (terminal_create_instance_fn)dlsym(library, "create_instance");
- if (createInstance != NULL)
- {
+ if (createInstance != NULL) {
terminal = (Terminal *)createInstance();
- if (terminal != NULL)
- {
+ if (terminal != NULL) {
_DBG("terminal [%p]", terminal);
- }
- else
- {
+ } else {
_ERR("terminal is null");
}
- }
- else
- {
+ } else {
_ERR("create_instance is null [%d]", errno);
}
@@ -827,13 +712,11 @@ namespace smartcard_service_api
bool result = false;
libHandle = dlopen(library, RTLD_LAZY);
- if (libHandle != NULL)
- {
+ if (libHandle != NULL) {
Terminal *terminal = NULL;
terminal = createInstance(libHandle);
- if (terminal != NULL)
- {
+ if (terminal != NULL) {
unsigned int handle = IntegerHandle::assignHandle();
mapTerminals.insert(make_pair(handle, terminal));
@@ -843,22 +726,17 @@ namespace smartcard_service_api
_DBG("register success [%s] [%p] [%s] [%p]", library, libHandle, terminal->getName(), terminal);
- if (terminal->isSecureElementPresence() == true)
- {
+ if (terminal->isSecureElementPresence() == true) {
createReader(handle);
}
result = true;
- }
- else
- {
+ } else {
_ERR("terminal is null [%s]", library);
dlclose(libHandle);
}
- }
- else
- {
+ } else {
_ERR("it is not se file [%s] [%d]", library, errno);
}
@@ -869,18 +747,14 @@ namespace smartcard_service_api
{
int result = 0;
- if (seLoaded == false)
- {
+ if (seLoaded == false) {
DIR *dir;
struct dirent *entry;
- if ((dir = opendir(OMAPI_SE_PATH)) != NULL)
- {
- while ((entry = readdir(dir)) != NULL)
- {
+ if ((dir = opendir(OMAPI_SE_PATH)) != NULL) {
+ while ((entry = readdir(dir)) != NULL) {
if (strncmp(entry->d_name, ".", 1) != 0 &&
- strncmp(entry->d_name, "..", 2) != 0)
- {
+ strncmp(entry->d_name, "..", 2) != 0) {
char fullPath[1024];
/* TODO : need additional name rule :) */
@@ -897,9 +771,7 @@ namespace smartcard_service_api
closedir(dir);
seLoaded = true;
- }
- else
- {
+ } else {
result = -1;
}
}
@@ -968,20 +840,15 @@ namespace smartcard_service_api
unsigned int offset = 0;
unsigned int nameLen = 0;
- if (mapReaders.size() > 0)
- {
+ if (mapReaders.size() > 0) {
const Terminal *terminal = NULL;
map<unsigned int, unsigned int>::const_iterator item;
- for (item = mapReaders.begin(); item != mapReaders.end(); item++)
- {
- if (item->second != IntegerHandle::INVALID_HANDLE)
- {
+ for (item = mapReaders.begin(); item != mapReaders.end(); item++) {
+ if (item->second != IntegerHandle::INVALID_HANDLE) {
terminal = getTerminal(item->second);
- if (terminal != NULL)
- {
- if (terminal->isSecureElementPresence())
- {
+ if (terminal != NULL) {
+ if (terminal->isSecureElementPresence()) {
length += sizeof(nameLen) + strlen(terminal->getName()) + sizeof(unsigned int);
result++;
}
@@ -990,19 +857,14 @@ namespace smartcard_service_api
}
buffer = new unsigned char[length];
- if (buffer != NULL)
- {
+ if (buffer != NULL) {
memset(buffer, 0, length);
- for (item = mapReaders.begin(); item != mapReaders.end(); item++)
- {
- if (item->second != IntegerHandle::INVALID_HANDLE)
- {
+ for (item = mapReaders.begin(); item != mapReaders.end(); item++) {
+ if (item->second != IntegerHandle::INVALID_HANDLE) {
terminal = getTerminal(item->second);
- if (terminal != NULL)
- {
- if (terminal->isSecureElementPresence())
- {
+ if (terminal != NULL) {
+ if (terminal->isSecureElementPresence()) {
nameLen = strlen(terminal->getName());
memcpy(buffer + offset, &nameLen, sizeof(nameLen));
@@ -1020,15 +882,11 @@ namespace smartcard_service_api
info.assign(buffer, length);
delete []buffer;
- }
- else
- {
+ } else {
_ERR("alloc failed");
result = -1;
}
- }
- else
- {
+ } else {
_INFO("no secure element");
}
@@ -1133,15 +991,11 @@ namespace smartcard_service_api
ServerChannel *channel = NULL;
/* open logical channel */
- if (channelType == 1)
- {
+ if (channelType == 1) {
channelNum = _openLogicalChannel(terminal);
- if (channelNum > 0)
- {
+ if (channelNum > 0) {
_DBG("channelNum [%d]", channelNum);
- }
- else
- {
+ } else {
_ERR("_openLogicalChannel failed [%d]", channelNum);
throw ExceptionBase(SCARD_ERROR_NOT_ENOUGH_RESOURCE);
}
@@ -1167,7 +1021,6 @@ namespace smartcard_service_api
if (channel != NULL) {
AccessControlList *acl = getAccessControlList(channel);
if (acl == NULL) {
-
/* load access control defined by Global Platform */
acl = new GPACE();
if (acl != NULL) {
@@ -1217,7 +1070,6 @@ namespace smartcard_service_api
if (channel != NULL) {
AccessControlList *acl = getAccessControlList(channel);
if (acl == NULL) {
-
/* load access control defined by Global Platform */
acl = new GPACE();
if (acl != NULL) {
diff --git a/server/ServerSEService.cpp b/server/ServerSEService.cpp
index a80d54c..d4f094e 100644
--- a/server/ServerSEService.cpp
+++ b/server/ServerSEService.cpp
@@ -56,20 +56,14 @@ namespace smartcard_service_api
/* create se instance */
createInstance = (terminal_create_instance_fn)dlsym(library, "create_instance");
- if (createInstance != NULL)
- {
+ if (createInstance != NULL) {
terminal = (Terminal *)createInstance();
- if (terminal != NULL)
- {
+ if (terminal != NULL) {
_DBG("terminal [%p]", terminal);
- }
- else
- {
+ } else {
_ERR("terminal is null");
}
- }
- else
- {
+ } else {
_ERR("create_instance is null [%d]", errno);
}
@@ -82,13 +76,11 @@ namespace smartcard_service_api
bool result = false;
libHandle = dlopen(library, RTLD_LAZY);
- if (libHandle != NULL)
- {
+ if (libHandle != NULL) {
Terminal *terminal = NULL;
terminal = createInstance(libHandle);
- if (terminal != NULL)
- {
+ if (terminal != NULL) {
_DBG("SE info : [%s] [%s]", library, terminal->getName());
libraries.push_back(libHandle);
@@ -96,37 +88,27 @@ namespace smartcard_service_api
pair<string, Terminal *> newPair(terminal->getName(), terminal);
mapTerminals.insert(newPair);
- if (terminal->isSecureElementPresence() == true)
- {
+ if (terminal->isSecureElementPresence() == true) {
ServerReader *reader = new ServerReader(this, terminal->getName(), terminal);
- if (reader != NULL)
- {
+ if (reader != NULL) {
_DBG("register success [%s]", terminal->getName());
readers.push_back(reader);
- }
- else
- {
+ } else {
_ERR("ServerReader alloc failed [%s]", terminal->getName());
/* throw exception */
}
- }
- else
- {
+ } else {
_DBG("SE is not ready [%s]", terminal->getName());
}
result = true;
- }
- else
- {
+ } else {
_ERR("createInstance failed [%s]", library);
dlclose(libHandle);
}
- }
- else
- {
+ } else {
_ERR("it is not se file [%s] [%d]", library, errno);
}
@@ -139,12 +121,9 @@ namespace smartcard_service_api
DIR *dir = NULL;
struct dirent *entry = NULL;
- if ((dir = opendir(OMAPI_SE_PATH)) != NULL)
- {
- while ((entry = readdir(dir)) != NULL)
- {
- if (strncmp(entry->d_name, ".", 1) != 0 && strncmp(entry->d_name, "..", 2) != 0)
- {
+ if ((dir = opendir(OMAPI_SE_PATH)) != NULL) {
+ while ((entry = readdir(dir)) != NULL) {
+ if (strncmp(entry->d_name, ".", 1) != 0 && strncmp(entry->d_name, "..", 2) != 0) {
char fullPath[1024] = { 0, };
/* need additional name rule :) */
@@ -161,9 +140,7 @@ namespace smartcard_service_api
closedir(dir);
result = 0;
- }
- else
- {
+ } else {
result = -1;
}
diff --git a/server/ServerSession.cpp b/server/ServerSession.cpp
index 4f0e93e..3bf6829 100755
--- a/server/ServerSession.cpp
+++ b/server/ServerSession.cpp
@@ -127,15 +127,13 @@ namespace smartcard_service_api
_BEGIN();
acList = ((ServerReader *)reader)->getAccessControlList();
- if (acList == NULL)
- {
+ if (acList == NULL) {
_ERR("acList is null");
return channel;
}
- if (acList->isAuthorizedAccess(aid, certHashes) == false)
- {
+ if (acList->isAuthorizedAccess(aid, certHashes) == false) {
_ERR("unauthorized access, aid : %s", aid.toString().c_str());
return channel;
@@ -144,31 +142,22 @@ namespace smartcard_service_api
/* select aid */
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_DF_NAME, channelID, aid);
rv = terminal->transmitSync(command, result);
- if (rv == 0 && result.size() >= 2)
- {
+ if (rv == 0 && result.size() >= 2) {
ResponseHelper resp(result);
- if (resp.getStatus() == 0)
- {
+ if (resp.getStatus() == 0) {
channel = new ServerChannel(this, caller, channelID, terminal);
- if (channel != NULL)
- {
+ if (channel != NULL) {
channel->selectResponse = result;
channels.push_back(channel);
- }
- else
- {
+ } else {
_ERR("alloc failed");
}
- }
- else
- {
+ } else {
_ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
}
- }
- else
- {
+ } else {
_ERR("select apdu is failed, rv [%d], length [%d]", rv, result.size());
}
#endif
@@ -225,15 +214,13 @@ namespace smartcard_service_api
int rv;
acList = ((ServerReader *)reader)->getAccessControlList();
- if (acList == NULL)
- {
+ if (acList == NULL) {
_ERR("unauthorized access, aid %s, hash %s");
return channel;
}
- if (acList->isAuthorizedAccess(aid, certHashes) == false)
- {
+ if (acList->isAuthorizedAccess(aid, certHashes) == false) {
_ERR("unauthorized access, aid : %s", aid.toString().c_str());
return channel;
@@ -243,23 +230,17 @@ namespace smartcard_service_api
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_OPEN_LOGICAL_CHANNEL, 0, ByteArray::EMPTY);
rv = terminal->transmitSync(command, result);
- if (rv == 0 && result.size() >= 2)
- {
+ if (rv == 0 && result.size() >= 2) {
ResponseHelper resp(result);
- if (resp.getStatus() == 0)
- {
+ if (resp.getStatus() == 0) {
channelID = resp.getDataField()[0];
- }
- else
- {
+ } else {
_ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
return channel;
}
- }
- else
- {
+ } else {
_ERR("select apdu is failed, rv [%d], length [%d]", rv, result.size());
return channel;
@@ -269,15 +250,12 @@ namespace smartcard_service_api
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_DF_NAME, channelID, aid);
rv = terminal->transmitSync(command, result);
- if (rv == 0 && result.size() >= 2)
- {
+ if (rv == 0 && result.size() >= 2) {
ResponseHelper resp(result);
- if (resp.getStatus() == 0)
- {
+ if (resp.getStatus() == 0) {
channel = new ServerChannel(this, caller, channelID, terminal);
- if (channel == NULL)
- {
+ if (channel == NULL) {
_ERR("alloc failed");
return NULL;
@@ -286,14 +264,10 @@ namespace smartcard_service_api
channel->selectResponse = result;
channels.push_back(channel);
- }
- else
- {
+ } else {
_ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
}
- }
- else
- {
+ } else {
_ERR("select apdu is failed, rv [%d], length [%d]", rv, result.size());
}
#endif
diff --git a/server/ServiceInstance.cpp b/server/ServiceInstance.cpp
index 1444990..9cc0429 100755
--- a/server/ServiceInstance.cpp
+++ b/server/ServiceInstance.cpp
@@ -95,7 +95,6 @@ namespace smartcard_service_api
mapSessions.erase(item);
IntegerHandle::releaseHandle(session);
-
}
}
@@ -125,16 +124,13 @@ namespace smartcard_service_api
/* create ServerChannel */
channel = new ServerChannel((ServerSession *)session, (void *)parent->getPID(), channelNum, terminal);
- if (channel != NULL)
- {
+ if (channel != NULL) {
handle = IntegerHandle::assignHandle();
mapChannels.insert(make_pair(handle, make_pair(session, channel)));
if (response != ByteArray::EMPTY)
channel->selectResponse = response;
- }
- else
- {
+ } else {
_ERR("alloc failed");
}
diff --git a/server/private/PKCS15CDFACL.cpp b/server/private/PKCS15CDFACL.cpp
index f124a8a..e0c8d0a 100644
--- a/server/private/PKCS15CDFACL.cpp
+++ b/server/private/PKCS15CDFACL.cpp
@@ -69,27 +69,18 @@ namespace smartcard_service_api
if (cdf != NULL)
{
result = loadRules(channel, cdf);
- if (result == SCARD_ERROR_OK)
- {
+ if (result == SCARD_ERROR_OK) {
printAccessControlList();
- }
- else
- {
+ } else {
result = SCARD_ERROR_OK;
}
- }
- else
- {
+ } else {
_ERR("dodf null, every request will be denied.");
}
- }
- else
- {
+ } else {
_ERR("odf null, every request will be denied.");
}
- }
- else
- {
+ } else {
_ERR("failed to open PKCS#15, every request will be denied.");
}
diff --git a/test-client/test-client-sync.cpp b/test-client/test-client-sync.cpp
index 27dc303..18f547d 100644
--- a/test-client/test-client-sync.cpp
+++ b/test-client/test-client-sync.cpp
@@ -86,8 +86,7 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
_BEGIN();
- if (service != NULL)
- {
+ if (service != NULL) {
_DBG("callback called, service [%p]", service);
context->clientService = service;
@@ -95,8 +94,7 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
readers = service->getReaders();
size_t i;
- for (i = 0; i < readers.size(); i++)
- {
+ for (i = 0; i < readers.size(); i++) {
Reader *reader = NULL;
reader = (Reader *)readers[i];
@@ -104,8 +102,7 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
_DBG("reader [%p]", reader);
Session *session = (Session *)reader->openSessionSync();
- if (session != NULL)
- {
+ if (session != NULL) {
_DBG("session [%p]", session);
ByteArray temp;
@@ -125,8 +122,7 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
try
{
ClientChannel *channel = (ClientChannel *)session->openLogicalChannelSync(aid);
- if (channel != NULL)
- {
+ if (channel != NULL) {
_DBG("channel [%p]", channel);
ByteArray response;
ByteArray data, command;
@@ -145,9 +141,7 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
_INFO("error : %d, response : %s", error, response.toString().c_str());
channel->closeSync();
- }
- else
- {
+ } else {
_ERR("openLogicalChannelSync failed");
}
}
@@ -157,17 +151,13 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
}
session->closeSync();
- }
- else
- {
+ } else {
_ERR("openSessionSync failed");
}
}
((SEService *)service)->shutdownSync();
- }
- else
- {
+ } else {
_ERR("service is NULL");
}
diff --git a/test-client/test-client.cpp b/test-client/test-client.cpp
index 6397f47..238191b 100644
--- a/test-client/test-client.cpp
+++ b/test-client/test-client.cpp
@@ -115,8 +115,7 @@ void testOpenChannelCallback(Channel *channel, int error, void *userData)
{
_DBG("channel [%p]", channel);
- if (error == 0 && channel != NULL)
- {
+ if (error == 0 && channel != NULL) {
ByteArray response;
ByteArray data, command;
int fid = 0x00003150;
@@ -134,9 +133,7 @@ void testOpenChannelCallback(Channel *channel, int error, void *userData)
data.assign((unsigned char *)&fid, 2);
command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_ID, 0, data);
context->clientChannel->transmit(command, testTransmitCallback, userData);
- }
- else
- {
+ } else {
_ERR("openBasicChannel failed");
}
}
@@ -156,22 +153,18 @@ void testGetATRCallback(unsigned char *atr, unsigned int length, int error, void
void testCloseSessionCallback(int error, void *userData)
{
-
}
void testOpenSessionCallback(SessionHelper *session, int error, void *userData)
{
_DBG("session [%p]", session);
- if (session != NULL)
- {
+ if (session != NULL) {
user_context_t *context = (user_context_t *)userData;
context->clientSession = (Session *)session;
context->clientSession->getATR(testGetATRCallback, userData);
- }
- else
- {
+ } else {
_ERR("openSession failed");
}
}
@@ -183,16 +176,14 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
_BEGIN();
- if (service != NULL)
- {
+ if (service != NULL) {
_DBG("callback called, service [%p]", service);
context->clientService = service;
readers = service->getReaders();
- if (readers.size() > 0)
- {
+ if (readers.size() > 0) {
Reader *reader = NULL;
reader = (Reader *)readers[0];
@@ -200,14 +191,10 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
_DBG("reader [%p]", reader);
reader->openSession(testOpenSessionCallback, userData);
- }
- else
- {
+ } else {
_ERR("reader is empty");
}
- }
- else
- {
+ } else {
_ERR("service is NULL");
}