My hobbyist coding updates and releases as the mysterious "Mr. Tines"

Showing posts with label mono. Show all posts
Showing posts with label mono. Show all posts

Saturday, 18 August 2007

After a break

Last week I was at Recombination so nothing done then.

Now I've started to wire up the logon dialog. This included a bit of shuffling of the main UI, and preparing to split the DirectoryPanel into UI (repeated) and Directory Model classes (local and FTP); and starting the process of writing an FTP client against the .Net socket APIs.

Writing the logon dialog exposed one Mono quirk. The UseSystemPasswordChar property on the text-box doesn't seem to do anything. I resorted to self.pwdTB.PasswordChar = u'\u2022' as a portable solution.

Also, you can use the Data Protection API for more safely storing passwords:

import clr
clr.AddReference("System.Security")
from System.Security.Cryptography import *
import System.Text
import System

…

  def getSecureValue(self, section, key, default):
    raw = self.getValue(section, key, None)
    if raw== None:
      return default
    try:
      array = System.Convert.FromBase64String(raw)
      chars = ProtectedData.Unprotect(array,
        None, DataProtectionScope.CurrentUser)
      result = System.Text.Encoding.UTF8.GetString(chars)
      for i in range(chars.Length):
        chars[i] = 0
      return result
    except System.Exception, ex:
      print ex.ToString()
      return default

  def setSecureValue(self, section, key, value):
    bytes = System.Text.Encoding.UTF8.GetBytes(value)
    try:
      safed = ProtectedData.Protect(bytes,
        None, DataProtectionScope.CurrentUser)
      for i in range(bytes.Length):
        bytes[i] = 0
      string = System.Convert.ToBase64String(safed)
      for i in range(safed.Length):
        safed[i] = 0
      self.setValue(section, key, string)
    except System.Exception, ex:
      print ex.ToString()

which stores the password as an encrypted Base64 blob -- and works with Mono on Win32 as well. The weak point is the password kept in memory as a string (immutable) -- if you can use it as char array, you can wipe that when done.

Sunday, 5 August 2007

Directory pane almost there

Some of the problems I was cursing Mono for turn out to be IronPython 1.x-isms -- mainly the insisting on having Images rather than Icons. Mono has other peculiarities, like in how it actually lays out widgets (not that .Net is much better) at runtime, so for the moment I'm forcing the issue by trapping any size change to the directory pane so that it fits inside the viewport.

Apart from wiring up the delete context menu, the directory pane is done.

Saturday, 4 August 2007

More Mono

A lot of work done for the benefit of Mono, redoing how I wrap files to use os.path rather than .Net directly; and rewriting the P/Invoke layer from scratch (and from pinvoke.net) --including finding that Bitmap.FromHicon() is the simplest way of getting the transparent pixels roughly honoured as well as feeding that system what it wants.

I said that the DirectoryPane would be the worst of it, and it's doing its best to prove me right.

Monday, 30 July 2007

Not quite so pretty

After remarkably little work, it runs under Mono 1.2.4 and IPCE-r6. The main changes are that as Mono doesn't support System.Management (and the extra work wasn't useful for the icon related info), I fell back to Directory.GetLogicalDrives(), and had to do a bit of type tweaking (explicitly converting to Bitmap to draw the icons).

Everything else is non-visible : the lower left sector has been factored out into a separate class and modules have been rationalised, ahead of making a next step in functionality.

First drop for the curious and for back-up distribution. Now updated.