davidmartos96 / sqflite_sqlcipher

SQLite flutter plugin
BSD 2-Clause "Simplified" License
99 stars 44 forks source link

Support dart command line of Linux #70

Closed iampopal closed 1 year ago

iampopal commented 1 year ago

Hello David, We want to run our server which has a database of sqlitecipher in the server with dart command line https://dart.dev/tutorials/server/cmdline

When we run our app with flutter as the flutter repository contains sqflite_sqlcipher: ^2.1.1+1 in .yaml file, our flatter app works all good with the local flutter server.

Now we want run our server in a container with Dockerfile so we need command line capability at pure dart code.

You can look at command line simple here: (https://dart.dev/tutorials/server/cmdline) Please help us how we can have sqflite_sqlcipher in our commandline dart app.

davidmartos96 commented 1 year ago

Hello! You would need to install/build SQLCipher in the Dockerfile.

Then refer to usage of this library in desktop/pure Dart pinned in the discussions section. You will need to tell the package where the native libraries are located.

iampopal commented 1 year ago

Okay thank you. On Thu, 9 Mar 2023 at 5:51 PM David Martos @.***> wrote:

Hello! You would need to install/build SQLCipher in the Dockerfile.

Then refer to usage of this library in desktop/pure Dart pinned in the discussions section. You will need to tell the package where the native libraries are located.

— Reply to this email directly, view it on GitHub https://github.com/davidmartos96/sqflite_sqlcipher/issues/70#issuecomment-1462059780, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIUFLXGFOAJAKWC7YZMOR6TW3HKMJANCNFSM6AAAAAAVVAOY5I . You are receiving this because you authored the thread.Message ID: @.***>

iampopal commented 1 year ago

I have macOS Computer I tried including sqlcipher binary file in the repository code and it worked all good. then I tried to download sqlcipher in VM of Linux and copied the binary of sqlcipher to the repitory then called it by

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

Then build a container with the following dockerfile code:

# Specify the Dart SDK base image version using dart:<version> (ex: dart:2.12)
FROM dart:stable AS build

RUN dart --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 --offline
RUN dart compile exe bin/server.dart -o bin/server

# Build minimal serving image from AOT-compiled `/server` and required system
# libraries and configuration files stored in `/runtime/` from the build stage.
FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/bin/server /app/bin/
COPY --from=build /app/bin/sqlcipher_linux /app/bin/
COPY --from=build /app/bin/Database.db /app/bin/

WORKDIR /app

# Start server.
ENV PORT 8080
EXPOSE 8080
CMD ["./bin/server"]

Now the issue is that the docker container filed to start sqlcipher

can you please help how can I easily include sqlcipher in dockerfile.

davidmartos96 commented 1 year ago

What binary file did you copy? It should be a .so file which is what Dart can use with FFI. Alternatively you can build sqlcipher inside the Dockerfile. I believe you can find some resources online on how to do that.

davidmartos96 commented 1 year ago

Also, watch out using load library with a relative path. I has issues with that in the past. Try with an absolute path to the .so file first in case that's an issue.

iampopal commented 1 year ago

It was not the .so file, It was just the normal binary file named sqlcipher in Linux, I copied it to my repository

iampopal commented 1 year ago

I have run File('./relativepath').exists() in dart, it's saying that file exists but the issue it not runs and SQL is not loading it.

iampopal commented 1 year ago

Hello @davidmartos96 I have setup a Linux Environment to understand the sqlcipher package better and recognize where the actual error is

I have installed the sqlcipher package and overridden it as before but I still give the error of: Failed to load dynamic library

Please help us find or install the correct sqlcipher in kali-linux?

iampopal commented 1 year ago

And I have installed sqlcipher with apt get install sqlcipher

where can I find the .so file of it.

The file that I am referring is without .so extension

davidmartos96 commented 1 year ago

.so file are normally located under /usr/lib/libxxx.so You would be looking for libsqlcipher.so

Loading that file in the override should work on Kali Linux. You can then extrapolate to the Dockerfile

iampopal commented 1 year ago

Thank you for your replay, It help me a lot

I did look for libsqlcipher.so under /usr/lib/ folder but it doesn't exists there

can you please tell me how to download it in kali-linux

iampopal commented 1 year ago

https://github.com/couchbaselabs/couchbase-lite-libsqlcipher/blob/master/libs/linux/amd64/libsqlcipher.so

I have did google for it and found this libsqlcipher.so file, then copied it over the folder and called it with override method but the error is still there saying: Failed to load dynamic library

davidmartos96 commented 1 year ago

Your best bet will be to compile sqlcipher from sources, then use the .so file that got built. The file you found may be old old it may depend on some other library (like SSL) which you may not have installed. Instructions to build it using cmake are in the sqlcipher github repository

iampopal commented 1 year ago

Thank you. Isn't here a place from where I can download the latest compiled version of libsqlcipher.so file

davidmartos96 commented 1 year ago

No that I'm aware of. I haven't tried on Kali but I did use this library on Fedora and Ubuntu before

iampopal commented 1 year ago

Ubuntu will be also fine, I can Install Ubuntu If you can please help me provide a .so File Ubunto please.

davidmartos96 commented 1 year ago

On Ubuntu you should be able to install sqlcipher 4.x from a PPA. That should provide the .so you need. That's whatI I have done in the past

iampopal commented 1 year ago

so PPA is package installer with which I can Install sqlcipher and it provider sqlcipher with .so file?

davidmartos96 commented 1 year ago

@iampopal When you run ldd <path of the .so> you should see something like the following. These are the libraries that are expected to exist in your system. Building from source or correctly installing sqlcipher should include them by default. But you can run it to see if something is missing, otherwise Dart FFI will fail

image