Ignore:
Timestamp:
Jun 22, 2021, 9:00:19 PM (3 years ago)
Author:
coas-nagasima
Message:

WolfSSLとAzure IoT SDKを更新

Location:
azure_iot_hub_f767zi/trunk/wolfssl-4.7.0
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/src/wolfio.c

    r457 r464  
    8989}
    9090
    91 static WC_INLINE int wolfSSL_LastError(void)
    92 {
     91static WC_INLINE int wolfSSL_LastError(int err)
     92{
     93    (void)err; /* Suppress unused arg */
     94
    9395#ifdef USE_WINDOWS_API
    9496    return WSAGetLastError();
    9597#elif defined(EBSNET)
    9698    return xn_getlasterror();
     99#elif defined(WOLFSSL_LINUXKM)
     100    return err; /* Return provided error value */
     101#elif defined(FUSION_RTOS)
     102    #include <fclerrno.h>
     103    return FCL_GET_ERRNO;
    97104#else
    98105    return errno;
     
    104111
    105112#ifdef OPENSSL_EXTRA
     113#ifndef NO_BIO
    106114/* Use the WOLFSSL read BIO for receiving data. This is set by the function
    107115 * wolfSSL_set_bio and can also be set by wolfSSL_CTX_SetIORecv.
     
    182190        WOLFSSL_MSG("Calling custom biowr");
    183191        sent = ssl->biowr->method->writeCb(ssl->biowr, buf, sz);
    184         if (sent < 0) {
     192        if ((sent < 0) && (sent != WOLFSSL_CBIO_ERR_WANT_WRITE)) {
    185193            return WOLFSSL_CBIO_ERR_GENERAL;
    186194        }
     
    205213    return sent;
    206214}
    207 #endif
     215#endif /* !NO_BIO */
     216#endif /* OPENSSL_EXTRA */
    208217
    209218
     
    215224int EmbedReceive(WOLFSSL *ssl, char *buf, int sz, void *ctx)
    216225{
     226    int recvd;
     227#ifndef WOLFSSL_LINUXKM
    217228    int sd = *(int*)ctx;
    218     int recvd;
     229#else
     230    struct socket *sd = (struct socket*)ctx;
     231#endif
    219232
    220233    recvd = wolfIO_Recv(sd, buf, sz, ssl->rflags);
    221234    if (recvd < 0) {
    222         int err = wolfSSL_LastError();
     235        int err = wolfSSL_LastError(recvd);
    223236        WOLFSSL_MSG("Embed Receive error");
    224237
     
    257270int EmbedSend(WOLFSSL* ssl, char *buf, int sz, void *ctx)
    258271{
     272    int sent;
     273#ifndef WOLFSSL_LINUXKM
    259274    int sd = *(int*)ctx;
    260     int sent;
     275#else
     276    struct socket *sd = (struct socket*)ctx;
     277#endif
    261278
    262279#ifdef WOLFSSL_MAX_SEND_SZ
     
    267284    sent = wolfIO_Send(sd, buf, sz, ssl->wflags);
    268285    if (sent < 0) {
    269         int err = wolfSSL_LastError();
     286        int err = wolfSSL_LastError(sent);
    270287        WOLFSSL_MSG("Embed Send error");
    271288
     
    319336    WOLFSSL_ENTER("EmbedReceiveFrom()");
    320337
    321     if (ssl->options.handShakeDone)
     338    /* Don't use ssl->options.handShakeDone since it is true even if
     339     * we are in the process of renegotiation */
     340    if (ssl->options.handShakeState == HANDSHAKE_DONE)
    322341        dtls_timeout = 0;
    323342
     
    335354        }
    336355    }
     356#ifndef NO_ASN_TIME
     357    else if(IsSCR(ssl)) {
     358        if (ssl->dtls_start_timeout &&
     359                LowResTimer() - ssl->dtls_start_timeout > (word32)dtls_timeout) {
     360            ssl->dtls_start_timeout = 0;
     361            return WOLFSSL_CBIO_ERR_TIMEOUT;
     362        }
     363        else if (!ssl->dtls_start_timeout) {
     364            ssl->dtls_start_timeout = LowResTimer();
     365        }
     366    }
     367#endif /* !NO_ASN_TIME */
    337368
    338369    recvd = (int)RECVFROM_FUNCTION(sd, buf, sz, ssl->rflags,
     
    342373
    343374    if (recvd < 0) {
    344         err = wolfSSL_LastError();
     375        err = wolfSSL_LastError(recvd);
    345376        WOLFSSL_MSG("Embed Receive From error");
    346377
     
    380411        }
    381412    }
     413#ifndef NO_ASN_TIME
     414    ssl->dtls_start_timeout = 0;
     415#endif /* !NO_ASN_TIME */
    382416
    383417    return recvd;
     
    404438
    405439    if (sent < 0) {
    406         err = wolfSSL_LastError();
     440        err = wolfSSL_LastError(sent);
    407441        WOLFSSL_MSG("Embed Send To error");
    408442
     
    452486
    453487    if (recvd < 0) {
    454         err = wolfSSL_LastError();
     488        err = wolfSSL_LastError(recvd);
    455489        WOLFSSL_MSG("Embed Receive From error");
    456490
     
    636670#endif /* WOLFSSL_SESSION_EXPORT */
    637671#endif /* WOLFSSL_DTLS */
     672
     673#ifdef WOLFSSL_LINUXKM
     674static int linuxkm_send(struct socket *socket, void *buf, int size,
     675    unsigned int flags)
     676{
     677    int ret;
     678    struct kvec vec = { .iov_base = buf, .iov_len = size };
     679    struct msghdr msg = { .msg_flags = flags };
     680    ret = kernel_sendmsg(socket, &msg, &vec, 1, size);
     681    return ret;
     682}
     683
     684static int linuxkm_recv(struct socket *socket, void *buf, int size,
     685    unsigned int flags)
     686{
     687    int ret;
     688    struct kvec vec = { .iov_base = buf, .iov_len = size };
     689    struct msghdr msg = { .msg_flags = flags };
     690    ret = kernel_recvmsg(socket, &msg, &vec, 1, size, msg.msg_flags);
     691    return ret;
     692}
     693#endif /* WOLFSSL_LINUXKM */
    638694
    639695
     
    733789            }
    734790        }
     791
     792        WOLFSSL_MSG("Select error");
    735793        return SOCKET_ERROR_E;
    736794    }
     
    780838#endif
    781839
     840    if (sockfd == NULL || ip == NULL) {
     841        return -1;
     842    }
     843
    782844    XMEMSET(&addr, 0, sizeof(addr));
    783845
     
    822884
    823885    *sockfd = (SOCKET_T)socket(addr.ss_family, SOCK_STREAM, 0);
    824 
    825886#ifdef USE_WINDOWS_API
    826     if (*sockfd == INVALID_SOCKET) {
     887    if (*sockfd == SOCKET_INVALID)
     888#else
     889    if (*sockfd <= SOCKET_INVALID)
     890#endif
     891    {
    827892        WOLFSSL_MSG("bad socket fd, out of fds?");
    828893        return -1;
    829894    }
    830 #else
    831      if (*sockfd < 0) {
    832          WOLFSSL_MSG("bad socket fd, out of fds?");
    833          return -1;
    834      }
    835 #endif
    836895
    837896#ifdef HAVE_IO_TIMEOUT
     
    858917    if (ret != 0) {
    859918        WOLFSSL_MSG("Responder tcp connect failed");
     919        CloseSocket(*sockfd);
     920        *sockfd = SOCKET_INVALID;
    860921        return -1;
    861922    }
     
    10741135            }
    10751136            else {
     1137                result = TranslateReturnCode(result, sfd);
     1138                result = wolfSSL_LastError(result);
     1139                if (result == SOCKET_EWOULDBLOCK || result == SOCKET_EAGAIN) {
     1140                    return OCSP_WANT_READ;
     1141                }
     1142
    10761143                WOLFSSL_MSG("wolfIO_HttpProcessResponse recv http from peer failed");
    10771144                return -1;
     
    13391406                        byte* ocspReqBuf, int ocspReqSz, byte** ocspRespBuf)
    13401407{
    1341     SOCKET_T sfd = 0;
     1408    SOCKET_T sfd = SOCKET_INVALID;
    13421409    word16   port;
    13431410    int      ret = -1;
     
    13861453
    13871454            ret = wolfIO_TcpConnect(&sfd, domainName, port, io_timeout_sec);
    1388             if ((ret != 0) || ((int)sfd < 0)) {
     1455            if (ret != 0) {
    13891456                WOLFSSL_MSG("OCSP Responder connection failed");
    13901457            }
     
    14011468                                                 HTTP_SCRATCH_BUFFER_SIZE, ctx);
    14021469            }
    1403 
    1404             CloseSocket(sfd);
     1470            if (sfd != SOCKET_INVALID)
     1471                CloseSocket(sfd);
    14051472            XFREE(httpBuf, ctx, DYNAMIC_TYPE_OCSP);
    14061473        }
     
    14601527int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url, int urlSz)
    14611528{
    1462     SOCKET_T sfd = 0;
     1529    SOCKET_T sfd = SOCKET_INVALID;
    14631530    word16   port;
    14641531    int      ret = -1;
     
    14921559
    14931560            ret = wolfIO_TcpConnect(&sfd, domainName, port, io_timeout_sec);
    1494             if ((ret != 0) || (sfd < 0)) {
     1561            if (ret != 0) {
    14951562                WOLFSSL_MSG("CRL connection failed");
    14961563            }
     
    15031570                                                      HTTP_SCRATCH_BUFFER_SIZE);
    15041571            }
    1505 
    1506             CloseSocket(sfd);
     1572            if (sfd != SOCKET_INVALID)
     1573                CloseSocket(sfd);
    15071574            XFREE(httpBuf, crl->heap, DYNAMIC_TYPE_CRL);
    15081575        }
     
    20312098
    20322099    XMEMSET(mynewt_ctx, 0, sizeof(Mynewt_Ctx));
    2033     mynewt_ctx->mnMemBuffer = XMALLOC(mempool_bytes, 0, 0);
     2100    mynewt_ctx->mnMemBuffer = (void *)XMALLOC(mempool_bytes, 0, 0);
    20342101    if(!mynewt_ctx->mnMemBuffer) {
    20352102        mynewt_ctx_clear((void*)mynewt_ctx);
     
    20822149    struct os_mbuf *m;
    20832150    int read_sz = 0;
    2084     uint16_t total;
     2151    word16 total;
    20852152
    20862153    if (mynewt_ctx == NULL || mynewt_ctx->mnSocket == NULL) {
     
    23252392    sock_udp_ep_t ep;
    23262393    int ret;
    2327     uint32_t timeout = wolfSSL_dtls_get_current_timeout(ssl) * 1000000;
     2394    word32 timeout = wolfSSL_dtls_get_current_timeout(ssl) * 1000000;
    23282395    sock_tls_t *ctx = (sock_tls_t *)_ctx;
    23292396    if (!ctx)
Note: See TracChangeset for help on using the changeset viewer.