Exemple #1
0
 def testGetValueUponStatus200(self):
     "Test result value upon status 200"
     source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
     document = Document(source)
     self.assertEquals(document.get_value(parser_func=parser_stub_func), 3)
Exemple #2
0
 def testGetValueUponWrongStatus(self):
     "Test result value upon wrong status"
     source = DocumentSourceMock((405, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
     document = Document(source)
     self.assertEquals(document.get_value(parser_func=parser_stub_func), None)
Exemple #3
0
 def testCorrectCertificateWithInvalidSignature(self):
     "Test correct certificate with invalid signature"
     source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_INVALID_SIGNATURE))
     document = Document(source)
     self.assertFalse(document.verify())
Exemple #4
0
 def testIncorrectCertificateWithValidSignature(self):
     "Test incorrect certificate with valid signature"
     source = DocumentSourceMock((200, INCORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
     document = Document(source)
     self.assertTrue(document.verify())
Exemple #5
0
 def testGetRawData(self):
     "Test result value of document raw data"
     source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
     document = Document(source)
     self.assertTrue(document.verify())
     self.assertEquals(document.get_raw_data(), CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE)
Exemple #6
0
 def testGetBody(self):
     "Test result value of document body"
     source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
     document = Document(source)
     self.assertTrue(document.verify())
     self.assertEquals(document.get_body(), VALID_BODY)
Exemple #7
0
 def testGetCertificateID(self):
     "Test result value of document ID"
     source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE))
     document = Document(source)
     self.assertTrue(document.verify())
     self.assertEquals(document.get_id(), '64D0 F8CA 822B BDF0 FF59  42F6 A363 ED80 D8A5 CEFF')
    def index(self, email=None, pgp=None, mime=None, sn=None, **params):
        cherrypy.response.headers["Content-Type"] = "text/html"
        page = [render_header()]
        if cherrypy.request.method == "POST":
            # TODO: check email for validity
            if email is None or email == "":
                return self._render_error_page(_("Missing parameter"), _("Email parameter is mandatory."))
            # TODO: check serial number for validity
            if sn is None or sn == "":
                return self._render_error_page(
                    _("Missing parameter"), _("Certificate serial number parameter is mandatory.")
                )
            document_source = DocumentSource(settings.ISSUER, sn=sn)
            document = Document(document_source)
            verified = document.verify()
            # document.verify() returns False if verification failed
            # and None upon another error
            if verified != False:
                _id = document.get_id()
                if mime:
                    signature = document.get_signature()
                    body = document.get_body()
                    message = MIMESignedMessage(settings.SMTP_USERNAME, email, render_subject(_id), body, signature)
                else:
                    if not pgp:
                        body = document.get_raw_data()
                        message = TextMessage(settings.SMTP_USERNAME, email, render_subject(_id), body)
                if pgp:
                    gnupg = GPG(gnupghome=ws_settings.GNUPG_HOME)
                    received = gnupg.receive_keys(pgp, always_trust=True)
                    if received:
                        if mime:
                            encrypted = gnupg.encrypt(message.as_string(), pgp, always_trust=True)
                            if encrypted:
                                message = MIMEEncryptedMessage(
                                    settings.SMTP_USERNAME, email, render_subject(_id), str(encrypted)
                                )
                            else:
                                return self._render_error_page(
                                    _("Something went wrong"), _("Encryption problem. Sorry for the inconvenience!")
                                )
                        else:
                            message = make_document(document.get_raw_data())
                            encrypted = gnupg.encrypt(message, pgp, always_trust=True, no_literal=True)
                            if encrypted:
                                message = TextMessage(
                                    settings.SMTP_USERNAME, email, render_subject(_id), str(encrypted)
                                )
                            else:
                                return self._render_error_page(
                                    _("Something went wrong"), _("Encryption problem. Sorry for the inconvenience!")
                                )
                    else:
                        return self._render_error_page(
                            _("Something went wrong"), _("Can not receive key. Sorry for the inconvenience!")
                        )

                m = Mailer(suppress_exceptions=False)
                try:
                    m.send(message)
                except MailerException:
                    return self._render_error_page(
                        _("Something went wrong"), _("Please try again later. Sorry for the inconvenience!")
                    )
                page.append(
                    render_message(
                        _("Request was completed successfully"),
                        _("Your receipt will be emailed shortly. Thank you for your patience!"),
                    )
                )
            else:
                return self._render_error_page(
                    _("Something went wrong"), _("Please try again later. Sorry for the inconvenience!")
                )
        else:
            page.append(
                render_message(
                    _("Malformed request"),
                    _(
                        "You should use POST request with Content-Type: application/x-www-form-urlencoded and appropriate parameters list."
                    ),
                )
            )
        page.append(render_footer())
        return page
Exemple #9
0
def index():
    D = request.args.get('D', None)
    B = request.args.get('B', '')
    F = request.args.get('F', None)
    E = request.args.get('E', None)
    K = request.args.get('K', None)
    L = request.args.get('L', '')
    status_code = 200
    payment_required = False
    if F is not None:
        try:
            F = int(F)
        except ValueError:
            F = 0
    else:
        F = 0
    page = [render_header()]
    if D is None:
        return _render_error_page(_('Missing parameter'),
            _('Parameter D is missing'))
    invoice = Invoice(D, B=B, F=F)
    document_source = DocumentSource(settings.ISSUER, docid=invoice.D)
    document = Document(document_source)
    value = None
    verified = document.verify()
    # document.verify() returns False if verification failed
    # and None upon another error
    if verified != False:
        value = document.get_value()
    if value is not None:
        invoice.value = value
        if value > 0:
            invoice.certificate_link = '<a href="%s/info?ID=%s">%s</a>' % (settings.ISSUER,
                invoice.D, _('GET CERTIFICATE'))
        if (value >= F) and (F is not None) and (F > 0):
            invoice.message = _('The corresponding invoice has been paid')
            page.append(render_invoce(invoice))
            # Email address
            email = ''
            if E is not None:
                set_cookie_value('pfemail', E)
                email = E
            else:
                email = request.cookies.get('pfemail')
            # PGP encryption key ID
            pgpkey = ''
            if K is not None:
                set_cookie_value('pfpgpkey', K)
                pgpkey = K
            else:
                pgpkey = request_cookies_get('pfpgpkey')
            # If mailreceipt application is configured render the email form
            if settings.MAILRECEIPT_URL:
                page.append(render_email_form(email, pgpkey, document.get_sn(),
                    settings.MAILRECEIPT_URL, L))
        else:
            if F > 0:
                payment_required = True
            status_code = 402
            invoice.G = '%s/?D=%s&F=%s' % (settings.REDIRECTION_TARGET, invoice.D,
                str(invoice.F))
            page.append(render_invoce_form(invoice))

    else:
        return self._render_error_page(_('Internal error'),
            _('Sorry for the inconvenience'))

    page.append(render_footer())
    
    response = make_response(page, status_code)
    if payment_required:
        response.headers['Content-Price'] = "%s EPT" % str(F - value)

    return response