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

6,739 views
6,545 views

Published on

Published in: Technology

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

  1. 1. 5 SQLiteTaro Matsuzawa aka. btm (@smellman) sumaben@kanto #11 Lightning Talk
  2. 2. SQLite• iPhone SQL•• Firefox
  3. 3. • JB • Blob
  4. 4. sqlcipher• SQLite • SQLite• iPhone
  5. 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. 6. 2• XCode • • SQLCIPHER_SRC SQLCipher • SQLCIPHER_SRC:/opt/smartphone/lib/sqlcipher • OPENSSL_SRC OpenSSL • OPENSSL_SRC:/opt/smartphone/lib/openssl
  7. 7. 3• XCode -> • OpenSSL openssl.xcodeproj • • SQLCipher sqlcipher.xcodeproj
  8. 8. 4• SQLCipher OpenSSL • sqlcipher.xcodeproj -> • SQLCIPHER_SRC • openssl.xcodeproj -> • OPENSSL_SRC
  9. 9. 5• XCode -> "SQLCipherTest" • + • OpenSSL crypto SQLCipher sqlcipher • • • $(SQLCIPHER_SRC) $(OPENSSL_SRC)
  10. 10. 6• sqlcipher.xcodeproj libsqlcipher.a• openssl.xcodeproj libcrypto.a• SQLITE_HAS_CODEC=1
  11. 11. • SQL • PRAGMA key = default_key; • sqlcipher•• FMDatabase • FMDatabase setKey
  12. 12. ! NSString* key = @"TaroMatsuzawaIsDead";! NSString* newKey = [key stringByAppendingString: [[UIDevice currentDevice] uniqueIdentifier]];! if (![rootViewController.encdb setKey:key])! ! NSLog(@"> Could not set key.");
  13. 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. 14. •$ 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.dbSQLite version 3.7.2Enter ".help" for instructionsEnter SQL statements terminated with a ";"sqlite> .read /Users/btm/develop/( )/schema.sqlsqlite> PRAGMA key = default_key;

×