InEnglish

How to modify SQLite3 schemas

Sunday, 31 January 2016
|
Écrit par
Grégory Soutadé

SQLite3 is a wonderful library allowing to have a tiny SQL database in a simple file rather than a big (but more powerful) SQL server. I use it a lot for my projects to be "self contained".

Unfortunately, SQLite3 has some limitations. One of them is the unavailability to modify columns constraints or to delete them.

By upgrading from Django 1.5 to Django 1.8, I found that I cannot add a new user to my database. The problem is that the constraint of the last_login column in the User schema (controlled by Django framework) has changed. Now it can be NULL, while the table was created with a non NULL constraint. I got this exception :

NOT NULL constraint failed: auth_user.last_login

I already faces this kind of situation. The solution is pretty simple and does not requires modifying code.

First of all, make a backup of your database.

To get round this problem, we will export database in SQL commands format, modify it with a simple text editor and import it again.

Assume that your database is named denote.db

$ cp denote.db denote.db.bak
$ sqlite3 denote.db
$ .output denote.sql
$ .dump
$ .exit
$ rm denote.db
$ emacs denote.sql
...
$ sqlite3 -init denote.sql denote.db
$ sudo apachectl restart

That's all !

For complex modifications, it can be long/boring, so I recommend to use tools like sed, perl or python scripts, regexp replace mode from emacs...

LUKS on Cubox (imx6 platform)

Sunday, 09 August 2015
|
Écrit par
Grégory Soutadé

Now I have a Cubox (i2ex), I wanted to encrypt my backup disks. I followed this excellent tutorial. The cipher recommendation is aes-xts-plain64. So, I created formated disk, encrypt it, copy data from my computer and connect it to the Cubox.

But, I get this error :

cryptsetup --type luks open /dev/sda1 backup
Enter passphrase for /dev/sda1: 
No key available with this passphrase.

I tried a couple of times, use a keyfile. Nothing worked !! It made me crazy. After a bunch of search, I found that the current kernel in the Debian image from Igor Pečovnik is 3.14.14 and has issues with NEON AES implementation.

I cannot blacklist the module as it's builtin. The solution is to build a new module from the latest 3.14.49 kernel (maintained by Greg Kroah-Hartman). Ouf ! I increased cra_priority to be sure to use the new implementation.

Instructions

In the Cubox :

  • Install kernel headers (already here in the image)
  • Download the latest 3.14 kernel from kernel.org
  • Decompress it
  • Apply this patch
  • Compile
  • Install
  • Reboot

Commands :

patch -p1 < crypto.patch
cd linux-3.14.49/arch/arm/crypto/
make
sudo make install
sudo echo aes-arm-bs >> /etc/modules
reboot

If you just want to test :

insmod aes-arm-bs.ko

Precompiled version

A precompiled version is available here. To manually install it :

sudo cp aes-arm-bs.ko /lib/modules/3.14.14-cubox-i/extra/
sudo depmod
sudo echo aes-arm-bs >> /etc/modules

Or just

sudo make install
sudo echo aes-arm-bs >> /etc/modules

How to make custom ROM for Cybook e-readers

Monday, 06 July 2015
|
Écrit par
Grégory Soutadé

Bookeen doesn't provides any way to hack their e-ink e-readers. Nevertheless, after they introduce a secured update file format for the first Cybook serie, they come back to a "tar-like" format for their e-readers based on Allwiner platform (new Odyssey, Muse, Nolimbook...). With this format, they try to be closest to Android platform.

Be careful : handling all bookeen's readers is difficult because there is a lot of derived/customized readers available ! For this, Bookeen has its own server that checks for serial number to determine which update to serve. A special attention must be done with manipulating boot and bootloader images, it can bricks your e-reader !

This tutorial will only works with UNIX/Linux tools, I do not plan to do it for Windows.

So, let's start. An archive is commonly named CybUpdate.bin. In facts it's a .tar.bz2 file.

First, decompresse it :

mkdir decompressed
cd decompressed
tar -jxvf ../CybUpdate.bin

The following content should be created :

contents
bootloader.fex
boot.fex
rootfs.fex

I think that boot.fex and bootloader.fex are optional, but not sure. Two types of files are present :

  • contents that contains meta information
  • fex files

Contents has the following format :

<ident>|<filename>|<length>|<sha256sum>|<version>

idents are :

  • LOAD for bootloader
  • BOOT for boot partition
  • ROOT for rootfs

Fex extension is a generic one that actually is flash images in different format (vfat, ext...).

