Roll back native LwIP

This commit is contained in:
Takashi Kojo 2014-03-11 10:59:09 +09:00
parent 3e41d8cecb
commit 6463d34fe7
17 changed files with 22 additions and 5488 deletions

View File

@ -1,360 +0,0 @@
/* https-nb.c
*
* Copyright (C) 2006-2014 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <cyassl/ctaocrypt/settings.h>
#if defined(HAVE_LWIP_NATIVE)
#if defined(CYASSL_IAR_ARM)
#include <stdio.h>
#include <string.h>
#endif
#include "lwip/tcp.h"
#include "lwip/sockets.h"
#include <cyassl/ctaocrypt/settings.h>
#include <cyassl/ssl.h>
#include <cyassl/internal.h>
#include <cyassl/ctaocrypt/memory.h>
#include "https-nb.h"
#if 0
/*Enable debug*/
#include <cstdio>
#define DBG0_PRINTF(x, ...) printf("[HTTPSClient : DBG]"x"\r\n", ##__VA_ARGS__);
#else
/*Disable debug*/
#define DBG0_PRINTF(x, ...)
#endif
#if 0
/*Enable debug*/
#include <cstdio>
#define DBG_PRINTF(x, ...) printf("[HTTPSClient : DBG]"x"\r\n", ##__VA_ARGS__);
#define ERR_PRINTF(x, ...) printf("[HTTPSClient:ERROR]"x"\r\n", ##__VA_ARGS__);
#else
/*Disable debug*/
#define DBG_PRINTF(x, ...)
#define ERR_PRINTF(x, ...)
#endif
static int LwIP_cb_mutex = 0 ;
static unsigned long localPort = 0 ;
static unsigned long getPort(void) {
return (localPort++ + 0x200) & 0x7fff ;
}
static err_t TcpConnectedCallback (void *arg, struct tcp_pcb *pcb, s8_t err)
{
DBG_PRINTF("TcpConnectedCallback(arg=%x, pcb=%x, err=%x)\n", arg, pcb, err) ;
*(enum HTTPS_Stat *)arg = TCP_CONNECTED ;
return ERR_OK;
}
static err_t DataReceiveCallback(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
DBG_PRINTF("DataReceiveCallback, pbuf->len=%d, err=%d\n", p->tot_len , err) ;
if(*(enum HTTPS_Stat *)(arg) == WAITING) {
*(enum HTTPS_Stat *)(arg) = HTTP_RECEIVE ;
return ERR_OK ;
} else return !ERR_OK ;
}
static int count = 0 ;
void CyaSSL_HTTPS_Client_NB_init(void *nb,
struct ip_addr svIP, unsigned long svPort, char *host, char *path)
{
CYASSL_HTTPS_NB *https_nb ;
https_nb = (CYASSL_HTTPS_NB *)nb ;
https_nb->serverIP_em = svIP ;
https_nb->serverPort = svPort ;
https_nb->hostname = host ;
https_nb->path = path ;
https_nb->stat = BEGIN ;
}
int CyaSSL_HTTPS_Client_NB(void *nb)
{
int ret ;
CYASSL_HTTPS_NB *https_nb ;
https_nb = (CYASSL_HTTPS_NB *)nb ;
CyaSSL_Debugging_ON() ;
switch(https_nb->stat) {
case BEGIN:
printf("== HTTPS Client(%x): %d ==\n", nb, count ++) ;
/*** Assuming LwIP has been initialized ***/
https_nb->stat = INITIALIZED ;
case INITIALIZED:
https_nb->pcb = tcp_new();
if(https_nb->pcb) {
tcp_arg(https_nb->pcb, (void *)&(https_nb->stat)) ;
DBG_PRINTF("New PCB(tcp_new=%x), &https->stat=%x\n",
https_nb->pcb, &https_nb->stat) ;
} else {
ERR_PRINTF("tcp_new, ret=%d\n", https_nb->pcb) ;
https_nb->stat = IDLE ;
return !ERR_OK ;
}
tcp_arg(https_nb->pcb, (void *)&https_nb->stat) ;
https_nb->localPort = getPort() ;
DBG_PRINTF("local Port=%d\n", https_nb->localPort) ;
ret = tcp_bind (https_nb->pcb, &(https_nb->localIP_em),
https_nb->localPort) ;
if(ret == ERR_OK) {
https_nb->stat = TCP_CONNECT ;
return ERR_OK;
} else {
ERR_PRINTF("tcp_bind, ret=%d\n", ret) ;
https_nb->stat = INITIALIZED ;
return !ERR_OK ;
}
case TCP_CONNECT:
if(LwIP_cb_mutex)return ERR_OK ;
else LwIP_cb_mutex = 1 ;
DBG_PRINTF("TCP_CONNECT(%x)\n", https_nb) ;
DBG_PRINTF("Server IP Addrress(%d.%d.%d.%d)\n",
(*(unsigned long *)&https_nb->serverIP_em&0xff),
(*(unsigned long *)&https_nb->serverIP_em>>8)&0xff,
(*(unsigned long *)&https_nb->serverIP_em>>16)&0xff,
(*(unsigned long *)&https_nb->serverIP_em>>24)&0xff) ;
ret = tcp_connect(https_nb->pcb, &(https_nb->serverIP_em),
https_nb->serverPort, TcpConnectedCallback);
if(ret == ERR_OK) {
https_nb->wait_cnt = 0 ;
https_nb->stat = WAITING ;
return ERR_OK;
} else {
ERR_PRINTF("tcp_connect, ret=%d\n", ret) ;
https_nb->stat = TCP_CLOSE ;
return !ERR_OK;
}
case TCP_CONNECTED:
DBG0_PRINTF("TCP CONNECTED(%x)\n", https_nb) ;
LwIP_cb_mutex = 0 ;
/*CyaSSLv3_client_method()
CyaTLSv1_client_method()
CyaTLSv1_1_client_method()
CyaTLSv1_2_client_method() */
https_nb->ctx = CyaSSL_CTX_new(CyaTLSv1_2_client_method());
if (https_nb->ctx == NULL) {
ERR_PRINTF("CyaSSL_CTX_new: unable to get ctx");
return !ERR_OK ;
}
CyaSSL_CTX_set_verify(https_nb->ctx, SSL_VERIFY_NONE, 0);
https_nb->ssl = CyaSSL_new(https_nb->ctx);
if (https_nb->ssl == NULL) {
ERR_PRINTF("CyaSSL_new: unable to get SSL object");
return !ERR_OK ;
}
CyaSSL_SetIO_LwIP(https_nb->ssl, https_nb->pcb,
DataReceiveCallback, NULL, (void *)&https_nb->stat);
https_nb->stat = SSL_CONN ;
case SSL_CONN: /* handshaking */
if(LwIP_cb_mutex) return ERR_OK ;
ret = CyaSSL_connect(https_nb->ssl);
DBG_PRINTF("CyaSSL_connect, ret = %d\n", ret) ;
if(ret == SSL_SUCCESS) {
DBG_PRINTF("SSL Connected\n") ;
https_nb->stat = HTTP_SEND ;
} else {
ret = CyaSSL_get_error(https_nb->ssl, NULL) ;
if(ret == SSL_ERROR_WANT_READ) {
https_nb->ssl->lwipCtx.wait = 1000000 ;
https_nb->stat = SSL_CONN_WAITING ;
return ERR_OK ;
} else {
ERR_PRINTF("CyaSSL_connecting_NB:ssl=%x, ret=%d\n", https_nb->ssl, ret) ;
return !ERR_OK ;
}
}
return ERR_OK ;
case SSL_CONN_WAITING:
if(https_nb->ssl->lwipCtx.wait-- <= 0) {
/* counting down after the callback for multiple callbacks */
https_nb->stat = SSL_CONN ;
LwIP_cb_mutex = 0 ;
}
return ERR_OK ;
case HTTP_SEND:
{
#define SEND_BUFF_SIZE 100
char sendBuff[SEND_BUFF_SIZE] ;
int size ;
if(LwIP_cb_mutex)return ERR_OK ;
else LwIP_cb_mutex = 1 ; /* lock */
DBG0_PRINTF("SSL CONNECTED(%x)\n", https_nb) ;
sprintf(sendBuff,
"GET %s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n",
https_nb->path, https_nb->hostname) ;
size = strlen((char const *)sendBuff) ;
CyaSSL_write(https_nb->ssl, sendBuff, size) ;
https_nb->wait_cnt = 0 ;
https_nb->stat = WAITING ;
return ERR_OK;
}
case HTTP_RECEIVE:
{
#define HTTP_BUFF_SIZE 2048
char httpbuff[HTTP_BUFF_SIZE] ;
LwIP_cb_mutex = 0 ;
memset(httpbuff, '\0', HTTP_BUFF_SIZE) ;
ret = CyaSSL_read(https_nb->ssl, httpbuff, HTTP_BUFF_SIZE) ;
DBG0_PRINTF("HTTPS GET(%x), Received(%d)\n",https_nb, strlen(httpbuff)) ;
/*DBG0_PRINTF*/puts(httpbuff) ;
}
case SSL_CLOSE:
{
CYASSL_CTX *ctx ; ;
ctx = https_nb->ssl->ctx ;
DBG_PRINTF("CyaSSL_close(%x)", https_nb->ssl) ;
CyaSSL_shutdown(https_nb->ssl);
CyaSSL_free(https_nb->ssl);
CyaSSL_CTX_free(ctx); ;
https_nb->stat = TCP_CLOSE ;
}
case TCP_CLOSE:
tcp_close(https_nb->pcb) ;
https_nb->idle = 0 ;
https_nb->stat = IDLE ;
case IDLE:
https_nb->idle ++ ;
if(https_nb->idle > 50000)
https_nb->stat = BEGIN ;
return ERR_OK;
case WAITING:
if(https_nb->wait_cnt++ > 1000000) {
LwIP_cb_mutex = 0 ;
https_nb->wait_cnt = 0 ;
if((https_nb->stat >= SSL_CONN)&&(https_nb->stat < SSL_CLOSE)) {
ERR_PRINTF("Wait Time out, go to CyaSSL close") ;
https_nb->stat = SSL_CLOSE ;
} else {
ERR_PRINTF("Wait Time out, go to Begin") ;
https_nb->stat = TCP_CLOSE ;
}
}
return ERR_OK ;
default:
return ERR_OK;
}
}
/*********************************************************************/
/*
Usage Example:
CyaSSL_HTTPS_Client_NB_init
CyaSSL_HTTPS_Client_NB
*/
/*********************************************************************/
#ifndef NO_MAIN_DRIVER
CYASSL_HTTPS_NB CyaSSL_HTTPS_Client_1 ;
void *CyaSSL_HTTPS_ClientP_1 = (void *)&CyaSSL_HTTPS_Client_1 ;
CYASSL_HTTPS_NB CyaSSL_HTTPS_Client_2 ;
void *CyaSSL_HTTPS_ClientP_2 = (void *)&CyaSSL_HTTPS_Client_2 ;
CYASSL_HTTPS_NB CyaSSL_HTTPS_Client_3 ;
void *CyaSSL_HTTPS_ClientP_3 = (void *)&CyaSSL_HTTPS_Client_3 ;
CYASSL_HTTPS_NB CyaSSL_HTTPS_Client_4 ;
void *CyaSSL_HTTPS_ClientP_4 = (void *)&CyaSSL_HTTPS_Client_4 ;
CYASSL_HTTPS_NB CyaSSL_HTTPS_Client_5 ;
void *CyaSSL_HTTPS_ClientP_5 = (void *)&CyaSSL_HTTPS_Client_5 ;
#define HTTPS_PORT 443
#define IP_ADDR(a,b,c,d) (((a)|((b)<<8)|((c)<<16)|(d)<<24))
static struct ip_addr server0_em = { IP_ADDR(192,168,11,9) } ;
static struct ip_addr server1_em = { IP_ADDR(31,13,68,33)} ;
void HTTPSClient_main_init() {
CyaSSL_HTTPS_Client_NB_init(CyaSSL_HTTPS_ClientP_1,
//server_em, HTTPS_PORT, "xxx.com", "/") ;
server1_em, HTTPS_PORT, "graph.facebook.com", "/takashikojo") ;
CyaSSL_HTTPS_Client_NB_init(CyaSSL_HTTPS_ClientP_2,
server0_em, HTTPS_PORT, "xxx.com", "/") ;
CyaSSL_HTTPS_Client_NB_init(CyaSSL_HTTPS_ClientP_3,
server1_em, HTTPS_PORT, "graph.facebook.com", "/takashikojo") ;
//server_em, HTTPS_PORT, "xxx.com", "/") ;
CyaSSL_HTTPS_Client_NB_init(CyaSSL_HTTPS_ClientP_4,
server0_em, HTTPS_PORT, "xxx.com", "/") ;
CyaSSL_HTTPS_Client_NB_init(CyaSSL_HTTPS_ClientP_5,
server0_em, HTTPS_PORT, "xxx.com", "/") ;
}
void HTTPSClient_main(int i)
{
if((i % 1) == 0) { /* wait for initializing TCP/IP, DHCP */
CyaSSL_HTTPS_Client_NB(CyaSSL_HTTPS_ClientP_1) ;
}
if((i % 2) == 0) { /* wait for initializing TCP/IP, DHCP */
CyaSSL_HTTPS_Client_NB(CyaSSL_HTTPS_ClientP_2) ;
}
#if 0
if((i % 3) == 0) { /* wait for initializing TCP/IP, DHCP */
CyaSSL_HTTPS_Client_NB(CyaSSL_HTTPS_ClientP_3) ;
}
if((i % 4) == 0) { /* wait for initializing TCP/IP, DHCP */
CyaSSL_HTTPS_Client_NB(CyaSSL_HTTPS_ClientP_4) ;
}
if((i % 5) == 0) { /* wait for initializing TCP/IP, DHCP */
CyaSSL_HTTPS_Client_NB(CyaSSL_HTTPS_ClientP_5) ;
}
#endif
}
#endif /* NO_MAIN_DRIVER */
#endif /* HAVE_LWIP_NATIVE */

