Add rule for 'All devices apps' when access rule is empty.
[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 #include "Debug.h"
18 #include "GPACE.h"
19 #include "GPARAACL.h"
20 #include "GPARFACL.h"
21 #include "SessionHelper.h"
22 #include "ReaderHelper.h"
23
24 #ifndef EXTERN_API
25 #define EXTERN_API __attribute__((visibility("default")))
26 #endif
27
28 namespace smartcard_service_api
29 {
30         GPACE::GPACE() : AccessControlList(), acl(NULL)
31         {
32         }
33
34         GPACE::~GPACE()
35         {
36                 if (acl != NULL) {
37                         delete acl;
38                 }
39         }
40
41         int GPACE::loadACL(Channel *channel)
42         {
43                 int result = SCARD_ERROR_OK;
44
45                 _BEGIN();
46
47                 if (channel == NULL)
48                 {
49                         return SCARD_ERROR_ILLEGAL_PARAM;
50                 }
51
52                 if (acl == NULL) {
53                         /* first, check ara-m */
54                         GPARAACL *araACL = new GPARAACL;
55
56                         result = araACL->loadACL(channel);
57                         if (result < SCARD_ERROR_OK) {
58                                 _ERR("ARA not found");
59
60                                 delete araACL;
61
62                                 if (true) {
63                                         _INFO("try to use ARF");
64                                         /* second, check arf when channel is for SIM */
65                                         GPARFACL *arfACL = new GPARFACL;
66
67                                         result = arfACL->loadACL(channel);
68                                         if (result >= SCARD_ERROR_OK) {
69                                                 acl = arfACL;
70                                         } else {
71                                                 delete arfACL;
72                                         }
73                                 }
74                         } else {
75                                 acl = araACL;
76                         }
77                 } else {
78                         result = acl->loadACL(channel);
79                 }
80
81                 _END();
82
83                 return result;
84         }
85
86         bool GPACE::isAuthorizedAccess(const ByteArray &aid,
87                 const ByteArray &certHash) const
88         {
89                 return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHash) : false;
90         }
91
92         bool GPACE::isAuthorizedAccess(const unsigned char *aidBuffer,
93                 unsigned int aidLength, const unsigned char *certHashBuffer,
94                 unsigned int certHashLength) const
95         {
96                 return (acl != NULL) ? acl->isAuthorizedAccess(aidBuffer, aidLength, certHashBuffer, certHashLength) : false;
97         }
98
99         bool GPACE::isAuthorizedAccess(const ByteArray &aid,
100                 const vector<ByteArray> &certHashes) const
101         {
102                 return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHashes) : false;
103         }
104
105         bool GPACE::isAuthorizedAccess(const ByteArray &aid,
106                 const vector<ByteArray> &certHashes,
107                 const ByteArray &command) const
108         {
109                 return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHashes, command) : false;
110         }
111
112         bool GPACE::isAuthorizedNFCAccess(const ByteArray &aid,
113                 const vector<ByteArray> &certHashes) const
114         {
115                 return (acl != NULL) ? acl->isAuthorizedNFCAccess(aid, certHashes) : false;
116         }
117
118 } /* namespace smartcard_service_api */