~ubuntu-branches/ubuntu/raring/nss/raring-security

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/pk11wrap/pk11cert.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2010-03-25 13:46:06 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100325134606-bl6liuok2w9l7snv
Tags: 3.12.6-0ubuntu1
* New upstream release 3.12.6 RTM (NSS_3_12_6_RTM)
  - fixes CVE-2009-3555 aka US-CERT VU#120541
* Adjust patches to changed upstream code base
  - update debian/patches/38_kbsd.patch
  - update debian/patches/38_mips64_build.patch
  - update debian/patches/85_security_load.patch
* Remove patches that are merged upstream
  - delete debian/patches/91_nonexec_stack.patch
  - update debian/patches/series
* Bump nspr dependency to 4.8
  - update debian/control
* Add new symbols for 3.12.6
  - update debian/libnss3-1d.symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
250
250
 
251
251
/*
252
252
 * Create an NSSCertificate from a slot/certID pair, return it as a
253
 
 * CERTCertificate.
 
253
 * CERTCertificate.  Optionally, output the nickname string.
254
254
 */
255
 
static CERTCertificate
256
 
*pk11_fastCert(PK11SlotInfo *slot, CK_OBJECT_HANDLE certID, 
257
 
                        CK_ATTRIBUTE *privateLabel, char **nickptr)
 
255
static CERTCertificate *
 
256
pk11_fastCert(PK11SlotInfo *slot, CK_OBJECT_HANDLE certID, 
 
257
              CK_ATTRIBUTE *privateLabel, char **nickptr)
258
258
{
259
259
    NSSCertificate *c;
260
260
    nssCryptokiObject *co = NULL;
261
261
    nssPKIObject *pkio;
262
262
    NSSToken *token;
263
263
    NSSTrustDomain *td = STAN_GetDefaultTrustDomain();
 
264
    PRStatus status;
264
265
 
265
266
    /* Get the cryptoki object from the handle */
266
267
    token = PK11Slot_GetNSSToken(slot);
287
288
        return NULL;
288
289
    }
289
290
 
290
 
    nssTrustDomain_AddCertsToCache(td, &c, 1);
291
 
 
292
 
    /* Build the old-fashioned nickname */
 
291
    /* Build and output a nickname, if desired. 
 
292
     * This must be done before calling nssTrustDomain_AddCertsToCache
 
293
     * because that function may destroy c, pkio and co!
 
294
     */
293
295
    if ((nickptr) && (co->label)) {
294
296
        CK_ATTRIBUTE label, id;
 
297
 
295
298
        label.type = CKA_LABEL;
296
299
        label.pValue = co->label;
297
300
        label.ulValueLen = PORT_Strlen(co->label);
 
301
 
298
302
        id.type = CKA_ID;
299
303
        id.pValue = c->id.data;
300
304
        id.ulValueLen = c->id.size;
 
305
 
301
306
        *nickptr = pk11_buildNickname(slot, &label, privateLabel, &id);
302
307
    }
 
308
 
 
309
    /* This function may destroy the cert in "c" and all its subordinate
 
310
     * structures, and replace the value in "c" with the address of a 
 
311
     * different NSSCertificate that it found in the cache.
 
312
     * Presumably, the nickname which we just output above remains valid. :)
 
313
     */
 
314
    status = nssTrustDomain_AddCertsToCache(td, &c, 1);
303
315
    return STAN_GetCERTCertificateOrRelease(c);
304
316
}
305
317
 
318
330
    PRBool swapNickname = PR_FALSE;
319
331
 
320
332
    cert = pk11_fastCert(slot,certID,privateLabel, &nickname);
321
 
    if (cert == NULL) goto loser;
 
333
    if (cert == NULL) 
 
334
        goto loser;
322
335
        
323
336
    if (nickname) {
324
337
        if (cert->nickname != NULL) {
325
 
                cert->dbnickname = cert->nickname;
 
338
            cert->dbnickname = cert->nickname;
326
339
        } 
327
340
        cert->nickname = PORT_ArenaStrdup(cert->arena,nickname);
328
341
        PORT_Free(nickname);
341
354
    }
