Coverage Report

Created: 2024-02-25 06:31

/src/nss/lib/ssl/ssl3ecc.c
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * SSL3 Protocol
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8
9
/* ECC code moved here from ssl3con.c */
10
11
#include "cert.h"
12
#include "ssl.h"
13
#include "cryptohi.h" /* for DSAU_ stuff */
14
#include "keyhi.h"
15
#include "secder.h"
16
#include "secitem.h"
17
18
#include "sslimpl.h"
19
#include "sslproto.h"
20
#include "sslerr.h"
21
#include "ssl3ext.h"
22
#include "prtime.h"
23
#include "prinrval.h"
24
#include "prerror.h"
25
#include "pratom.h"
26
#include "prthread.h"
27
#include "prinit.h"
28
29
#include "pk11func.h"
30
#include "secmod.h"
31
32
#include <stdio.h>
33
34
SECStatus
35
ssl_NamedGroup2ECParams(PLArenaPool *arena, const sslNamedGroupDef *ecGroup,
36
                        SECKEYECParams *params)
37
39.1k
{
38
39.1k
    SECOidData *oidData = NULL;
39
40
39.1k
    if (!params) {
41
0
        PORT_Assert(0);
42
0
        PORT_SetError(SEC_ERROR_INVALID_ARGS);
43
0
        return SECFailure;
44
0
    }
45
46
39.1k
    if (!ecGroup || ecGroup->keaType != ssl_kea_ecdh ||
47
39.1k
        (oidData = SECOID_FindOIDByTag(ecGroup->oidTag)) == NULL) {
48
0
        PORT_SetError(SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE);
49
0
        return SECFailure;
50
0
    }
51
52
39.1k
    if (SECITEM_AllocItem(arena, params, (2 + oidData->oid.len)) == NULL) {
53
0
        PORT_SetError(SEC_ERROR_NO_MEMORY);
54
0
        return SECFailure;
55
0
    }
56
57
    /*
58
     * params->data needs to contain the ASN encoding of an object ID (OID)
59
     * representing the named curve. The actual OID is in
60
     * oidData->oid.data so we simply prepend 0x06 and OID length
61
     */
62
39.1k
    params->data[0] = SEC_ASN1_OBJECT_ID;
63
39.1k
    params->data[1] = oidData->oid.len;
64
39.1k
    memcpy(params->data + 2, oidData->oid.data, oidData->oid.len);
65
66
39.1k
    return SECSuccess;
67
39.1k
}
68
69
const sslNamedGroupDef *
70
ssl_ECPubKey2NamedGroup(const SECKEYPublicKey *pubKey)
71
6.56k
{
72
6.56k
    SECItem oid = { siBuffer, NULL, 0 };
73
6.56k
    SECOidData *oidData = NULL;
74
6.56k
    PRUint32 policyFlags = 0;
75
6.56k
    unsigned int i;
76
6.56k
    const SECKEYECParams *params;
77
78
6.56k
    if (pubKey->keyType != ecKey) {
79
0
        PORT_Assert(0);
80
0
        return NULL;
81
0
    }
82
83
6.56k
    params = &pubKey->u.ec.DEREncodedParams;
84
85
    /*
86
     * params->data needs to contain the ASN encoding of an object ID (OID)
87
     * representing a named curve. Here, we strip away everything
88
     * before the actual OID and use the OID to look up a named curve.
89
     */
90
6.56k
    if (params->data[0] != SEC_ASN1_OBJECT_ID)
91
0
        return NULL;
92
6.56k
    oid.len = params->len - 2;
93
6.56k
    oid.data = params->data + 2;
94
6.56k
    if ((oidData = SECOID_FindOID(&oid)) == NULL)
95
0
        return NULL;
96
6.56k
    if ((NSS_GetAlgorithmPolicy(oidData->offset, &policyFlags) ==
97
6.56k
         SECSuccess) &&
98
6.56k
        !(policyFlags & NSS_USE_ALG_IN_SSL_KX)) {
99
0
        return NULL;
100
0
    }
101
14.8k
    for (i = 0; i < SSL_NAMED_GROUP_COUNT; ++i) {
102
14.8k
        if (ssl_named_groups[i].oidTag == oidData->offset) {
103
6.55k
            return &ssl_named_groups[i];
104
6.55k
        }
105
14.8k
    }
106
107
14
    return NULL;
108
6.56k
}
109
110
/* Caller must set hiLevel error code. */
111
static SECStatus
112
ssl3_ComputeECDHKeyHash(SSLHashType hashAlg,
113
                        SECItem ec_params, SECItem server_ecpoint,
114
                        PRUint8 *client_rand, PRUint8 *server_rand,
115
                        SSL3Hashes *hashes)
