[gnome-autoar/wip/oholy/compressor-encryption: 1/2] compressor: Add encryption support
- From: Ondrej Holy <oholy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-autoar/wip/oholy/compressor-encryption: 1/2] compressor: Add encryption support
- Date: Mon, 19 Jul 2021 14:46:03 +0000 (UTC)
commit 62e5aa4b847a7323afd195a0376a971a1d90545d
Author: Ondrej Holy <oholy redhat com>
Date: Wed Jun 2 09:57:58 2021 +0200
compressor: Add encryption support
`AutoarExtractor` supports extraction of encrypted archives. It would be nice
to have support for encrypted archives also in `AutoarCompressor`. Though the
libarchive library doesn't provide a much. It supports encryption only for the
ZIP format. There is a choice between `zipcrypt`, `aes128` and `aes256`. Given
the phact that `zipcrypt` is insecure and not recommended, I think it is fine
to hardcode `aes256`. It is probably a bit slower then `aes128`, but more secure.
So the only thing which needs to be set is a passphrase. Let's add
`autoar_compressor_set_passphrase` to allow creating encrypted archives.
Relates: https://gitlab.gnome.org/GNOME/nautilus/-/issues/822
gnome-autoar/autoar-compressor.c | 36 ++++++++++++++++++++++++++++++++++++
gnome-autoar/autoar-compressor.h | 2 ++
2 files changed, 38 insertions(+)
---
diff --git a/gnome-autoar/autoar-compressor.c b/gnome-autoar/autoar-compressor.c
index 31a5a58..5da7258 100644
--- a/gnome-autoar/autoar-compressor.c
+++ b/gnome-autoar/autoar-compressor.c
@@ -113,6 +113,8 @@ struct _AutoarCompressor
int in_thread : 1;
gboolean create_top_level_directory;
+
+ gchar *passphrase;
};
G_DEFINE_TYPE (AutoarCompressor, autoar_compressor, G_TYPE_OBJECT)
@@ -455,6 +457,23 @@ autoar_compressor_set_notify_interval (AutoarCompressor *self,
self->notify_interval = notify_interval;
}
+/**
+ * autoar_compressor_set_passphrase:
+ * @self: an #AutoarCompressor
+ * @passphrase: the archive passphrase
+ *
+ * Sets the archive passphrase. It works only with %ARCHIVE_FORMAT_ZIP.
+ **/
+void
+autoar_compressor_set_passphrase (AutoarCompressor *self,
+ const gchar *passphrase)
+{
+ g_return_if_fail (AUTOAR_IS_COMPRESSOR (self));
+ g_return_if_fail (self->format == AUTOAR_FORMAT_ZIP);
+
+ self->passphrase = g_strdup (passphrase);
+}
+
static void
autoar_compressor_dispose (GObject *object)
{
@@ -536,6 +555,8 @@ autoar_compressor_finalize (GObject *object)
g_free (self->extension);
self->extension = NULL;
+ g_clear_pointer (&self->passphrase, g_free);
+
G_OBJECT_CLASS (autoar_compressor_parent_class)->finalize (object);
}
@@ -1292,6 +1313,7 @@ autoar_compressor_init (AutoarCompressor *self)
self->extension = NULL;
self->in_thread = FALSE;
+ self->passphrase = NULL;
}
/**
@@ -1373,6 +1395,20 @@ autoar_compressor_step_initialize_object (AutoarCompressor *self)
self->error = autoar_common_g_error_new_a (self->a, NULL);
return;
}
+
+ if (self->passphrase != NULL && self->format == AUTOAR_FORMAT_ZIP) {
+ r = archive_write_set_options (self->a, "zip:encryption=aes256");
+ if (r != ARCHIVE_OK) {
+ self->error = autoar_common_g_error_new_a (self->a, NULL);
+ return;
+ }
+
+ r = archive_write_set_passphrase (self->a, self->passphrase);
+ if (r != ARCHIVE_OK) {
+ self->error = autoar_common_g_error_new_a (self->a, NULL);
+ return;
+ }
+ }
}
static void
diff --git a/gnome-autoar/autoar-compressor.h b/gnome-autoar/autoar-compressor.h
index 931a4fc..6dad196 100644
--- a/gnome-autoar/autoar-compressor.h
+++ b/gnome-autoar/autoar-compressor.h
@@ -75,6 +75,8 @@ void autoar_compressor_set_output_is_dest (AutoarCompr
gboolean output_is_dest);
void autoar_compressor_set_notify_interval (AutoarCompressor *self,
gint64 notify_interval);
+void autoar_compressor_set_passphrase (AutoarCompressor *self,
+ const gchar *passphrase);
G_END_DECLS
#endif /* AUTOAR_COMPRESSOR_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]