342
355
 
343
356
    trust = (CERTCertTrust*)PORT_ArenaAlloc(cert->arena, sizeof(CERTCertTrust));
344
 
    if (trust == NULL) goto loser;
 
357
    if (trust == NULL) 
 
358
        goto loser;
345
359
    PORT_Memset(trust,0, sizeof(CERTCertTrust));
346
360
    cert->trust = trust;
347
361
 
348
 
    
349
 
 
350
362
    if(! pk11_HandleTrustObject(slot, cert, trust) ) {
351
363
        unsigned int type;
352
364
 
386
398
        trust->emailFlags |= CERTDB_USER;
387
399
        /*    trust->objectSigningFlags |= CERTDB_USER; */
388
400
    }
389
 
 
390
401
    return cert;
391
402
 
392
403
loser:
393
 
    if (nickname) PORT_Free(nickname);
394
 
    if (cert) CERT_DestroyCertificate(cert);
 
404
    if (nickname) 
 
405
        PORT_Free(nickname);
 
406
    if (cert) 
 
407
        CERT_DestroyCertificate(cert);
395
408
    return NULL;
396
409
}
397
410
 
841
854
    nssCertificateStoreTrace unlockTrace = {NULL, NULL, PR_FALSE, PR_FALSE};
842
855
 
843
856
    if (keyID == NULL) {
 
857
        goto loser; /* error code should be set already */
 
858
    }
 
859
    if (!token) {
 
860
        PORT_SetError(SEC_ERROR_NO_TOKEN);
844
861
        goto loser;
845
862
    }
846
863
 
858
875
        }
859
876
    }
860
877
 
861
 
    if (c->object.cryptoContext) {
862
 
        /* Delete the temp instance */
863
 
        NSSCryptoContext *cc = c->object.cryptoContext;
864
 
        nssCertificateStore_Lock(cc->certStore, &lockTrace);
865
 
        nssCertificateStore_RemoveCertLOCKED(cc->certStore, c);
866
 
        nssCertificateStore_Unlock(cc->certStore, &lockTrace, &unlockTrace);
867
 
        c->object.cryptoContext = NULL;
868
 
        cert->istemp = PR_FALSE;
869
 
        cert->isperm = PR_TRUE;
870
 
    }
871
 
 
872
878
    /* set the id for the cert */
873
879
    nssItem_Create(c->object.arena, &c->id, keyID->len, keyID->data);
874
880
    if (!c->id.data) {
913
919
        }
914
920
        goto loser;
915
921
    }
 
922
 
 
923
    if (c->object.cryptoContext) {
 
924
        /* Delete the temp instance */
 
925
        NSSCryptoContext *cc = c->object.cryptoContext;
 
926
        nssCertificateStore_Lock(cc->certStore, &lockTrace);
 
927
        nssCertificateStore_RemoveCertLOCKED(cc->certStore, c);
 
928
        nssCertificateStore_Unlock(cc->certStore, &lockTrace, &unlockTrace);
 
929
        c->object.cryptoContext = NULL;
 
930
        cert->istemp = PR_FALSE;
 
931
        cert->isperm = PR_TRUE;
 
932
    }
 
933
 
916
934
    /* add the new instance to the cert, force an update of the
917
935
     * CERTCertificate, and finish
918
936
     */
1927
1945
        nssPKIObjectCollection_Destroy(collection);
1928
1946
        return SECFailure;
1929
1947
    }
1930
 
    (void *)nssTrustDomain_GetCertsFromCache(td, certList);
 
1948
    (void)nssTrustDomain_GetCertsFromCache(td, certList);
1931
1949
    transfer_token_certs_to_collection(certList, tok, collection);
1932
1950
    instances = nssToken_FindObjects(tok, NULL, CKO_CERTIFICATE,
1933
1951
                                     tokenOnly, 0, &nssrv);