2002-06-29 15:46:34 +02:00
|
|
|
/* photoid.c - photo ID handling code
|
2005-08-31 20:40:39 +02:00
|
|
|
* Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
|
2002-06-29 15:46:34 +02:00
|
|
|
*
|
|
|
|
* 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
|
2005-05-31 10:39:18 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
2002-06-29 15:46:34 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2003-08-29 02:14:42 +02:00
|
|
|
#ifdef _WIN32
|
2002-06-30 09:40:40 +02:00
|
|
|
# include <windows.h>
|
|
|
|
# ifndef VER_PLATFORM_WIN32_WINDOWS
|
|
|
|
# define VER_PLATFORM_WIN32_WINDOWS 1
|
|
|
|
# endif
|
2002-06-29 15:46:34 +02:00
|
|
|
#endif
|
|
|
|
#include "packet.h"
|
|
|
|
#include "status.h"
|
|
|
|
#include "exec.h"
|
|
|
|
#include "keydb.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "i18n.h"
|
|
|
|
#include "iobuf.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "options.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "photoid.h"
|
2004-09-09 14:42:10 +02:00
|
|
|
#include "ttyio.h"
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
/* Generate a new photo id packet, or return NULL if canceled */
|
2005-08-31 20:40:39 +02:00
|
|
|
PKT_user_id *
|
|
|
|
generate_photo_id(PKT_public_key *pk)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
PKT_user_id *uid;
|
|
|
|
int error=1,i;
|
|
|
|
unsigned int len;
|
|
|
|
char *filename=NULL;
|
|
|
|
byte *photo=NULL;
|
|
|
|
byte header[16];
|
|
|
|
IOBUF file;
|
|
|
|
|
|
|
|
header[0]=0x10; /* little side of photo header length */
|
|
|
|
header[1]=0; /* big side of photo header length */
|
|
|
|
header[2]=1; /* 1 == version of photo header */
|
|
|
|
header[3]=1; /* 1 == JPEG */
|
|
|
|
|
|
|
|
for(i=4;i<16;i++) /* The reserved bytes */
|
|
|
|
header[i]=0;
|
|
|
|
|
2002-09-10 10:40:12 +02:00
|
|
|
#define EXTRA_UID_NAME_SPACE 71
|
2005-07-27 20:10:56 +02:00
|
|
|
uid=xmalloc_clear(sizeof(*uid)+71);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2004-09-07 18:49:10 +02:00
|
|
|
tty_printf(_("\nPick an image to use for your photo ID. "
|
|
|
|
"The image must be a JPEG file.\n"
|
2002-06-29 15:46:34 +02:00
|
|
|
"Remember that the image is stored within your public key. "
|
|
|
|
"If you use a\n"
|
|
|
|
"very large picture, your key will become very large as well!\n"
|
|
|
|
"Keeping the image close to 240x288 is a good size to use.\n"));
|
|
|
|
|
|
|
|
while(photo==NULL)
|
|
|
|
{
|
2005-08-31 20:40:39 +02:00
|
|
|
char *tempname;
|
|
|
|
|
2004-09-07 18:49:10 +02:00
|
|
|
tty_printf("\n");
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(filename);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2005-08-31 20:40:39 +02:00
|
|
|
tty_enable_completion(NULL);
|
|
|
|
|
|
|
|
tempname=cpr_get("photoid.jpeg.add",
|
2002-06-29 15:46:34 +02:00
|
|
|
_("Enter JPEG filename for photo ID: "));
|
|
|
|
|
2005-08-31 20:40:39 +02:00
|
|
|
tty_disable_completion();
|
|
|
|
|
|
|
|
filename=make_filename(tempname,(void *)NULL);
|
|
|
|
|
|
|
|
xfree(tempname);
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
if(strlen(filename)==0)
|
|
|
|
goto scram;
|
|
|
|
|
|
|
|
file=iobuf_open(filename);
|
2004-10-13 20:10:06 +02:00
|
|
|
if (file && is_secured_file (iobuf_get_fd (file)))
|
|
|
|
{
|
|
|
|
iobuf_close (file);
|
|
|
|
file = NULL;
|
|
|
|
errno = EPERM;
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
if(!file)
|
|
|
|
{
|
2004-10-13 20:10:06 +02:00
|
|
|
log_error(_("unable to open JPEG file `%s': %s\n"),
|
2002-06-29 15:46:34 +02:00
|
|
|
filename,strerror(errno));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
len=iobuf_get_filelength(file);
|
|
|
|
if(len>6144)
|
|
|
|
{
|
2004-09-07 18:49:10 +02:00
|
|
|
tty_printf( _("This JPEG is really large (%d bytes) !\n"),len);
|
2002-06-29 15:46:34 +02:00
|
|
|
if(!cpr_get_answer_is_yes("photoid.jpeg.size",
|
2004-10-10 17:27:14 +02:00
|
|
|
_("Are you sure you want to use it? (y/N) ")))
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
iobuf_close(file);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
photo=xmalloc(len);
|
2002-06-29 15:46:34 +02:00
|
|
|
iobuf_read(file,photo,len);
|
|
|
|
iobuf_close(file);
|
|
|
|
|
|
|
|
/* Is it a JPEG? */
|
|
|
|
if(photo[0]!=0xFF || photo[1]!=0xD8 ||
|
|
|
|
photo[6]!='J' || photo[7]!='F' || photo[8]!='I' || photo[9]!='F')
|
|
|
|
{
|
2004-10-11 23:08:37 +02:00
|
|
|
log_error(_("`%s' is not a JPEG file\n"),filename);
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(photo);
|
2002-06-29 15:46:34 +02:00
|
|
|
photo=NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build the packet */
|
|
|
|
build_attribute_subpkt(uid,1,photo,len,header,16);
|
|
|
|
parse_attribute_subpkts(uid);
|
2002-09-10 10:40:12 +02:00
|
|
|
make_attribute_uidname(uid, EXTRA_UID_NAME_SPACE);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
/* Showing the photo is not safe when noninteractive since the
|
|
|
|
"user" may not be able to dismiss a viewer window! */
|
|
|
|
if(opt.command_fd==-1)
|
|
|
|
{
|
|
|
|
show_photos(uid->attribs,uid->numattribs,pk,NULL);
|
|
|
|
switch(cpr_get_answer_yes_no_quit("photoid.jpeg.okay",
|
|
|
|
_("Is this photo correct (y/N/q)? ")))
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
goto scram;
|
|
|
|
case 0:
|
|
|
|
free_attributes(uid);
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(photo);
|
2002-06-29 15:46:34 +02:00
|
|
|
photo=NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error=0;
|
|
|
|
uid->ref=1;
|
|
|
|
|
|
|
|
scram:
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(filename);
|
|
|
|
xfree(photo);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
if(error)
|
|
|
|
{
|
|
|
|
free_attributes(uid);
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(uid);
|
2002-06-29 15:46:34 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns 0 for error, 1 for valid */
|
|
|
|
int parse_image_header(const struct user_attribute *attr,byte *type,u32 *len)
|
|
|
|
{
|
2002-07-01 18:40:52 +02:00
|
|
|
u16 headerlen;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
if(attr->len<3)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* For historical reasons (i.e. "oops!"), the header length is
|
|
|
|
little endian. */
|
|
|
|
headerlen=(attr->data[1]<<8) | attr->data[0];
|
|
|
|
|
|
|
|
if(headerlen>attr->len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(type && attr->len>=4)
|
|
|
|
{
|
|
|
|
if(attr->data[2]==1) /* header version 1 */
|
|
|
|
*type=attr->data[3];
|
|
|
|
else
|
|
|
|
*type=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*len=attr->len-headerlen;
|
|
|
|
|
|
|
|
if(*len==0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* style==0 for extension, 1 for name, 2 for MIME type. Remember that
|
|
|
|
the "name" style string could be used in a user ID name field, so
|
2002-11-24 02:49:32 +01:00
|
|
|
make sure it is not too big (see parse-packet.c:parse_attribute).
|
|
|
|
Extensions should be 3 characters long for the best cross-platform
|
|
|
|
compatibility. */
|
2002-06-29 15:46:34 +02:00
|
|
|
char *image_type_to_string(byte type,int style)
|
|
|
|
{
|
|
|
|
char *string;
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case 1: /* jpeg */
|
|
|
|
if(style==0)
|
|
|
|
string="jpg";
|
|
|
|
else if(style==1)
|
|
|
|
string="jpeg";
|
|
|
|
else
|
|
|
|
string="image/jpeg";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if(style==0)
|
|
|
|
string="bin";
|
|
|
|
else if(style==1)
|
|
|
|
string="unknown";
|
|
|
|
else
|
|
|
|
string="image/x-unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2002-07-04 18:06:38 +02:00
|
|
|
#if !defined(FIXED_PHOTO_VIEWER) && !defined(DISABLE_PHOTO_VIEWER)
|
2002-06-29 15:46:34 +02:00
|
|
|
static const char *get_default_photo_command(void)
|
|
|
|
{
|
2003-08-29 02:14:42 +02:00
|
|
|
#if defined(_WIN32)
|
2002-06-29 15:46:34 +02:00
|
|
|
OSVERSIONINFO osvi;
|
|
|
|
|
|
|
|
memset(&osvi,0,sizeof(osvi));
|
|
|
|
osvi.dwOSVersionInfoSize=sizeof(osvi);
|
|
|
|
GetVersionEx(&osvi);
|
|
|
|
|
|
|
|
if(osvi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
|
|
|
|
return "start /w %i";
|
|
|
|
else
|
|
|
|
return "cmd /c start /w %i";
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
/* OS X. This really needs more than just __APPLE__. */
|
|
|
|
return "open %I";
|
|
|
|
#elif defined(__riscos__)
|
|
|
|
return "Filer_Run %I";
|
|
|
|
#else
|
|
|
|
return "xloadimage -fork -quiet -title 'KeyID 0x%k' stdin";
|
|
|
|
#endif
|
|
|
|
}
|
2002-07-04 18:06:38 +02:00
|
|
|
#endif
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
void show_photos(const struct user_attribute *attrs,
|
|
|
|
int count,PKT_public_key *pk,PKT_secret_key *sk)
|
|
|
|
{
|
2002-07-04 18:06:38 +02:00
|
|
|
#ifndef DISABLE_PHOTO_VIEWER
|
2002-06-29 15:46:34 +02:00
|
|
|
int i;
|
|
|
|
struct expando_args args;
|
|
|
|
u32 len;
|
|
|
|
u32 kid[2]={0,0};
|
|
|
|
|
|
|
|
memset(&args,0,sizeof(args));
|
|
|
|
args.pk=pk;
|
|
|
|
args.sk=sk;
|
|
|
|
|
|
|
|
if(pk)
|
|
|
|
keyid_from_pk(pk,kid);
|
|
|
|
else if(sk)
|
|
|
|
keyid_from_sk(sk,kid);
|
|
|
|
|
|
|
|
for(i=0;i<count;i++)
|
|
|
|
if(attrs[i].type==ATTRIB_IMAGE &&
|
|
|
|
parse_image_header(&attrs[i],&args.imagetype,&len))
|
|
|
|
{
|
|
|
|
char *command,*name;
|
|
|
|
struct exec_info *spawn;
|
|
|
|
int offset=attrs[i].len-len;
|
|
|
|
|
2002-07-04 18:06:38 +02:00
|
|
|
#ifdef FIXED_PHOTO_VIEWER
|
|
|
|
opt.photo_viewer=FIXED_PHOTO_VIEWER;
|
|
|
|
#else
|
2002-06-29 15:46:34 +02:00
|
|
|
if(!opt.photo_viewer)
|
|
|
|
opt.photo_viewer=get_default_photo_command();
|
2002-07-04 18:06:38 +02:00
|
|
|
#endif
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
/* make command grow */
|
|
|
|
command=pct_expando(opt.photo_viewer,&args);
|
|
|
|
if(!command)
|
|
|
|
goto fail;
|
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
name=xmalloc(16+strlen(EXTSEP_S)+
|
2002-06-29 15:46:34 +02:00
|
|
|
strlen(image_type_to_string(args.imagetype,0))+1);
|
|
|
|
|
|
|
|
/* Make the filename. Notice we are not using the image
|
|
|
|
encoding type for more than cosmetics. Most external image
|
|
|
|
viewers can handle a multitude of types, and even if one
|
2002-11-24 02:49:32 +01:00
|
|
|
cannot understand a particular type, we have no way to know
|
2002-06-29 15:46:34 +02:00
|
|
|
which. The spec permits this, by the way. -dms */
|
|
|
|
|
|
|
|
#ifdef USE_ONLY_8DOT3
|
|
|
|
sprintf(name,"%08lX" EXTSEP_S "%s",(ulong)kid[1],
|
|
|
|
image_type_to_string(args.imagetype,0));
|
|
|
|
#else
|
|
|
|
sprintf(name,"%08lX%08lX" EXTSEP_S "%s",(ulong)kid[0],(ulong)kid[1],
|
|
|
|
image_type_to_string(args.imagetype,0));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(exec_write(&spawn,NULL,command,name,1,1)!=0)
|
|
|
|
{
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(name);
|
2002-06-29 15:46:34 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __riscos__
|
2002-10-31 17:58:47 +01:00
|
|
|
riscos_set_filetype_by_mimetype(spawn->tempfile_in,
|
|
|
|
image_type_to_string(args.imagetype,2));
|
2002-06-29 15:46:34 +02:00
|
|
|
#endif
|
|
|
|
|
2005-07-27 20:10:56 +02:00
|
|
|
xfree(name);
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
fwrite(&attrs[i].data[offset],attrs[i].len-offset,1,spawn->tochild);
|
|
|
|
|
|
|
|
if(exec_read(spawn)!=0)
|
|
|
|
{
|
|
|
|
exec_finish(spawn);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(exec_finish(spawn)!=0)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
* g10.c (main): Add --no-textmode.
* export.c (do_export_stream), keyedit.c (show_key_with_all_names,
menu_addrevoker), mainproc.c (check_sig_and_print), photoid.c
(show_photos), sign.c (mk_notation_and_policy), trustdb.c (get_validity,
reset_trust_records, validate_keys): Make some strings translatable.
* mainproc.c (check_sig_and_print): Show digest algorithm and sig class
when verifying a sig with --verbose on, and add version, pk and hash
algorithms and sig class to VALIDSIG.
* parse-packet.c (enum_sig_subpkt): Make a warning message a --verbose
warning message since we don't need to warn every time we see an unknown
critical (we only need to invalidate the signature).
* trustdb.c (init_trustdb): Check the trustdb options even with TM_AUTO
since the auto may become TM_CLASSIC or TM_OPENPGP.
2003-04-27 22:22:09 +02:00
|
|
|
log_error(_("unable to display photo ID!\n"));
|
2002-07-04 18:06:38 +02:00
|
|
|
#endif
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|