In bootloader.fex and rootfs.fex we have a file "/version" specifying the current version (allowing to do checks). Mounting bootloader and rootfs is quite easy :

mkdir root
sudo mount -t ext2 rootfs.fex root -o loop

mkdir bootloader
sudo mount -t vfat bootloader.fex bootloader -o loop

After doing modifications, just unmount the directory and the image is automatically generated ! (Don't forget to update contents metadata).

boot.fex is more complex, it has Android bootloader format. You have to use split_bootimg.pl to decompress it.

mkdir boot
cd boot
../split_bootimg.pl ../boot.fex
> Page size: 2048 (0x00000800)
> Kernel size: 10863524 (0x00a5c3a4)
> Ramdisk size: 2253456 (0x00226290)
> Second size: 0 (0x00000000)
> Board name: sun5i
> Command line: 
> Writing boot.fex-kernel ... complete.
> Writing boot.fex-ramdisk.gz ... complete.

boot.fex-kernel is a binary version (compiled) of Linux.

Then we decompress ramdisk :

mkdir ramdisk_decompressed
cd ramdisk_decompressed
gzip -dc ../boot.fex-ramdisk.gz | cpio -i

You can re compress it with :

find | cpio -o | gzip -c > ../boot.fex-ramdisk.gz

Rebuilding boot is done with mkbootimg. Be careful to use the same parameters split_bootimg.pl displayed !

./mkbootimg.py --kernel boot.fex-kernel --ramdisk boot.fex-ramdisk.gz --pagesize 2048 --board sun5i -o ../boot.fex

As you see, there is nothing complicated here, but mistakes with boot/bootloader or init scripts can bricks your e-reader.

Have fun !

Mixing Apache2 and nginx log file

Wednesday, 27 May 2015
|
Écrit par
Grégory Soutadé

My configuration is a bit specific. I have an Apache server for PHP and Python stuff with nginx as a frontend (and for serving static files like this blog). This part seems normal for most of people. BUT, in my case, I want that the two servers write the access logs IN THE SAME FILE (/var/log/apache2/access.log)

I run a Debian stable on my server. With the previous version (7.0), all was fine, but, until Jessie (8.0), I found a very strange behaviour with my web statistics analyzer. I usually have from 60 to 80 visits per day. In may (after the upgrade to Jessie), I get only 2 or 3 visits per day, using only one subdomain. Plus, it's a period where I have no internet at home and no time to investigate...

Finally, I found the problem ! It's located in logrotate. The two files are :

/etc/logrotate.d/apache2

/var/log/apache2/*.log {
    daily
    missingok
    rotate 14
...
    postrotate
            if /etc/init.d/apache2 status > /dev/null ; then \
                /etc/init.d/apache2 reload > /dev/null; \
            fi;
    endscript
...
}

And /etc/logrotate.d/nginx

/var/log/nginx/*.log {
    weekly
    missingok
    rotate 52
...
    postrotate
            invoke-rc.d nginx rotate >/dev/null 2>&1
    endscript
}

The first one do a logrotate every day of all files in /var/log/apache2/*.log (that contains our . The second one, do only one logrotate every week. But, the most important line is located in postrotate. Why it's important ? Because it says to nginx and Apache "Now the log file has changed, close the previous and open the new one". Seems correct, but without that, nginx write in /var/log/apache2/access.log.1 and not /var/log/apache2/access.log until it gets rotated (after a week) because it will keep the handle on access.log that is renamed to access.log.1 by logrotate.

The solution is to add

invoke-rc.d nginx rotate >/dev/null 2>&1

In the postrotate section of /etc/logrotate.d/apache2 (after the if). Then, restart nginx :

systemctl restart nginx

GAME_OVER

Monday, 02 March 2015
|
Écrit par
Grégory Soutadé

EDITED : 03rd January 2019 : Add ADB section

EDITED : 03rd September 2018 : Muse HD screen calibration issue seems solved

EDITED : 29th January 2018 : Link for Nolimbook 5.2.2020 stock rom

EDITED : 31th December 2017 : Add jailbreak for Nolimbook HD 6.3.2325

EDITED : 10th August 2017 : Add jailbreak for Muse HD 2 6.3.2536 (thanks Lupin)

EDITED : 2nd August 2016 : Add jailbreak for Odyssey Frontlight 2 6.3.2322

EDITED : 27th july 2016 : Add jailbreak for Muse 6.3.2350

EDITED : 15th august 2015 : Add jailbreak_backup (suggested by niceguy)

EDITED : 12th august 2015 : Another problem with Odyssey jailbreak reported by niceguy.

EDITED : 21th july 2015 : Totally rework Odyssey jailbreak : key generation was bad

EDITED : 07th july 2015 : Seems not to work for firmware >= 2340. Add /lib/libutils.so.

EDITED : 28th may 2015 : Remove Orizon/Fallback support (now it's tested). Set Muse jailbreak to version 6.3.2326

EDITED : 2nd april 2015

Those who do not try to hack the Cybook Odyssey e-reader won't understand the title. In facts, Bookeen appends this sentence at the end of update files. Arrogant, isn't it ? Surely, but now it's outdated.

Bookeen primary delivers a full access to its e-readers. Unfortunately, since Odyssey one they became very proprietary while its concurrents (except Amazon) lets user modify the core system. Did the concurrents puts out of business ? No. They're still alive, and they sell more e-readers than Bookeen. Kobo ahead.

OK, stop doing politic and start hacking. It has been a hard work, but I finally did it : a Cybook Jailbreak.

This jailbreak installs dropbear (a SSH client/server) onto the e-reader and launch it at boot. It has been fully tested on Cybook Odyssey and Nolimbook HD+ (Muse) whatever the firmware version running. See notes for other Cybook versions.

Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ADB

I Finally found how to activate adb daemon on AW8/13 platforms (all platforms except Odyssey one). It's less destructive than apply a new update. To do it, follow these instructions :

  • Plug your reader in USB mode
  • Create an empty file called "adb_debug" in the mounted filesystem
  • Unplug your reader
  • Plug your reader in USB mode again
  • A popup should appears asking you if you want your computer to see your reader's files : SAY NO
  • Go to Menu -> Advanced
  • Click on "Open ADB"

Now you should be able to use adb util to open a shell on your reader. I can't start adb on my Odyssey reader, maybe you should enable ADB first and plug your reader after or use adb through Wifi.

Downloads

It seems that more and more people have problems with these jailbreaks for Nolimbook device. So, please, don't try it if your current reader has a different version than the proposed one. Plus, Bookeen don't seems to upload new firmwares (they're only burned in factory). For now (as I don't own a Muse serie device), I can't provide another way to jailbreak it.

Muse firmware should be compatible with Odyssey frontlight 2

Signature verification

gpg --verify SHA256SUMS.sign SHA256SUMS

My gpg key can be found here

Instructions

Rename downloaded files into CybUpdate.bin and copy it to the e-reader via USB. De-connect USB and start upgrade.

Once rebooted, activate Wifi and connect to the e-reader (you can find the IP address in your internet box/router web interface) :

ssh -o "KexAlgorithms +diffie-hellman-group1-sha1" -o "Ciphers +aes128-cbc" root@EREADERIP

There is no password.

Those who uses Windows can download putty as SSH client.

Info : I compiled a new version of dropbear, but I'm not able to test it. If someone want to test, send me an email. I will then put it on new jailbreak versions.

Enjoy !

Tip : The e-reader goes to sleep after X minutes of inactivity and switch off Wifi, and thus SSH connexion. To avoid this problem, kill ebrmain and boordr (the first re spawn the second).

Notes for Muse/Nolimbook/Odyssey essential/Odyssey frontlight 2 e-readers

The update format has changed and for my surprise it's more simple than the previous one. I saw that the whole flash is overwritten during an update. So, keep the jailbreak related to your current version.

If you want to make your own custom ROM, please read my another article How to make custom ROM for Cybook e-readers

Nolimbook recover

A lot of people bricked their reader after applying jailbreak on Carrefour Nolimbook device. KotCzarny succeded in recover its reader by reading NAND flash thanks to UART pads available on motherboard. Here is a stock ROM 5.2.2020. Thanks to him ! For any more help, he is reachable on freenode irc, channel #h3droid, nick KotCzarny.

A page dedicated to Muse device has been created on linux-sunxi. You'll find some information about Muse hardware and FEL mode (in an other section). On new hardware boards, there is no information printed about UART pins, you needs to search dedicated pins thanks to a multimeter. Don't hesitate to update the page with new information !

Backup for Odyssey

Hacking Odyssey may lead to editing/removing files you should not. A backup jailbreak that contains a full factory image (+SSH server) is available for Odyssey readers. It willl only works if /boot has not been damaged !!

Hacking Muse

Alejandro Antúnez hacks basic display/event functions in combination with DirectFB, helping develop applications. Code and example are available on GitHub. A lot of thanks to him.

Legal notices

Providing a jailbreak is not a benign choice. I had a long reflexion before this and tried to know why Bookeen doesn't wants users access core system. The only response I got was "It's not scheduled".

Laws concerning copyright are complex and different in each country. France has its own who is called DADVSI (Loi relative au droit d'auteur et aux droits voisins dans la société de l'information) which is the transposition of European directives. It defines DRM and penal sentences. We can resume in some paragraphs (sorry, french only) :

Article 13

« Art. L. 331-5. - Les mesures techniques efficaces destinées à empêcher ou à limiter les utilisations non autorisées par les titulaires d'un droit d'auteur ou d'un droit voisin du droit d'auteur d'une oeuvre, autre qu'un logiciel, d'une interprétation, d'un phonogramme, d'un vidéogramme ou d'un programme sont protégées dans les conditions prévues au présent titre.

« On entend par mesure technique au sens du premier alinéa toute technologie, dispositif, composant qui, dans le cadre normal de son fonctionnement, accomplit la fonction prévue par cet alinéa. Ces mesures techniques sont réputées efficaces lorsqu'une utilisation visée au même alinéa est contrôlée par les titulaires de droits grâce à l'application d'un code d'accès, d'un procédé de protection tel que le cryptage, le brouillage ou toute autre transformation de l'objet de la protection ou d'un mécanisme de contrôle de la copie qui atteint cet objectif de protection.

Un protocole, un format, une méthode de cryptage, de brouillage ou de transformation ne constitue pas en tant que tel une mesure technique au sens du présent article.

« Les mesures techniques ne doivent pas avoir pour effet d'empêcher la mise en oeuvre effective de l'interopérabilité, dans le respect du droit d'auteur. Les fournisseurs de mesures techniques donnent l'accès aux informations essentielles à l'interopérabilité dans les conditions définies aux articles L. 331-6 et L. 331-7.

« Les mesures techniques ne peuvent s'opposer au libre usage de l'oeuvre ou de l'objet protégé dans les limites des droits prévus par le présent code, ainsi que de ceux accordés par les détenteurs de droits.

Article 14

« Art. L. 331-7. - Tout éditeur de logiciel, tout fabricant de système technique et tout exploitant de service peut, en cas de refus d'accès aux informations essentielles à l'interopérabilité, demander à l'Autorité de régulation des mesures techniques de garantir l'interopérabilité des systèmes et des services existants, dans le respect des droits des parties, et d'obtenir du titulaire des droits sur la mesure technique les informations essentielles à cette interopérabilité. A compter de sa saisine, l'autorité dispose d'un délai de deux mois pour rendre sa décision.

« On entend par informations essentielles à l'interopérabilité la documentation technique et les interfaces de programmation nécessaires pour permettre à un dispositif technique d'accéder, y compris dans un standard ouvert au sens de l'article 4 de la loi n° 2004-575 du 21 juin 2004 pour la confiance dans l'économie numérique, à une oeuvre ou à un objet protégé par une mesure technique et aux informations sous forme électronique jointes, dans le respect des conditions d'utilisation de l'oeuvre ou de l'objet protégé qui ont été définies à l'origine.

« L'autorité a le pouvoir d'infliger une sanction pécuniaire applicable soit en cas d'inexécution de ses injonctions, soit en cas de non-respect des engagements qu'elle a acceptés. Chaque sanction pécuniaire est proportionnée à l'importance du dommage causé aux intéressés, à la situation de l'organisme ou de l'entreprise sanctionné et à l'éventuelle réitération des pratiques contraires à l'interopérabilité. Elle est déterminée individuellement et de façon motivée. Son montant maximum s'élève à 5 % du montant du chiffre d'affaires mondial hors taxes le plus élevé réalisé au cours d'un des exercices clos depuis l'exercice précédant celui au cours duquel les pratiques contraires à l'interopérabilité ont été mises en oeuvre dans le cas d'une entreprise et à 1,5 million d'euros dans les autres cas.

Article 21

« Art. L. 335-2-1. - Est puni de trois ans d'emprisonnement et de 300 000 EUR d'amende le fait :

1° D'éditer, de mettre à la disposition du public ou de communiquer au public, sciemment et sous quelque forme que ce soit, un logiciel manifestement destiné à la mise à disposition du public non autorisée d'oeuvres ou d'objets protégés ;

I think it's a good summary. The purpose of this jailbreak is to fully access a computer I OWN without damage it. Particularly, it do not help to get/read illegal content.