Giter Site home page Giter Site logo

jstun's Introduction

Build Status Maven Central

"JSTUN" - Java Simple Traversal of User Datagram Protocol (UDP) Through Network Address Translation (NAT)

(by Thomas King - king[at]t-king.de)

What is "JSTUN"?

"JSTUN" is a Java-based STUN (Simple Traversal of User Datagram Protocol (UDP) Through Network Address Translation (NAT)) implementation. STUN provides a mean for applications to discover the presence and type of firewalls or NATs between them and the public internet. Additionally, in presence of a NAT STUN can be used by applications to learn the public Internet Protocol (IP) address assigned to the NAT.

So far, most of the message headers and attributes as standardized in RFC 3489 are part of "JSTUN". The current "JSTUN" version also includes a STUN client and a STUN server. "JSTUN" is dual-licensed under GNU General Public License iversion 2.0 and Apache License version 2.0.

How does it work?

STUN is described in RFC 3489. A STUN server is running on jstun.javawi.de:3478.

Just invoke "java -cp jstun-0.7.4.jar:slf4j-api-1.5.6.jar:slf4j-jdk14-1.5.6.jar de.javawi.jstun.test.demo.DiscoveryTestDemo" or use the de.javawi.jstun.test.demo.DiscoveryTest and de.javawi.jstun.test.demo.BindingLifetimeTest classes in order to start the STUN client.

A "JSTUN"-based STUN server is also available. Just try it (assuming you own a dual-homed machine): java -cp jstun-0.7.4.jar:slf4j-api-1.5.6.jar:slf4j-jdk14-1.5.6.jar de.javawi.jstun.test.demo. StunServer PORT1 IP1 PORT2 IP2.

What about RFC 5389?

I am looking for a way to enhance the current "JSTUN" implementation to support the new Session Traversal Utilities for NAT (STUN) protocol as described in RFC 5389. If you are interested in supporting this effort with code or money please drop me a mail (king[at]t-king.de).

Limits?

Due to the lack of fully RFC compliant STUN servers I could not test the shared secret request / response functionality. Additionally, the message attribute username, password and message integrity are not tested for the same reason. The implementation of the message attribute message integrity is not completed, because I see no reason to add a cryptographic library as long as no public available STUN server supports message integrity.

The reality is not as dark as it might seem after reading the previous section. All tested STUN servers provided a minimal set of functionality that is required to discover firewalls and NATs.

If you found a bug or if you want to implement enhancements or additional functionalities please do not hesitate to contact me.

What do you need?

A Java 6 compliant Java Runtime Environment is required by "JSTUN".

jstun's People

Contributors

guusdk avatar krial057 avatar tbutter avatar tking avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jstun's Issues

Cannot assign requested address (Bind failed)

Hello! I trying start stun server. such a parameter set public ip address, and because server not have second ip then as second ip set another. but when I start take error

java.net.BindException: Cannot assign requested address (Bind failed)
at java.net.PlainDatagramSocketImpl.bind0(Native Method)
at java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:93)
at java.net.DatagramSocket.bind(DatagramSocket.java:392)
at java.net.DatagramSocket.(DatagramSocket.java:242)
at java.net.DatagramSocket.(DatagramSocket.java:299)
at de.javawi.jstun.test.demo.StunServer.(StunServer.java:52)
at de.javawi.jstun.test.demo.StunServer.main(StunServer.java:271)

then I try start two server and set two address in start, but still get error. Maybe I completely do not understand how run self server. Server was run in AWS EC2.

A variable in Username.java seems to has not been declared before using.

Hi, king. I am a beginner of programing.

Your code is awesome. But in the morning, I read the Username.java. I was puzzled that why the variable named type was not declared before using.

