1 /*
2  * NSS utility functions
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 
8 #include "prtypes.h"
9 #include "prinit.h"
10 #include "seccomon.h"
11 #include "secerr.h"
12 #include "ssl.h"
13 #include "sslimpl.h"
14 #include "sslproto.h"
15 
16 static int ssl_isInited = 0;
17 static PRCallOnceType ssl_init = { 0 };
18 PR_STATIC_ASSERT(sizeof(unsigned long) <= sizeof(PRUint64));
19 
20 PRStatus
ssl_InitCallOnce(void * arg)21 ssl_InitCallOnce(void *arg)
22 {
23     int *error = (int *)arg;
24     SECStatus rv;
25 
26     rv = ssl_InitializePRErrorTable();
27     if (rv != SECSuccess) {
28         *error = SEC_ERROR_NO_MEMORY;
29         return PR_FAILURE;
30     }
31 #ifdef DEBUG
32     ssl3_CheckCipherSuiteOrderConsistency();
33 #endif
34 
35     rv = ssl3_ApplyNSSPolicy();
36     if (rv != SECSuccess) {
37         *error = PORT_GetError();
38         return PR_FAILURE;
39     }
40     return PR_SUCCESS;
41 }
42 
43 SECStatus
ssl_Init(void)44 ssl_Init(void)
45 {
46     PRStatus nrv;
47 
48     /* short circuit test if we are already inited */
49     if (!ssl_isInited) {
50         int error;
51         /* only do this once at init time, block all others until we are done */
52         nrv = PR_CallOnceWithArg(&ssl_init, ssl_InitCallOnce, &error);
53         if (nrv != PR_SUCCESS) {
54             PORT_SetError(error);
55             return SECFailure;
56         }
57         ssl_isInited = 1;
58     }
59     return SECSuccess;
60 }
61