summaryrefslogtreecommitdiff
path: root/libsylph/masterpassword.c
diff options
context:
space:
mode:
Diffstat (limited to 'libsylph/masterpassword.c')
-rw-r--r--libsylph/masterpassword.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/libsylph/masterpassword.c b/libsylph/masterpassword.c
index d240a7a..23e8f2f 100644
--- a/libsylph/masterpassword.c
+++ b/libsylph/masterpassword.c
@@ -48,6 +48,15 @@ void unload_master_password(void) {
48 48
49} 49}
50 50
51gint mpes_string_prefix(const gchar *str) {
52
53 /* this function will be expanded in time as the format changes */
54 if (g_str_has_prefix(str, "mpes1:"))
55 return 6;
56 return 0;
57
58}
59
51gboolean master_password_active(void) { 60gboolean master_password_active(void) {
52 61
53#if USE_SSL 62#if USE_SSL
@@ -59,38 +68,40 @@ gboolean master_password_active(void) {
59 68
60} 69}
61 70
62gchar *decrypt_with_master_password(gchar *str) { 71gchar *decrypt_with_master_password(const gchar *str) {
63 72
64#if USE_SSL 73#if USE_SSL
65 gchar *new_str; 74 gchar *new_str;
75 gint str_prefix;
66 76
67 if ((!str) || (!master_password_active())) 77 if ((!str) || (!master_password_active()))
68 return str; /* do nothing */ 78 return g_strdup(str);
69 79
80 str_prefix = mpes_string_prefix(str);
70 if (decrypt_data(&new_str, 81 if (decrypt_data(&new_str,
71 str, 82 str + str_prefix,
72 master_password, 83 master_password,
73 strlen(str)) != RC_OK) { 84 strlen(str) - str_prefix) != RC_OK) {
74 OPENSSL_cleanse(new_str, strlen(new_str)); 85 OPENSSL_cleanse(new_str, strlen(new_str));
75 g_free(new_str); 86 g_free(new_str);
76 return str; 87 return g_strdup(str);
77 } 88 }
78 89
79 return new_str; 90 return new_str;
80#else 91#else
81 return str; /* do nothing */ 92 return g_strdup(str);
82#endif 93#endif
83 94
84} 95}
85 96
86gchar *encrypt_with_master_password(gchar *str) { 97gchar *encrypt_with_master_password(const gchar *str) {
87 98
88#if USE_SSL 99#if USE_SSL
89 gchar *new_str; 100 gchar *new_str;
90 gint length_encrypted; 101 gint length_encrypted;
91 102
92 if ((!str) || (!master_password_active())) 103 if ((!str) || (!master_password_active()))
93 return str; /* do nothing */ 104 return g_strdup(str);
94 105
95 if (encrypt_data(&new_str, 106 if (encrypt_data(&new_str,
96 &length_encrypted, 107 &length_encrypted,
@@ -101,12 +112,12 @@ gchar *encrypt_with_master_password(gchar *str) {
101 TRUE) != RC_OK) { 112 TRUE) != RC_OK) {
102 OPENSSL_cleanse(new_str, strlen(new_str)); 113 OPENSSL_cleanse(new_str, strlen(new_str));
103 g_free(new_str); 114 g_free(new_str);
104 return str; 115 return g_strdup(str);
105 } 116 }
106 117
107 return new_str; 118 return new_str;
108#else 119#else
109 return str; /* do nothing */ 120 return g_strdup(str);
110#endif 121#endif
111 122
112} 123}