Пример #1
0
def importCertificateDialog(repView):
    """
    Let the user import a certificate. First brings up a file selection
    dialog, then asks for trust settings for the certificate being imported.
    """
    certificate = None
    app = wx.GetApp()
    res = Util.showFileDialog(app.mainFrame,
                              _(u"Choose a certificate to import"), u"", u"",
                              _(u"PEM files|*.pem;*.crt|All files (*.*)|*.*"),
                              wx.OPEN)

    (cmd, dir, filename) = res

    if cmd == wx.ID_OK:
        # dir and filename are unicode
        path = os.path.join(dir, filename)

        try:
            x509 = X509.load_cert(path)

            fprint = utils.fingerprint(x509)
            purpose = certificatePurpose(x509)
            # Note: the order of choices must match the selections code below
            choices = [_(u"Trust this certificate.")]
            if purpose & constants.PURPOSE_CA:
                choices += [
                    _(u"Trust this certificate to sign site certificates.")
                ]

            dlg = dialogs.ImportCertificateDialog(app.mainFrame, purpose,
                                                  fprint, x509, choices)
            trust = constants.TRUST_NONE
            if dlg.ShowModal() == wx.ID_OK:
                selections = dlg.GetSelections()
                # Note: this code must match the choices above
                for sel in selections:
                    if sel == 0:
                        trust |= constants.TRUST_AUTHENTICITY
                    if sel == 1:
                        trust |= constants.TRUST_SERVER
                certificate = importCertificate(x509, fprint, trust, repView)
            dlg.Destroy()

        except utils.CertificateException, e:
            wx.MessageBox(e.__unicode__(),
                          messages.ERROR,
                          parent=wx.GetApp().mainFrame)

        except Exception, e:
            log.exception(e)
            wx.MessageBox(_(
                u"Could not add certificate from: %(path)s\nCheck the path and try again."
            ) % {'path': path},
                          messages.ERROR,
                          parent=wx.GetApp().mainFrame)
Пример #2
0
def importCertificateDialog(repView):
    """
    Let the user import a certificate. First brings up a file selection
    dialog, then asks for trust settings for the certificate being imported.
    """
    certificate = None
    app = wx.GetApp()
    res = Util.showFileDialog(app.mainFrame,
                              _(u"Choose a certificate to import"),
                              u"",
                              u"",
                              _(u"PEM files|*.pem;*.crt|All files (*.*)|*.*"),
                              wx.OPEN)

    (cmd, dir, filename) = res

    if cmd  == wx.ID_OK:
        # dir and filename are unicode
        path = os.path.join(dir, filename)

        try:
            x509 = X509.load_cert(path)

            fprint = utils.fingerprint(x509)
            purpose = certificatePurpose(x509)
            # Note: the order of choices must match the selections code below
            choices = [_(u"Trust this certificate.")]
            if purpose & constants.PURPOSE_CA:
                choices += [_(u"Trust this certificate to sign site certificates.")]

            dlg = dialogs.ImportCertificateDialog(app.mainFrame,
                                       purpose,
                                       fprint,
                                       x509,
                                       choices)
            trust = constants.TRUST_NONE
            if dlg.ShowModal() == wx.ID_OK:
                selections = dlg.GetSelections()
                # Note: this code must match the choices above
                for sel in selections:
                    if sel == 0:
                        trust |= constants.TRUST_AUTHENTICITY
                    if sel == 1:
                        trust |= constants.TRUST_SERVER
                certificate = importCertificate(x509, fprint, trust, repView)
            dlg.Destroy()

        except utils.CertificateException, e:
            wx.MessageBox (e.__unicode__(), messages.ERROR,
                           parent=wx.GetApp().mainFrame)

        except Exception, e:
            log.exception(e)
            wx.MessageBox (_(u"Could not add certificate from: %(path)s\nCheck the path and try again.") % {'path': path},
                           messages.ERROR,
                           parent=wx.GetApp().mainFrame)
