Update for PHP 8.4 and my needs (packaging happens elsewhere)
This commit is contained in:
parent
96df2f4362
commit
89fe566573
11 changed files with 27 additions and 787 deletions
54
README.en.md
54
README.en.md
|
|
@ -1,54 +0,0 @@
|
|||
# PDO SQLCipher
|
||||
|
||||
A driver for implementing [PDO](http://php.net/manual/en/book.pdo.php) (PHP Data Objects) interface for [SQLCipher](http://sqlcipher.net) without replacing genuine PDO SQLite or the system version of [SQLite](http://www.sqlite.org/). It's based on PDO SQLite source code and created by simply replacing names and inserting SQLCipher code (instead of dynamic linking with SQLite libraries).
|
||||
|
||||
A detachment of this kind allows granting access to encrypted databases only to applications that obviously need it, without fear of data loss or slowing down other applications.
|
||||
|
||||
## Assembling
|
||||
|
||||
To assemble this extension, run `build.sh` script. After successful assembly, all the necessary files will be placed in the directory named `release`:
|
||||
|
||||
* `sqlcipher` - console client (equivalent of `sqlite3` client)
|
||||
* `pdo_sqlcipher.so` - php extension (equivalent of `pdo_sqlite.so` extension)
|
||||
|
||||
If assembling is performed under Debain, the following dev packages may be required (in addition to standard):
|
||||
|
||||
* `libicu-dev`
|
||||
* `libreadline-dev`
|
||||
* `libssl-dev`
|
||||
* `php5-dev`
|
||||
* `tcl-dev`
|
||||
|
||||
If assembling is performed under RHEL, the following dev packages may be required (in addition to standard):
|
||||
|
||||
* `libicu-devel`
|
||||
* `readline-devel`
|
||||
* `openssl-devel`
|
||||
* `php-devel`
|
||||
* `tcl-devel`
|
||||
|
||||
If assembling is performed under FreeBSD, `lang/tcl-wrapper` port installation may be required (to support `tclsh`).
|
||||
|
||||
Assembling script was tested under Debian Wheezy (PHP 5.4.4-14) and FreeBSD 9.1 (PHP 5.4.13)
|
||||
|
||||
## Installation
|
||||
|
||||
Install this extension by copying files from the `release` directory:
|
||||
|
||||
* `sqlcipher` to the `/usr/local/bin/` directory
|
||||
* `pdo_sqlcipher.so` to the directory of php modules (depends on specific distro):
|
||||
* Debian: `/usr/lib/php5/20100525/`
|
||||
* RHEL: `/usr/lib64/php/modules/`
|
||||
* FreeBSD: `/usr/local/lib/php/20100525/`
|
||||
|
||||
And enable the php extension:
|
||||
|
||||
```
|
||||
extension=pdo_sqlcipher.so
|
||||
```
|
||||
|
||||
* Debian: `/etc/php5/conf.d/pdo_sqlcipher.ini`
|
||||
* RHEL: `/etc/php.d/pdo_sqlcipher.ini`
|
||||
* FreeBSD: `/usr/local/etc/php/extensions.ini`
|
||||
|
||||
You can find an example of extension usage in `example.php` file within the repository.
|
||||
34
README.md
34
README.md
|
|
@ -1,19 +1,17 @@
|
|||
# PDO SQLCipher
|
||||
|
||||
[English version](https://github.com/abbat/pdo_sqlcipher/blob/master/README.en.md)
|
||||
A driver for implementing [PDO](http://php.net/manual/en/book.pdo.php) (PHP Data Objects) interface for [SQLCipher](http://sqlcipher.net) without replacing genuine PDO SQLite or the system version of [SQLite](http://www.sqlite.org/). It's based on PDO SQLite source code and created by simply replacing names and inserting SQLCipher code (instead of dynamic linking with SQLite libraries).
|
||||
|
||||
Драйвер, реализующий интерфейс [PDO](http://php.net/manual/en/book.pdo.php) (PHP Data Objects) для [SQLCipher](http://sqlcipher.net) без замещения оригинальной версии PDO SQLite или системной версии [SQLite](http://www.sqlite.org/). Основан на оригинальном коде PDO SQLite путем простого замещения имен и встраиванием кода SQLCipher (вместо динамической линковки с библиотеками SQLite).
|
||||
A detachment of this kind allows granting access to encrypted databases only to applications that obviously need it, without fear of data loss or slowing down other applications.
|
||||
|
||||
Подобное разделение позволяет работать с шифрованными базами только тем приложениям, которые в этом явно нуждаются не опасаясь потери данных или замедления работы остальных приложений.
|
||||
## Assembling
|
||||
|
||||
## Сборка
|
||||
To assemble this extension, run `build.sh` script. After successful assembly, all the necessary files will be placed in the directory named `release`:
|
||||
|
||||
Для сборки расширения запустите скрипт `build.sh`. После успешной сборки необходимые файлы будут помещены в директорию `release`:
|
||||
* `sqlcipher` - console client (equivalent of `sqlite3` client)
|
||||
* `pdo_sqlcipher.so` - php extension (equivalent of `pdo_sqlite.so` extension)
|
||||
|
||||
* `sqlcipher` - консольный клиент (аналогичный клиенту `sqlite3`)
|
||||
* `pdo_sqlcipher.so` - расширение php (аналогичное расширению `pdo_sqlite.so`)
|
||||
|
||||
Для сборки под Debain могут потребоваться (помимо стандартных) следующие dev пакеты:
|
||||
If assembling is performed under Debain, the following dev packages may be required (in addition to standard):
|
||||
|
||||
* `libicu-dev`
|
||||
* `libreadline-dev`
|
||||
|
|
@ -21,7 +19,7 @@
|
|||
* `php5-dev`
|
||||
* `tcl-dev`
|
||||
|
||||
Для сборки под RHEL могут потребоваться (помимо стандартных) следующие dev пакеты:
|
||||
If assembling is performed under RHEL, the following dev packages may be required (in addition to standard):
|
||||
|
||||
* `libicu-devel`
|
||||
* `readline-devel`
|
||||
|
|
@ -29,21 +27,21 @@
|
|||
* `php-devel`
|
||||
* `tcl-devel`
|
||||
|
||||
Для сборки под FreeBSD может потребоваться установка порта `lang/tcl-wrapper` (для поддержки `tclsh`).
|
||||
If assembling is performed under FreeBSD, `lang/tcl-wrapper` port installation may be required (to support `tclsh`).
|
||||
|
||||
Скрипт сборки протестирован на Debian Wheezy (PHP 5.4.4-14) и FreeBSD 9.1 (PHP 5.4.13)
|
||||
Assembling script was tested under Debian Wheezy (PHP 5.4.4-14) and FreeBSD 9.1 (PHP 5.4.13)
|
||||
|
||||
## Установка
|
||||
## Installation
|
||||
|
||||
Для установки расширения скопируйте файлы из директории `release`:
|
||||
Install this extension by copying files from the `release` directory:
|
||||
|
||||
* `sqlcipher` в директорию `/usr/local/bin/`
|
||||
* `pdo_sqlcipher.so` в директорию модулей php (зависит от дистрибутива):
|
||||
* `sqlcipher` to the `/usr/local/bin/` directory
|
||||
* `pdo_sqlcipher.so` to the directory of php modules (depends on specific distro):
|
||||
* Debian: `/usr/lib/php5/20100525/`
|
||||
* RHEL: `/usr/lib64/php/modules/`
|
||||
* FreeBSD: `/usr/local/lib/php/20100525/`
|
||||
|
||||
И подключите расширение php:
|
||||
And enable the php extension:
|
||||
|
||||
```
|
||||
extension=pdo_sqlcipher.so
|
||||
|
|
@ -53,4 +51,4 @@ extension=pdo_sqlcipher.so
|
|||
* RHEL: `/etc/php.d/pdo_sqlcipher.ini`
|
||||
* FreeBSD: `/usr/local/etc/php/extensions.ini`
|
||||
|
||||
Пример использования расширения можно найти в файле `example.php` репозитория.
|
||||
You can find an example of extension usage in `example.php` file within the repository.
|
||||
|
|
|
|||
318
build-debian.sh
318
build-debian.sh
|
|
@ -1,318 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# SQLite3 compile options
|
||||
#
|
||||
|
||||
CFLAGS=" \
|
||||
-DSQLITE_HAS_CODEC \
|
||||
-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT \
|
||||
-DSQLITE_ENABLE_COLUMN_METADATA \
|
||||
-DSQLITE_ENABLE_STAT3 \
|
||||
-DSQLITE_ENABLE_RTREE \
|
||||
-DSQLITE_ENABLE_FTS3 \
|
||||
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
|
||||
-DSQLITE_ENABLE_FTS4 \
|
||||
-DSQLITE_SECURE_DELETE \
|
||||
-DSQLITE_ENABLE_ICU \
|
||||
-DSQLITE_SOUNDEX \
|
||||
-DSQLITE_DEFAULT_FOREIGN_KEYS=1 \
|
||||
-I. -I/usr/local/include"
|
||||
|
||||
LDFLAGS="-lcrypto -licuuc -licui18n -L/usr/local/lib"
|
||||
|
||||
|
||||
PHP_CONFIG=$(which php-config)
|
||||
|
||||
if [ "x${PHP_CONFIG}" = "x" ]; then
|
||||
echo "Error: php-config not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PHP_VER=$(${PHP_CONFIG} --version )
|
||||
PHP_API=$(${PHP_CONFIG} --phpapi )
|
||||
# There is prolly a better way to do this (getting the proper source pkg name):
|
||||
PHP_DEB_VER="$(dpkg-query -W -f='${Version}' php5)"
|
||||
PHP_SRC=php5-${PHP_DEB_VER%*-*}
|
||||
|
||||
if [ "x${PHP_VER}" = "x" ]; then
|
||||
echo "Error: unknown php version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "${PHP_SRC}" ]; then
|
||||
apt-get source php5
|
||||
if [ $? -ne 0 ]; then
|
||||
# sources.list not defined source packages
|
||||
echo "Cannot get the php source package, please add a 'source' line to /etc/apt/sources.list"
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Get SQLCipher source code and make SQLite Amalgamation
|
||||
#
|
||||
|
||||
SQLCIPHER_SRC="sqlcipher.git"
|
||||
|
||||
if [ ! -d "${SQLCIPHER_SRC}" ]; then
|
||||
git clone "git://github.com/sqlcipher/sqlcipher.git" "${SQLCIPHER_SRC}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f "${SQLCIPHER_SRC}/sqlite3.c" ]; then
|
||||
cd "${SQLCIPHER_SRC}"
|
||||
|
||||
make distclean
|
||||
|
||||
# subject to change (see http://www.sqlite.org/compile.html)
|
||||
./configure \
|
||||
--disable-shared \
|
||||
--enable-tempstore=yes \
|
||||
CFLAGS="${CFLAGS}" \
|
||||
LDFLAGS="${LDFLAGS}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
make
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cd ..
|
||||
fi
|
||||
|
||||
#
|
||||
# Clone pdo_sqlite sources for pdo_sqlcipher
|
||||
#
|
||||
|
||||
BUILD_DIR="build"
|
||||
|
||||
if [ -d "${BUILD_DIR}" ]; then
|
||||
rm -rf "${BUILD_DIR}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "${BUILD_DIR}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
PDO_SQLITE="${PHP_SRC}/ext/pdo_sqlite"
|
||||
|
||||
cp "${PDO_SQLITE}/"*.c "${PDO_SQLITE}"/*.h "${BUILD_DIR}/"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# magic :)
|
||||
for FILE in "${BUILD_DIR}"/*
|
||||
do
|
||||
cat "${FILE}" | \
|
||||
sed -e 's/sqlite/sqlcipher/g' | \
|
||||
sed -e 's/SQLite/SQLCipher/g' | \
|
||||
sed -e 's/PDO_SQLITE/PDO_SQLCIPHER/g' > \
|
||||
"${FILE}.tmp"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
NEW_FILE=$(echo ${FILE} | sed 's/sqlite/sqlcipher/')
|
||||
|
||||
mv "${FILE}.tmp" "${NEW_FILE}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
if [ "${NEW_FILE}" != "${FILE}" ]; then
|
||||
rm -f "${FILE}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# magic for sqlite3 api sources
|
||||
cp "${SQLCIPHER_SRC}/sqlite3.c" "${BUILD_DIR}/sqlcipher3.c"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cp "${SQLCIPHER_SRC}/sqlite3.h" "${BUILD_DIR}/sqlcipher3.h"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
for FILE in "${BUILD_DIR}"/sqlcipher3.*
|
||||
do
|
||||
sed -ie 's/sqlite3/sqlcipher3/g' "${FILE}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
sed -rie 's/(".*)sqlcipher3(.*")/\1sqlite3\2/g' "${FILE}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
done
|
||||
|
||||
#
|
||||
# Build pdo_sqlcipher
|
||||
#
|
||||
|
||||
cp "config.m4" "${BUILD_DIR}/config.m4"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cd "${BUILD_DIR}"
|
||||
|
||||
phpize --clean
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
phpize
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
./configure \
|
||||
CFLAGS="${CFLAGS}" \
|
||||
LDFLAGS="${LDFLAGS}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
make
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cd ..
|
||||
|
||||
#
|
||||
# Copy binaries
|
||||
#
|
||||
|
||||
RELEASE_DIR="release"
|
||||
|
||||
if [ -d "${RELEASE_DIR}" ]; then
|
||||
rm -rf "${RELEASE_DIR}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "${RELEASE_DIR}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# pdo_sqlite.so
|
||||
cp "${BUILD_DIR}/modules/pdo_sqlcipher.so" "${RELEASE_DIR}/pdo_sqlcipher.so"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
strip "${RELEASE_DIR}/pdo_sqlcipher.so"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
chmod 0644 "${RELEASE_DIR}/pdo_sqlcipher.so"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# sqlcipher static binary
|
||||
cp "${SQLCIPHER_SRC}/sqlcipher" "${RELEASE_DIR}/sqlcipher"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
strip "${RELEASE_DIR}/sqlcipher"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
#
|
||||
# Clean
|
||||
#
|
||||
|
||||
#rm -rf ${PHP_SRC}
|
||||
#rm -rf ${SQLCIPHER_SRC}
|
||||
#rm -rf ${BUILD_DIR}
|
||||
#rm -f ${PHP_TGZ}
|
||||
|
||||
|
||||
## Create the .deb package
|
||||
|
||||
LIBICU="$(dpkg-query -W -f='${Package}\n' libicu* | grep -v '\-')"
|
||||
LIBICU_VER="$(dpkg-query -W -f='${Version}' $LIBICU)"
|
||||
|
||||
sed -i "s/_PHP_DEB_VER/$PHP_DEB_VER/g;s/_PHP_VER/$PHP_VER/g;s/_PHP_API/$PHP_API/g;s/_LIBICU_VER/$LIBICU_VER/g;s/_LIBICU/$LIBICU/g" package/DEBIAN/control
|
||||
|
||||
mkdir -p package/usr/bin
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
mkdir -p package/usr/lib/php5/${PHP_API}
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cp "${RELEASE_DIR}/pdo_sqlcipher.so" package/usr/lib/php5/${PHP_API}/
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cp "${RELEASE_DIR}/sqlcipher" package/usr/bin/
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cd package
|
||||
|
||||
md5deep -rl etc usr > DEBIAN/md5sums
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cd ..
|
||||
|
||||
fakeroot dpkg-deb -z9 -b package
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
mv package.deb php5-sqlcipher.deb
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# http://lintian.debian.org/tags.html
|
||||
lintian php5-sqlcipher.deb
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# clean
|
||||
rm -rf package/usr/bin
|
||||
rm -rf package/usr/lib
|
||||
rm -f package/DEBIAN/md5sums
|
||||
|
||||
echo "=============== All Done ====================="
|
||||
echo "Now run 'dpkg -i php5-sqlcipher.deb' to install"
|
||||
echo ""
|
||||
|
||||
exit
|
||||
|
||||
#EOF
|
||||
269
build.sh
269
build.sh
|
|
@ -1,269 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
#
|
||||
# SQLite3 compile options
|
||||
#
|
||||
|
||||
CFLAGS=" \
|
||||
-DSQLITE_HAS_CODEC \
|
||||
-DSQLITE_ENABLE_UPDATE_DELETE_LIMIT \
|
||||
-DSQLITE_ENABLE_COLUMN_METADATA \
|
||||
-DSQLITE_ENABLE_STAT3 \
|
||||
-DSQLITE_ENABLE_RTREE \
|
||||
-DSQLITE_ENABLE_FTS3 \
|
||||
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
|
||||
-DSQLITE_ENABLE_FTS4 \
|
||||
-DSQLITE_SECURE_DELETE \
|
||||
-DSQLITE_ENABLE_ICU \
|
||||
-DSQLITE_SOUNDEX \
|
||||
-DSQLITE_DEFAULT_FOREIGN_KEYS=1 \
|
||||
-I. -I/usr/local/include"
|
||||
|
||||
LDFLAGS="-lcrypto -licuuc -licui18n -L/usr/local/lib"
|
||||
|
||||
# fix FreeBSD include
|
||||
UNAME=$(uname)
|
||||
if [ "x${UNAME}" = "xFreeBSD" ]; then
|
||||
CFLAGS="${CFLAGS} -include /usr/include/sys/stat.h"
|
||||
fi
|
||||
|
||||
#
|
||||
# Get PHP source code (installed version)
|
||||
#
|
||||
|
||||
PHP_CONFIG=$(which php-config)
|
||||
|
||||
if [ "x${PHP_CONFIG}" = "x" ]; then
|
||||
echo "Error: php-config not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PHP_VER=$(${PHP_CONFIG} --version | cut -d '-' -f 1)
|
||||
PHP_MAJOR_VER=${PHP_VER:0:1}
|
||||
|
||||
if [ "x${PHP_VER}" = "x" ]; then
|
||||
echo "Error: unknown php version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PHP_SRC="php-${PHP_VER}"
|
||||
PHP_TGZ="${PHP_SRC}.tar.gz"
|
||||
|
||||
if [ ! -f "${PHP_TGZ}" ]; then
|
||||
wget "http://museum.php.net/php${PHP_MAJOR_VER}/${PHP_TGZ}"
|
||||
if [ $? -ne 0 ]; then
|
||||
# newest version?
|
||||
wget -O "${PHP_TGZ}" "http://ru2.php.net/get/${PHP_TGZ}/from/this/mirror"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -d "${PHP_SRC}" ]; then
|
||||
tar -xf "${PHP_TGZ}" -C ./
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# Get SQLCipher source code and make SQLite Amalgamation
|
||||
#
|
||||
|
||||
SQLCIPHER_SRC="sqlcipher.git"
|
||||
|
||||
if [ ! -d "${SQLCIPHER_SRC}" ]; then
|
||||
git clone "git://github.com/sqlcipher/sqlcipher.git" "${SQLCIPHER_SRC}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f "${SQLCIPHER_SRC}/sqlite3.c" ]; then
|
||||
cd "${SQLCIPHER_SRC}"
|
||||
|
||||
make distclean
|
||||
|
||||
# subject to change (see http://www.sqlite.org/compile.html)
|
||||
./configure \
|
||||
--disable-shared \
|
||||
--enable-tempstore=yes \
|
||||
CFLAGS="${CFLAGS}" \
|
||||
LDFLAGS="${LDFLAGS}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
make
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cd ..
|
||||
fi
|
||||
|
||||
#
|
||||
# Clone pdo_sqlite sources for pdo_sqlcipher
|
||||
#
|
||||
|
||||
BUILD_DIR="build"
|
||||
|
||||
if [ -d "${BUILD_DIR}" ]; then
|
||||
rm -rf "${BUILD_DIR}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "${BUILD_DIR}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
PDO_SQLITE="${PHP_SRC}/ext/pdo_sqlite"
|
||||
|
||||
cp "${PDO_SQLITE}/"*.c "${PDO_SQLITE}"/*.h "${BUILD_DIR}/"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# magic :)
|
||||
for FILE in "${BUILD_DIR}"/*
|
||||
do
|
||||
cat "${FILE}" | \
|
||||
sed -e 's/sqlite/sqlcipher/g' | \
|
||||
sed -e 's/SQLite/SQLCipher/g' | \
|
||||
sed -e 's/PDO_SQLITE/PDO_SQLCIPHER/g' > \
|
||||
"${FILE}.tmp"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
NEW_FILE=$(echo ${FILE} | sed 's/sqlite/sqlcipher/')
|
||||
|
||||
mv "${FILE}.tmp" "${NEW_FILE}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
if [ "${NEW_FILE}" != "${FILE}" ]; then
|
||||
rm -f "${FILE}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# magic for sqlite3 api sources
|
||||
cp "${SQLCIPHER_SRC}/sqlite3.c" "${BUILD_DIR}/sqlcipher3.c"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cp "${SQLCIPHER_SRC}/sqlite3.h" "${BUILD_DIR}/sqlcipher3.h"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
for FILE in "${BUILD_DIR}"/sqlcipher3.*
|
||||
do
|
||||
sed -ie 's/sqlite3/sqlcipher3/g' "${FILE}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
sed -rie 's/(".*)sqlcipher3(.*")/\1sqlite3\2/g' "${FILE}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
done
|
||||
|
||||
#
|
||||
# Build pdo_sqlcipher
|
||||
#
|
||||
|
||||
cp "config.m4" "${BUILD_DIR}/config.m4"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cd "${BUILD_DIR}"
|
||||
|
||||
phpize --clean
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
phpize
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
./configure \
|
||||
CFLAGS="${CFLAGS}" \
|
||||
LDFLAGS="${LDFLAGS}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
make
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cd ..
|
||||
|
||||
#
|
||||
# Copy binaries
|
||||
#
|
||||
|
||||
RELEASE_DIR="release"
|
||||
|
||||
if [ -d "${RELEASE_DIR}" ]; then
|
||||
rm -rf "${RELEASE_DIR}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "${RELEASE_DIR}"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# pdo_sqlite.so
|
||||
cp "${BUILD_DIR}/modules/pdo_sqlcipher.so" "${RELEASE_DIR}/pdo_sqlcipher.so"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
strip "${RELEASE_DIR}/pdo_sqlcipher.so"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
chmod 0644 "${RELEASE_DIR}/pdo_sqlcipher.so"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
# sqlcipher static binary
|
||||
cp "${SQLCIPHER_SRC}/sqlcipher" "${RELEASE_DIR}/sqlcipher"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
strip "${RELEASE_DIR}/sqlcipher"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit $?
|
||||
fi
|
||||
|
||||
#
|
||||
# Clean
|
||||
#
|
||||
|
||||
rm -rf ${PHP_SRC}
|
||||
rm -rf ${SQLCIPHER_SRC}
|
||||
rm -rf ${BUILD_DIR}
|
||||
rm -f ${PHP_TGZ}
|
||||
19
config.m4
19
config.m4
|
|
@ -1,16 +1,12 @@
|
|||
dnl $Id$
|
||||
dnl config.m4 for extension pdo_sqlcipher
|
||||
dnl vim:et:sw=2:ts=2:
|
||||
|
||||
PHP_ARG_ENABLE(pdo_sqlcipher, whether to enable pdo_sqlcipher support,
|
||||
[ --enable-pdo_sqlcipher Enable pdo_sqlcipher support])
|
||||
|
||||
if test "$PHP_PDO_SQLCIPHER" != "no"; then
|
||||
|
||||
if test "$PHP_PDO" = "no" && test "$ext_shared" = "no"; then
|
||||
AC_MSG_ERROR([PDO is not enabled! Add --enable-pdo to your configure line.])
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([for PDO includes])
|
||||
if test -f $abs_srcdir/include/php/ext/pdo/php_pdo_driver.h; then
|
||||
pdo_inc_path=$abs_srcdir/ext
|
||||
|
|
@ -30,13 +26,20 @@ if test "$PHP_PDO_SQLCIPHER" != "no"; then
|
|||
AC_MSG_ERROR([Cannot find php_pdo_driver.h.])
|
||||
fi
|
||||
AC_MSG_RESULT($pdo_inc_path)
|
||||
php_pdo_sqlcipher_sources_core="pdo_sqlite.c sqlite_driver.c sqlite_statement.c sqlite3.c"
|
||||
dnl Detect PHP 8.4’s DSN parser unit and compile it if present
|
||||
AC_MSG_CHECKING([for sqlite_sql_parser.c (PHP 8.4 DSN parser)])
|
||||
if test -f "$abs_srcdir/sqlite_sql_parser.c"; then
|
||||
AC_MSG_RESULT([yes])
|
||||
php_pdo_sqlcipher_sources_core="$php_pdo_sqlcipher_sources_core sqlite_sql_parser.c"
|
||||
else
|
||||
AC_MSG_RESULT([no])
|
||||
fi
|
||||
|
||||
php_pdo_sqlcipher_sources_core="pdo_sqlcipher.c sqlcipher_driver.c sqlcipher_statement.c sqlcipher3.c"
|
||||
|
||||
PHP_NEW_EXTENSION(pdo_sqlcipher, $php_pdo_sqlcipher_sources_core, $ext_shared,,-I$pdo_inc_path)
|
||||
PHP_NEW_EXTENSION(pdo_sqlite, $php_pdo_sqlcipher_sources_core, $ext_shared,,-I$pdo_inc_path)
|
||||
|
||||
ifdef([PHP_ADD_EXTENSION_DEP],
|
||||
[
|
||||
PHP_ADD_EXTENSION_DEP(pdo_sqlcipher, pdo)
|
||||
PHP_ADD_EXTENSION_DEP(pdo_sqlite, pdo)
|
||||
])
|
||||
fi
|
||||
|
|
|
|||
95
example.php
95
example.php
|
|
@ -1,95 +0,0 @@
|
|||
<?php
|
||||
|
||||
// database file name
|
||||
$database = "example.db";
|
||||
|
||||
// database password
|
||||
$password = "123456";
|
||||
|
||||
// returns new instance of PDO object
|
||||
function getPDO($database) {
|
||||
try {
|
||||
$pdo = new PDO("sqlcipher:" . $database);
|
||||
} catch (PDOException $e) {
|
||||
die($e->getMessage() . PHP_EOL);
|
||||
}
|
||||
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
//
|
||||
// Create new example database with one table
|
||||
// (it can be done through sqlcipher command line client)
|
||||
//
|
||||
|
||||
$sql = "PRAGMA key = '$password';
|
||||
PRAGMA encoding = \"UTF-8\";
|
||||
PRAGMA auto_vacuum = 2;
|
||||
PRAGMA incremental_vacuum(10);
|
||||
|
||||
CREATE TABLE `test` (
|
||||
`id` INTEGER NOT NULL PRIMARY KEY,
|
||||
`value` TEXT NOT NULL
|
||||
);";
|
||||
|
||||
$pdo = getPDO($database);
|
||||
|
||||
if ($pdo->exec($sql) === false) {
|
||||
$error = $pdo->errorInfo();
|
||||
die($error[0] . ": " . $error[2] . PHP_EOL);
|
||||
}
|
||||
|
||||
//
|
||||
// Use example database
|
||||
//
|
||||
|
||||
// set encryption key before any sql command
|
||||
$sql = "PRAGMA key = '$password'";
|
||||
$pdo = getPDO($database);
|
||||
|
||||
if ($pdo->exec($sql) === false) {
|
||||
$error = $pdo->errorInfo();
|
||||
die($error[0] . ": " . $error[2] . PHP_EOL);
|
||||
}
|
||||
|
||||
// insert rows
|
||||
$sql = "INSERT INTO `test` VALUES (1, 'value1');
|
||||
INSERT INTO `test` VALUES (2, 'value2');
|
||||
INSERT INTO `test` VALUES (3, 'value3');";
|
||||
|
||||
if ($pdo->exec($sql) === false) {
|
||||
$error = $pdo->errorInfo();
|
||||
die($error[0] . ": " . $error[2] . PHP_EOL);
|
||||
}
|
||||
|
||||
// select rows
|
||||
$result = $pdo->query("SELECT * FROM `test`");
|
||||
|
||||
if ($result === false) {
|
||||
$error = $pdo->errorInfo();
|
||||
die($error[0] . ": " . $error[2] . PHP_EOL);
|
||||
}
|
||||
|
||||
foreach ($result as $row) {
|
||||
print_r($row);
|
||||
}
|
||||
|
||||
// alter table
|
||||
$sql = "ALTER TABLE `test` RENAME TO `test2`";
|
||||
|
||||
if ($pdo->exec($sql) === false) {
|
||||
$error = $pdo->errorInfo();
|
||||
die($error[0] . ": " . $error[2] . PHP_EOL);
|
||||
}
|
||||
|
||||
// select rows
|
||||
$result = $pdo->query("SELECT * FROM `test2`");
|
||||
|
||||
if ($result === false) {
|
||||
$error = $pdo->errorInfo();
|
||||
die($error[0] . ": " . $error[2] . PHP_EOL);
|
||||
}
|
||||
|
||||
foreach ($result as $row) {
|
||||
print_r($row);
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
/etc/php5/conf.d/pdo_sqlcipher.ini
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
Package: php5-sqlcipher
|
||||
Version: _PHP_VER
|
||||
Architecture: amd64
|
||||
Maintainer: Anton Batenev <antonbatenev@yandex.ru>
|
||||
Installed-Size: 350
|
||||
Depends: libc6 (>= 2.13-38), libssl1.0.0 (>= 1.0.1e-2), _LIBICU (>= _LIBICU_VER), phpapi-_PHP_API, php5-common (= _PHP_DEB_VER)
|
||||
Section: php
|
||||
Priority: optional
|
||||
Homepage: https://github.com/abbat/pdo_sqlcipher
|
||||
Description: sqlcipher module for PHP 5
|
||||
SQLCipher is an SQLite extension that provides transparent
|
||||
256-bit AES encryption of database files.
|
||||
|
|
@ -1 +0,0 @@
|
|||
extension=pdo_sqlcipher.so
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
This package was debianized by Anton Batenev <antonbatenev@yandex.ru>
|
||||
|
||||
pdo_sqlite under PHP License (http://www.php.net/license/3_0.txt)
|
||||
sqlcipher under BSD-style open source license (http://sqlcipher.net/license)
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
php5-sqlcipher: debian-changelog-file-missing
|
||||
php5-sqlcipher: hardening-no-relro
|
||||
php5-sqlcipher: copyright-without-copyright-notice
|
||||
php5-sqlcipher: binary-or-shlib-defines-rpath
|
||||
php5-sqlcipher: embedded-library
|
||||
php5-sqlcipher: hardening-no-fortify-functions
|
||||
php5-sqlcipher: binary-without-manpage
|
||||
Loading…
Add table
Add a link
Reference in a new issue