2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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()
43 AccessControlList::AccessControlList(Channel *channel)
51 AccessControlList::AccessControlList(Terminal *terminal)
56 setTerminal(terminal);
59 AccessControlList::~AccessControlList()
63 if (terminal != NULL && channel != NULL)
69 int AccessControlList::setChannel(Channel *channel)
71 this->channel = channel;
76 int AccessControlList::updateACL()
83 void AccessControlList::releaseACL()
85 mapConditions.clear();
88 bool AccessControlList::isAuthorizedAccess(ByteArray aid, ByteArray certHash)
91 map<ByteArray, AccessCondition>::iterator iterMap;
93 SCARD_DEBUG("aid : %s", aid.toString());
94 SCARD_DEBUG("hash : %s", certHash.toString());
96 /* null aid means default applet */
97 if (aid.isEmpty() == true)
102 /* first.. find hashes matched with aid */
103 if ((iterMap = mapConditions.find(aid)) != mapConditions.end())
105 result = iterMap->second.isAuthorizedAccess(certHash);
107 /* finally.. find hashes in 'all' list */
108 else if ((iterMap = mapConditions.find(AID_ALL)) != mapConditions.end())
110 result = iterMap->second.isAuthorizedAccess(certHash);
116 bool AccessControlList::isAuthorizedAccess(unsigned char *aidBuffer, unsigned int aidLength, unsigned char *certHashBuffer, unsigned int certHashLength)
118 return isAuthorizedAccess(ByteArray(aidBuffer, aidLength), ByteArray(certHashBuffer, certHashLength));
121 void AccessControlList::printAccessControlList()
125 /* release map and vector */
126 map<ByteArray, AccessCondition>::iterator iterMap;
128 SCARD_DEBUG("================ Certification Hashes ==================");
129 for (iterMap = mapConditions.begin(); iterMap != mapConditions.end(); iterMap++)
131 temp = iterMap->first;
133 SCARD_DEBUG("+ aid : %s", (temp == AID_DEFAULT) ? "DEFAULT" : (temp == AID_ALL) ? "ALL" : temp.toString());
135 iterMap->second.printAccessConditions();
137 SCARD_DEBUG("========================================================");
140 } /* namespace smartcard_service_api */