~ubuntu-branches/ubuntu/vivid/gnupg/vivid

« back to all changes in this revision

Viewing changes to g10/import.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-12-04 22:26:16 UTC
  • mfrom: (1.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20121204222616-cr0fow26geq90l3y
Tags: 1.4.12-6ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Disable mlock() test since it fails with ulimit 0 (on buildds).
  - Set gpg (or gpg2) and gpgsm to use a passphrase agent by default.
  - Only suggest gnupg-curl and libldap; recommendations are pulled into
    minimal, and we don't need the keyserver utilities in a minimal Ubuntu
    system.
  - Remove the Win32 build.
  - Update config.guess/config.sub for aarch64.
* Dropped patches:
  - Fix udeb build failure on powerpc, building with -O2 instead of -Os.
    (No longer seems to be necessary.)
* Simplify removal of Win32 build, to make this easier to merge in future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
        rc = import( inp, "[stream]", stats, fpr, fpr_len, options);
176
176
    }
177
177
    else {
178
 
        if( !fnames && !nnames )
179
 
            nnames = 1;  /* Ohh what a ugly hack to jump into the loop */
 
178
        int once = (!fnames && !nnames);
180
179
 
181
 
        for(i=0; i < nnames; i++ ) {
 
180
        for(i=0; once || i < nnames; once=0, i++ ) {
182
181
            const char *fname = fnames? fnames[i] : NULL;
183
182
            IOBUF inp2 = iobuf_open(fname);
184
183
            if( !fname )
201
200
                  log_error("import from `%s' failed: %s\n", fname,
202
201
                            g10_errstr(rc) );
203
202
              }
204
 
            if( !fname )
205
 
                break;
206
203
        }
207
204
    }
208
205
    if (!stats_handle) {
256
253
    while( !(rc = read_block( inp, &pending_pkt, &keyblock) )) {
257
254
        if( keyblock->pkt->pkttype == PKT_PUBLIC_KEY )
258
255
            rc = import_one( fname, keyblock, stats, fpr, fpr_len, options, 0);
259
 
        else if( keyblock->pkt->pkttype == PKT_SECRET_KEY ) 
 
256
        else if( keyblock->pkt->pkttype == PKT_SECRET_KEY )
260
257
                rc = import_secret_one( fname, keyblock, stats, options );
261
258
        else if( keyblock->pkt->pkttype == PKT_SIGNATURE
262
259
                 && keyblock->pkt->pkt.signature->sig_class == 0x20 )
615
612
  KBNODE node;
616
613
  PKT_public_key *pk;
617
614
  int problem=0;
618
 
  
 
615
 
619
616
  merge_keys_and_selfsig(keyblock);
620
617
  pk=keyblock->pkt->pkt.public_key;
621
618
 
759
756
        log_error( _("key %s: no user ID\n"), keystr_from_pk(pk));
760
757
        return 0;
761
758
      }
762
 
    
 
759
 
763
760
    if (opt.interactive) {
764
761
        if(is_status_enabled())
765
762
          print_import_check (pk, uidnode->pkt->pkt.user_id);
896
893
            size_t an;
897
894
 
898
895
            fingerprint_from_pk (pk_orig, afp, &an);
899
 
            while (an < MAX_FINGERPRINT_LEN) 
 
896
            while (an < MAX_FINGERPRINT_LEN)
900
897
                afp[an++] = 0;
901
898
            rc = keydb_search_fpr (hd, afp);
902
899
        }
920
917
        n_sigs_cleaned = fix_bad_direct_key_sigs (keyblock_orig, keyid);
921
918
        if (n_sigs_cleaned)
922
919
          commit_kbnode (&keyblock_orig);
923
 
            
 
920
 
924
921
        /* and try to merge the block */
925
922
        clear_kbnode_flags( keyblock_orig );
926
923
        clear_kbnode_flags( keyblock );
990
987
            stats->n_sigs_cleaned +=n_sigs_cleaned;
991
988
            stats->n_uids_cleaned +=n_uids_cleaned;
992
989
 
993
 
            if (is_status_enabled ()) 
 
990
            if (is_status_enabled ())
994
991
                 print_import_ok (pk, NULL,
995
992
                                  ((n_uids?2:0)|(n_sigs?4:0)|(n_subk?8:0)));
996
993
        }
997
994
        else