116
13.8k
{
117
13.8k
    PRUint8 *hashBuf;
118
13.8k
    PRUint8 *pBuf;
119
13.8k
    SECStatus rv = SECSuccess;
120
13.8k
    unsigned int bufLen;
121
    /*
122
     * We only support named curves (the appropriate checks are made before this
123
     * method is called) so ec_params takes up only two bytes. ECPoint needs to
124
     * fit in 256 bytes because the spec says the length must fit in one byte.
125
     */
126
13.8k
    PRUint8 buf[2 * SSL3_RANDOM_LENGTH + 2 + 1 + 256];
127
128
13.8k
    bufLen = 2 * SSL3_RANDOM_LENGTH + ec_params.len + 1 + server_ecpoint.len;
129
13.8k
    if (bufLen <= sizeof buf) {
130
13.8k
        hashBuf = buf;
131
13.8k
    } else {
132
0
        hashBuf = PORT_Alloc(bufLen);
133
0
        if (!hashBuf) {
134
0
            return SECFailure;
135
0
        }
136
0
    }
137
138
13.8k
    memcpy(hashBuf, client_rand, SSL3_RANDOM_LENGTH);
139
13.8k
    pBuf = hashBuf + SSL3_RANDOM_LENGTH;
140
13.8k
    memcpy(pBuf, server_rand, SSL3_RANDOM_LENGTH);
141
13.8k
    pBuf += SSL3_RANDOM_LENGTH;
142
13.8k
    memcpy(pBuf, ec_params.data, ec_params.len);
143
13.8k
    pBuf += ec_params.len;
144
13.8k
    pBuf[0] = (PRUint8)(server_ecpoint.len);
145
13.8k
    pBuf += 1;
146
13.8k
    memcpy(pBuf, server_ecpoint.data, server_ecpoint.len);
147
13.8k
    pBuf += server_ecpoint.len;
148
13.8k
    PORT_Assert((unsigned int)(pBuf - hashBuf) == bufLen);
149
150
13.8k
    rv = ssl3_ComputeCommonKeyHash(hashAlg, hashBuf, bufLen, hashes);
151
152
13.8k
    PRINT_BUF(95, (NULL, "ECDHkey hash: ", hashBuf, bufLen));
153
13.8k
    PRINT_BUF(95, (NULL, "ECDHkey hash: MD5 result",
154
13.8k
                   hashes->u.s.md5, MD5_LENGTH));
155
13.8k
    PRINT_BUF(95, (NULL, "ECDHkey hash: SHA1 result",
156
13.8k
                   hashes->u.s.sha, SHA1_LENGTH));
157
158
13.8k
    if (hashBuf != buf)
159
0
        PORT_Free(hashBuf);
160
13.8k
    return rv;
161
13.8k
}
162
163
/* Called from ssl3_SendClientKeyExchange(). */
164
SECStatus
165
ssl3_SendECDHClientKeyExchange(sslSocket *ss, SECKEYPublicKey *svrPubKey)
166
5.81k
{
167
5.81k
    PK11SymKey *pms = NULL;
168
5.81k
    SECStatus rv = SECFailure;
169
5.81k
    PRBool isTLS, isTLS12;
170
5.81k
    CK_MECHANISM_TYPE target;
171
5.81k
    const sslNamedGroupDef *groupDef;
172
5.81k
    sslEphemeralKeyPair *keyPair = NULL;
173
5.81k
    SECKEYPublicKey *pubKey;
174
175
5.81k
    PORT_Assert(ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss));
176
5.81k
    PORT_Assert(ss->opt.noLocks || ssl_HaveXmitBufLock(ss));
177
178
5.81k
    isTLS = (PRBool)(ss->version > SSL_LIBRARY_VERSION_3_0);
179
5.81k
    isTLS12 = (PRBool)(ss->version >= SSL_LIBRARY_VERSION_TLS_1_2);
180
181
    /* Generate ephemeral EC keypair */
182
5.81k
    if (svrPubKey->keyType != ecKey) {
183
8
        PORT_SetError(SEC_ERROR_BAD_KEY);
184
8
        goto loser;
185
8
    }
186
5.80k
    groupDef = ssl_ECPubKey2NamedGroup(svrPubKey);
187
5.80k
    if (!groupDef) {
188
14
        PORT_SetError(SEC_ERROR_BAD_KEY);
189
14
        goto loser;
190
14
    }
191
5.79k
    ss->sec.keaGroup = groupDef;
192
5.79k
    rv = ssl_CreateECDHEphemeralKeyPair(ss, groupDef, &keyPair);
193
5.79k
    if (rv != SECSuccess) {
194
19
        ssl_MapLowLevelError(SEC_ERROR_KEYGEN_FAIL);
195
19
        goto loser;
196
19
    }
197
198
5.77k
    pubKey = keyPair->keys->pubKey;
199
5.77k
    PRINT_BUF(50, (ss, "ECDH public value:",
200
5.77k
                   pubKey->u.ec.publicValue.data,
201
5.77k
                   pubKey->u.ec.publicValue.len));
202
203
5.77k
    if (isTLS12) {
204
2.35k
        target = CKM_TLS12_MASTER_KEY_DERIVE_DH;
205
3.41k
    } else if (isTLS) {
206
3.41k
        target = CKM_TLS_MASTER_KEY_DERIVE_DH;
207
3.41k
    } else {
208
0
        target = CKM_SSL3_MASTER_KEY_DERIVE_DH;
209
0
    }
210
211
    /* Determine the PMS */
212
5.77k
    pms = PK11_PubDeriveWithKDF(keyPair->keys->privKey, svrPubKey,
213
5.77k
                                PR_FALSE, NULL, NULL, CKM_ECDH1_DERIVE, target,
214
5.77k
                                CKA_DERIVE, 0, CKD_NULL, NULL, NULL);
215
216
5.77k
    if (pms == NULL) {
217
1.43k
        (void)SSL3_SendAlert(ss, alert_fatal, illegal_parameter);
218
1.43k
        ssl_MapLowLevelError(SSL_ERROR_CLIENT_KEY_EXCHANGE_FAILURE);
219
1.43k
        goto loser;
220
1.43k
    }
221
222
4.33k
    rv = ssl3_AppendHandshakeHeader(ss, ssl_hs_client_key_exchange,
223
4.33k
                                    pubKey->u.ec.publicValue.len + 1);
224
4.33k
    if (rv != SECSuccess) {
225
0
        goto loser; /* err set by ssl3_AppendHandshake* */
226
0
    }
227
228
4.33k
    rv = ssl3_AppendHandshakeVariable(ss, pubKey->u.ec.publicValue.data,
229
4.33k
                                      pubKey->u.ec.publicValue.len, 1);
230
231
4.33k
    if (rv != SECSuccess) {
232
0
        goto loser; /* err set by ssl3_AppendHandshake* */
233
0
    }
234
235
4.33k
    rv = ssl3_InitPendingCipherSpecs(ss, pms, PR_TRUE);
236
4.33k
    if (rv != SECSuccess) {
237
0
        ssl_MapLowLevelError(SSL_ERROR_CLIENT_KEY_EXCHANGE_FAILURE);
238
0
        goto loser;
239
0
    }
240
241
4.33k
    PK11_FreeSymKey(pms);
