Browse Source

Merge branch 'develop'

master gfsecret-0.4.2
Damien Goutte-Gattat 5 years ago
  1. 2
  2. 2
  3. 7
  4. 4
  5. 6
  6. 2
  7. 506
  8. 505
  9. 4
  10. 35
  11. 8


@ -20,3 +20,5 @@ src/gfsec-use


@ -1,4 +1,4 @@
SUBDIRS = lib src man
SUBDIRS = lib src man info
ACLOCAL_AMFLAGS = -I m4 --install


@ -1,3 +1,10 @@
Changes in gfsecret 0.4.2
* Fix a crash upon error in LibMTP.
* Write user-specified config file in config directory by default.
* Refuse to overwrite a pre-existing config file.
Changes in gfsecret 0.4.1
* Add the -i, --interactive option to gfsec-split.


@ -143,7 +143,7 @@ License, version 3 or higher. The full license is included in the
Homepage and repository
The project is located at
The project is located at
The latest source code is available in a Git repository at
git:// and may also be browsed at;a=summary.;a=summary.


@ -1,7 +1,6 @@
dnl Configure template for the gfsecret package
AC_INIT([gfsecret], [0.4.1],
AC_INIT([gfsecret], [0.4.2], [])
@ -55,7 +54,8 @@ AC_DEFINE_UNQUOTED([GFSEC_SECRET_MAX_SIZE], [$max_secret_size],
dnl Output files
AC_CONFIG_FILES([Makefile lib/Makefile src/Makefile
man/Makefile man/gfsec-use.1 man/gfsec-split.1])
man/Makefile man/gfsec-use.1 man/gfsec-split.1
dnl Summary


@ -0,0 +1,2 @@
info_TEXINFOS = gfsecret.texi
gfsecret_TEXINFOS = fdl.texi


@ -0,0 +1,506 @@
@c The GNU Free Documentation License.
@center Version 1.3, 3 November 2008
@c This file is intended to be included within another document,
@c hence no sectioning command or @node.
Copyright @copyright{} 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@end display
@enumerate 0
The purpose of this License is to make a manual, textbook, or other
functional and useful document @dfn{free} in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially.
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.
This License is a kind of ``copyleft'', which means that derivative
works of the document must themselves be free in the same sense. It
complements the GNU General Public License, which is a copyleft
license designed for free software.
We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does. But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book. We recommend this License
principally for works whose purpose is instruction or reference.
This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License. Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein. The ``Document'', below,
refers to any such manual or work. Any member of the public is a
licensee, and is addressed as ``you''. You accept the license if you
copy, modify or distribute the work in a way requiring permission
under copyright law.
A ``Modified Version'' of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.
A ``Secondary Section'' is a named appendix or a front-matter section
of the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall
subject (or to related matters) and contains nothing that could fall
directly within that overall subject. (Thus, if the Document is in
part a textbook of mathematics, a Secondary Section may not explain
any mathematics.) The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
The ``Invariant Sections'' are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License. If a
section does not fit the above definition of Secondary then it is not
allowed to be designated as Invariant. The Document may contain zero
Invariant Sections. If the Document does not identify any Invariant
Sections then there are none.
The ``Cover Texts'' are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License. A Front-Cover Text may
be at most 5 words, and a Back-Cover Text may be at most 25 words.
A ``Transparent'' copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters. A copy made in an otherwise Transparent file
format whose markup, or absence of markup, has been arranged to thwart
or discourage subsequent modification by readers is not Transparent.
An image format is not Transparent if used for any substantial amount
of text. A copy that is not ``Transparent'' is called ``Opaque''.
Examples of suitable formats for Transparent copies include plain
@sc{ascii} without markup, Texinfo input format, La@TeX{} input
format, @acronym{SGML} or @acronym{XML} using a publicly available
@acronym{DTD}, and standard-conforming simple @acronym{HTML},
PostScript or @acronym{PDF} designed for human modification. Examples
of transparent image formats include @acronym{PNG}, @acronym{XCF} and
@acronym{JPG}. Opaque formats include proprietary formats that can be
read and edited only by proprietary word processors, @acronym{SGML} or
@acronym{XML} for which the @acronym{DTD} and/or processing tools are
not generally available, and the machine-generated @acronym{HTML},
PostScript or @acronym{PDF} produced by some word processors for
output purposes only.
The ``Title Page'' means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page. For works in
formats which do not have any title page as such, ``Title Page'' means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.
The ``publisher'' means any person or entity that distributes copies
of the Document to the public.
A section ``Entitled XYZ'' means a named subunit of the Document whose
title either is precisely XYZ or contains XYZ in parentheses following
text that translates XYZ in another language. (Here XYZ stands for a
specific section name mentioned below, such as ``Acknowledgements'',
``Dedications'', ``Endorsements'', or ``History''.) To ``Preserve the Title''
of such a section when you modify the Document means that it remains a
section ``Entitled XYZ'' according to this definition.
The Document may include Warranty Disclaimers next to the notice which
states that this License applies to the Document. These Warranty
Disclaimers are considered to be included by reference in this
License, but only as regards disclaiming warranties: any other
implication that these Warranty Disclaimers may have is void and has
no effect on the meaning of this License.
You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License. You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute. However, you may accept
compensation in exchange for copies. If you distribute a large enough
number of copies you must also follow the conditions in section 3.
You may also lend copies, under the same conditions stated above, and
you may publicly display copies.
If you publish printed copies (or copies in media that commonly have
printed covers) of the Document, numbering more than 100, and the
Document's license notice requires Cover Texts, you must enclose the
copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover. Both covers must also clearly and legibly identify
you as the publisher of these copies. The front cover must present
the full title with all words of the title equally prominent and
visible. You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a computer-network location from which the general network-using
public has access to download using public-standard network protocols
a complete Transparent copy of the Document, free of added material.
If you use the latter option, you must take reasonably prudent steps,
when you begin distribution of Opaque copies in quantity, to ensure
that this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you distribute an
Opaque copy (directly or through your agents or retailers) of that
edition to the public.
It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.
You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it. In addition, you must do these things in the Modified Version:
@enumerate A
Use in the Title Page (and on the covers, if any) a title distinct
from that of the Document, and from those of previous versions
(which should, if there were any, be listed in the History section
of the Document). You may use the same title as a previous version
if the original publisher of that version gives permission.
List on the Title Page, as authors, one or more persons or entities
responsible for authorship of the modifications in the Modified
Version, together with at least five of the principal authors of the
Document (all of its principal authors, if it has fewer than five),
unless they release you from this requirement.
State on the Title page the name of the publisher of the
Modified Version, as the publisher.
Preserve all the copyright notices of the Document.
Add an appropriate copyright notice for your modifications
adjacent to the other copyright notices.
Include, immediately after the copyright notices, a license notice
giving the public permission to use the Modified Version under the
terms of this License, in the form shown in the Addendum below.
Preserve in that license notice the full lists of Invariant Sections
and required Cover Texts given in the Document's license notice.
Include an unaltered copy of this License.
Preserve the section Entitled ``History'', Preserve its Title, and add
to it an item stating at least the title, year, new authors, and
publisher of the Modified Version as given on the Title Page. If
there is no section Entitled ``History'' in the Document, create one
stating the title, year, authors, and publisher of the Document as
given on its Title Page, then add an item describing the Modified
Version as stated in the previous sentence.
Preserve the network location, if any, given in the Document for
public access to a Transparent copy of the Document, and likewise
the network locations given in the Document for previous versions
it was based on. These may be placed in the ``History'' section.
You may omit a network location for a work that was published at
least four years before the Document itself, or if the original
publisher of the version it refers to gives permission.
For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve
the Title of the section, and preserve in the section all the
substance and tone of each of the contributor acknowledgements and/or
dedications given therein.
Preserve all the Invariant Sections of the Document,
unaltered in their text and in their titles. Section numbers
or the equivalent are not considered part of the section titles.
Delete any section Entitled ``Endorsements''. Such a section
may not be included in the Modified Version.
Do not retitle any existing section to be Entitled ``Endorsements'' or
to conflict in title with any Invariant Section.
Preserve any Warranty Disclaimers.
@end enumerate
If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant. To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice.
These titles must be distinct from any other section titles.
You may add a section Entitled ``Endorsements'', provided it contains
nothing but endorsements of your Modified Version by various
parties---for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version. Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity. If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.
You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy. If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number.
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled ``History''
in the various original documents, forming one section Entitled
``History''; likewise combine any sections Entitled ``Acknowledgements'',
and any sections Entitled ``Dedications''. You must delete all
sections Entitled ``Endorsements.''
You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this
License in the various documents with a single copy that is included in
the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.
You may extract a single document from such a collection, and distribute
it individually under this License, provided you insert a copy of this
License into the extracted document, and follow this License in all
other respects regarding verbatim copying of that document.
A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an ``aggregate'' if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit.
When the Document is included in an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form.
Otherwise they must appear on printed covers that bracket the whole
Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4.
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections. You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers. In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.
If a section in the Document is Entitled ``Acknowledgements'',
``Dedications'', or ``History'', the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
You may not copy, modify, sublicense, or distribute the Document
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense, or distribute it is void, and
will automatically terminate your rights under this License.
However, if you cease all violation of this License, then your license
from a particular copyright holder is reinstated (a) provisionally,
unless and until the copyright holder explicitly and finally
terminates your license, and (b) permanently, if the copyright holder
fails to notify you of the violation by some reasonable means prior to
60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, receipt of a copy of some or all of the same material does
not give you any rights to use it.
The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns. See
Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
License ``or any later version'' applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation. If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation. If the Document
specifies that a proxy can decide which future versions of this
License can be used, that proxy's public statement of acceptance of a
version permanently authorizes you to choose that version for the
``Massive Multiauthor Collaboration Site'' (or ``MMC Site'') means any
World Wide Web server that publishes copyrightable works and also
provides prominent facilities for anybody to edit those works. A
public wiki that anybody can edit is an example of such a server. A
``Massive Multiauthor Collaboration'' (or ``MMC'') contained in the
site means any set of copyrightable works thus published on the MMC
``CC-BY-SA'' means the Creative Commons Attribution-Share Alike 3.0
license published by Creative Commons Corporation, a not-for-profit
corporation with a principal place of business in San Francisco,
California, as well as future copyleft versions of that license
published by that same organization.
``Incorporate'' means to publish or republish a Document, in whole or
in part, as part of another Document.
An MMC is ``eligible for relicensing'' if it is licensed under this
License, and if all works that were first published under this License
somewhere other than this MMC, and subsequently incorporated in whole
or in part into the MMC, (1) had no cover texts or invariant sections,
and (2) were thus incorporated prior to November 1, 2008.
The operator of an MMC Site may republish an MMC contained in the site
under CC-BY-SA on the same site at any time before August 1, 2009,
provided the MMC is eligible for relicensing.
@end enumerate
@heading ADDENDUM: How to use this License for your documents
To use this License in a document you have written, include a copy of
the License in the document and put the following copyright and
license notices just after the title page:
Copyright (C) @var{year} @var{your name}.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. A copy of the license is included in the section entitled ``GNU
Free Documentation License''.
@end group
@end smallexample
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
replace the ``with@dots{}Texts.'' line with this:
with the Invariant Sections being @var{list their titles}, with
the Front-Cover Texts being @var{list}, and with the Back-Cover Texts
being @var{list}.
@end group
@end smallexample
If you have Invariant Sections without Cover Texts, or some other
combination of the three, merge those two alternatives to suit the
If your document contains nontrivial examples of program code, we
recommend releasing these examples in parallel under your choice of
free software license, such as the GNU General Public License,
to permit their use in free software.
@c Local Variables:
@c ispell-local-pdict: "ispell-dict"
@c End:


@ -0,0 +1,505 @@
\input texinfo
@settitle The Gfsecret Manual
@include version.texi
This is the manual for Gfsecret (version @value{VERSION}, last updated
Copyright @copyright{} 2017 Damien Goutte-Gattat
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the section entitled ``GNU
Free Documentation License''.
@end quotation
@end copying
@title Gfsecret
@subtitle for version @value{VERSION}, @value{UPDATED}
@author Damien Goutte-Gattat (@email{})
@vskip 0pt plus 1filll
@end titlepage
@node Top
@top Gfsecret
This manual is for Gfsecret (version @value{VERSION}, @value{UPDATED}).
@end ifnottex
* Introduction::
* The Share URI Syntax::
* Splitting a Secret::
* Using a Splitted Secret::
* Examples::
* GNU Free Documentation License::
* Index::
@end menu
@node Introduction
@chapter Introduction
You may have some important files that you both don't want to lose and
don't want to fall into any other hands than yours. It may be files
containing your OpenPGP private keys, the file containing all your
online passwords, the file describing your plan for total world
domination, whatever.
Such files pose an interesting problem. Obviously, you have to backup
them to avoid losing them, but any supplementary copy gives your
adversary one more opportunity to grab your secret.
* Adi Shamir's Secret Sharing::
* Overview of Gfsecret::
@end menu
@node Adi Shamir's Secret Sharing
@section Adi Shamir's Secret Sharing
A secret sharing scheme is precisely what you need to fulfill both of
the contradictory goals.
The Adi Shamir's secret sharing scheme, devised by the famous
cryptographer Adi Shamir (the ``A'' in the RSA public cryptography
algorithm) in 1979, relies on the fact that @math{n + 1} points are
required to uniquely define a curve corresponding to a polynom of order
To illustrate the scheme, let's say you want to share a secret value
@math{b} in two or more shares, so that at least two shares are needed
to reconstitute the secret. You will define a curve of the form
@math{f(x) = ax + b}, where @math{a} is a randomly chosen coefficient
and @math{b} (the secret value) is the y coordinate where the curve
intersects the Y axis.
A share is then a point on that curve, that is, a couple @math{x, f(x)}.
If you have only one point, there's no way for you to know what the
curve is, and where it intersects the Y axis, because there's an
infinity of curves passing through this point.
As soon as you have (at least) two points, however, you have all the
information that you need: there's only one straight curve passing
through two distinct points, and you can trace it, and trivially find
where it intersects the Y axis (and thus retrieve the secret value).
@node Overview of Gfsecret
@section Overview of Gfsecret
Gfsecret implements the Adi Shamir's secret sharing scheme to allow its
user to split a secret file into a given number of @emph{shares}, to
dispatch the shares onto several external storage devoces such as USB
sticks, and to temporarily reconstruct the original file when needed.
Gfsecret comprises two programs: @command{gfsec-split} splits a secret
file into shares and dispatches them, leaving behind a configuration
file describing the location of the shares; @command{fgsec-use} reads
the configuration file left by @command{gfsec-split}, attempts to fetch
the shares, and reconstructs the secret file if enough shares are
available. If the reconstruction is successful, @command{gfsec-use}
will then execute a single command (or start a new interactive shell if
the user didn't specify any command), and remove the reconstructed
secret once that command terminates.
@node The Share URI Syntax
@chapter The Share URI Syntax
Both @command{gfsec-split} and @command{gfsec-use} use the concept of a
@emph{share URI} to describe and represent shares. A share URI is an
URI-like string of the form @samp{scheme://authority/path?parameters}.
The @var{scheme} part indicates the method to use to access the share.
It can be: @samp{file} for a share on the local filesystem; @samp{label}
for a share on an external volume identified by its label; @samp{uuid}
for a share on an external volume identified by its UUID; or @samp{mtp}
for a share on a MTP-compliant device identified by its serial number.
The @var{authority} part identifies the storage device. It should be
empty when using the @samp{file://} scheme (although for consistency
with other uses of that scheme by other programs, it is permitted to
specify @samp{localhost}). It represents the volume's label when using
the @samp{label://} scheme, the volume's UUID when using the
@samp{uuid://} scheme, and the device's serial number when using the
@samp{mtp://} scheme.
The @var{path} part is the pathname to the share file on the device.
The filename itself should end with a numeric extension representing the
share number (needed by @command{gfsec-use} to appropriately reconstruct
the secret). That share number is automatically determined and appended
to the original filename by @command{gfsec-split}.
Finally, the optional @var{parameters} part may contains options
expressed as @samp{key=value} pairs. Currently, valid options are
@samp{sha256}, which specifies a SHA2-256 hash that the share should
match (@command{gfsec-use} will refuse to use the share otherwise), and
@samp{share=no}, which indicates that the corresponding share actually
contains the whole secret.
@node Splitting a Secret
@chapter Splitting a Secret
The @command{gfsec-split} tool is used to split a secret file into
The program must be given the pathname of the file to split as its first
positional argument. The location of the shares to create can either be
specified as @emph{share URIs} (@ref{The Share URI Syntax}) as
subsequent positional arguments on the command line (@ref{Specifying
Share URIs on the Command Line}), or be given through an interactive
menu (@ref{Interactive Selection of Shares}).
The threshold, that is, the minimal number of shares needed to
reconstruct the original file, is specified with the option @option{-n}
(@option{--threshold}). The default threshold is 2. The total number of
shares must of course be greater than or equal to that threshold, and
@command{gfsec-split} will fail otherwise (obviously you cannot split a
secret in two shares and require three shares to reconstruct it).
By default, if the split is successful, @command{gfsec-split} will
delete the original secret file once the shares have been dispatched to
their final location. Use the option @option{-k} (@option{--keep}) to
leave the original file intact.
A configuration file, needed by @command{gfsec-use} to reconstruct the
splitted file, will be automatically generated in the directory
@file{$XDG_CONFIG_HOME/gfsecret/@var{basename}.conf}, where
@var{basename} is the basename of the original file (without any
directory part and file extension). For example, when called to split a
file @file{/home/alice/Documents/mysecret.dat}, @command{gfsec-split} will
generate a configuration file in
@file{/home/alice/.config/gfsecret/mysecret.conf} (assuming the default
value for the @var{XDG_CONFIG_HOME} environment variable).
Use the option @option{-c} (@option{--config}) @var{name} to specify
yourself the name of the configuration file. If @var{name} is a filename
without extension and without a directory part, the configuration file
will be written to @file{$XDG_CONFIG_HOME/gfsecret/@var{name}.conf}.
Otherwise it will be written exactly at the specified location.
* Specifying Share URIs on the Command Line::
* Interactive Selection of Shares::
@end menu
@node Specifying Share URIs on the Command Line
@section Specifying Share URIs on the Command Line
The first method to tell @command{gfsec-split} where to put the shares
is to give it @emph{share URIs} (@ref{The Share URI Syntax}) on the
command line, as follows:
$ gfsec-split @var{secretfile} @var{uri1} @var{uri2} @var{uri3}
@end example
Before actually splitting the secret, you may invoke
@command{gfsec-split} with the option @option{-l}
(@option{--list-supports}) to get a list of available storage devices so
that you can construct the needed share URIs:
$ gfsec-split -l
file:/// Local filesystem
label://USBSTICK/ External volume with label 'USBSTICK'
mtp://RF2GB6X704P/ Samsung Galaxy A3
@end example
With those informations, you may then proceed to the actual split. Here,
assuming you want to put a share on each one of the available devices:
$ gfsec-split @var{secretfile} \
file:///home/alice/.shares/mysecret \
label://USBSTICK/mysecret \
@end example
(Note that shares do not need to have the same filename.)
With this example, @command{gfsec-split} with split @var{secretfile} in
three shares and store the first one in Alice's home directory, the
second one in the USB mass storage device called @emph{USBSTICK}, and
the third one on the Samsung Galaxy A3 smartphone with serial number
@emph{RF2GB6X704P}. External volumes will be automatically mounted if
needed (in that case they will also be unmounted at the end).
Note that @command{gfsec-split} will not create parent directories,
which must exist beforehand.
@node Interactive Selection of Shares
@section Interactive Selection of Shares
To avoid manually specifying the share URIs, use the @option{-i}
(@option{--interactive}). You will then be presented with an interactive
menu with the available devices:
$ gfsec-split -i @var{secretfile}
Select a support for share #1:
(1) Local filesystem
(2) External volume with label 'USBSTICK'
(3) Samsung Galaxy A3
(x) Done
Your choice?
@end example
Select the device on which you want to put the first share, then enter
the pathname to use on that device when prompted (again, be aware that
no parent directories will be created).
Repeat for all the shares you want to create, then select @kbd{x} when
you are done. @command{gfsec-split} will then show you a summary of what
you have selected, and ask for your confirmation:
The following shares will be created:
Proceed (y/N)?
@end example
Note that you can use both the command line and the interactive menu in
the same invocation of @command{gfsec-split}. The shares that you
describe on the command line will be added to the one you select in the
@node Using a Splitted Secret
@chapter Using a Splitted Secret
The @command{gfsec-use} program allows its user to temporarily
reconstruct a previously splitted file.
It reads a configuration file (automatically generated by the
@command{gfsec-split} program, although a configuration file can also be
crafted by hand) which gives, in particular, the location of the shares
(@ref{The Gfsecret Configuration File}).
Configuration files are normally stored in
@file{$XDG_CONFIG_HOME/gfsecret}, and @command{gfsec-use} reads by
default the file @file{XDG_CONFIG_HOME/gfsecret/default.conf}. The
option @option{-c} (@option{--config}) allows to specify another file:
$ gfsec-use -c @var{myconfig}
@end example
If the file @var{myconfig} exists, it is used as the configuration file;
otherwise, @command{gfsec-use} looks for a file named
@file{@var{myconfig}.conf} in the directory
Once the splitted file has been reconstructed (if enough shares are
available), @command{gfsec-use} will either spawn a new shell, or
execute any program specified at the end of the command line. When the
shell, or the user-specified program, terminates, the reconstructed file
is deleted again.
The @option{-k} (@option{--keep}) prevents @command{gfsec-use} from
deleting the reconstructed file. As a special case, if this option is
used and there is no user-specified command to execute,
@command{gfsec-use} will not spawn a new shell, but exits as soon as the
file is reconstructed.
The reconstructed file is normally written at the location of the
original file (or any other location specified by the @option{OUTFILE}
key in the configuration file). It may be written elsewhere by using the
@option{-o} (@option{--output}).
* The Gfsecret Configuration File::
@end menu
@node The Gfsecret Configuration File
@section The Gfsecret Configuration File
A configuration file contains all the informations needed by
@command{gfsec-use} to reconstruct a splitted file.
Those informations are stored as @code{key=value} pairs, with one such a
pair per line. Blank lines are ignored, as well as lines starting with a
@code{#} character.
The following table lists the allowed keys and their signification:
@table @code
This is the pathname to the file where the reconstructed secret is to be
written. When the configuration file is generated by
@command{gfsec-split}, this defaults to the location of the original
This is the threshold, indicating the lowest number of shares required
to reconstruct the secret.
@item URI
This is an URI representing one of the shares, as described previously in
@ref{The Share URI Syntax}.
@end table
@node Examples
@chapter Examples
This chapter describes some precise use cases for Gfsecret.
* Keeping a GnuPG Master Key Offline::
@end menu
@node Keeping a GnuPG Master Key Offline
@section Keeping a GnuPG Master Key Offline
In this example, Alice has a GnuPG keyring containing a @emph{master
key} and two subkeys: one for signing and one for encryption. Alice only
needs her master key on rare occasions (mainly to certify other people's
keys), and thus wants to keep it offline most of the time.
Note that the following is only possible when using GnuPG 2.1 (or
The first thing Alice has to do is to obtain the @emph{keygrip} of her
master key:
$ gpg2 --list-secret-keys --with-keygrip
sec rsa4096 2016-12-25 [SC] [expires: 2019-12-25]
Keygrip = @emph{47921AA1A41065B89D2790C3EAD88922063E8AA8}
uid [ultimate] Alice Smith <>
ssb rsa2048 2016-12-25 [E] [expires: 2017-12-25]
Keygrip = 543E2A5037F6C5B8C655255CA76DCF5FB0D9C9C0
ssb rsa2048 2016-12-25 [S] [expires: 2017-12-25]
Keygrip = 6BA62F5EFDB16B8F1D7407E12466166FE90424B8
@end example
The master key has the keygrip @code{47921A[...]3E8AA8}. This means
(with GnuPG 2.1) that it is stored in the file
Alice plugs in her removable storage devices and calls
@command{gfsec-split} with the @option{-l} option:
$ gfsec-split -l
file:/// Local filesystem
label://USBKEY/ External volume with label 'USBKEY'
mtp://RF2GB6X704P/ Samsung Galaxy A3
@end example
Alice wants now to split her master key in three shares, one for each of
the available devices. She thus calls @command{gfsec-split} again as
$ gfsec-split -c master \
/home/alice/.gnupg/private-keys-v1.d/47921A[...]3EA88A.key \
file:///home/alice/.local/share/gfsecret/master-key \
label://USBKEY/master-key \
@end example
Here, Alice explicitly sets the name of the configuration file to
generate (with the @option{-c} option). The default behavior of
@command{gfsec-split} would have created a configuration file named with
the 40 characters of the keygrip, which would have been especially
If the command succeeded, Alice can check with GnuPG that her master key
is indeed no longer available:
$ gpg2 --list-secret-keys
sec# rsa4096 2016-12-25 [SC] [expires: 2019-12-25]
uid [ultimate] Alice Smith <>
ssb rsa2048 2016-12-25 [E] [expires: 2017-12-25]
ssb rsa2048 2016-12-25 [S] [expires: 2017-12-25]
@end example
Note the @code{#} symbol following the @code{sec} keyword: it indicates
that the corresponding private key is not available.
Later on, Alice obtains Bob's public key and wants to certify it. For
that, she needs her master private key. In order to reconstruct it, she
calls @command{gfsec-use} with the name of the configuration file she
specified above:
$ gfsec-use -c master
Found share data in file:///home/alice/.local/share/gfsecret/master-key.070
gfsec-use: Cannot reconstitute the secret: Not enough shares available
@end example
The reconstruction attempt failed because @command{gfsec-use} found only
the share stored on the local filesystem. Alice then plugs in one of her
two removable devices and run the same command again:
$ gfsec-use -c master
Found share data in file:///home/alice/.local/share/gfsecret/master-key.070
Found share data in label://USBKEY/master-key.134
@end example
This time, the reconstruction was successful, and Alice is dropped into
a new shell in which she can do everything she needs to do with her
private key. Once she is done, she can quit that shell, and her
reconstructed key will be deleted again:
gfsec> ^D
Removing secret.
@end example
Instead of spawning a shell, Alice could also have directly invoked the
key editor of GnuPG from @command{gfsec-use}'s command line:
$ gfsec-use -c master -- gpg2 --edit-key
@end example
(Note the @code{--}: it is needed to make sure @command{gfsec-use} will
not try to parse options that belongs to @command{gpg2}, such as
@option{--edit-key} in this example.)
@node GNU Free Documentation License
@appendix GNU Free Documentation License
@include fdl.texi
@node Index
@unnumbered Index
@printindex cp


@ -46,6 +46,10 @@ the secret with
.BR gfsec-use (1)
) to the specified file. Default is the basename of
the splitted file in $XDG_CONFIG_HOME/gfsecret.
If \fiFILE\fR is a single filename without extension and
without a directory part, the file will be placed under
the $XDG_CONFIG_HOME/gfsecret directory with a .conf
.BR -i ", " --interactive
Present the user with an interactive menu to specify the


@ -143,7 +143,7 @@ prompt_for_share(gfsec_secret_t *cfg, gfsec_supports_list_t *list, unsigned numb
rc = -1;
printf("Select a support for share #%u:\n\n", number);
for ( i = 0; i < list->count; i++ )
for ( i = 0; (unsigned)i < list->count; i++ )
printf(" (%d) %s\n", i+1, list->supports[i].description);
printf(" (x) Done\n\n");
@ -156,7 +156,7 @@ prompt_for_share(gfsec_secret_t *cfg, gfsec_supports_list_t *list, unsigned numb
int selected;
selected = strtol(answer, NULL, 10);
if ( selected > 0 && selected < list->count ) {
if ( selected > 0 && (unsigned)selected < list->count ) {
path = ask_nonempty("Specify a pathname on this support:");
share = gfsec_share_new();
@ -204,6 +204,23 @@ interactive_loop(gfsec_secret_t *cfg)
errx(EXIT_FAILURE, "Split cancelled");
static void
transform_config_pathname(char **cfg, const char *secret)
char *base = NULL;
if ( ! *cfg )
base = get_file_basename(secret);
else if ( ! strchr(*cfg, '/') && ! strchr(*cfg, '.') )
base = xstrdup(*cfg);
if ( base ) {
xasprintf(cfg, "%s/gfsecret/%s.conf",
getenv("XDG_CONFIG_HOME"), base);
static unsigned
get_uinteger_or_die(const char *arg)
@ -294,7 +311,7 @@ main(int argc, char **argv)
if ( list_mode ) {
gfsec_supports_list_t *list;
char *schemes[] = { "file", "uuid", "label", "mtp" };
int i;
unsigned i;
list = gfsec_scheme_module_get_supports();
@ -319,15 +336,9 @@ main(int argc, char **argv)
errx(EXIT_FAILURE, "Missing secret file");
secret_file = argv[optind++];
if ( ! config_path ) {
char *base;
base = get_file_basename(secret_file);
xasprintf(&config_path, "%s/gfsecret/%s.conf",
getenv("XDG_CONFIG_HOME"), base);
transform_config_pathname(&config_path, secret_file);
if ( file_exists(config_path) != -1 )
errx(EXIT_FAILURE, "Configuration file %s already exists", config_path);
if ( (c = gfsec_secret_set_secret_file(cfg, secret_file)) != 0 )
errx(EXIT_FAILURE, "Cannot set secret: %s", gfsec_error_string(c));


@ -54,7 +54,9 @@ find_mtp_device(const char *wanted_serial)
for ( i = 0, device = NULL; i < n && device == NULL; i++ ) {
char *serial;
device = LIBMTP_Open_Raw_Device_Uncached(&(raw_devices[i]));
if ( ! (device = LIBMTP_Open_Raw_Device_Uncached(&(raw_devices[i]))) )
if ( (serial = LIBMTP_Get_Serialnumber(device)) == NULL ||
strcmp(serial, wanted_serial) != 0 ) {
@ -400,7 +402,9 @@ gfsec_scheme_libmtp_get_supports(gfsec_supports_list_t *list)
for ( i = 0, device = NULL; i < n && device == NULL; i++ ) {
char *serial, *name;
device = LIBMTP_Open_Raw_Device_Uncached(&(raw_devices[i]));
if ( ! (device = LIBMTP_Open_Raw_Device_Uncached(&(raw_devices[i]))) )
serial = LIBMTP_Get_Serialnumber(device);
name = LIBMTP_Get_Friendlyname(device);