~ubuntu-branches/ubuntu/jaunty/gnupg2/jaunty-security

« back to all changes in this revision

Viewing changes to kbx/keybox-blob.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* keybox-blob.c - KBX Blob handling
2
 
 *      Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
2
 * Copyright (C) 2000, 2001, 2002, 2003, 2008 Free Software Foundation, Inc.
3
3
 *
4
4
 * This file is part of GnuPG.
5
5
 *
6
6
 * GnuPG is free software; you can redistribute it and/or modify
7
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
 
8
 * the Free Software Foundation; either version 3 of the License, or
9
9
 * (at your option) any later version.
10
10
 *
11
11
 * GnuPG is distributed in the hope that it will be useful,
14
14
 * GNU General Public License for more details.
15
15
 *
16
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
 
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
20
 
22
21
/* The keybox data formats
23
22
 
24
23
The KeyBox uses an augmented OpenPGP/X.509 key format.  This makes
25
 
random access to a keyblock/Certificate easier and also gives the
 
24
random access to a keyblock/certificate easier and also gives the
26
25
opportunity to store additional information (e.g. the fingerprint)
27
26
along with the key.  All integers are stored in network byte order,
28
27
offsets are counted from the beginning of the Blob.
104
103
 
105
104
 b16    MD5 checksum  (useful for KS syncronisation), we might also want to use
106
105
    a mac here.
107
 
 b4    resevered
 
106
 b4    reserved
108
107
 
109
108
*/
110
109
 
779
778
 
780
779
#ifdef KEYBOX_WITH_X509
781
780
 
782
 
/* return an allocated string with the email address extracted from a
783
 
   DN */
 
781
/* Return an allocated string with the email address extracted from a
 
782
   DN.  Note hat we use this code also in ../sm/keylist.c.  */
784
783
static char *
785
784
x509_email_kludge (const char *name)
786
785
{
787
 
  const char *p;
 
786
  const char *p, *string;
788
787
  unsigned char *buf;
789
788
  int n;
790
789
 
791
 
  if (strncmp (name, "1.2.840.113549.1.9.1=#", 22))
792
 
    return NULL;
 
790
  string = name;
 
791
  for (;;)
 
792
    {
 
793
      p = strstr (string, "1.2.840.113549.1.9.1=#");
 
794
      if (!p)
 
795
        return NULL;
 
796
      if (p == name || (p > string+1 && p[-1] == ',' && p[-2] != '\\'))
 
797
        {
 
798
          name = p + 22;
 
799
          break;
 
800
        }
 
801
      string = p + 22;
 
802
    }
 
803
 
 
804
 
793
805
  /* This looks pretty much like an email address in the subject's DN
794
806
     we use this to add an additional user ID entry.  This way,
795
 
     openSSL generated keys get a nicer and usable listing */
796
 
  name += 22;    
 
807
     OpenSSL generated keys get a nicer and usable listing.  */
797
808
  for (n=0, p=name; hexdigitp (p) && hexdigitp (p+1); p +=2, n++)
798
809
    ;
799
 
  if (*p != '#' || !n)
 
810
  if (!n)
800
811
    return NULL;
801
812
  buf = xtrymalloc (n+3);
802
813
  if (!buf)
803
814
    return NULL; /* oops, out of core */
804
815
  *buf = '<';
805
 
  for (n=1, p=name; *p != '#'; p +=2, n++)
 
816
  for (n=1, p=name; hexdigitp (p); p +=2, n++)
806
817
    buf[n] = xtoi_2 (p);
807
818
  buf[n++] = '>';
808
819
  buf[n] = 0;
809
 
  return (char *)buf;
 
820
  return (char*)buf;
810
821
}
811
822
 
812
823