Skip to content

Commit

Permalink
initial update
Browse files Browse the repository at this point in the history
  • Loading branch information
dashsp committed May 25, 2015
0 parents commit 0defec7
Show file tree
Hide file tree
Showing 27 changed files with 2,917 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ignore output folders
.idea/
out/
target/

# ignore files
config.json
*.iml

30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
shadowsocks-java is distributed under the following BSD-style license:

Copyright (c) 2015, Blake <stfl0622@gmail.com>
All Rights Reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
shadowsocks-java
================

shadowsocks-java is a pure JAVA client for [shadowsocks](https://github.com/shadowsocks/shadowsocks) project.

Only tested AES encryption.

### Requirements
* Bouncy Castle v1.5.2 [Release](https://www.bouncycastle.org/)
* json-simple v1.1.1 [Release](https://code.google.com/p/json-simple/)

### Developers
* Using Non-blocking server
Config config = new Config("SS_SERVER_IP", "SS_SERVER_PORT", "LOCAL_IP", "LOCAL_PORT", "CIPHER_NAME", "PASSWORD");
NioLocalServer server = new NioLocalServer(config);
new Thread(server).start();
* Using blocking server
Config config = new Config("SS_SERVER_IP", "SS_SERVER_PORT", "LOCAL_IP", "LOCAL_PORT", "CIPHER_NAME", "PASSWORD");
LocalServer server = new LocalServer(config);
new Thread(server).start();
51 changes: 51 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.stfl</groupId>
<artifactId>shadowsocks-java</artifactId>
<version>0.1-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.52</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<!-- remove junit dependency since it's not required during runtime -->
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
125 changes: 125 additions & 0 deletions src/main/java/com/stfl/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.stfl;

import com.stfl.misc.Config;
import com.stfl.misc.Util;
import com.stfl.network.LocalServer;
import com.stfl.network.NioLocalServer;
import com.stfl.ss.CryptFactory;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.logging.Logger;

public class Main {

public static void main(String[] args) {
Logger logger = Logger.getLogger(Main.class.getName());
Config config;

config = parseArgument(args);
if (config == null) {
printUsage();
return;
}

String s = config.saveToJson();
PrintWriter writer = null;
try {
writer = new PrintWriter("config.json");
writer.println(s);
writer.close();
} catch (FileNotFoundException e) {
logger.warning("Unable to save config");
}

try {
//LocalServer server = new LocalServer(config);
NioLocalServer server = new NioLocalServer(config);
Thread t = new Thread(server);
t.start();
logger.info("Shadowsocks-Java v" + Util.getVersion());
logger.info("Server starts at port: " + config.getLocalPort());
t.join();
} catch (Exception e) {
e.printStackTrace();
}
}

private static Config parseArgument(String[] args) {
Config config = new Config();

if (args.length == 2) {
if (args[0].equals("--config")) {
Path path = Paths.get(args[1]);
try {
String json = new String(Files.readAllBytes(path));
config.loadFromJson(json);
} catch (IOException e) {
System.out.println("Unable to read configuration file: " + args[1]);
return null;
}
return config;
}
else {
return null;
}
}

if (args.length != 8) {
return null;
}

// parse arguments
for (int i = 0; i < args.length; i+=2) {
String[] tempArgs;
if (args[i].equals("--local")) {
tempArgs = args[i+1].split(":");
if (tempArgs.length < 2) {
System.out.println("Invalid argument: " + args[i]);
return null;
}
config.setLocalIpAddress(tempArgs[0]);
config.setLocalPort(Integer.parseInt(tempArgs[1]));
}
else if (args[i].equals("--remote")) {
tempArgs = args[i+1].split(":");
if (tempArgs.length < 2) {
System.out.println("Invalid argument: " + args[i]);
return null;
}
config.setRemoteIpAddress(tempArgs[0]);
config.setRemotePort(Integer.parseInt(tempArgs[1]));
}
else if (args[i].equals("--cipher")) {
config.setMethod(args[i+1]);
}
else if (args[i].equals("--password")) {
config.setPassword(args[i + 1]);
}
}

return config;
}

private static void printUsage() {
System.out.println("Usage: ss --[option] value --[option] value...");
System.out.println("Option:");
System.out.println(" --local [IP:PORT]");
System.out.println(" --remote [IP:PORT]");
System.out.println(" --cipher [CIPHER_NAME]");
System.out.println(" --password [PASSWORD]");
System.out.println(" --config [CONFIG_FILE]");
System.out.println("Support Ciphers:");
for (String s : CryptFactory.getSupportedCiphers()) {
System.out.printf(" %s\n", s);
}
System.out.println("Example:");
System.out.println(" ss --local \"127.0.0.1:1080\" --remote \"[SS_SERVER_IP]:8080\" --cipher \"aes-256-cfb\" --password \"HelloWorld\"");
System.out.println(" ss --config config.json");

}
}
Loading

0 comments on commit 0defec7

Please sign in to comment.