Coverage Report

Created: 2026-11-15 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/nss/lib/pki/pkibase.c
Line
Count
Source
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#ifndef DEV_H
6
#include "dev.h"
7
#endif /* DEV_H */
8
9
#ifndef PKIM_H
10
#include "pkim.h"
11
#endif /* PKIM_H */
12
13
#include "pki3hack.h"
14
15
extern const NSSError NSS_ERROR_NOT_FOUND;
16
17
NSS_IMPLEMENT void
18
nssPKIObject_Lock(nssPKIObject *object)
19
7.29M
{
20
7.29M
    switch (object->lockType) {
21
7.29M
        case nssPKIMonitor:
22
7.29M
            PR_EnterMonitor(object->sync.mlock);
23
7.29M
            break;
24
0
        case nssPKILock:
25
0
            PR_Lock(object->sync.lock);
26
0
            break;
27
0
        default:
28
0
            PORT_Assert(0);
29
7.29M
    }
30
7.29M
}
31
32
NSS_IMPLEMENT void
33
nssPKIObject_Unlock(nssPKIObject *object)
34
7.29M
{
35
7.29M
    switch (object->lockType) {
36
7.29M
        case nssPKIMonitor:
37
7.29M
            PR_ExitMonitor(object->sync.mlock);
38
7.29M
            break;
39
0
        case nssPKILock:
40
0
            PR_Unlock(object->sync.lock);
41
0
            break;
42
0
        default:
43
0
            PORT_Assert(0);
44
7.29M
    }
45
7.29M
}
46
47
NSS_IMPLEMENT PRStatus
48
nssPKIObject_NewLock(nssPKIObject *object, nssPKILockType lockType)
49
1.31M
{
50
1.31M
    object->lockType = lockType;
51
1.31M
    switch (lockType) {
52
1.31M
        case nssPKIMonitor:
53
1.31M
            object->sync.mlock = PR_NewMonitor();
54
1.31M
            return (object->sync.mlock ? PR_SUCCESS : PR_FAILURE);
55
0
        case nssPKILock:
56
0
            object->sync.lock = PR_NewLock();
57
0
            return (object->sync.lock ? PR_SUCCESS : PR_FAILURE);
58
0
        default:
59
0
            PORT_Assert(0);
60
0
            return PR_FAILURE;
61
1.31M
    }
62
1.31M
}
63
64
NSS_IMPLEMENT void
65
nssPKIObject_DestroyLock(nssPKIObject *object)
66
1.31M
{
67
1.31M
    switch (object->lockType) {
68
1.31M
        case nssPKIMonitor:
69
1.31M
            PR_DestroyMonitor(object->sync.mlock);
70
1.31M
            object->sync.mlock = NULL;
71
1.31M
            break;
72
0
        case nssPKILock:
73
0
            PR_DestroyLock(object->sync.lock);
74
0
            object->sync.lock = NULL;
75
0
            break;
76
0
        default:
77
0
            PORT_Assert(0);
78
1.31M
    }
79
1.31M
}
80
81
NSS_IMPLEMENT nssPKIObject *
82
nssPKIObject_Create(
83
    NSSArena *arenaOpt,
84
    nssCryptokiObject *instanceOpt,
85
    NSSTrustDomain *td,
86
    NSSCryptoContext *cc,
87
    nssPKILockType lockType)
88
1.31M
{
89
1.31M
    NSSArena *arena;
90
1.31M
    nssArenaMark *mark = NULL;
91
1.31M
    nssPKIObject *object;
92
1.31M
    if (arenaOpt) {
93
0
        arena = arenaOpt;
94
0
        mark = nssArena_Mark(arena);
95
1.31M
    } else {
96
1.31M
        arena = nssArena_Create();
97
1.31M
        if (!arena) {
98
0
            return (nssPKIObject *)NULL;
99
0
        }
100
1.31M
    }
101
1.31M
    object = nss_ZNEW(arena, nssPKIObject);
102
1.31M
    if (!object) {
103
0
        goto loser;
104
0
    }
105
1.31M
    object->arena = arena;
106
1.31M
    object->trustDomain = td; /* XXX */
107
1.31M
    object->cryptoContext = cc;
108
1.31M
    if (PR_SUCCESS != nssPKIObject_NewLock(object, lockType)) {
109
0
        goto loser;
110
0
    }
111
1.31M
    if (instanceOpt) {
112
3.02k
        if (nssPKIObject_AddInstance(object, instanceOpt) != PR_SUCCESS) {
113
0
            goto loser;
114
0
        }
115
3.02k
    }
116
1.31M
    PR_ATOMIC_INCREMENT(&object->refCount);
117
1.31M
    if (mark) {
118
0
        nssArena_Unmark(arena, mark);
119
0
    }
120
1.31M
    return object;
121
0
loser:
122
0
    if (mark) {
123
0
        nssArena_Release(arena, mark);
124
0
    } else {
125
0
        nssArena_Destroy(arena);
126
0
    }
127
0
    return (nssPKIObject *)NULL;
128
1.31M
}
129
130
NSS_IMPLEMENT PRBool
131
nssPKIObject_Destroy(
132
    nssPKIObject *object)
133
1.54M
{
134
1.54M
    PRUint32 i;
135
1.54M
    PRInt32 refCount = PR_ATOMIC_DECREMENT(&object->refCount);
136
1.54M
    PORT_ReleaseAssert(refCount >= 0);
137
1.54M
    if (refCount == 0) {
138
0
        for (i = 0; i < object->numInstances; i++) {
139
0
            nssCryptokiObject_Destroy(object->instances[i]);
140
0
        }
141
0
        nssPKIObject_DestroyLock(object);
142
0
        nssArena_Destroy(object->arena);
143
0
        return PR_TRUE;
144
0
    }
145
1.54M
    return PR_FALSE;
146
1.54M
}
147
148
NSS_IMPLEMENT nssPKIObject *
149
nssPKIObject_AddRef(
150
    nssPKIObject *object)
151
2.15M
{
152
2.15M
    PRInt32 refCount = PR_ATOMIC_INCREMENT(&object->refCount);
153
2.15M
    PORT_ReleaseAssert(refCount > 1);
154
2.15M
    return object;
155
2.15M
}
156
157
NSS_IMPLEMENT PRStatus
158
nssPKIObject_AddInstance(
159
    nssPKIObject *object,
160
    nssCryptokiObject *instance)
