Thursday, September 20, 2012

Generate MD5, SHA-1 or SHA-512 UNIX password hashes in Python

When scripting the installation of an Ubuntu server template, I needed to pre-populate the template with a couple of system users that had specific passwords.

My old method of doing this was using openssl:

$ openssl passwd -1

Password: secretstuff
Verifying - Password: secretstuff
$1$IothUf.l$E/4eCqLD9JLdg2et7FurS1


This generates the standard MD5-based password hashes that work in the /etc/shadow file. The string enclosed in the first and second dollar sign indicates the hash method used. The string enclosed in the second and third dollar sign is the password salt used.

If you need other formats, I ended up using Python's built-in crypt module. It supports MD5, SHA-1 and SHA-256 hashes, depending on the value you provide as the "salt" (second parameter):

Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
<<< import crypt
<<< crypt.crypt('secret', '$1$somesalt$')
'$1$somesalt$jezmI5TSY7mVTzHLgsK5L.'
<<< crypt.crypt('secret', '$5$somesalt$')
'$5$somesalt$BY2M0Tw/b.yijagFoMZoeHEQSuk9iqvGNX/dBDdRp8A'
<<< crypt.crypt('secret', '$6$somesalt$')
'$6$somesalt$JX0Uhce8rLRHbaqoSQDYsnTxsqcjCNNcrl79ieTwPGzEhxBEeJcsgDUWIOwc3sDvZN34ZJBWQep7.lcAuSesy/'

Thursday, September 6, 2012

Kdenlive with X.264 Support in Ubuntu 12.04

When installing kdenlive in Ubuntu 12.04, I was not able to export videos in H.264 and other formats out-of-the-box. Instead, I would get "output format not supported" errors when trying to render the videos, even though libx264 was installed.

I came across this multiple times already and was scratching my head every time, since enough time had passed since the last time I dealt with this. I could not easily remember what Ubuntu package was missing. Now it goes in my little knowledge base for next time, hehe.

The package needed is libavcodec-extra-53:
$ sudo apt-get install libavcodec-extra-53

Wednesday, September 5, 2012

Run Android SDK in 64-bit Ubuntu 12.04

When installing the Android SDK on a pure 64-bit Ubuntu system, I noticed that the tools and platform toold didn't run:
/opt/android-sdk-linux $ ./platform-tools/adb

bash: ./platform-tools/adb: No such file or directory

The files are executable and binaries, but compiled for 32-bit environments:
/opt/android-sdk-linux $ file ./platform-tools/adb

/opt/android-sdk-linux/platform-tools/adb: ELF 32-bit
LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.8,
stripped

Trying to find out the usual way, which 32-bit libraries it needs, did not work:
/opt/android-sdk-linux $ ldd ./platform-tools/adb

not a dynamic executable

Searching through several posts on the Internet, people recommended to install the whole set of 32-bit compatibility libraries in the form of the ia32-libs-multiarch package. This would have pulled in 230 new packages with all kinds of 32-bit libraries, and I did not care for this all that much.

So I tried to manually install just the lib32stdc++6 package (pulling in 2 more packages and 4 MB worth of data). Then I re-ran the ldd command to find out what else was needed:
/opt/android-sdk-linux $ ldd ./platform-tools/adb

        linux-gate.so.1 =>  (0xf77b2000)
        librt.so.1 => /lib32/librt.so.1 (0xf7795000)
        libncurses.so.5 => not found
        libpthread.so.0 => /lib32/libpthread.so.0 (0xf777a000)
        libstdc++.so.6 => /usr/lib32/libstdc++.so.6 (0xf7695000)
        libm.so.6 => /lib32/libm.so.6 (0xf766a000)
        libgcc_s.so.1 => /usr/lib32/libgcc_s.so.1 (0xf764b000)
        libc.so.6 => /lib32/libc.so.6 (0xf74a9000)
        /lib/ld-linux.so.2 (0xf77b3000)

Only the libncurses.so.5 is still missing! Yaay. After installing lib32ncurses5 (pulling in one dependency and 200 KB), the adb and fastboot tools launched fine:
/opt/android-sdk-linux $ ./platform-tools/adb version

Android Debug Bridge version 1.0.29