[gcr] gcr: Expose GcrSecureEntryBuffer as a public class
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcr] gcr: Expose GcrSecureEntryBuffer as a public class
- Date: Mon, 19 Dec 2011 07:33:53 +0000 (UTC)
commit 23ab85ea7e8844104ea7b700f276f9e494ad449e
Author: Stef Walter <stefw collabora co uk>
Date: Thu Oct 27 12:53:46 2011 +0200
gcr: Expose GcrSecureEntryBuffer as a public class
* This is a GtkEntryBuffer that uses non-pageable memory for the
buffer, to be used with passwords and secrets.
docs/reference/gcr/gcr-docs.sgml | 1 +
docs/reference/gcr/gcr-sections.txt | 17 +++
docs/reference/gcr/gcr.types | 1 +
egg/Makefile.am | 8 --
egg/egg-entry-buffer.h | 59 ----------
gcr/Makefile.am | 3 +-
gcr/gcr-failure-renderer.c | 5 +-
gcr/gcr-pkcs11-import-dialog.c | 4 +-
.../gcr-secure-entry-buffer.c | 121 ++++++++++++-------
gcr/gcr-secure-entry-buffer.h | 63 ++++++++++
gcr/gcr-unlock-renderer.c | 5 +-
gcr/gcr.h | 1 +
gcr/tests/Makefile.am | 1 -
13 files changed, 167 insertions(+), 122 deletions(-)
---
diff --git a/docs/reference/gcr/gcr-docs.sgml b/docs/reference/gcr/gcr-docs.sgml
index c68c120..14f4a36 100644
--- a/docs/reference/gcr/gcr-docs.sgml
+++ b/docs/reference/gcr/gcr-docs.sgml
@@ -60,6 +60,7 @@
<xi:include href="xml/gcr-library.xml"/>
<xi:include href="xml/gcr-fingerprint.xml"/>
<xi:include href="xml/gcr-secret-exchange.xml"/>
+ <xi:include href="xml/gcr-secure-entry-buffer.xml"/>
</part>
<xi:include href="xml/annotation-glossary.xml">
diff --git a/docs/reference/gcr/gcr-sections.txt b/docs/reference/gcr/gcr-sections.txt
index 29432bc..6fa835b 100644
--- a/docs/reference/gcr/gcr-sections.txt
+++ b/docs/reference/gcr/gcr-sections.txt
@@ -643,6 +643,23 @@ gcr_fingerprint_from_subject_public_key_info
</SECTION>
<SECTION>
+<FILE>gcr-secure-entry-buffer</FILE>
+GcrSecureEntryBuffer
+GcrSecureEntryBufferClass
+gcr_secure_entry_buffer_new
+<SUBSECTION Standard>
+gcr_secure_entry_buffer_get_type
+GCR_IS_SECURE_ENTRY_BUFFER
+GCR_IS_SECURE_ENTRY_BUFFER_CLASS
+GCR_SECURE_ENTRY_BUFFER
+GCR_SECURE_ENTRY_BUFFER_CLASS
+GCR_SECURE_ENTRY_BUFFER_GET_CLASS
+GCR_TYPE_SECURE_ENTRY_BUFFER
+<SUBSECTION Private>
+GcrSecureEntryBufferPrivate
+</SECTION>
+
+<SECTION>
<FILE>gcr-private</FILE>
<SUBSECTION Private>
GCR_GNUPG_COLLECTION
diff --git a/docs/reference/gcr/gcr.types b/docs/reference/gcr/gcr.types
index 4f2ac11..bbfa483 100644
--- a/docs/reference/gcr/gcr.types
+++ b/docs/reference/gcr/gcr.types
@@ -15,6 +15,7 @@ gcr_list_selector_get_type
gcr_parser_get_type
gcr_pkcs11_certificate_get_type
gcr_renderer_get_type
+gcr_secure_entry_buffer_get_type
gcr_simple_certificate_get_type
gcr_simple_collection_get_type
gcr_tree_selector_get_type
diff --git a/egg/Makefile.am b/egg/Makefile.am
index 64b0934..045902f 100644
--- a/egg/Makefile.am
+++ b/egg/Makefile.am
@@ -3,7 +3,6 @@ include $(top_srcdir)/Makefile.decl
noinst_LTLIBRARIES = \
libegg.la \
libegg-asn1x.la \
- libegg-entry-buffer.la \
libegg-hex.la \
libegg-secmem.la \
libegg-test.la
@@ -64,13 +63,6 @@ libegg_asn1x_la_SOURCES = \
libegg_asn1x_la_CFLAGS = \
$(GLIB_CFLAGS)
-libegg_entry_buffer_la_SOURCES = \
- egg-entry-buffer.c egg-entry-buffer.h
-
-libegg_entry_buffer_la_CFLAGS = \
- $(GLIB_CFLAGS) \
- $(GTK_CFLAGS)
-
libegg_hex_la_SOURCES = \
egg-hex.c egg-hex.h
diff --git a/gcr/Makefile.am b/gcr/Makefile.am
index 544063e..92af49f 100644
--- a/gcr/Makefile.am
+++ b/gcr/Makefile.am
@@ -52,6 +52,7 @@ HEADER_UI_FILES = \
gcr-import-button.h \
gcr-list-selector.h \
gcr-renderer.h \
+ gcr-secure-entry-buffer.h \
gcr-simple-collection.h \
gcr-tree-selector.h \
gcr-unlock-options-widget.h \
@@ -166,6 +167,7 @@ libgcr_ GCR_MAJOR@_la_SOURCES = \
gcr-pkcs11-import-dialog.c gcr-pkcs11-import-dialog.h \
gcr-record.c gcr-record.h \
gcr-renderer.c gcr-renderer.h \
+ gcr-secure-entry-buffer.c gcr-secure-entry-buffer.h \
gcr-subject-public-key.c gcr-subject-public-key.h \
gcr-tree-selector.c gcr-tree-selector.h \
gcr-unlock-options.h \
@@ -205,7 +207,6 @@ libgcr_base_ GCR_MAJOR@_la_LIBADD = \
libgcr_ GCR_MAJOR@_la_LIBADD = \
$(GTK_LIBS) \
$(libgcr_base_ GCR_MAJOR@_la_LIBADD) \
- $(top_builddir)/egg/libegg-entry-buffer.la \
$(builddir)/libgcr-base-$(GCR_MAJOR).la
noinst_LTLIBRARIES = libgcr-testable.la
diff --git a/gcr/gcr-failure-renderer.c b/gcr/gcr-failure-renderer.c
index 4cf84bd..ef37f2f 100644
--- a/gcr/gcr-failure-renderer.c
+++ b/gcr/gcr-failure-renderer.c
@@ -20,11 +20,10 @@
#include "config.h"
#include "gcr-display-view.h"
+#include "gcr-failure-renderer.h"
#include "gcr-icons.h"
#include "gcr-parser.h"
-#include "gcr-failure-renderer.h"
-
-#include "egg/egg-entry-buffer.h"
+#include "gcr-secure-entry-buffer.h"
#include <gdk/gdk.h>
#include <glib/gi18n-lib.h>
diff --git a/gcr/gcr-pkcs11-import-dialog.c b/gcr/gcr-pkcs11-import-dialog.c
index 7b801de..8f52816 100644
--- a/gcr/gcr-pkcs11-import-dialog.c
+++ b/gcr/gcr-pkcs11-import-dialog.c
@@ -23,9 +23,9 @@
#include "gcr-dialog-util.h"
#include "gcr-icons.h"
+#include "gcr-secure-entry-buffer.h"
#include "gcr-pkcs11-import-dialog.h"
-#include "egg/egg-entry-buffer.h"
#include "egg/egg-secure-memory.h"
#include <gtk/gtk.h>
@@ -96,7 +96,7 @@ _gcr_pkcs11_import_dialog_constructed (GObject *obj)
gtk_widget_hide (self->password_area);
/* Add a secure entry */
- buffer = egg_entry_buffer_new ();
+ buffer = gcr_secure_entry_buffer_new ();
self->password_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "password-entry"));
gtk_entry_set_buffer (self->password_entry, buffer);
gtk_entry_set_activates_default (self->password_entry, TRUE);
diff --git a/egg/egg-entry-buffer.c b/gcr/gcr-secure-entry-buffer.c
similarity index 51%
rename from egg/egg-entry-buffer.c
rename to gcr/gcr-secure-entry-buffer.c
index cac1f2d..cd9197f 100644
--- a/egg/egg-entry-buffer.c
+++ b/gcr/gcr-secure-entry-buffer.c
@@ -1,5 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* egg-secure-buffer.c - secure memory gtkentry buffer
+/* gcr-secure-buffer.c - secure memory gtkentry buffer
Copyright (C) 2009 Stefan Walter
@@ -23,17 +23,47 @@
#include "config.h"
-#include "egg-entry-buffer.h"
-#include "egg-secure-memory.h"
+#include "gcr-secure-entry-buffer.h"
+
+#include "egg/egg-secure-memory.h"
#include <string.h>
-EGG_SECURE_DECLARE (entry_buffer);
+/**
+ * SECTION:gcr-secure-entry-buffer
+ * @title: GcrSecureEntryBuffer
+ * @short_description: a GtkEntryBuffer that uses non-pageable memory
+ *
+ * It's good practice to try to keep passwords or sensitive secrets out of
+ * pageable memory whenever possible, so that they don't get written to disk.
+ *
+ * This is a #GtkEntryBuffer to be used with #GtkEntry which uses non-pageable
+ * memory to store a password placed in the entry. In order to make any sense
+ * at all, the entry must have it's visibility turned off, and just be displaying
+ * place holder characters for the text. That is, a password style entry.
+ *
+ * Use gtk_entry_new_with_buffer() or gtk_entry_set_buffer() to set this buffer
+ * on an entry.
+ */
+
+/**
+ * GcrSecureEntryBuffer:
+ *
+ * A #GtkEntryBuffer which uses non-pageable memory for passwords or secrets.
+ */
+
+/**
+ * GcrSecureEntryBufferClass:
+ *
+ * The class for #GcrSecureEntryBuffer.
+ */
+
+EGG_SECURE_DECLARE (secure_entry_buffer);
/* Initial size of buffer, in bytes */
#define MIN_SIZE 16
-struct _EggEntryBufferPrivate
+struct _GcrSecureEntryBufferPrivate
{
gchar *text;
gsize text_size;
@@ -41,16 +71,13 @@ struct _EggEntryBufferPrivate
guint text_chars;
};
-G_DEFINE_TYPE (EggEntryBuffer, egg_entry_buffer, GTK_TYPE_ENTRY_BUFFER);
+G_DEFINE_TYPE (GcrSecureEntryBuffer, gcr_secure_entry_buffer, GTK_TYPE_ENTRY_BUFFER);
-/* --------------------------------------------------------------------------------
- * SECURE IMPLEMENTATIONS OF TEXT BUFFER
- */
-
-static const gchar*
-egg_entry_buffer_real_get_text (GtkEntryBuffer *buffer, gsize *n_bytes)
+static const gchar *
+gcr_secure_entry_buffer_real_get_text (GtkEntryBuffer *buffer,
+ gsize *n_bytes)
{
- EggEntryBuffer *self = EGG_ENTRY_BUFFER (buffer);
+ GcrSecureEntryBuffer *self = GCR_SECURE_ENTRY_BUFFER (buffer);
if (n_bytes)
*n_bytes = self->priv->text_bytes;
if (!self->priv->text)
@@ -59,18 +86,20 @@ egg_entry_buffer_real_get_text (GtkEntryBuffer *buffer, gsize *n_bytes)
}
static guint
-egg_entry_buffer_real_get_length (GtkEntryBuffer *buffer)
+gcr_secure_entry_buffer_real_get_length (GtkEntryBuffer *buffer)
{
- EggEntryBuffer *self = EGG_ENTRY_BUFFER (buffer);
+ GcrSecureEntryBuffer *self = GCR_SECURE_ENTRY_BUFFER (buffer);
return self->priv->text_chars;
}
static guint
-egg_entry_buffer_real_insert_text (GtkEntryBuffer *buffer, guint position,
- const gchar *chars, guint n_chars)
+gcr_secure_entry_buffer_real_insert_text (GtkEntryBuffer *buffer,
+ guint position,
+ const gchar *chars,
+ guint n_chars)
{
- EggEntryBuffer *self = EGG_ENTRY_BUFFER (buffer);
- EggEntryBufferPrivate *pv = self->priv;
+ GcrSecureEntryBuffer *self = GCR_SECURE_ENTRY_BUFFER (buffer);
+ GcrSecureEntryBufferPrivate *pv = self->priv;
gsize n_bytes;
gsize at;
@@ -116,10 +145,12 @@ egg_entry_buffer_real_insert_text (GtkEntryBuffer *buffer, guint position,
}
static guint
-egg_entry_buffer_real_delete_text (GtkEntryBuffer *buffer, guint position, guint n_chars)
+gcr_secure_entry_buffer_real_delete_text (GtkEntryBuffer *buffer,
+ guint position,
+ guint n_chars)
{
- EggEntryBuffer *self = EGG_ENTRY_BUFFER (buffer);
- EggEntryBufferPrivate *pv = self->priv;
+ GcrSecureEntryBuffer *self = GCR_SECURE_ENTRY_BUFFER (buffer);
+ GcrSecureEntryBufferPrivate *pv = self->priv;
gsize start, end;
if (position > pv->text_chars)
@@ -141,15 +172,11 @@ egg_entry_buffer_real_delete_text (GtkEntryBuffer *buffer, guint position, guint
return n_chars;
}
-/* --------------------------------------------------------------------------------
- *
- */
-
static void
-egg_entry_buffer_init (EggEntryBuffer *self)
+gcr_secure_entry_buffer_init (GcrSecureEntryBuffer *self)
{
- EggEntryBufferPrivate *pv;
- pv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EGG_TYPE_ENTRY_BUFFER, EggEntryBufferPrivate);
+ GcrSecureEntryBufferPrivate *pv;
+ pv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GCR_TYPE_SECURE_ENTRY_BUFFER, GcrSecureEntryBufferPrivate);
pv->text = NULL;
pv->text_chars = 0;
@@ -158,10 +185,10 @@ egg_entry_buffer_init (EggEntryBuffer *self)
}
static void
-egg_entry_buffer_finalize (GObject *obj)
+gcr_secure_entry_buffer_finalize (GObject *obj)
{
- EggEntryBuffer *self = EGG_ENTRY_BUFFER (obj);
- EggEntryBufferPrivate *pv = self->priv;
+ GcrSecureEntryBuffer *self = GCR_SECURE_ENTRY_BUFFER (obj);
+ GcrSecureEntryBufferPrivate *pv = self->priv;
if (pv->text) {
egg_secure_strfree (pv->text);
@@ -170,31 +197,35 @@ egg_entry_buffer_finalize (GObject *obj)
pv->text_chars = 0;
}
- G_OBJECT_CLASS (egg_entry_buffer_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (gcr_secure_entry_buffer_parent_class)->finalize (obj);
}
static void
-egg_entry_buffer_class_init (EggEntryBufferClass *klass)
+gcr_secure_entry_buffer_class_init (GcrSecureEntryBufferClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkEntryBufferClass *buffer_class = GTK_ENTRY_BUFFER_CLASS (klass);
- gobject_class->finalize = egg_entry_buffer_finalize;
+ gobject_class->finalize = gcr_secure_entry_buffer_finalize;
- buffer_class->get_text = egg_entry_buffer_real_get_text;
- buffer_class->get_length = egg_entry_buffer_real_get_length;
- buffer_class->insert_text = egg_entry_buffer_real_insert_text;
- buffer_class->delete_text = egg_entry_buffer_real_delete_text;
+ buffer_class->get_text = gcr_secure_entry_buffer_real_get_text;
+ buffer_class->get_length = gcr_secure_entry_buffer_real_get_length;
+ buffer_class->insert_text = gcr_secure_entry_buffer_real_insert_text;
+ buffer_class->delete_text = gcr_secure_entry_buffer_real_delete_text;
- g_type_class_add_private (gobject_class, sizeof (EggEntryBufferPrivate));
+ g_type_class_add_private (gobject_class, sizeof (GcrSecureEntryBufferPrivate));
}
-/* --------------------------------------------------------------------------------
+/**
+ * gcr_secure_entry_buffer_new:
*
+ * Create a new #GcrSecureEntryBuffer, a #GtkEntryBuffer which uses
+ * non-pageable memory for the text.
+ *
+ * Returns: (transfer full): the new entry buffer
*/
-
-GtkEntryBuffer*
-egg_entry_buffer_new (void)
+GtkEntryBuffer *
+gcr_secure_entry_buffer_new (void)
{
- return g_object_new (EGG_TYPE_ENTRY_BUFFER, NULL);
+ return g_object_new (GCR_TYPE_SECURE_ENTRY_BUFFER, NULL);
}
diff --git a/gcr/gcr-secure-entry-buffer.h b/gcr/gcr-secure-entry-buffer.h
new file mode 100644
index 0000000..d991c48
--- /dev/null
+++ b/gcr/gcr-secure-entry-buffer.h
@@ -0,0 +1,63 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* gcr-secure-buffer.h - secure memory gtkentry buffer
+
+ Copyright (C) 2009 Stefan Walter
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stef memberwebs com>
+*/
+
+#if !defined (__GCR_INSIDE_HEADER__) && !defined (GCR_COMPILATION)
+#error "Only <gcr/gcr.h> or <gcr/gcr-base.h> can be included directly."
+#endif
+
+#ifndef __GCR_SECURE_ENTRY_BUFFER_H__
+#define __GCR_SECURE_ENTRY_BUFFER_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GCR_TYPE_SECURE_ENTRY_BUFFER (gcr_secure_entry_buffer_get_type ())
+#define GCR_SECURE_ENTRY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCR_TYPE_SECURE_ENTRY_BUFFER, GcrSecureEntryBuffer))
+#define GCR_SECURE_ENTRY_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCR_TYPE_SECURE_ENTRY_BUFFER, GcrSecureEntryBufferClass))
+#define GCR_IS_SECURE_ENTRY_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCR_TYPE_SECURE_ENTRY_BUFFER))
+#define GCR_IS_SECURE_ENTRY_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCR_TYPE_SECURE_ENTRY_BUFFER))
+#define GCR_SECURE_ENTRY_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCR_TYPE_SECURE_ENTRY_BUFFER, GcrSecureEntryBufferClass))
+
+typedef struct _GcrSecureEntryBuffer GcrSecureEntryBuffer;
+typedef struct _GcrSecureEntryBufferClass GcrSecureEntryBufferClass;
+typedef struct _GcrSecureEntryBufferPrivate GcrSecureEntryBufferPrivate;
+
+struct _GcrSecureEntryBuffer
+{
+ GtkEntryBuffer parent;
+ GcrSecureEntryBufferPrivate *priv;
+};
+
+struct _GcrSecureEntryBufferClass
+{
+ GtkEntryBufferClass parent_class;
+};
+
+GType gcr_secure_entry_buffer_get_type (void) G_GNUC_CONST;
+
+GtkEntryBuffer * gcr_secure_entry_buffer_new (void);
+
+G_END_DECLS
+
+#endif /* __GCR_SECURE_ENTRY_BUFFER_H__ */
diff --git a/gcr/gcr-unlock-renderer.c b/gcr/gcr-unlock-renderer.c
index 4615057..69d163d 100644
--- a/gcr/gcr-unlock-renderer.c
+++ b/gcr/gcr-unlock-renderer.c
@@ -22,10 +22,9 @@
#include "gcr-display-view.h"
#include "gcr-icons.h"
#include "gcr-parser.h"
+#include "gcr-secure-entry-buffer.h"
#include "gcr-unlock-renderer.h"
-#include "egg/egg-entry-buffer.h"
-
#include <gdk/gdk.h>
#include <glib/gi18n-lib.h>
@@ -116,7 +115,7 @@ _gcr_unlock_renderer_init (GcrUnlockRenderer *self)
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
- buffer = egg_entry_buffer_new ();
+ buffer = gcr_secure_entry_buffer_new ();
self->pv->entry = GTK_ENTRY (gtk_entry_new_with_buffer (buffer));
gtk_entry_set_visibility (self->pv->entry, FALSE);
gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (self->pv->entry), TRUE, FALSE, 0);
diff --git a/gcr/gcr.h b/gcr/gcr.h
index ec150a9..6c09364 100644
--- a/gcr/gcr.h
+++ b/gcr/gcr.h
@@ -49,6 +49,7 @@
#include "gcr-import-button.h"
#include "gcr-list-selector.h"
#include "gcr-renderer.h"
+#include "gcr-secure-entry-buffer.h"
#include "gcr-tree-selector.h"
#include "gcr-union-collection.h"
#include "gcr-unlock-options-widget.h"
diff --git a/gcr/tests/Makefile.am b/gcr/tests/Makefile.am
index f711931..7f71f68 100644
--- a/gcr/tests/Makefile.am
+++ b/gcr/tests/Makefile.am
@@ -14,7 +14,6 @@ INCLUDES = \
LDADD = \
$(top_builddir)/gcr/libgcr-testable.la \
$(top_builddir)/egg/libegg.la \
- $(top_builddir)/egg/libegg-entry-buffer.la \
$(top_builddir)/gck/libgck-testable.la \
$(GTK_LIBS) \
$(GLIB_LIBS) \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]