Make CryptoAlgorithm copyable.
[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
43 enum class ControlCommand : int {
44     UNLOCK_USER_KEY,
45     LOCK_USER_KEY,
46     REMOVE_USER_DATA,
47     CHANGE_USER_PASSWORD,
48     RESET_USER_PASSWORD,
49     REMOVE_APP_DATA,
50     UPDATE_CC_MODE,
51     SET_PERMISSION
52     // for backward compatibility append new at the end
53 };
54
55 enum class LogicCommand : int {
56     GET,
57     GET_LIST,
58     SAVE,
59     REMOVE,
60     CREATE_KEY_PAIR_RSA,
61     CREATE_KEY_PAIR_ECDSA,
62     GET_CHAIN_CERT,
63     GET_CHAIN_ALIAS,
64     CREATE_SIGNATURE,
65     VERIFY_SIGNATURE,
66     CREATE_KEY_PAIR_DSA,
67     SET_PERMISSION,
68     SAVE_PKCS12,
69     GET_PKCS12
70     // for backward compatibility append new at the end
71 };
72
73 // (client side) Alias = (service side) Label::Name
74 COMMON_API extern char const * const LABEL_NAME_SEPARATOR;
75 COMMON_API extern char const * const LABEL_SYSTEM_DB;
76 typedef std::string Name;
77 typedef std::vector<std::pair<Label, Name> > LabelNameVector;
78
79 class IStream;
80
81 struct COMMON_API PolicySerializable : public Policy, ISerializable {
82     PolicySerializable() {};
83     explicit PolicySerializable(const Policy &policy) : Policy(policy) {}
84     explicit PolicySerializable(IStream &stream) {
85         Deserialization::Deserialize(stream, password);
86         Deserialization::Deserialize(stream, extractable);
87     }
88     void Serialize(IStream &stream) const {
89         Serialization::Serialize(stream, password);
90         Serialization::Serialize(stream, extractable);
91     }
92 };
93
94 struct COMMON_API PKCS12Serializable : public PKCS12Impl, ISerializable {
95     PKCS12Serializable();
96     explicit PKCS12Serializable(const PKCS12 &);
97     explicit PKCS12Serializable(IStream &);
98     PKCS12Serializable(
99             const KeyShPtr &privKey,
100             const CertificateShPtr &cert,
101             const CertificateShPtrVector &chainCerts);
102     void Serialize(IStream &) const;
103 };
104
105 struct COMMON_API CryptoAlgorithmSerializable : public CryptoAlgorithm, ISerializable {
106     DECLARE_EXCEPTION_TYPE(Exception, Base);
107     DECLARE_EXCEPTION_TYPE(Exception, UnsupportedParam);
108
109     CryptoAlgorithmSerializable();
110     explicit CryptoAlgorithmSerializable(const CryptoAlgorithm &);
111     explicit CryptoAlgorithmSerializable(IStream &);
112
113     void Serialize(IStream &) const;
114 };
115
116 } // namespace CKM
117