• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <openssl/ecdsa.h>
20 
21 #include <hardware/keymaster1.h>
22 #include <keymaster/android_keymaster_utils.h>
23 #include <keymaster/contexts/soft_keymaster_context.h>
24 #include <keymaster/km_openssl/ec_key.h>
25 #include <keymaster/km_openssl/ec_key_factory.h>
26 #include <keymaster/logger.h>
27 
28 #include "keymaster1_engine.h"
29 
30 namespace keymaster {
31 
32 /**
33  * EcdsaKeymaster1KeyFactory is a KeyFactory that creates and loads keys which are actually backed
34  * by a hardware keymaster1 module, but which does not support all keymaster1 digests.  During
35  * generation or import any unsupported digests in the key description are silently replaced with
36  * KM_DIGEST_NONE.
37  */
38 class EcdsaKeymaster1KeyFactory : public EcKeyFactory {
39   public:
40     EcdsaKeymaster1KeyFactory(const SoftwareKeyBlobMaker& blob_maker,
41                               const KeymasterContext& context,  //
42                               const Keymaster1Engine* engine);
43 
44     keymaster_error_t GenerateKey(const AuthorizationSet& key_description,
45                                   UniquePtr<Key> attest_key,            //
46                                   const KeymasterBlob& issuer_subject,  //
47                                   KeymasterKeyBlob* key_blob,           //
48                                   AuthorizationSet* hw_enforced,        //
49                                   AuthorizationSet* sw_enforced,
50                                   CertificateChain* cert_chain) const override;
51 
52     keymaster_error_t ImportKey(const AuthorizationSet& key_description,
53                                 keymaster_key_format_t input_key_material_format,
54                                 const KeymasterKeyBlob& input_key_material,
55                                 UniquePtr<Key> attest_key,  //
56                                 const KeymasterBlob& issuer_subject,
57                                 KeymasterKeyBlob* output_key_blob,  //
58                                 AuthorizationSet* hw_enforced,      //
59                                 AuthorizationSet* sw_enforced,
60                                 CertificateChain* cert_chain) const override;
61 
62     keymaster_error_t LoadKey(KeymasterKeyBlob&& key_material,
63                               const AuthorizationSet& additional_params,
64                               AuthorizationSet&& hw_enforced, AuthorizationSet&& sw_enforced,
65                               UniquePtr<Key>* key) const override;
66 
67     OperationFactory* GetOperationFactory(keymaster_purpose_t purpose) const override;
68 
69   private:
70     const Keymaster1Engine* engine_;
71 
72     std::unique_ptr<OperationFactory> sign_factory_;
73     std::unique_ptr<OperationFactory> verify_factory_;
74 };
75 
76 class EcdsaKeymaster1Key : public EcKey {
77   public:
EcdsaKeymaster1Key(EC_KEY * ecdsa_key,AuthorizationSet && hw_enforced,AuthorizationSet && sw_enforced,const KeyFactory * key_factory)78     EcdsaKeymaster1Key(EC_KEY* ecdsa_key, AuthorizationSet&& hw_enforced,
79                        AuthorizationSet&& sw_enforced, const KeyFactory* key_factory)
80         : EcKey(ecdsa_key, move(hw_enforced), move(sw_enforced), key_factory) {}
81 };
82 
83 }  // namespace keymaster
84