Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#492 Conditional support for database encryption in ooSQLite

ooSQLite.1.0.0
closed
Mark Miesfeld
ooSQLite (9)
none
1
2013-05-19
2012-10-20
Staffan Tylen
No

By adding the attached code samples to ooSQLite.cpp and (optionally) shell.c, support for database encryption in ooSQLite can be controlled using a compile flag, here chosen to be identical to the flag controlling the encryption support in SQLite3 (SQLITE_HAS_CODEC). The requirement to change ooSQLite.cls in line with this could be documented. Note that this change alone does not implement the actual encryption mechanism but it allows for a simple activation once the prerequisites are in place. This has successfully been tested using the crypt library Botan, integrated into SQLite3 using botanSQLite3.

1 Attachments

Discussion

1 2 > >> (Page 1 of 2)
  • Mark Miesfeld
    Mark Miesfeld
    2012-10-21

    Committed revision 8524.
    [r8524]

    Staffan, thanks. Your code in RFE.txt looks good.

    I changed the #ifdef logic slightly. The key(), rekey() methods and the oosqlKey(), oosqlRekey() methods are always compiled in. If SQLITE_HAS_CODEC is not defined during the compile, then the methods and routines return an error code if invoked from Rexx code. This is a better way to do this. It allows one ooSQLite.cls file to support things.

    One other method and function need to be added. Something like: ooSQLite::hasEncryption() and oosqlHasEncryption() Then in Rexx code you can test if the library has the encryption code compiled in or not.

    I will work on some other stuff to better integrate things so that is is easy to do a build with the Botan library included. Please continue to discuss this on the user list so that other people that may be interested in this can follow the developments.

    It seems to me you must be doing your own compiles now. If you do a svn update you will pick up this change and also the fix for the oosqlExec() bug you opened.

     

    Related

    Commit: [r8524]

  • Mark Miesfeld
    Mark Miesfeld
    2012-10-21

    • labels: --> ooSQLite
    • status: open --> accepted
    • assigned_to: Mark Miesfeld
     
  • Staffan Tylen
    Staffan Tylen
    2012-10-21

    It seems to me you must be doing your own compiles now. If you do a svn
    update you will pick up this change and also the fix for the oosqlExec()
    bug you opened.

    I'm using TortoiseSVN for Windows but when I try to do "Update to
    revision..." using revision 8524 it says "No such revision 8524". Don't
    know what I'm doing wrong (this is all new to me).

    Instead I tried by manually downloading ooSQLite.cpp and ooSQLite.hpp but
    when I run the make I get:

    src\ooSQLite.cpp(1247) : error C3861: 'oosqlGetCurrentThreadId': identifier
    not found
    src\ooSQLite.cpp(1309) : error C3861: 'oosqlGetCurrentThreadId': identifier
    not found
    src\ooSQLite.cpp(1379) : error C3861: 'oosqlGetCurrentThreadId': identifier
    not found
    src\ooSQLite.cpp(1444) : error C3861: 'oosqlGetCurrentThreadId': identifier
    not found
    src\ooSQLite.cpp(1500) : error C3861: 'oosqlGetCurrentThreadId': identifier
    not found
    src\ooSQLite.cpp(1564) : error C3861: 'oosqlGetCurrentThreadId': identifier
    not found
    src\ooSQLite.cpp(1628) : error C3861: 'oosqlGetCurrentThreadId': identifier
    not found
    src\ooSQLite.cpp(1692) : error C3861: 'oosqlGetCurrentThreadId': identifier
    not found
    src\ooSQLite.cpp(3114) : error C3861: 'oosqlGetCurrentThreadId': identifier
    not found
    src\ooSQLite.cpp(7303) : error C3861: 'oosqlGetCurrentThreadId': identifier
    not found

    Any idea?

    Staffan

     
  • Staffan Tylen
    Staffan Tylen
    2012-10-21

    Changes required to shell.c to support key/rekey (based on sqlite amalgamation source 3.7.14.1). "After" refers to the line number before any changes have been made:

    After 1405:
    
    #ifdef SQLITE_HAS_CODEC
      ".key STRING            Encryption key\n"
    #endif
    
    After 1424:
    
    #ifdef SQLITE_HAS_CODEC
      ".rekey STRING          New encryption key\n"
    #endif
    
    After 1971:
    
    #ifdef SQLITE_HAS_CODEC
      if( c=='k' && strncmp(azArg[0], "key", n)==0 && nArg==2 ){
        const char *zKey;
        char *zErrMsg = 0;
        open_db(p);
        zKey = azArg[1];
        rc = sqlite3_key(p->db, azArg[1], (int)strlen(zKey));
        if( rc!=SQLITE_OK ){
          fprintf(stderr, "Error: %s\n", zErrMsg);
          sqlite3_free(zErrMsg);
          rc = 1;
        }
      }else
    #endif
    
    After 2096:
    
    #ifdef SQLITE_HAS_CODEC
      if( c=='r' && strncmp(azArg[0], "rekey", n)==0 && nArg==2 ){
        const char *zKey;
        char *zErrMsg = 0;
        open_db(p);
        zKey = azArg[1];
        rc = sqlite3_rekey(p->db, azArg[1], (int)strlen(zKey));
        if( rc!=SQLITE_OK ){
          fprintf(stderr, "Error: %s\n", zErrMsg);
          sqlite3_free(zErrMsg);
          rc = 1;
        }
      }else
    #endif
    
     
  • Mark Miesfeld
    Mark Miesfeld
    2012-10-21

    re: I'm using TortoiseSVN for Windows but when I try to do "Update to
    revision..." using revision 8524 it says "No such revision 8524". Don't
    know what I'm doing wrong (this is all new to me).

    I think you are using the old URL to the repository. It should be something like:

    http://svn.code.sf.net/p/oorexx/code-0/incubator/ooSQLite

    or I think this also works:

    svn://svn.code.sf.net/p/oorexx/code-0/incubator/ooSQLite

    When we switched to the new interface on SourceForge a new repository was created. The old repository still exists, it is just not being updated.

    The best thing in my opinion to do, would be to check out using the above URL to a new location. Then merge any code you had changed in you current check out to the new location, then delete the old check out.

    re: Instead I tried by manually downloading ooSQLite.cpp and ooSQLite.hpp but
    when I run the make I get:
    srcooSQLite.cpp(1247) : error C3861: 'oosqlGetCurrentThreadId': identifier
    not found

    Yeah, you need to get the complete source code tree. If all your other code was up to date, that would have worked. But your current source code tree is out of date.

     
  • Staffan Tylen
    Staffan Tylen
    2012-10-21

    Thanks for the code Staffan. I'm curious as to where you found it.

    Not sure what you mean by "the code". The additions to ooSQLite and shell I
    created myself if that's what you mean. I have no C experience but have
    millions of years of mainframe assembler coding behind me so I'm used to
    dig into things when there is a need. ;)

    Staffan

     
1 2 > >> (Page 1 of 2)


Anonymous


Cancel   Add attachments