64ba04f3f6e5bf673c052ed03250e498c903ed70
[platform/core/security/ode.git] / lib / ode / external-encryption.cpp
1 /*
2  *  Copyright (c) 2015 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
17 #include "debug.h"
18 #include "external-encryption.h"
19
20 #include "client.h"
21 #include "rmi/external-encryption.h"
22
23 using namespace ode;
24
25 int ode_external_encryption_mount(const char* password)
26 {
27         RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
28
29         ODEContext client;
30         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
31         ExternalEncryption external = client.createInterface<ExternalEncryption>();
32
33         return external.mount(password);
34 }
35
36 int ode_external_encryption_umount()
37 {
38         ODEContext client;
39         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
40         ExternalEncryption external = client.createInterface<ExternalEncryption>();
41
42         return external.umount();
43 }
44
45 int ode_external_encryption_encrypt(const char* password, unsigned int options)
46 {
47         RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
48
49         ODEContext client;
50         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
51         ExternalEncryption external = client.createInterface<ExternalEncryption>();
52
53         return external.encrypt(password, options);
54 }
55
56 int ode_external_encryption_decrypt(const char* password)
57 {
58         RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
59
60         ODEContext client;
61         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
62         ExternalEncryption external = client.createInterface<ExternalEncryption>();
63
64         return external.decrypt(password);
65 }
66
67 int ode_external_encryption_is_password_initialized(bool* result)
68 {
69         RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
70
71         ODEContext client;
72         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
73         ExternalEncryption external = client.createInterface<ExternalEncryption>();
74         int ret = external.isPasswordInitialized();
75
76         RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
77
78         *result = ret;
79         return ODE_ERROR_NONE;
80 }
81
82 int ode_external_encryption_init_password(const char* password)
83 {
84         RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
85
86         ODEContext client;
87         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
88         ExternalEncryption external = client.createInterface<ExternalEncryption>();
89
90         return external.initPassword(password);
91 }
92
93 int ode_external_encryption_clean_password(const char* password)
94 {
95         RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
96
97         ODEContext client;
98         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
99         ExternalEncryption external = client.createInterface<ExternalEncryption>();
100
101         return external.cleanPassword(password);
102 }
103
104 int ode_external_encryption_change_password(const char* old_password,
105                                                                                         const char* new_password)
106 {
107         RET_ON_FAILURE(old_password, ODE_ERROR_INVALID_PARAMETER);
108         RET_ON_FAILURE(new_password, ODE_ERROR_INVALID_PARAMETER);
109
110         ODEContext client;
111         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
112         ExternalEncryption external = client.createInterface<ExternalEncryption>();
113
114         return external.changePassword(old_password, new_password);
115 }
116
117 int ode_external_encryption_verify_password(const char* password, bool* result)
118 {
119         RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
120         RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
121
122         ODEContext client;
123         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
124         ExternalEncryption external = client.createInterface<ExternalEncryption>();
125         int ret = external.verifyPassword(password);
126
127         RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
128
129         *result = ret;
130         return ODE_ERROR_NONE;
131 }
132
133 int ode_external_encryption_get_state(int* state)
134 {
135         RET_ON_FAILURE(state, ODE_ERROR_INVALID_PARAMETER);
136
137         ODEContext client;
138         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
139         ExternalEncryption external = client.createInterface<ExternalEncryption>();
140         int ret = external.getState();
141
142         RET_ON_FAILURE(ret >= 0, ODE_ERROR_INVALID_PARAMETER);
143
144         *state = ret;
145         return ODE_ERROR_NONE;
146 }
147
148 int ode_external_encryption_get_supported_options(unsigned int* options)
149 {
150         RET_ON_FAILURE(options, ODE_ERROR_INVALID_PARAMETER);
151
152         ODEContext client;
153         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
154         ExternalEncryption external = client.createInterface<ExternalEncryption>();
155         *options = external.getSupportedOptions();
156         return ODE_ERROR_NONE;
157 }