• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
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  * Copyright (c) 2017, The Linux Foundation.
18  */
19 
20 /*
21  * Copyright 2012 Giesecke & Devrient GmbH.
22  *
23  * Licensed under the Apache License, Version 2.0 (the "License");
24  * you may not use this file except in compliance with the License.
25  * You may obtain a copy of the License at
26  *
27  *      http://www.apache.org/licenses/LICENSE-2.0
28  *
29  * Unless required by applicable law or agreed to in writing, software
30  * distributed under the License is distributed on an "AS IS" BASIS,
31  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32  * See the License for the specific language governing permissions and
33  * limitations under the License.
34  */
35 
36 package com.android.se.security;
37 
38 /** Class for Storing the APDU and NFC Access for a particular Channel */
39 public class ChannelAccess {
40 
41     private final String mTag = "SecureElement-ChannelAccess";
42     private String mPackageName = "";
43     private ACCESS mAccess = ACCESS.UNDEFINED;
44     private ACCESS mApduAccess = ACCESS.UNDEFINED;
45     private boolean mUseApduFilter = false;
46     private int mCallingPid = 0;
47     private String mReason = "no access by default";
48     private ACCESS mNFCEventAccess = ACCESS.UNDEFINED;
49     private ApduFilter[] mApduFilter = null;
50 
51     /** Clones the ChannelAccess */
clone()52     public ChannelAccess clone() {
53         ChannelAccess ca = new ChannelAccess();
54         ca.setAccess(mAccess, mReason);
55         ca.setPackageName(mPackageName);
56         ca.setApduAccess(mApduAccess);
57         ca.setCallingPid(mCallingPid);
58         ca.setNFCEventAccess(mNFCEventAccess);
59         ca.setUseApduFilter(mUseApduFilter);
60         if (mApduFilter != null) {
61             ApduFilter[] apduFilter = new ApduFilter[mApduFilter.length];
62             int i = 0;
63             for (ApduFilter filter : mApduFilter) {
64                 apduFilter[i++] = filter.clone();
65             }
66             ca.setApduFilter(apduFilter);
67         } else {
68             ca.setApduFilter(null);
69         }
70         return ca;
71     }
72 
getPackageName()73     public String getPackageName() {
74         return mPackageName;
75     }
76 
setPackageName(String name)77     public void setPackageName(String name) {
78         mPackageName = name;
79     }
80 
getApduAccess()81     public ACCESS getApduAccess() {
82         return mApduAccess;
83     }
84 
setApduAccess(ACCESS apduAccess)85     public void setApduAccess(ACCESS apduAccess) {
86         mApduAccess = apduAccess;
87     }
88 
getAccess()89     public ACCESS getAccess() {
90         return mAccess;
91     }
92 
93     /** Sets the Access for the ChannelAccess */
setAccess(ACCESS access, String reason)94     public void setAccess(ACCESS access, String reason) {
95         mAccess = access;
96         mReason = reason;
97     }
98 
isUseApduFilter()99     public boolean isUseApduFilter() {
100         return mUseApduFilter;
101     }
102 
setUseApduFilter(boolean useApduFilter)103     public void setUseApduFilter(boolean useApduFilter) {
104         mUseApduFilter = useApduFilter;
105     }
106 
getCallingPid()107     public int getCallingPid() {
108         return mCallingPid;
109     }
110 
setCallingPid(int callingPid)111     public void setCallingPid(int callingPid) {
112         mCallingPid = callingPid;
113     }
114 
getReason()115     public String getReason() {
116         return mReason;
117     }
118 
getApduFilter()119     public ApduFilter[] getApduFilter() {
120         return mApduFilter;
121     }
122 
setApduFilter(ApduFilter[] accessConditions)123     public void setApduFilter(ApduFilter[] accessConditions) {
124         mApduFilter = accessConditions;
125     }
126 
getNFCEventAccess()127     public ACCESS getNFCEventAccess() {
128         return mNFCEventAccess;
129     }
130 
setNFCEventAccess(ACCESS access)131     public void setNFCEventAccess(ACCESS access) {
132         mNFCEventAccess = access;
133     }
134 
135     @Override
toString()136     public String toString() {
137         StringBuilder sb = new StringBuilder();
138         sb.append(this.getClass().getName());
139         sb.append("\n [mPackageName=");
140         sb.append(mPackageName);
141         sb.append(", mAccess=");
142         sb.append(mAccess);
143         sb.append(", mApduAccess=");
144         sb.append(mApduAccess);
145         sb.append(", mUseApduFilter=");
146         sb.append(mUseApduFilter);
147         sb.append(", mApduFilter=");
148         if (mApduFilter != null) {
149             for (ApduFilter f : mApduFilter) {
150                 sb.append(f.toString());
151                 sb.append(" ");
152             }
153         } else {
154             sb.append("null");
155         }
156         sb.append(", mCallingPid=");
157         sb.append(mCallingPid);
158         sb.append(", mReason=");
159         sb.append(mReason);
160         sb.append(", mNFCEventAllowed=");
161         sb.append(mNFCEventAccess);
162         sb.append("]\n");
163 
164         return sb.toString();
165     }
166 
167     public enum ACCESS {
168         ALLOWED,
169         DENIED,
170         UNDEFINED;
171     }
172 }
173