Skip to content

Commit

Permalink
changes in point extension format
Browse files Browse the repository at this point in the history
  • Loading branch information
gstarovo committed May 14, 2024
1 parent 6db0826 commit 4a2d3df
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 74 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,13 @@ jobs:
COVERALLS_FLAG_NAME: ${{ matrix.name }}
COVERALLS_PARALLEL: true
COVERALLS_SERVICE_NAME: github
run: coveralls
PY_VERSION: ${{ matrix.python-version }}
run: |
if [[ $PY_VERSION == "2.6" ]]; then
COVERALLS_SKIP_SSL_VERIFY=1 coveralls
else
coveralls
fi
- name: Publish coverage to Codeclimate
if: ${{ contains(matrix.opt-deps, 'codeclimate') }}
env:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ coverage.xml
pylint_report.txt
build/
docs/_build/
htmlcov/
htmlcov/
3 changes: 2 additions & 1 deletion scripts/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def printGoodConnection(connection, seconds):
print(" Extended Master Secret: {0}".format(
connection.extendedMasterSecret))
print(" Session Resumed: {0}".format(connection.resumed))
print(" Session used ec point format extension: {0}".format(connection.session.ec_point_format))

def printExporter(connection, expLabel, expLength):
if expLabel is None:
Expand Down Expand Up @@ -424,7 +425,7 @@ def clientCmd(argv):
connection.handshakeClientCert(cert_chain, privateKey,
settings=settings, serverName=address[0], alpn=alpn)
stop = time_stamp()
print("Handshake success")
print("Handshake success")
except TLSLocalAlert as a:
if a.description == AlertDescription.user_canceled:
print(str(a))
Expand Down
Empty file removed test
Empty file.
157 changes: 147 additions & 10 deletions tests/tlstest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Authors:
# Authors:
# Trevor Perrin
# Kees Bos - Added tests for XML-RPC
# Dimitris Moraitis - Anon ciphersuites
Expand Down Expand Up @@ -44,30 +44,30 @@
from xmlrpc import client as xmlrpclib
import ssl
from tlslite import *
from tlslite.constants import KeyUpdateMessageType
from tlslite.constants import KeyUpdateMessageType, ECPointFormat

try:
from tack.structures.Tack import Tack

except ImportError:
pass