View File

@ -1,76 +0,0 @@
/* HTTPS-NB.h
*
* Copyright (C) 2006-2014 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifndef HTTPS_NB_H
#define HTTPS_NB_H
extern int CyaSSL_GetDataFromPbuf(char *buff, struct pbuf *p, int size) ;
#define IP4_LONG_2_ADDR(ipaddr, iplong) \
(ipaddr)->addr = htonl(((u32_t)(iplong) & 0xFF000000) | \
((u32_t)(iplong) & 0xFF0000) | \
((u32_t)(iplong) & 0xFF00) | \
(u32_t)(iplong) & 0xFF)
#define IP_ADDR(a,b,c,d) (((a)|((b)<<8)|((c)<<16)|(d)<<24))
enum HTTPS_Stat {
BEGIN,
GET_MYIP,
INITIALIZED,
TCP_CONNECT,
TCP_CONNECTED,
SSL_INIT,
SSL_CONN,
SSL_CONN_WAITING,
HTTP_SEND,
HTTP_RECEIVE,
HTTP_DONE,
SSL_CLOSE,
TCP_CLOSE,
WAITING,
IDLE
} ;
#define HTTPS_PORT 443
typedef struct {
CYASSL *ssl ;
CYASSL_CTX *ctx ;
enum HTTPS_Stat stat ;
struct tcp_pcb * pcb ;
unsigned long ipaddress ;
struct ip_addr localIP_em;
unsigned long localPort ;
struct ip_addr serverIP_em ;
unsigned long serverPort ;
char *hostname ;
char *path ;
int idle ;
int wait_cnt ; /* wait tick counter */
} CYASSL_HTTPS_NB ;
extern void CyaSSL_HTTPS_Client_NB_init(void *nb,
struct ip_addr svIP, unsigned long svPort, char *host, char *path) ;
extern int CyaSSL_HTTPS_Client_NB(void *nb) ;
#endif