161
3.02k
{
162
3.02k
    nssCryptokiObject **newInstances = NULL;
163
164
3.02k
    nssPKIObject_Lock(object);
165
3.02k
    if (object->numInstances == 0) {
166
3.02k
        newInstances = nss_ZNEWARRAY(object->arena,
167
3.02k
                                     nssCryptokiObject *,
168
3.02k
                                     object->numInstances + 1);
169
3.02k
    } else {
170
0
        PRBool found = PR_FALSE;
171
0
        PRUint32 i;
172
0
        for (i = 0; i < object->numInstances; i++) {
173
0
            if (nssCryptokiObject_Equal(object->instances[i], instance)) {
174
0
                found = PR_TRUE;
175
0
                break;
176
0
            }
177
0
        }
178
0
        if (found) {
179
            /* The new instance is identical to one in the array, except
180
             * perhaps that the label may be different.  So replace
181
             * the label in the array instance with the label from the
182
             * new instance, and discard the new instance.
183
             */
184
0
            nss_ZFreeIf(object->instances[i]->label);
185
0
            object->instances[i]->label = instance->label;
186
0
            nssPKIObject_Unlock(object);
187
0
            instance->label = NULL;
188
0
            nssCryptokiObject_Destroy(instance);
189
0
            return PR_SUCCESS;
190
0
        }
191
0
        newInstances = nss_ZREALLOCARRAY(object->instances,
192
0
                                         nssCryptokiObject *,
193
0
                                         object->numInstances + 1);
194
0
    }
195
3.02k
    if (newInstances) {
196
3.02k
        object->instances = newInstances;
197
3.02k
        newInstances[object->numInstances++] = instance;
198
3.02k
    }
199
3.02k
    nssPKIObject_Unlock(object);
200
3.02k
    return (newInstances ? PR_SUCCESS : PR_FAILURE);
201
3.02k
}
202
203
NSS_IMPLEMENT PRBool
204
nssPKIObject_HasInstance(
205
    nssPKIObject *object,
206
    nssCryptokiObject *instance)
207
11
{
208
11
    PRUint32 i;
209
11
    PRBool hasIt = PR_FALSE;
210
11
    ;
211
11
    nssPKIObject_Lock(object);
212
12
    for (i = 0; i < object->numInstances; i++) {
213
11
        if (nssCryptokiObject_Equal(object->instances[i], instance)) {
214
10
            hasIt = PR_TRUE;
215
10
            break;
216
10
        }
217
11
    }
218
11
    nssPKIObject_Unlock(object);
219
11
    return hasIt;
220
11
}
221
222
NSS_IMPLEMENT PRStatus
223
nssPKIObject_RemoveInstanceForToken(
224
    nssPKIObject *object,
225
    NSSToken *token)
226
0
{
227
0
    PRUint32 i;
228
0
    nssCryptokiObject *instanceToRemove = NULL;
229
0
    nssPKIObject_Lock(object);
230
0
    if (object->numInstances == 0) {
231
0
        nssPKIObject_Unlock(object);
232
0
        return PR_SUCCESS;
233
0
    }
234
0
    for (i = 0; i < object->numInstances; i++) {
235
0
        if (object->instances[i]->token == token) {
236
0
            instanceToRemove = object->instances[i];
237
0
            object->instances[i] = object->instances[object->numInstances - 1];
238
0
            object->instances[object->numInstances - 1] = NULL;
239
0
            break;
240
0
        }
241
0
    }
242
0
    if (--object->numInstances > 0) {
243
0
        nssCryptokiObject **instances = nss_ZREALLOCARRAY(object->instances,
244
0
                                                          nssCryptokiObject *,
245
0
                                                          object->numInstances);
246
0
        if (instances) {
247
0
            object->instances = instances;
248
0
        }
249
0
    } else {
250
0
        nss_ZFreeIf(object->instances);
251
0
    }
252
0
    nssCryptokiObject_Destroy(instanceToRemove);
253
0
    nssPKIObject_Unlock(object);
254
0
    return PR_SUCCESS;
255
0
}
256
257
/* this needs more thought on what will happen when there are multiple
258
 * instances
259
 */
260
NSS_IMPLEMENT PRStatus
261
nssPKIObject_DeleteStoredObject(
262
    nssPKIObject *object,
263
    NSSCallback *uhh,
264
    PRBool isFriendly)
265
0
{
266
0
    PRUint32 i, numNotDestroyed;
267
0
    PRStatus status = PR_SUCCESS;
268
0
    numNotDestroyed = 0;
269
0
    nssPKIObject_Lock(object);
270
0
    for (i = 0; i < object->numInstances; i++) {
271
0
        nssCryptokiObject *instance = object->instances[i];
272
0
        status = nssToken_DeleteStoredObject(instance);
273
0
        object->instances[i] = NULL;
274
0
        if (status == PR_SUCCESS) {
275
0
            nssCryptokiObject_Destroy(instance);
276
0
        } else {
277
0
            object->instances[numNotDestroyed++] = instance;
278
0
        }
279
0
    }
280
0
    if (numNotDestroyed == 0) {
281
0
        nss_ZFreeIf(object->instances);
282
0
        object->numInstances = 0;
283
0
    } else {
284
0
        object->numInstances = numNotDestroyed;
285
0
    }
286
0
    nssPKIObject_Unlock(object);
287
0
    return status;
288
0
}
289
290
NSS_IMPLEMENT NSSToken **
291
nssPKIObject_GetTokens(
292
    nssPKIObject *object,
293
    PRStatus *statusOpt)
294
0
{
295
0
    NSSToken **tokens = NULL;
296
0
    nssPKIObject_Lock(object);
297
0
    if (object->numInstances > 0) {
298
0
        tokens = nss_ZNEWARRAY(NULL, NSSToken *, object->numInstances + 1);
299
0
        if (tokens) {
300
0
            PRUint32 i;
301
0
            for (i = 0; i < object->numInstances; i++) {
302
0
                tokens[i] = nssToken_AddRef(object->instances[i]->token);
303
0
            }
304
0
        }
305
0
    }
306
0
    nssPKIObject_Unlock(object);
307
0
    if (statusOpt)
308
0
        *statusOpt = PR_SUCCESS; /* until more logic here */
309
0
    return tokens;
310
0
}
311
312
NSS_IMPLEMENT NSSUTF8 *
313
nssPKIObject_GetNicknameForToken(
314
    nssPKIObject *object,
315
    NSSToken *tokenOpt)
