Skip to content

Commit

Permalink
status save
Browse files Browse the repository at this point in the history
  • Loading branch information
KagayamaKaede committed Nov 28, 2015
1 parent c169b01 commit 4139a7e
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 5,794 deletions.
6 changes: 6 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
##1.1.3 Beta

+ Fixed start fail when first start vpn.
+ Fixed RC4-MD5 crypto.
+

##1.1.2 Beta

+ Improve network operate speed.
Expand Down
3 changes: 0 additions & 3 deletions Readme.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

##计划

* 完成 Kotlin 版本的 Shadowsocks.
* 完善材料设计UI.
* 提升性能,降低内存和电池使用率。
* 修复bug.
* 写 Kotlin 版本的 ShadowsocksR 插件。

##开发

Expand Down
3 changes: 0 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ Compatible Shadowsocks protocol and support some ShadowsocksR function.

##Plans

* Full Kotlin implementation of Shadowsocks stable function.
* Improve the material design UI.
* Improve performance, reduce memory and battery usage.
* Fix bug.
* Write Kotlin implementation of ShadowsocksR plugin.

##Develop

Expand Down
Binary file modified app/libs/armeabi-v7a/libJni.so
Binary file not shown.
Binary file modified app/libs/x86/libJni.so
Binary file not shown.
2 changes: 1 addition & 1 deletion app/src/main/java/com/proxy/shadowsocksr/Jni.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public final class Jni
System.loadLibrary("Jni");
}

public static native int exec(String cmd);
//public static native int exec(String cmd);

public static native String getABI();

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/proxy/shadowsocksr/SSRNatService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.proxy.shadowsocksr

