summaryrefslogtreecommitdiff
path: root/src/manager/common/protocols.h
blob: 4f0fd2c41f3d2620efa3b42604055ee0a944e733 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License
 *
 * @file        protocols.h
 * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
 * @author      Zofia Abramowska (z.abramowska@samsung.com)
 * @version     1.0
 * @brief       This file contains list of all protocols suported by Central
 *              Key Manager.
 */
#pragma once

#include <stdexcept>
#include <string>

#include <ckm/ckm-type.h>
#include <pkcs12-impl.h>

#include <dpl/exception.h>
#include <dpl/serialization.h>
#include <symbol-visibility.h>
#include <data-type.h>

namespace CKM {

COMMON_API extern char const * const SERVICE_SOCKET_ECHO;
COMMON_API extern char const * const SERVICE_SOCKET_CKM_CONTROL;
COMMON_API extern char const * const SERVICE_SOCKET_CKM_STORAGE;
COMMON_API extern char const * const SERVICE_SOCKET_OCSP;
COMMON_API extern char const * const SERVICE_SOCKET_ENCRYPTION;

enum class ControlCommand : int {
    UNLOCK_USER_KEY,
    LOCK_USER_KEY,
    REMOVE_USER_DATA,
    CHANGE_USER_PASSWORD,
    RESET_USER_PASSWORD,
    REMOVE_APP_DATA,
    UPDATE_CC_MODE,
    SET_PERMISSION
};

enum class LogicCommand : int {
    GET,
    GET_LIST,
    SAVE,
    REMOVE,
    CREATE_KEY_AES,
    CREATE_KEY_PAIR,
    GET_CHAIN_CERT,
    GET_CHAIN_ALIAS,
    CREATE_SIGNATURE,
    VERIFY_SIGNATURE,
    SET_PERMISSION,
    SAVE_PKCS12,
    GET_PKCS12
};

enum class EncryptionCommand : int {
    ENCRYPT,
    DECRYPT
};

// (client side) Alias = (service side) Label::Name
COMMON_API extern char const * const LABEL_NAME_SEPARATOR;
COMMON_API extern char const * const LABEL_SYSTEM_DB;
typedef std::string Name;
typedef std::vector<std::pair<Label, Name> > LabelNameVector;

class IStream;

struct COMMON_API PolicySerializable : public Policy, ISerializable {
    PolicySerializable() {};
    explicit PolicySerializable(const Policy &policy) : Policy(policy) {}
    explicit PolicySerializable(IStream &stream) {
        Deserialization::Deserialize(stream, password);
        Deserialization::Deserialize(stream, extractable);
    }
    void Serialize(IStream &stream) const {
        Serialization::Serialize(stream, password);
        Serialization::Serialize(stream, extractable);
    }
};

struct COMMON_API PKCS12Serializable : public PKCS12Impl, ISerializable {
    PKCS12Serializable();
    explicit PKCS12Serializable(const PKCS12 &);
    explicit PKCS12Serializable(IStream &);
    PKCS12Serializable(
            const KeyShPtr &privKey,
            const CertificateShPtr &cert,
            const CertificateShPtrVector &chainCerts);
    void Serialize(IStream &) const;
};

struct COMMON_API CryptoAlgorithmSerializable : public CryptoAlgorithm, ISerializable {
    DECLARE_EXCEPTION_TYPE(Exception, Base);
    DECLARE_EXCEPTION_TYPE(Exception, UnsupportedParam);

    CryptoAlgorithmSerializable();
    explicit CryptoAlgorithmSerializable(const CryptoAlgorithm &);
    explicit CryptoAlgorithmSerializable(IStream &);

    void Serialize(IStream &) const;
};

} // namespace CKM