242
4.33k
    ssl_FreeEphemeralKeyPair(keyPair);
243
4.33k
    return SECSuccess;
244
245
1.47k
loser:
246
1.47k
    if (pms)
247
0
        PK11_FreeSymKey(pms);
248
1.47k
    if (keyPair)
249
1.43k
        ssl_FreeEphemeralKeyPair(keyPair);
250
1.47k
    return SECFailure;
251
4.33k
}
252
253
/*
254
** Called from ssl3_HandleClientKeyExchange()
255
*/
256
SECStatus
257
ssl3_HandleECDHClientKeyExchange(sslSocket *ss, PRUint8 *b,
258
                                 PRUint32 length,
259
                                 sslKeyPair *serverKeyPair)
260
18
{
261
18
    PK11SymKey *pms;
262
18
    SECStatus rv;
263
18
    SECKEYPublicKey clntPubKey;
264
18
    CK_MECHANISM_TYPE target;
265
18
    PRBool isTLS, isTLS12;
266
18
    int errCode = SSL_ERROR_RX_MALFORMED_CLIENT_KEY_EXCH;
267
268
18
    PORT_Assert(ss->opt.noLocks || ssl_HaveRecvBufLock(ss));
269
18
    PORT_Assert(ss->opt.noLocks || ssl_HaveSSL3HandshakeLock(ss));
270
271
18
    clntPubKey.keyType = ecKey;
272
18
    clntPubKey.u.ec.DEREncodedParams.len =
273
18
        serverKeyPair->pubKey->u.ec.DEREncodedParams.len;
274
18
    clntPubKey.u.ec.DEREncodedParams.data =
275
18
        serverKeyPair->pubKey->u.ec.DEREncodedParams.data;
276
18
    clntPubKey.u.ec.encoding = ECPoint_Undefined;
277
278
18
    rv = ssl3_ConsumeHandshakeVariable(ss, &clntPubKey.u.ec.publicValue,
279
18
                                       1, &b, &length);
280
18
    if (rv != SECSuccess) {
281
0
        PORT_SetError(errCode);
282
0
        return SECFailure;
283
0
    }
284
285
    /* we have to catch the case when the client's public key has length 0. */
286
18
    if (!clntPubKey.u.ec.publicValue.len) {
287
3
        (void)SSL3_SendAlert(ss, alert_fatal, illegal_parameter);
288
3
        PORT_SetError(errCode);
289
3
        return SECFailure;
290
3
    }
291
292
15
    isTLS = (PRBool)(ss->ssl3.prSpec->version > SSL_LIBRARY_VERSION_3_0);
293
15
    isTLS12 = (PRBool)(ss->ssl3.prSpec->version >= SSL_LIBRARY_VERSION_TLS_1_2);
294
295
15
    if (isTLS12) {
296
15
        target = CKM_TLS12_MASTER_KEY_DERIVE_DH;
297
15
    } else if (isTLS) {
298
0
        target = CKM_TLS_MASTER_KEY_DERIVE_DH;
299
0
    } else {
300
0
        target = CKM_SSL3_MASTER_KEY_DERIVE_DH;
301
0
    }
302
303
    /*  Determine the PMS */
304
15
    pms = PK11_PubDeriveWithKDF(serverKeyPair->privKey, &clntPubKey,
305
15
                                PR_FALSE, NULL, NULL,
306
15
                                CKM_ECDH1_DERIVE, target, CKA_DERIVE, 0,
307
15
                                CKD_NULL, NULL, NULL);
308
309
15
    if (pms == NULL) {
310
        /* last gasp.  */
311
11
        errCode = ssl_MapLowLevelError(SSL_ERROR_CLIENT_KEY_EXCHANGE_FAILURE);
312
11
        PORT_SetError(errCode);
313
11
        return SECFailure;
314
11
    }
315
316
4
    rv = ssl3_InitPendingCipherSpecs(ss, pms, PR_TRUE);
317
4
    PK11_FreeSymKey(pms);
318
4
    if (rv != SECSuccess) {
319
        /* error code set by ssl3_InitPendingCipherSpec */
320
0
        return SECFailure;
321
0
    }
322
4
    ss->sec.keaGroup = ssl_ECPubKey2NamedGroup(&clntPubKey);
323
4
    return SECSuccess;
324
4
}
325
326
/*
327
** Take an encoded key share and make a public key out of it.
328
*/
329
SECStatus
330
ssl_ImportECDHKeyShare(SECKEYPublicKey *peerKey,
331
                       PRUint8 *b, PRUint32 length,
332
                       const sslNamedGroupDef *ecGroup)
333
3.11k
{
334
3.11k
    SECStatus rv;
335
3.11k
    SECItem ecPoint = { siBuffer, NULL, 0 };
336
337
3.11k
    if (!length) {
338
2
        PORT_SetError(SSL_ERROR_RX_MALFORMED_ECDHE_KEY_SHARE);
339
2
        return SECFailure;
340
2
    }
341
342
    /* Fail if the ec point uses compressed representation */
343
3.11k
    if (b[0] != EC_POINT_FORM_UNCOMPRESSED &&
344
3.11k
        ecGroup->name != ssl_grp_ec_curve25519) {
345
5
        PORT_SetError(SEC_ERROR_UNSUPPORTED_EC_POINT_FORM);
346
5
        return SECFailure;
347
5
    }
348
349
3.10k
    peerKey->keyType = ecKey;
350
    /* Set up the encoded params */
351
3.10k
    rv = ssl_NamedGroup2ECParams(peerKey->arena, ecGroup,
352
3.10k
                                 &peerKey->u.ec.DEREncodedParams);
353
3.10k
    if (rv != SECSuccess) {
354
0
        ssl_MapLowLevelError(SSL_ERROR_RX_MALFORMED_ECDHE_KEY_SHARE);
355
0
        return SECFailure;
356
0
    }
357
3.10k
    peerKey->u.ec.encoding = ECPoint_Undefined;
358
359
    /* copy publicValue in peerKey */
360
3.10k
    ecPoint.data = b;
361
3.10k
    ecPoint.len = length;
362
363
3.10k
    rv = SECITEM_CopyItem(peerKey->arena, &peerKey->u.ec.publicValue, &ecPoint);
364
3.10k
    if (rv != SECSuccess) {
365
0
        return SECFailure;
366
0
    }
367
368
3.10k
    return SECSuccess;
369
3.10k
}
370
371
const sslNamedGroupDef *
372
ssl_GetECGroupWithStrength(sslSocket *ss, unsigned int requiredECCbits)
373
9.71k
{
374
9.71k
    int i;
375
376
9.71k
    PORT_Assert(ss);
377
378
25.1k
    for (i = 0; i < SSL_NAMED_GROUP_COUNT; ++i) {
379
25.1k
        const sslNamedGroupDef *group = ss->namedGroupPreferences[i];
380
25.1k
        if (group && group->keaType == ssl_kea_ecdh &&
381
25.1k
            group->bits >= requiredECCbits) {
382
9.71k
            return group;
383
9.71k
        }
384
25.1k
    }
385
386
0
    PORT_SetError(SSL_ERROR_NO_CYPHER_OVERLAP);
387
0
    return NULL;
388
9.71k
}
389
390
/* Find the "weakest link".  Get the strength of the signature and symmetric
391
 * keys and choose a curve based on the weakest of those two. */
