Asynchronous API framework
[platform/core/security/key-manager.git] / src / include / ckm / ckm-manager.h
1 /*
2  *  Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file        ckm-manager.h
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @version     1.0
20  * @brief       Main header file for client library.
21  */
22 #pragma once
23
24 #include <string>
25 #include <vector>
26 #include <memory>
27
28 #include <ckm/ckm-certificate.h>
29 #include <ckm/ckm-error.h>
30 #include <ckm/ckm-key.h>
31 #include <ckm/ckm-type.h>
32
33 // Central Key Manager namespace
34 namespace CKM {
35
36 class Manager;
37 typedef std::shared_ptr<Manager> ManagerShPtr;
38
39 class Manager {
40 public:
41     virtual ~Manager(){}
42
43     virtual int saveKey(const Alias &alias, const KeyShPtr &key, const Policy &policy) = 0;
44     virtual int saveCertificate(const Alias &alias, const CertificateShPtr &cert, const Policy &policy) = 0;
45
46     /*
47      * Data must be extractable. If you set extractable bit to false funciton will
48      * return ERROR_INPUT_PARAM.
49      */
50     virtual int saveData(const Alias &alias, const RawBuffer &data, const Policy &policy) = 0;
51
52     virtual int removeKey(const Alias &alias) = 0;
53     virtual int removeCertificate(const Alias &alias) = 0;
54     virtual int removeData(const Alias &alias) = 0;
55
56     virtual int getKey(const Alias &alias, const Password &password, KeyShPtr &key) = 0;
57     virtual int getCertificate(
58         const Alias &alias,
59         const Password &password,
60         CertificateShPtr &certificate) = 0;
61     virtual int getData(const Alias &alias, const Password &password, RawBuffer &data) = 0;
62
63     // send request for list of all keys/certificates/data that application/user may use
64     virtual int getKeyAliasVector(AliasVector &aliasVector) = 0;
65     virtual int getCertificateAliasVector(AliasVector &aliasVector) = 0;
66     virtual int getDataAliasVector(AliasVector &aliasVector) = 0;
67
68     virtual int createKeyPairRSA(
69         const int size,              // size in bits [1024, 2048, 4096]
70         const Alias &privateKeyAlias,
71         const Alias &publicKeyAlias,
72         const Policy &policyPrivateKey = Policy(),
73         const Policy &policyPublicKey = Policy()) = 0;
74
75     virtual int createKeyPairDSA(
76         const int size,              // size in bits [1024, 2048, 3072, 4096]
77         const Alias &privateKeyAlias,
78         const Alias &publicKeyAlias,
79         const Policy &policyPrivateKey = Policy(),
80         const Policy &policyPublicKey = Policy()) = 0;
81
82     virtual int createKeyPairECDSA(
83         const ElipticCurve type,
84         const Alias &privateKeyAlias,
85         const Alias &publicKeyAlias,
86         const Policy &policyPrivateKey = Policy(),
87         const Policy &policyPublicKey = Policy()) = 0;
88
89     virtual int getCertificateChain(
90         const CertificateShPtr &certificate,
91         const CertificateShPtrVector &untrustedCertificates,
92         CertificateShPtrVector &certificateChainVector) = 0;
93
94     virtual int getCertificateChain(
95         const CertificateShPtr &certificate,
96         const AliasVector &untrustedCertificates,
97         CertificateShPtrVector &certificateChainVector) = 0;
98
99     virtual int createSignature(
100         const Alias &privateKeyAlias,
101         const Password &password,           // password for private_key
102         const RawBuffer &message,
103         const HashAlgorithm hash,
104         const RSAPaddingAlgorithm padding,
105         RawBuffer &signature) = 0;
106
107     virtual int verifySignature(
108         const Alias &publicKeyOrCertAlias,
109         const Password &password,           // password for public_key (optional)
110         const RawBuffer &message,
111         const RawBuffer &signature,
112         const HashAlgorithm hash,
113         const RSAPaddingAlgorithm padding) = 0;
114
115     // This function will check all certificates in chain except Root CA.
116     // This function will delegate task to service. You may use this even
117     // if application does not have permission to use network.
118     virtual int ocspCheck(const CertificateShPtrVector &certificateChainVector, int &ocspStatus) = 0;
119
120     virtual int allowAccess(const std::string &alias, const std::string &accessor, AccessRight granted) = 0;
121     virtual int denyAccess(const std::string &alias, const std::string &accessor) = 0;
122
123
124     static ManagerShPtr create();
125 //    static ManagerShPtr getManager(int uid); // TODO
126 };
127
128 } // namespace CKM
129