1 /*
2  * Copyright 2015 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 #pragma once
18 
19 #include "key_factory.h"
20 
21 namespace keymaster {
22 
23 class SoftwareKeyBlobMaker {
24   protected:
25     // make destructor protected so only implementers can destroy instances.
~SoftwareKeyBlobMaker()26     virtual ~SoftwareKeyBlobMaker() {}
27 
28   public:
29     /**
30      * CreateKeyBlob takes authorization sets and key material and produces a key blob and hardware
31      * and software authorization lists ready to be returned to the AndroidKeymaster client
32      * (Keystore, generally).  The blob must be integrity-checked and may be encrypted, depending
33      * on the needs of the context.
34      */
35     virtual keymaster_error_t CreateKeyBlob(const AuthorizationSet& key_description,
36                                             keymaster_key_origin_t origin,
37                                             const KeymasterKeyBlob& key_material,
38                                             KeymasterKeyBlob* blob, AuthorizationSet* hw_enforced,
39                                             AuthorizationSet* sw_enforced) const = 0;
40 };
41 
42 class SoftKeyFactoryMixin {
43   public:
SoftKeyFactoryMixin(const SoftwareKeyBlobMaker & blob_maker)44     explicit SoftKeyFactoryMixin(const SoftwareKeyBlobMaker& blob_maker)
45         : blob_maker_(blob_maker) {}
~SoftKeyFactoryMixin()46     virtual ~SoftKeyFactoryMixin() {}
47 
48   protected:
49     const SoftwareKeyBlobMaker& blob_maker_;
50 };
51 
52 }  // namespace keymaster
53