mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-14 21:47:19 +02:00
changed structure of trustdb
This commit is contained in:
parent
3bcd3cd7b2
commit
c8f12e218f
28 changed files with 2323 additions and 979 deletions
176
g10/g10.c
176
g10/g10.c
|
@ -42,18 +42,15 @@
|
|||
|
||||
|
||||
enum cmd_values { aNull = 0,
|
||||
aSym, aStore, aEncr, aPrimegen, aKeygen, aSign, aSignEncr,
|
||||
aPrintMDs, aSignKey, aClearsig, aListPackets, aEditSig,
|
||||
aKMode, aKModeC, aChangePass, aImport, aListTrustDB,
|
||||
aListTrustPath, aExport,
|
||||
aSym, aStore, aEncr, aKeygen, aSign, aSignEncr,
|
||||
aSignKey, aClearsig, aListPackets, aEditSig,
|
||||
aKMode, aKModeC, aChangePass, aImport,
|
||||
aExport,
|
||||
aTest };
|
||||
|
||||
|
||||
static void set_cmd( enum cmd_values *ret_cmd,
|
||||
enum cmd_values new_cmd );
|
||||
static void print_hex( byte *p, size_t n );
|
||||
static void print_mds( const char *fname );
|
||||
static void do_test(int);
|
||||
|
||||
const char *
|
||||
strusage( int level )
|
||||
|
@ -104,7 +101,7 @@ strusage( int level )
|
|||
static void
|
||||
i18n_init(void)
|
||||
{
|
||||
#ifdef HAVE_LIBINTL
|
||||
#ifdef ENABLE_NLS
|
||||
setlocale( LC_MESSAGES, "" );
|
||||
bindtextdomain( PACKAGE, G10_LOCALEDIR );
|
||||
textdomain( PACKAGE );
|
||||
|
@ -189,10 +186,7 @@ main( int argc, char **argv )
|
|||
{ 510, "debug" ,4|16, N_("set debugging flags")},
|
||||
{ 511, "debug-all" ,0, N_("enable full debugging")},
|
||||
{ 512, "status-fd" ,1, N_("write status info to this fd") },
|
||||
{ 513, "gen-prime" , 0, "\r" },
|
||||
{ 514, "test" , 0, "\r" },
|
||||
{ 515, "fingerprint", 0, N_("show the fingerprints")},
|
||||
{ 516, "print-mds" , 0, N_("print all message digests")},
|
||||
{ 517, "secret-keyring" ,2, N_("add this secret keyring to the list")},
|
||||
{ 518, "options" , 2, N_("read options from file")},
|
||||
{ 519, "no-armor", 0, "\r"},
|
||||
|
@ -207,13 +201,12 @@ main( int argc, char **argv )
|
|||
{ 528, "pubkey-algo", 2 , N_("select default puplic key algorithm")},
|
||||
{ 529, "digest-algo", 2 , N_("select default message digest algorithm")},
|
||||
{ 530, "import", 0 , N_("put public keys into the trustdb")},
|
||||
{ 531, "list-trustdb",0 , "\r"},
|
||||
{ 532, "quick-random", 0, "\r"},
|
||||
{ 533, "list-trust-path",0, "\r"},
|
||||
{ 534, "no-comment", 0, N_("do not write comment packets")},
|
||||
{ 535, "completes-needed", 1, N_("(default is 1)")},
|
||||
{ 536, "marginals-needed", 1, N_("(default is 3)")},
|
||||
{ 537, "export", 0, N_("export all or the given keys") },
|
||||
{ 538, "trustdb-name", 2, "\r" },
|
||||
|
||||
{0} };
|
||||
ARGPARSE_ARGS pargs;
|
||||
|
@ -236,6 +229,7 @@ main( int argc, char **argv )
|
|||
int default_keyring = 1;
|
||||
int greeting = 1;
|
||||
enum cmd_values cmd = 0;
|
||||
const char *trustdb_name = NULL;
|
||||
|
||||
|
||||
secmem_init( 16384 );
|
||||
|
@ -331,10 +325,7 @@ main( int argc, char **argv )
|
|||
case 510: opt.debug |= pargs.r.ret_ulong; break;
|
||||
case 511: opt.debug = ~0; break;
|
||||
case 512: set_status_fd( pargs.r.ret_int ); break;
|
||||
case 513: set_cmd( &cmd, aPrimegen); break;
|
||||
case 514: set_cmd( &cmd, aTest); break;
|
||||
case 515: opt.fingerprint = 1; break;
|
||||
case 516: set_cmd( &cmd, aPrintMDs); break;
|
||||
case 517: add_secret_keyring(pargs.r.ret_str); sec_nrings++; break;
|
||||
case 518:
|
||||
/* config files may not be nested (silently ignore them) */
|
||||
|
@ -362,13 +353,12 @@ main( int argc, char **argv )
|
|||
opt.def_digest_algo = string_to_digest_algo(pargs.r.ret_str);
|
||||
break;
|
||||
case 530: set_cmd( &cmd, aImport); break;
|
||||
case 531: set_cmd( &cmd, aListTrustDB); break;
|
||||
case 532: quick_random_gen(1); break;
|
||||
case 533: set_cmd( &cmd, aListTrustPath); break;
|
||||
case 534: opt.no_comment=1; break;
|
||||
case 535: opt.completes_needed = pargs.r.ret_int; break;
|
||||
case 536: opt.marginals_needed = pargs.r.ret_int; break;
|
||||
case 537: set_cmd( &cmd, aExport); break;
|
||||
case 538: trustdb_name = pargs.r.ret_str; break;
|
||||
default : errors++; pargs.err = configfp? 1:2; break;
|
||||
}
|
||||
}
|
||||
|
@ -453,13 +443,7 @@ main( int argc, char **argv )
|
|||
}
|
||||
}
|
||||
|
||||
switch( cmd ) {
|
||||
case aPrimegen:
|
||||
case aPrintMDs:
|
||||
break;
|
||||
case aListTrustDB: rc = init_trustdb( argc? 1:0 ); break;
|
||||
default: rc = init_trustdb(1); break;
|
||||
}
|
||||
rc = init_trustdb(1, trustdb_name );
|
||||
if( rc )
|
||||
log_error(_("failed to initialize the TrustDB: %s\n"), g10_errstr(rc));
|
||||
|
||||
|
@ -578,46 +562,12 @@ main( int argc, char **argv )
|
|||
usage(1);
|
||||
break;
|
||||
|
||||
case aPrimegen:
|
||||
if( argc == 1 ) {
|
||||
mpi_print( stdout, generate_public_prime( atoi(argv[0]) ), 1);
|
||||
putchar('\n');
|
||||
}
|
||||
else if( argc == 2 ) {
|
||||
mpi_print( stdout, generate_elg_prime( atoi(argv[0]),
|
||||
atoi(argv[1]), NULL ), 1);
|
||||
putchar('\n');
|
||||
}
|
||||
else if( argc == 3 ) {
|
||||
MPI g = mpi_alloc(1);
|
||||
mpi_print( stdout, generate_elg_prime( atoi(argv[0]),
|
||||
atoi(argv[1]), g ), 1);
|
||||
printf("\nGenerator: ");
|
||||
mpi_print( stdout, g, 1 );
|
||||
putchar('\n');
|
||||
mpi_free(g);
|
||||
}
|
||||
else
|
||||
usage(1);
|
||||
break;
|
||||
|
||||
case aPrintMDs:
|
||||
if( !argc )
|
||||
print_mds(NULL);
|
||||
else {
|
||||
for(; argc; argc--, argv++ )
|
||||
print_mds(*argv);
|
||||
}
|
||||
break;
|
||||
|
||||
case aKeygen: /* generate a key (interactive) */
|
||||
if( argc )
|
||||
usage(1);
|
||||
generate_keypair();
|
||||
break;
|
||||
|
||||
case aTest: do_test( argc? atoi(*argv): 0 ); break;
|
||||
|
||||
case aImport:
|
||||
if( !argc )
|
||||
usage(1);
|
||||
|
@ -637,22 +587,6 @@ main( int argc, char **argv )
|
|||
free_strlist(sl);
|
||||
break;
|
||||
|
||||
|
||||
case aListTrustDB:
|
||||
if( !argc )
|
||||
list_trustdb(NULL);
|
||||
else {
|
||||
for( ; argc; argc--, argv++ )
|
||||
list_trustdb( *argv );
|
||||
}
|
||||
break;
|
||||
|
||||
case aListTrustPath:
|
||||
if( argc != 2 )
|
||||
wrong_args("--list-trust-path [-- -]<maxdepth> <username>");
|
||||
list_trust_path( atoi(*argv), argv[1] );
|
||||
break;
|
||||
|
||||
case aListPackets:
|
||||
opt.list_packets=1;
|
||||
default:
|
||||
|
@ -693,95 +627,3 @@ g10_exit( int rc )
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
print_hex( byte *p, size_t n )
|
||||
{
|
||||
int i;
|
||||
|
||||
if( n == 20 ) {
|
||||
for(i=0; i < n ; i++, i++, p += 2 ) {
|
||||
if( i == 10 )
|
||||
putchar(' ');
|
||||
printf(" %02X%02X", *p, p[1] );
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i=0; i < n ; i++, p++ ) {
|
||||
if( i && !(i%8) )
|
||||
putchar(' ');
|
||||
printf(" %02X", *p );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_mds( const char *fname )
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[1024];
|
||||
size_t n;
|
||||
MD_HANDLE md;
|
||||
|
||||
if( !fname ) {
|
||||
fp = stdin;
|
||||
fname = "[stdin]";
|
||||
}
|
||||
else
|
||||
fp = fopen( fname, "rb" );
|
||||
if( !fp ) {
|
||||
log_error("%s: %s\n", fname, strerror(errno) );
|
||||
return;
|
||||
}
|
||||
|
||||
md = md_open( DIGEST_ALGO_MD5, 0 );
|
||||
md_enable( md, DIGEST_ALGO_RMD160 );
|
||||
md_enable( md, DIGEST_ALGO_SHA1 );
|
||||
|
||||
while( (n=fread( buf, 1, DIM(buf), fp )) )
|
||||
md_write( md, buf, n );
|
||||
if( ferror(fp) )
|
||||
log_error("%s: %s\n", fname, strerror(errno) );
|
||||
else {
|
||||
md_final(md);
|
||||
printf( "%s: MD5 =", fname ); print_hex(md_read(md, DIGEST_ALGO_MD5), 16 );
|
||||
printf("\n%s: RMD160 =", fname ); print_hex(md_read(md, DIGEST_ALGO_RMD160), 20 );
|
||||
printf("\n%s: SHA1 =", fname ); print_hex(md_read(md, DIGEST_ALGO_SHA1), 20 );
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
||||
md_close(md);
|
||||
|
||||
if( fp != stdin )
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
do_test(int times)
|
||||
{
|
||||
#if 0
|
||||
MPI t = mpi_alloc( 50 );
|
||||
MPI m = mpi_alloc( 50 );
|
||||
MPI a = mpi_alloc( 50 );
|
||||
MPI b = mpi_alloc( 50 );
|
||||
MPI p = mpi_alloc( 50 );
|
||||
MPI x = mpi_alloc( 50 );
|
||||
|
||||
/* output = b/(a^x) mod p */
|
||||
log_debug("invm %d times ", times);
|
||||
for( ; times > 0; times -- ) {
|
||||
mpi_fromstr(a, "0xef45678343589854354a4545545454554545455"
|
||||
"aaaaaaaaaaaaa44444fffdecb33434343443331" );
|
||||
mpi_fromstr(b, "0x8765765589854354a4545545454554545455"
|
||||
"aaaaaaa466577778decb36666343443331" );
|
||||
mpi_invm( t, a, b );
|
||||
fputc('.', stderr); fflush(stderr);
|
||||
}
|
||||
|
||||
|
||||
m_check(NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue