tlsfuzzer/python-ecdsa

Help needed, issue

wojake opened this issue · 3 comments

Hey ECDSA team,

I have a problem, im trying to exchange the keys for "SigningKey, NIST521p, VerifyingKey" to another computer/code using sockets module.

I tried sending the other computer the key (hex) but it dint work out, need some help to make this work out. #

how did you encode the key to hex and how did you try to decode it from hex?

how did you encode the key to hex and how did you try to decode it from hex?

The probelm is not about the hex encode/decode, im sorry but whats the most effiecient and secure way to exchange keys with 1 machine to another using socket(SSL) module?

python-ecdsa doesn't support encrypting private keys (SigningKey), so you can't really do anything "secure" with them on python-ecdsa level; if you establish TLS connection to the other side with proper certificate verification and modern parameters, then sending them over it will be secure, but that's completely outside this library...

most efficient (smallest) is the raw encoding for private keys, and sending the public key as a compressed point. Note that you'll need to also send some ID of the used curve, if you don't hardcode use of a specific one.

that is, those two calls:

def to_string(self, encoding="raw"):
"""
Convert the public key to a byte string.
The method by default uses the :term:`raw encoding` (specified
by `encoding="raw"`. It can also output keys in :term:`uncompressed`,
:term:`compressed` and :term:`hybrid` formats.
Remember that the curve identification is not part of the encoding
so to decode the point using :func:`~VerifyingKey.from_string`, curve
needs to be specified.
Note: while the method is called "to_string", it's a misnomer from
Python 2 days when character strings and byte strings shared type.
On Python 3 the returned type will be `bytes`.
:return: :term:`raw encoding` of the public key (public point) on the
curve
:rtype: bytes
"""

python-ecdsa/src/ecdsa/keys.py

Lines 1080 to 1090 in 106798c

def to_string(self):
"""
Convert the private key to :term:`raw encoding`.
Note: while the method is named "to_string", its name comes from
Python 2 days, when binary and character strings used the same type.
The type used in Python 3 is `bytes`.
:return: raw encoding of private key
:rtype: bytes
"""

look for from_string() methods to perform the inverse operation.