Giter Site home page Giter Site logo

Comments (17)

iampopal avatar iampopal commented on September 6, 2024

Can you please help us with which command to run and get the libsqlcipher.so file or provide us libsqlcipher.so file to include it with our command line.

from sqlite3.dart.

simolus3 avatar simolus3 commented on September 6, 2024

Could you post the Dockerfile you're using at the moment? There are many ways to get a libsqlcipher.so for most Linux distributions - depending on the one you use as the basis for your container, I can suggest a way to install it.

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

Here is my dockerfile:

FROM dart:stable AS build

# Install sqlcipher
RUN apt update; \
    apt install -y sqlcipher

# double checking that sqlcipher is installed successfully 
RUN sqlcipher --version

# Resolve app dependencies.
WORKDIR /app
COPY pubspec.* ./
RUN dart pub get

# Copy app source code and AOT compile it.
COPY . .

# Ensure packages are still up-to-date if anything has changed
# RUN dart pub get
RUN dart pub get --offline
RUN dart compile exe bin/server.dart -o bin/server

# Changing current directry to /app/bin
WORKDIR /app/bin

# Start server.
ENV PORT 8080
EXPOSE 8080

# Runing Dart Server
CMD ["./server"]

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

After not getting able to get a good result from Dockerfile so tried to install Kali-Linux arm64 on my M1
then
tried to compile https://github.com/sqlcipher/sqlcipher and install
then
copied libsqlcipher.so from /usr/local/lib
and posted it in bin folder of dart server and called it with:

      open.overrideFor(
        OperatingSystem.linux,
        () {
          return DynamicLibrary.open('./bin/libsqlcipher.so');
        },
      );

But I am still getting the error of file is not database which is because of sqlcipher not exists.

static bool hasCipherDb(database) {
   hasCipher = database.select('PRAGMA cipher_version;').isNotEmpty;
   return hasCipher;
 }

did double checked by hasCipherDb(db) it still return false

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

Our encrypted sqlcipher db work all good in: Android, Windows, iOS and MacOS

We really need it to work on Dockerfile so we can host our db in serverless platform.

thank you.

from sqlite3.dart.

simolus3 avatar simolus3 commented on September 6, 2024

This works for me (note the sqlcipher-dev instead of sqlcipher):

FROM dart:stable AS build

# Install sqlcipher
RUN apt update; \
    apt install -y sqlcipher-dev

# Resolve app dependencies.
WORKDIR /app
...

In the container, I'm just using this override:

open.overrideForAll(() {
  return DynamicLibrary.open('libsqlcipher.so');
});

If you want to make the image smaller at runtime, you can also use the recommended FROM scratch setup recommended by the Dart image:

FROM dart:stable AS build

# Install sqlcipher
RUN apt update; \
    apt install -y libsqlcipher-dev

# Resolve app dependencies.
WORKDIR /app
COPY pubspec.* ./
RUN dart pub get

# Copy app source code and AOT compile it.
COPY . .

# Ensure packages are still up-to-date if anything has changed
# RUN dart pub get
RUN dart pub get --offline
RUN dart compile exe bin/main.dart -o bin/server

FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/bin/server /app/bin/
COPY --from=build /usr/lib/x86_64-linux-gnu/libsqlcipher.so /lib/
COPY --from=build /usr/lib/x86_64-linux-gnu/libcrypto.so.* /lib/

# Changing current directry to /app/bin
WORKDIR /app/bin

# Runing Dart Server
CMD ["./server"]

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

Thank you so much for your contribution, it worked all good thank you so much.

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

@simolus3 I am using the drift package and have a very amazing experience with it.
Thank you so much for providing these awesome packages

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

@simolus3
I am back again

The good news is that libsqlcipher.so exists and the function of:

static bool hasCipherDb(database) {
   hasCipher = database.select('PRAGMA cipher_version;').isNotEmpty;
   return hasCipher;
 }

Return true when opening a new or old database which is good news and sqlcipher exists.

but

Now here is one more issue with opening the old database:
When opening the old database I get the following error:

SqliteException(26): file is encrypted or is not a database, file is encrypted or is not a database (code 26)
Causing statement: SELECT * FROM \"users\

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

This my new Dockerfile

FROM dart:stable AS build

# Install sqlcipher
RUN apt update; \
    apt install -y libsqlcipher-dev

# Resolve app dependencies.
WORKDIR /app
COPY pubspec.* ./
RUN dart pub get

# Copy app source code and AOT compile it.
COPY . .

# Ensure packages are still up-to-date if anything has changed
# RUN dart pub get
RUN dart pub get --offline
RUN dart compile exe bin/server.dart -o bin/server

FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /usr/lib/x86_64-linux-gnu/libsqlcipher.so /lib/
COPY --from=build /usr/lib/x86_64-linux-gnu/libcrypto.so.* /lib/
COPY --from=build /app/bin/server /app/bin/
COPY --from=build /app/bin/data.db /app/bin/

# Changing current directry to /bin
WORKDIR /app

# Setting Port
ENV PORT 8080
EXPOSE 8080

# Runing Dart Server
CMD ["./bin/server"]

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

I did try opening the database with 'DB Browser for SQLite'
When opening a Database with SQLCipher 4 Default: It works all Good.
When opening a Database with SQLCipher 3 Default: It does not work.

So I am thinking that which version of the sqlcipher:
apt install -y libsqlcipher-dev
Is installing..

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

I have tried to check the version of sqlcipher in my local directory and container by calling:
var res = database.select('PRAGMA cipher_version;').toString();
The version number in my local directory where everything works all fine is: [{cipher_version: 4.5.3 community}]
The version in the docker file where db failed to open is: [{cipher_version: 3.4.1}]

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

Can you with how can I download the new version sqlcipher and share dockerfile back?

from sqlite3.dart.

simolus3 avatar simolus3 commented on September 6, 2024

Seems like you'll have to download and compile SQLCipher yourself then. You can take a look at my CMakeLists.txt for inspiration - you'll also have to install OpenSSL and a compiler toolchain. I'm not sure if you want to do this in the container, you can probably also compile a libsqlcipher.so outside of the container and then COPY it with a Dockerfile.

I can't give you a fully working solution here unfortunately - but if you compile SQLCipher on an x64 machine (if the container runtime is x64 as well), it should work.

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

Thank you @simolus3.
here is my updated Dockerfile which works well with dart image:

FROM dart:stable AS build

RUN apt update; \
    DEBIAN_FRONTEND=noninteractive apt install -y build-essential git gcc g++ make libffi-dev libssl-dev tcl; \
    cd /root; \
    git clone https://github.com/sqlcipher/sqlcipher.git; \
    mkdir bld; \
    cd bld; \
    ../sqlcipher/configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"; \
    make; make install; \
    apt remove -y build-essential git gcc g++ make libffi-dev libssl-dev tcl; \
    apt autoremove -y; \
    rm -rf ~/bld ~/sqlcipher

RUN cp /usr/local/lib/libsqlcipher.so /lib/

# Resolve app dependencies.
WORKDIR /app
COPY pubspec.* ./
RUN dart pub get

# Copy app source code and AOT compile it.
COPY . .

# Ensure packages are still up-to-date if anything has changed
RUN dart pub get --offline
RUN dart compile exe bin/server.dart -o bin/server

# FROM scratch
# COPY --from=build /runtime/ /
# COPY --from=build /app/bin/server /app/bin/
# COPY --from=build /app/bin/data.db /app/bin/

# Changing current directry to /bin
WORKDIR /app

# Setting Port
ENV PORT 8080
EXPOSE 8080

# Runing Dart Server
CMD ["./bin/server"]

As you can see above I have commented the FROM scratch part because I still don't know what files shall I copy from above container.

# FROM scratch
# COPY --from=build /runtime/ /
# COPY --from=build /app/bin/libsqlcipher.so /app/bin/
# COPY --from=build /app/bin/libsqlcipher.la /app/bin/
# COPY --from=build /app/bin/libsqlcipher.so.0 /app/bin/
# COPY --from=build /app/bin/libsqlcipher.so.0.8.6 /app/bin/
# COPY --from=build /usr/local/lib/libsqlcipher.so /lib/
# COPY --from=build /app/bin/server /app/bin/
# COPY --from=build /app/bin/data.db /app/bin/

I have tried to connect to the docker container with ssh and downloaded the libsqlciopher.so and a couple of other files associated with it but From scratch still not able to load sqlcipher but the dart image where I installed the sqlcipher by compiling works all good.

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

Please help me tell me which files are required for sqlcipher.so to work fine.

so I will download these needed file by ssh scp and place it in the repo docker file and will not needed to always compile sqlcipher.

from sqlite3.dart.

iampopal avatar iampopal commented on September 6, 2024

I have downloaded the following files from the docker server by remote ssh scp:

/usr/local/lib/libsqlcipher.so
/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1

  1. Where shall I place them From scratch to work?
  2. Are any other files also needed for sqlcipher to work?
  3. Do I still need to compile in dockerfile after downloading and placing in repo 2 files?

from sqlite3.dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.