1
/* photoid.c - photo ID handling code
2
* Copyright (C) 2001, 2002 Free Software Foundation, Inc.
4
* This file is part of GnuPG.
6
* GnuPG is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* GnuPG is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
27
# ifndef VER_PLATFORM_WIN32_WINDOWS
28
# define VER_PLATFORM_WIN32_WINDOWS 1
43
/* Generate a new photo id packet, or return NULL if canceled */
44
PKT_user_id *generate_photo_id(PKT_public_key *pk)
54
header[0]=0x10; /* little side of photo header length */
55
header[1]=0; /* big side of photo header length */
56
header[2]=1; /* 1 == version of photo header */
57
header[3]=1; /* 1 == JPEG */
59
for(i=4;i<16;i++) /* The reserved bytes */
62
#define EXTRA_UID_NAME_SPACE 71
63
uid=xcalloc (1,sizeof(*uid)+71);
65
printf(_("\nPick an image to use for your photo ID. "
66
"The image must be a JPEG file.\n"
67
"Remember that the image is stored within your public key. "
69
"very large picture, your key will become very large as well!\n"
70
"Keeping the image close to 240x288 is a good size to use.\n"));
78
filename=cpr_get("photoid.jpeg.add",
79
_("Enter JPEG filename for photo ID: "));
81
if(strlen(filename)==0)
84
file=iobuf_open(filename);
87
log_error(_("Unable to open photo \"%s\": %s\n"),
88
filename,strerror(errno));
92
len=iobuf_get_filelength(file);
95
printf("This JPEG is really large (%d bytes) !\n",len);
96
if(!cpr_get_answer_is_yes("photoid.jpeg.size",
97
_("Are you sure you want to use it (y/N)? ")))
105
iobuf_read(file,photo,len);
109
if(photo[0]!=0xFF || photo[1]!=0xD8 ||
110
photo[6]!='J' || photo[7]!='F' || photo[8]!='I' || photo[9]!='F')
112
log_error(_("\"%s\" is not a JPEG file\n"),filename);
118
/* Build the packet */
119
build_attribute_subpkt(uid,1,photo,len,header,16);
120
parse_attribute_subpkts(uid);
121
make_attribute_uidname(uid, EXTRA_UID_NAME_SPACE);
123
/* Showing the photo is not safe when noninteractive since the
124
"user" may not be able to dismiss a viewer window! */
125
if(opt.command_fd==-1)
127
show_photos(uid->attribs,uid->numattribs,pk,NULL);
128
switch(cpr_get_answer_yes_no_quit("photoid.jpeg.okay",
129
_("Is this photo correct (y/N/q)? ")))
134
free_attributes(uid);
151
free_attributes(uid);
159
/* Returns 0 for error, 1 for valid */
160
int parse_image_header(const struct user_attribute *attr,byte *type,u32 *len)
167
/* For historical reasons (i.e. "oops!"), the header length is
169
headerlen=(attr->data[1]<<8) | attr->data[0];
171
if(headerlen>attr->len)
174
if(type && attr->len>=4)
176
if(attr->data[2]==1) /* header version 1 */
182
*len=attr->len-headerlen;
190
/* style==0 for extension, 1 for name, 2 for MIME type. Remember that
191
the "name" style string could be used in a user ID name field, so
192
make sure it is not too big (see parse-packet.c:parse_attribute).
193
Extensions should be 3 characters long for the best cross-platform
195
char *image_type_to_string(byte type,int style)
216
string="image/x-unknown";
223
#if !defined(FIXED_PHOTO_VIEWER) && !defined(DISABLE_PHOTO_VIEWER)
224
static const char *get_default_photo_command(void)
229
memset(&osvi,0,sizeof(osvi));
230
osvi.dwOSVersionInfoSize=sizeof(osvi);
233
if(osvi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
234
return "start /w %i";
236
return "cmd /c start /w %i";
237
#elif defined(__APPLE__)
238
/* OS X. This really needs more than just __APPLE__. */
240
#elif defined(__riscos__)
241
return "Filer_Run %I";
243
return "xloadimage -fork -quiet -title 'KeyID 0x%k' stdin";
248
void show_photos(const struct user_attribute *attrs,
249
int count,PKT_public_key *pk,PKT_secret_key *sk)
251
#ifndef DISABLE_PHOTO_VIEWER
253
struct expando_args args;
257
memset(&args,0,sizeof(args));
262
keyid_from_pk(pk,kid);
264
keyid_from_sk(sk,kid);
267
if(attrs[i].type==ATTRIB_IMAGE &&
268
parse_image_header(&attrs[i],&args.imagetype,&len))
271
struct exec_info *spawn;
272
int offset=attrs[i].len-len;
274
#ifdef FIXED_PHOTO_VIEWER
275
opt.photo_viewer=FIXED_PHOTO_VIEWER;
277
if(!opt.photo_viewer)
278
opt.photo_viewer=get_default_photo_command();
281
/* make command grow */
282
command=pct_expando(opt.photo_viewer,&args);
286
name=xmalloc (16+strlen(EXTSEP_S)+
287
strlen(image_type_to_string(args.imagetype,0))+1);
289
/* Make the filename. Notice we are not using the image
290
encoding type for more than cosmetics. Most external image
291
viewers can handle a multitude of types, and even if one
292
cannot understand a particular type, we have no way to know
293
which. The spec permits this, by the way. -dms */
295
#ifdef USE_ONLY_8DOT3
296
sprintf(name,"%08lX" EXTSEP_S "%s",(ulong)kid[1],
297
image_type_to_string(args.imagetype,0));
299
sprintf(name,"%08lX%08lX" EXTSEP_S "%s",(ulong)kid[0],(ulong)kid[1],
300
image_type_to_string(args.imagetype,0));
303
if(exec_write(&spawn,NULL,command,name,1,1)!=0)
310
riscos_set_filetype_by_mimetype(spawn->tempfile_in,
311
image_type_to_string(args.imagetype,2));
316
fwrite(&attrs[i].data[offset],attrs[i].len-offset,1,spawn->tochild);
318
if(exec_read(spawn)!=0)
324
if(exec_finish(spawn)!=0)
331
log_error(_("unable to display photo ID!\n"));