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

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/pk11wrap/pk11slot.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:
482
482
SECMOD_HasRootCerts(void)
483
483
{
484
484
   SECMODModuleList *mlp;
485
 
   SECMODModuleList *modules = SECMOD_GetDefaultModuleList();
 
485
   SECMODModuleList *modules;
486
486
   SECMODListLock *moduleLock = SECMOD_GetDefaultModuleListLock();
487
487
   int i;
488
488
   PRBool found = PR_FALSE;
489
489
 
 
490
    if (!moduleLock) {
 
491
        PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
 
492
        return found;
 
493
    }
 
494
 
490
495
   /* work through all the slots */
491
496
   SECMOD_GetReadLock(moduleLock);
 
497
   modules = SECMOD_GetDefaultModuleList();
492
498
   for(mlp = modules; mlp != NULL; mlp = mlp->next) {
493
499
        for (i=0; i < mlp->module->slotCount; i++) {
494
500
            PK11SlotInfo *tmpSlot = mlp->module->slots[i];
514
520
                        const char* tokenName, PRBool presentOnly)
515
521
{
516
522
    SECMODModuleList *mlp;
517
 
    SECMODModuleList *modules = SECMOD_GetDefaultModuleList();
 
523
    SECMODModuleList *modules;
518
524
    SECMODListLock *moduleLock = SECMOD_GetDefaultModuleListLock();
519
525
    int i;
520
526
    PK11SlotList* slotList = NULL;
521
527
    PRUint32 slotcount = 0;
522
528
    SECStatus rv = SECSuccess;
523
529
 
 
530
    if (!moduleLock) {
 
531
        PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
 
532
        return slotList;
 
533
    }
 
534
 
524
535
    slotList = PK11_NewSlotList();
525
536
    if (!slotList) {
526
537
        PORT_SetError(SEC_ERROR_NO_MEMORY);
527
 
        return NULL;
 
538
        return slotList;
528
539
    }
529
540
 
530
541
    if ( ((NULL == dllName) || (0 == *dllName)) &&
537
548
 
538
549
    /* work through all the slots */
539
550
    SECMOD_GetReadLock(moduleLock);
 
551
    modules = SECMOD_GetDefaultModuleList();
540
552
    for (mlp = modules; mlp != NULL; mlp = mlp->next) {
541
553
        PORT_Assert(mlp->module);
542
554
        if (!mlp->module) {
584
596
PK11_FindSlotByName(const char *name)
585
597
{
586
598
   SECMODModuleList *mlp;
587
 
   SECMODModuleList *modules = SECMOD_GetDefaultModuleList();
 
599
   SECMODModuleList *modules;
588
600
   SECMODListLock *moduleLock = SECMOD_GetDefaultModuleListLock();
589
601
   int i;
590
602
   PK11SlotInfo *slot = NULL;
591
603
 
 
604
    if (!moduleLock) {
 
605
        PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
 
606
        return slot;
 
607
    }
592
608
   if ((name == NULL) || (*name == 0)) {
593
609
        return PK11_GetInternalKeySlot();
594
610
   }
595
611
 
596
612
   /* work through all the slots */
597
613
   SECMOD_GetReadLock(moduleLock);
 
614
   modules = SECMOD_GetDefaultModuleList();
598
615
   for(mlp = modules; mlp != NULL; mlp = mlp->next) {
599
616
        for (i=0; i < mlp->module->slotCount; i++) {
600
617
            PK11SlotInfo *tmpSlot = mlp->module->slots[i];
621
638
PK11_FindSlotBySerial(char *serial)
622
639
{
623
640
   SECMODModuleList *mlp;
624
 
   SECMODModuleList *modules = SECMOD_GetDefaultModuleList();
 
641
   SECMODModuleList *modules;
625
642
   SECMODListLock *moduleLock = SECMOD_GetDefaultModuleListLock();
626
643
   int i;
627
644
   PK11SlotInfo *slot = NULL;
628
645
 
 
646
    if (!moduleLock) {
 
647
        PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
 
648
        return slot;
 
649
    }
629
650
   /* work through all the slots */
630
651
   SECMOD_GetReadLock(moduleLock);
 
652
   modules = SECMOD_GetDefaultModuleList();
631
653
   for(mlp = modules; mlp != NULL; mlp = mlp->next) {
632
654
        for (i=0; i < mlp->module->slotCount; i++) {
633
655
            PK11SlotInfo *tmpSlot = mlp->module->slots[i];
1107
1129
                                                        PR_TRUE : PR_FALSE);
1108
1130
    slot->readOnly = ((tokenInfo.flags & CKF_WRITE_PROTECTED) ? 
1109
1131
                                                        PR_TRUE : PR_FALSE);
 
1132
        
 
1133
         
1110
1134
    slot->hasRandom = ((tokenInfo.flags & CKF_RNG) ? PR_TRUE : PR_FALSE);
1111
1135
    slot->protectedAuthPath =
1112
1136
                ((tokenInfo.flags & CKF_PROTECTED_AUTHENTICATION_PATH) 
1226
1250
            PK11_FreeSlot(int_slot);
1227
1251
        }
1228
1252
    }
1229
 
 
 
1253
    /* work around a problem in softoken where it incorrectly
 
1254
     * reports databases opened read only as read/write. */
 
1255
    if (slot->isInternal && !slot->readOnly) {
 
1256
        CK_SESSION_HANDLE session = CK_INVALID_SESSION;
 
1257
 
 
1258
        /* try to open a R/W session */
 
1259
        crv =PK11_GETTAB(slot)->C_OpenSession(slot->slotID,
 
1260
              CKF_RW_SESSION|CKF_SERIAL_SESSION, slot, pk11_notify ,&session);
 
1261
        /* what a well behaved token should return if you open 
 
1262
         * a RW session on a read only token */
 
1263
        if (crv == CKR_TOKEN_WRITE_PROTECTED) {
 
1264
            slot->readOnly = PR_TRUE;
 
1265
        } else if (crv == CKR_OK) {
 
1266
            CK_SESSION_INFO sessionInfo;
 
1267
 
 
1268
            /* Because of a second bug in softoken, which silently returns
 
1269
             * a RO session, we need to check what type of session we got. */
 
1270
            crv = PK11_GETTAB(slot)->C_GetSessionInfo(session, &sessionInfo);
 
1271
            if (crv == CKR_OK) {
 
1272
                if ((sessionInfo.flags & CKF_RW_SESSION) == 0) {
 
1273
                    /* session was readonly, so this softoken slot must be                           * readonly */
 
1274
                    slot->readOnly = PR_TRUE;
 
1275
                }
 
1276
            }
 
1277
            PK11_GETTAB(slot)->C_CloseSession(session);
 
1278
        }
 
1279
    }
1230
1280
        
1231
1281
    return SECSuccess;
1232
1282
}
1517
1567
}
1518
1568
 
1519
1569
PRBool
 
1570
PK11_IsInternalKeySlot(PK11SlotInfo *slot)
 
1571
{
 
1572
    PK11SlotInfo *int_slot;
 
1573
    PRBool result;
 
1574
 
 
1575
    if (!slot->isInternal) {
 
1576
        return PR_FALSE;
 
1577
    }
 
1578
 
 
1579
    int_slot = PK11_GetInternalKeySlot();
 
1580
    result = (int_slot == slot) ? PR_TRUE : PR_FALSE;
 
1581
    PK11_FreeSlot(int_slot);
 
1582
    return result;
 
1583
}
 
1584
 
 
1585
PRBool
1520
1586
PK11_NeedLogin(PK11SlotInfo *slot)
1521
1587
{
1522
1588
    return slot->needLogin;
1659
1725
    return (PRBool)((slot->flags & CKF_USER_PIN_INITIALIZED) == 0);
1660
1726
}
1661
1727
 
 
1728
static PK11SlotInfo *pk11InternalKeySlot = NULL;
 
1729
void
 
1730
pk11_SetInternalKeySlot(PK11SlotInfo *slot)
 
1731
{
 
1732
   if (pk11InternalKeySlot) {
 
1733
        PK11_FreeSlot(pk11InternalKeySlot);
 
1734
   }
 
1735
   pk11InternalKeySlot = slot ? PK11_ReferenceSlot(slot) : NULL;
 
1736
}
 
1737
 
 
1738
 
1662
1739
/* get the internal key slot. FIPS has only one slot for both key slots and
1663
1740
 * default slots */
1664
1741
PK11SlotInfo *
1665
1742
PK11_GetInternalKeySlot(void)
1666
1743
{
1667
 
    SECMODModule *mod = SECMOD_GetInternalModule();
 
1744
    SECMODModule *mod;
 
1745
 
 
1746
    if (pk11InternalKeySlot) {
 
1747
        return PK11_ReferenceSlot(pk11InternalKeySlot);
 
1748
    }
 
1749
 
 
1750
    mod = SECMOD_GetInternalModule();
1668
1751
    PORT_Assert(mod != NULL);
1669
1752
    if (!mod) {
1670
1753
        PORT_SetError( SEC_ERROR_NO_MODULE );
1683
1766
        PORT_SetError( SEC_ERROR_NO_MODULE );
1684
1767
        return NULL;
1685
1768
    }
 
1769
    if (mod->isFIPS) {
 
1770
        return PK11_GetInternalKeySlot();
 
1771
    }
1686
1772
    return PK11_ReferenceSlot(mod->slots[0]);
1687
1773
}
1688
1774
 
1722
1808
PK11_TokenExists(CK_MECHANISM_TYPE type)
1723
1809
{
1724
1810
    SECMODModuleList *mlp;
1725
 
    SECMODModuleList *modules = SECMOD_GetDefaultModuleList();
 
1811
    SECMODModuleList *modules;
1726
1812
    SECMODListLock *moduleLock = SECMOD_GetDefaultModuleListLock();
1727
1813
    PK11SlotInfo *slot;
1728
1814
    PRBool found = PR_FALSE;
1729
1815
    int i;
1730
1816
 
 
1817
    if (!moduleLock) {
 
1818
        PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
 
1819
        return found;
 
1820
    }
1731
1821
    /* we only need to know if there is a token that does this mechanism.
1732
1822
     * check the internal module first because it's fast, and supports 
1733
1823
     * almost everything. */
1739
1829
    if (found) return PR_TRUE; /* bypass getting module locks */
1740
1830
 
1741
1831
    SECMOD_GetReadLock(moduleLock);
 
1832
    modules = SECMOD_GetDefaultModuleList();
1742
1833
    for(mlp = modules; mlp != NULL && (!found); mlp = mlp->next) {
1743
1834
        for (i=0; i < mlp->module->slotCount; i++) {
1744
1835
            slot = mlp->module->slots[i];
1764
1855
PK11_GetAllTokens(CK_MECHANISM_TYPE type, PRBool needRW, PRBool loadCerts, 
1765
1856
                  void *wincx)
1766
1857
{
1767
 
    PK11SlotList *     list         = PK11_NewSlotList();
1768
 
    PK11SlotList *     loginList    = PK11_NewSlotList();
1769
 
    PK11SlotList *     friendlyList = PK11_NewSlotList();
 
1858
    PK11SlotList *     list;
 
1859
    PK11SlotList *     loginList;
 
1860
    PK11SlotList *     friendlyList;
1770
1861
    SECMODModuleList * mlp;
1771
 
    SECMODModuleList * modules      = SECMOD_GetDefaultModuleList();
1772
 
    SECMODListLock *   moduleLock   = SECMOD_GetDefaultModuleListLock();
 
1862
    SECMODModuleList * modules;
 
1863
    SECMODListLock *   moduleLock;
1773
1864
    int                i;
1774
1865
#if defined( XP_WIN32 ) 
1775
1866
    int                j            = 0;
1776
1867
    PRInt32            waste[16];
1777
1868
#endif
1778
1869
 
 
1870
    moduleLock   = SECMOD_GetDefaultModuleListLock();
 
1871
    if (!moduleLock) {
 
1872
        PORT_SetError(SEC_ERROR_NOT_INITIALIZED);
 
1873
        return NULL;
 
1874
    }
 
1875
 
 
1876
    list         = PK11_NewSlotList();
 
1877
    loginList    = PK11_NewSlotList();
 
1878
    friendlyList = PK11_NewSlotList();
1779
1879
    if ((list == NULL)  || (loginList == NULL) || (friendlyList == NULL)) {
1780
1880
        if (list) PK11_FreeSlotList(list);
1781
1881
        if (loginList) PK11_FreeSlotList(loginList);
1784
1884
    }
1785
1885
 
1786
1886
    SECMOD_GetReadLock(moduleLock);
 
1887
 
 
1888
    modules      = SECMOD_GetDefaultModuleList();
1787
1889
    for(mlp = modules; mlp != NULL; mlp = mlp->next) {
1788
1890
 
1789
1891
#if defined( XP_WIN32 )