316
3.86k
{
317
3.86k
    PRUint32 i;
318
3.86k
    NSSUTF8 *nickname = NULL;
319
3.86k
    nssPKIObject_Lock(object);
320
3.86k
    for (i = 0; i < object->numInstances; i++) {
321
3.02k
        if ((!tokenOpt && object->instances[i]->label) ||
322
3.02k
            (object->instances[i]->token == tokenOpt)) {
323
            /* Must copy, see bug 745548 */
324
3.02k
            nickname = nssUTF8_Duplicate(object->instances[i]->label, NULL);
325
3.02k
            break;
326
3.02k
        }
327
3.02k
    }
328
3.86k
    nssPKIObject_Unlock(object);
329
3.86k
    return nickname;
330
3.86k
}
331
332
NSS_IMPLEMENT nssCryptokiObject **
333
nssPKIObject_GetInstances(
334
    nssPKIObject *object)
335
91.8k
{
336
91.8k
    nssCryptokiObject **instances = NULL;
337
91.8k
    PRUint32 i;
338
339
91.8k
    nssPKIObject_Lock(object);
340
91.8k
    if (object->numInstances == 0) {
341
85.7k
        nssPKIObject_Unlock(object);
342
85.7k
        return (nssCryptokiObject **)NULL;
343
85.7k
    }
344
6.06k
    instances = nss_ZNEWARRAY(NULL, nssCryptokiObject *,
345
6.06k
                              object->numInstances + 1);
346
6.06k
    if (instances) {
347
12.1k
        for (i = 0; i < object->numInstances; i++) {
348
6.06k
            instances[i] = nssCryptokiObject_Clone(object->instances[i]);
349
6.06k
        }
350
6.06k
    }
351
6.06k
    nssPKIObject_Unlock(object);
352
6.06k
    return instances;
353
91.8k
}
354
355
NSS_IMPLEMENT void
356
nssCertificateArray_Destroy(
357
    NSSCertificate **certs)
358
45.9k
{
359
45.9k
    if (certs) {
360
21.2k
        NSSCertificate **certp;
361
48.5k
        for (certp = certs; *certp; certp++) {
362
27.3k
            if ((*certp)->decoding) {
363
27.3k
                CERTCertificate *cc = STAN_GetCERTCertificate(*certp);
364
27.3k
                if (cc) {
365
27.3k
                    CERT_DestroyCertificate(cc);
366
27.3k
                }
367
27.3k
                continue;
368
27.3k
            }
369
0
            nssCertificate_Destroy(*certp);
370
0
        }
371
21.2k
        nss_ZFreeIf(certs);
372
21.2k
    }
373
45.9k
}
374
375
NSS_IMPLEMENT NSSCertificate **
376
nssCertificateArray_Join(
377
    NSSCertificate **certs1,
378
    NSSCertificate **certs2)
379
24.7k
{
380
24.7k
    if (certs1 && certs2) {
381
10
        NSSCertificate **certs, **cp;
382
10
        PRUint32 count = 0;
383
10
        PRUint32 count1 = 0;
384
10
        cp = certs1;
385
20
        while (*cp++)
386
10
            count1++;
387
10
        count = count1;
388
10
        cp = certs2;
389
20
        while (*cp++)
390
10
            count++;
391
10
        certs = nss_ZREALLOCARRAY(certs1, NSSCertificate *, count + 1);
392
10
        if (!certs) {
393
0
            nss_ZFreeIf(certs1);
394
0
            nss_ZFreeIf(certs2);
395
0
            return (NSSCertificate **)NULL;
396
0
        }
397
20
        for (cp = certs2; *cp; cp++, count1++) {
398
10
            certs[count1] = *cp;
399
10
        }
400
10
        nss_ZFreeIf(certs2);
401
10
        return certs;
402
24.7k
    } else if (certs1) {
403
21.1k
        return certs1;
404
21.1k
    } else {
405
3.54k
        return certs2;
406
3.54k
    }
407
24.7k
}
408
409
NSS_IMPLEMENT NSSCertificate *
410
nssCertificateArray_FindBestCertificate(
411
    NSSCertificate **certs,
412
    NSSTime *timeOpt,
413
    const NSSUsage *usage,
414
    NSSPolicies *policiesOpt)
