mirror of
git://git.gnupg.org/gnupg.git
synced 2025-03-28 22:49:59 +01:00
agent: Do not consider --min-passphrase-len for the magic wand.
* agent/call-pinentry.c (generate_pin): Lock to exactly 30 octets. * g10/gpg.c (main) <aGenRandom>: Add Level 30. (cherry picked from commit ae2f1f0785e429d6dbb577a1fcf9a880aaff8e49)
This commit is contained in:
parent
1d8191faee
commit
af9a1b5599
@ -57,7 +57,9 @@
|
|||||||
* passphrase will be rendered as zbase32 which results for 150 bits
|
* passphrase will be rendered as zbase32 which results for 150 bits
|
||||||
* in a string of 30 characters. That fits nicely into the 5
|
* in a string of 30 characters. That fits nicely into the 5
|
||||||
* character blocking which pinentry can do. 128 bits would actually
|
* character blocking which pinentry can do. 128 bits would actually
|
||||||
* be sufficient but can't be formatted nicely. */
|
* be sufficient but can't be formatted nicely. Please do not change
|
||||||
|
* this value because pattern check files may let such passwords
|
||||||
|
* always pass. */
|
||||||
#define DEFAULT_GENPIN_BITS 150
|
#define DEFAULT_GENPIN_BITS 150
|
||||||
|
|
||||||
/* The assuan context of the current pinentry. */
|
/* The assuan context of the current pinentry. */
|
||||||
@ -834,21 +836,20 @@ estimate_passphrase_quality (const char *pw)
|
|||||||
|
|
||||||
|
|
||||||
/* Generate a random passphrase in zBase32 encoding (RFC-6189) to be
|
/* Generate a random passphrase in zBase32 encoding (RFC-6189) to be
|
||||||
* used by Pinentry to suggest a passphrase. */
|
* used by Pinentry to suggest a passphrase. Note that we have the
|
||||||
|
* same algorithm in gpg.c for --gen-random at level 30. It is
|
||||||
|
* important that we always output exactly 30 characters to match the
|
||||||
|
* special exception we have in the pattern file for symmetric
|
||||||
|
* encryption. */
|
||||||
static char *
|
static char *
|
||||||
generate_pin (void)
|
generate_pin (void)
|
||||||
{
|
{
|
||||||
unsigned int nbits = opt.min_passphrase_len * 8;
|
unsigned int nbits = DEFAULT_GENPIN_BITS;
|
||||||
size_t nbytes;
|
size_t nbytes = nbytes = (nbits + 7) / 8;
|
||||||
void *rand;
|
void *rand;
|
||||||
char *generated;
|
char *generated;
|
||||||
|
|
||||||
if (nbits < 128)
|
rand = gcry_random_bytes_secure (nbytes, GCRY_STRONG_RANDOM);
|
||||||
nbits = DEFAULT_GENPIN_BITS;
|
|
||||||
|
|
||||||
nbytes = (nbits + 7) / 8;
|
|
||||||
|
|
||||||
rand = gcry_random_bytes_secure (nbytes, GCRY_STRONG_RANDOM);
|
|
||||||
if (!rand)
|
if (!rand)
|
||||||
{
|
{
|
||||||
log_error ("failed to generate random pin\n");
|
log_error ("failed to generate random pin\n");
|
||||||
|
@ -609,13 +609,14 @@ Print message digest of algorithm @var{algo} for all given files or STDIN.
|
|||||||
With the second form (or a deprecated "*" for @var{algo}) digests for all
|
With the second form (or a deprecated "*" for @var{algo}) digests for all
|
||||||
available algorithms are printed.
|
available algorithms are printed.
|
||||||
|
|
||||||
@item --gen-random @var{0|1|2} @var{count}
|
@item --gen-random @var{0|1|2|16|30} @var{count}
|
||||||
@opindex gen-random
|
@opindex gen-random
|
||||||
Emit @var{count} random bytes of the given quality level 0, 1 or 2. If
|
Emit @var{count} random bytes of the given quality level 0, 1 or 2. If
|
||||||
@var{count} is not given or zero, an endless sequence of random bytes
|
@var{count} is not given or zero, an endless sequence of random bytes
|
||||||
will be emitted. If used with @option{--armor} the output will be
|
will be emitted. If used with @option{--armor} the output will be
|
||||||
base64 encoded. PLEASE, don't use this command unless you know what
|
base64 encoded. The special level 16 uses a quality level of 1 and
|
||||||
you are doing; it may remove precious entropy from the system!
|
outputs and endless stream of hex-encoded octets. The special level
|
||||||
|
30 outputs random as 30 zBase-32 characters.
|
||||||
|
|
||||||
@item --gen-prime @var{mode} @var{bits}
|
@item --gen-prime @var{mode} @var{bits}
|
||||||
@opindex gen-prime
|
@opindex gen-prime
|
||||||
|
24
g10/gpg.c
24
g10/gpg.c
@ -62,6 +62,7 @@
|
|||||||
#include "tofu.h"
|
#include "tofu.h"
|
||||||
#include "../common/init.h"
|
#include "../common/init.h"
|
||||||
#include "../common/mbox-util.h"
|
#include "../common/mbox-util.h"
|
||||||
|
#include "../common/zb32.h"
|
||||||
#include "../common/shareddefs.h"
|
#include "../common/shareddefs.h"
|
||||||
#include "../common/compliance.h"
|
#include "../common/compliance.h"
|
||||||
|
|
||||||
@ -4910,8 +4911,29 @@ main (int argc, char **argv)
|
|||||||
if (hexhack)
|
if (hexhack)
|
||||||
level = 1;
|
level = 1;
|
||||||
|
|
||||||
|
/* Level 30 uses the same algorithm as our magic wand in
|
||||||
|
* pinentry/gpg-agent. */
|
||||||
|
if (level == 30)
|
||||||
|
{
|
||||||
|
unsigned int nbits = 150;
|
||||||
|
size_t nbytes = (nbits + 7) / 8;
|
||||||
|
void *rand;
|
||||||
|
char *generated;
|
||||||
|
|
||||||
|
rand = gcry_random_bytes_secure (nbytes, GCRY_STRONG_RANDOM);
|
||||||
|
if (!rand)
|
||||||
|
log_fatal ("failed to generate random password\n");
|
||||||
|
|
||||||
|
generated = zb32_encode (rand, nbits);
|
||||||
|
gcry_free (rand);
|
||||||
|
es_fputs (generated, es_stdout);
|
||||||
|
es_putc ('\n', es_stdout);
|
||||||
|
xfree (generated);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (argc < 1 || argc > 2 || level < 0 || level > 2 || count < 0)
|
if (argc < 1 || argc > 2 || level < 0 || level > 2 || count < 0)
|
||||||
wrong_args ("--gen-random 0|1|2 [count]");
|
wrong_args ("--gen-random 0|1|2|16|30 [count]");
|
||||||
|
|
||||||
while (endless || count)
|
while (endless || count)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user