Simplify check_X509.py
as pyasn1 and pyOpenSSL are required now
This commit is contained in:
parent
6d10a5e2cf
commit
749a01a276
|
@ -1,23 +1,19 @@
|
|||
import logging
|
||||
log = logging.getLogger('gajim.c.check_X509')
|
||||
|
||||
try:
|
||||
import OpenSSL.SSL
|
||||
import OpenSSL.crypto
|
||||
ver = OpenSSL.__version__
|
||||
if ver < '0.12':
|
||||
raise ImportError
|
||||
from pyasn1.type import univ, constraint, char, namedtype, tag
|
||||
from pyasn1.codec.der.decoder import decode
|
||||
from gajim.common.helpers import prep, InvalidFormat
|
||||
import OpenSSL.SSL
|
||||
import OpenSSL.crypto
|
||||
|
||||
MAX = 64
|
||||
oid_xmppaddr = '1.3.6.1.5.5.7.8.5'
|
||||
oid_dnssrv = '1.3.6.1.5.5.7.8.7'
|
||||
from pyasn1.type import univ, constraint, char, namedtype, tag
|
||||
from pyasn1.codec.der.decoder import decode
|
||||
from gajim.common.helpers import prep, InvalidFormat
|
||||
|
||||
MAX = 64
|
||||
oid_xmppaddr = '1.3.6.1.5.5.7.8.5'
|
||||
oid_dnssrv = '1.3.6.1.5.5.7.8.7'
|
||||
|
||||
|
||||
|
||||
class DirectoryString(univ.Choice):
|
||||
class DirectoryString(univ.Choice):
|
||||
componentType = namedtype.NamedTypes(
|
||||
namedtype.NamedType(
|
||||
'teletexString', char.TeletexString().subtype(
|
||||
|
@ -42,30 +38,30 @@ try:
|
|||
subtypeSpec=constraint.ValueSizeConstraint(1, MAX))),
|
||||
)
|
||||
|
||||
class AttributeValue(DirectoryString):
|
||||
class AttributeValue(DirectoryString):
|
||||
pass
|
||||
|
||||
class AttributeType(univ.ObjectIdentifier):
|
||||
class AttributeType(univ.ObjectIdentifier):
|
||||
pass
|
||||
|
||||
class AttributeTypeAndValue(univ.Sequence):
|
||||
class AttributeTypeAndValue(univ.Sequence):
|
||||
componentType = namedtype.NamedTypes(
|
||||
namedtype.NamedType('type', AttributeType()),
|
||||
namedtype.NamedType('value', AttributeValue()),
|
||||
)
|
||||
|
||||
class RelativeDistinguishedName(univ.SetOf):
|
||||
class RelativeDistinguishedName(univ.SetOf):
|
||||
componentType = AttributeTypeAndValue()
|
||||
|
||||
class RDNSequence(univ.SequenceOf):
|
||||
class RDNSequence(univ.SequenceOf):
|
||||
componentType = RelativeDistinguishedName()
|
||||
|
||||
class Name(univ.Choice):
|
||||
class Name(univ.Choice):
|
||||
componentType = namedtype.NamedTypes(
|
||||
namedtype.NamedType('', RDNSequence()),
|
||||
)
|
||||
|
||||
class GeneralName(univ.Choice):
|
||||
class GeneralName(univ.Choice):
|
||||
componentType = namedtype.NamedTypes(
|
||||
namedtype.NamedType('otherName', univ.Sequence().subtype(
|
||||
implicitTag=tag.Tag(tag.tagClassContext,
|
||||
|
@ -97,11 +93,11 @@ try:
|
|||
tag.tagFormatSimple, 8))),
|
||||
)
|
||||
|
||||
class GeneralNames(univ.SequenceOf):
|
||||
class GeneralNames(univ.SequenceOf):
|
||||
componentType = GeneralName()
|
||||
sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, MAX)
|
||||
|
||||
def _parse_asn1(asn1):
|
||||
def _parse_asn1(asn1):
|
||||
obj = decode(asn1, asn1Spec=GeneralNames())[0]
|
||||
r = {}
|
||||
for o in obj:
|
||||
|
@ -122,7 +118,7 @@ try:
|
|||
r['uniformResourceIdentifier'] = True
|
||||
return r
|
||||
|
||||
def check_certificate(cert, domain):
|
||||
def check_certificate(cert, domain):
|
||||
cnt = cert.get_extension_count()
|
||||
if '.' in domain:
|
||||
compared_domain = domain.split('.', 1)[1]
|
||||
|
@ -172,12 +168,4 @@ try:
|
|||
if subject.commonName == domain:
|
||||
return True
|
||||
return False
|
||||
except ImportError:
|
||||
log.warning('Import of PyOpenSSL or pyasn1 failed. Cannot correctly check '
|
||||
'SSL certificate')
|
||||
|
||||
def check_certificate(cert, domain):
|
||||
subject = cert.get_subject()
|
||||
if subject.commonName == domain:
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -45,10 +45,6 @@ class FeaturesWindow:
|
|||
|
||||
# {name: (available_function, unix_text, windows_text)}
|
||||
self.features = {
|
||||
_('SSL certificate validation'): (self.pyopenssl_available,
|
||||
_('A library used to validate server certificates to ensure a secure connection.'),
|
||||
_('Requires python-pyopenssl > 0.12 and pyasn1.'),
|
||||
_('Requires python-pyopenssl > 0.12 and pyasn1.')),
|
||||
_('Bonjour / Zeroconf'): (self.zeroconf_available,
|
||||
_('Serverless chatting with autodetected clients in a local network.'),
|
||||
_('Requires python-avahi.'),
|
||||
|
@ -151,19 +147,6 @@ class FeaturesWindow:
|
|||
text = text + self.features[feature][2]
|
||||
self.desc_label.set_text(text)
|
||||
|
||||
def pyopenssl_available(self):
|
||||
try:
|
||||
import OpenSSL.SSL
|
||||
import OpenSSL.crypto
|
||||
ver = OpenSSL.__version__
|
||||
ver_l = [int(i) for i in ver.split('.')]
|
||||
if ver_l < [0, 12]:
|
||||
raise ImportError
|
||||
import pyasn1
|
||||
except Exception:
|
||||
return False
|
||||
return True
|
||||
|
||||
def zeroconf_available(self):
|
||||
return app.HAVE_ZEROCONF
|
||||
|
||||
|
|
Loading…
Reference in New Issue