415
21.2k
{
416
21.2k
    NSSCertificate *bestCert = NULL;
417
21.2k
    nssDecodedCert *bestdc = NULL;
418
21.2k
    NSSTime *time, sTime;
419
21.2k
    PRBool bestCertMatches = PR_FALSE;
420
21.2k
    PRBool thisCertMatches;
421
21.2k
    PRBool bestCertIsValidAtTime = PR_FALSE;
422
21.2k
    PRBool bestCertIsTrusted = PR_FALSE;
423
424
21.2k
    if (timeOpt) {
425
21.2k
        time = timeOpt;
426
21.2k
    } else {
427
0
        NSSTime_Now(&sTime);
428
0
        time = &sTime;
429
0
    }
430
21.2k
    if (!certs) {
431
0
        return (NSSCertificate *)NULL;
432
0
    }
433
48.5k
    for (; *certs; certs++) {
434
27.3k
        nssDecodedCert *dc;
435
27.3k
        NSSCertificate *c = *certs;
436
27.3k
        dc = nssCertificate_GetDecoding(c);
437
27.3k
        if (!dc)
438
0
            continue;
439
27.3k
        thisCertMatches = dc->matchUsage(dc, usage);
440
27.3k
        if (!bestCert) {
441
            /* always take the first cert, but remember whether or not
442
             * the usage matched
443
             */
444
20.9k
            bestCert = nssCertificate_AddRef(c);
445
20.9k
            bestCertMatches = thisCertMatches;
446
20.9k
            bestdc = dc;
447
20.9k
            continue;
448
20.9k
        } else {
449
6.35k
            if (bestCertMatches && !thisCertMatches) {
450
                /* if already have a cert for this usage, and if this cert
451
                 * doesn't have the correct usage, continue
452
                 */
453
0
                continue;
454
6.35k
            } else if (!bestCertMatches && thisCertMatches) {
455
                /* this one does match usage, replace the other */
456
0
                nssCertificate_Destroy(bestCert);
457
0
                bestCert = nssCertificate_AddRef(c);
458
0
                bestCertMatches = thisCertMatches;
459
0
                bestdc = dc;
460
0
                continue;
461
0
            }
462
            /* this cert match as well as any cert we've found so far,
463
             * defer to time/policies
464
             * */
465
6.35k
        }
466
        /* time */
467
6.35k
        if (bestCertIsValidAtTime || bestdc->isValidAtTime(bestdc, time)) {
468
            /* The current best cert is valid at time */
469
6.32k
            bestCertIsValidAtTime = PR_TRUE;
470
6.32k
            if (!dc->isValidAtTime(dc, time)) {
471
                /* If the new cert isn't valid at time, it's not better */
472
1.93k
                continue;
473
1.93k
            }
474
6.32k
        } else {
475
            /* The current best cert is not valid at time */
476
24
            if (dc->isValidAtTime(dc, time)) {
477
                /* If the new cert is valid at time, it's better */
478
5
                nssCertificate_Destroy(bestCert);
479
5
                bestCert = nssCertificate_AddRef(c);
480
5
                bestdc = dc;
481
5
                bestCertIsValidAtTime = PR_TRUE;
482
5
                continue;
483
5
            }
484
24
        }
485
        /* Either they are both valid at time, or neither valid.
486
         * If only one is trusted for this usage, take it.
487
         */
488
4.40k
        if (bestCertIsTrusted || bestdc->isTrustedForUsage(bestdc, usage)) {
489
0
            bestCertIsTrusted = PR_TRUE;
490
0
            if (!dc->isTrustedForUsage(dc, usage)) {
491
0
                continue;
492
0
            }
493
4.40k
        } else {
494
            /* The current best cert is not trusted */
495
4.40k
            if (dc->isTrustedForUsage(dc, usage)) {
496
                /* If the new cert is trusted, it's better */
497
0
                nssCertificate_Destroy(bestCert);
498
0
                bestCert = nssCertificate_AddRef(c);
499
0
                bestdc = dc;
500
0
                bestCertIsTrusted = PR_TRUE;
501
0
                continue;
502
0
            }
503
4.40k
        }
504
        /* Otherwise, take the newer one. */
505
4.40k
        if (!bestdc->isNewerThan(bestdc, dc)) {
506
3.65k
            nssCertificate_Destroy(bestCert);
507
3.65k
            bestCert = nssCertificate_AddRef(c);
508
3.65k
            bestdc = dc;
509
3.65k
            continue;
510
3.65k
        }
511
        /* policies */
512
        /* XXX later -- defer to policies */
513
4.40k
    }
514
21.2k
    return bestCert;
515
21.2k
}
516
517
NSS_IMPLEMENT void
518
nssCRLArray_Destroy(
519
    NSSCRL **crls)
520
0
{
521
0
    if (crls) {
522
0
        NSSCRL **crlp;
523
0
        for (crlp = crls; *crlp; crlp++) {
524
0
            nssCRL_Destroy(*crlp);
525
0
        }
526
0
        nss_ZFreeIf(crls);
527
0
    }
528
0
}
529
530
/*
531
 * Object collections
532
 */
533
534
typedef enum {
535
    pkiObjectType_Certificate = 0,
536
    pkiObjectType_CRL = 1,
537
} pkiObjectType;
538
539
/* Each object is defined by a set of items that uniquely identify it.
540
 * Here are the uid sets:
541
 *
542
 * NSSCertificate ==>  { issuer, serial }
543
 */
544
5.13k
#define MAX_ITEMS_FOR_UID 2
545
546
/* pkiObjectCollectionNode
547
 *
548
 * A node in the collection is the set of unique identifiers for a single
549
 * object, along with either the actual object or a proto-object.
550
 */
551
typedef struct
552
{
553
    PRCList link;
554
    PRBool haveObject;
555
    nssPKIObject *object;
556
    NSSItem uid[MAX_ITEMS_FOR_UID];
557
} pkiObjectCollectionNode;
558
559
/* nssPKIObjectCollection
560
 *
561
 * The collection is the set of all objects, plus the interfaces needed
562
 * to manage the objects.
563
 *
564
 */
565
struct nssPKIObjectCollectionStr {
566
    NSSArena *arena;
567
    NSSTrustDomain *td;
568
    NSSCryptoContext *cc;
569
    PRCList head; /* list of pkiObjectCollectionNode's */
570
    PRUint32 size;
571
    pkiObjectType objectType;
572
    void (*destroyObject)(nssPKIObject *o);
573
    PRStatus (*getUIDFromObject)(nssPKIObject *o, NSSItem *uid);
574
    PRStatus (*getUIDFromInstance)(nssCryptokiObject *co, NSSItem *uid,
575
                                   NSSArena *arena);
576
    nssPKIObject *(*createObject)(nssPKIObject *o);
577
    nssPKILockType lockType; /* type of lock to use for new proto-objects */
578
};
579
580
static nssPKIObjectCollection *
581
nssPKIObjectCollection_Create(
582
    NSSTrustDomain *td,
583
    NSSCryptoContext *ccOpt,
584
    nssPKILockType lockType)
585
56.7k
{
586
56.7k
    NSSArena *arena;
587
56.7k
    nssPKIObjectCollection *rvCollection = NULL;
588
56.7k
    arena = nssArena_Create();
589
56.7k
    if (!arena) {
590
0
        return (nssPKIObjectCollection *)NULL;
591
0
    }
592
56.7k
    rvCollection = nss_ZNEW(arena, nssPKIObjectCollection);
593
56.7k
    if (!rvCollection) {
594
0
        goto loser;
595
0
    }
596
56.7k
    PR_INIT_CLIST(&rvCollection->head);
597
56.7k
    rvCollection->arena = arena;
598
56.7k
    rvCollection->td = td; /* XXX */
599
56.7k
    rvCollection->cc = ccOpt;
600
56.7k
    rvCollection->lockType = lockType;
601
56.7k
    return rvCollection;
602
0
loser:
603
0
    nssArena_Destroy(arena);
604
0
    return (nssPKIObjectCollection *)NULL;
605
56.7k
}
606
607
NSS_IMPLEMENT void
608
nssPKIObjectCollection_Destroy(
609
    nssPKIObjectCollection *collection)
