2 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Bumjin Im <bj.im@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
19 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @author Zofia Abramowska (z.abramowska@samsung.com)
22 * @brief List of all protocols supported by Central Key Manager.
25 #include <protocols.h>
27 #include <dpl/serialization.h>
28 #include <ckm/ckm-type.h>
32 char const * const SERVICE_SOCKET_ECHO = "/tmp/.central-key-manager-echo.sock";
33 char const * const SERVICE_SOCKET_CKM_CONTROL = "/tmp/.central-key-manager-api-control.sock";
34 char const * const SERVICE_SOCKET_CKM_STORAGE = "/tmp/.central-key-manager-api-storage.sock";
35 char const * const SERVICE_SOCKET_OCSP = "/tmp/.central-key-manager-api-ocsp.sock";
36 char const * const SERVICE_SOCKET_ENCRYPTION = "/tmp/.central-key-manager-api-encryption.sock";
37 char const * const LABEL_NAME_SEPARATOR = " ";
38 char const * const LABEL_SYSTEM_DB = "/";
41 PKCS12Serializable::PKCS12Serializable() {}
42 PKCS12Serializable::PKCS12Serializable(const PKCS12 &pkcs)
46 PKCS12Serializable::PKCS12Serializable(IStream &stream)
50 Deserialization::Deserialize(stream, numKeys);
54 Deserialization::Deserialize(stream, keyType);
55 Deserialization::Deserialize(stream, keyData);
56 m_pkey = CKM::Key::create(keyData);
61 Deserialization::Deserialize(stream, numCerts);
64 Deserialization::Deserialize(stream, certData);
65 m_cert = CKM::Certificate::create(certData, DataFormat::FORM_DER);
70 Deserialization::Deserialize(stream, num_CA);
71 for(size_t i=0; i<num_CA; i++)
74 Deserialization::Deserialize(stream, CAcertData);
75 m_ca.push_back(CKM::Certificate::create(CAcertData, DataFormat::FORM_DER));
78 PKCS12Serializable::PKCS12Serializable(const KeyShPtr &privKey, const CertificateShPtr &cert, const CertificateShPtrVector &chainCerts)
85 void PKCS12Serializable::Serialize(IStream &stream) const
88 Key *keyPtr = getKey().get();
89 bool isAnyKeyPresent = (getKey().get()!=NULL);
91 // logics if PKCS is correct or not is on the service side.
92 // sending number of keys and certificates to allow proper parsing on the service side.
93 // (what if no key or cert present? attempt to deserialize a not present key/cert would
94 // throw an error and close the connection).
95 Serialization::Serialize(stream, static_cast<size_t>(isAnyKeyPresent?1:0));
97 Serialization::Serialize(stream, DataType(keyPtr->getType()));
98 Serialization::Serialize(stream, keyPtr->getDER());
101 bool isAnyCertPresent = (getCertificate().get()!=NULL);
102 Serialization::Serialize(stream, static_cast<size_t>(isAnyCertPresent?1:0));
103 if(isAnyCertPresent) {
104 Serialization::Serialize(stream, getCertificate().get()->getDER());
108 Serialization::Serialize(stream, getCaCertificateShPtrVector().size());
109 for(auto it : getCaCertificateShPtrVector())
110 Serialization::Serialize(stream, it->getDER());
114 CryptoAlgorithmSerializable::CryptoAlgorithmSerializable() {}
115 CryptoAlgorithmSerializable::CryptoAlgorithmSerializable(const CryptoAlgorithm &algo) :
116 CryptoAlgorithm(algo)
120 CryptoAlgorithmSerializable::CryptoAlgorithmSerializable(IStream &stream)
123 Deserializer<size_t>::Deserialize(stream, plen);
129 Deserializer<int>::Deserialize(stream, tmpName);
130 name = static_cast<ParamName>(tmpName);
132 case ParamName::ED_IV:
133 case ParamName::ED_AAD:
134 case ParamName::ED_LABEL:
135 Deserializer<RawBuffer>::Deserialize(stream, buffer);
136 setParam(name, buffer);
139 case ParamName::ALGO_TYPE:
140 case ParamName::ED_CTR_LEN:
141 case ParamName::ED_TAG_LEN:
142 case ParamName::GEN_KEY_LEN:
143 case ParamName::GEN_EC:
144 case ParamName::SV_HASH_ALGO:
145 case ParamName::SV_RSA_PADDING:
146 Deserializer<uint64_t>::Deserialize(stream, integer);
147 setParam(name, integer);
151 ThrowMsg(UnsupportedParam, "Unsupported param name");
157 void CryptoAlgorithmSerializable::Serialize(IStream &stream) const
159 Serializer<size_t>::Serialize(stream, m_params.size());
160 for(const auto& it : m_params) {
161 Serializer<int>::Serialize(stream, static_cast<int>(it.first));
164 if (it.second->getInt(integer))
165 Serializer<uint64_t>::Serialize(stream, integer);
166 else if (it.second->getBuffer(buffer))
167 Serializer<RawBuffer>::Serialize(stream, buffer);
169 ThrowMsg(UnsupportedParam, "Unsupported param type");