2001-11-07 17:44:22 +00:00
|
|
|
|
/* import.c - Import certificates
|
|
|
|
|
* Copyright (C) 2001 Free Software Foundation, Inc.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
|
*
|
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
2001-11-10 18:08:10 +00:00
|
|
|
|
#include <gcrypt.h>
|
2001-11-07 17:44:22 +00:00
|
|
|
|
#include <ksba.h>
|
|
|
|
|
|
|
|
|
|
#include "gpgsm.h"
|
2001-11-13 12:50:14 +00:00
|
|
|
|
#include "keydb.h"
|
|
|
|
|
#include "i18n.h"
|
2001-11-07 17:44:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2001-11-19 12:42:01 +00:00
|
|
|
|
gpgsm_import (CTRL ctrl, int in_fd)
|
2001-11-07 17:44:22 +00:00
|
|
|
|
{
|
|
|
|
|
int rc;
|
2001-11-27 17:40:09 +00:00
|
|
|
|
Base64Context b64reader = NULL;
|
|
|
|
|
KsbaReader reader;
|
2001-11-07 17:44:22 +00:00
|
|
|
|
KsbaCert cert = NULL;
|
2001-11-27 17:40:09 +00:00
|
|
|
|
FILE *fp = NULL;
|
2001-11-07 17:44:22 +00:00
|
|
|
|
|
2001-11-27 17:40:09 +00:00
|
|
|
|
fp = fdopen ( dup (in_fd), "rb");
|
|
|
|
|
if (!fp)
|
2001-11-07 17:44:22 +00:00
|
|
|
|
{
|
|
|
|
|
log_error ("fdopen() failed: %s\n", strerror (errno));
|
|
|
|
|
rc = seterr (IO_Error);
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-27 17:40:09 +00:00
|
|
|
|
rc = gpgsm_create_reader (&b64reader, ctrl, fp, &reader);
|
2001-11-07 17:44:22 +00:00
|
|
|
|
if (rc)
|
|
|
|
|
{
|
2001-11-27 17:40:09 +00:00
|
|
|
|
log_error ("can't create reader: %s\n", gnupg_strerror (rc));
|
2001-11-07 17:44:22 +00:00
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cert = ksba_cert_new ();
|
|
|
|
|
if (!cert)
|
|
|
|
|
{
|
|
|
|
|
rc = seterr (Out_Of_Core);
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = ksba_cert_read_der (cert, reader);
|
|
|
|
|
if (rc)
|
|
|
|
|
{
|
|
|
|
|
rc = map_ksba_err (rc);
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-15 13:02:47 +00:00
|
|
|
|
if ( !gpgsm_basic_cert_check (cert) )
|
|
|
|
|
keydb_store_cert (cert);
|
2001-11-07 17:44:22 +00:00
|
|
|
|
|
|
|
|
|
leave:
|
|
|
|
|
ksba_cert_release (cert);
|
2001-11-27 17:40:09 +00:00
|
|
|
|
gpgsm_destroy_reader (b64reader);
|
|
|
|
|
if (fp)
|
|
|
|
|
fclose (fp);
|
2001-11-07 17:44:22 +00:00
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-13 12:50:14 +00:00
|
|
|
|
|