Changeset 5ebff60 for lib/ssl_nss.c


Ignore:
Timestamp:
2015-02-20T22:50:54Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0b9daac, 3d45471, 7733b8c
Parents:
af359b4
git-author:
Indent <please@…> (19-02-15 05:47:20)
git-committer:
dequis <dx@…> (20-02-15 22:50:54)
Message:

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/ssl_nss.c

    raf359b4 r5ebff60  
    1   /********************************************************************\
     1/********************************************************************\
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
     
    6060
    6161static gboolean ssl_connected(gpointer data, gint source,
    62                               b_input_condition cond);
     62                              b_input_condition cond);
    6363static gboolean ssl_starttls_real(gpointer data, gint source,
    64                                   b_input_condition cond);
     64                                  b_input_condition cond);
    6565
    6666static SECStatus nss_auth_cert(void *arg, PRFileDesc * socket, PRBool checksig,
    67                                PRBool isserver)
     67                               PRBool isserver)
    6868{
    6969        return SECSuccess;
     
    7474        PRErrorCode err;
    7575
    76         if (!arg)
     76        if (!arg) {
    7777                return SECFailure;
     78        }
    7879
    7980        *(PRErrorCode *) arg = err = PORT_GetError();
     
    114115
    115116void *ssl_connect(char *host, int port, gboolean verify,
    116                   ssl_input_function func, gpointer data)
     117                  ssl_input_function func, gpointer data)
    117118{
    118119        struct scd *conn = g_new0(struct scd, 1);
     
    137138
    138139static gboolean ssl_starttls_real(gpointer data, gint source,
    139                                   b_input_condition cond)
     140                                  b_input_condition cond)
    140141{
    141142        struct scd *conn = data;
     
    145146
    146147void *ssl_starttls(int fd, char *hostname, gboolean verify,
    147                    ssl_input_function func, gpointer data)
     148                   ssl_input_function func, gpointer data)
    148149{
    149150        struct scd *conn = g_new0(struct scd, 1);
     
    175176
    176177static gboolean ssl_connected(gpointer data, gint source,
    177                               b_input_condition cond)
     178                              b_input_condition cond)
    178179{
    179180        struct scd *conn = data;
     
    183184        if (conn->verify) {
    184185                conn->func(conn->data, 1, NULL, cond);
    185                 if (source >= 0)
     186                if (source >= 0) {
    186187                        closesocket(source);
     188                }
    187189                g_free(conn->hostname);
    188190                g_free(conn);
     
    191193        }
    192194
    193         if (source == -1)
     195        if (source == -1) {
    194196                goto ssl_connected_failure;
     197        }
    195198
    196199        /* Until we find out how to handle non-blocking I/O with NSS... */
     
    198201
    199202        conn->prfd = SSL_ImportFD(NULL, PR_ImportTCPSocket(source));
    200         if (!conn->prfd)
     203        if (!conn->prfd) {
    201204                goto ssl_connected_failure;
     205        }
    202206        SSL_OptionSet(conn->prfd, SSL_SECURITY, PR_TRUE);
    203207        SSL_OptionSet(conn->prfd, SSL_HANDSHAKE_AS_CLIENT, PR_TRUE);
    204208        SSL_BadCertHook(conn->prfd, (SSLBadCertHandler) nss_bad_cert, NULL);
    205209        SSL_AuthCertificateHook(conn->prfd, (SSLAuthCertificate) nss_auth_cert,
    206                                 (void *)CERT_GetDefaultCertDB());
     210                                (void *) CERT_GetDefaultCertDB());
    207211        SSL_SetURL(conn->prfd, conn->hostname);
    208212        SSL_ResetHandshake(conn->prfd, PR_FALSE);
     
    216220        return FALSE;
    217221
    218  ssl_connected_failure:
     222ssl_connected_failure:
    219223
    220224        conn->func(conn->data, 0, NULL, cond);
    221225
    222         if (conn->prfd)
     226        if (conn->prfd) {
    223227                PR_Close(conn->prfd);
    224         if (source >= 0)
     228        }
     229        if (source >= 0) {
    225230                closesocket(source);
     231        }
    226232        g_free(conn->hostname);
    227233        g_free(conn);
     
    235241        PRErrorCode PR_err;
    236242
    237         if (!((struct scd *)conn)->established) {
     243        if (!((struct scd *) conn)->established) {
    238244                ssl_errno = SSL_NOHANDSHAKE;
    239245                return -1;
    240246        }
    241247
    242         st = PR_Read(((struct scd *)conn)->prfd, buf, len);
     248        st = PR_Read(((struct scd *) conn)->prfd, buf, len);
    243249        PR_err = PR_GetError();
    244250
    245251        ssl_errno = SSL_OK;
    246         if (PR_err == PR_WOULD_BLOCK_ERROR)
     252        if (PR_err == PR_WOULD_BLOCK_ERROR) {
    247253                ssl_errno = SSL_AGAIN;
    248 
    249         if (SSLDEBUG && getenv("BITLBEE_DEBUG") && st > 0)
     254        }
     255
     256        if (SSLDEBUG && getenv("BITLBEE_DEBUG") && st > 0) {
    250257                len = write(STDERR_FILENO, buf, st);
     258        }
    251259
    252260        return st;
     
    258266        PRErrorCode PR_err;
    259267
    260         if (!((struct scd *)conn)->established) {
     268        if (!((struct scd *) conn)->established) {
    261269                ssl_errno = SSL_NOHANDSHAKE;
    262270                return -1;
    263271        }
    264         st = PR_Write(((struct scd *)conn)->prfd, buf, len);
     272        st = PR_Write(((struct scd *) conn)->prfd, buf, len);
    265273        PR_err = PR_GetError();
    266274
    267275        ssl_errno = SSL_OK;
    268         if (PR_err == PR_WOULD_BLOCK_ERROR)
     276        if (PR_err == PR_WOULD_BLOCK_ERROR) {
    269277                ssl_errno = SSL_AGAIN;
    270 
    271         if (SSLDEBUG && getenv("BITLBEE_DEBUG") && st > 0)
     278        }
     279
     280        if (SSLDEBUG && getenv("BITLBEE_DEBUG") && st > 0) {
    272281                len = write(2, buf, st);
     282        }
    273283
    274284        return st;
     
    277287int ssl_pending(void *conn)
    278288{
    279         struct scd *c = (struct scd *)conn;
     289        struct scd *c = (struct scd *) conn;
    280290
    281291        if (c == NULL) {
     
    293303        // NSS_Shutdown();
    294304
    295         if (conn->prfd)
     305        if (conn->prfd) {
    296306                PR_Close(conn->prfd);
     307        }
    297308
    298309        g_free(conn->hostname);
     
    302313int ssl_getfd(void *conn)
    303314{
    304         return (((struct scd *)conn)->fd);
     315        return (((struct scd *) conn)->fd);
    305316}
    306317
     
    314325{
    315326        return
    316             g_strdup
    317             ("SSL certificate verification not supported by BitlBee NSS code.");
     327                g_strdup
     328                        ("SSL certificate verification not supported by BitlBee NSS code.");
    318329}
    319330
    320331size_t ssl_des3_encrypt(const unsigned char *key, size_t key_len,
    321                         const unsigned char *input, size_t input_len,
    322                         const unsigned char *iv, unsigned char **res)
     332                        const unsigned char *input, size_t input_len,
     333                        const unsigned char *iv, unsigned char **res)
    323334{
    324335#define CIPHER_MECH CKM_DES3_CBC
     
    342353        }
    343354
    344         keyItem.data = (unsigned char *)key;
     355        keyItem.data = (unsigned char *) key;
    345356        keyItem.len = key_len;
    346357
     
    348359        if (slot == NULL) {
    349360                fprintf(stderr, "PK11_GetBestSlot failed (err %d)\n",
    350                         PR_GetError());
     361                        PR_GetError());
    351362                rc = 0;
    352363                goto out;
     
    354365
    355366        symKey =
    356             PK11_ImportSymKey(slot, CIPHER_MECH, PK11_OriginUnwrap, CKA_ENCRYPT,
    357                               &keyItem, NULL);
     367                PK11_ImportSymKey(slot, CIPHER_MECH, PK11_OriginUnwrap, CKA_ENCRYPT,
     368                                  &keyItem, NULL);
    358369        if (symKey == NULL) {
    359370                fprintf(stderr, "PK11_ImportSymKey failed (err %d)\n",
    360                         PR_GetError());
    361                 rc = 0;
    362                 goto out;
    363         }
    364 
    365         ivItem.data = (unsigned char *)iv;
     371                        PR_GetError());
     372                rc = 0;
     373                goto out;
     374        }
     375
     376        ivItem.data = (unsigned char *) iv;
    366377        /* See msn_soap_passport_sso_handle_response in protocols/msn/soap.c */
    367378        ivItem.len = 8;
     
    370381        if (secParam == NULL) {
    371382                fprintf(stderr, "PK11_ParamFromIV failed (err %d)\n",
    372                         PR_GetError());
     383                        PR_GetError());
    373384                rc = 0;
    374385                goto out;
     
    376387
    377388        ctx =
    378             PK11_CreateContextBySymKey(CIPHER_MECH, CKA_ENCRYPT, symKey,
    379                                        secParam);
     389                PK11_CreateContextBySymKey(CIPHER_MECH, CKA_ENCRYPT, symKey,
     390                                           secParam);
    380391        if (ctx == NULL) {
    381392                fprintf(stderr, "PK11_CreateContextBySymKey failed (err %d)\n",
    382                         PR_GetError());
     393                        PR_GetError());
    383394                rc = 0;
    384395                goto out;
     
    388399
    389400        rv = PK11_CipherOp(ctx, *res, &len1, MAX_OUTPUT_LEN,
    390                            (unsigned char *)input, input_len);
     401                           (unsigned char *) input, input_len);
    391402        if (rv != SECSuccess) {
    392403                fprintf(stderr, "PK11_CipherOp failed (err %d)\n",
    393                         PR_GetError());
     404                        PR_GetError());
    394405                rc = 0;
    395406                goto out;
     
    399410
    400411        rv = PK11_DigestFinal(ctx, *res + len1, &len2,
    401                               (unsigned int)MAX_OUTPUT_LEN - len1);
     412                              (unsigned int) MAX_OUTPUT_LEN - len1);
    402413        if (rv != SECSuccess) {
    403414                fprintf(stderr, "PK11_DigestFinal failed (err %d)\n",
    404                         PR_GetError());
     415                        PR_GetError());
    405416                rc = 0;
    406417                goto out;
     
    409420        rc = len1 + len2;
    410421
    411  out:
    412         if (ctx)
     422out:
     423        if (ctx) {
    413424                PK11_DestroyContext(ctx, PR_TRUE);
    414         if (symKey)
     425        }
     426        if (symKey) {
    415427                PK11_FreeSymKey(symKey);
    416         if (secParam)
     428        }
     429        if (secParam) {
    417430                SECITEM_FreeItem(secParam, PR_TRUE);
    418         if (slot)
     431        }
     432        if (slot) {
    419433                PK11_FreeSlot(slot);
     434        }
    420435
    421436        return rc;
Note: See TracChangeset for help on using the changeset viewer.