2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 /* standard library header */
21 /* SLP library header */
25 #include "AccessControlList.h"
27 #include "AccessCondition.h"
29 namespace smartcard_service_api
31 const unsigned char aid_all[] = { 0x00, 0x00 };
32 const unsigned char aid_default[] = { 0x00, 0x01 };
34 ByteArray AccessControlList::AID_ALL(ARRAY_AND_SIZE(aid_all));
35 ByteArray AccessControlList::AID_DEFAULT(ARRAY_AND_SIZE(aid_default));
37 AccessControlList::AccessControlList()
42 AccessControlList::~AccessControlList()
47 void AccessControlList::releaseACL()
49 mapConditions.clear();
53 bool AccessControlList::isAuthorizedAccess(ByteArray aid, ByteArray certHash, bool update)
55 bool result = allGranted;
56 map<ByteArray, AccessCondition>::iterator iterMap;
60 SCARD_DEBUG("aid : %s", aid.toString());
61 SCARD_DEBUG("hash : %s", certHash.toString());
63 /* null aid means default applet */
64 if (aid.isEmpty() == true)
69 /* first.. find hashes matched with aid */
70 if ((iterMap = mapConditions.find(aid)) != mapConditions.end())
72 result = iterMap->second.isAuthorizedAccess(certHash);
74 /* finally.. find hashes in 'all' list */
75 else if ((iterMap = mapConditions.find(AID_ALL)) != mapConditions.end())
77 result = iterMap->second.isAuthorizedAccess(certHash);
84 bool AccessControlList::isAuthorizedAccess(ByteArray aid, ByteArray certHash)
86 return isAuthorizedAccess(aid, certHash, true);
89 bool AccessControlList::isAuthorizedAccess(unsigned char *aidBuffer, unsigned int aidLength, unsigned char *certHashBuffer, unsigned int certHashLength)
91 return isAuthorizedAccess(ByteArray(aidBuffer, aidLength), ByteArray(certHashBuffer, certHashLength), true);
94 bool AccessControlList::isAuthorizedAccess(ByteArray aid, vector<ByteArray> &certHashes)
103 for (i = 0; result == false && i < certHashes.size(); i++)
105 result = isAuthorizedAccess(aid, certHashes[i], false);
112 void AccessControlList::printAccessControlList()
116 /* release map and vector */
117 map<ByteArray, AccessCondition>::iterator iterMap;
119 SCARD_DEBUG("================ Certification Hashes ==================");
120 for (iterMap = mapConditions.begin(); iterMap != mapConditions.end(); iterMap++)
122 temp = iterMap->first;
124 SCARD_DEBUG("+ aid : %s", (temp == AID_DEFAULT) ? "DEFAULT" : (temp == AID_ALL) ? "ALL" : temp.toString());
126 iterMap->second.printAccessConditions();
128 SCARD_DEBUG("========================================================");
131 } /* namespace smartcard_service_api */