Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.3.0 #333

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(OTPClient VERSION "3.2.2" LANGUAGES "C")
project(OTPClient VERSION "3.3.0" LANGUAGES "C")
include(GNUInstallDirs)

configure_file("src/common/version.h.in" "version.h")
Expand Down Expand Up @@ -45,7 +45,7 @@ endif()
find_package(PkgConfig REQUIRED)
find_package(Protobuf 3.6.0 REQUIRED)
find_package(Gcrypt 1.8.0 REQUIRED)
pkg_check_modules(COTP REQUIRED cotp>=2.0.0)
pkg_check_modules(COTP REQUIRED cotp>=3.0.0)
pkg_check_modules(PNG REQUIRED libpng>=1.6.30)
pkg_check_modules(JANSSON REQUIRED jansson>=2.12)
pkg_check_modules(ZBAR REQUIRED zbar>=0.20)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Highly secure and easy to use GTK+ software for two-factor authentication that s
| jansson | 2.12 |
| libgcrypt | 1.8.0 |
| libpng | 1.6.30 |
| [libcotp](https://github.com/paolostivanin/libcotp) | 2.0.0 |
| [libcotp](https://github.com/paolostivanin/libcotp) | 3.0.0 |
| zbar | 0.20 |
| protobuf-c | 1.3.0 |
| protobuf | 3.6.0 |
Expand Down
9 changes: 9 additions & 0 deletions data/com.github.paolostivanin.OTPClient.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@
</content_rating>

<releases>
<release version="3.3.0" date="2024-01-08">
<description>
<p>OTPClient 3.3.0 brings the following changes:</p>
<ul>
<li>NEW: set background to red when delete mode is entered (#323)</li>
<li>FIX: handling of base32 string (#328)</li>
</ul>
</description>
</release>
<release version="3.2.1" date="2023-10-31">
<description>
<p>OTPClient 3.2.1 fixes a couple of issues.</p>
Expand Down
22 changes: 16 additions & 6 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,21 @@ del_data_cb (GtkToggleButton *btn,
{
AppData *app_data = (AppData *)user_data;

GtkStyleContext *gsc = gtk_widget_get_style_context (GTK_WIDGET(btn));
GtkStyleContext *gsc_btn = gtk_widget_get_style_context (GTK_WIDGET(btn));
GtkStyleContext *gsc_tv = gtk_widget_get_style_context (GTK_WIDGET(app_data->tree_view));

GtkTreeSelection *tree_selection = gtk_tree_view_get_selection (app_data->tree_view);

if (gtk_toggle_button_get_active (btn)) {
app_data->css_provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (app_data->css_provider, "#delbtn { background: #ff0033; }", -1, NULL);
gtk_style_context_add_provider (gsc, GTK_STYLE_PROVIDER(app_data->css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
app_data->delbtn_css_provider = gtk_css_provider_new ();
app_data->tv_css_provider = gtk_css_provider_new ();

gtk_css_provider_load_from_data (app_data->delbtn_css_provider, "#delbtn { background: #970000; }", -1, NULL);
gtk_css_provider_load_from_data (app_data->tv_css_provider, "#tv { background: #970000; }", -1, NULL);

gtk_style_context_add_provider (gsc_btn, GTK_STYLE_PROVIDER(app_data->delbtn_css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
gtk_style_context_add_provider (gsc_tv, GTK_STYLE_PROVIDER(app_data->tv_css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER);

const gchar *msg = _("You just entered the deletion mode. You can now click on the row(s) you'd like to delete.\n"
"Please note that once a row has been deleted, <b>it's impossible to recover the associated data.</b>");

Expand All @@ -693,8 +701,10 @@ del_data_cb (GtkToggleButton *btn,
gtk_toggle_button_set_active (btn, FALSE);
}
} else {
gtk_style_context_remove_provider (gsc, GTK_STYLE_PROVIDER(app_data->css_provider));
g_object_unref (app_data->css_provider);
gtk_style_context_remove_provider (gsc_btn, GTK_STYLE_PROVIDER(app_data->delbtn_css_provider));
gtk_style_context_remove_provider (gsc_tv, GTK_STYLE_PROVIDER(app_data->tv_css_provider));
g_object_unref (app_data->delbtn_css_provider);
g_object_unref (app_data->tv_css_provider);
g_signal_handlers_disconnect_by_func (app_data->tree_view, delete_rows_cb, app_data);
g_signal_connect (app_data->tree_view, "row-activated", G_CALLBACK(row_selected_cb), app_data);
}
Expand Down
3 changes: 2 additions & 1 deletion src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ typedef struct app_data_t {
gboolean auto_lock;
gint inactivity_timeout;

GtkCssProvider *css_provider;
GtkCssProvider *delbtn_css_provider;
GtkCssProvider *tv_css_provider;

GNotification *notification;

Expand Down
91 changes: 43 additions & 48 deletions src/parse-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <string.h>
#include <jansson.h>
#include <gcrypt.h>
#include <cotp.h>
#include "db-misc.h"
#include "manual-add-cb.h"
#include "gquarks.h"
Expand All @@ -10,27 +11,26 @@
#include "common/common.h"


static gboolean is_input_valid (GtkWidget *dialog,
const gchar *acc_label,
const gchar *acc_iss,
const gchar *secret,
const gchar *digits,
const gchar *period,
gboolean period_active,
const gchar *counter,
gboolean counter_active);
static gboolean is_input_valid (GtkWidget *dialog,
const gchar *acc_label,
const gchar *acc_iss,
const gchar *secret,
const gchar *digits,
const gchar *period,
gboolean period_active,
const gchar *counter,
gboolean counter_active);

static gboolean str_is_only_num_or_alpha (const gchar *string);
static gboolean is_str_valid (const gchar *string,
gboolean (*validation_func)(gunichar));

static gboolean str_is_only_num (const gchar *string);

static json_t *get_json_obj (Widgets *widgets,
const gchar *acc_label,
const gchar *acc_iss,
const gchar *acc_key,
const gchar *digits,
const gchar *period,
const gchar *counter);
static json_t *get_json_obj (Widgets *widgets,
const gchar *acc_label,
const gchar *acc_iss,
const gchar *acc_key,
const gchar *digits,
const gchar *period,
const gchar *counter);


gboolean
Expand All @@ -39,20 +39,20 @@ parse_user_data (Widgets *widgets,
{
json_t *obj;

const gchar *acc_label = gtk_entry_get_text (GTK_ENTRY (widgets->label_entry));
const gchar *acc_iss = gtk_entry_get_text (GTK_ENTRY (widgets->iss_entry));
const gchar *acc_key = gtk_entry_get_text (GTK_ENTRY (widgets->sec_entry));
const gchar *digits = gtk_entry_get_text (GTK_ENTRY (widgets->digits_entry));
const gchar *period = gtk_entry_get_text (GTK_ENTRY (widgets->period_entry));
const gchar *counter = gtk_entry_get_text (GTK_ENTRY (widgets->counter_entry));
const gchar *acc_label = gtk_entry_get_text (GTK_ENTRY(widgets->label_entry));
const gchar *acc_iss = gtk_entry_get_text (GTK_ENTRY(widgets->iss_entry));
const gchar *acc_key = gtk_entry_get_text (GTK_ENTRY(widgets->sec_entry));
const gchar *digits = gtk_entry_get_text (GTK_ENTRY(widgets->digits_entry));
const gchar *period = gtk_entry_get_text (GTK_ENTRY(widgets->period_entry));
const gchar *counter = gtk_entry_get_text (GTK_ENTRY(widgets->counter_entry));
gboolean period_active = gtk_widget_get_sensitive (widgets->period_entry);
gboolean counter_active = gtk_widget_get_sensitive (widgets->counter_entry);
gchar *acc_key_trimmed = g_trim_whitespace (acc_key);
if (is_input_valid (widgets->dialog, acc_label, acc_iss, acc_key_trimmed, digits, period, period_active, counter, counter_active)) {
obj = get_json_obj (widgets, acc_label, acc_iss, acc_key_trimmed, digits, period, counter);
guint32 hash = json_object_get_hash (obj);
if (g_slist_find_custom (db_data->objects_hash, GUINT_TO_POINTER (hash), check_duplicate) == NULL) {
db_data->objects_hash = g_slist_append (db_data->objects_hash, g_memdupX (&hash, sizeof (guint)));
if (g_slist_find_custom (db_data->objects_hash, GUINT_TO_POINTER(hash), check_duplicate) == NULL) {
db_data->objects_hash = g_slist_append (db_data->objects_hash, g_memdupX(&hash, sizeof (guint)));
db_data->data_to_add = g_slist_append (db_data->data_to_add, obj);
} else {
g_print ("[INFO] Duplicate element not added\n");
Expand Down Expand Up @@ -87,28 +87,28 @@ is_input_valid (GtkWidget *dialog,
g_free (msg);
return FALSE;
}
if (!str_is_only_num_or_alpha (secret)) {
gchar *msg = g_strconcat ("Secret can contain only characters from the english alphabet and digits. Entry with label '",
if (!is_string_valid_b32 (secret)) {
gchar *msg = g_strconcat ("Secret is not a valid base32 encoded string. Entry with label '",
acc_label, "' will not be added.", NULL);
show_message_dialog (dialog, msg, GTK_MESSAGE_ERROR);
g_free (msg);
return FALSE;
}
if (!str_is_only_num (digits) || g_ascii_strtoll (digits, NULL, 10) < 4 || g_ascii_strtoll (digits, NULL, 10) > 10) {
if (!is_str_valid (digits, g_unichar_isdigit) || g_ascii_strtoll (digits, NULL, 10) < 4 || g_ascii_strtoll (digits, NULL, 10) > 10) {
gchar *msg = g_strconcat ("The digits entry should contain only digits and the value should be between 4 and 10 inclusive.\n"
"Entry with label '", acc_label, "' will not be added.", NULL);
show_message_dialog (dialog, msg, GTK_MESSAGE_ERROR);
g_free (msg);
return FALSE;
}
if (period_active && (!str_is_only_num (period) || g_ascii_strtoll (period, NULL, 10) < 10 || g_ascii_strtoll (period, NULL, 10) > 120)) {
if (period_active && (!is_str_valid (period, g_unichar_isdigit) || g_ascii_strtoll (period, NULL, 10) < 10 || g_ascii_strtoll (period, NULL, 10) > 120)) {
gchar *msg = g_strconcat ("The period entry should contain only digits and the value should be between 10 and 120 (inclusive).\n"
"Entry with label '", acc_label, "' will not be added.", NULL);
show_message_dialog (dialog, msg, GTK_MESSAGE_ERROR);
g_free (msg);
return FALSE;
}
if (counter_active && (!str_is_only_num (counter) || g_ascii_strtoll (counter, NULL, 10) < 1 || g_ascii_strtoll (counter, NULL, 10) == G_MAXINT64)) {
if (counter_active && (!is_str_valid (counter, g_unichar_isdigit) || g_ascii_strtoll (counter, NULL, 10) < 1 || g_ascii_strtoll (counter, NULL, 10) == G_MAXINT64)) {
gchar *msg = g_strconcat ("The counter entry should contain only digits and the value should be between 1 and G_MAXINT64-1 (inclusive).\n"
"Entry with label '", acc_label, "' will not be added.", NULL);
show_message_dialog (dialog, msg, GTK_MESSAGE_ERROR);
Expand All @@ -121,27 +121,22 @@ is_input_valid (GtkWidget *dialog,


static gboolean
str_is_only_num_or_alpha (const gchar *string)
is_str_valid (const gchar *string,
gboolean (*validation_func)(gunichar))
{
size_t s_len = g_utf8_strlen (string, -1);
for (gint i = 0; i < s_len; i++) {
if (!g_ascii_isalnum (string[i])) {
return FALSE;
}
if (string == NULL || !g_utf8_validate (string, -1, NULL)) {
return FALSE;
}
return TRUE;
}

gsize s_len = g_utf8_strlen (string, -1);

static gboolean
str_is_only_num (const gchar *string)
{
size_t s_len = g_utf8_strlen (string, -1);
for (gint i = 0; i < s_len; i++) {
if (!g_ascii_isdigit (string[i])) {
for (gsize i = 0; i < s_len; i++) {
gunichar character = g_utf8_get_char (g_utf8_offset_to_pointer (string, (glong)i));
if (!validation_func (character)) {
return FALSE;
}
}

return TRUE;
}

Expand All @@ -155,8 +150,8 @@ get_json_obj (Widgets *widgets,
const gchar *period,
const gchar *counter)
{
gchar *type = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (widgets->otp_cb));
gchar *algo = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (widgets->algo_cb));
gchar *type = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT(widgets->otp_cb));
gchar *algo = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT(widgets->algo_cb));
gint digits_int = (gint)g_ascii_strtoll (digits, NULL, 10);
gint period_int = (gint)g_ascii_strtoll (period, NULL, 10);
gint64 ctr = g_ascii_strtoll (counter, NULL, 10);
Expand Down
3 changes: 2 additions & 1 deletion src/ui/otpclient.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ but not the number of digits and/or the period/counter.</property>
<property name="max-length">255</property>
<property name="visibility">False</property>
<property name="secondary-icon-name">dialog-password-symbolic</property>
<property name="primary-icon-tooltip-text" translatable="yes">Secret</property>
<property name="primary-icon-tooltip-text" translatable="yes">Must be an uppercase base32 string. It may contain spaces. </property>
<property name="placeholder-text" translatable="yes">Secret</property>
<property name="input-purpose">password</property>
</object>
Expand Down Expand Up @@ -2612,6 +2612,7 @@ but not the number of digits and/or the period/counter.</property>
<property name="shadow-type">etched-in</property>
<child>
<object class="GtkTreeView" id="treeview_id">
<property name="name">tv</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
Expand Down
Loading