Minor change
[platform/core/connectivity/smartcard-service.git] / common / GPACE.cpp
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /* standard library header */
18
19 /* SLP library header */
20
21 /* local header */
22 #include "Debug.h"
23 #include "GPACE.h"
24 #include "GPARAACL.h"
25 #include "GPARFACL.h"
26 #include "SessionHelper.h"
27 #include "ReaderHelper.h"
28
29 #ifndef EXTERN_API
30 #define EXTERN_API __attribute__((visibility("default")))
31 #endif
32
33 namespace smartcard_service_api
34 {
35         GPACE::GPACE() : AccessControlList(), acl(NULL)
36         {
37         }
38
39         GPACE::~GPACE()
40         {
41                 if (acl != NULL) {
42                         delete acl;
43                 }
44         }
45
46         int GPACE::loadACL(Channel *channel)
47         {
48                 int result = SCARD_ERROR_OK;
49
50                 _BEGIN();
51
52                 if (channel == NULL)
53                 {
54                         return SCARD_ERROR_ILLEGAL_PARAM;
55                 }
56
57                 if (acl == NULL) {
58                         /* first, check ara-m */
59                         GPARAACL *araACL = new GPARAACL;
60
61                         result = araACL->loadACL(channel);
62                         if (result < SCARD_ERROR_OK) {
63                                 _ERR("ARA not found");
64
65                                 delete araACL;
66
67                                 if (true) {
68                                         _INFO("try to use ARF");
69                                         /* second, check arf when channel is for SIM */
70                                         GPARFACL *arfACL = new GPARFACL;
71
72                                         result = arfACL->loadACL(channel);
73                                         if (result >= SCARD_ERROR_OK) {
74                                                 acl = arfACL;
75                                         } else {
76                                                 delete arfACL;
77                                         }
78                                 }
79                         } else {
80                                 acl = araACL;
81                         }
82                 } else {
83                         result = acl->loadACL(channel);
84                 }
85
86                 _END();
87
88                 return result;
89         }
90
91         bool GPACE::isAuthorizedAccess(const ByteArray &aid,
92                 const ByteArray &certHash) const
93         {
94                 return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHash) : false;
95         }
96
97         bool GPACE::isAuthorizedAccess(const unsigned char *aidBuffer,
98                 unsigned int aidLength, const unsigned char *certHashBuffer,
99                 unsigned int certHashLength) const
100         {
101                 return (acl != NULL) ? acl->isAuthorizedAccess(aidBuffer, aidLength, certHashBuffer, certHashLength) : false;
102         }
103
104         bool GPACE::isAuthorizedAccess(const ByteArray &aid,
105                 const vector<ByteArray> &certHashes) const
106         {
107                 return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHashes) : false;
108         }
109
110         bool GPACE::isAuthorizedAccess(const ByteArray &aid,
111                 const vector<ByteArray> &certHashes,
112                 const ByteArray &command) const
113         {
114                 return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHashes, command) : false;
115         }
116
117         bool GPACE::isAuthorizedNFCAccess(const ByteArray &aid,
118                 const vector<ByteArray> &certHashes) const
119         {
120                 return (acl != NULL) ? acl->isAuthorizedNFCAccess(aid, certHashes) : false;
121         }
122
123 } /* namespace smartcard_service_api */