importCertificate( const char* fpr )
This commit is contained in:
parent
da40b7130f
commit
3debbf008e
@ -1,3 +1,8 @@
|
|||||||
|
2002-06-25 Steffen Hansen <steffen@hrhansen.dk>
|
||||||
|
|
||||||
|
* cryptplug.h, gpgmeplug.c: New function importCertificate() for importing a
|
||||||
|
certificate from the temp. db to the real one given a fingerprint.
|
||||||
|
|
||||||
2002-06-20 Werner Koch <wk@gnupg.org>
|
2002-06-20 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
* gpgmeplug.c (reorder_dn): Added missing stdpart list terminator.
|
* gpgmeplug.c (reorder_dn): Added missing stdpart list terminator.
|
||||||
|
@ -1820,7 +1820,7 @@ struct CertificateInfo {
|
|||||||
Example that runs through certs matching "Steffen":
|
Example that runs through certs matching "Steffen":
|
||||||
\verbatim
|
\verbatim
|
||||||
struct CertificateInfo* info;
|
struct CertificateInfo* info;
|
||||||
struct CertIterator* it = startListCertificates("Steffen");
|
struct CertIterator* it = startListCertificates("Steffen", 0 );
|
||||||
while( nextCertificate( it, &info ) == GPGME_No_Error && info ) {
|
while( nextCertificate( it, &info ) == GPGME_No_Error && info ) {
|
||||||
do something with info.
|
do something with info.
|
||||||
dont free() it, the struct will be reused
|
dont free() it, the struct will be reused
|
||||||
@ -1829,10 +1829,23 @@ struct CertificateInfo {
|
|||||||
endListCertificates( it );
|
endListCertificates( it );
|
||||||
\endverbatim
|
\endverbatim
|
||||||
*/
|
*/
|
||||||
struct CertIterator* startListCertificates( const char* pattern, int remote );
|
struct CertIterator*
|
||||||
int nextCertificate( struct CertIterator*, struct CertificateInfo** result );
|
startListCertificates( const char* pattern, int remote );
|
||||||
void endListCertificates( struct CertIterator* );
|
|
||||||
|
|
||||||
|
int
|
||||||
|
nextCertificate( struct CertIterator*, struct CertificateInfo** result );
|
||||||
|
|
||||||
|
void
|
||||||
|
endListCertificates( struct CertIterator* );
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Import a certificate that was a result from a search-operation using the startListCertificates(), nextCertificate() funtions.
|
||||||
|
|
||||||
|
The fingerprint must be passed to identify the key.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
importCertificate( const char* fingerprint );
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1856,7 +1856,8 @@ void updateCRL(){}
|
|||||||
#define safe_malloc( x ) malloc( x )
|
#define safe_malloc( x ) malloc( x )
|
||||||
#define xstrdup( x ) (x)?strdup(x):0
|
#define xstrdup( x ) (x)?strdup(x):0
|
||||||
|
|
||||||
static void safe_free( void** x )
|
static void
|
||||||
|
safe_free( void** x )
|
||||||
{
|
{
|
||||||
free( *x );
|
free( *x );
|
||||||
*x = 0;
|
*x = 0;
|
||||||
@ -2040,7 +2041,8 @@ parse_dn (const unsigned char *string)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int add_dn_part( char* result, struct DnPair* dn, const char* part )
|
static int
|
||||||
|
add_dn_part( char* result, struct DnPair* dn, const char* part )
|
||||||
{
|
{
|
||||||
int any = 0;
|
int any = 0;
|
||||||
|
|
||||||
@ -2058,7 +2060,8 @@ static int add_dn_part( char* result, struct DnPair* dn, const char* part )
|
|||||||
return any;
|
return any;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* reorder_dn( struct DnPair *dn )
|
static char*
|
||||||
|
reorder_dn( struct DnPair *dn )
|
||||||
{
|
{
|
||||||
// note: The must parts are: CN, L, OU, O, C
|
// note: The must parts are: CN, L, OU, O, C
|
||||||
const char* stdpart[] = {
|
const char* stdpart[] = {
|
||||||
@ -2111,7 +2114,8 @@ struct CertIterator {
|
|||||||
struct CertificateInfo info;
|
struct CertificateInfo info;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CertIterator* startListCertificates( const char* pattern, int remote )
|
struct CertIterator*
|
||||||
|
startListCertificates( const char* pattern, int remote )
|
||||||
{
|
{
|
||||||
GpgmeError err;
|
GpgmeError err;
|
||||||
struct CertIterator* it;
|
struct CertIterator* it;
|
||||||
@ -2139,7 +2143,8 @@ struct CertIterator* startListCertificates( const char* pattern, int remote )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* free() each string in a char*[] and the array itself */
|
/* free() each string in a char*[] and the array itself */
|
||||||
static void freeStringArray( char** c )
|
static void
|
||||||
|
freeStringArray( char** c )
|
||||||
{
|
{
|
||||||
char** _c = c;
|
char** _c = c;
|
||||||
while( c && *c ) {
|
while( c && *c ) {
|
||||||
@ -2151,7 +2156,8 @@ static void freeStringArray( char** c )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* free all malloc'ed data in a struct CertificateInfo */
|
/* free all malloc'ed data in a struct CertificateInfo */
|
||||||
static void freeInfo( struct CertificateInfo* info )
|
static void
|
||||||
|
freeInfo( struct CertificateInfo* info )
|
||||||
{
|
{
|
||||||
struct DnPair* a = info->dnarray;
|
struct DnPair* a = info->dnarray;
|
||||||
assert( info );
|
assert( info );
|
||||||
@ -2188,7 +2194,8 @@ static char* make_fingerprint( const char* fpr )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nextCertificate( struct CertIterator* it, struct CertificateInfo** result )
|
int
|
||||||
|
nextCertificate( struct CertIterator* it, struct CertificateInfo** result )
|
||||||
{
|
{
|
||||||
GpgmeError err;
|
GpgmeError err;
|
||||||
GpgmeKey key;
|
GpgmeKey key;
|
||||||
@ -2276,7 +2283,8 @@ int nextCertificate( struct CertIterator* it, struct CertificateInfo** result )
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void endListCertificates( struct CertIterator* it )
|
void
|
||||||
|
endListCertificates( struct CertIterator* it )
|
||||||
{
|
{
|
||||||
/*fprintf( stderr, "endListCertificates()\n" );*/
|
/*fprintf( stderr, "endListCertificates()\n" );*/
|
||||||
assert(it);
|
assert(it);
|
||||||
@ -2286,7 +2294,92 @@ void endListCertificates( struct CertIterator* it )
|
|||||||
free( it );
|
free( it );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
importCertificate( const char* fingerprint )
|
||||||
|
{
|
||||||
|
GpgmeError err;
|
||||||
|
GpgmeCtx ctx;
|
||||||
|
GpgmeData keydata;
|
||||||
|
GpgmeRecipients recips;
|
||||||
|
/*
|
||||||
|
char* buf;
|
||||||
|
char* tmp1;
|
||||||
|
char* tmp2;
|
||||||
|
*/
|
||||||
|
err = gpgme_new( &ctx );
|
||||||
|
/*fprintf( stderr, "2: gpgme returned %d\n", err );*/
|
||||||
|
if( err != GPGME_No_Error ) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = gpgme_data_new( &keydata );
|
||||||
|
if( err ) {
|
||||||
|
fprintf( stderr, "gpgme_data_new returned %d\n", err );
|
||||||
|
gpgme_release( ctx );
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = gpgme_recipients_new( &recips );
|
||||||
|
if( err ) {
|
||||||
|
fprintf( stderr, "gpgme_recipients_new returned %d\n", err );
|
||||||
|
gpgme_data_release( keydata );
|
||||||
|
gpgme_release( ctx );
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
buf = safe_malloc( sizeof(char)*( strlen( fingerprint ) + 1 ) );
|
||||||
|
if( !buf ) {
|
||||||
|
gpgme_recipients_release( recips );
|
||||||
|
gpgme_data_release( keydata );
|
||||||
|
gpgme_release( ctx );
|
||||||
|
return GPGME_Out_Of_Core;
|
||||||
|
}
|
||||||
|
tmp1 = fingerprint;
|
||||||
|
tmp2 = buf;
|
||||||
|
while( *tmp1 ) {
|
||||||
|
if( *tmp1 != ':' ) *tmp2++ = *tmp1;
|
||||||
|
tmp1++;
|
||||||
|
}
|
||||||
|
*tmp2 = 0;
|
||||||
|
fprintf( stderr, "calling gpgme_recipients_add_name( %s )\n", buf );
|
||||||
|
*/
|
||||||
|
|
||||||
|
err = gpgme_recipients_add_name( recips, fingerprint );
|
||||||
|
if( err ) {
|
||||||
|
fprintf( stderr, "gpgme_recipients_add_name returned %d\n", err );
|
||||||
|
/*safe_free( (void**)&buf );*/
|
||||||
|
gpgme_recipients_release( recips );
|
||||||
|
gpgme_data_release( keydata );
|
||||||
|
gpgme_release( ctx );
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = gpgme_op_export( ctx, recips, keydata );
|
||||||
|
if( err ) {
|
||||||
|
fprintf( stderr, "gpgme_op_export returned %d\n", err );
|
||||||
|
/*safe_free( (void**)&buf );*/
|
||||||
|
gpgme_recipients_release( recips );
|
||||||
|
gpgme_data_release( keydata );
|
||||||
|
gpgme_release( ctx );
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
/*safe_free( (void**)&buf );*/
|
||||||
|
|
||||||
|
err = gpgme_op_import( ctx, keydata );
|
||||||
|
if( err ) {
|
||||||
|
fprintf( stderr, "gpgme_op_import returned %d\n", err );
|
||||||
|
gpgme_recipients_release( recips );
|
||||||
|
gpgme_data_release( keydata );
|
||||||
|
gpgme_release( ctx );
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
gpgme_recipients_release( recips );
|
||||||
|
gpgme_data_release( keydata );
|
||||||
|
gpgme_release( ctx );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// // // // // // // // // // // // // // // // // // // // // // // // //
|
// // // // // // // // // // // // // // // // // // // // // // // // //
|
||||||
// //
|
// //
|
||||||
|
Loading…
Reference in New Issue
Block a user