610
56.7k
{
611
56.7k
    if (collection) {
612
56.7k
        PRCList *link;
613
56.7k
        pkiObjectCollectionNode *node;
614
        /* first destroy any objects in the collection */
615
56.7k
        link = PR_NEXT_LINK(&collection->head);
616
109k
        while (link != &collection->head) {
617
52.9k
            node = (pkiObjectCollectionNode *)link;
618
52.9k
            if (node->haveObject) {
619
52.9k
                (*collection->destroyObject)(node->object);
620
52.9k
            } else {
621
0
                nssPKIObject_Destroy(node->object);
622
0
            }
623
52.9k
            link = PR_NEXT_LINK(link);
624
52.9k
        }
625
        /* then destroy it */
626
56.7k
        nssArena_Destroy(collection->arena);
627
56.7k
    }
628
56.7k
}
629
630
NSS_IMPLEMENT PRUint32
631
nssPKIObjectCollection_Count(
632
    nssPKIObjectCollection *collection)
633
220
{
634
220
    return collection->size;
635
220
}
636
637
NSS_IMPLEMENT PRStatus
638
nssPKIObjectCollection_AddObject(
639
    nssPKIObjectCollection *collection,
640
    nssPKIObject *object)
641
51.2k
{
642
51.2k
    pkiObjectCollectionNode *node;
643
51.2k
    node = nss_ZNEW(collection->arena, pkiObjectCollectionNode);
644
51.2k
    if (!node) {
645
0
        return PR_FAILURE;
646
0
    }
647
51.2k
    node->haveObject = PR_TRUE;
648
51.2k
    node->object = nssPKIObject_AddRef(object);
649
51.2k
    (*collection->getUIDFromObject)(object, node->uid);
650
51.2k
    PR_INIT_CLIST(&node->link);
651
51.2k
    PR_INSERT_BEFORE(&node->link, &collection->head);
652
51.2k
    collection->size++;
653
51.2k
    return PR_SUCCESS;
654
51.2k
}
655
656
static pkiObjectCollectionNode *
657
find_instance_in_collection(
658
    nssPKIObjectCollection *collection,
659
    nssCryptokiObject *instance)
660
1.72k
{
661
1.72k
    PRCList *link;
662
1.72k
    pkiObjectCollectionNode *node;
663
1.72k
    link = PR_NEXT_LINK(&collection->head);
664
1.72k
    while (link != &collection->head) {
665
11
        node = (pkiObjectCollectionNode *)link;
666
11
        if (nssPKIObject_HasInstance(node->object, instance)) {
667
10
            return node;
668
10
        }
669
1
        link = PR_NEXT_LINK(link);
670
1
    }
671
1.71k
    return (pkiObjectCollectionNode *)NULL;
672
1.72k
}
673
674
static pkiObjectCollectionNode *
675
find_object_in_collection(
676
    nssPKIObjectCollection *collection,
677
    NSSItem *uid)
678
1.71k
{
679
1.71k
    PRUint32 i;
680
1.71k
    PRStatus status;
681
1.71k
    PRCList *link;
682
1.71k
    pkiObjectCollectionNode *node;
683
1.71k
    link = PR_NEXT_LINK(&collection->head);
684
1.71k
    while (link != &collection->head) {
685
1
        node = (pkiObjectCollectionNode *)link;
686
1
        for (i = 0; i < MAX_ITEMS_FOR_UID; i++) {
687
1
            if (!nssItem_Equal(&node->uid[i], &uid[i], &status)) {
688
1
                break;
689
1
            }
690
1
        }
691
1
        if (i == MAX_ITEMS_FOR_UID) {
692
0
            return node;
693
0
        }
694
1
        link = PR_NEXT_LINK(link);
695
1
    }
696
1.71k
    return (pkiObjectCollectionNode *)NULL;
697
1.71k
}
698
699
static pkiObjectCollectionNode *
700
add_object_instance(
701
    nssPKIObjectCollection *collection,
702
    nssCryptokiObject *instance,
703
    PRBool *foundIt)
704
1.72k
{
705
1.72k
    PRUint32 i;
706
1.72k
    PRStatus status;
707
1.72k
    pkiObjectCollectionNode *node;
708
1.72k
    nssArenaMark *mark = NULL;
709
1.72k
    NSSItem uid[MAX_ITEMS_FOR_UID];
710
1.72k
    nsslibc_memset(uid, 0, sizeof uid);
711
    /* The list is traversed twice, first (here) looking to match the
712
     * { token, handle } tuple, and if that is not found, below a search
713
     * for unique identifier is done.  Here, a match means this exact object
714
     * instance is already in the collection, and we have nothing to do.
715
     */
716
1.72k
    *foundIt = PR_FALSE;
717
1.72k
    node = find_instance_in_collection(collection, instance);
718
1.72k
    if (node) {
719
        /* The collection is assumed to take over the instance.  Since we
720
         * are not using it, it must be destroyed.
721
         */
722
10
        nssCryptokiObject_Destroy(instance);
723
10
        *foundIt = PR_TRUE;
724
10
        return node;
725
10
    }
726
1.71k
    mark = nssArena_Mark(collection->arena);
727
1.71k
    if (!mark) {
728
0
        goto loser;
729
0
    }
730
1.71k
    status = (*collection->getUIDFromInstance)(instance, uid,
731
1.71k
                                               collection->arena);
732
1.71k
    if (status != PR_SUCCESS) {
733
0
        goto loser;
734
0
    }
735
    /* Search for unique identifier.  A match here means the object exists
736
     * in the collection, but does not have this instance, so the instance
737
     * needs to be added.
738
     */
739
1.71k
    node = find_object_in_collection(collection, uid);
740
1.71k
    if (node) {
741
        /* This is an object with multiple instances */
742
0
        status = nssPKIObject_AddInstance(node->object, instance);
743
1.71k
    } else {
744
        /* This is a completely new object.  Create a node for it. */
745
1.71k
        node = nss_ZNEW(collection->arena, pkiObjectCollectionNode);
746
1.71k
        if (!node) {
747
0
            goto loser;
748
0
        }
749
1.71k
        node->object = nssPKIObject_Create(NULL, instance,
750
1.71k
                                           collection->td, collection->cc,
751
1.71k
                                           collection->lockType);
752
1.71k
        if (!node->object) {
753
0
            goto loser;
754
0
        }
755
5.13k
        for (i = 0; i < MAX_ITEMS_FOR_UID; i++) {
756
3.42k
            node->uid[i] = uid[i];
757
3.42k
        }
758
1.71k
        node->haveObject = PR_FALSE;
759
1.71k
        PR_INIT_CLIST(&node->link);
760
1.71k
        PR_INSERT_BEFORE(&node->link, &collection->head);
761
1.71k
        collection->size++;
762
1.71k
        status = PR_SUCCESS;
763
1.71k
    }
764
1.71k
    nssArena_Unmark(collection->arena, mark);
765
1.71k
    return node;
766
0
loser:
767
0
    if (mark) {
768
0
        nssArena_Release(collection->arena, mark);
769
0
    }
770
0
    nssCryptokiObject_Destroy(instance);
771
0
    return (pkiObjectCollectionNode *)NULL;
772
1.71k
}
773
774
NSS_IMPLEMENT PRStatus
775
nssPKIObjectCollection_AddInstances(
776
    nssPKIObjectCollection *collection,
777
    nssCryptokiObject **instances,
778
    PRUint32 numInstances)
