Revert "Alias is not unique user-wide: (alias, label) pair is unique now."
[platform/core/security/key-manager.git] / src / manager / common / protocols.cpp
1 /*
2  *  Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Bumjin Im <bj.im@samsung.com>
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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
17  *
18  * @file        protocols.cpp
19  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20  * @author      Zofia Abramowska (z.abramowska@samsung.com)
21  * @version     1.0
22  * @brief       List of all protocols supported by Central Key Manager.
23  */
24
25 #include <protocols.h>
26
27 #include <dpl/serialization.h>
28
29 namespace CKM {
30
31 char const * const SERVICE_SOCKET_ECHO = "/tmp/.central-key-manager-echo.sock";
32 char const * const SERVICE_SOCKET_CKM_CONTROL = "/tmp/.central-key-manager-api-control.sock";
33 char const * const SERVICE_SOCKET_CKM_STORAGE = "/tmp/.central-key-manager-api-storage.sock";
34 char const * const SERVICE_SOCKET_OCSP = "/tmp/.central-key-manager-api-ocsp.sock";
35
36 DBDataType toDBDataType(KeyType key) {
37     switch(key) {
38     case KeyType::KEY_RSA_PUBLIC:  return DBDataType::KEY_RSA_PUBLIC;
39     case KeyType::KEY_RSA_PRIVATE: return DBDataType::KEY_RSA_PRIVATE;
40     case KeyType::KEY_DSA_PUBLIC:  return DBDataType::KEY_DSA_PUBLIC;
41     case KeyType::KEY_DSA_PRIVATE: return DBDataType::KEY_DSA_PRIVATE;
42     case KeyType::KEY_ECDSA_PUBLIC: return DBDataType::KEY_ECDSA_PUBLIC;
43     case KeyType::KEY_ECDSA_PRIVATE: return DBDataType::KEY_ECDSA_PRIVATE;
44     case KeyType::KEY_AES: return DBDataType::KEY_AES;
45     default:
46         // TODO
47         throw 1;
48     }
49 }
50
51 KeyType toKeyType(DBDataType dbtype) {
52     switch(dbtype) {
53     case DBDataType::KEY_RSA_PUBLIC: return KeyType::KEY_RSA_PUBLIC;
54     case DBDataType::KEY_RSA_PRIVATE: return KeyType::KEY_RSA_PRIVATE;
55     case DBDataType::KEY_DSA_PUBLIC: return KeyType::KEY_DSA_PUBLIC;
56     case DBDataType::KEY_DSA_PRIVATE: return KeyType::KEY_DSA_PRIVATE;
57     case DBDataType::KEY_ECDSA_PRIVATE: return KeyType::KEY_ECDSA_PRIVATE;
58     case DBDataType::KEY_ECDSA_PUBLIC: return KeyType::KEY_ECDSA_PUBLIC;
59     case DBDataType::KEY_AES: return KeyType::KEY_AES;
60     default:
61         // TODO
62         throw 1;
63     }
64 }
65
66 const char* toDBAccessRight(AccessRight access_right_type) {
67     switch(access_right_type) {
68     case AccessRight::AR_READ:          return "R";
69     case AccessRight::AR_READ_REMOVE:   return "RD";
70     default:
71         // TODO
72         throw 1;
73     }
74 }
75
76 PolicySerializable::PolicySerializable()
77 {}
78
79
80 PolicySerializable::PolicySerializable(const Policy &policy)
81   : Policy(policy)
82 {}
83
84 PolicySerializable::PolicySerializable(IStream &stream) {
85     Deserialization::Deserialize(stream, password);
86     Deserialization::Deserialize(stream, extractable);
87 }
88
89 void PolicySerializable::Serialize(IStream &stream) const {
90     Serialization::Serialize(stream, password);
91     Serialization::Serialize(stream, extractable);
92 }
93
94 } // namespace CKM
95