Пример #3
0
    def onGoToDateEvent(self, event):
        newDate = event.arguments.get("DateTime")
        dateString = event.arguments.get("DateString")
        if newDate is None and dateString is None:
            dateString = Util.promptUser(
                _(u"Go to date"),
                _(u"Enter a date in the form %(dateFormat)s") % dict(dateFormat=DateTimeUtil.sampleDate),
            )
            if dateString is None:
                return

        if newDate is None:
            newDate = DateTimeUtil.shortDateFormat.parse(self.itsView, dateString)
        self.changeDate(newDate)
Пример #4
0
def beforeBackup(view, parent=None):
    """
    Call before doing any kind of backup or export of data that includes
    account passwords. Will prompt the user to set their master password
    if appropriate.
    
    Must be called from the UI thread.
    """
    prefs = schema.ns("osaf.framework.MasterPassword",
                      view).masterPasswordPrefs
    if not prefs.masterPassword:
        # Check if we have any passwords we'd want to protect
        from osaf.framework import password
        count = 0
        for item in password.Password.iterItems(view):
            if not waitForDeferred(item.initialized()):
                continue
            
            if waitForDeferred(item.decryptPassword()):
                count += 1
        if count == 1: # We will always have at least one, the dummy password
            return
        if parent is None:
            parent = wx.GetApp().mainFrame

        # Check if the user has set a persistent preference on what to do
        protect = getattr(prefs, 'protect', None)
        if protect is not None:
            if protect:
                waitForDeferred(change(view, parent))
            return
        
        dlg = Util.checkboxUserDialog(parent,
                                     _(u'Protect Passwords'),
                                     _(u'Anyone who gains access to your data can view your account passwords. Do you want to protect your account passwords by encrypting them with a master password?'),
                                     value = _(u'&Never ask again'))
        try:
            val = dlg.ShowModal()
            neverAskAgain = dlg.GetValue()
            
            if val == wx.ID_YES:
                waitForDeferred(change(view, parent))
                if neverAskAgain:
                    prefs.protect = True
            else:
                if neverAskAgain:
                    prefs.protect = False
        finally:
            dlg.Destroy()
    def onGoToDateEvent(self, event):
        newDate = event.arguments.get('DateTime')
        dateString = event.arguments.get('DateString')
        if newDate is None and dateString is None:
            dateString = Util.promptUser(
                _(u"Go to date"),
                _(u"Enter a date in the form %(dateFormat)s") %
                dict(dateFormat=DateTimeUtil.sampleDate))
            if dateString is None:
                return

        if newDate is None:
            newDate = DateTimeUtil.shortDateFormat.parse(
                self.itsView, dateString)
        self.changeDate(newDate)
Пример #6
0
    def onSaveFileEvent(self, event):
        """
        Open a file to associate with this script, or save an existing
        script to a file.
        """
        if not self._item.body:
            # no script body, open and overwrite existing model data
            title = _(u"Open Script File")
            flags = wx.OPEN
        else:
            # model data exists, we need a place to write it
            title =_(u"Save Script File As")
            flags = wx.SAVE | wx.OVERWRITE_PROMPT

        if self._item.filePath:
            # already have a file, default to that name and path
            # dirname returns unicode here since the filePath variable is unicode
            path = os.path.dirname(self._item.filePath)
            name = self._item.filePath.split(os.sep)[-1]
        else:
            # no file yet, point to scripts directory, use display name
            name = self._item.displayName+u".py"
            # dirname returns an str of bytes since the __file__ variable is bytes
            path = os.path.dirname(schema.ns('osaf.app', self).scripts.__file__)
            # convert the path bytes to unicode
            path = unicode(path, sys.getfilesystemencoding())

        # present the Open/Save dialog
        result = Util.showFileDialog(wx.GetApp().mainFrame, 
                                     title,
                                     path,
                                     name,
                                     _(u"Python files|*.py|") + _(u"All files (*.*)|*.*"),
                                     flags)
        cmd, dir, fileName = result

        if cmd == wx.ID_OK:
            preferFile = len(self._item.body) == 0
            self._item.filePath = os.path.join(dir, fileName)
            self._item.sync_file_with_model(preferFile=preferFile)
            resyncEvent = schema.ns('osaf.views.detail', self).Resynchronize
            Block.Block.post(resyncEvent, {}, self)
            self.postEventByName('ResyncDetailParent', {})