Exemplo n.º 1
0
    def __init__(self, config, distributor, schedule):
        """Create a context for storing configs for email bridge distribution.

        :type config: :class:`bridgedb.persistent.Conf`
        :type distributor: :class:`~bridgedb.distributors.email.distributor.EmailDistributor`
        :param distributor: The distributor will handle getting the correct
            bridges (or none) for a client for us.
        :type schedule: :class:`bridgedb.schedule.ScheduledInterval`
        :param schedule: An interval-based scheduler, used to help the
            :data:`distributor` know if we should give bridges to a client.
        """
        self.config = config
        self.distributor = distributor
        self.schedule = schedule

        self.maximumSize = smtp.SMTP.MAX_LENGTH
        self.includeFingerprints = config.EMAIL_INCLUDE_FINGERPRINTS
        self.nBridges = config.EMAIL_N_BRIDGES_PER_ANSWER

        self.username = (config.EMAIL_USERNAME or "bridges")
        self.hostname = socket.gethostname().encode("utf-8")
        self.fromAddr = (config.EMAIL_FROM_ADDR or "*****@*****.**")
        self.smtpFromAddr = (config.EMAIL_SMTP_FROM_ADDR or self.fromAddr)
        self.smtpServerPort = (config.EMAIL_SMTP_PORT or 25)
        self.smtpServerIP = (config.EMAIL_SMTP_HOST or "127.0.0.1")

        self.domainRules = config.EMAIL_DOMAIN_RULES or {}
        self.domainMap = config.EMAIL_DOMAIN_MAP or {}
        self.canon = self.buildCanonicalDomainMap()
        self.whitelist = config.EMAIL_WHITELIST or {}
        self.blacklist = config.EMAIL_BLACKLIST or []
        self.fuzzyMatch = config.EMAIL_FUZZY_MATCH or 0

        self.gpg, self.gpgSignFunc = initializeGnuPG(config)
Exemplo n.º 2
0
 def test_crypto_initializeGnuPG(self):
     """crypto.initializeGnuPG() should return a 2-tuple with a gpg object
     and a signing function.
     """
     gpg, signfunc = crypto.initializeGnuPG(self.config)
     self.assertIsNotNone(gpg)
     self.assertIsNotNone(signfunc)
Exemplo n.º 3
0
 def test_crypto_initializeGnuPG(self):
     """crypto.initializeGnuPG() should return a 2-tuple with a gpg object
     and a signing function.
     """
     gpg, signfunc = crypto.initializeGnuPG(self.config)
     self.assertIsNotNone(gpg)
     self.assertIsNotNone(signfunc)
Exemplo n.º 4
0
    def __init__(self, config, distributor, schedule):
        """Create a context for storing configs for email bridge distribution.

        :type config: :class:`bridgedb.persistent.Conf`
        :type distributor: :class:`~bridgedb.distributors.email.distributor.EmailDistributor`
        :param distributor: The distributor will handle getting the correct
            bridges (or none) for a client for us.
        :type schedule: :class:`bridgedb.schedule.ScheduledInterval`
        :param schedule: An interval-based scheduler, used to help the
            :data:`distributor` know if we should give bridges to a client.
        """
        self.config = config
        self.distributor = distributor
        self.schedule = schedule

        self.maximumSize = smtp.SMTP.MAX_LENGTH
        self.includeFingerprints = config.EMAIL_INCLUDE_FINGERPRINTS
        self.nBridges = config.EMAIL_N_BRIDGES_PER_ANSWER

        self.username = (config.EMAIL_USERNAME or "bridges")
        self.hostname = socket.gethostname()
        self.fromAddr = (config.EMAIL_FROM_ADDR or "*****@*****.**")
        self.smtpFromAddr = (config.EMAIL_SMTP_FROM_ADDR or self.fromAddr)
        self.smtpServerPort = (config.EMAIL_SMTP_PORT or 25)
        self.smtpServerIP = (config.EMAIL_SMTP_HOST or "127.0.0.1")

        self.domainRules = config.EMAIL_DOMAIN_RULES or {}
        self.domainMap = config.EMAIL_DOMAIN_MAP or {}
        self.canon = self.buildCanonicalDomainMap()
        self.whitelist = config.EMAIL_WHITELIST or {}
        self.blacklist = config.EMAIL_BLACKLIST or []
        self.fuzzyMatch = config.EMAIL_FUZZY_MATCH or 0

        self.gpg, self.gpgSignFunc = initializeGnuPG(config)
Exemplo n.º 5
0
 def test_crypto_initializeGnuPG_with_passphrase_file(self):
     """crypto.initializeGnuPG() should initialize correctly when a
     passphrase file is given but no passphrase is needed.
     """
     self.config.EMAIL_GPG_PASSPHRASE_FILE = self.passphraseFile
     gpg, signfunc = crypto.initializeGnuPG(self.config)
     self.assertIsNotNone(gpg)
     self.assertIsNotNone(signfunc)
Exemplo n.º 6
0
 def test_crypto_initializeGnuPG_with_passphrase_file(self):
     """crypto.initializeGnuPG() should initialize correctly when a
     passphrase file is given but no passphrase is needed.
     """
     self.config.EMAIL_GPG_PASSPHRASE_FILE = self.passphraseFile
     gpg, signfunc = crypto.initializeGnuPG(self.config)
     self.assertIsNotNone(gpg)
     self.assertIsNotNone(signfunc)
Exemplo n.º 7
0
 def test_crypto_initializeGnuPG_nonexistent_default_key(self):
     """When the key specified by EMAIL_GPG_PRIMARY_KEY_FINGERPRINT doesn't
     exist in the keyrings, crypto.initializeGnuPG() should return a 2-tuple
     of None.
     """
     self.config.EMAIL_GPG_PRIMARY_KEY_FINGERPRINT = 'A' * 40
     gpg, signfunc = crypto.initializeGnuPG(self.config)
     self.assertIsNone(gpg)
     self.assertIsNone(signfunc)
Exemplo n.º 8
0
    def test_crypto_initializeGnuPG_disabled(self):
        """When EMAIL_GPG_SIGNING_ENABLED=False, crypto.initializeGnuPG()
        should return a 2-tuple of None.
        """
        self.config.EMAIL_GPG_SIGNING_ENABLED = False
        gpg, signfunc = crypto.initializeGnuPG(self.config)

        self.assertIsNone(gpg)
        self.assertIsNone(signfunc)
Exemplo n.º 9
0
 def test_crypto_initializeGnuPG_nonexistent_default_key(self):
     """When the key specified by EMAIL_GPG_PRIMARY_KEY_FINGERPRINT doesn't
     exist in the keyrings, crypto.initializeGnuPG() should return a 2-tuple
     of None.
     """
     self.config.EMAIL_GPG_PRIMARY_KEY_FINGERPRINT = 'A' * 40
     gpg, signfunc = crypto.initializeGnuPG(self.config)
     self.assertIsNone(gpg)
     self.assertIsNone(signfunc)
Exemplo n.º 10
0
    def test_crypto_initializeGnuPG_disabled(self):
        """When EMAIL_GPG_SIGNING_ENABLED=False, crypto.initializeGnuPG()
        should return a 2-tuple of None.
        """
        self.config.EMAIL_GPG_SIGNING_ENABLED = False
        gpg, signfunc = crypto.initializeGnuPG(self.config)

        self.assertIsNone(gpg)
        self.assertIsNone(signfunc)
Exemplo n.º 11
0
 def test_crypto_initializeGnuPG_missing_passphrase_file(self):
     """crypto.initializeGnuPG() should initialize correctly if a passphrase
     file is given but that file is missing (when no passphrase is actually
     necessary).
     """
     self.config.EMAIL_GPG_PASSPHRASE_FILE = self.passphraseFile
     os.remove(self.passphraseFile)
     gpg, signfunc = crypto.initializeGnuPG(self.config)
     self.assertIsNotNone(gpg)
     self.assertIsNotNone(signfunc)
Exemplo n.º 12
0
 def test_crypto_initializeGnuPG_missing_passphrase_file(self):
     """crypto.initializeGnuPG() should initialize correctly if a passphrase
     file is given but that file is missing (when no passphrase is actually
     necessary).
     """
     self.config.EMAIL_GPG_PASSPHRASE_FILE = self.passphraseFile
     os.remove(self.passphraseFile)
     gpg, signfunc = crypto.initializeGnuPG(self.config)
     self.assertIsNotNone(gpg)
     self.assertIsNotNone(signfunc)
Exemplo n.º 13
0
    def test_crypto_initializeGnuPG_no_publics(self):
        """When the pubring.gpg is missing, crypto.initializeGnuPG() should
        return a 2-tuple of None.
        """
        pubring = os.path.join(self.gnupghome, 'pubring.gpg')
        if os.path.isfile(pubring):
            os.remove(pubring)

        gpg, signfunc = crypto.initializeGnuPG(self.config)
        self.assertIsNone(gpg)
        self.assertIsNone(signfunc)
Exemplo n.º 14
0
    def test_crypto_initializeGnuPG_no_publics(self):
        """When the pubring.gpg is missing, crypto.initializeGnuPG() should
        return a 2-tuple of None.
        """
        pubring = os.path.join(self.gnupghome, 'pubring.gpg')
        if os.path.isfile(pubring):
            os.remove(pubring)

        gpg, signfunc = crypto.initializeGnuPG(self.config)
        self.assertIsNone(gpg)
        self.assertIsNone(signfunc)
Exemplo n.º 15
0
    def test_crypto_initializeGnuPG_signingFunc(self):
        """crypto.initializeGnuPG() should return a signing function which
        produces OpenPGP signatures.
        """
        gpg, signfunc = crypto.initializeGnuPG(self.config)
        self.assertIsNotNone(gpg)
        self.assertIsNotNone(signfunc)

        sig = signfunc("This is a test of the public broadcasting system.")
        print(sig)
        self.assertIsNotNone(sig)
        self.assertTrue(sig.startswith('-----BEGIN PGP SIGNED MESSAGE-----'))
Exemplo n.º 16
0
    def test_crypto_initializeGnuPG_signingFunc(self):
        """crypto.initializeGnuPG() should return a signing function which
        produces OpenPGP signatures.
        """
        gpg, signfunc = crypto.initializeGnuPG(self.config)
        self.assertIsNotNone(gpg)
        self.assertIsNotNone(signfunc)

        sig = signfunc("This is a test of the public broadcasting system.")
        print(sig)
        self.assertIsNotNone(sig)
        self.assertTrue(sig.startswith('-----BEGIN PGP SIGNED MESSAGE-----'))