UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » How to send a file on socket

#1 2007-09-27 12:11 PM

mehdiizadeh
Member
From: Malaysia
Registered: 2007-09-18
Posts: 10

Re: How to send a file on socket

Hi All

Is it possible to use Sendto() to sending a small file not buffer or string?
I need to protect the data when sending to destination.
I read about encryption in C programmin like XOR encryption, but when using encryption, no one can see the data without key but can change the content of buffer or string.
I think maybe saving the string on the file and compressing with password, then sending this file to destination can protect data.
is it possible?

Any suggestion or help will be very appreciated.
Thanks

Offline

#2 2007-09-27 12:52 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: How to send a file on socket

I'm not sure I understand what you're asking at all...

If you want to send the contents of a file over a socket, you can do that by simply
reading in the contents and sending via normal write()/send()/sendto() calls...  Or,
if your system has sendfile(), you can use that instead...  You also probably want to
prefix the data with other info about the file, such as filename, size, perms, etc., so
the receiving side can save it properly (and the size so it knows how much data to
receive)...

Now, what the hell that all has to do with encryption or compression, I haven't the
faintest clue...  So, perhaps I'm just not understanding your question at all...

Offline

#3 2007-09-27 01:44 PM

mehdiizadeh
Member
From: Malaysia
Registered: 2007-09-18
Posts: 10

Re: How to send a file on socket

Thanks Rob for quick reply and Sorry if my question is not clear.

I want to send one string like "ABCDE" with some prefix to receiver, this string should be locked or compressed with a key. i need to show that receiver after receiving can open and see this string if it has the key. otherwise can't even open that. possible?
XOR encryption will encrypt the "ABCDE" with one key and receiver will decrypt correctly with same key. without the key receiver can change this encrypted string like this:

.
.
for (i=0, i<5; i++)
{
string[i] +=1;
}
.
.

is there any way to prevent the receiver to modify it without the key?

I hope i have explained better to understand.
Thanks for any suggestion

Offline

#4 2007-09-27 04:24 PM

jfriesne
Administrator
From: California
Registered: 2005-07-06
Posts: 348
Website

Re: How to send a file on socket

Offline

#5 2007-09-27 07:25 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: How to send a file on socket

Offline

#6 2007-09-27 08:02 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: How to send a file on socket

How exactly is SSL preventing man-in-the-middle attacks Rob? As far as I know it
doesn't, all it does is storing the peer's public key and checking that the next time it
connects, it's still the same. But that's not really preventing man-in-the-middle
attacks, just hampering them.

But the case described here, with both peers knowing a secret key, is very simple
and safe against man-in-the-middle. (Add secure key management and distribution,
replay attack preventions, a real crypto ciper instead of XOR and it might be overall
secure too).

Offline

#7 2007-09-27 08:44 PM

HectorLasso
Administrator
From: Colombia
Registered: 2002-06-12
Posts: 353

Re: How to send a file on socket

Offline

#8 2007-09-27 09:05 PM

mehdiizadeh
Member
From: Malaysia
Registered: 2007-09-18
Posts: 10

Re: How to send a file on socket

Thanks alot for all your answers and guide

Actually i wanted to show man-in-the-middle attack on Mobile IPv6 Testbed but i couldn't.
that's why i changed the data string on the receiver part.
my scenario is: one node(mobile node) is generating the ipv6 packets send to destination (correspondent node) via pc-based router.
MN put flag (prefix like 'X') on some packets and sending data (e.g "ABCDE") to CN, when CN receive them, it return those flaged packets back to MN,
then MN compares them and see whether any modification is happened or not.
if yes start to protect the packets to prevent the attacker from modification.

I'm student and new in this area and i'll search more about all your suggestion.
i'll will very appreciate if you give me suitable references to help me to do it faster.
please give me your suggestion.
Thanks alot

Offline

#9 2007-09-27 09:19 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: How to send a file on socket

Offline

#10 2007-09-27 09:21 PM

HectorLasso
Administrator
From: Colombia
Registered: 2002-06-12
Posts: 353

Re: How to send a file on socket

Offline

#11 2007-09-27 09:28 PM

HectorLasso
Administrator
From: Colombia
Registered: 2002-06-12
Posts: 353

Re: How to send a file on socket

Offline

#12 2007-09-28 01:25 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: How to send a file on socket

Offline

#13 2007-09-29 07:20 PM

mehdiizadeh
Member
From: Malaysia
Registered: 2007-09-18
Posts: 10

Re: How to send a file on socket

Thanks again to all of you for your good explanation, so i have new issues to investigate.

some more questions, any suggestion will be very appreciated.

1.when i used XOR encryption (Just for testing) the stirng changed to nasty character but receiver can decrypt it correctly.
can sendto() send any character?

2. is possible to run two programm at the same time that can access to one port using recvfrom()

recvfrom (s, buffer, 2000, 0, (struct sockaddr*)&a, sizeof(a));


if one programm modify the buffer, another programm will be affected?

3. i'm using UDP connection, is SSL just for TCP connection? or can be used  with UDP.

4. in my testbed, between sender and receiver there is a pc (as a router) with fedora core 5 OS and Wireshark packet analyzer,
without encryption Wireshark shows data but with encryption no. any idea?

sorry if my last question is not related to this forum, just asking

Offline

#14 2007-09-30 06:06 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: How to send a file on socket

Offline

#15 2007-10-05 06:35 PM

mehdiizadeh
Member
From: Malaysia
Registered: 2007-09-18
Posts: 10

Re: How to send a file on socket

Thanks RobSeace, your guide helped me alot

I saw in other forums asking following question. any suggestion???

What would be wrong with using TLS as the basis for a secure channel, with some sort of multiplexing layer on top of that,
a system in which you have a secure channel between each pair of connected onion routers, and then the client builds a stack of nested TLS session for each hop it wants to route through.

Offline

#16 2007-10-05 07:40 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: How to send a file on socket

Um, I'm not sure of the context that question was asked in, or what exactly you
want to know?

I'm not too up on my onion-routing knowledge...  I only know of the basic concept
vaguely, with no first-hand experience...

But, if I understand the question, you want to tunnel multiple logically separate
streams over a single SSL/TLS tunnel?  Sure, no reason you couldn't do so, if
you designed the end-points to handle it correctly...  (Effectively, that's what SSH
does: it's capable of forwarding multiple streams of data through its single connection
to do port-forwarding and such...)

Offline

#17 2007-10-05 08:40 PM

mehdiizadeh
Member
From: Malaysia
Registered: 2007-09-18
Posts: 10

Re: How to send a file on socket

Thanks Rob
you are right, SSH does it but when we want to be able to experiment with link padding, using fixed-size cells ....
so an observer can't distinguish control cells from relay cells.
Doing it with TLS might be feasible than inflexible SSH.

I'm wondering that can use TLS as a security method on internet for all communication of the clients and servers.
e.g some website are using HTTPS (running HTTP on top of TLS or SSL),
why not all applications using such security method? is it costly?

Offline

#18 2007-10-05 10:13 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: How to send a file on socket

Offline

  • Index
  • » C
  • » How to send a file on socket

Board footer

Powered by FluxBB