Added Gtest for smartcard-service
[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         /* LCOV_EXCL_START */
36         GPACE::GPACE() : AccessControlList(), acl(NULL)
37         {
38         }
39
40         GPACE::~GPACE()
41         {
42                 if (acl != NULL) {
43                         delete acl;
44                 }
45         }
46
47         int GPACE::loadACL(Channel *channel)
48         {
49                 int result = SCARD_ERROR_OK;
50
51                 _BEGIN();
52
53                 if (channel == NULL)
54                 {
55                         return SCARD_ERROR_ILLEGAL_PARAM;
56                 }
57
58                 if (acl == NULL) {
59                         /* first, check ara-m */
60                         GPARAACL *araACL = new GPARAACL;
61
62                         result = araACL->loadACL(channel);
63                         if (result < SCARD_ERROR_OK) {
64                                 _ERR("ARA not found");
65
66                                 delete araACL;
67
68                                 if (true) {
69                                         _INFO("try to use ARF");
70                                         /* second, check arf when channel is for SIM */
71                                         GPARFACL *arfACL = new GPARFACL;
72
73                                         result = arfACL->loadACL(channel);
74                                         if (result >= SCARD_ERROR_OK) {
75                                                 acl = arfACL;
76                                         } else {
77                                                 delete arfACL;
78                                         }
79                                 }
80                         } else {
81                                 acl = araACL;
82                         }
83                 } else {
84                         result = acl->loadACL(channel);
85                 }
86
87                 _END();
88
89                 return result;
90         }
91
92         bool GPACE::isAuthorizedAccess(const ByteArray &aid,
93                 const ByteArray &certHash) const
94         {
95                 return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHash) : false;
96         }
97
98         bool GPACE::isAuthorizedAccess(const unsigned char *aidBuffer,
99                 unsigned int aidLength, const unsigned char *certHashBuffer,
100                 unsigned int certHashLength) const
101         {
102                 return (acl != NULL) ? acl->isAuthorizedAccess(aidBuffer, aidLength, certHashBuffer, certHashLength) : false;
103         }
104
105         bool GPACE::isAuthorizedAccess(const ByteArray &aid,
106                 const vector<ByteArray> &certHashes) const
107         {
108                 return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHashes) : false;
109         }
110
111         bool GPACE::isAuthorizedAccess(const ByteArray &aid,
112                 const vector<ByteArray> &certHashes,
113                 const ByteArray &command) const
114         {
115                 return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHashes, command) : false;
116         }
117
118         bool GPACE::isAuthorizedNFCAccess(const ByteArray &aid,
119                 const vector<ByteArray> &certHashes) const
120         {
121                 return (acl != NULL) ? acl->isAuthorizedNFCAccess(aid, certHashes) : false;
122         }
123
124         /* LCOV_EXCL_STOP */
125 } /* namespace smartcard_service_api */