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) 2014-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"); you may not
24  * use this file except in compliance with the License. You may obtain a copy of
25  * 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, WITHOUT
31  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
32  * License for the specific language governing permissions and limitations under
33  * the License.
34  */
35 package com.android.se.security.arf;
36 
37 import com.android.se.Terminal;
38 import com.android.se.security.AccessRuleCache;
39 import com.android.se.security.arf.pkcs15.PKCS15Handler;
40 
41 import java.io.IOException;
42 import java.util.MissingResourceException;
43 import java.util.NoSuchElementException;
44 
45 /** Initializes and maintains the ARF access rules of a Secure Element */
46 public class ArfController {
47 
48     private PKCS15Handler mPkcs15Handler = null;
49     private SecureElement mSecureElement = null;
50     private AccessRuleCache mAccessRuleCache = null;
51     private Terminal mTerminal = null;
52 
ArfController(AccessRuleCache cache, Terminal terminal)53     public ArfController(AccessRuleCache cache, Terminal terminal) {
54         mAccessRuleCache = cache;
55         mTerminal = terminal;
56     }
57 
58     /** Initializes the ARF Rules for the Secure Element */
initialize()59     public synchronized boolean initialize() throws IOException, MissingResourceException,
60             NoSuchElementException {
61         if (mSecureElement == null) {
62             mSecureElement = new SecureElement(this, mTerminal);
63         }
64         if (mPkcs15Handler == null) {
65             mPkcs15Handler = new PKCS15Handler(mSecureElement);
66         }
67         return mPkcs15Handler.loadAccessControlRules(mTerminal.getName());
68     }
69 
getAccessRuleCache()70     public AccessRuleCache getAccessRuleCache() {
71         return mAccessRuleCache;
72     }
73 }
74