View File

@ -1,360 +0,0 @@
/* https-nb.c
*
* Copyright (C) 2006-2014 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <cyassl/ctaocrypt/settings.h>
#if defined(HAVE_LWIP_NATIVE)
#if defined(CYASSL_IAR_ARM)
#include <stdio.h>
#include <string.h>
#endif
#include "lwip/tcp.h"
#include "lwip/sockets.h"
#include <cyassl/ctaocrypt/settings.h>
#include <cyassl/ssl.h>
#include <cyassl/internal.h>
#include <cyassl/ctaocrypt/memory.h>
#include "https-nb.h"
#if 0
/*Enable debug*/
#include <cstdio>
#define DBG0_PRINTF(x, ...) printf("[HTTPSClient : DBG]"x"\r\n", ##__VA_ARGS__);
#else
/*Disable debug*/
#define DBG0_PRINTF(x, ...)
#endif
#if 0
/*Enable debug*/
#include <cstdio>
#define DBG_PRINTF(x, ...) printf("[HTTPSClient : DBG]"x"\r\n", ##__VA_ARGS__);
#define ERR_PRINTF(x, ...) printf("[HTTPSClient:ERROR]"x"\r\n", ##__VA_ARGS__);
#else
/*Disable debug*/
#define DBG_PRINTF(x, ...)
#define ERR_PRINTF(x, ...)
#endif
static int LwIP_cb_mutex = 0 ;
static unsigned long localPort = 0 ;
static unsigned long getPort(void) {
return (localPort++ + 0x200) & 0x7fff ;
}
static err_t TcpConnectedCallback (void *arg, struct tcp_pcb *pcb, s8_t err)
{
DBG_PRINTF("TcpConnectedCallback(arg=%x, pcb=%x, err=%x)\n", arg, pcb, err) ;
*(enum HTTPS_Stat *)arg = TCP_CONNECTED ;
return ERR_OK;
}
static err_t DataReceiveCallback(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
DBG_PRINTF("DataReceiveCallback, pbuf->len=%d, err=%d\n", p->tot_len , err) ;
if(*(enum HTTPS_Stat *)(arg) == WAITING) {
*(enum HTTPS_Stat *)(arg) = HTTP_RECEIVE ;
return ERR_OK ;
} else return !ERR_OK ;
}
static int count = 0 ;
void CyaSSL_HTTPS_Client_NB_init(void *nb,
struct ip_addr svIP, unsigned long svPort, char *host, char *path)
{
CYASSL_HTTPS_NB *https_nb ;
https_nb = (CYASSL_HTTPS_NB *)nb ;
https_nb->serverIP_em = svIP ;
https_nb->serverPort = svPort ;
https_nb->hostname = host ;
https_nb->path = path ;
https_nb->stat = BEGIN ;
}
int CyaSSL_HTTPS_Client_NB(void *nb)
{
int ret ;
CYASSL_HTTPS_NB *https_nb ;
https_nb = (CYASSL_HTTPS_NB *)nb ;
CyaSSL_Debugging_ON() ;
switch(https_nb->stat) {
case BEGIN:
printf("== HTTPS Client(%x): %d ==\n", nb, count ++) ;
/*** Assuming LwIP has been initialized ***/
https_nb->stat = INITIALIZED ;
case INITIALIZED:
https_nb->pcb = tcp_new();
if(https_nb->pcb) {
tcp_arg(https_nb->pcb, (void *)&(https_nb->stat)) ;
DBG_PRINTF("New PCB(tcp_new=%x), &https->stat=%x\n",
https_nb->pcb, &https_nb->stat) ;
} else {
ERR_PRINTF("tcp_new, ret=%d\n", https_nb->pcb) ;
https_nb->stat = IDLE ;
return !ERR_OK ;
}
tcp_arg(https_nb->pcb, (void *)&https_nb->stat) ;
https_nb->localPort = getPort() ;
DBG_PRINTF("local Port=%d\n", https_nb->localPort) ;
ret = tcp_bind (https_nb->pcb, &(https_nb->localIP_em),
https_nb->localPort) ;
if(ret == ERR_OK) {
https_nb->stat = TCP_CONNECT ;
return ERR_OK;
} else {
ERR_PRINTF("tcp_bind, ret=%d\n", ret) ;
https_nb->stat = INITIALIZED ;
return !ERR_OK ;
}
case TCP_CONNECT:
if(LwIP_cb_mutex)return ERR_OK ;
else LwIP_cb_mutex = 1 ;
DBG_PRINTF("TCP_CONNECT(%x)\n", https_nb) ;
DBG_PRINTF("Server IP Addrress(%d.%d.%d.%d)\n",
(*(unsigned long *)&https_nb->serverIP_em&0xff),
(*(unsigned long *)&https_nb->serverIP_em>>8)&0xff,
(*(unsigned long *)&https_nb->serverIP_em>>16)&0xff,
(*(unsigned long *)&https_nb->serverIP_em>>24)&0xff) ;
ret = tcp_connect(https_nb->pcb, &(https_nb->serverIP_em),
https_nb->serverPort, TcpConnectedCallback);
if(ret == ERR_OK) {
https_nb->wait_cnt = 0 ;
https_nb->stat = WAITING ;
return ERR_OK;
} else {
ERR_PRINTF("tcp_connect, ret=%d\n", ret) ;
https_nb->stat = TCP_CLOSE ;
return !ERR_OK;
}
case TCP_CONNECTED:
DBG0_PRINTF("TCP CONNECTED(%x)\n", https_nb) ;
LwIP_cb_mutex = 0 ;
/*CyaSSLv3_client_method()
CyaTLSv1_client_method()
CyaTLSv1_1_client_method()
CyaTLSv1_2_client_method() */
https_nb->ctx = CyaSSL_CTX_new(CyaTLSv1_2_client_method());
if (https_nb->ctx == NULL) {
ERR_PRINTF("CyaSSL_CTX_new: unable to get ctx");
return !ERR_OK ;
}
CyaSSL_CTX_set_verify(https_nb->ctx, SSL_VERIFY_NONE, 0);
https_nb->ssl = CyaSSL_new(https_nb->ctx);
if (https_nb->ssl == NULL) {
ERR_PRINTF("CyaSSL_new: unable to get SSL object");
return !ERR_OK ;
}
CyaSSL_SetIO_LwIP(https_nb->ssl, https_nb->pcb,
DataReceiveCallback, NULL, (void *)&https_nb->stat);
https_nb->stat = SSL_CONN ;
case SSL_CONN: /* handshaking */
if(LwIP_cb_mutex) return ERR_OK ;
ret = CyaSSL_connect(https_nb->ssl);
DBG_PRINTF("CyaSSL_connect, ret = %d\n", ret) ;
if(ret == SSL_SUCCESS) {
DBG_PRINTF("SSL Connected\n") ;
https_nb->stat = HTTP_SEND ;
} else {
ret = CyaSSL_get_error(https_nb->ssl, NULL) ;
if(ret == SSL_ERROR_WANT_READ) {
https_nb->ssl->lwipCtx.wait = 1000000 ;
https_nb->stat = SSL_CONN_WAITING ;
return ERR_OK ;
} else {
ERR_PRINTF("CyaSSL_connecting_NB:ssl=%x, ret=%d\n", https_nb->ssl, ret) ;
return !ERR_OK ;
}
}
return ERR_OK ;
case SSL_CONN_WAITING:
if(https_nb->ssl->lwipCtx.wait-- <= 0) {
/* counting down after the callback for multiple callbacks */
https_nb->stat = SSL_CONN ;
LwIP_cb_mutex = 0 ;
}
return ERR_OK ;
case HTTP_SEND:
{
#define SEND_BUFF_SIZE 100
char sendBuff[SEND_BUFF_SIZE] ;
int size ;
if(LwIP_cb_mutex)return ERR_OK ;
else LwIP_cb_mutex = 1 ; /* lock */
DBG0_PRINTF("SSL CONNECTED(%x)\n", https_nb) ;
sprintf(sendBuff,
"GET %s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n",
https_nb->path, https_nb->hostname) ;
size = strlen((char const *)sendBuff) ;
CyaSSL_write(https_nb->ssl, sendBuff, size) ;
https_nb->wait_cnt = 0 ;
https_nb->stat = WAITING ;
return ERR_OK;
}
case HTTP_RECEIVE:
{
#define HTTP_BUFF_SIZE 2048
char httpbuff[HTTP_BUFF_SIZE] ;
LwIP_cb_mutex = 0 ;
memset(httpbuff, '\0', HTTP_BUFF_SIZE) ;
ret = CyaSSL_read(https_nb->ssl, httpbuff, HTTP_BUFF_SIZE) ;
DBG0_PRINTF("HTTPS GET(%x), Received(%d)\n",https_nb, strlen(httpbuff)) ;
/*DBG0_PRINTF*/puts(httpbuff) ;
}
case SSL_CLOSE:
{
CYASSL_CTX *ctx ; ;
ctx = https_nb->ssl->ctx ;
DBG_PRINTF("CyaSSL_close(%x)", https_nb->ssl) ;
CyaSSL_shutdown(https_nb->ssl);
CyaSSL_free(https_nb->ssl);
CyaSSL_CTX_free(ctx); ;
https_nb->stat = TCP_CLOSE ;
}
case TCP_CLOSE:
tcp_close(https_nb->pcb) ;
https_nb->idle = 0 ;
https_nb->stat = IDLE ;
case IDLE:
https_nb->idle ++ ;
if(https_nb->idle > 50000)
https_nb->stat = BEGIN ;
return ERR_OK;
case WAITING:
if(https_nb->wait_cnt++ > 1000000) {
LwIP_cb_mutex = 0 ;
https_nb->wait_cnt = 0 ;
if((https_nb->stat >= SSL_CONN)&&(https_nb->stat < SSL_CLOSE)) {
ERR_PRINTF("Wait Time out, go to CyaSSL close") ;
https_nb->stat = SSL_CLOSE ;
} else {
ERR_PRINTF("Wait Time out, go to Begin") ;
https_nb->stat = TCP_CLOSE ;
}
}
return ERR_OK ;
default:
return ERR_OK;
}
}
/*********************************************************************/
/*
Usage Example:
CyaSSL_HTTPS_Client_NB_init
CyaSSL_HTTPS_Client_NB
*/
/*********************************************************************/
#ifndef NO_MAIN_DRIVER
CYASSL_HTTPS_NB CyaSSL_HTTPS_Client_1 ;
void *CyaSSL_HTTPS_ClientP_1 = (void *)&CyaSSL_HTTPS_Client_1 ;
CYASSL_HTTPS_NB CyaSSL_HTTPS_Client_2 ;
void *CyaSSL_HTTPS_ClientP_2 = (void *)&CyaSSL_HTTPS_Client_2 ;
CYASSL_HTTPS_NB CyaSSL_HTTPS_Client_3 ;
void *CyaSSL_HTTPS_ClientP_3 = (void *)&CyaSSL_HTTPS_Client_3 ;
CYASSL_HTTPS_NB CyaSSL_HTTPS_Client_4 ;
void *CyaSSL_HTTPS_ClientP_4 = (void *)&CyaSSL_HTTPS_Client_4 ;
CYASSL_HTTPS_NB CyaSSL_HTTPS_Client_5 ;
void *CyaSSL_HTTPS_ClientP_5 = (void *)&CyaSSL_HTTPS_Client_5 ;
#define HTTPS_PORT 443
#define IP_ADDR(a,b,c,d) (((a)|((b)<<8)|((c)<<16)|(d)<<24))
static struct ip_addr server0_em = { IP_ADDR(192,168,11,9) } ;
static struct ip_addr server1_em = { IP_ADDR(31,13,68,33)} ;
void HTTPSClient_main_init() {
CyaSSL_HTTPS_Client_NB_init(CyaSSL_HTTPS_ClientP_1,
//server_em, HTTPS_PORT, "xxx.com", "/") ;
server1_em, HTTPS_PORT, "graph.facebook.com", "/takashikojo") ;
CyaSSL_HTTPS_Client_NB_init(CyaSSL_HTTPS_ClientP_2,
server0_em, HTTPS_PORT, "xxx.com", "/") ;
CyaSSL_HTTPS_Client_NB_init(CyaSSL_HTTPS_ClientP_3,
server1_em, HTTPS_PORT, "graph.facebook.com", "/takashikojo") ;
//server_em, HTTPS_PORT, "xxx.com", "/") ;
CyaSSL_HTTPS_Client_NB_init(CyaSSL_HTTPS_ClientP_4,
server0_em, HTTPS_PORT, "xxx.com", "/") ;
CyaSSL_HTTPS_Client_NB_init(CyaSSL_HTTPS_ClientP_5,
server0_em, HTTPS_PORT, "xxx.com", "/") ;
}
void HTTPSClient_main(int i)
{
if((i % 1) == 0) { /* wait for initializing TCP/IP, DHCP */
CyaSSL_HTTPS_Client_NB(CyaSSL_HTTPS_ClientP_1) ;
}
if((i % 2) == 0) { /* wait for initializing TCP/IP, DHCP */
CyaSSL_HTTPS_Client_NB(CyaSSL_HTTPS_ClientP_2) ;
}
#if 0
if((i % 3) == 0) { /* wait for initializing TCP/IP, DHCP */
CyaSSL_HTTPS_Client_NB(CyaSSL_HTTPS_ClientP_3) ;
}
if((i % 4) == 0) { /* wait for initializing TCP/IP, DHCP */
CyaSSL_HTTPS_Client_NB(CyaSSL_HTTPS_ClientP_4) ;
}
if((i % 5) == 0) { /* wait for initializing TCP/IP, DHCP */
CyaSSL_HTTPS_Client_NB(CyaSSL_HTTPS_ClientP_5) ;
}
#endif
}
#endif /* NO_MAIN_DRIVER */
#endif /* HAVE_LWIP_NATIVE */

View File

@ -1,76 +0,0 @@
/* HTTPS-NB.h
*
* Copyright (C) 2006-2014 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifndef HTTPS_NB_H
#define HTTPS_NB_H
extern int CyaSSL_GetDataFromPbuf(char *buff, struct pbuf *p, int size) ;
#define IP4_LONG_2_ADDR(ipaddr, iplong) \
(ipaddr)->addr = htonl(((u32_t)(iplong) & 0xFF000000) | \
((u32_t)(iplong) & 0xFF0000) | \
((u32_t)(iplong) & 0xFF00) | \
(u32_t)(iplong) & 0xFF)
#define IP_ADDR(a,b,c,d) (((a)|((b)<<8)|((c)<<16)|(d)<<24))
enum HTTPS_Stat {
BEGIN,
GET_MYIP,
INITIALIZED,
TCP_CONNECT,
TCP_CONNECTED,
SSL_INIT,
SSL_CONN,
SSL_CONN_WAITING,
HTTP_SEND,
HTTP_RECEIVE,
HTTP_DONE,
SSL_CLOSE,
TCP_CLOSE,
WAITING,
IDLE
} ;
#define HTTPS_PORT 443
typedef struct {
CYASSL *ssl ;
CYASSL_CTX *ctx ;
enum HTTPS_Stat stat ;
struct tcp_pcb * pcb ;
unsigned long ipaddress ;
struct ip_addr localIP_em;
unsigned long localPort ;
struct ip_addr serverIP_em ;
unsigned long serverPort ;
char *hostname ;
char *path ;
int idle ;
int wait_cnt ; /* wait tick counter */
} CYASSL_HTTPS_NB ;
extern void CyaSSL_HTTPS_Client_NB_init(void *nb,
struct ip_addr svIP, unsigned long svPort, char *host, char *path) ;
extern int CyaSSL_HTTPS_Client_NB(void *nb) ;
#endif

View File

@ -1,166 +0,0 @@
/* tcp-conn-nb.c
*
* Copyright (C) 2006-2014 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <cyassl/ctaocrypt/settings.h>
/*** Simulating tcp_connect by LwIP Native TCP ***/
#if defined(HAVE_LWIP_NATIVE)
#include <cyassl/ctaocrypt/types.h>
#include <string.h>
#include "lwip/tcp.h"
#include "lwip/sockets.h"
#include "lwip/inet.h"
#include "lwip/ip_addr.h"
#include "cyassl/ssl.h"
#include "tcp-conn-nb.h"
int myoptind;
char* myoptarg;
static struct tcp_cb {
enum TCP_stat stat ;
struct tcp_pcb *pcb ;
unsigned long localPort;
ip_addr_t localIP_em ;
unsigned long serverPort ;
ip_addr_t serverIP_em ;
} tcp ;
#define LOCAL_PORT 11111
#if 0
/*Enable debug*/
#include <cstdio>
#define DBG_PRINTF(x, ...) printf("[HTTPSClient : DBG]"x"\r\n", ##__VA_ARGS__);
#define ERR_PRINTF(x, ...) printf("[HTTPSClient:ERROR]"x"\r\n", ##__VA_ARGS__);
#else
/*Disable debug*/
#define DBG_PRINTF(x, ...)
#define ERR_PRINTF(x, ...)
#endif
static err_t TcpConnectedCallback (void *arg, struct tcp_pcb *pcb, s8_t err)
{
DBG_PRINTF("TcpConnectedCallback(arg=%x, pcb=%x, err=%x)\n", arg, pcb, err) ;
*(int *)arg = TCP_CONNECTED ;
return ERR_OK;
}
/** strictly IPV4 ***/
#define IP_ADDR(a,b,c,d) (((a)|((b)<<8)|((c)<<16)|(d)<<24))
ip_addr_t ip_addr_s2i(const char *ip_s) {
unsigned int ip[4] ;
ip_addr_t ip_addr ;
sscanf(ip_s, "%d.%d.%d.%d",
&(ip[0]), &(ip[1]), &(ip[2]), &(ip[3])) ;
ip_addr.addr = IP_ADDR(ip[0], ip[1], ip[2], ip[3]) ;
return ip_addr ;
}
/** Placeholders for now **/
void tcp_socket(SOCKET_T *s, int flag) { }
void build_addr(int *addr, char *host, int port, int mode) { }
void tcp_CloseSocket_nb(SOCKET_T *sockfd) { }
void tcp_select(SOCKET_T *s, int flag) { }
unsigned long current_time(void) { return 0 ; }
int tcp_connect_nb(struct tcp_pcb **pcb, const char* ip, word16 port,
int udp)
{
int ret ;
switch(tcp.stat) {
case TCP_BEGIN:
tcp.pcb = tcp_new();
if(tcp.pcb) {
tcp_arg(tcp.pcb, (void *)&(tcp.stat)) ;
DBG_PRINTF("New PCB(tcp_new=%x), &https->stat=%x\n",
tcp.pcb, &tcp.stat) ;
} else {
ERR_PRINTF("tcp_new, ret=%d\n", tcp.pcb) ;
tcp.stat = TCP_IDLE ;
return TCP_ERROR ;
}
*pcb = tcp.pcb ;
tcp_arg(tcp.pcb, (void *)&tcp.stat) ;
tcp.localPort = LOCAL_PORT ;
DBG_PRINTF("local Port=%d\n", tcp.localPort) ;
ret = tcp_bind (tcp.pcb, &(tcp.localIP_em),
tcp.localPort) ;
if(ret == ERR_OK) {
tcp.stat = TCP_CONNECTING ;
return TCP_CONNECTING ;
} else {
ERR_PRINTF("tcp_bind, ret=%d\n", ret) ;
tcp.stat = TCP_CLOSE ;
return TCP_CONNECTING ;
}
case TCP_CONNECTING:
tcp.serverPort = port ;
tcp.serverIP_em = ip_addr_s2i(ip) ;
DBG_PRINTF("TCP_CONNECT(%x)\n", tcp.pcb) ;
ret = tcp_connect(tcp.pcb, &(tcp.serverIP_em),
tcp.serverPort, TcpConnectedCallback);
if(ret == ERR_OK) {
tcp.stat = TCP_WAITING ;
return TCP_CONNECTING ;
} else {
ERR_PRINTF("tcp_connect, ret=%d\n", ret) ;
tcp.stat = TCP_CLOSE ;
return TCP_ERROR ;
}
case TCP_WAITING:
return TCP_CONNECTING ;
case TCP_CONNECTED:
*pcb = tcp.pcb ;
return TCP_CONNECTED ;
case TCP_CLOSE:
tcp_close(tcp.pcb) ;
tcp.stat = TCP_IDLE ;
return TCP_CONNECTING ;
case TCP_IDLE:
default:
return TCP_CONNECTING ;
}
}
#endif

View File