392
const sslNamedGroupDef *
393
ssl_GetECGroupForServerSocket(sslSocket *ss)
394
9.71k
{
395
9.71k
    const sslServerCert *cert = ss->sec.serverCert;
396
9.71k
    unsigned int certKeySize;
397
9.71k
    const ssl3BulkCipherDef *bulkCipher;
398
9.71k
    unsigned int requiredECCbits;
399
400
9.71k
    PORT_Assert(cert);
401
9.71k
    if (!cert || !cert->serverKeyPair || !cert->serverKeyPair->pubKey) {
402
0
        PORT_SetError(SSL_ERROR_NO_CYPHER_OVERLAP);
403
0
        return NULL;
404
0
    }
405
406
9.71k
    if (SSL_CERT_IS(cert, ssl_auth_rsa_sign) ||
407
9.71k
        SSL_CERT_IS(cert, ssl_auth_rsa_pss)) {
408
8.52k
        certKeySize = SECKEY_PublicKeyStrengthInBits(cert->serverKeyPair->pubKey);
409
8.52k
        certKeySize = SSL_RSASTRENGTH_TO_ECSTRENGTH(certKeySize);
410
8.52k
    } else if (SSL_CERT_IS_EC(cert)) {
411
        /* We won't select a certificate unless the named curve has been
412
         * negotiated (or supported_curves was absent), double check that. */
413
1.19k
        PORT_Assert(cert->namedCurve->keaType == ssl_kea_ecdh);
414
1.19k
        PORT_Assert(ssl_NamedGroupEnabled(ss, cert->namedCurve));
415
1.19k
        if (!ssl_NamedGroupEnabled(ss, cert->namedCurve)) {
416
0
            return NULL;
417
0
        }
418
1.19k
        certKeySize = cert->namedCurve->bits;
419
1.19k
    } else {
420
0
        PORT_Assert(0);
421
0
        return NULL;
422
0
    }
423
9.71k
    bulkCipher = ssl_GetBulkCipherDef(ss->ssl3.hs.suite_def);
424
9.71k
    requiredECCbits = bulkCipher->key_size * BPB * 2;
425
9.71k
    PORT_Assert(requiredECCbits ||
426
9.71k
                ss->ssl3.hs.suite_def->bulk_cipher_alg == cipher_null);
427
9.71k
    if (requiredECCbits > certKeySize) {
428
8.90k
        requiredECCbits = certKeySize;
429
8.90k
    }
430
431
9.71k
    return ssl_GetECGroupWithStrength(ss, requiredECCbits);
432
9.71k
}
433
434
/* Create an ECDHE key pair for a given curve */
435
SECStatus
436
ssl_CreateECDHEphemeralKeyPair(const sslSocket *ss,
437
                               const sslNamedGroupDef *ecGroup,
438
                               sslEphemeralKeyPair **keyPair)