779
1.82k
{
780
1.82k
    PRStatus status = PR_SUCCESS;
781
1.82k
    PRUint32 i = 0;
782
1.82k
    PRBool foundIt;
783
1.82k
    pkiObjectCollectionNode *node;
784
1.82k
    if (instances) {
785
3.43k
        while ((!numInstances || i < numInstances) && *instances) {
786
1.71k
            if (status == PR_SUCCESS) {
787
1.71k
                node = add_object_instance(collection, *instances, &foundIt);
788
1.71k
                if (node == NULL) {
789
                    /* add_object_instance freed the current instance */
790
                    /* free the remaining instances */
791
0
                    status = PR_FAILURE;
792
0
                }
793
1.71k
            } else {
794
0
                nssCryptokiObject_Destroy(*instances);
795
0
            }
796
1.71k
            instances++;
797
1.71k
            i++;
798
1.71k
        }
799
1.71k
    }
800
1.82k
    return status;
801
1.82k
}
802
803
static void
804
nssPKIObjectCollection_RemoveNode(
805
    nssPKIObjectCollection *collection,
806
    pkiObjectCollectionNode *node)
807
0
{
808
0
    PR_REMOVE_LINK(&node->link);
809
0
    collection->size--;
810
0
}
811
812
static PRStatus
813
nssPKIObjectCollection_GetObjects(
814
    nssPKIObjectCollection *collection,
815
    nssPKIObject **rvObjects,
816
    PRUint32 rvSize)
817
32.0k
{
818
32.0k
    PRUint32 i = 0;
819
32.0k
    PRCList *link = PR_NEXT_LINK(&collection->head);
820
32.0k
    pkiObjectCollectionNode *node;
821
32.0k
    int error = 0;
822
84.9k
    while ((i < rvSize) && (link != &collection->head)) {
823
52.9k
        node = (pkiObjectCollectionNode *)link;
824
52.9k
        if (!node->haveObject) {
825
            /* Convert the proto-object to an object */
826
1.70k
            node->object = (*collection->createObject)(node->object);
827
1.70k
            if (!node->object) {
828
0
                link = PR_NEXT_LINK(link);
829
                /*remove bogus object from list*/
830
0
                nssPKIObjectCollection_RemoveNode(collection, node);
831
0
                error++;
832
0
                continue;
833
0
            }
834
1.70k
            node->haveObject = PR_TRUE;
835
1.70k
        }
836
52.9k
        rvObjects[i++] = nssPKIObject_AddRef(node->object);
837
52.9k
        link = PR_NEXT_LINK(link);
838
52.9k
    }
839
32.0k
    if (!error && *rvObjects == NULL) {
840
0
        nss_SetError(NSS_ERROR_NOT_FOUND);
841
0
    }
842
32.0k
    return PR_SUCCESS;
843
32.0k
}
844
845
NSS_IMPLEMENT PRStatus
846
nssPKIObjectCollection_Traverse(
847
    nssPKIObjectCollection *collection,
848
    nssPKIObjectCallback *callback)
849
5
{
850
5
    PRCList *link = PR_NEXT_LINK(&collection->head);
851
5
    pkiObjectCollectionNode *node;
852
7
    while (link != &collection->head) {
853
2
        node = (pkiObjectCollectionNode *)link;
854
2
        if (!node->haveObject) {
855
0
            node->object = (*collection->createObject)(node->object);
856
0
            if (!node->object) {
857
0
                link = PR_NEXT_LINK(link);
858
                /*remove bogus object from list*/
859
0
                nssPKIObjectCollection_RemoveNode(collection, node);
860
0
                continue;
861
0
            }
862
0
            node->haveObject = PR_TRUE;
863
0
        }
864
2
        switch (collection->objectType) {
865
2
            case pkiObjectType_Certificate:
866
2
                (void)(*callback->func.cert)((NSSCertificate *)node->object,
867
2
                                             callback->arg);
868
2
                break;
869
0
            case pkiObjectType_CRL:
870
0
                (void)(*callback->func.crl)((NSSCRL *)node->object,
871
0
                                            callback->arg);
872
0
                break;
873
2
        }
874
2
        link = PR_NEXT_LINK(link);
875
2
    }
876
5
    return PR_SUCCESS;
877
5
}
878
879
NSS_IMPLEMENT PRStatus
880
nssPKIObjectCollection_AddInstanceAsObject(
881
    nssPKIObjectCollection *collection,
882
    nssCryptokiObject *instance)
883
2
{
884
2
    pkiObjectCollectionNode *node;
885
2
    PRBool foundIt;
886
2
    node = add_object_instance(collection, instance, &foundIt);
887
2
    if (node == NULL) {
888
0
        return PR_FAILURE;
889
0
    }
890
2
    if (!node->haveObject) {
891
2
        nssPKIObject *original = node->object;
892
2
        node->object = (*collection->createObject)(node->object);
893
2
        if (!node->object) {
894
            /*remove bogus object from list*/
895
0
            nssPKIObject_Destroy(original);
896
0
            nssPKIObjectCollection_RemoveNode(collection, node);
897
0
            return PR_FAILURE;
898
0
        }
899
2
        node->haveObject = PR_TRUE;
900
2
    } else if (!foundIt) {
901
        /* The instance was added to a pre-existing node.  This
902
         * function is *only* being used for certificates, and having
903
         * multiple instances of certs in 3.X requires updating the
904
         * CERTCertificate.
905
         * But only do it if it was a new instance!!!  If the same instance
906
         * is encountered, we set *foundIt to true.  Detect that here and
907
         * ignore it.
908
         */
909
0
        STAN_ForceCERTCertificateUpdate((NSSCertificate *)node->object);
910
0
    }
911
2
    return PR_SUCCESS;
912
2
}
913
914
/*
915
 * Certificate collections
916
 */