def printUsage(s=None):
if m2cryptoLoaded:
crypto = "M2Crypto/OpenSSL"
else:
crypto = "Python crypto"
crypto = "Python crypto"
if s:
print("ERROR: %s" % s)
print("""\ntls.py version %s (using %s)
print("""\ntls.py version %s (using %s)
Commands:
server HOST:PORT DIRECTORY
client HOST:PORT DIRECTORY
""" % (__version__, crypto))
sys.exit(-1)


def testConnClient(conn):
b1 = os.urandom(1)
Expand All @@ -92,9 +92,9 @@ def testConnClient(conn):
assert r1000 == b1000

def clientTestCmd(argv):

address = argv[0]
dir = argv[1]
dir = argv[1]

#Split address into hostname/port tuple
address = address.split(":")
Expand Down Expand Up @@ -235,7 +235,7 @@ def connect():
settings.minVersion = (3,0)
settings.maxVersion = (3,0)
connection.handshakeClientCert(settings=settings)
testConnClient(connection)
testConnClient(connection)
assert(isinstance(connection.session.serverCertChain, X509CertChain))
connection.close()

Expand Down Expand Up @@ -286,6 +286,72 @@ def connect():

test_no += 1

print("Test {0} - client compressed/uncompressed - uncompressed, TLSv1.2".format(test_no))
synchro.recv(1)
connection = connect()
settings = HandshakeSettings()
settings.minVersion = (3, 3)
settings.maxVersion = (3, 3)
settings.eccCurves = ["secp256r1", "secp384r1", "secp521r1", "x25519", "x448"]
connection.handshakeClientCert(settings=settings)
testConnClient(connection)
assert connection.session.ec_point_format == ECPointFormat.uncompressed
connection.close()

test_no += 1

print("Test {0} - client compressed - compressed, TLSv1.2".format(test_no))
synchro.recv(1)
connection = connect()
settings = HandshakeSettings()
settings.minVersion = (3, 3)
settings.maxVersion = (3, 3)
settings.eccCurves = ["secp256r1", "secp384r1", "secp521r1", "x25519", "x448"]
connection.handshakeClientCert(settings=settings)
testConnClient(connection)
assert connection.session.ec_point_format == ECPointFormat.ansiX962_compressed_prime
connection.close()

test_no += 1

print("Test {0} - client uncompressed - error, TLSv1.2".format(test_no))
synchro.recv(1)
connection = connect()
settings = HandshakeSettings()
settings.minVersion = (3, 3)
settings.maxVersion = (3, 3)
settings.ec_point_formats = [ECPointFormat.uncompressed]
settings.eccCurves = ["secp256r1", "secp384r1", "secp521r1", "x25519", "x448"]
try:
connection.handshakeClientCert(settings=settings)
assert False
except TLSIllegalParameterException as e:
assert "No common EC point format" in str(e)
except TLSAbruptCloseError as e:
pass
connection.close()

test_no += 1

print("Test {0} - client comppressed char2 - error, TLSv1.2".format(test_no))
synchro.recv(1)
connection = connect()
settings = HandshakeSettings()
settings.minVersion = (3, 3)
settings.maxVersion = (3, 3)
settings.ec_point_formats = [ECPointFormat.ansiX962_compressed_char2]
settings.eccCurves = ["secp256r1", "secp384r1", "secp521r1", "x25519", "x448"]
try:
connection.handshakeClientCert(settings=settings)
assert False
except ValueError as e:
assert "Unknown EC point format provided: [2]" in str(e)
except TLSAbruptCloseError as e:
pass
connection.close()

test_no += 1

print("Test {0} - mismatched ECDSA curve, TLSv1.2".format(test_no))
synchro.recv(1)
connection = connect()
Expand Down Expand Up @@ -2162,6 +2228,76 @@ def connect():

test_no += 1

print("Test {0} - server uncompressed ec format - uncompressed, TLSv1.2".format(test_no))
synchro.send(b'R')
connection = connect()
settings = HandshakeSettings()
settings.minVersion = (3, 1)
settings.maxVersion = (3, 3)
settings.eccCurves = ["secp256r1", "secp384r1", "secp521r1", "x25519", "x448"]
settings.ec_point_formats = [ECPointFormat.uncompressed]
connection.handshakeServer(certChain=x509ecdsaChain,
privateKey=x509ecdsaKey, settings=settings)
testConnServer(connection)
assert connection.session.ec_point_format == ECPointFormat.uncompressed
connection.close()

test_no += 1

print("Test {0} - server compressed ec format - compressed, TLSv1.2".format(test_no))
synchro.send(b'R')
connection = connect()
settings = HandshakeSettings()
settings.minVersion = (3, 1)
settings.maxVersion = (3, 3)
settings.eccCurves = ["secp256r1", "secp384r1", "secp521r1", "x25519", "x448"]
connection.handshakeServer(certChain=x509ecdsaChain,
privateKey=x509ecdsaKey, settings=settings)
testConnServer(connection)
assert connection.session.ec_point_format == ECPointFormat.ansiX962_compressed_prime
connection.close()

test_no +=1

print("Test {0} - server compressed ec format - error, TLSv1.2".format(test_no))
synchro.send(b'R')
connection = connect()
settings = HandshakeSettings()
settings.minVersion = (3, 1)
settings.maxVersion = (3, 3)
settings.ec_point_formats = [ECPointFormat.ansiX962_compressed_prime]
settings.eccCurves = ["secp256r1", "secp384r1", "secp521r1", "x25519", "x448"]
try:
connection.handshakeServer(certChain=x509ecdsaChain,
privateKey=x509ecdsaKey, settings=settings)
assert False
except TLSIllegalParameterException as e:
assert "No common EC point format" in str(e)
except TLSAbruptCloseError as e:
pass
connection.close()

test_no +=1

print("Test {0} - client compressed char2 - error, TLSv1.2".format(test_no))
synchro.send(b'R')
connection = connect()
settings = HandshakeSettings()
settings.minVersion = (3, 1)
settings.maxVersion = (3, 3)
settings.eccCurves = ["secp256r1", "secp384r1", "secp521r1", "x25519", "x448"]
try:
connection.handshakeServer(certChain=x509ecdsaChain,
privateKey=x509ecdsaKey, settings=settings)
assert False
except ValueError as e:
assert "Unknown EC point format provided: [2]" in str(e)
except TLSAbruptCloseError as e:
pass
connection.close()

test_no +=1

print("Test {0} - mismatched ECDSA curve, TLSv1.2".format(test_no))
synchro.send(b'R')
connection = connect()
Expand Down Expand Up @@ -3416,7 +3552,7 @@ def heartbeat_response_check(message):
assert synchro.recv(1) == b'R'
connection.close()

test_no += 1
test_no +=1

print("Tests {0}-{1} - XMLRPXC server".format(test_no, test_no + 2))

Expand Down Expand Up @@ -3449,6 +3585,7 @@ def add(self, x, y): return x + y

synchro.close()
synchroSocket.close()

test_no += 2

print("Test succeeded")
Expand Down
16 changes: 15 additions & 1 deletion tlslite/handshakesettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

"""Class for setting handshake parameters."""

from .constants import CertificateType
from .constants import CertificateType, ECPointFormat
from .utils import cryptomath
from .utils import cipherfactory
from .utils.compat import ecdsaAllCurves, int_types
Expand Down Expand Up @@ -61,6 +61,8 @@
TICKET_CIPHERS = ["chacha20-poly1305", "aes256gcm", "aes128gcm", "aes128ccm",
"aes128ccm_8", "aes256ccm", "aes256ccm_8"]
PSK_MODES = ["psk_dhe_ke", "psk_ke"]
EC_POINT_FORMATS = [ECPointFormat.ansiX962_compressed_prime,
ECPointFormat.uncompressed]


class Keypair(object):
Expand Down Expand Up @@ -353,6 +355,10 @@ class HandshakeSettings(object):
:vartype keyExchangeNames: list
:ivar keyExchangeNames: Enabled key exchange types for the connection,
influences selected cipher suites.
:vartype ec_point_formats: list
:ivar ec_point_formats: Enabled point format extension for
elliptic curves.
"""

def _init_key_settings(self):
Expand Down Expand Up @@ -396,6 +402,7 @@ def _init_misc_extensions(self):
# resumed connections (as tickets are single-use in TLS 1.3
self.ticket_count = 2
self.record_size_limit = 2**14 + 1 # TLS 1.3 includes content type
self.ec_point_formats = list(EC_POINT_FORMATS)

def __init__(self):
"""Initialise default values for settings."""
Expand Down Expand Up @@ -599,6 +606,12 @@ def _sanityCheckExtensions(other):
not 64 <= other.record_size_limit <= 2**14 + 1:
raise ValueError("record_size_limit cannot exceed 2**14+1 bytes")

bad_ec_ext = [i for i in other.ec_point_formats if
i not in EC_POINT_FORMATS]
if bad_ec_ext:
raise ValueError("Unknown EC point format provided: "
"{0}".format(bad_ec_ext))

HandshakeSettings._sanityCheckEMSExtension(other)

@staticmethod
Expand Down Expand Up @@ -667,6 +680,7 @@ def _copy_extension_settings(self, other):
other.sendFallbackSCSV = self.sendFallbackSCSV
other.useEncryptThenMAC = self.useEncryptThenMAC
other.usePaddingExtension = self.usePaddingExtension
other.ec_point_formats = self.ec_point_formats
# session tickets
other.padding_cb = self.padding_cb
other.ticketKeys = self.ticketKeys
Expand Down
Loading

0 comments on commit 4a2d3df

Please sign in to comment.