|
|
|
@ -24,10 +24,13 @@
|
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <errno.h> |
|
|
|
|
#include <sys/mman.h> |
|
|
|
|
|
|
|
|
|
#include <getopt.h> |
|
|
|
|
#include <err.h> |
|
|
|
|
|
|
|
|
|
#include <libgfshare.h> |
|
|
|
|
|
|
|
|
|
#include "util.h" |
|
|
|
|
#include "share.h" |
|
|
|
|
#include "secretcfg.h" |
|
|
|
@ -218,6 +221,66 @@ main(int argc, char **argv)
|
|
|
|
|
share = share->next; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( have_full ) { |
|
|
|
|
share = cfg->shares; |
|
|
|
|
while ( share ) { |
|
|
|
|
if ( share->data && (share->flags & GFSEC_SHARE_FLAGS_FULL) > 0 ) |
|
|
|
|
break; |
|
|
|
|
share = share->next; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
printf("Using full data in %s\n", get_share_display_name(share)); |
|
|
|
|
if ( write_file(cfg->output_file, share->data, share->length) == -1 ) |
|
|
|
|
err(EXIT_FAILURE, "Cannot write secret"); |
|
|
|
|
} |
|
|
|
|
else if ( have_shares >= cfg->threshold ) { |
|
|
|
|
gfshare_ctx *ctx; |
|
|
|
|
unsigned char sharenrs[255], *secret; |
|
|
|
|
unsigned n, size; |
|
|
|
|
|
|
|
|
|
n = size = 0; |
|
|
|
|
share = cfg->shares; |
|
|
|
|
while ( share ) { |
|
|
|
|
if ( share->data && share->share_nr > 0 ) { |
|
|
|
|
sharenrs[n++] = share->share_nr; |
|
|
|
|
|
|
|
|
|
if ( size == 0 ) |
|
|
|
|
size = share->length; |
|
|
|
|
else if ( size != share->length ) |
|
|
|
|
errx(EXIT_FAILURE, "Shares have different sizes"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
share = share->next; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( ! (secret = malloc(size)) || mlock(secret, size) == -1 ) |
|
|
|
|
err(EXIT_FAILURE, "Cannot allocated mlocked memory"); |
|
|
|
|
|
|
|
|
|
if ( ! (ctx = gfshare_ctx_init_dec(sharenrs, n, size)) ) |
|
|
|
|
errx(EXIT_FAILURE, "Cannot initialize libgfshare context"); |
|
|
|
|
|
|
|
|
|
n = 0; |
|
|
|
|
share = cfg->shares; |
|
|
|
|
while ( share ) { |
|
|
|
|
if ( share->data && share->share_nr > 0 ) { |
|
|
|
|
printf("using share data in %s\n", get_share_display_name(share)); |
|
|
|
|
gfshare_ctx_dec_giveshare(ctx, n++, share->data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
share = share->next; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gfshare_ctx_dec_extract(ctx, secret); |
|
|
|
|
if ( write_file(cfg->output_file, secret, size) == -1 ) |
|
|
|
|
err(EXIT_FAILURE, "Cannot write secret"); |
|
|
|
|
|
|
|
|
|
memset(secret, 0, size); |
|
|
|
|
munlock(secret, size); |
|
|
|
|
free(secret); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
errx(EXIT_FAILURE, "Not enough data to reconstitute secret"); |
|
|
|
|
|
|
|
|
|
gfsec_destroy_config(cfg); |
|
|
|
|
|
|
|
|
|
return EXIT_SUCCESS; |
|
|
|
|