917
918
static void
919
cert_destroyObject(nssPKIObject *o)
920
52.9k
{
921
52.9k
    NSSCertificate *c = (NSSCertificate *)o;
922
52.9k
    if (c->decoding) {
923
52.9k
        CERTCertificate *cc = STAN_GetCERTCertificate(c);
924
52.9k
        if (cc) {
925
52.9k
            CERT_DestroyCertificate(cc);
926
52.9k
            return;
927
52.9k
        } /* else destroy it as NSSCertificate below */
928
52.9k
    }
929
0
    nssCertificate_Destroy(c);
930
0
}
931
932
static PRStatus
933
cert_getUIDFromObject(nssPKIObject *o, NSSItem *uid)
934
51.2k
{
935
51.2k
    NSSCertificate *c = (NSSCertificate *)o;
936
    /* The builtins are still returning decoded serial numbers.  Until
937
     * this compatibility issue is resolved, use the full DER of the
938
     * cert to uniquely identify it.
939
     */
940
51.2k
    NSSDER *derCert;
941
51.2k
    derCert = nssCertificate_GetEncoding(c);
942
51.2k
    uid[0].data = NULL;
943
51.2k
    uid[0].size = 0;
944
51.2k
    uid[1].data = NULL;
945
51.2k
    uid[1].size = 0;
946
51.2k
    if (derCert != NULL) {
947
51.2k
        uid[0] = *derCert;
948
51.2k
    }
949
51.2k
    return PR_SUCCESS;
950
51.2k
}
951
952
static PRStatus
953
cert_getUIDFromInstance(nssCryptokiObject *instance, NSSItem *uid,
954
                        NSSArena *arena)
955
1.71k
{
956
    /* The builtins are still returning decoded serial numbers.  Until
957
     * this compatibility issue is resolved, use the full DER of the
958
     * cert to uniquely identify it.
959
     */
960
1.71k
    uid[1].data = NULL;
961
1.71k
    uid[1].size = 0;
962
1.71k
    return nssCryptokiCertificate_GetAttributes(instance,
963
1.71k
                                                NULL,    /* XXX sessionOpt */
964
1.71k
                                                arena,   /* arena    */
965
1.71k
                                                NULL,    /* type     */
966
1.71k
                                                NULL,    /* id       */
967
1.71k
                                                &uid[0], /* encoding */
968
1.71k
                                                NULL,    /* issuer   */
969
1.71k
                                                NULL,    /* serial   */
970
1.71k
                                                NULL);   /* subject  */
971
1.71k
}
972
973
static nssPKIObject *
974
cert_createObject(nssPKIObject *o)
975
1.71k
{
976
1.71k
    NSSCertificate *cert = nssCertificate_Create(o);
977
1.71k
    if (!cert) {
978
0
        return NULL;
979
0
    }
980
1.71k
    NSSTrustDomain *td = o->trustDomain;
981
    /* nssTrustDomain_AddCertToCache takes ownership of the reference to cert,
982
     * so first increase the refcount so it doesn't go away. */
983
1.71k
    nssCertificate_AddRef(cert);
984
1.71k
    NSSCertificate *certInCache = nssTrustDomain_AddCertToCache(td, cert);
985
1.71k
    if (certInCache) {
986
        // This code should probably use the certificate returned from the cache,
987
        // but currently the merge tests rely on not doing so. Discard it
988
        // instead.
989
1.71k
        nssCertificate_Destroy(certInCache);
990
1.71k
    }
991
1.71k
    return (nssPKIObject *)cert;
992
1.71k
}
993
994
NSS_IMPLEMENT nssPKIObjectCollection *
995
nssCertificateCollection_Create(
996
    NSSTrustDomain *td,
997
    NSSCertificate **certsOpt)
998
56.7k
{
999
56.7k
    nssPKIObjectCollection *collection;
1000
56.7k
    collection = nssPKIObjectCollection_Create(td, NULL, nssPKIMonitor);
1001
56.7k
    if (!collection) {
1002
0
        return NULL;
1003
0
    }
1004
56.7k
    collection->objectType = pkiObjectType_Certificate;
1005
56.7k
    collection->destroyObject = cert_destroyObject;
1006
56.7k
    collection->getUIDFromObject = cert_getUIDFromObject;
1007
56.7k
    collection->getUIDFromInstance = cert_getUIDFromInstance;
1008
56.7k
    collection->createObject = cert_createObject;
1009
56.7k
    if (certsOpt) {
1010
20
        for (; *certsOpt; certsOpt++) {
1011
10
            nssPKIObject *object = (nssPKIObject *)(*certsOpt);
1012
10
            (void)nssPKIObjectCollection_AddObject(collection, object);
1013
10
        }
1014
10
    }
1015
56.7k
    return collection;
1016
56.7k
}
1017
1018
NSS_IMPLEMENT NSSCertificate **
1019
nssPKIObjectCollection_GetCertificates(
1020
    nssPKIObjectCollection *collection,
1021
    NSSCertificate **rvOpt,
1022
    PRUint32 maximumOpt,
1023
    NSSArena *arenaOpt)
1024
56.7k
{
1025
56.7k
    PRStatus status;
1026
56.7k
    PRUint32 rvSize;
1027
56.7k
    PRBool allocated = PR_FALSE;
1028
56.7k
    if (collection->size == 0) {
1029
24.7k
        return (NSSCertificate **)NULL;
1030
24.7k
    }
1031
32.0k
    if (maximumOpt == 0) {
1032
113
        rvSize = collection->size;
1033
31.9k
    } else {
1034
31.9k
        rvSize = PR_MIN(collection->size, maximumOpt);
1035
31.9k
    }
1036
32.0k
    if (!rvOpt) {
1037
129
        rvOpt = nss_ZNEWARRAY(arenaOpt, NSSCertificate *, rvSize + 1);
1038
129
        if (!rvOpt) {
1039
0
            return (NSSCertificate **)NULL;
1040
0
        }
1041
129
        allocated = PR_TRUE;
1042
129
    }
1043
32.0k
    status = nssPKIObjectCollection_GetObjects(collection,
1044
32.0k
                                               (nssPKIObject **)rvOpt,
1045
32.0k
                                               rvSize);
1046
32.0k
    if (status != PR_SUCCESS) {
1047
0
        if (allocated) {
1048
0
            nss_ZFreeIf(rvOpt);
1049
0
        }
1050
0
        return (NSSCertificate **)NULL;
1051
0
    }
1052
32.0k
    return rvOpt;
1053
32.0k
}
1054
1055
/*
1056
 * CRL/KRL collections
1057
 */
