Yubikey & KeePass cross platform

A while back i got a Yubikey Neo and a Neo-n they are cool little devices that can work as the second part of a 2 factor authentication. The Neo apart from usb also supports Nfc so it can be used with most modern Android phones. So here's a short summary of how to get it all working. To get everything to work you need to install the KeeChallenge plugin in KeePass, I used the latest version (2.29) when setting everything up. The trick is to put the password file on something shared that everything can read usb stick, Dropbox or similar.

KeePass on windows

For windows follow this guide. Don't forget to copy the files from the YubiKey-Personalization release.

KeePass on OSX

On OSX the use following guide. A bit more hands on work but just follow the steps. Currently it seems like mono 4.0.2 doesn't work so go with 4.0.1.

KeePass on Android

On android you need the Keepass2Android Password Safe and YubiChallenge and a phone that supports Nfc, most modern Android phones do.

iOS

Nope, return in a couple of years when iOS has working nfc support

Home monitoring and sensors

I like dashboards

everything So I built one using InfluxDB, Grafana, Nginx, Tellstick Net and a bunch of scripts. Here's a breakdown of the parts and what feeds them.

Temperatures

At home i have a Tellstick Net and a bunch of remotecontrolled power switches connected to this i also have a bunch of temperature sensors (this model) places around the house, outside and in my shed.

Logging to InfluxDB

Data is fed into InfluxDB using a couple of different scripts.

  • Temperatures are read from Telldus Live using a modified version of their tdtool.py script every 10 minutes
  • To log status for my home server running ubuntu I modified my status script, this is logged every 5 minutes.
  • Ping & packet loss is logged with a simple ping script, right now it only pings googles public dns but is should be extended to ping multiple things (isp dns server etc) currently this script runs every minute

Improvements

I plan to add more fun sensors that work with Tellstick, things like rain and wind sensors. Something that logs how bright the sun is would be cool to. At some point when I have more info it will be fun to do some 'big data' stuff using the data set I have, right now it's been running for about 6 months so next year it's possible to graph current vs last year for many values.

AutoMapper & AutoFac

Prelude

So I tend to develop things in the way of

  1. Make it work
  2. Make it pretty

Make it work

So when using AutoMapper after step one I ended up with something like this

.ForMember(d => d.SomeSource, 
     o => o.MapFrom(
          s => new Serializer().Deserialize<SomeViewModel>(s.Serialized)))

Some background, for the destination SomeSource I needed to Deserialize the value as it was currently stored as Json in my database.

Make it pretty

While it works it looks rather horrible, so I started looking into something that allowed me to get a ISerializer from AutoFac (my IoC of choice) instead.

So, first I added a custom ValueResolver that looked like this

public class SomeViewModelResolver 
    : ValueResolver<OrderRow, ScheduleViewModel>
    {
        private readonly ISerializer _serializer;

        public ScheduleViewModelResolver(ISerializer serializer)
        {
            _serializer = serializer;
        }

        protected override SomeViewModel ResolveCore(Source source)
        {
            return _serializer.Deserialize<SomeViewModel>(source.Serialized);
        }
    }

Next was to connect AutoMapper with AutoFac and to register the ValueResolver:

// Register my new valueresolver
builder.RegisterType<SomeViewModelResolver>();

// Connect AutoMapper to AutoFac
Mapper.Initialize(x => x.ConstructServicesUsing(container.Resolve));

Once that is done the last thing to change is to modify the ForMember call to use the new ValueResolver instead

.ForMember(d => d.SomeSource, o => o.ResolveUsing<SomeViewModelResolver>())

Looks a lot cleaner and follows the flow that you would expect when using a IoC container.

Bonus

If you don't want to have calls to the static Mapper.Map<> all over your code, it is possible to register the IMappingEngine in AutoMapper in you IoC container and have that as an dependency for you class too. For AutoFac the registration looks like this

builder.Register(c => Mapper.Engine).As<IMappingEngine>().SingleInstance();

The important thing is to register it as a singelton. Once that is done just add IMappingEngine mappingEngine to the constructors of those classes that use AutomMapper.

Recent changes

So I've made some (mostly) under the hood changes to this blog. Lets start with the visible part I've dropped the blog part from the domain, the redirect is permanent but it might be a good idea to update your rss feed.

The fun parts are that the blog has moved from wordpress to using jekyll and is hosted on github from this repository. Migrating to jekyll was rather simple, there's plugins that support conversion from a wordpress backup xml file to jekylls structure. Since I liked the theme (decode) used on the wordpress site I 'ported' it to jekyll, or well cherry picked some parts and removed most things that I didn't need. Since I also moved the blog up from blog. to the top level I had to support the old links too, that is done using a nginx instance that does a redirect (301, permanent) from blog.* to the top level with the path intact.

A big bonus with jekyll is that I can write my posts in markdown and they are stored as simple text, no weird database or anything.

When I moved of one.com I lost my mail account that was connected to the domain, and since google apps doesn't accept any new accounts for free anymore I looked around for an alternative that could work. While outlook.com does offer custom domain hosting if looked around a bit more and found zoho they offer a bit less space per account than google but has pop3/imap access and overall as fast as gmail.