[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [pkg-gnupg-maint] How (not) to detect if a keyring file is a keybox in apt-key



Hi,

file knows about the keybox format:
  GPG keybox database version 1, created-at [...]

Here is the format description:

   The first blob of a plain KBX file has a special format:

   - u32  Length of this blob
   - byte Blob type (1)
   - byte Version number (1)
   - u16  Header flags
          bit 0 - RFU
          bit 1 - Is being or has been used for OpenPGP blobs
   - b4   Magic 'KBXf'
   - u32  RFU
   - u32  file_created_at
   - u32  last_maintenance_run
   - u32  RFU
   - u32  RFU


gpg uses this code to detect keybox files:

--8<---------------cut here---------------start------------->8---
  u32 magic;
  unsigned char verbuf[4];
  FILE *fp;

  fp = fopen (filename, "rb");
  if (fp)
    {
      *r_found = 1;

      if (fread (&magic, 4, 1, fp) == 1 )
        {
          if (magic == 0x13579ace || magic == 0xce9a5713)
            ; /* GDBM magic - not anymore supported. */
          else if (fread (&verbuf, 4, 1, fp) == 1
                   && verbuf[0] == 1
                   && fread (&magic, 4, 1, fp) == 1
                   && !memcmp (&magic, "KBXf", 4))
            {
              if ((verbuf[3] & 0x02))
                *r_openpgp = 1;
              rt = KEYDB_RESOURCE_TYPE_KEYBOX;
            }
          else
            rt = KEYDB_RESOURCE_TYPE_KEYRING;
        }
      else /* Maybe empty: assume keyring. */
        rt = KEYDB_RESOURCE_TYPE_KEYRING;

      fclose (fp);
    }
--8<---------------cut here---------------end--------------->8---



Shalom-Salam,

   Werner

-- 
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.

Attachment: pgpNgXuyBZRRh.pgp
Description: PGP signature


Reply to: