提交 77b67554 编写于 作者: M maosiping

liteos only ipv4

Signed-off-by: Nmaosiping <maosiping@huawei.com>
上级 de3a6678
...@@ -27,10 +27,23 @@ MBEDTLS_SOURCES += [ ...@@ -27,10 +27,23 @@ MBEDTLS_SOURCES += [
"library/x509write_csr.c", "library/x509write_csr.c",
] ]
if (defined(ohos_lite)) {
MBEDTLS_SOURCES -= [ "library/ssl_srv.c" ]
}
if (defined(ohos_lite)) { if (defined(ohos_lite)) {
import("//build/lite/config/component/lite_component.gni") import("//build/lite/config/component/lite_component.gni")
import("//build/lite/ndk/ndk.gni") import("//build/lite/ndk/ndk.gni")
if (ohos_kernel_type != "liteos_m") {
MBEDTLS_SOURCES += [ "library/ssl_srv.c" ]
MBEDTLS_SOURCES -= [
"$MBEDTLSDIR/library/ssl_srv.c",
"$MBEDTLSDIR/port/src/tls_client.c",
"$MBEDTLSDIR/port/src/tls_certificate.c",
]
}
config("mbedtls_config") { config("mbedtls_config") {
include_dirs = MBEDTLS_INLCUDE_DIRS include_dirs = MBEDTLS_INLCUDE_DIRS
if (ohos_kernel_type == "liteos_m") { if (ohos_kernel_type == "liteos_m") {
......
...@@ -193,8 +193,15 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, ...@@ -193,8 +193,15 @@ int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host,
ret = MBEDTLS_ERR_NET_UNKNOWN_HOST; ret = MBEDTLS_ERR_NET_UNKNOWN_HOST;
for( cur = addr_list; cur != NULL; cur = cur->ai_next ) for( cur = addr_list; cur != NULL; cur = cur->ai_next )
{ {
#ifdef LITEOS_VERSION
if (cur->ai_family != AF_INET || cur->ai_socktype != SOCK_STREAM) {
continue;
}
ctx->fd = (int) socket(AF_INET, SOCK_STREAM, 0);
#else
ctx->fd = (int) socket( cur->ai_family, cur->ai_socktype, ctx->fd = (int) socket( cur->ai_family, cur->ai_socktype,
cur->ai_protocol ); cur->ai_protocol );
#endif
if( ctx->fd < 0 ) if( ctx->fd < 0 )
{ {
ret = MBEDTLS_ERR_NET_SOCKET_FAILED; ret = MBEDTLS_ERR_NET_SOCKET_FAILED;
...@@ -575,8 +582,12 @@ int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len ) ...@@ -575,8 +582,12 @@ int mbedtls_net_recv( void *ctx, unsigned char *buf, size_t len )
ret = check_fd( fd, 0 ); ret = check_fd( fd, 0 );
if( ret != 0 ) if( ret != 0 )
return( ret ); return( ret );
#ifdef LITEOS_VERSION
ret = (int) recv( fd, buf, len, 0);
#else
ret = (int) read( fd, buf, len ); ret = (int) read( fd, buf, len );
#endif
if( ret < 0 ) if( ret < 0 )
{ {
...@@ -658,7 +669,12 @@ int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len ) ...@@ -658,7 +669,12 @@ int mbedtls_net_send( void *ctx, const unsigned char *buf, size_t len )
if( ret != 0 ) if( ret != 0 )
return( ret ); return( ret );
#ifdef LITEOS_VERSION
ret = (int) send( fd, buf, len, 0);
#else
ret = (int) write( fd, buf, len ); ret = (int) write( fd, buf, len );
#endif
if( ret < 0 ) if( ret < 0 )
{ {
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
MBEDTLSDIR = "//third_party/mbedtls/" MBEDTLSDIR = "//third_party/mbedtls/"
KERNELDIR = "//kernel/liteos_m/" KERNELDIR = "//kernel/liteos_m/"
...@@ -129,3 +129,13 @@ MBEDTLS_INLCUDE_DIRS = [ ...@@ -129,3 +129,13 @@ MBEDTLS_INLCUDE_DIRS = [
"$MBEDTLSDIR/include/mbedtls", "$MBEDTLSDIR/include/mbedtls",
"$MBEDTLSDIR/tests/include", "$MBEDTLSDIR/tests/include",
] ]
if (defined(ohos_lite)) {
MBEDTLS_SOURCES += [
"$MBEDTLSDIR/library/ssl_srv.c",
"$MBEDTLSDIR/port/src/tls_client.c",
"$MBEDTLSDIR/port/src/tls_certificate.c",
]
MBEDTLS_INLCUDE_DIRS += [ "$MBEDTLSDIR/port/include" ]
}
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
import("//build/lite/config/component/lite_component.gni") import("//build/lite/config/component/lite_component.gni")
...@@ -22,6 +22,7 @@ if (ohos_build_type == "debug") { ...@@ -22,6 +22,7 @@ if (ohos_build_type == "debug") {
"//third_party/mbedtls/include", "//third_party/mbedtls/include",
"//commonlibrary/utils_lite/include", "//commonlibrary/utils_lite/include",
"//third_party/bounds_checking_function/include", "//third_party/bounds_checking_function/include",
"//third_party/mbedtls/port/include",
] ]
} }
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#ifndef OHOS_DEBUG #ifndef OHOS_DEBUG
#define DECORATOR_HILOG(op, fmt, args...) \ #define DECORATOR_HILOG(op, fmt, args...) \
do { \ do { \
op(LOG_CORE, fmt, ##args); \
} while (0) } while (0)
#else #else
#define DECORATOR_HILOG(op, fmt, args...) \ #define DECORATOR_HILOG(op, fmt, args...) \
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#define MBEDTLS_CLIENT_H #define MBEDTLS_CLIENT_H
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#include "mbedtls/net_sockets" #include "mbedtls/net_sockets.h"
#include "mbedtls/ssl.h" #include "mbedtls/ssl.h"
#include "mbedtls/entropy.h" #include "mbedtls/entropy.h"
#include "mbedtls/ctr_drbg.h" #include "mbedtls/ctr_drbg.h"
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
#define RET_ERROR -1; #define RET_ERROR -1;
#define RET_EOK 0 #define RET_EOK 0
#ifndef LOG_CORE
#define LOG_CORE 3
#endif
typedef struct MbedTLSSession { typedef struct MbedTLSSession {
char *host; char *host;
......
...@@ -90,7 +90,7 @@ int MbedtlsClientContext(MbedTLSSession *session) ...@@ -90,7 +90,7 @@ int MbedtlsClientContext(MbedTLSSession *session)
int ret = mbedtls_x509_crt_parse(&session->cacert, (const unsigned char *)G_MBEDTLS_ROOT_CERTIFICATE, int ret = mbedtls_x509_crt_parse(&session->cacert, (const unsigned char *)G_MBEDTLS_ROOT_CERTIFICATE,
G_MBEDTLS_ROOT_CERTIFICATE_LEN); G_MBEDTLS_ROOT_CERTIFICATE_LEN);
if (ret < 0) { if (ret < 0) {
LOGE("mbedtls_x509_crt_parse error, return -0x%x.", -ret); LOGD("mbedtls_x509_crt_parse error, return -0x%x.", -ret);
return ret; return ret;
} }
...@@ -135,7 +135,7 @@ int MbedtlsClientConnect(MbedTLSSession *session) ...@@ -135,7 +135,7 @@ int MbedtlsClientConnect(MbedTLSSession *session)
if (session == NULL) { if (session == NULL) {
return -RET_ERROR; return -RET_ERROR;
} }
LOGI("connect: host:%s, port: %s", session->host, session->port); LOGD("connect: host:%s, port: %s", session->host, session->port);
int ret = mbedtls_net_connect(&session->server_fd, session->host, session->port, MBEDTLS_NET_PROTO_TCP); int ret = mbedtls_net_connect(&session->server_fd, session->host, session->port, MBEDTLS_NET_PROTO_TCP);
if (ret != 0) { if (ret != 0) {
...@@ -145,7 +145,6 @@ int MbedtlsClientConnect(MbedTLSSession *session) ...@@ -145,7 +145,6 @@ int MbedtlsClientConnect(MbedTLSSession *session)
LOGD("Connected %s:%s fd:%d, success...", session->host, session->port, session->server_fd.fd); LOGD("Connected %s:%s fd:%d, success...", session->host, session->port, session->server_fd.fd);
mbedtls_ssl_set_bio(&session->ssl, &session->server_fd, mbedtls_net_send, mbedtls_net_recv, NULL); mbedtls_ssl_set_bio(&session->ssl, &session->server_fd, mbedtls_net_send, mbedtls_net_recv, NULL);
LOGD("ssl state=%d", session->ssl.state);
while ((ret = mbedtls_ssl_handshake(&session->ssl)) != 0) { while ((ret = mbedtls_ssl_handshake(&session->ssl)) != 0) {
LOGD("mbedtls_ssl_handshake ret=0x%x.", -ret); LOGD("mbedtls_ssl_handshake ret=0x%x.", -ret);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册