5
  SQLite
Taro Matsuzawa aka. btm (@smellman)
  sumaben@kanto #11 Lightning Talk
SQLite

• iPhone       SQL

•
• Firefox
• JB
 •     Blob
sqlcipher
• SQLite
 • SQLite


• iPhone
1

$ sudo mkdir -p /opt/smartphone/lib
$ sudo chown -R btm:staff /opt/smartphone
$ cd /opt/smartphone/lib/
$ git clone git://github.com/sjlombardo/sqlcipher.git
$ curl -O ftp://ftp.infoscience.co.jp/pub/Crypto/SSL/openssl/source/openssl-1.0.0a.tar.gz
$ git clone git://github.com/sjlombardo/openssl-xcode.git
$ tar zxf openssl-1.0.0a.tar.gz
$ cp -fr openssl-xcode/openssl.xcodeproj openssl-1.0.0a/
$ mv openssl-1.0.0a openssl
2
•   XCode

    •
        •   SQLCIPHER_SRC       SQLCipher

            •   SQLCIPHER_SRC:/opt/smartphone/lib/sqlcipher

        •   OPENSSL_SRC       OpenSSL

            •   OPENSSL_SRC:/opt/smartphone/lib/openssl
3

•   XCode                      ->

    •   OpenSSL          openssl.xcodeproj

        •

    •        SQLCipher              sqlcipher.xcodeproj
4

•   SQLCipher    OpenSSL

    •   sqlcipher.xcodeproj                  ->

        •                   SQLCIPHER_SRC

    •   openssl.xcodeproj                   ->

        •                   OPENSSL_SRC
5
•   XCode                            ->
        "SQLCipherTest"

    •                                       +

        •   OpenSSL   crypto   SQLCipher   sqlcipher

    •
        •
            •   $(SQLCIPHER_SRC)   $(OPENSSL_SRC)
6

•   sqlcipher.xcodeproj    libsqlcipher.a



•   openssl.xcodeproj     libcrypto.a



•                                           SQLITE_HAS_CODEC=1
•   SQL

    •   PRAGMA key = 'default_key';

    •                       sqlcipher

•
•   FMDatabase

    •   FMDatabase setKey
! NSString* key = @"TaroMatsuzawaIsDead";
! NSString* newKey = [key stringByAppendingString:
             [[UIDevice currentDevice] uniqueIdentifier]];

! if (![rootViewController.encdb setKey:key])
! ! NSLog(@"> Could not set key.");
URL
•   sqlcipher

    •   http://sqlcipher.net/

•   sqlcipher document

    •   http://sqlcipher.net/documentation

•   openssl-xcode

    •   https://github.com/sjlombardo/openssl-xcode

•   FMDatabase

    •   https://github.com/ccgus/fmdb
•
$ sudo port install openssl
$ mkdir -p ~/develop/sqlcipher
$ cd ~/develop/sqlcipher
$ git clone git://github.com/sjlombardo/sqlcipher.git
$ cd sqlcipher
$ ./configure CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="/opt/local/lib/libcrypto.a"
$ make

$ ~/develop/sqlcipher/sqlcipher/sqlite3 sqlite3.db
SQLite version 3.7.2
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .read /Users/btm/develop/(      )/schema.sql
sqlite> PRAGMA key = 'default_key';

スマートフォン勉強会@関東 #11 LT 5分で語る SQLite暗号化

  • 1.
    5 SQLite TaroMatsuzawa aka. btm (@smellman) sumaben@kanto #11 Lightning Talk
  • 2.
    SQLite • iPhone SQL • • Firefox
  • 3.
  • 4.
    sqlcipher • SQLite •SQLite • iPhone
  • 5.
    1 $ sudo mkdir-p /opt/smartphone/lib $ sudo chown -R btm:staff /opt/smartphone $ cd /opt/smartphone/lib/ $ git clone git://github.com/sjlombardo/sqlcipher.git $ curl -O ftp://ftp.infoscience.co.jp/pub/Crypto/SSL/openssl/source/openssl-1.0.0a.tar.gz $ git clone git://github.com/sjlombardo/openssl-xcode.git $ tar zxf openssl-1.0.0a.tar.gz $ cp -fr openssl-xcode/openssl.xcodeproj openssl-1.0.0a/ $ mv openssl-1.0.0a openssl
  • 6.
    2 • XCode • • SQLCIPHER_SRC SQLCipher • SQLCIPHER_SRC:/opt/smartphone/lib/sqlcipher • OPENSSL_SRC OpenSSL • OPENSSL_SRC:/opt/smartphone/lib/openssl
  • 7.
    3 • XCode -> • OpenSSL openssl.xcodeproj • • SQLCipher sqlcipher.xcodeproj
  • 8.
    4 • SQLCipher OpenSSL • sqlcipher.xcodeproj -> • SQLCIPHER_SRC • openssl.xcodeproj -> • OPENSSL_SRC
  • 9.
    5 • XCode -> "SQLCipherTest" • + • OpenSSL crypto SQLCipher sqlcipher • • • $(SQLCIPHER_SRC) $(OPENSSL_SRC)
  • 10.
    6 • sqlcipher.xcodeproj libsqlcipher.a • openssl.xcodeproj libcrypto.a • SQLITE_HAS_CODEC=1
  • 11.
    SQL • PRAGMA key = 'default_key'; • sqlcipher • • FMDatabase • FMDatabase setKey
  • 12.
    ! NSString* key= @"TaroMatsuzawaIsDead"; ! NSString* newKey = [key stringByAppendingString: [[UIDevice currentDevice] uniqueIdentifier]]; ! if (![rootViewController.encdb setKey:key]) ! ! NSLog(@"> Could not set key.");
  • 13.
    URL • sqlcipher • http://sqlcipher.net/ • sqlcipher document • http://sqlcipher.net/documentation • openssl-xcode • https://github.com/sjlombardo/openssl-xcode • FMDatabase • https://github.com/ccgus/fmdb
  • 14.
    • $ sudo portinstall openssl $ mkdir -p ~/develop/sqlcipher $ cd ~/develop/sqlcipher $ git clone git://github.com/sjlombardo/sqlcipher.git $ cd sqlcipher $ ./configure CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="/opt/local/lib/libcrypto.a" $ make $ ~/develop/sqlcipher/sqlcipher/sqlite3 sqlite3.db SQLite version 3.7.2 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .read /Users/btm/develop/( )/schema.sql sqlite> PRAGMA key = 'default_key';