Ignore:
Timestamp:
Feb 7, 2019, 8:36:33 AM (5 years ago)
Author:
coas-nagasima
Message:

wolfsslを3.15.7にバージョンアップ

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_rx/trunk/wolfssl-3.12.2/src/sniffer.c

    r337 r372  
    246246    /* 81 */
    247247    "Bad Decrypt Size",
    248     "Extended Master Secret Hash Error"
     248    "Extended Master Secret Hash Error",
     249    "Handshake Message Split Across TLS Records"
    249250};
    250251
     
    253254static void GetError(int idx, char* str)
    254255{
    255     XSTRNCPY(str, msgTable[idx - 1], MAX_ERROR_LEN);
     256    XSTRNCPY(str, msgTable[idx - 1], MAX_ERROR_LEN-1);
     257    str[MAX_ERROR_LEN-1] = '\0';
    256258}
    257259
     
    10161018
    10171019
     1020/* Show SSLInfo if provided and is valid. */
     1021static void TraceSessionInfo(SSLInfo* sslInfo)
     1022{
     1023    if (TraceOn) {
     1024        if (sslInfo != NULL && sslInfo->isValid) {
     1025            fprintf(TraceFile,
     1026                    "\tver:(%u %u) suiteId:(%02x %02x) suiteName:(%s)\n",
     1027                    sslInfo->protocolVersionMajor,
     1028                    sslInfo->protocolVersionMinor,
     1029                    sslInfo->serverCipherSuite0,
     1030                    sslInfo->serverCipherSuite,
     1031                    sslInfo->serverCipherSuiteName);
     1032        }
     1033    }
     1034}
     1035
     1036
    10181037/* Set user error string */
    10191038static void SetError(int idx, char* error, SnifferSession* session, int fatal)
     
    11661185    file = XFOPEN(keyFile, "rb");
    11671186    if (file == XBADFILE) return -1;
    1168     XFSEEK(file, 0, XSEEK_END);
     1187    if(XFSEEK(file, 0, XSEEK_END) != 0) return -1;
    11691188    fileSz = XFTELL(file);
    11701189    XREWIND(file);
     
    11901209        ret = -1;
    11911210        if (saveBuf != NULL) {
    1192             saveBufSz = wolfSSL_KeyPemToDer(loadBuf, (int)fileSz,
     1211            saveBufSz = wc_KeyPemToDer(loadBuf, (int)fileSz,
    11931212                                                saveBuf, (int)fileSz, password);
    11941213            if (saveBufSz < 0) {
     
    12491268
    12501269        namedKey->nameSz = (word32)XSTRLEN(name);
    1251         XSTRNCPY(namedKey->name, name, sizeof(namedKey->name));
    1252         if (namedKey->nameSz >= sizeof(namedKey->name)) {
     1270        if (namedKey->nameSz > sizeof(namedKey->name)-1)
    12531271            namedKey->nameSz = sizeof(namedKey->name) - 1;
    1254             namedKey->name[namedKey->nameSz] = '\0';
    1255         }
     1272        XSTRNCPY(namedKey->name, name, namedKey->nameSz);
     1273        namedKey->name[MAX_SERVER_NAME-1] = '\0';
    12561274
    12571275        ret = LoadKeyFile(&namedKey->key, &namedKey->keySz,
     
    12891307        sniffer->port = port;
    12901308
    1291         sniffer->ctx = SSL_CTX_new(TLSv1_client_method());
     1309        sniffer->ctx = SSL_CTX_new(TLSv1_2_client_method());
    12921310        if (!sniffer->ctx) {
    12931311            SetError(MEMORY_STR, error, NULL, 0);
     
    13021320    if (name == NULL) {
    13031321        if (password) {
     1322    #ifdef WOLFSSL_ENCRYPTED_KEYS
    13041323            SSL_CTX_set_default_passwd_cb(sniffer->ctx, SetPassword);
    13051324            SSL_CTX_set_default_passwd_cb_userdata(
    13061325                                                 sniffer->ctx, (void*)password);
     1326    #endif
    13071327        }
    13081328        ret = SSL_CTX_use_PrivateKey_file(sniffer->ctx, keyFile, type);
     
    18291849            NamedKey* namedKey;
    18301850
    1831             if (nameSz >= sizeof(name))
     1851            if (nameSz > sizeof(name) - 1)
    18321852                nameSz = sizeof(name) - 1;
    18331853            name[nameSz] = 0;
     
    20592079
    20602080    if (*sslBytes < size) {
    2061         SetError(HANDSHAKE_INPUT_STR, error, session, FATAL_ERROR_STATE);
    2062         return -1;
     2081        Trace(SPLIT_HANDSHAKE_MSG_STR);
     2082        *sslBytes = 0;
     2083        return ret;
    20632084    }
    20642085
     
    34623483
    34633484
     3485/* Copies the session's infomation to the provided sslInfo. Skip copy if
     3486 * SSLInfo is not provided. */
     3487static void CopySessionInfo(SnifferSession* session, SSLInfo* sslInfo)
     3488{
     3489    if (NULL != sslInfo) {
     3490        XMEMSET(sslInfo, 0, sizeof(SSLInfo));
     3491
     3492        /* Pass back Session Info after we have processed the Server Hello. */
     3493        if (0 != session->sslServer->options.cipherSuite) {
     3494            const char* pCipher;
     3495
     3496            sslInfo->isValid = 1;
     3497            sslInfo->protocolVersionMajor = session->sslServer->version.major;
     3498            sslInfo->protocolVersionMinor = session->sslServer->version.minor;
     3499            sslInfo->serverCipherSuite0 =
     3500                        session->sslServer->options.cipherSuite0;
     3501            sslInfo->serverCipherSuite =
     3502                        session->sslServer->options.cipherSuite;
     3503
     3504            pCipher = wolfSSL_get_cipher(session->sslServer);
     3505            if (NULL != pCipher) {
     3506                XSTRNCPY((char*)sslInfo->serverCipherSuiteName, pCipher,
     3507                         sizeof(sslInfo->serverCipherSuiteName));
     3508                sslInfo->serverCipherSuiteName
     3509                         [sizeof(sslInfo->serverCipherSuiteName) - 1] = '\0';
     3510            }
     3511            TraceSessionInfo(sslInfo);
     3512        }
     3513    }
     3514}
     3515
     3516
    34643517/* Passes in an IP/TCP packet for decoding (ethernet/localhost frame) removed */
    34653518/* returns Number of bytes on success, 0 for no data yet, and -1 on error */
    3466 int ssl_DecodePacket(const byte* packet, int length, byte** data, char* error)
     3519static int ssl_DecodePacketInternal(const byte* packet, int length,
     3520                                    byte** data, SSLInfo* sslInfo, char* error)
    34673521{
    34683522    TcpInfo           tcpInfo;
     
    34973551    if (RemoveFatalSession(&ipInfo, &tcpInfo, session, error)) return -1;
    34983552    CheckFinCapture(&ipInfo, &tcpInfo, session);
     3553
     3554    CopySessionInfo(session, sslInfo);
     3555
    34993556    return ret;
     3557}
     3558
     3559
     3560/* Passes in an IP/TCP packet for decoding (ethernet/localhost frame) removed */
     3561/* returns Number of bytes on success, 0 for no data yet, and -1 on error */
     3562/* Also returns Session Info if available */
     3563int ssl_DecodePacketWithSessionInfo(const unsigned char* packet, int length,
     3564    unsigned char** data, SSLInfo* sslInfo, char* error)
     3565{
     3566    return ssl_DecodePacketInternal(packet, length, data, sslInfo, error);
     3567}
     3568
     3569
     3570/* Passes in an IP/TCP packet for decoding (ethernet/localhost frame) removed */
     3571/* returns Number of bytes on success, 0 for no data yet, and -1 on error */
     3572int ssl_DecodePacket(const byte* packet, int length, byte** data, char* error)
     3573{
     3574    return ssl_DecodePacketInternal(packet, length, data, NULL, error);
    35003575}
    35013576
Note: See TracChangeset for help on using the changeset viewer.