998
995
          {
999
 
            if (is_status_enabled ()) 
 
996
            if (is_status_enabled ())
1000
997
              print_import_ok (pk, NULL, 0);
1001
998
 
1002
999
            if( !opt.quiet )
1127
1124
 * with the trust calculation.
1128
1125
 */
1129
1126
static int
1130
 
import_secret_one( const char *fname, KBNODE keyblock, 
 
1127
import_secret_one( const char *fname, KBNODE keyblock,
1131
1128
                   struct stats_s *stats, unsigned int options)
1132
1129
{
1133
1130
    PKT_secret_key *sk;
1179
1176
        log_error (_("importing secret keys not allowed\n"));
1180
1177
        return 0;
1181
1178
      }
1182
 
#endif 
1183
 
    
 
1179
#endif
 
1180
 
1184
1181
    clear_kbnode_flags( keyblock );
1185
1182
 
1186
1183
    /* do we have this key already in one of our secrings ? */
1206
1203
        if( !opt.quiet )
1207
1204
          log_info( _("key %s: secret key imported\n"), keystr_from_sk(sk));
1208
1205
        stats->secret_imported++;
1209
 
        if (is_status_enabled ()) 
 
1206
        if (is_status_enabled ())
1210
1207
          print_import_ok (NULL, sk, 1|16);
1211
1208
 
1212
1209
        if(options&IMPORT_SK2PK)
1237
1234
        log_error( _("key %s: already in secret keyring\n"),
1238
1235
                   keystr_from_sk(sk));
1239
1236
        stats->secret_dups++;
1240
 
        if (is_status_enabled ()) 
 
1237
        if (is_status_enabled ())
1241
1238
          print_import_ok (NULL, sk, 16);
1242
1239
 
1243
1240
        /* TODO: if we ever do merge secret keys, make sure to handle
1291
1288
    {
1292
1289
        byte afp[MAX_FINGERPRINT_LEN];
1293
1290
        size_t an;
1294
 
        
 
1291
 
1295
1292
        fingerprint_from_pk (pk, afp, &an);
1296
 
        while (an < MAX_FINGERPRINT_LEN) 
 
1293
        while (an < MAX_FINGERPRINT_LEN)
1297
1294
            afp[an++] = 0;
1298
1295
        rc = keydb_search_fpr (hd, afp);
1299
1296
    }
2274
2271
          PACKET *pkt = xmalloc_clear (sizeof *pkt);
2275
2272
          PKT_secret_key *sk = xmalloc_clear (sizeof *sk);
2276
2273
          int i, n;
2277
 
          
 
2274
 
2278
2275
          if (pubnode->pkt->pkttype == PKT_PUBLIC_KEY)
2279
2276
            pkt->pkttype = PKT_SECRET_KEY;
2280
2277
          else
2281
2278
            pkt->pkttype = PKT_SECRET_SUBKEY;
2282
 
          
 
2279
 
2283
2280
          pkt->pkt.secret_key = sk;
2284
2281
 
2285
2282
          copy_public_parts_to_secret_key ( pk, sk );
2286
2283
          sk->version     = pk->version;
2287
2284
          sk->timestamp   = pk->timestamp;
2288
 
        
 
2285
 
2289
2286
          n = pubkey_get_npkey (pk->pubkey_algo);
2290
2287
          if (!n)
2291
2288
            n = 1; /* Unknown number of parameters, however the data
2292
2289
                      is stored in the first mpi. */
2293
2290
          for (i=0; i < n; i++ )
2294
2291
            sk->skey[i] = mpi_copy (pk->pkey[i]);
2295
 
  
 
2292
 
2296
2293
          sk->is_protected = 1;
2297
2294
          sk->protect.s2k.mode = 1001;
2298
 
  
 
2295
 
2299
2296
          secnode = new_kbnode (pkt);
2300
2297
        }
2301
2298
      else
2302
2299
        {
2303
2300
          secnode = clone_kbnode (pubnode);
2304
2301
        }
2305
 
      
 
2302
 
2306
2303
      if(!sec_keyblock)
2307
2304
        sec_keyblock = secnode;
2308
2305
      else
2316
2313
/* Walk over the secret keyring SEC_KEYBLOCK and update any simple
2317
2314
   stub keys with the serial number SNNUM of the card if one of the
2318
2315
   fingerprints FPR1, FPR2 or FPR3 match.  Print a note if the key is
2319
 
   a duplicate (may happen in case of backed uped keys). 
2320
 
   
 
2316
   a duplicate (may happen in case of backed uped keys).
 
2317
 
2321
2318
   Returns: True if anything changed.
2322
2319
*/
2323
2320
static int
2324
 
update_sec_keyblock_with_cardinfo (KBNODE sec_keyblock, 
 
2321
update_sec_keyblock_with_cardinfo (KBNODE sec_keyblock,
2325
2322
                                   const unsigned char *fpr1,
2326
2323
                                   const unsigned char *fpr2,
2327
2324
                                   const unsigned char *fpr3,
2341
2338
          && node->pkt->pkttype != PKT_SECRET_SUBKEY)
2342
2339
        continue;
2343
2340
      sk = node->pkt->pkt.secret_key;
2344
 
      
 
2341
 
2345
2342
      fingerprint_from_sk (sk, array, &n);
2346
2343
      if (n != 20)
2347
2344
        continue; /* Can't be a card key.  */
2391
2388
   exists, add appropriate subkey stubs and update the secring.
2392
2389
   Return 0 if the key could be created. */
2393
2390
int
2394
 
auto_create_card_key_stub ( const char *serialnostr, 
 
2391
auto_create_card_key_stub ( const char *serialnostr,
2395
2392
                            const unsigned char *fpr1,
2396
2393
                            const unsigned char *fpr2,
2397
2394
                            const unsigned char *fpr3)
2402
2399
  int rc;
2403
2400
 
2404
2401
  /* We only want to do this for an OpenPGP card.  */
2405
 
  if (!serialnostr || strncmp (serialnostr, "D27600012401", 12) 
 
2402
  if (!serialnostr || strncmp (serialnostr, "D27600012401", 12)
2406
2403
      || strlen (serialnostr) != 32 )
2407
2404
    return G10ERR_GENERAL;
2408
2405
 
2413
2410
    ;
2414
2411
  else
2415
2412
    return G10ERR_GENERAL;
2416
 
 
 
2413
 
2417
2414
  hd = keydb_new (1);
2418
2415
 
2419
2416
  /* Now check whether there is a secret keyring.  */
2439
2436
      else
2440
2437
        {
2441
2438
          merge_keys_and_selfsig (sec_keyblock);
2442
 
          
 
2439
 
2443
2440
          /* FIXME: We need to add new subkeys first.  */
2444
2441
          if (update_sec_keyblock_with_cardinfo (sec_keyblock,
2445
2442
                                                 fpr1, fpr2, fpr3,
2473
2470
                       keydb_get_resource_name (hd), g10_errstr(rc) );
2474
2471
        }
2475
2472
    }
2476
 
    
 
2473
 
2477
2474
  release_kbnode (sec_keyblock);
2478
2475
  release_kbnode (pub_keyblock);
2479
2476
  keydb_release (hd);