Commit b01b6d30 by Fear1ess

4/26

parent ca0ab15e
......@@ -11,13 +11,13 @@ android {
keyPassword 'reyun12345'
}
}
compileSdkVersion 30
compileSdkVersion 26
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.reyun.sdktestdemo"
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 26
versionCode 1
versionName "1.0"
......@@ -45,9 +45,9 @@ android {
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// implementation 'androidx.appcompat:appcompat:1.1.0'
// implementation 'com.google.android.material:material:1.1.0'
// implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
......
......@@ -12,10 +12,8 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ReyunSdk">
android:supportsRtl="true">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
package com.reyun.sdktestdemo;
import android.util.Log;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipInputStream;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class HttpServer extends NanoHTTPD {
public HttpServer(int port) {
super(port);
}
@Override
public Response serve(IHTTPSession session) {
if(!session.getMethod().equals(Method.POST)) return newFixedLengthResponse("not support GET");
try{
InputStream in = session.getInputStream();
byte[] b = new byte[1024];
int len;
ByteArrayOutputStream bo = new ByteArrayOutputStream();
DataInputStream di = new DataInputStream(in);
byte[] key = new byte[16];
byte[] iv = new byte[16];
byte[] data_md5 = new byte[16];
int ts;
int data_len;
if(di.read(key, 0, 16) == 16) {
if(di.read(iv, 0, 16) == 16) {
ts = di.readInt();
if(di.read(data_md5, 0, 16) == 16) {
data_len = di.readInt();
byte[] data = new byte[data_len];
if(di.read(data, 0, data_len) == data_len) {
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(iv));
byte[] decodedData = cipher.doFinal(data);
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(decodedData));
byte[] buf = new byte[1024];
ByteArrayOutputStream bo2 = new ByteArrayOutputStream();
int len2;
while((len2 = zis.read(buf, 0, 1024)) >= 0) {
bo2.write(buf, 0, len2);
}
byte[] ori_data = bo2.toByteArray();
Log.d("wdsdk", "ori_data: " + ori_data);
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (InvalidAlgorithmParameterException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
}
return newFixedLengthResponse("hahaha...");
}
}
package com.reyun.sdktestdemo;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.app.Activity;
import android.app.Application;
import android.app.Service;
import android.content.Context;
......@@ -63,7 +60,7 @@ import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
public class MainActivity extends AppCompatActivity {
public class MainActivity extends Activity {
private TextView mText;
@Override
......@@ -110,12 +107,18 @@ public class MainActivity extends AppCompatActivity {
e.printStackTrace();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if(requestCode == 100) {
String aa = System.getProperty("http.agent");
HttpServer hs = new HttpServer(9666);
try {
hs.start();
} catch (IOException e) {
e.printStackTrace();
}
//初始化sdk环境
WdMain wm = WdMain.getInstance();
wm.init(getApplicationContext(), "test-a341fsfr3123ddadfs");
......
......@@ -12,4 +12,6 @@ public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
}
}
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.ReyunSdk" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
\ No newline at end of file
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.ReyunSdk" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
\ No newline at end of file
......@@ -3,12 +3,12 @@ plugins {
}
android {
compileSdkVersion 30
compileSdkVersion 26
buildToolsVersion "30.0.3"
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 26
versionCode 1
versionName "1.0"
......
......@@ -9,9 +9,15 @@
#include "string.h"
#include "android/log.h"
#include "mybase64.h"
#include "wd_syscall.h"
#include <time.h>
#include <syscall.h>
#include <openssl/md5.h>
#define LOG_TAG "WD_COLLECT"
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__);
IMPORTWDSYSCALL
void generateAESKeyIv(char *key, char*iv, char* key_Table);
void encrpyt_buf(char*m_key,char*m_iv, char *raw_buf, char **encrpy_buf, int len );
void decrpyt_buf(char*m_key,char*m_iv, char *raw_buf, char **encrpy_buf, int len );
......@@ -19,9 +25,6 @@ int startAESEncode(char*m_key,char*m_iv, char* src,int src_Size,char**encode_ptr
char *padding_buf(char *buf,int size, int *final_size);
char *padding_buf(char *buf,int size, int *final_size) {
char *ret = NULL;
//填充区的大小
......@@ -50,16 +53,30 @@ int startAESEncode(char*m_key,char*m_iv, char* src,int src_Size,char**encode_ptr
if(after_padding_buf==NULL){
return 0;
}
// 进行加密
encrypt_buf = (char *)calloc(1,padding_size);
// 进行加密 key, iv, ts, data_md5, data_len
unsigned char* data_buf = (unsigned char*) calloc(1, padding_size + 16 + 16 + 4 + 16 + 4);
encrypt_buf = data_buf + 56;
encrpyt_buf(m_key,m_iv,after_padding_buf,&encrypt_buf, padding_size);
memcpy(data_buf, m_key, 16);
memcpy(data_buf + 16, m_iv, 16);
struct timespec ts;
if(WDSYSCALL(SYS_clock_gettime, CLOCK_REALTIME, &ts) == 0) {
snprintf(data_buf + 32, 4, "%x", ts.tv_sec);
}else {
memset(data_buf + 32, 0, 4);
}
char md5[16];
MD5(encrypt_buf, padding_size, md5);
memcpy(data_buf + 36, md5, 16);
memcpy(data_buf + 52, &padding_size, 4);
free(after_padding_buf);
//传出加密后的内容
*encode_ptr = encrypt_buf;
*out_size=padding_size;
*encode_ptr = data_buf;
*out_size=padding_size + 56;
//-----------------测试代码
//打印源字符串的16进制
unsigned char* temp=( unsigned char*)calloc(1,padding_size*2+1);
unsigned char* temp = ( unsigned char*)calloc(1,padding_size * 2 + 1);
int strLen=padding_size;
for(int i=0;i<strLen;++i){
char temp2[0x10]={0};
......@@ -119,7 +136,7 @@ void decrpyt_buf(char*m_key,char*m_iv, char *raw_buf, char **encrpy_buf, int len
void aes_Encoder_Base64(char *src,int src_Len,char**encode_ptr,unsigned int* out_len, char*out_key,char*out_iv ){
void aes_Encoder_Base64(char *src,int src_Len, char** encode_ptr, unsigned int* out_len, char*out_key,char*out_iv ){
//用于密钥生成的表
char key_Table[]="0123456789abcdef";
//用于接收AES加密后的内容
......
......@@ -110,8 +110,8 @@ jstring do_collect(JNIEnv* env) {
size_t encoded_len = 0;
aes_Encoder_Base64(compressed_data, bound, &encoded_data, &encoded_len, aes_key, aes_iv);
//https
http_PostConnect(env, "https://192.168.7.103:6666", encoded_data, encoded_len);
//http post
http_PostConnect(env, "http://172.23.0.3:9666", encoded_data, encoded_len);
}
}
}
......@@ -283,7 +283,6 @@ void collect_mac_addr(JNIEnv *env, cJSON *json) {
}
jbyteArray mac_byteArr = wdCallObjectMethod(env, ni, "getHardwareAddress", "()[B");
if(mac_byteArr == NULL) {
cJSON_AddStringToObject(json, "mac_addr", "");
goto return_label;
}
jsize size = (*env)->GetArrayLength(env, mac_byteArr);
......@@ -298,6 +297,7 @@ void collect_mac_addr(JNIEnv *env, cJSON *json) {
(*env)->DeleteLocalRef(env, ni);
return_label2:
(*env)->DeleteLocalRef(env, name_str);
cJSON_AddStringToObject(json, "mac_addr", "");
logd(WD_COLLECT, "%s", "collect mac_addr finished...");
}
......@@ -623,9 +623,17 @@ void collect_battery_info(JNIEnv *env, cJSON *json) {
}
void collect_env(JNIEnv *env, cJSON *json) {
cJSON* env_item = cJSON_CreateObject();
char* path = getenv("PATH");
cJSON_AddStringToObject(env_item, "PATH", path);
cJSON* env_item = cJSON_CreateArray();
// char* path = getenv("PATH");
// cJSON_AddStringToObject(env_item, "PATH", path);
// cJSON_AddItemToObject(json, "env", env_item);
char** p = environ;
while(*p) {
cJSON_AddItemToArray(env_item, cJSON_CreateString(*p));
++p;
}
cJSON_AddItemToObject(json, "env", env_item);
logd(WD_COLLECT, "%s", "collect env finished...");
......
......@@ -35,7 +35,7 @@ char* http_PostConnect(JNIEnv *env, char* url, unsigned char* post_Body, size_t
jstring post=(*env)->NewStringUTF(env,"POST");
wdCallVoidMethod(env,connection,"setRequestMethod","(Ljava/lang/String;)V",post);
jstring type=(*env)->NewStringUTF(env,"Content-Type");
jstring type_Content=(*env)->NewStringUTF(env,"text/plain;charset=UTF-8");
jstring type_Content=(*env)->NewStringUTF(env,"application/octet-stream");
wdCallVoidMethod(env,connection,"setRequestProperty",
"(Ljava/lang/String;Ljava/lang/String;)V",type,type_Content);
wdCallVoidMethod(env,connection,"setDoInput",
......@@ -43,12 +43,12 @@ char* http_PostConnect(JNIEnv *env, char* url, unsigned char* post_Body, size_t
wdCallVoidMethod(env,connection,"setDoOutput",
"(Z)V",1);
wdCallVoidMethod(env,connection,"setConnectTimeout",
"(I)V",10000);
"(I)V",5000);
wdCallVoidMethod(env,connection,"setReadTimeout",
"(I)V",10000);
"(I)V",5000);
jobject outPutStream=wdCallObjectMethod(env,connection,"getOutputStream","()Ljava/io/OutputStream;");
jobject out=wdNewObject(env,"java/io/DataOutputStream","(Ljava/io/OutputStream;)V",outPutStream);
wdCallVoidMethod(env,out,"write","([B)V",body_Array);
wdCallVoidMethod(env,out,"write","([B)V", body_Array);
wdCallVoidMethod(env,out,"flush","()V");
wdCallVoidMethod(env,out,"close","()V");
wdCallVoidMethod(env,connection,"connect","()V");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment