Add get/set encryption state using vconf
[platform/core/security/ode.git] / lib / ode / internal-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 "internal-encryption.h"
19
20 #include "client.h"
21 #include "rmi/internal-encryption.h"
22
23 using namespace ode;
24
25 int ode_internal_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         InternalEncryption internal = client.createInterface<InternalEncryption>();
32
33         return internal.mount(password);
34 }
35
36 int ode_internal_encryption_umount()
37 {
38         ODEContext client;
39         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
40         InternalEncryption internal = client.createInterface<InternalEncryption>();
41
42         return internal.umount();
43 }
44
45 int ode_internal_encryption_encrypt(const char* password)
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         InternalEncryption internal = client.createInterface<InternalEncryption>();
52
53         return internal.encrypt(password);
54 }
55
56 int ode_internal_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         InternalEncryption internal = client.createInterface<InternalEncryption>();
63
64         return internal.decrypt(password);
65 }
66
67 int ode_internal_encryption_change_password(const char* old_password,
68                                                                                         const char* new_password)
69 {
70         RET_ON_FAILURE(old_password, ODE_ERROR_INVALID_PARAMETER);
71         RET_ON_FAILURE(new_password, ODE_ERROR_INVALID_PARAMETER);
72
73         ODEContext client;
74         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
75         InternalEncryption internal = client.createInterface<InternalEncryption>();
76
77         return internal.changePassword(old_password, new_password);
78 }
79
80 int ode_internal_encryption_get_state(int* state)
81 {
82         RET_ON_FAILURE(state, ODE_ERROR_INVALID_PARAMETER);
83
84         ODEContext client;
85         RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
86         InternalEncryption internal = client.createInterface<InternalEncryption>();
87         int ret = internal.getState();
88
89         RET_ON_FAILURE(ret < 0, ODE_ERROR_INVALID_PARAMETER);
90
91         *state = ret;
92         return ODE_ERROR_NONE;
93 }