Skip to content

Commit

Permalink
Merge pull request #3 from alibaba/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
xiaowenhuyuehu authored Mar 28, 2019
2 parents 8c5812d + dba2b63 commit c295c52
Show file tree
Hide file tree
Showing 13 changed files with 985 additions and 113 deletions.
Binary file added .sconsign.dblite
Binary file not shown.
47 changes: 42 additions & 5 deletions remote_terminal.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,46 @@
"cert_path": "root.pem",
"is_tls_on": 1,
"is_debug_on": 0,
"listen_port": 22,
"listen_ip": "127.0.0.1",
"product_key": "aaaaaaaaaaa",
"device_name": "bbbbbbbbbbbbb",
"device_secret": "cccccccccccccccccccccccccccccccc"
"services": [{
"type": "FTP",
"name": "ftp_localhost",
"ip": "127.0.0.1",
"port": 21
}, {
"type": "SFTP",
"name": "sftp_localhost",
"ip": "127.0.0.1",
"port": 22
}, {
"type": "SSH",
"name": "ssh_localhost",
"ip": "127.0.0.1",
"port": 22
},
{
"type": "TELNET",
"name": "telnet_local",
"ip": "127.0.0.1",
"port": 23
}, {
"type": "HTTP",
"name": "http_localhost",
"ip": "127.0.0.1",
"port": 80
}, {
"type": "RDP",
"name": "rdp_localhost",
"ip": "127.0.0.1",
"port": 3389
}, {
"type": "HTTP",
"name": "openapi",
"ip": "100.69.166.91",
"port": 26999
}

],
"product_key": "AAAAAAAAAAA",
"device_name": "BBBBBBBBBBBBBBBBBBBB",
"device_secret": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
}
21 changes: 0 additions & 21 deletions root.pem

This file was deleted.

35 changes: 3 additions & 32 deletions src/connectivity/ws_nopoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,22 @@ int ws_nopoll_read(void *handle, char *buffer, int len, int timeout_ms)
noPollConn *conn = (noPollConn *)handle;
int bytes_read = 0;

#if 1
bytes_read = nopoll_conn_read(conn, buffer, len, nopoll_false, 100);
#else
noPollMsg *msg = NULL;
int size = 0;

msg = nopoll_conn_get_msg(conn);
if (NULL != msg) {
size = nopoll_msg_get_payload_size(msg);
if (size >= len) {
size = len - 1;
}
if (size > 0) {
memset(buffer, 0x0, len);
memcpy(buffer, nopoll_msg_get_payload(msg), size);
}
}
bytes_read = size;
#endif
return bytes_read;
return bytes_read;
}

int ws_nopoll_write(void *handle, const char *buffer, int len, int timeout_ms)
{
noPollConn *conn = (noPollConn *)handle;
int tries = 0;
int bytes_written = 0;

if ((NULL != buffer) && (len > 0)) {
bytes_written = nopoll_conn_send_binary (conn, buffer, len);
if (bytes_written == len) {
//log_debug ("send all. ");
return bytes_written;
}

while (tries < 5 && errno == NOPOLL_EWOULDBLOCK
&& nopoll_conn_pending_write_bytes (conn) > 0) {
nopoll_sleep (10000);
if (0 == nopoll_conn_complete_pending_write (conn)) {
log_debug ("send complete. ");
return len;
}
tries++;
}
log_debug ("send len: %d, try: %d. ", bytes_written, tries);
bytes_written = nopoll_conn_flush_writes (conn, 2000000, bytes_written);

return bytes_written;
} else {
log_debug ("ERROR: content is NULL or len <= 0 ");
Expand Down
51 changes: 51 additions & 0 deletions src/core/ca.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <stdio.h>
#include <string.h>

#include "ca.h"
#include "simple_log.h"

#define DEFAULT_ROOT_PEM_NAEM "./link_iot_edge_remote_access.pem"

static const char remote_debug_cert[] =
"-----BEGIN CERTIFICATE-----\r\n" \
"MIIDdTCCAl2gAwIBAgILBAAAAAABFUtaw5QwDQYJKoZIhvcNAQEFBQAwVzELMAkG\r\n" \
"A1UEBhMCQkUxGTAXBgNVBAoTEEdsb2JhbFNpZ24gbnYtc2ExEDAOBgNVBAsTB1Jv\r\n" \
"b3QgQ0ExGzAZBgNVBAMTEkdsb2JhbFNpZ24gUm9vdCBDQTAeFw05ODA5MDExMjAw\r\n" \
"MDBaFw0yODAxMjgxMjAwMDBaMFcxCzAJBgNVBAYTAkJFMRkwFwYDVQQKExBHbG9i\r\n" \
"YWxTaWduIG52LXNhMRAwDgYD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ret = 0;

fp = fopen(DEFAULT_ROOT_PEM_NAEM, "w+");

ret = fwrite(remote_debug_cert, 1, strlen(remote_debug_cert), fp);
if(ret != strlen(remote_debug_cert)){
fclose(fp);
log_error("failed to create ca file \n");
return NULL;
}

fclose(fp);
log_info("create ca root file done: %s.\n", DEFAULT_ROOT_PEM_NAEM);
return DEFAULT_ROOT_PEM_NAEM;
}


7 changes: 7 additions & 0 deletions src/core/ca.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef _CA_H__
#define _CA_H__

char *load_certs();

#endif

Loading

0 comments on commit c295c52

Please sign in to comment.