439
36.0k
{
440
36.0k
    SECKEYPrivateKey *privKey = NULL;
441
36.0k
    SECKEYPublicKey *pubKey = NULL;
442
36.0k
    SECKEYECParams ecParams = { siBuffer, NULL, 0 };
443
36.0k
    sslEphemeralKeyPair *pair;
444
445
36.0k
    if (ssl_NamedGroup2ECParams(NULL, ecGroup, &ecParams) != SECSuccess) {
446
0
        return SECFailure;
447
0
    }
448
36.0k
    privKey = SECKEY_CreateECPrivateKey(&ecParams, &pubKey, ss->pkcs11PinArg);
449
36.0k
    SECITEM_FreeItem(&ecParams, PR_FALSE);
450
451
36.0k
    if (!privKey || !pubKey ||
452
36.0k
        !(pair = ssl_NewEphemeralKeyPair(ecGroup, privKey, pubKey))) {
453
283
        if (privKey) {
454
0
            SECKEY_DestroyPrivateKey(privKey);
455
0
        }
456
283
        if (pubKey) {
457
0
            SECKEY_DestroyPublicKey(pubKey);
458
0
        }
459
283
        ssl_MapLowLevelError(SEC_ERROR_KEYGEN_FAIL);
460
283
        return SECFailure;
461
283
    }
462
463
35.8k
    *keyPair = pair;
464
35.8k
    SSL_TRC(50, ("%d: SSL[%d]: Create ECDH ephemeral key %d",
465
35.8k
                 SSL_GETPID(), ss ? ss->fd : NULL, ecGroup->name));
466
35.8k
    PRINT_BUF(50, (ss, "Public Key", pubKey->u.ec.publicValue.data,
467
35.8k
                   pubKey->u.ec.publicValue.len));
468
35.8k
#ifdef TRACE
469
35.8k
    if (ssl_trace >= 50) {
470
0
        SECItem d = { siBuffer, NULL, 0 };
471
0
        SECStatus rv = PK11_ReadRawAttribute(PK11_TypePrivKey, privKey,
472
0
                                             CKA_VALUE, &d);
473
0
        if (rv == SECSuccess) {
474
0
            PRINT_BUF(50, (ss, "Private Key", d.data, d.len));
475
0
            SECITEM_FreeItem(&d, PR_FALSE);
476
0
        } else {
477
0
            SSL_TRC(50, ("Error extracting private key"));
478
0
        }
479
0
    }
480
35.8k
#endif
481
35.8k
    return SECSuccess;
482
36.0k
}
483
484
SECStatus
485
ssl3_HandleECDHServerKeyExchange(sslSocket *ss, PRUint8 *b, PRUint32 length)
486
4.26k
{
487
4.26k
    PLArenaPool *arena = NULL;
488
4.26k
    SECKEYPublicKey *peerKey = NULL;
489
4.26k
    PRBool isTLS;
490
4.26k
    SECStatus rv;
491
4.26k
    int errCode = SSL_ERROR_RX_MALFORMED_SERVER_KEY_EXCH;
492
4.26k
    SSL3AlertDescription desc = illegal_parameter;
493
4.26k
    SSL3Hashes hashes;
494
4.26k
    SECItem signature = { siBuffer, NULL, 0 };
495
4.26k
    SSLHashType hashAlg;
496
4.26k
    SSLSignatureScheme sigScheme;
497
498
4.26k
    SECItem ec_params = { siBuffer, NULL, 0 };
499
4.26k
    SECItem ec_point = { siBuffer, NULL, 0 };
500
4.26k
    unsigned char paramBuf[3];
501
4.26k
    const sslNamedGroupDef *ecGroup;
502
503
4.26k
    isTLS = (PRBool)(ss->ssl3.prSpec->version > SSL_LIBRARY_VERSION_3_0);
504
505
4.26k
    ec_params.len = sizeof paramBuf;
506
4.26k
    ec_params.data = paramBuf;
507
4.26k
    rv = ssl3_ConsumeHandshake(ss, ec_params.data, ec_params.len, &b, &length);
508
4.26k
    if (rv != SECSuccess) {
509
5
        goto loser; /* malformed. */
510
5
    }
511
512
    /* Fail if the curve is not a named curve */
513
4.25k
    if (ec_params.data[0] != ec_type_named) {
514
9
        errCode = SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE;
515
9
        desc = handshake_failure;
516
9
        goto alert_loser;
517
9
    }
518
4.24k
    ecGroup = ssl_LookupNamedGroup(ec_params.data[1] << 8 | ec_params.data[2]);
519
4.24k
    if (!ecGroup || ecGroup->keaType != ssl_kea_ecdh) {
520
11
        errCode = SEC_ERROR_UNSUPPORTED_ELLIPTIC_CURVE;
521
11
        desc = handshake_failure;
522
11
        goto alert_loser;
523
11
    }
524
525
4.23k
    rv = ssl3_ConsumeHandshakeVariable(ss, &ec_point, 1, &b, &length);
526
4.23k
    if (rv != SECSuccess) {
527
3
        goto loser; /* malformed. */
528
3
    }
529
530
    /* Fail if the provided point has length 0. */
531
4.23k
    if (!ec_point.len) {
532
        /* desc and errCode are initialized already */
533
5
        goto alert_loser;
534
5
    }
535
536
    /* Fail if the ec point is not uncompressed for any curve that's not 25519. */
537
4.23k
    if (ecGroup->name != ssl_grp_ec_curve25519 &&
538
4.23k
        ec_point.data[0] != EC_POINT_FORM_UNCOMPRESSED) {
539
12
        errCode = SEC_ERROR_UNSUPPORTED_EC_POINT_FORM;
540
12
        desc = handshake_failure;
541
12
        goto alert_loser;
542
12
    }
543
544
4.21k
    PORT_Assert(ss->ssl3.prSpec->version <= SSL_LIBRARY_VERSION_TLS_1_2);
545
4.21k
    if (ss->ssl3.prSpec->version == SSL_LIBRARY_VERSION_TLS_1_2) {
546
3.39k
        rv = ssl_ConsumeSignatureScheme(ss, &b, &length, &sigScheme);
547
3.39k
        if (rv != SECSuccess) {
548
24
            errCode = PORT_GetError();
549
24
            goto alert_loser; /* malformed or unsupported. */
550
24
        }
551
3.36k
        rv = ssl_CheckSignatureSchemeConsistency(
552
3.36k
            ss, sigScheme, &ss->sec.peerCert->subjectPublicKeyInfo);
553
3.36k
        if (rv != SECSuccess) {
554
45
            errCode = PORT_GetError();
555
45
            goto alert_loser;
556
45
        }
557
3.32k
        hashAlg = ssl_SignatureSchemeToHashType(sigScheme);
558
3.32k
    } else {
559
        /* Use ssl_hash_none to represent the MD5+SHA1 combo. */
560
825
        hashAlg = ssl_hash_none;
561
825
        sigScheme = ssl_sig_none;
562
825
    }
563
564
4.14k
    rv = ssl3_ConsumeHandshakeVariable(ss, &signature, 2, &b, &length);
565
4.14k
    if (rv != SECSuccess) {
566
8
        goto loser; /* malformed. */
567
8
    }
568
569
4.14k
    if (length != 0) {
570
2
        if (isTLS)
571
2
            desc = decode_error;
572
2
        goto alert_loser; /* malformed. */
573
2
    }
574
575
4.13k
    PRINT_BUF(60, (NULL, "Server EC params", ec_params.data, ec_params.len));
576
4.13k
    PRINT_BUF(60, (NULL, "Server EC point", ec_point.data, ec_point.len));
577
578
    /* failures after this point are not malformed handshakes. */
579
    /* TLS: send decrypt_error if signature failed. */
580
4.13k
    desc = isTLS ? decrypt_error : handshake_failure;
581
582
    /*
583
     *  check to make sure the hash is signed by right guy
584
     */
585
4.13k
    rv = ssl3_ComputeECDHKeyHash(hashAlg, ec_params, ec_point,
586
4.13k
                                 ss->ssl3.hs.client_random,
587
4.13k
                                 ss->ssl3.hs.server_random,
588
4.13k
                                 &hashes);
589
590
4.13k
    if (rv != SECSuccess) {
591
0
        errCode =
592
0
            ssl_MapLowLevelError(SSL_ERROR_SERVER_KEY_EXCHANGE_FAILURE);
593
0
        goto alert_loser;
594
0
    }
595
4.13k
    rv = ssl3_VerifySignedHashes(ss, sigScheme, &hashes, &signature);
596
4.13k
    if (rv != SECSuccess) {
597
1.80k
        errCode =
598
1.80k
            ssl_MapLowLevelError(SSL_ERROR_SERVER_KEY_EXCHANGE_FAILURE);
599
1.80k
        goto alert_loser;
600
1.80k
    }
601
602
2.33k
    arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
603
2.33k
    if (arena == NULL) {
604
0
        errCode = SEC_ERROR_NO_MEMORY;
605
0
        goto loser;
606
0
    }
607
608
2.33k
    peerKey = PORT_ArenaZNew(arena, SECKEYPublicKey);
609
2.33k
    if (peerKey == NULL) {
610
0
        errCode = SEC_ERROR_NO_MEMORY;
611
0
        goto loser;
612
0
    }
613
2.33k
    peerKey->arena = arena;
614
615
    /* create public key from point data */
616
2.33k
    rv = ssl_ImportECDHKeyShare(peerKey, ec_point.data, ec_point.len,
617
2.33k
                                ecGroup);
618
2.33k
    if (rv != SECSuccess) {
619
        /* error code is set */
620
0
        desc = handshake_failure;
621
0
        errCode = PORT_GetError();
622
0
        goto alert_loser;
623
0
    }
624
2.33k
    peerKey->pkcs11Slot = NULL;
625
2.33k
    peerKey->pkcs11ID = CK_INVALID_HANDLE;
626
627
2.33k
    ss->sec.peerKey = peerKey;
628
2.33k
    return SECSuccess;
629
630
1.91k
alert_loser:
631
1.91k
    (void)SSL3_SendAlert(ss, alert_fatal, desc);
632
1.93k
loser:
633
1.93k
    if (arena) {
634
0
        PORT_FreeArena(arena, PR_FALSE);
635
0
    }
636
1.93k
    PORT_SetError(errCode);
637
1.93k
    return SECFailure;
638
1.91k
}
639
640
SECStatus
641
ssl3_SendECDHServerKeyExchange(sslSocket *ss)
642
9.71k
{
643
9.71k
    SECStatus rv = SECFailure;
644
9.71k
    int length;
645
9.71k
    PRBool isTLS12;
646
9.71k
    SECItem signed_hash = { siBuffer, NULL, 0 };
647
9.71k
    SSLHashType hashAlg;
648
9.71k
    SSL3Hashes hashes;
649
650
9.71k
    SECItem ec_params = { siBuffer, NULL, 0 };
651
9.71k
    unsigned char paramBuf[3];
652
9.71k
    const sslNamedGroupDef *ecGroup;
653
9.71k
    sslEphemeralKeyPair *keyPair;
654
9.71k
    SECKEYPublicKey *pubKey;
655
656
    /* Generate ephemeral ECDH key pair and send the public key */
657
9.71k
    ecGroup = ssl_GetECGroupForServerSocket(ss);
658
9.71k
    if (!ecGroup) {
659
0
        goto loser;
660
0
    }
661
662
9.71k
    PORT_Assert(PR_CLIST_IS_EMPTY(&ss->ephemeralKeyPairs));
663
9.71k
    if (ss->opt.reuseServerECDHEKey) {
664
0
        rv = ssl_CreateStaticECDHEKey(ss, ecGroup);
665
0
        if (rv != SECSuccess) {
666
0
            goto loser;
667
0
        }
668
0
        keyPair = (sslEphemeralKeyPair *)PR_NEXT_LINK(&ss->ephemeralKeyPairs);
669
9.71k
    } else {
670
9.71k
        rv = ssl_CreateECDHEphemeralKeyPair(ss, ecGroup, &keyPair);
671
9.71k
        if (rv != SECSuccess) {
672
0
            goto loser;
673
0
        }
674
9.71k
        PR_APPEND_LINK(&keyPair->link, &ss->ephemeralKeyPairs);
675
9.71k
    }
676
677
9.71k
    PORT_Assert(keyPair);
678
9.71k
    if (!keyPair) {
679
0
        PORT_SetError(SSL_ERROR_SERVER_KEY_EXCHANGE_FAILURE);
680
0
        return SECFailure;
681
0
    }
682
683
9.71k
    ec_params.len = sizeof(paramBuf);
684
9.71k
    ec_params.data = paramBuf;
685
9.71k
    PORT_Assert(keyPair->group);
686
9.71k
    PORT_Assert(keyPair->group->keaType == ssl_kea_ecdh);
687
9.71k
    ec_params.data[0] = ec_type_named;
688
9.71k
    ec_params.data[1] = keyPair->group->name >> 8;
689
9.71k
    ec_params.data[2] = keyPair->group->name & 0xff;
690
691
9.71k
    pubKey = keyPair->keys->pubKey;
692
9.71k
    if (ss->version == SSL_LIBRARY_VERSION_TLS_1_2) {
693
9.71k
        hashAlg = ssl_SignatureSchemeToHashType(ss->ssl3.hs.signatureScheme);
694
9.71k
    } else {
695
        /* Use ssl_hash_none to represent the MD5+SHA1 combo. */
696
0
        hashAlg = ssl_hash_none;
697
0
    }
698
9.71k
    rv = ssl3_ComputeECDHKeyHash(hashAlg, ec_params,
699
9.71k
                                 pubKey->u.ec.publicValue,
700
9.71k
                                 ss->ssl3.hs.client_random,
701
9.71k
                                 ss->ssl3.hs.server_random,
702
9.71k
                                 &hashes);
703
9.71k
    if (rv != SECSuccess) {
704
0
        ssl_MapLowLevelError(SSL_ERROR_SERVER_KEY_EXCHANGE_FAILURE);
705
0
        goto loser;
706
0
    }
707
708
9.71k
    isTLS12 = (PRBool)(ss->version >= SSL_LIBRARY_VERSION_TLS_1_2);
709
710
9.71k
    rv = ssl3_SignHashes(ss, &hashes,
711
9.71k
                         ss->sec.serverCert->serverKeyPair->privKey, &signed_hash);
712
9.71k
    if (rv != SECSuccess) {
713
0
        goto loser; /* ssl3_SignHashes has set err. */
714
0
    }
715
716
9.71k
    length = ec_params.len +
717
9.71k
             1 + pubKey->u.ec.publicValue.len +
718
9.71k
             (isTLS12 ? 2 : 0) + 2 + signed_hash.len;
719
720
9.71k
    rv = ssl3_AppendHandshakeHeader(ss, ssl_hs_server_key_exchange, length);
721
9.71k
    if (rv != SECSuccess) {
722
0
        goto loser; /* err set by AppendHandshake. */
723
0
    }
724
725
9.71k
    rv = ssl3_AppendHandshake(ss, ec_params.data, ec_params.len);
726
9.71k
    if (rv != SECSuccess) {
727
0
        goto loser; /* err set by AppendHandshake. */
728
0
    }
729
730
9.71k
    rv = ssl3_AppendHandshakeVariable(ss, pubKey->u.ec.publicValue.data,
731
9.71k
                                      pubKey->u.ec.publicValue.len, 1);
732
9.71k
    if (rv != SECSuccess) {
733
0
        goto loser; /* err set by AppendHandshake. */
734
0
    }
735
736
9.71k
    if (isTLS12) {
737
9.71k
        rv = ssl3_AppendHandshakeNumber(ss, ss->ssl3.hs.signatureScheme, 2);
738
9.71k
        if (rv != SECSuccess) {
739
0
            goto loser; /* err set by AppendHandshake. */
740
0
        }
741
9.71k
    }
742
743
9.71k
    rv = ssl3_AppendHandshakeVariable(ss, signed_hash.data,
744
9.71k
                                      signed_hash.len, 2);
745
9.71k
    if (rv != SECSuccess) {
746
0
        goto loser; /* err set by AppendHandshake. */
747
0
    }
748
749
9.71k
    PORT_Free(signed_hash.data);
750
9.71k
    return SECSuccess;
751
752
0
loser:
753
0
    if (signed_hash.data != NULL)
754
0
        PORT_Free(signed_hash.data);
755
0
    return SECFailure;
756
9.71k
}
757
758
/* List of all ECC cipher suites */
759
static const ssl3CipherSuite ssl_all_ec_suites[] = {
760
    TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA,
761
    TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
762
    TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
763
    TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
764
    TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
765
    TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
766
    TLS_ECDHE_ECDSA_WITH_NULL_SHA,
767
    TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
768
    TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,
769
    TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
770
    TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
771
    TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
772
    TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
773
    TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
774
    TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
775
    TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
776
    TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
777
    TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
778
    TLS_ECDHE_RSA_WITH_NULL_SHA,
779
    TLS_ECDHE_RSA_WITH_RC4_128_SHA,
780
    TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA,
781
    TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
782
    TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
783
    TLS_ECDH_ECDSA_WITH_NULL_SHA,
784
    TLS_ECDH_ECDSA_WITH_RC4_128_SHA,
785
    TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA,
786
    TLS_ECDH_RSA_WITH_AES_128_CBC_SHA,
787
    TLS_ECDH_RSA_WITH_AES_256_CBC_SHA,
788
    TLS_ECDH_RSA_WITH_NULL_SHA,
789
    TLS_ECDH_RSA_WITH_RC4_128_SHA,
790
    0 /* end of list marker */
791
};
792
793
static const ssl3CipherSuite ssl_dhe_suites[] = {
794
    TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
795
    TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
796
    TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
797
    TLS_DHE_DSS_WITH_AES_128_GCM_SHA256,
798
    TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
799
    TLS_DHE_DSS_WITH_AES_128_CBC_SHA,
800
    TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,
801
    TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,
802
    TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA,
803
    TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA,
804
    TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
805
    TLS_DHE_DSS_WITH_AES_256_CBC_SHA,
806
    TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,
807
    TLS_DHE_DSS_WITH_AES_256_CBC_SHA256,
808
    TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA,
809
    TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA,
810
    TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA,
811
    TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA,
812
    TLS_DHE_DSS_WITH_RC4_128_SHA,
813
    TLS_DHE_RSA_WITH_DES_CBC_SHA,
814
    TLS_DHE_DSS_WITH_DES_CBC_SHA,
815
    0
816
};
817
818
/* Order(N^2).  Yuk. */
819
static PRBool
820
ssl_IsSuiteEnabled(const sslSocket *ss, const ssl3CipherSuite *list)
821
69.9k
{
822
69.9k
    const ssl3CipherSuite *suite;
823
824
69.9k
    for (suite = list; *suite; ++suite) {
825
69.9k
        PRBool enabled = PR_FALSE;
826
69.9k
        SECStatus rv = ssl3_CipherPrefGet(ss, *suite, &enabled);
827
828
69.9k
        PORT_Assert(rv == SECSuccess); /* else is coding error */
829
69.9k
        if (rv == SECSuccess && enabled)
830
69.9k
            return PR_TRUE;
831
69.9k
    }
832
0
    return PR_FALSE;
833
69.9k
}
834
835
/* Ask: is ANY ECC cipher suite enabled on this socket? */
836
PRBool
837
ssl_IsECCEnabled(const sslSocket *ss)
838
60.1k
{
839
60.1k
    PK11SlotInfo *slot;
840
841
    /* make sure we can do ECC */
842
60.1k
    slot = PK11_GetBestSlot(CKM_ECDH1_DERIVE, ss->pkcs11PinArg);
843
60.1k
    if (!slot) {
844
0
        return PR_FALSE;
845
0
    }
846
60.1k
    PK11_FreeSlot(slot);
847
848
    /* make sure an ECC cipher is enabled */
849
60.1k
    return ssl_IsSuiteEnabled(ss, ssl_all_ec_suites);
850
60.1k
}
851
852
PRBool
853
ssl_IsDHEEnabled(const sslSocket *ss)
854
9.71k
{
855
9.71k
    return ssl_IsSuiteEnabled(ss, ssl_dhe_suites);
856
9.71k
}
857
858
/* Send our Supported Groups extension. */
859
SECStatus
860
ssl_SendSupportedGroupsXtn(const sslSocket *ss, TLSExtensionData *xtnData,
861
                           sslBuffer *buf, PRBool *added)