public byte[] getBytes() throws UtilityException {
		int length = username.length();
		// username header
		if ((length % 4) != 0) {
			length += 4 - (length % 4);
		}
		// message attribute header
		length += 4;
		byte[] result = new byte[length];
		// message attribute header
		// type
		System.arraycopy(Utility.integerToTwoBytes(typeToInteger(type)), 0, result, 0, 2);
		// length
		System.arraycopy(Utility.integerToTwoBytes(length-4), 0, result, 2, 2);
		
		// username header
		byte[] temp = username.getBytes();
		System.arraycopy(temp, 0, result, 4, temp.length);
		return result;
}

Looking forward to your reply, thank you!

It should be possible to stop the StunServer

When starting the StunServer, it will, under normal circumstances, open sockets and start listening indefinitely. There is no way of stopping the server, apart from killing the JVM.

The StunServer should get a facility that allows it to shutdown gracefully. as there's a start method, a corresponding stop method seems obvious.

Library is dual licensed (apache and gpl) but github project claims MIT license

Hi guys :)

I noticed there is an inconsistency between the code and the project licensing. On the github project page, the license is MIT. But in the code the licensing is dual licensed.

The dual licensing prevents commercial use due to the fact you would have to make our code GPL as well. We cannot use it in our company because of that.

I decided to write because I thought maybe that is a mistake and MIT is really the license you wished to use? If you want to use MIT, then the two license files in the repo and the licensing section in the pom.xml file would have to be changed.

Let me know!

  • Nicolas

NAT type discovery returned is incorrect

I am trying to find my NAT type but its returning incorrect type as Full Cone Nat while my actual NAT type is symmetric. my source port gets changed everytime when I make stun request. Seems like test2() method need some modification.

ICENegotiator fails with remote candidate

Hi TKing,

I am wondering about the following: maybe i am misinterpreting it. But when resolving local and remote candidates with the ICENegotiator, We get an exception when doing remote candidates.

It is logical the remote ip cannot be bound locally, because it is the router's IP and not the machines IP. Only the local ip is added after this exception offcourse. Is this normal behaviour: not returning the remote candidate?

I have added sysout calls to log what was happening.

add host candidate [local] /192.168.1.10
add server reflexive address, Discovery Info:
Network interface: en1
Local IP address: 192.168.1.10
Result: Symmetric Cone NAT handles connections.
Public IP address: 10.0.10.10

[remote] /10.0.10.10
java.net.BindException: Can't assign requested address
at java.net.PlainDatagramSocketImpl.bind0(Native Method)
at java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:95)
at java.net.DatagramSocket.bind(DatagramSocket.java:376)
at java.net.DatagramSocket.(DatagramSocket.java:231)
at java.net.DatagramSocket.(DatagramSocket.java:284)
at de.javawi.jstun.test.demo.ice.Candidate.(Candidate.java:44)
at de.javawi.jstun.test.demo.ice.ICENegotiator.gatherCandidateAddresses(ICENegotiator.java:98)
at de.javawi.jstun.test.demo.ice.ICENegotiator.main(ICENegotiator.java:186)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Add junit

It might be helpful to add the junit jar to the lib directory

OSGI ready?

Hi,

I was wondering if JSTUN is OSGI ready, I would like to run it next to other services.

Best regards
Gino

0x0020: XOR-MAPPED-ADDRESS

STUN Attributes types 0x0020: XOR-MAPPED-ADDRESS
not support, generate:

UnknownMessageAttributeException("Unkown mandatory message attribute");

Enable Travis CI integration

Travis is a free continuous integration platform, that integrates easily with Github-based Maven projects (among many, many others). By using it, every pull request would be automatically build by Travis, which will provide feedback on compile and/or test failures.

Setting it up is trivial, but requires you to allow Travis some permissions on this repository. After that, a single textfile is to be added to the root of the project. The textfile should be named .travis.yml (starts with a dot), and should contain this single line:

language: java

There's a wealth of further information available, but this is the absolute beginners guide to Travis: https://docs.travis-ci.com/user/for-beginners

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.