Encrypt traffic with VpnService - android

I've searched for a solution for 2 days.
The problem is: i need to create the app for encrypting (with some custom algorithm) all internet traffic from a device.
I've found that I can use vpn and android provides me a class VpnService. I don't understand how to encrypt the tcp packets with VpnService class.
Could anyone help me please?

By using VpnService, you can get all the IP packet routed to your interface.
What you get here, is IP packet, which takes TCP/UDP packet as payload.
The the IP packet should be tunneled to remote server.
Encrypt the traffic with remote server is what you need.

Related

Capturing packets from Android VPNService and transfer them over sockets to proxy server

Intention is to intercept all the traffic from the android device. I did this previously by creating a local proxy server and manually adding it in the wifi settings of the device. But now to avoid that we need that settings need not be changed and packets get intercepted automatically. For this purpose I employed AndroidVpnService, using this I am able to capture the packets but these are raw IP packets. I am not using the VPN tunnel since it seems it happens to support remote servers while I am having a local proxy server in place. Thus I am using simple JAVA sockets but the raw ip packets cannot be transmitted over these sockets especially due to difference in network layers at which they operate. Any suggestions on how can I make that happen or may be construct the suitable headers for transferring the packets over socket to connect to the internet and get the response back?

Using packets gotten from devices connected to an android device's hotspot interface

I created a VPN using android's VPNService class. Now, I want this VPN to also handle packets from the device's hotspot interface. So in the VPNService Builder, I called the addRoute("0.0.0.0",0). This made sure I got all outgoing packets including the Hotspot.
The problem I am currently facing is that when I get packets redirected from the hotspot, the packets seem to still have IPs from the hotspot network. 192.168.43.... both in the source field and destination fields of the IP packets and the payload doesn't seem to contain a TCP packet either.
My questions are:
Why does the hotspot packet I receive from the VPN interface not have the same source IP as that of the VPN interface created by VPNService class?
Is there another layer the packets from the hotspot are packaged for since I can't seem to get a remote Address for the real request in the IP headers?
Is my VPNInterface setup wrongly?
My interface was setup correctly.
Apparently, what I was getting then were DHCP packets. DHCPOFFER Packets from Android's Local DHCP Servers.
Even though android's VPN interface is setup to get all outgoing packets on a device, it doesn't seem to get broadcast packets but for some reason, it gets replies to broadcast packets.
I wonder why it was designed that way.
Understanding this helped me solve my problem.

Android vpn Service

I am trying to implement kind of android firewall via vpnService. So far I managed to get all the incoming packets to my VPN service. I need help to parse the packets and get destination IP address and source IP address with their ports! in order to open new socket connection and forward the packet to it's destination.
In addition, Is it enough to forward only the data of the packet to the destination or I need to forward it as is with the headers?
Any
You help is much appreciated.
Always try to post your current code if you want better answers.
As for your question, I understand so far you only have all the traffic routed into your application but you haven't been able to read it. You will need to decode the headers of TCP, UDP and even IP to get that info. Read a bit about the protocols. Wireshark is a good tool.
Have a look at this question: "Android firewall with VpnService"
Your application will essentially need to be able to interpret and construct IPv4 and IPv6 headers and options, and as the IP payload, the UDP headers and TCP headers and options.

Receiving data through wifi connection

I'm trying to make the following work, and wonder if it is possible:
I want to send data from a hardware piece to an android device. Although the hardware only has an Ethernet connection available.
If I were to make an Ethernet connection from the hardware piece to a router, and then communicate from the router to the android device with WiFi, is there any way I could tell the android device, just receive data from the WiFi?
Using IP protocol will allow you to communicate over any IP network.
Easiest way to do that is using TCP sockets that uses Server/Client relation to communicate.
I'm guessing you are using a microcontroller (arduino?) if that is the case there are many IP labraries and examples you can look at.
after writing the server code on the hardware then you can easily use sockets to connect to it from android, here is an example on how to connect android client to TCP server.
TCP Client tutorial
Extra links:
TCP on Wikipedia no need to read the implimentation details just understand the concept.
Java All about Sockets Great overview of socket programming and should get you ready to write effective code on the android side.
LAN wikipedea article about LANs

Establishing a sip proxy server on PC with Android clients

I have implemented a sip based real time voice transfer under the impression that two of my phones on the same WIFI network can communicate provided that they have each others IP addresses. However, I could not make it work... I am using rtp to transfer voice between these clients.
Also, it's come to my notice that using a PC on the WIFI network as server is better. Now, can I use this PC as a proxy server to establish a sip end to end connection? If yes, how?
Are there existing implementations for initializing a session? Specifically, if someone could give me an example on what address/ports I would need both of my clients to establish the connection to, it would be great.
If you have implemented correctly all the necessary parts that SIP protocol demands, then you have to install a SIP server on your PC and just create two accounts that the phones will connect with them on the server. I have tried with Android the Asterisk server, but I am sure that there will be many others out there...
By default SIP servers are listening on port 5060 using UDP. This port is used only for the initiation of the session (and other control messages) and NOT for the transfer of RTP packets.

Categories

Resources