862
42.8k
{
863
42.8k
    unsigned int i;
864
42.8k
    PRBool ec;
865
42.8k
    PRBool ec_hybrid = PR_FALSE;
866
42.8k
    PRBool ff = PR_FALSE;
867
42.8k
    PRBool found = PR_FALSE;
868
42.8k
    SECStatus rv;
869
42.8k
    unsigned int lengthOffset;
870
871
    /* We only send FF supported groups if we require DH named groups
872
     * or if TLS 1.3 is a possibility. */
873
42.8k
    if (ss->vrange.max < SSL_LIBRARY_VERSION_TLS_1_3) {
874
16.9k
        ec = ssl_IsECCEnabled(ss);
875
16.9k
        if (ss->opt.requireDHENamedGroups) {
876
9.71k
            ff = ssl_IsDHEEnabled(ss);
877
9.71k
        }
878
16.9k
        if (!ec && !ff) {
879
0
            return SECSuccess;
880
0
        }
881
25.9k
    } else {
882
25.9k
        ec = ec_hybrid = ff = PR_TRUE;
883
25.9k
    }
884
885
    /* Mark the location of the length. */
886
42.8k
    rv = sslBuffer_Skip(buf, 2, &lengthOffset);
887
42.8k
    if (rv != SECSuccess) {
888
0
        return SECFailure;
889
0
    }
890
891
1.41M
    for (i = 0; i < SSL_NAMED_GROUP_COUNT; ++i) {
892
1.37M
        const sslNamedGroupDef *group = ss->namedGroupPreferences[i];
893
1.37M
        if (!group) {
894
992k
            continue;
895
992k
        }
896
380k
        if (group->keaType == ssl_kea_ecdh && !ec) {
897
0
            continue;
898
0
        }
899
380k
        if (group->keaType == ssl_kea_ecdh_hybrid && !ec_hybrid) {
900
0
            continue;
901
0
        }
902
380k
        if (group->keaType == ssl_kea_dh && !ff) {
903
36.2k
            continue;
904
36.2k
        }
905
906
344k
        found = PR_TRUE;
907
344k
        rv = sslBuffer_AppendNumber(buf, group->name, 2);
908
344k
        if (rv != SECSuccess) {
909
0
            return SECFailure;
910
0
        }
911
344k
    }
912
913
    /* GREASE SupportedGroups:
914
     * A client MAY select one or more GREASE named group values and advertise
915
     * them in the "supported_groups" extension, if sent [RFC8701, Section 3.1].
916
     */
917
42.8k
    if (!ss->sec.isServer &&
918
42.8k
        ss->opt.enableGrease &&
919
42.8k
        ss->vrange.max >= SSL_LIBRARY_VERSION_TLS_1_3) {
920
0
        rv = sslBuffer_AppendNumber(buf, ss->ssl3.hs.grease->idx[grease_group], 2);
921
0
        if (rv != SECSuccess) {
922
0
            return SECFailure;
923
0
        }
924
0
        found = PR_TRUE;
925
0
    }
926
927
42.8k
    if (!found) {
928
        /* We added nothing, don't send the extension. */
929
0
        return SECSuccess;
930
0
    }
931
932
42.8k
    rv = sslBuffer_InsertLength(buf, lengthOffset, 2);
933
42.8k
    if (rv != SECSuccess) {
934
0
        return SECFailure;
935
0
    }
936
937
42.8k
    *added = PR_TRUE;
938
42.8k
    return SECSuccess;
939
42.8k
}
940
941
/* Send our "canned" (precompiled) Supported Point Formats extension,
942
 * which says that we only support uncompressed points.
943
 */
