2 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
18 * @author Zofia Abramowska (z.abramowska@samsung.com)
20 * @brief This file contains list of all protocols suported by Central
28 #include <ckm/ckm-type.h>
29 #include <pkcs12-impl.h>
31 #include <dpl/exception.h>
32 #include <dpl/serialization.h>
33 #include <symbol-visibility.h>
37 COMMON_API extern char const * const SERVICE_SOCKET_ECHO;
38 COMMON_API extern char const * const SERVICE_SOCKET_CKM_CONTROL;
39 COMMON_API extern char const * const SERVICE_SOCKET_CKM_STORAGE;
40 COMMON_API extern char const * const SERVICE_SOCKET_OCSP;
42 enum class ControlCommand : int {
51 // for backward compatibility append new at the end
54 enum class LogicCommand : int {
60 CREATE_KEY_PAIR_ECDSA,
69 // for backward compatibility append new at the end
72 class COMMON_API DataType {
76 DECLARE_EXCEPTION_TYPE(CKM::Exception, Base)
77 DECLARE_EXCEPTION_TYPE(Base, OutOfRange)
108 // Special types to support database,
109 DB_KEY_FIRST = KEY_RSA_PUBLIC,
110 DB_KEY_LAST = KEY_AES,
111 DB_CHAIN_FIRST = CHAIN_CERT_0,
112 DB_CHAIN_LAST = CHAIN_CERT_15,
113 DB_FIRST = KEY_RSA_PUBLIC,
114 DB_LAST = CHAIN_CERT_15,
118 : m_dataType(BINARY_DATA)
124 if (!isInRange(data))
125 ThrowMsg(Exception::OutOfRange, "Invalid conversion from DataType to DBDataType");
128 explicit DataType(KeyType key) {
130 case KeyType::KEY_RSA_PUBLIC: m_dataType = DataType::KEY_RSA_PUBLIC; break;
131 case KeyType::KEY_RSA_PRIVATE: m_dataType = DataType::KEY_RSA_PRIVATE; break;
132 case KeyType::KEY_DSA_PUBLIC: m_dataType = DataType::KEY_DSA_PUBLIC; break;
133 case KeyType::KEY_DSA_PRIVATE: m_dataType = DataType::KEY_DSA_PRIVATE; break;
134 case KeyType::KEY_ECDSA_PUBLIC: m_dataType = DataType::KEY_ECDSA_PUBLIC; break;
135 case KeyType::KEY_ECDSA_PRIVATE: m_dataType = DataType::KEY_ECDSA_PRIVATE; break;
136 case KeyType::KEY_AES: m_dataType = DataType::KEY_AES; break;
138 ThrowMsg(Exception::OutOfRange, "Invalid conversion from KeyType to DBDataType");
142 explicit DataType(int data)
143 : m_dataType(static_cast<Type>(data))
145 if (!isInRange(data))
146 ThrowMsg(Exception::OutOfRange, "Invalid conversion from int to DBDataType");
149 DataType(const DataType &) = default;
150 DataType& operator=(const DataType &) = default;
152 operator int () const {
153 return static_cast<int>(m_dataType);
156 operator KeyType () const {
158 case DataType::KEY_RSA_PUBLIC: return KeyType::KEY_RSA_PUBLIC;
159 case DataType::KEY_RSA_PRIVATE: return KeyType::KEY_RSA_PRIVATE;
160 case DataType::KEY_DSA_PUBLIC: return KeyType::KEY_DSA_PUBLIC;
161 case DataType::KEY_DSA_PRIVATE: return KeyType::KEY_DSA_PRIVATE;
162 case DataType::KEY_ECDSA_PRIVATE: return KeyType::KEY_ECDSA_PRIVATE;
163 case DataType::KEY_ECDSA_PUBLIC: return KeyType::KEY_ECDSA_PUBLIC;
164 case DataType::KEY_AES: return KeyType::KEY_AES;
166 ThrowMsg(Exception::OutOfRange, "Invalid conversion from DBDataType to KeyType");
170 bool operator==(const DataType &second) const {
171 return m_dataType == second.m_dataType;
175 if (DB_KEY_FIRST <= m_dataType && DB_KEY_LAST >= m_dataType)
180 bool isChainCert() const {
181 if (DB_CHAIN_FIRST <= m_dataType && DB_CHAIN_LAST >= m_dataType)
186 static DataType getChainDatatype(unsigned int index)
188 DataType result(static_cast<int>(index) + DB_CHAIN_FIRST);
190 if ( !result.isChainCert() )
191 ThrowMsg(Exception::OutOfRange, "Certificate number is out of range");
196 bool isKeyPrivate() const {
197 switch (m_dataType) {
198 case KEY_RSA_PRIVATE:
199 case KEY_DSA_PRIVATE:
200 case KEY_ECDSA_PRIVATE:
207 bool isKeyPublic() const {
208 switch (m_dataType) {
211 case KEY_ECDSA_PUBLIC:
218 bool isCertificate() const {
219 return m_dataType == CERTIFICATE;
222 bool isBinaryData() const {
223 return m_dataType == BINARY_DATA;
226 static bool isInRange(int data) {
227 if (data < static_cast<int>(DB_FIRST))
229 if (data > static_cast<int>(DB_LAST))
234 // it's not virtual for a reason!
241 // (client side) Alias = (service side) Label::Name
242 COMMON_API extern char const * const LABEL_NAME_SEPARATOR;
243 typedef std::string Name;
244 typedef std::vector<std::pair<Label, Name> > LabelNameVector;
248 struct COMMON_API PolicySerializable : public Policy, ISerializable {
249 PolicySerializable() {};
250 explicit PolicySerializable(const Policy &policy) : Policy(policy) {}
251 explicit PolicySerializable(IStream &stream) {
252 Deserialization::Deserialize(stream, password);
253 Deserialization::Deserialize(stream, extractable);
255 void Serialize(IStream &stream) const {
256 Serialization::Serialize(stream, password);
257 Serialization::Serialize(stream, extractable);
261 struct COMMON_API PKCS12Serializable : public PKCS12Impl, ISerializable {
262 PKCS12Serializable();
263 explicit PKCS12Serializable(const PKCS12 &);
264 explicit PKCS12Serializable(IStream &);
266 const KeyShPtr &privKey,
267 const CertificateShPtr &cert,
268 const CertificateShPtrVector &chainCerts);
269 void Serialize(IStream &) const;