Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Respect is a rational process -- McCoy, "The Galileo Seven", stardate 2822.3


devel / comp.lang.python / Re: Simple SSL client hangs

SubjectAuthor
* Simple SSL client hangsLoris Bennett
+- Re: Simple SSL client hangsStefan Ram
+- Re: Simple SSL client hangsDouglas Wells
`* Re: Simple SSL client hangsMRAB
 `- Re: Simple SSL client hangsLoris Bennett

1
Simple SSL client hangs

<871r821wlg.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18557&group=comp.lang.python#18557

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.bennett@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Simple SSL client hangs
Date: Tue, 13 Jul 2021 09:50:19 +0200
Organization: Freie Universitaet Berlin
Lines: 54
Message-ID: <871r821wlg.fsf@hornfels.zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de 04Cl+rUvUsigiwNzg+kPZA4sUcxpkLJlCi6tpgtthxVqZg
Cancel-Lock: sha1:ZiQAkGQJ9B9pvAt0iAuh79H714o=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
 by: Loris Bennett - Tue, 13 Jul 2021 07:50 UTC

Hi,

In Perl I have the following

use IO::Socket::SSL;

my $my_socket = new IO::Socket::SSL(PeerAddr => 'some.server.somewhere,
PeerPort => 12345,
);

my $line = <$my_socket>;
print("$line\n");
say $my_socket 'ECHO 1';
$line = <$my_socket>;
print("$line\n");

This runs as expected and I get

200 Some Server Somewhere - Hello [123.456.789.123]

310 Hello Echo

If I try the same with the following Python code:

import socket
import ssl

HOST = "some.server.somewhere"
PORT = 12345

context = ssl.create_default_context()

with socket.create_connection((HOST, PORT)) as sock:
with context.wrap_socket(sock, server_hostname=HOST) as ssock:
data = ssock.recv(1024)
print(data.decode())
ssock.write(b'ECHO 1')
data = ssock.read(1024)
print(data.decode())

I get a timeout for the 'ECHO' command:

200 Some Server Somewhere - Hello [123.456.789.123]

501 Timeout

Does anyone have an idea what I might be doing wrong?

Cheers,

Loris

--
This signature is currently under construction.

Re: Simple SSL client hangs

<socket-20210713152519@ram.dialup.fu-berlin.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18558&group=comp.lang.python#18558

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Simple SSL client hangs
Date: 13 Jul 2021 14:25:59 GMT
Organization: Stefan Ram
Lines: 17
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <socket-20210713152519@ram.dialup.fu-berlin.de>
References: <871r821wlg.fsf@hornfels.zedat.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de a1L2VYaCmRvgehVNVXTmEAIxVBRWUlqwIuvmIfJS6QaVcY
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Tue, 13 Jul 2021 14:25 UTC

"Loris Bennett" <loris.bennett@fu-berlin.de> writes:
....
>ssock.write(b'ECHO 1')
>data = ssock.read(1024)
....
>Does anyone have an idea what I might be doing wrong?

No. But I'd try:

ssock.send( b"ECHO 1\r\n\r\n" )
data = ssock.recv( 1024 )

. (I don't know about a possible difference between "write"/
"read" and "send"/"recv", but just took that part from working
code of mine.)

Re: Simple SSL client hangs

<1626188072.34643@nowhere.invalid>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18559&group=comp.lang.python#18559

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: nr201504@gmail.com (Douglas Wells)
Newsgroups: comp.lang.python
Subject: Re: Simple SSL client hangs
Date: Tue, 13 Jul 2021 10:54:32 -0400 (EDT)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <1626188072.34643@nowhere.invalid>
References: <871r821wlg.fsf@hornfels.zedat.fu-berlin.de>
Injection-Info: reader02.eternal-september.org; posting-host="c4631ea37a0f69fb3b2a1e3a0f808ee5";
logging-data="20595"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yzbZnPZ7SUhw/crE3T01V"
Cancel-Lock: sha1:8UY3iabtPwghEmxOCLXsVJ6ZEx4=
 by: Douglas Wells - Tue, 13 Jul 2021 14:54 UTC

In article <871r821wlg.fsf@hornfels.zedat.fu-berlin.de>,
Loris Bennett <loris.bennett@fu-berlin.de> wrote:
>In Perl I have the following
>
> use IO::Socket::SSL;
> my $my_socket = new IO::Socket::SSL(PeerAddr => 'some.server.somewhere,
> PeerPort => 12345,
> );
> my $line = <$my_socket>;
> print("$line\n");
> say $my_socket 'ECHO 1';
> $line = <$my_socket>;
> print("$line\n");
>
>This runs as expected and I get
>
> 200 Some Server Somewhere - Hello [123.456.789.123]
> 310 Hello Echo
>
>If I try the same with the following Python code:
>
> import socket
> import ssl
> HOST = "some.server.somewhere"
> PORT = 12345
> context = ssl.create_default_context()
> with socket.create_connection((HOST, PORT)) as sock:
> with context.wrap_socket(sock, server_hostname=HOST) as ssock:
> data = ssock.recv(1024)
> print(data.decode())
> ssock.write(b'ECHO 1')
> data = ssock.read(1024)
> print(data.decode())
>
>I get a timeout for the 'ECHO' command:
>
> 200 Some Server Somewhere - Hello [123.456.789.123]
> 501 Timeout
>
>Does anyone have an idea what I might be doing wrong?

Loris,

You don't specify the type of your server, but it looks like a
"normal" SMTP or NNTP or whatever server. This type of server is line
oriented.

The Perl "say" operation adds a trailing line terminator. The Python
"ssl:write" does not. Try adding an appropriate line terminator to
your Python code. Most likely it needs to be CR-LF. Perhaps use
"ssock.write(b'ECHO 1\r\n')

- dmw

Re: Simple SSL client hangs

<mailman.210.1626195066.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18561&group=comp.lang.python#18561

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: python@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: Simple SSL client hangs
Date: Tue, 13 Jul 2021 17:51:03 +0100
Lines: 54
Message-ID: <mailman.210.1626195066.4164.python-list@python.org>
References: <871r821wlg.fsf@hornfels.zedat.fu-berlin.de>
<90db8099-786a-db88-9cff-6c15bd43d958@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de +uHG0F4Pjsb9qusnDazdyQIZdD0KJsVHj0kGBSX+oUlQ==
Return-Path: <python@mrabarnett.plus.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=plus.com header.i=@plus.com header.b=Kc++10O7;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'timeout': 0.07;
'from:addr:python': 0.09; 'hand,': 0.09; 'problem?': 0.09;
'received:192.168.1.64': 0.09; 'import': 0.14; 'append': 0.16;
'bennett': 0.16; 'command:': 0.16;
'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16;
'message-id:@mrabarnett.plus.com': 0.16; 'received:plus.net':
0.16; 'ssl': 0.16; 'subject:SSL': 0.16; 'subject:client': 0.16;
'wrote:': 0.16; 'says': 0.16; 'python': 0.16; 'anyone': 0.23;
'to:addr:python-list': 0.23; 'idea': 0.25; 'port': 0.27; 'header
:User-Agent:1': 0.31; 'received:192.168.1': 0.31; "doesn't": 0.32;
'context': 0.32; 'skip:" 20': 0.33; 'server': 0.33; 'header:In-
Reply-To:1': 0.33; 'same': 0.34; 'following': 0.35; 'code:': 0.35;
'received:192.168': 0.37; 'use': 0.38; 'does': 0.38; 'hi,': 0.39;
'could': 0.40; 'host': 0.40; "skip:' 10": 0.40; "skip:' 20": 0.40;
'200': 0.66; 'received:212': 0.68
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1626195064; bh=cg5akefVpysoJ+qDLuQnOZSPDbzLGICbCeYKfPyxHLo=;
h=Subject:To:References:From:Date:In-Reply-To;
b=Kc++10O7fCXxybkhSGM9sx46c5G6fly+wZIRpwhojtlQwlnu259e3Wl1xQP46ke7k
cOcdsYlMTpaankErQ9saBLSPrE5zWKfnpWDQH+zW7yc9YmvHiIOpO3xmlM4KidPBz5
+DP2lfZHQI2SY626DMv3DRGI+6NWVFQX9fHZ0tErmoyfbA94nNdQj+2yRKJLUbAzbq
4pk37vwVNRFct/VsdDEymjJTCNskPdYB8zEo+eMTtgJoD6+/TFPTVACaMvbMj/Vdy8
CZAASHvEZXVKimjrzHLKwFsySHV9NgQDK87jNvo9PsHTlz9pmagFNy19Rugqd+rCSl
GJ2cUM+385SSw==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.3 cv=H+BAP9Qi c=1 sm=1 tr=0
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=8sn5pQ5dcjqXYShfUKIA:9 a=QEXdDO2ut3YA:10
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
In-Reply-To: <871r821wlg.fsf@hornfels.zedat.fu-berlin.de>
Content-Language: en-GB
X-CMAE-Envelope: MS4wfGUWbNBzKbA8tmP1v3TX3/nS6lLRn5OrflOuIzal2Ghm/MXbCB3B4HDwy7EInkhjfearocIo/FlLbpONNQPv7ARxS4K6sjlSfc3AX2QXTje55POwjD8X
KQGgX25DxCwNAJnFjhz/Zm6vtevq6Osds1oKY4P6pIhpEO3w+mHOtqAqtP4jvUZpglzT60X/gWOoMA==
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <90db8099-786a-db88-9cff-6c15bd43d958@mrabarnett.plus.com>
X-Mailman-Original-References: <871r821wlg.fsf@hornfels.zedat.fu-berlin.de>
 by: MRAB - Tue, 13 Jul 2021 16:51 UTC

