Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
bfa0f1cf
Commit
bfa0f1cf
authored
Dec 31, 2012
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on rc4 cipher
parent
57f6e87f
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
94 additions
and
38 deletions
+94
-38
assets/shadowsocks
assets/shadowsocks
+0
-0
jni/shadowsocks/encrypt.c
jni/shadowsocks/encrypt.c
+41
-28
jni/shadowsocks/encrypt.h
jni/shadowsocks/encrypt.h
+11
-0
jni/shadowsocks/local.c
jni/shadowsocks/local.c
+12
-3
jni/shadowsocks/local.h
jni/shadowsocks/local.h
+1
-1
libs/armeabi/shadowsocks
libs/armeabi/shadowsocks
+0
-0
res/values/strings.xml
res/values/strings.xml
+9
-4
res/xml/shadowsocks_preference.xml
res/xml/shadowsocks_preference.xml
+8
-0
src/com/github/shadowsocks/Shadowsocks.java
src/com/github/shadowsocks/Shadowsocks.java
+8
-0
src/com/github/shadowsocks/ShadowsocksService.java
src/com/github/shadowsocks/ShadowsocksService.java
+4
-2
No files found.
assets/shadowsocks
View file @
bfa0f1cf
No preview for this file type
jni/shadowsocks/encrypt.c
View file @
bfa0f1cf
#include "encrypt.h"
#include "android.h"
#include <openssl/md5.h>
#include <endian.h>
static
int
random_compare
(
const
void
*
_x
,
const
void
*
_y
)
{
uint32_t
i
=
_i
;
uint64_t
a
=
_a
;
...
...
@@ -115,30 +112,42 @@ static void mergesort(uint8_t array[], int length)
}
void
encrypt
(
char
*
buf
,
int
len
)
{
char
*
end
=
buf
+
len
;
while
(
buf
<
end
)
{
*
buf
=
(
char
)
encrypt_table
[(
uint8_t
)
*
buf
];
buf
++
;
if
(
_method
==
RC4_ENC
)
{
unsigned
char
mybuf
[
BUF_SIZE
];
RC4
(
&
rc4_key
,
len
,
(
unsigned
char
*
)
buf
,
mybuf
);
memcpy
(
buf
,
mybuf
,
len
);
}
else
{
char
*
end
=
buf
+
len
;
while
(
buf
<
end
)
{
*
buf
=
(
char
)
encrypt_table
[(
uint8_t
)
*
buf
];
buf
++
;
}
}
}
void
decrypt
(
char
*
buf
,
int
len
)
{
char
*
end
=
buf
+
len
;
while
(
buf
<
end
)
{
*
buf
=
(
char
)
decrypt_table
[(
uint8_t
)
*
buf
];
buf
++
;
if
(
_method
==
RC4_ENC
)
{
unsigned
char
mybuf
[
BUF_SIZE
];
RC4
(
&
rc4_key
,
len
,
(
unsigned
char
*
)
buf
,
mybuf
);
memcpy
(
buf
,
mybuf
,
len
);
}
else
{
char
*
end
=
buf
+
len
;
while
(
buf
<
end
)
{
*
buf
=
(
char
)
decrypt_table
[(
uint8_t
)
*
buf
];
buf
++
;
}
}
}
int
send_encrypt
(
int
sock
,
char
*
buf
,
int
len
,
int
flags
)
{
char
mybuf
[
4096
];
char
mybuf
[
BUF_SIZE
];
memcpy
(
mybuf
,
buf
,
len
);
encrypt
(
mybuf
,
len
);
return
send
(
sock
,
mybuf
,
len
,
flags
);
}
int
recv_decrypt
(
int
sock
,
char
*
buf
,
int
len
,
int
flags
)
{
char
mybuf
[
4096
];
char
mybuf
[
BUF_SIZE
];
int
result
=
recv
(
sock
,
mybuf
,
len
,
flags
);
memcpy
(
buf
,
mybuf
,
len
);
decrypt
(
buf
,
len
);
...
...
@@ -146,20 +155,24 @@ int recv_decrypt(int sock, char *buf, int len, int flags) {
}
void
get_table
(
const
char
*
key
)
{
uint8_t
*
table
=
encrypt_table
;
uint8_t
*
tmp_hash
=
MD5
((
const
uint8_t
*
)
key
,
strlen
(
key
),
NULL
);
_a
=
htole64
(
*
(
uint64_t
*
)
tmp_hash
);
uint32_t
i
;
for
(
i
=
0
;
i
<
256
;
++
i
)
{
table
[
i
]
=
i
;
}
for
(
i
=
1
;
i
<
1024
;
++
i
)
{
_i
=
i
;
mergesort
(
table
,
256
);
}
for
(
i
=
0
;
i
<
256
;
++
i
)
{
// gen decrypt table from encrypt table
decrypt_table
[
encrypt_table
[
i
]]
=
i
;
if
(
_method
==
RC4_ENC
)
{
RC4_set_key
(
&
rc4_key
,
strlen
(
key
),
(
unsigned
char
*
)
key
);
}
else
{
uint8_t
*
table
=
encrypt_table
;
uint8_t
*
tmp_hash
=
MD5
((
const
uint8_t
*
)
key
,
strlen
(
key
),
NULL
);
_a
=
htole64
(
*
(
uint64_t
*
)
tmp_hash
);
uint32_t
i
;
for
(
i
=
0
;
i
<
256
;
++
i
)
{
table
[
i
]
=
i
;
}
for
(
i
=
1
;
i
<
1024
;
++
i
)
{
_i
=
i
;
mergesort
(
table
,
256
);
}
for
(
i
=
0
;
i
<
256
;
++
i
)
{
// gen decrypt table from encrypt table
decrypt_table
[
encrypt_table
[
i
]]
=
i
;
}
}
}
jni/shadowsocks/encrypt.h
View file @
bfa0f1cf
...
...
@@ -4,9 +4,19 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <openssl/md5.h>
#include <openssl/rc4.h>
#include <endian.h>
#define BUF_SIZE 4096
#define TABLE_ENC 0
#define RC4_ENC 1
unsigned
char
encrypt_table
[
256
];
unsigned
char
decrypt_table
[
256
];
RC4_KEY
rc4_key
;
void
get_table
(
const
char
*
key
);
void
encrypt
(
char
*
buf
,
int
len
);
void
decrypt
(
char
*
buf
,
int
len
);
...
...
@@ -15,4 +25,5 @@ int recv_decrypt(int sock, char *buf, int len, int flags);
unsigned
int
_i
;
unsigned
long
long
_a
;
int
_method
;
jni/shadowsocks/local.c
View file @
bfa0f1cf
...
...
@@ -21,7 +21,6 @@
#include "local.h"
#include "socks5.h"
#include "encrypt.h"
#include "android.h"
#define min(a,b) (((a)<(b))?(a):(b))
...
...
@@ -567,12 +566,13 @@ int main (int argc, char **argv)
char
*
port
=
NULL
;
char
*
key
=
NULL
;
char
*
timeout
=
"10"
;
char
*
method
=
NULL
;
int
c
;
int
f_flags
=
0
;
opterr
=
0
;
while
((
c
=
getopt
(
argc
,
argv
,
"fs:p:l:k:t:"
))
!=
-
1
)
{
while
((
c
=
getopt
(
argc
,
argv
,
"fs:p:l:k:t:
m:
"
))
!=
-
1
)
{
switch
(
c
)
{
case
's'
:
server
=
optarg
;
...
...
@@ -592,6 +592,9 @@ int main (int argc, char **argv)
case
't'
:
timeout
=
optarg
;
break
;
case
'm'
:
method
=
optarg
;
break
;
}
}
...
...
@@ -600,6 +603,12 @@ int main (int argc, char **argv)
exit
(
EXIT_FAILURE
);
}
if
(
method
!=
NULL
)
{
if
(
strcmp
(
method
,
"rc4"
)
==
0
)
{
_method
=
RC4_ENC
;
}
}
if
(
f_flags
)
{
/* Our process ID and Session ID */
...
...
@@ -653,7 +662,7 @@ int main (int argc, char **argv)
_remote_port
=
strdup
(
remote_port
);
_timeout
=
atoi
(
timeout
);
LOGD
(
"calculating ciphers
"
);
LOGD
(
"calculating ciphers
%d"
,
_method
);
get_table
(
key
);
int
listenfd
;
...
...
jni/shadowsocks/local.h
View file @
bfa0f1cf
...
...
@@ -2,7 +2,7 @@
#include <ev.h>
#
define BUF_SIZE 4096
#
include "encrypt.h"
struct
listen_ctx
{
ev_io
io
;
...
...
libs/armeabi/shadowsocks
View file @
bfa0f1cf
No preview for this file type
res/values/strings.xml
View file @
bfa0f1cf
...
...
@@ -61,10 +61,15 @@
<string
name=
"copy_rights"
>
Shadowsocks is an open source socks proxy.\n\nYou can find more details here:\ngithub.com/shadowsocks
</string>
<string
name=
"about"
>
About
</string>
<string
name=
"proxy_type"
>
Proxy Type
</string>
<array
name=
"proxy_type_entry"
>
<item>
GAE
</item>
<item>
PaaS
</item>
<string
name=
"enc_method"
>
Encrypt Method
</string>
<array
name=
"enc_method_entry"
>
<item>
Table
</item>
<item>
RC4
</item>
</array>
<array
name=
"enc_method_value"
>
<item>
table
</item>
<item>
rc4
</item>
</array>
<string-array
name=
"gfw_list"
>
...
...
res/xml/shadowsocks_preference.xml
View file @
bfa0f1cf
...
...
@@ -39,6 +39,14 @@
android:summary=
"@string/sitekey_summary"
android:title=
"@string/sitekey"
>
</EditTextPreference>
<ListPreference
android:dependency=
"isRunning"
android:defaultValue=
"table"
android:key=
"encMethod"
android:entries=
"@array/enc_method_entry"
android:entryValues=
"@array/enc_method_value"
android:title=
"@string/enc_method"
>
</ListPreference>
</PreferenceCategory>
<PreferenceCategory
android:title=
"@string/fearute_cat"
>
<CheckBoxPreference
...
...
src/com/github/shadowsocks/Shadowsocks.java
View file @
bfa0f1cf
...
...
@@ -98,6 +98,7 @@ public class Shadowsocks extends PreferenceActivity implements
private
EditTextPreference
portText
;
private
EditTextPreference
remotePortText
;
private
EditTextPreference
sitekeyText
;
private
ListPreference
encMethodText
;
private
Preference
proxyedApps
;
private
CheckBoxPreference
isBypassAppsCheck
;
private
CheckBoxPreference
isRunningCheck
;
...
...
@@ -169,6 +170,7 @@ public class Shadowsocks extends PreferenceActivity implements
portText
=
(
EditTextPreference
)
findPreference
(
"port"
);
remotePortText
=
(
EditTextPreference
)
findPreference
(
"remotePort"
);
sitekeyText
=
(
EditTextPreference
)
findPreference
(
"sitekey"
);
encMethodText
=
(
ListPreference
)
findPreference
(
"encMethod"
);
proxyedApps
=
findPreference
(
"proxyedApps"
);
isBypassAppsCheck
=
(
CheckBoxPreference
)
findPreference
(
"isBypassApps"
);
...
...
@@ -343,6 +345,9 @@ public class Shadowsocks extends PreferenceActivity implements
if
(!
settings
.
getString
(
"sitekey"
,
""
).
equals
(
""
))
sitekeyText
.
setSummary
(
settings
.
getString
(
"sitekey"
,
""
));
if
(!
settings
.
getString
(
"encMethod"
,
""
).
equals
(
""
))
encMethodText
.
setSummary
(
settings
.
getString
(
"encMethod"
,
""
));
if
(!
settings
.
getString
(
"port"
,
""
).
equals
(
""
))
portText
.
setSummary
(
settings
.
getString
(
"port"
,
getString
(
R
.
string
.
port_summary
)));
...
...
@@ -416,6 +421,9 @@ public class Shadowsocks extends PreferenceActivity implements
sitekeyText
.
setSummary
(
getString
(
R
.
string
.
sitekey_summary
));
else
sitekeyText
.
setSummary
(
settings
.
getString
(
"sitekey"
,
""
));
else
if
(
key
.
equals
(
"encMethod"
))
if
(!
settings
.
getString
(
"encMethod"
,
""
).
equals
(
""
))
encMethodText
.
setSummary
(
settings
.
getString
(
"encMethod"
,
""
));
else
if
(
key
.
equals
(
"proxy"
))
if
(
settings
.
getString
(
"proxy"
,
""
).
equals
(
""
))
{
proxyText
.
setSummary
(
getString
(
R
.
string
.
proxy_summary
));
...
...
src/com/github/shadowsocks/ShadowsocksService.java
View file @
bfa0f1cf
...
...
@@ -164,6 +164,7 @@ public class ShadowsocksService extends Service {
private
boolean
isGFWList
=
false
;
private
boolean
isBypassApps
=
false
;
private
boolean
isDNSProxy
=
false
;
private
String
encMethod
;
private
ProxyedApp
apps
[];
private
Method
mSetForeground
;
private
Method
mStartForeground
;
...
...
@@ -205,8 +206,8 @@ public class ShadowsocksService extends Service {
@Override
public
void
run
()
{
final
String
cmd
=
String
.
format
(
BASE
+
"shadowsocks -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\""
,
appHost
,
remotePort
,
port
,
sitekey
);
"shadowsocks -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\"
-m \"%s\"
"
,
appHost
,
remotePort
,
port
,
sitekey
,
encMethod
);
Node
.
exec
(
cmd
);
}
}.
start
();
...
...
@@ -238,6 +239,7 @@ public class ShadowsocksService extends Service {
appHost
=
settings
.
getString
(
"proxy"
,
"127.0.0.1"
);
sitekey
=
settings
.
getString
(
"sitekey"
,
"default"
);
encMethod
=
settings
.
getString
(
"encMethod"
,
"table"
);
try
{
remotePort
=
Integer
.
valueOf
(
settings
.
getString
(
"remotePort"
,
"1984"
));
}
catch
(
NumberFormatException
ex
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment