~ubuntu-branches/ubuntu/quantal/gnutls26/quantal

« back to all changes in this revision

Viewing changes to lib/opencdk/sig-check.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-05-20 13:07:18 UTC
  • mfrom: (12.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110520130718-db41dybbanzfvlji
Tags: 2.10.5-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Fix build failure with --no-add-needed.
  - Build for multiarch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* sig-check.c - Check signatures
2
 
 * Copyright (C) 1998-2002, 2003, 2007, 2008 Free Software Foundation, Inc.
 
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2007, 2008, 2010
 
3
 * Free Software Foundation, Inc.
3
4
 *
4
5
 * Author: Timo Schulz
5
6
 *
289
290
  if (is_selfsig)
290
291
    *is_selfsig = 0;
291
292
  if ((knode->pkt->pkttype != CDK_PKT_PUBLIC_KEY &&
292
 
      knode->pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY) ||
 
293
       knode->pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY) ||
293
294
      snode->pkt->pkttype != CDK_PKT_SIGNATURE)
294
295
    {
295
296
      gnutls_assert ();
542
543
            }
543
544
        }
544
545
 
545
 
      _cdk_log_debug ("signature %s: signer %08lX keyid %08lX\n",
546
 
                      rc == CDK_Bad_Sig ? "BAD" : "good", sig->keyid[1],
547
 
                      keyid);
 
546
      _cdk_log_debug ("signature %s: signer %08X keyid %08X\n",
 
547
                      rc == CDK_Bad_Sig ? "BAD" : "good",
 
548
                      (unsigned int) sig->keyid[1], (unsigned int) keyid);
548
549
 
549
550
      if (IS_UID_SIG (sig) && uid_name != NULL)
550
551
        {
551
552
          /* add every uid in the uid list. Only consider valid:
552
553
           * - verification was ok
553
 
           * - not a selfsig 
 
554
           * - not a selfsig
554
555
           */
555
556
          rc =
556
557
            uid_list_add_sig (&uid_list, uid_name,
580
581
 * cdk_pk_check_self_sig:
581
582
 * @key: the key node
582
583
 * @r_status: output the status of the key.
583
 
 * 
 
584
 *
584
585
 * A convenient function to make sure the key is valid.
585
586
 * Valid means the self signature is ok.
586
587
 **/
603
604
  while ((p = cdk_kbnode_walk (key, &ctx, 0)))
604
605
    {
605
606
      pkt = cdk_kbnode_get_packet (p);
606
 
      if (pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY && pkt->pkttype != CDK_PKT_PUBLIC_KEY)
607
 
        continue;
 
607
      if (pkt->pkttype != CDK_PKT_PUBLIC_SUBKEY
 
608
          && pkt->pkttype != CDK_PKT_PUBLIC_KEY)
 
609
        continue;
608
610
 
609
611
      /* FIXME: we should set expire/revoke here also but callers
610
612
         expect CDK_KEY_VALID=0 if the key is okay. */
611
613
      sig_ok = 0;
612
614
      for (node = p; node; node = node->next)
613
 
        {
614
 
          if (node->pkt->pkttype != CDK_PKT_SIGNATURE)
615
 
            continue;
616
 
          sig = node->pkt->pkt.signature;
 
615
        {
 
616
          if (node->pkt->pkttype != CDK_PKT_SIGNATURE)
 
617
            continue;
 
618
          sig = node->pkt->pkt.signature;
617
619
 
618
 
          cdk_sig_get_keyid (sig, sigid);
619
 
          if (sigid[0] != keyid[0] || sigid[1] != keyid[1])
 
620
          cdk_sig_get_keyid (sig, sigid);
 
621
          if (sigid[0] != keyid[0] || sigid[1] != keyid[1])
620
622
            continue;
621
 
          /* FIXME: Now we check all self signatures. */
622
 
          rc = _cdk_pk_check_sig (NULL, p, node, &is_selfsig, NULL);
623
 
          if (rc)
 
623
          /* FIXME: Now we check all self signatures. */
 
624
          rc = _cdk_pk_check_sig (NULL, p, node, &is_selfsig, NULL);
 
625
          if (rc)
624
626
            {
625
 
              *r_status = CDK_KEY_INVALID;
 
627
              *r_status = CDK_KEY_INVALID;
626
628
              return rc;
627
 
            }
628
 
          else                  /* For each valid self sig we increase this counter. */
 
629
            }
 
630
          else                  /* For each valid self sig we increase this counter. */
629
631
            sig_ok++;
630
 
        }
 
632
        }
631
633
 
632
634
      /* A key without a self signature is not valid. At least one
633
635
       * signature for the given key has to be found.
634
636
       */
635
637
      if (!sig_ok)
636
 
        {
637
 
          *r_status = CDK_KEY_INVALID;
638
 
          return CDK_General_Error;
639
 
        }
640
 
 
 
638
        {
 
639
          *r_status = CDK_KEY_INVALID;
 
640
          return CDK_General_Error;
 
641
        }
641
642
    }
642
643
 
643
 
    /* No flags indicate a valid key. */
644
 
    *r_status = CDK_KEY_VALID;
 
644
  /* No flags indicate a valid key. */
 
645
  *r_status = CDK_KEY_VALID;
645
646
 
646
 
    return 0;
 
647
  return 0;
647
648
}