On 2021-07-13 08:50, Loris Bennett wrote:
> Hi,
>
> In Perl I have the following
>
> use IO::Socket::SSL;
>
> my $my_socket = new IO::Socket::SSL(PeerAddr => 'some.server.somewhere,
> PeerPort => 12345,
> );
>
> my $line = <$my_socket>;
> print("$line\n");
> say $my_socket 'ECHO 1';
> $line = <$my_socket>;
> print("$line\n");
>
> This runs as expected and I get
>
> 200 Some Server Somewhere - Hello [123.456.789.123]
>
> 310 Hello Echo
>
> If I try the same with the following Python code:
>
> import socket
> import ssl
>
> HOST = "some.server.somewhere"
> PORT = 12345
>
> context = ssl.create_default_context()
>
> with socket.create_connection((HOST, PORT)) as sock:
> with context.wrap_socket(sock, server_hostname=HOST) as ssock:
> data = ssock.recv(1024)
> print(data.decode())
> ssock.write(b'ECHO 1')
> data = ssock.read(1024)
> print(data.decode())
>
> I get a timeout for the 'ECHO' command:
>
> 200 Some Server Somewhere - Hello [123.456.789.123]
>
> 501 Timeout
>
> Does anyone have an idea what I might be doing wrong?
>
The docs for Perl says that 'say' appends a newline.

On the other hand, 'ssock.write' doesn't append a newline.

Could that be the problem?

Re: Simple SSL client hangs

<87r1g1o2y1.fsf@hornfels.zedat.fu-berlin.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18566&group=comp.lang.python#18566

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: loris.bennett@fu-berlin.de (Loris Bennett)
Newsgroups: comp.lang.python
Subject: Re: Simple SSL client hangs
Date: Wed, 14 Jul 2021 07:54:30 +0200
Organization: Freie Universitaet Berlin
Lines: 72
Message-ID: <87r1g1o2y1.fsf@hornfels.zedat.fu-berlin.de>
References: <871r821wlg.fsf@hornfels.zedat.fu-berlin.de>
<90db8099-786a-db88-9cff-6c15bd43d958@mrabarnett.plus.com>
<mailman.210.1626195066.4164.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: news.uni-berlin.de z+pkoJzYHU+qW3CNtUZ3bA5X3PfpVZzKR0IGxe7ElPsvhf
Cancel-Lock: sha1:blZ6uBznA1LWNBhhm1aM2LcKMho=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
 by: Loris Bennett - Wed, 14 Jul 2021 05:54 UTC

Hi,

MRAB <python@mrabarnett.plus.com> writes:

> On 2021-07-13 08:50, Loris Bennett wrote:
>> Hi,
>>
>> In Perl I have the following
>>
>> use IO::Socket::SSL;
>>
>> my $my_socket = new IO::Socket::SSL(PeerAddr => 'some.server.somewhere,
>> PeerPort => 12345,
>> );
>>
>> my $line = <$my_socket>;
>> print("$line\n");
>> say $my_socket 'ECHO 1';
>> $line = <$my_socket>;
>> print("$line\n");
>>
>> This runs as expected and I get
>>
>> 200 Some Server Somewhere - Hello [123.456.789.123]
>>
>> 310 Hello Echo
>>
>> If I try the same with the following Python code:
>>
>> import socket
>> import ssl
>>
>> HOST = "some.server.somewhere"
>> PORT = 12345
>>
>> context = ssl.create_default_context()
>>
>> with socket.create_connection((HOST, PORT)) as sock:
>> with context.wrap_socket(sock, server_hostname=HOST) as ssock:
>> data = ssock.recv(1024)
>> print(data.decode())
>> ssock.write(b'ECHO 1')
>> data = ssock.read(1024)
>> print(data.decode())
>>
>> I get a timeout for the 'ECHO' command:
>>
>> 200 Some Server Somewhere - Hello [123.456.789.123]
>>
>> 501 Timeout
>>
>> Does anyone have an idea what I might be doing wrong?
>>
> The docs for Perl says that 'say' appends a newline.
>
> On the other hand, 'ssock.write' doesn't append a newline.
>
> Could that be the problem?

Thanks and well-spotted everyone! The missing newline was indeed the
problem. With

ssock.write(b'ECHO 1\n')

the Python codes behaves like the Perl code.

Cheers,

Loris

--
This signature is currently under construction.


devel / comp.lang.python / Re: Simple SSL client hangs

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor