AES: add generation, save, get support.
[platform/core/security/key-manager.git] / src / manager / common / protocols.h
1 /*
2  *  Copyright (c) 2000 - 2014 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  * @file        protocols.h
17  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
18  * @author      Zofia Abramowska (z.abramowska@samsung.com)
19  * @version     1.0
20  * @brief       This file contains list of all protocols suported by Central
21  *              Key Manager.
22  */
23 #pragma once
24
25 #include <stdexcept>
26 #include <string>
27
28 #include <ckm/ckm-type.h>
29 #include <pkcs12-impl.h>
30
31 #include <dpl/exception.h>
32 #include <dpl/serialization.h>
33 #include <symbol-visibility.h>
34 #include <data-type.h>
35
36 namespace CKM {
37
38 COMMON_API extern char const * const SERVICE_SOCKET_ECHO;
39 COMMON_API extern char const * const SERVICE_SOCKET_CKM_CONTROL;
40 COMMON_API extern char const * const SERVICE_SOCKET_CKM_STORAGE;
41 COMMON_API extern char const * const SERVICE_SOCKET_OCSP;
42 COMMON_API extern char const * const SERVICE_SOCKET_ENCRYPTION;
43
44 enum class ControlCommand : int {
45     UNLOCK_USER_KEY,
46     LOCK_USER_KEY,
47     REMOVE_USER_DATA,
48     CHANGE_USER_PASSWORD,
49     RESET_USER_PASSWORD,
50     REMOVE_APP_DATA,
51     UPDATE_CC_MODE,
52     SET_PERMISSION
53 };
54
55 enum class LogicCommand : int {
56     GET,
57     GET_LIST,
58     SAVE,
59     REMOVE,
60     CREATE_KEY_AES,
61     CREATE_KEY_PAIR,
62     GET_CHAIN_CERT,
63     GET_CHAIN_ALIAS,
64     CREATE_SIGNATURE,
65     VERIFY_SIGNATURE,
66     SET_PERMISSION,
67     SAVE_PKCS12,
68     GET_PKCS12
69 };
70
71 enum class EncryptionCommand : int {
72     ENCRYPT,
73     DECRYPT
74 };
75
76 // (client side) Alias = (service side) Label::Name
77 COMMON_API extern char const * const LABEL_NAME_SEPARATOR;
78 COMMON_API extern char const * const LABEL_SYSTEM_DB;
79 typedef std::string Name;
80 typedef std::vector<std::pair<Label, Name> > LabelNameVector;
81
82 class IStream;
83
84 struct COMMON_API PolicySerializable : public Policy, ISerializable {
85     PolicySerializable() {};
86     explicit PolicySerializable(const Policy &policy) : Policy(policy) {}
87     explicit PolicySerializable(IStream &stream) {
88         Deserialization::Deserialize(stream, password);
89         Deserialization::Deserialize(stream, extractable);
90     }
91     void Serialize(IStream &stream) const {
92         Serialization::Serialize(stream, password);
93         Serialization::Serialize(stream, extractable);
94     }
95 };
96
97 struct COMMON_API PKCS12Serializable : public PKCS12Impl, ISerializable {
98     PKCS12Serializable();
99     explicit PKCS12Serializable(const PKCS12 &);
100     explicit PKCS12Serializable(IStream &);
101     PKCS12Serializable(
102             const KeyShPtr &privKey,
103             const CertificateShPtr &cert,
104             const CertificateShPtrVector &chainCerts);
105     void Serialize(IStream &) const;
106 };
107
108 struct COMMON_API CryptoAlgorithmSerializable : public CryptoAlgorithm, ISerializable {
109     DECLARE_EXCEPTION_TYPE(Exception, Base);
110     DECLARE_EXCEPTION_TYPE(Exception, UnsupportedParam);
111
112     CryptoAlgorithmSerializable();
113     explicit CryptoAlgorithmSerializable(const CryptoAlgorithm &);
114     explicit CryptoAlgorithmSerializable(IStream &);
115
116     void Serialize(IStream &) const;
117 };
118
119 } // namespace CKM
120