Skip to content

Commit

Permalink
Make OpenSSL version regexes more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Aug 17, 2023
1 parent ebbc944 commit d5f3437
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions oscrypto/_openssl/_libcrypto_cffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@

is_libressl = 'LibreSSL' in version_string

version_match = re.search('\\b(\\d\\.\\d\\.\\d+[a-z]*)\\b', version_string)
version_match = re.search('\\b(\\d+\\.\\d+\\.\\d+[a-z]*)\\b', version_string)
if not version_match:
version_match = re.search('(?<=LibreSSL )(\\d\\.\\d(\\.\\d)?)\\b', version_string)
version_match = re.search('(?<=LibreSSL )(\\d+\\.\\d+(\\.\\d+)?)\\b', version_string)
if not version_match:
raise LibraryNotFoundError('Error detecting the version of libcrypto')
version = version_match.group(1)
version_parts = re.sub('(\\d)([a-z]+)', '\\1.\\2', version).split('.')
version_parts = re.sub('(\\d+)([a-z]+)', '\\1.\\2', version).split('.')
version_info = tuple(int(part) if part.isdigit() else part for part in version_parts)

# LibreSSL is compatible with libcrypto from OpenSSL 1.0.1
Expand Down
6 changes: 3 additions & 3 deletions oscrypto/_openssl/_libcrypto_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@

is_libressl = 'LibreSSL' in version_string

version_match = re.search('\\b(\\d\\.\\d\\.\\d+[a-z]*)\\b', version_string)
version_match = re.search('\\b(\\d+\\.\\d+\\.\\d+[a-z]*)\\b', version_string)
if not version_match:
version_match = re.search('(?<=LibreSSL )(\\d\\.\\d(\\.\\d)?)\\b', version_string)
version_match = re.search('(?<=LibreSSL )(\\d+\\.\\d+(\\.\\d+)?)\\b', version_string)
if not version_match:
raise LibraryNotFoundError('Error detecting the version of libcrypto')
version = version_match.group(1)
version_parts = re.sub('(\\d)([a-z]+)', '\\1.\\2', version).split('.')
version_parts = re.sub('(\\d+)([a-z]+)', '\\1.\\2', version).split('.')
version_info = tuple(int(part) if part.isdigit() else part for part in version_parts)

# LibreSSL is compatible with libcrypto from OpenSSL 1.0.1
Expand Down

0 comments on commit d5f3437

Please sign in to comment.