@ -1,202 +0,0 @@
/* tcp-conn-nb.h
*
* Copyright (C) 2006-2014 wolfSSL Inc.
*
* This file is part of CyaSSL.
*
* CyaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CyaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifndef TCP_CONN_NB_H
#define TCP_CONN_NB_H
/* Options for LwIP native socket client example */
#define NO_MAIN_DRIVER
#define NO_SESSION_CACHE
#define NO_PSK
#define NO_BENCHMARK
#undef USE_CYASSL_MEMORY
/******/
#include <cyassl/ctaocrypt/types.h>
#include <string.h>
#include "lwip/tcp.h"
#include "lwip/sockets.h"
#include "lwip/inet.h"
#include "lwip/ip_addr.h"
#define THREAD_RETURN int
#define CYASSL_THREAD
#define SOCKET_T struct tcp_pcb *
#define SOCKADDR_IN_T int
//#define ip_addr_t char *
#define err_sys(msg) puts(msg)
#define exit(code) return(code) ;
enum TCP_stat {
TCP_BEGIN,
TCP_CONNECTING, /* return code */
TCP_CONNECTED, /* return code */
TCP_WAITING,
TCP_CLOSE,
TCP_IDLE,
TCP_ERROR,
} ;
/*** from test.h ***/
#define CYASSL_MAX_ERROR_SZ 128
#define CLIENT_DEFAULT_VERSION 3
#define CLIENT_DTLS_DEFAULT_VERSION (-2)
#define CLIENT_INVALID_VERSION (-99)
static const char* const yasslIP = "127.0.0.1";
static const word16 yasslPort = 11111;
#define caCert "./certs/ca-cert.pem"
#define cliCert "./certs/client-cert.pem"
#define cliKey "./certs/client-key.pem"
#define MY_EX_USAGE 2
#define StackTrap(a)
#define InitMemoryTracker(a)
typedef struct func_args {
int argc;
char** argv;
int return_code;
} func_args;
extern int myoptind;
extern char* myoptarg;
void build_addr(int *addr, char *host, int port, int mode) ;
void tcp_socket(SOCKET_T *s, int flag) ;
enum {
TEST_SELECT_FAIL,
TEST_TIMEOUT,
TEST_RECV_READY,
TEST_ERROR_READY
};
static INLINE void tcp_set_nonblocking(SOCKET_T* sockfd){ }
static INLINE int mygetopt(int argc, char** argv, const char* optstring)
{
static char* next = NULL;
char c;
char* cp;
if (myoptind == 0)
next = NULL; /* we're starting new/over */
if (next == NULL || *next == '\0') {
if (myoptind == 0)
myoptind++;
if (myoptind >= argc || argv[myoptind][0] != '-' ||
argv[myoptind][1] == '\0') {
myoptarg = NULL;
if (myoptind < argc)
myoptarg = argv[myoptind];
return -1;
}
if (strcmp(argv[myoptind], "--") == 0) {
myoptind++;
myoptarg = NULL;
if (myoptind < argc)
myoptarg = argv[myoptind];
return -1;
}
next = argv[myoptind];
next++; /* skip - */
myoptind++;
}
c = *next++;
/* The C++ strchr can return a different value */
cp = (char*)strchr(optstring, c);
if (cp == NULL || c == ':')
return '?';
cp++;
if (*cp == ':') {
if (*next != '\0') {
myoptarg = next;
next = NULL;
}
else if (myoptind < argc) {
myoptarg = argv[myoptind];
myoptind++;
}
else
return '?';
}
return c;
}
static INLINE void showPeer(CYASSL* ssl)
{
CYASSL_CIPHER* cipher;
#ifdef KEEP_PEER_CERT
CYASSL_X509* peer = CyaSSL_get_peer_certificate(ssl);
if (peer)
ShowX509(peer, "peer's cert info:");
else
printf("peer has no cert!\n");
#endif
printf("SSL version is %s\n", CyaSSL_get_version(ssl));
cipher = CyaSSL_get_current_cipher(ssl);
printf("SSL cipher suite is %s\n", CyaSSL_CIPHER_get_name(cipher));
#if defined(SESSION_CERTS) && defined(SHOW_CERTS)
{
CYASSL_X509_CHAIN* chain = CyaSSL_get_peer_chain(ssl);
int count = CyaSSL_get_chain_count(chain);
int i;
for (i = 0; i < count; i++) {
int length;
unsigned char buffer[3072];
CYASSL_X509* chainX509;
CyaSSL_get_chain_cert_pem(chain,i,buffer, sizeof(buffer), &length);
buffer[length] = 0;
printf("cert %d has length %d data = \n%s\n", i, length, buffer);
chainX509 = CyaSSL_get_chain_X509(chain, i);
if (chainX509)
ShowX509(chainX509, "session cert info:");
else
printf("get_chain_X509 failed\n");
CyaSSL_FreeX509(chainX509);
}
}
#endif
(void)ssl;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<workspace>
<project>
<path>$WS_DIR$\CyaSSL-Lib.ewp</path>
</project>
<batchBuild/>
</workspace>

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<workspace>
<project>
<path>$WS_DIR$\client.ewp</path>
</project>
<batchBuild/>
</workspace>

View File

@ -962,13 +962,8 @@ int SetCipherList(Suites*, const char* list);
#ifdef HAVE_NETX
CYASSL_LOCAL int NetX_Receive(CYASSL *ssl, char *buf, int sz, void *ctx);
CYASSL_LOCAL int NetX_Send(CYASSL *ssl, char *buf, int sz, void *ctx);
#endif
#ifdef HAVE_LWIP_NATIVE
CYASSL_LOCAL int CyaSSL_LwIP_Send(CYASSL* ssl, char *buf, int sz, void *cb);
CYASSL_LOCAL int CyaSSL_LwIP_Receive(CYASSL* ssl, char *buf, int sz, void *cb);
CYASSL_API int CyaSSL_SetIO_LwIP(CYASSL* ssl, void *pcb,
tcp_recv_fn recv, tcp_sent_fn sent, void *arg);
#endif /* HAVE_LWIP_NATIVE */
#endif /* HAVE_NETX */
/* CyaSSL Cipher type just points back to SSL */
struct CYASSL_CIPHER {
@ -1805,19 +1800,6 @@ typedef struct DtlsMsg {
#endif
#ifdef HAVE_LWIP_NATIVE
/* LwIP native tpc socket context */
typedef struct LwIP_native_Ctx {
struct tcp_pcb * pcb ;
tcp_recv_fn recv ;
tcp_sent_fn sent ;
int pulled ;
struct pbuf *pbuf ;
int wait ;
void * arg ; /* arg for application */
int idle_count ;
} LwIP_native_Ctx ;
#endif
/* CyaSSL ssl type */
struct CYASSL {
@ -1929,9 +1911,6 @@ struct CYASSL {
#ifdef HAVE_NETX
NetX_Ctx nxCtx; /* NetX IO Context */
#endif
#ifdef HAVE_LWIP_NATIVE
LwIP_native_Ctx lwipCtx; /* NetX IO Context */
#endif
#ifdef SESSION_INDEX
int sessionIndex; /* Session's location in the cache. */
#endif

View File

@ -941,9 +941,7 @@ CYASSL_API void CyaSSL_SetIOWriteFlags(CYASSL* ssl, int flags);
CYASSL_API void CyaSSL_SetIO_NetX(CYASSL* ssl, NX_TCP_SOCKET* nxsocket,
ULONG waitoption);
#endif
#ifdef HAVE_LWIP_NATIVE
#include "lwip/tcp.h"
#endif
typedef int (*CallbackGenCookie)(CYASSL* ssl, unsigned char* buf, int sz,
void* ctx);
CYASSL_API void CyaSSL_CTX_SetGenCookie(CYASSL_CTX*, CallbackGenCookie);
@ -1289,9 +1287,13 @@ CYASSL_API int CyaSSL_accept_ex(CYASSL*, HandShakeCallBack, TimeoutCallBack,
#ifdef CYASSL_HAVE_WOLFSCEP
CYASSL_API void CyaSSL_wolfSCEP(void);
CYASSL_API void CyaSSL_wolfSCEP(void);
#endif /* CYASSL_HAVE_WOLFSCEP */
#ifdef CYASSL_HAVE_CERT_SERVICE
CYASSL_API void CyaSSL_cert_service(void);
#endif
#ifdef __cplusplus
} /* extern "C" */

View File

@ -37,7 +37,7 @@
#else
#include <string.h>
#include <sys/types.h>
#if !defined(CYASSL_LEANPSK) && !defined(HAVE_LWIP_NATIVE)
#ifndef CYASSL_LEANPSK
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
@ -59,14 +59,6 @@
#define SNPRINTF snprintf
#endif /* USE_WINDOWS_API */
#if defined(HAVE_LWIP_NATIVE)
#include <string.h>
#include "lwip/tcp.h"
#include "lwip/sockets.h"
#include "lwip/inet.h"
#include "lwip/ip_addr.h"
#endif
#ifdef HAVE_CAVIUM
#include "cavium_sysdep.h"
#include "cavium_common.h"

View File

@ -38,12 +38,7 @@
#endif
#include <cyassl/ssl.h>
#if defined(HAVE_LWIP_NATIVE)
#include "tcp-conn-nb.h"
#else
#include <cyassl/test.h>
#endif
#include <cyassl/test.h>
#include "examples/client/client.h"
@ -54,6 +49,7 @@
Timeval timeout;
#endif
static void NonBlockingSSL_Connect(CYASSL* ssl)
{
#ifndef CYASSL_CALLBACKS
@ -163,10 +159,11 @@ static void Usage(void)
THREAD_RETURN CYASSL_THREAD client_test(void* args)
{
STATIC_NB SOCKET_T sockfd = 0 ;
SOCKET_T sockfd = 0;
CYASSL_METHOD* method = 0;
STATIC_NB CYASSL_CTX* ctx = 0;
STATIC_NB CYASSL* ssl = 0;
CYASSL_CTX* ctx = 0;
CYASSL* ssl = 0;
CYASSL* sslResume = 0;
CYASSL_SESSION* session = 0;
@ -392,9 +389,7 @@ THREAD_RETURN CYASSL_THREAD client_test(void* args)
}
myoptind = 0; /* reset for test cases */
SWITCH_STAT {
/* sort out DTLS versus TLS versions */
if (version == CLIENT_INVALID_VERSION) {
if (doDTLS)
@ -600,15 +595,13 @@ SWITCH_STAT {
exit(EXIT_SUCCESS);
}
#if defined(CYASSL_MDK_ARM) || defined(HAVE_LWIP_NATIVE)
#if defined(CYASSL_MDK_ARM)
CyaSSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, 0);
#endif
ssl = CyaSSL_new(ctx);
if (ssl == NULL)
err_sys("unable to get SSL object");
CASE(CLIENT_TCP_CONN):
if (doDTLS) {
SOCKADDR_IN_T addr;
build_addr(&addr, host, port, 1);
@ -616,15 +609,7 @@ CASE(CLIENT_TCP_CONN):
tcp_socket(&sockfd, 1);
}
else {
#if !defined(HAVE_LWIP_NATIVE)
tcp_connect(&sockfd, host, port, 0);
#else
int err = tcp_connect(&sockfd, host, port, 0);
if(err == TCP_CONNECTED)
CyaSSL_SetIO_LwIP(ssl, sockfd, NULL, NULL, NULL);
else
BREAK ;
#endif
tcp_connect(&sockfd, host, port, 0);
}
CyaSSL_set_fd(ssl, sockfd);
#ifdef HAVE_CRL
@ -646,9 +631,6 @@ CASE(CLIENT_TCP_CONN):
if (matchName && doPeerCheck)
CyaSSL_check_domain_name(ssl, domain);
#ifndef CYASSL_CALLBACKS
CASE(CLIENT_SSL_CONN):
if (nonBlocking) {
CyaSSL_set_using_nonblock(ssl, 1);
tcp_set_nonblocking(&sockfd);
@ -657,10 +639,6 @@ CASE(CLIENT_SSL_CONN):
else if (CyaSSL_connect(ssl) != SSL_SUCCESS) {
/* see note at top of README */
int err = CyaSSL_get_error(ssl, 0);
#if defined(HAVE_LWIP_NATIVE)
if(err == SSL_ERROR_WANT_READ)
BREAK ;
#endif
char buffer[CYASSL_MAX_ERROR_SZ];
printf("err = %d, %s\n", err,
CyaSSL_ERR_error_string(err, buffer));
@ -672,21 +650,17 @@ CASE(CLIENT_SSL_CONN):
timeout.tv_usec = 0;
NonBlockingSSL_Connect(ssl); /* will keep retrying on timeout */
#endif
showPeer(ssl);
if (sendGET) {
printf("SSL connect ok, sending GET...\n");
msgSz = 28;
//strncpy(msg, "GET /index.html HTTP/1.0\r\n\r\n", msgSz);
strncpy(msg, "GET / HTTP/1.0\r\n\r\n", msgSz);
strncpy(msg, "GET /index.html HTTP/1.0\r\n\r\n", msgSz);
msg[msgSz] = '\0';
}
if (CyaSSL_write(ssl, msg, msgSz) != msgSz)
err_sys("SSL_write failed");
CASE(CLIENT_SSL_READ):
input = CyaSSL_read(ssl, reply, sizeof(reply)-1);
if (input > 0) {
reply[input] = 0;
@ -708,9 +682,8 @@ CASE(CLIENT_SSL_READ):
int readErr = CyaSSL_get_error(ssl, 0);
if (readErr != SSL_ERROR_WANT_READ)
err_sys("CyaSSL_read failed");
BREAK ;
}
#ifndef NO_SESSION_CACHE
if (resumeSession) {
if (doDTLS) {
@ -809,11 +782,6 @@ CASE(CLIENT_SSL_READ):
#endif /* USE_CYASSL_MEMORY */
return 0;
}
END_SWITCH ; /* End of SWITCH(stat) */
return 0 ;
}
@ -863,6 +831,7 @@ END_SWITCH ; /* End of SWITCH(stat) */
#endif /* NO_MAIN_DRIVER */
#ifdef CYASSL_CALLBACKS
int handShakeCB(HandShakeInfo* info)

View File

@ -23,40 +23,3 @@
THREAD_RETURN CYASSL_THREAD client_test(void* args);
#if defined(HAVE_LWIP_NATIVE)
static enum Client_Stat {
CLIENT_BEGIN ,
CLIENT_TCP_CONN ,
CLIENT_SSL_CONN ,
CLIENT_SSL_READ ,
} client_stat ;
int tcp_connect_nb(struct tcp_pcb **pcb, const char* ip, word16 port, int udp);
void tcp_CloseSocket_nb(struct tcp_pcb *pcb) ;
#define tcp_connect(s, h, p, f) tcp_connect_nb(s, h, p, f)
#define CloseSocket(s) tcp_CloseSocket_nb(s)
#define CyaSSL_set_fd(ssl, s)
#endif
#if defined(HAVE_LWIP_NATIVE)
#define SWITCH_STAT switch(client_stat) { case CLIENT_BEGIN:
#define CASE(stat) client_stat = stat ; case stat
#define BREAK break
#define END_SWITCH }
#define STATIC_NB static
#else
#define SWITCH_STAT
#define CASE(value)
#define BREAK
#define END_SWITHCH
#define STATIC_NB
#endif

View File

@ -396,11 +396,6 @@ int InitSSL_Ctx(CYASSL_CTX* ctx, CYASSL_METHOD* method)
ctx->CBIORecv = NetX_Receive;
ctx->CBIOSend = NetX_Send;
#endif
#ifdef HAVE_LWIP_NATIVE
ctx->CBIORecv = CyaSSL_LwIP_Receive ;
ctx->CBIOSend = CyaSSL_LwIP_Send ;
#endif
ctx->partialWrite = 0;
ctx->verifyCallback = 0;
@ -1433,10 +1428,6 @@ int InitSSL(CYASSL* ssl, CYASSL_CTX* ctx)
ssl->IOCB_ReadCtx = &ssl->nxCtx; /* default NetX IO ctx, same for read */
ssl->IOCB_WriteCtx = &ssl->nxCtx; /* and write */
#endif
#ifdef HAVE_LWIP_NATIVE
ssl->lwipCtx.pbuf = NULL ;
ssl->lwipCtx.pulled = 0 ;
#endif
#ifdef CYASSL_DTLS
ssl->IOCB_CookieCtx = NULL; /* we don't use for default cb */
ssl->dtls_expected_rx = MAX_MTU;

209
src/io.c
View File

@ -553,6 +553,7 @@ static int tcp_connect(SOCKET_T* sockfd, const char* ip, word16 port)
CYASSL_MSG("bad socket fd, out of fds?");
return -1;
}
if (connect(*sockfd, (struct sockaddr *)&addr, sockaddr_len) != 0) {
CYASSL_MSG("OCSP responder tcp connect failed");
return -1;
@ -1044,211 +1045,3 @@ void CyaSSL_SetIO_NetX(CYASSL* ssl, NX_TCP_SOCKET* nxSocket, ULONG waitOption)
#endif /* HAVE_NETX */
#ifdef HAVE_LWIP_NATIVE
#include "lwip/tcp.h"
#include "lwip/pbuf.h"
#include "lwip/sockets.h"
#if 0
/*Enable debug*/
#include <cstdio>
#define DBG_PRINTF(x, ...) printf("[SSLClient : DBG]"x"\r\n", ##__VA_ARGS__);
#define ERR_PRINTF(x, ...) printf("[SSLClient:ERROR]"x"\r\n", ##__VA_ARGS__);
#else
/*Disable debug*/
#define DBG_PRINTF(x, ...)
#define ERR_PRINTF(x, ...)
#endif
#if 0
/*Enable debug*/
#define DBG_PRINTF_CB(x, ...) printf("[HTTPSClient : DBG]"x"\r\n", ##__VA_ARGS__);
#else
/*Disable debug*/
#define DBG_PRINTF_CB(x, ...)
#endif
#ifdef CYASSL_IAR_ARM
#include "intrinsics.h"
#endif
static void CyaSSL_PbufFree(void *vp)
{
struct pbuf *p ;
struct pbuf * next;
p = (struct pbuf *) vp ;
while(p->next != NULL)
{
next = p->next;
pbuf_free(p);
p = next;
}
pbuf_free(p);
}
static int CyaSSL_GetDataFromPbuf(char *buff, CYASSL *ssl, int size)
{
struct pbuf *p ;
struct pbuf *p_next ;
int totalLen ;
int skipLen = 0 ;
p = ssl->lwipCtx.pbuf ;
#if defined(DEBUG_PBUF)
printf("WantRead Size=%d\n", size) ;
do {
printf("p=%x, p->len=%d, p->tot_len=%d\n", p, p->len, p->tot_len) ;
if(p != p->next)
p = p->next ;
else break ;
} while(p) ;
p = ssl->lwipCtx.pbuf ;
#endif
if(p->tot_len < (ssl->lwipCtx.pulled + size))
return 0 ;
while(p) { /* skip the part pulled before */
if(p->len && p->len > (ssl->lwipCtx.pulled - skipLen) ){
skipLen = (ssl->lwipCtx.pulled - skipLen) ;
break ;
} else {
skipLen += p->len ;
if(p->next)
p = p->next ;
else return 0 ;
}
}
totalLen = 0 ;
while(p){
if(p->len) {
if((p->len - skipLen) > (size - totalLen)) { /* buffer full */
memcpy(&buff[totalLen], (const char *)&(((char *)(p->payload))[skipLen]), size-totalLen) ;
totalLen = size ;
break ;
} else {
memcpy(&buff[totalLen], (const char *)&(((char *)(p->payload))[skipLen]), p->len - skipLen) ;
totalLen += (p->len-skipLen) ;
skipLen = 0 ;
}
}
if(p->next){
p_next = p->next ;
p = p_next ;
} else break ;
}
ssl->lwipCtx.pulled += totalLen ;
if(ssl->lwipCtx.pbuf->tot_len <= ssl->lwipCtx.pulled) {
CyaSSL_PbufFree(ssl->lwipCtx.pbuf) ;
ssl->lwipCtx.pbuf = NULL ;
tcp_recved(ssl->lwipCtx.pcb,ssl->lwipCtx.pbuf->tot_len) ;
}
return totalLen;
}
err_t CyaSSL_LwIP_recv_cb(void *cb, struct tcp_pcb *pcb, struct pbuf *p, s8_t err)
{
struct pbuf *next ;
CYASSL *ssl ;
ssl = (CYASSL *)cb ;
if((cb == NULL)||(pcb == NULL))
ERR_PRINTF("CyaSSL_LwIP_recv_cb, cb=%x, pcb=%d\n", cb, pcb) ;
if(p && (err == 0)) {
DBG_PRINTF_CB("CyaSSL_LwIP_recv_cb, pbuf=%x, err=%d, tot_len=%d\n", p, err, p->tot_len) ;
}else {
ERR_PRINTF("CyaSSL_LwIP_recv_cb, pbuf=%x, err=%d\n", p, err) ;
return ERR_OK; /* don't go to SSL_CONN */
}
if(ssl->lwipCtx.pbuf) {
next = ssl->lwipCtx.pbuf ;
while(1) {
if(next->next)
next = next->next ;
else break ;
}
next->next = p ;
ssl->lwipCtx.pbuf->tot_len += p->tot_len ;
} else {
ssl->lwipCtx.pbuf = p ;
}
ssl->lwipCtx.pulled = 0 ;
ssl->lwipCtx.wait = 10000 ;
if(ssl->lwipCtx.recv)
return ssl->lwipCtx.recv(ssl->lwipCtx.arg, pcb, p, err) ;
/* user callback */
return ERR_OK;
}
err_t CyaSSL_LwIP_sent_cb(void *cb, struct tcp_pcb *pcb, u16_t err)
{
CYASSL *ssl ;
ssl = (CYASSL *)cb ;
DBG_PRINTF_CB("CaSSL_LwIP_write_cb, err=%d\n", err) ;
if(ssl->lwipCtx.sent)
return ssl->lwipCtx.sent(ssl->lwipCtx.arg, pcb, err) ;
/* user callback */
return ERR_OK;
}
int CyaSSL_LwIP_Receive(CYASSL* ssl, char *buf, int sz, void *cb)
{
int ret ;
DBG_PRINTF_CB("CyaSSL_LwIP_Receive: ssl_nb = %x\n", ssl) ;
if(ssl->lwipCtx.pbuf) {
if(ssl->lwipCtx.wait){
ssl->lwipCtx.wait-- ;
return CYASSL_CBIO_ERR_WANT_READ ;
}
DBG_PRINTF_CB("Received Len=%d, Want Len= %d\n", ssl->lwipCtx.pbuf->tot_len, sz) ;
ret = CyaSSL_GetDataFromPbuf(buf, ssl, sz) ;
if(ret == 0)
ret = CYASSL_CBIO_ERR_WANT_READ ;
} else {
DBG_PRINTF_CB("No Received Data\n") ;
ret = CYASSL_CBIO_ERR_WANT_READ ;
}
return ret ;
}
int CyaSSL_LwIP_Send(CYASSL* ssl, char *buf, int sz, void *cb)
{
err_t ret ;
DBG_PRINTF_CB("CyaSSL_LwIP_Send: ssl = %x, pcb = %x\n", ssl, ssl->lwipCtx.pcb) ;
DBG_PRINTF_CB("Send buf[0,1,2,3]=%x,%x,%x,%x, sz=%d\n", buf[0], buf[1], buf[2], buf[3], sz) ;
ret = tcp_write(ssl->lwipCtx.pcb, buf, sz, TCP_WRITE_FLAG_COPY) ;
if(ret == ERR_OK)
return sz ;
else {
ERR_PRINTF("Send ssl=%x, ret=%d\n", ssl, ret) ;
return -1 ;
}
}
int CyaSSL_SetIO_LwIP(CYASSL* ssl, void* pcb,
tcp_recv_fn recv, tcp_sent_fn sent, void *arg)
{
if (ssl && pcb) {
ssl->lwipCtx.pcb = (struct tcp_pcb *)pcb ;
ssl->lwipCtx.recv = recv ; /* recv user callback */
ssl->lwipCtx.sent = sent ; /* sent user callback */
ssl->lwipCtx.arg = arg ;
ssl->lwipCtx.pbuf = 0 ;
ssl->lwipCtx.pulled = 0 ;
ssl->lwipCtx.wait = 0 ;
/* CyaSSL_LwIP_recv/sent_cb invokes recv/sent user callback in them. */
tcp_recv(pcb, CyaSSL_LwIP_recv_cb) ;
tcp_sent(pcb, CyaSSL_LwIP_sent_cb) ;
tcp_arg (pcb, (void *)ssl) ;
} else return BAD_FUNC_ARG ;
return ERR_OK ;
}
#endif /* HAVE_LWIP_NATIVE */