944
SECStatus
945
ssl3_SendSupportedPointFormatsXtn(const sslSocket *ss, TLSExtensionData *xtnData,
946
                                  sslBuffer *buf, PRBool *added)
947
43.2k
{
948
43.2k
    SECStatus rv;
949
950
    /* No point in doing this unless we have a socket that supports ECC.
951
     * Similarly, no point if we are going to do TLS 1.3 only or we have already
952
     * picked TLS 1.3 (server) given that it doesn't use point formats. */
953
43.2k
    if (!ss || !ssl_IsECCEnabled(ss) ||
954
43.2k
        ss->vrange.min >= SSL_LIBRARY_VERSION_TLS_1_3 ||
955
43.2k
        (ss->sec.isServer && ss->version >= SSL_LIBRARY_VERSION_TLS_1_3)) {
956
0
        return SECSuccess;
957
0
    }
958
43.2k
    rv = sslBuffer_AppendNumber(buf, 1, 1); /* length */
959
43.2k
    if (rv != SECSuccess) {
960
0
        return SECFailure;
961
0
    }
962
43.2k
    rv = sslBuffer_AppendNumber(buf, 0, 1); /* uncompressed type only */
963
43.2k
    if (rv != SECSuccess) {
964
0
        return SECFailure;
965
0
    }
966
967
43.2k
    *added = PR_TRUE;
968
43.2k
    return SECSuccess;
969
43.2k
}