1058
1059
static void
1060
crl_destroyObject(nssPKIObject *o)
1061
0
{
1062
0
    NSSCRL *crl = (NSSCRL *)o;
1063
0
    nssCRL_Destroy(crl);
1064
0
}
1065
1066
static PRStatus
1067
crl_getUIDFromObject(nssPKIObject *o, NSSItem *uid)
1068
0
{
1069
0
    NSSCRL *crl = (NSSCRL *)o;
1070
0
    NSSDER *encoding;
1071
0
    encoding = nssCRL_GetEncoding(crl);
1072
0
    if (!encoding) {
1073
0
        nss_SetError(NSS_ERROR_INVALID_ARGUMENT);
1074
0
        return PR_FALSE;
1075
0
    }
1076
0
    uid[0] = *encoding;
1077
0
    uid[1].data = NULL;
1078
0
    uid[1].size = 0;
1079
0
    return PR_SUCCESS;
1080
0
}
1081
1082
static PRStatus
1083
crl_getUIDFromInstance(nssCryptokiObject *instance, NSSItem *uid,
1084
                       NSSArena *arena)
1085
0
{
1086
0
    return nssCryptokiCRL_GetAttributes(instance,
1087
0
                                        NULL,    /* XXX sessionOpt */
1088
0
                                        arena,   /* arena    */
1089
0
                                        &uid[0], /* encoding */
1090
0
                                        NULL,    /* subject  */
1091
0
                                        NULL,    /* class    */
1092
0
                                        NULL,    /* url      */
1093
0
                                        NULL);   /* isKRL    */
1094
0
}
1095
1096
static nssPKIObject *
1097
crl_createObject(nssPKIObject *o)
1098
0
{
1099
0
    return (nssPKIObject *)nssCRL_Create(o);
1100
0
}
1101
1102
NSS_IMPLEMENT nssPKIObjectCollection *
1103
nssCRLCollection_Create(
1104
    NSSTrustDomain *td,
1105
    NSSCRL **crlsOpt)
1106
0
{
1107
0
    nssPKIObjectCollection *collection;
1108
0
    collection = nssPKIObjectCollection_Create(td, NULL, nssPKILock);
1109
0
    if (!collection) {
1110
0
        return NULL;
1111
0
    }
1112
0
    collection->objectType = pkiObjectType_CRL;
1113
0
    collection->destroyObject = crl_destroyObject;
1114
0
    collection->getUIDFromObject = crl_getUIDFromObject;
1115
0
    collection->getUIDFromInstance = crl_getUIDFromInstance;
1116
0
    collection->createObject = crl_createObject;
1117
0
    if (crlsOpt) {
1118
0
        for (; *crlsOpt; crlsOpt++) {
1119
0
            nssPKIObject *object = (nssPKIObject *)(*crlsOpt);
1120
0
            (void)nssPKIObjectCollection_AddObject(collection, object);
1121
0
        }
1122
0
    }
1123
0
    return collection;
1124
0
}
1125
1126
NSS_IMPLEMENT NSSCRL **
1127
nssPKIObjectCollection_GetCRLs(
1128
    nssPKIObjectCollection *collection,
1129
    NSSCRL **rvOpt,
1130
    PRUint32 maximumOpt,
1131
    NSSArena *arenaOpt)
1132
0
{
1133
0
    PRStatus status;
1134
0
    PRUint32 rvSize;
1135
0
    PRBool allocated = PR_FALSE;
1136
0
    if (collection->size == 0) {
1137
0
        return (NSSCRL **)NULL;
1138
0
    }
1139
0
    if (maximumOpt == 0) {
1140
0
        rvSize = collection->size;
1141
0
    } else {
1142
0
        rvSize = PR_MIN(collection->size, maximumOpt);
1143
0
    }
1144
0
    if (!rvOpt) {
1145
0
        rvOpt = nss_ZNEWARRAY(arenaOpt, NSSCRL *, rvSize + 1);
1146
0
        if (!rvOpt) {
1147
0
            return (NSSCRL **)NULL;
1148
0
        }
1149
0
        allocated = PR_TRUE;
1150
0
    }
1151
0
    status = nssPKIObjectCollection_GetObjects(collection,
1152
0
                                               (nssPKIObject **)rvOpt,
1153
0
                                               rvSize);
1154
0
    if (status != PR_SUCCESS) {
1155
0
        if (allocated) {
1156
0
            nss_ZFreeIf(rvOpt);
1157
0
        }
1158
0
        return (NSSCRL **)NULL;
1159
0
    }
1160
0
    return rvOpt;
1161
0
}
1162
1163
/* how bad would it be to have a static now sitting around, updated whenever
1164
 * this was called?  would avoid repeated allocs...
1165
 */
1166
NSS_IMPLEMENT NSSTime *
1167
NSSTime_Now(NSSTime *timeOpt)
1168
0
{
1169
0
    return NSSTime_SetPRTime(timeOpt, PR_Now());
1170
0
}
1171
1172
NSS_IMPLEMENT NSSTime *
1173
NSSTime_SetPRTime(
1174
    NSSTime *timeOpt,
1175
    PRTime prTime)
1176
30.2k
{
1177
30.2k
    NSSTime *rvTime;
1178
30.2k
    rvTime = (timeOpt) ? timeOpt : nss_ZNEW(NULL, NSSTime);
1179
30.2k
    if (rvTime) {
1180
30.2k
        rvTime->prTime = prTime;
1181
30.2k
    }
1182
30.2k
    return rvTime;
1183
30.2k
}
1184
1185
NSS_IMPLEMENT PRTime
1186
NSSTime_GetPRTime(
1187
    NSSTime *time)
1188
6.95k
{
1189
6.95k
    return time->prTime;
1190
6.95k
}