import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.IBinder
import android.content.*
import android.content.pm.PackageManager
import android.net.ConnectivityManager
import android.os.IBinder
import android.os.RemoteException
import android.support.v4.app.NotificationCompat
import android.support.v4.content.ContextCompat
Expand Down Expand Up @@ -341,8 +341,8 @@ class SSRNatService : Service()
killProcesses()
//
Thread({
if (!InetAddressUtil.Companion.isIPv4Address(connProfile!!.server) &&
!InetAddressUtil.Companion.isIPv6Address(connProfile!!.server))
if (!InetAddressUtil.isIPv4Address(connProfile!!.server) &&
!InetAddressUtil.isIPv6Address(connProfile!!.server))
{
val du: DNSUtil = DNSUtil()
var ip = du.resolve(connProfile!!.server, true)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/proxy/shadowsocksr/SSRVPNService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ class SSRVPNService() : VpnService(), OnNeedProtectTCPListener, OnNeedProtectUDP
cmd += " --netif-ip6addr ${PRIVATE_VLAN6.format("2")}"
}

cmd += " --enable-udprelay"
//cmd += " --enable-udprelay"

if (connProfile!!.dnsForward)
{
Expand Down
66 changes: 36 additions & 30 deletions app/src/main/java/com/proxy/shadowsocksr/fragment/PrefFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import android.preference.CheckBoxPreference
import android.preference.Preference
import android.preference.PreferenceFragment
import android.preference.PreferenceManager
import android.support.v4.view.ViewCompat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ListView

import com.orhanobut.hawk.Hawk
import com.proxy.shadowsocksr.Consts
Expand Down Expand Up @@ -81,20 +86,21 @@ class PrefFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceC
}
}

// override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
// savedInstanceState: Bundle?): View?
// {
// val v = super.onCreateView(inflater, container, savedInstanceState)
//
// if (v != null)
// {
// val lv = v.findViewById(android.R.id.list) as ListView
// ViewCompat.setNestedScrollingEnabled(lv, true)
// lv.clipToPadding = false
// //lv.setPadding(0, 0, 0, ScreenUtil.getNavigationBarSize(getActivity()).y);
// }
// return super.onCreateView(inflater, container, savedInstanceState)
// }
// override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
// savedInstanceState: Bundle?): View?
// {
// val v = super.onCreateView(inflater, container, savedInstanceState)
//
// if (v != null)
// {
// val lv = v.findViewById(android.R.id.list) as ListView
// ViewCompat.setNestedScrollingEnabled(lv, true)
// //lv.clipToPadding = false
// ////lv.setPadding(0, 0, 0, ScreenUtil.getNavigationBarSize(getActivity()).y);
// //
// }
// return super.onCreateView(inflater, container, savedInstanceState)
// }

override fun onResume()
{
Expand Down Expand Up @@ -151,14 +157,14 @@ class PrefFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceC
var jump = false
when (key)
{
"route" -> globalProfile!!.route = sp.getString(key, "bypass-lan")
"ipv6_route" -> globalProfile!!.ipv6Route = sp.getBoolean("ipv6_route", false)
"route" -> globalProfile!!.route = sp.getString(key, "bypass-lan")
"ipv6_route" -> globalProfile!!.ipv6Route = sp.getBoolean("ipv6_route", false)
"proxy_work_mode" ->
globalProfile!!.vpnMode = sp.getBoolean("proxy_work_mode", true)
"global_proxy" -> globalProfile!!.globalProxy = sp.getBoolean(key, false)
"udp_dns" -> globalProfile!!.dnsForward = sp.getBoolean(key, true)
"auto_connect" -> globalProfile!!.autoConnect = sp.getBoolean(key, false)
else -> jump = true
"global_proxy" -> globalProfile!!.globalProxy = sp.getBoolean(key, false)
"udp_dns" -> globalProfile!!.dnsForward = sp.getBoolean(key, true)
"auto_connect" -> globalProfile!!.autoConnect = sp.getBoolean(key, false)
else -> jump = true
}
if (!jump)
{
Expand All @@ -184,7 +190,7 @@ class PrefFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceC

when (key)
{
"label" ->
"label" ->
{
var changed: String = sp.getString(key, currentSvr + System.currentTimeMillis())
val lst = Hawk.get<ArrayList<String>>("ServerList")
Expand All @@ -206,18 +212,18 @@ class PrefFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceC
return
}

"server" -> ss.server = sp.getString(key, Consts.defaultIP)
"remote_port" -> ss.remotePort = Integer.valueOf(sp.getString(
"server" -> ss.server = sp.getString(key, Consts.defaultIP)
"remote_port" -> ss.remotePort = Integer.valueOf(sp.getString(
key, Consts.defaultRemotePort.toString()))!!
"local_port" -> ss.localPort = Integer.valueOf(sp.getString(
"local_port" -> ss.localPort = Integer.valueOf(sp.getString(
key, Consts.defaultLocalPort.toString()))!!
"crypt_method" -> ss.cryptMethod = sp.getString(key, Consts.defaultCryptMethod)
"password" -> ss.passwd = sp.getString(key, "")
"crypt_method" -> ss.cryptMethod = sp.getString(key, Consts.defaultCryptMethod)
"password" -> ss.passwd = sp.getString(key, "")
"protocol_type" -> ss.tcpProtocol = sp.getString(key, Consts.defaultTcpProtocol)
"obfs_method" -> ss.obfsMethod = sp.getString(key, Consts.defaultObfsMethod)
"obfs_param" -> ss.obfsParam = sp.getString(key, "")
"tcp_over_udp" -> ss.tcpOverUdp = sp.getBoolean(key, false)
"udp_over_tcp" -> ss.udpOverTcp = sp.getBoolean(key, false)
"obfs_method" -> ss.obfsMethod = sp.getString(key, Consts.defaultObfsMethod)
"obfs_param" -> ss.obfsParam = sp.getString(key, "")
"tcp_over_udp" -> ss.tcpOverUdp = sp.getBoolean(key, false)
"udp_over_tcp" -> ss.udpOverTcp = sp.getBoolean(key, false)
}
Hawk.put(currentSvr, ss)
}
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/proxy/shadowsocksr/impl/AddressUtils.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.proxy.shadowsocksr.impl

import java.util.*
import java.util.regex.Matcher
import java.util.regex.Pattern

Expand All @@ -13,7 +12,8 @@ object AddressUtils

fun ipv4BytesToIp(bytes: ByteArray): String
{
return StringBuilder().append(bytes[0].toInt() and 255).append('.')
return StringBuilder()
.append(bytes[0].toInt() and 255).append('.')
.append(bytes[1].toInt() and 255).append('.')
.append(bytes[2].toInt() and 255).append('.')
.append(bytes[3].toInt() and 255).toString()
Expand Down Expand Up @@ -59,13 +59,13 @@ object AddressUtils

var addLong = ip.toLong() and UNSIGNED_INT_MASK
var lowLong = ((broadcast.toLong() and UNSIGNED_INT_MASK) -
(if ((network.toLong() and UNSIGNED_INT_MASK) > 1L)
network.toLong() + 1L
else 0L)).toLong() and UNSIGNED_INT_MASK
(if ((network.toLong() and UNSIGNED_INT_MASK) > 1L)
network.toLong() + 1L
else 0L)).toLong() and UNSIGNED_INT_MASK
var highLong = ((broadcast.toLong() and UNSIGNED_INT_MASK) -
(if ((network.toLong() and UNSIGNED_INT_MASK) > 1L)
broadcast.toLong() - 1L
else 0L)).toLong() and UNSIGNED_INT_MASK
(if ((network.toLong() and UNSIGNED_INT_MASK) > 1L)
broadcast.toLong() - 1L
else 0L)).toLong() and UNSIGNED_INT_MASK
if (addLong >= lowLong && addLong <= highLong)
{
return true;
Expand Down
74 changes: 34 additions & 40 deletions app/src/main/java/com/proxy/shadowsocksr/impl/ImplUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.proxy.shadowsocksr.impl

import android.util.Log
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import java.security.SecureRandom
import java.util.*
import java.util.zip.CRC32

object ImplUtils
{
private val md5: MessageDigest = MessageDigest.getInstance(
"MD5")// i think all api14+ devices have md5

fun fillCRC32(src: ByteArray, dst: ByteArray, dstOff: Int)
{
val crc32 = CRC32()
Expand All @@ -30,10 +32,7 @@ object ImplUtils
private val srnd: SecureRandom = SecureRandom()
private val rnd: Random = Random()

fun randomInt(up: Int): Int
{
return rnd.nextInt(up)
}
fun randomInt(up: Int): Int = rnd.nextInt(up)

fun randomBytes(cnt: Int): ByteArray
{
Expand Down Expand Up @@ -66,9 +65,9 @@ object ImplUtils
}
when (buf[0].toInt() and 0xFF)
{
1 -> return 7 //ipv4
3 -> return 4 + (buf[1].toInt() and 0xFF) //domain
4 -> return 19 //ipv6
1 -> return 7 //ipv4
3 -> return 4 + (buf[1].toInt() and 0xFF) //domain
4 -> return 19 //ipv6
else -> return dft
}
}
Expand All @@ -77,49 +76,44 @@ object ImplUtils
{
val result = ByteArray(password.size + 16)
var i = 0
var md5: ByteArray = ByteArray(0)
var md: ByteArray = ByteArray(0)

while (i < key.size)
{
try
if (i == 0)
{
val md = MessageDigest.getInstance("MD5")
if (i == 0)
{
md5 = md.digest(password)
}
else
{
System.arraycopy(md5, 0, result, 0, md5.size)
System.arraycopy(password, 0, result, md5.size, password.size)
md5 = md.digest(result)
}
System.arraycopy(md5, 0, key, i, md5.size)
i += md5.size
md = md5.digest(password)
}
catch(ignored: NoSuchAlgorithmException)
else
{
System.arraycopy(md, 0, result, 0, md.size)
System.arraycopy(password, 0, result, md.size, password.size)
md = md5.digest(result)
}
System.arraycopy(md, 0, key, i, md.size)
i += md.size
}
}

fun fillIntAsBytes(i: Int, dst: ByteArray, dstOff: Int)
{
dst[dstOff] = i.toByte()
dst[dstOff + 1] = (i shr 8).toByte()
dst[dstOff + 2] = (i shr 16).toByte()
dst[dstOff + 3] = (i shr 24).toByte()
}
fun getMD5(src: ByteArray): ByteArray = md5.digest(src)

fun bytesHexDmp(tag: String, bytes: ByteArray)
{
val sb = StringBuilder()
for (b in bytes)
{
sb.append("%02X ".format(b))
}
Log.e(tag, sb.toString())
}
fun fillIntAsBytes(i: Int, dst: ByteArray, dstOff: Int)
{
dst[dstOff] = i.toByte()
dst[dstOff + 1] = (i shr 8).toByte()
dst[dstOff + 2] = (i shr 16).toByte()
dst[dstOff + 3] = (i shr 24).toByte()
}

fun bytesHexDmp(tag: String, bytes: ByteArray)
{
val sb = StringBuilder()
for (b in bytes)
{
sb.append("%02X ".format(b))
}
Log.e(tag, sb.toString())
}
//
// fun bufHexDmp(tag: String, bb: ByteBuffer)
// {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.proxy.shadowsocksr.impl.crypto.crypto

import com.google.code.commons.checksum.ChecksumUtils
import android.util.Log
import com.proxy.shadowsocksr.impl.ImplUtils
import org.spongycastle.crypto.StreamCipher
import org.spongycastle.crypto.engines.RC4Engine
Expand All @@ -14,22 +14,20 @@ class RC4MD5Crypto(cryptMethod: String, key: ByteArray) : AbsCrypto(cryptMethod,
//rc4-md5 spec: https://github.com/shadowsocks/shadowsocks/issues/178
override fun updateEncryptIV(iv: ByteArray)
{
val bts = ByteArray(key.size + iv.size)
var bts = ByteArray(key.size + iv.size)
System.arraycopy(key, 0, bts, 0, key.size)
System.arraycopy(iv, 0, bts, key.size, iv.size)
ImplUtils.fillCRC32(bts, bts, 0)
e.reset()
bts = ImplUtils.getMD5(bts)
e.init(true, KeyParameter(bts))
}

override fun updateDecryptIV(iv: ByteArray)
{
val bts = ByteArray(key.size + iv.size)
var bts = ByteArray(key.size + iv.size)
System.arraycopy(key, 0, bts, 0, key.size)
System.arraycopy(iv, 0, bts, key.size, iv.size)
ImplUtils.fillCRC32(bts, bts, 0)
d.reset()
d.init(true, KeyParameter(bts))
bts = ImplUtils.getMD5(bts)
d.init(false, KeyParameter(bts))
}

override fun encrypt(data: ByteArray): ByteArray
Expand Down
Loading

0 comments on commit 4139a7e

Please sign in to comment.