# Path: Peach/publisher.py
# class PublisherSoftException(SoftException):
#     """
#     Recoverable exception occurred in the Publisher.
#     """
#     pass
# 
# Path: Peach/Engine/common.py
# class PeachException(HardException):
#     """
#     Peach exceptions are specialized hard exceptions.
#     The message contained in a PeachException is presentable to the user w/o any stack trace, etc.
#     Examples would be:
#         "Error: The DataModel element requires a name attribute."
#     """
#     def __init__(self, msg, module="Unknown"):
#         Exception.__init__(self, msg)
#         self.module = module
#         self.msg = msg


import sys
import ssl
import socket
import tlslite.api
from Peach.Publishers.tcp import TcpListener
from Peach.publisher import PublisherSoftException
from Peach.Engine.common import PeachException
            with open(self.cert) as fd:
                cert_content = fd.read()
        except IOError:
            raise PeachException("Unable to open %s" % self.cert)

        x509 = tlslite.api.X509()
        x509.parse(cert_content)
        self.certChain = tlslite.api.X509CertChain([x509])

        try:
            with open(self.pkey) as fd:
                pkey_content = fd.read()
        except IOError:
            raise PeachException("Unable to open %s" % self.pkey)

        self.privateKey = tlslite.api.parsePEMKey(pkey_content, private=True)

    def accept(self):
        print("[*] Waiting for incoming connection")
        sys.stdout.flush()
        client, addr = self._listen.accept()

        print("[*] Connected by %s:%s" % (addr[0], str(addr[1])))
        print("[*] Wrapping socket to TLS/SSL")
        try:
            self._socket = tlslite.api.TLSConnection(client)
        except:
            client.close()
            value = sys.exc_info()[1]
            msg = "[!] Wrapping socket failed, reason: %s" % value

# Path: Peach/publisher.py
# class PublisherSoftException(SoftException):
#     """
#     Recoverable exception occurred in the Publisher.
#     """
#     pass
# 
# Path: Peach/Engine/common.py
# class PeachException(HardException):
#     """
#     Peach exceptions are specialized hard exceptions.
#     The message contained in a PeachException is presentable to the user w/o any stack trace, etc.
#     Examples would be:
#         "Error: The DataModel element requires a name attribute."
#     """
#     def __init__(self, msg, module="Unknown"):
#         Exception.__init__(self, msg)
#         self.module = module
#         self.msg = msg


# Path: Peach/Publishers/sslayer.py
import sys
import ssl
import socket
import tlslite.api
from Peach.Publishers.tcp import TcpListener
from Peach.publisher import PublisherSoftException
from Peach.Engine.common import PeachException

            with open(self.cert) as fd:
                cert_content = fd.read()
        except IOError:
            raise PeachException("Unable to open %s" % self.cert)

        x509 = tlslite.api.X509()
        x509.parse(cert_content)
        self.certChain = tlslite.api.X509CertChain([x509])

        try:
            with open(self.pkey) as fd:
                pkey_content = fd.read()
        except IOError:
            raise PeachException("Unable to open %s" % self.pkey)

        self.privateKey = tlslite.api.parsePEMKey(pkey_content, private=True)

    def accept(self):
        print("[*] Waiting for incoming connection")
        sys.stdout.flush()
        client, addr = self._listen.accept()

        print("[*] Connected by %s:%s" % (addr[0], str(addr[1])))
        print("[*] Wrapping socket to TLS/SSL")
        try:
            self._socket = tlslite.api.TLSConnection(client)
        except:
            client.close()
            value = sys.exc_info()[1]
            msg = "[!] Wrapping socket failed, reason: %s" % value

            raise PublisherSoftException(msg)