niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Berkeley DB
Encryption Question
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
dtuttle1@gmail.com
*nix forums beginner


Joined: 20 Jul 2006
Posts: 2

PostPosted: Thu Jul 20, 2006 10:09 pm    Post subject: Encryption Question Reply with quote

Hi,

I've enabled encryption, and I can read and write without errors using
the correct password. However, if I view the .db file I can see the
plain text so it seems that the encryption isn't working.
This is db-4.4.20, using the BDB Java API on Debian, Linux kernel
2.6.15-1-486.

Here are my methods that open and write to the database:
public void open(String databaseName) throws Exception {
databaseName = ENVIRONMENT_NAME + "/" + databaseName;
EnvironmentConfig environmentConfig = new EnvironmentConfig();
environmentConfig.setTransactional(true);
environmentConfig.setInitializeCache(true);
environmentConfig.setInitializeLocking(true);
environmentConfig.setInitializeLogging(true);
environmentConfig.setAllowCreate(true);
environmentConfig.setEncrypted("password");
environment = new Environment(new File(ENVIRONMENT_NAME),
environmentConfig);
DatabaseConfig databaseConfig = new DatabaseConfig();
databaseConfig.setAllowCreate(true);
databaseConfig.setType(DatabaseType.HASH);
database = new Database(databaseName, null, databaseConfig);
Transaction transaction = environment.beginTransaction(null, null);
database = environment.openDatabase(transaction, databaseName, null,
databaseConfig);
transaction.commit();
database.truncate(null, false);
}

public void write(String key, String value) throws Exception {
DatabaseEntry databaseEntryKey = new
DatabaseEntry(key.getBytes("UTF-8"));
DatabaseEntry databaseEntryValue = new
DatabaseEntry(value.getBytes("UTF-8"));
Transaction transaction = environment.beginTransaction(null, null);
try {
if (database.putNoOverwrite(transaction, databaseEntryKey,
databaseEntryValue) == OperationStatus.KEYEXIST) {
throw new Exception("Key already exists.");
}
transaction.commit();
} catch (DatabaseException e) {
transaction.abort();
e.printStackTrace();
}
}

Thanks, Dave
Back to top
Alex
*nix forums Guru Wannabe


Joined: 22 May 2002
Posts: 290

PostPosted: Fri Jul 21, 2006 1:12 am    Post subject: Re: Encryption Question Reply with quote

Hi Dave,

I was not able to run your program as posted - since the open is not
doing the correct thing.

You have two database opens assigning to the same object. The first is
opening outside of an environment, encryption is not supported unless
an environment is being used.

The second open within the environment is failing because the code is
explicitly prepending the environment directory to the DB name.

Once I changed the open method to be:
public void open(String databaseName) throws Exception {
EnvironmentConfig environmentConfig = new EnvironmentConfig();
environmentConfig.setTransactional(true);
environmentConfig.setInitializeCache(true);
environmentConfig.setInitializeLocking(true);
environmentConfig.setInitializeLogging(true);
environmentConfig.setAllowCreate(true);
environmentConfig.setEncrypted("password");
environment = new Environment(new File(ENVIRONMENT_NAME),
environmentConfig);
DatabaseConfig databaseConfig = new DatabaseConfig();
databaseConfig.setAllowCreate(true);
databaseConfig.setType(DatabaseType.HASH);
Transaction transaction = environment.beginTransaction(null, null);
database = environment.openDatabase(transaction, databaseName, null,
databaseConfig);
transaction.commit();
database.truncate(null, false);
}

The open works and the DB is encrypted.

It is worth noting that the memory mapped regions contain data that is
not encrypted. So the __db.XXXX files might contain references to
unencrypted data. See here:
http://www.sleepycat.com/docs/ref/env/encrypt.html
For more information.

I hope this helps,
Alex

dtuttle1@gmail.com wrote:

Quote:
Hi,

I've enabled encryption, and I can read and write without errors using
the correct password. However, if I view the .db file I can see the
plain text so it seems that the encryption isn't working.
This is db-4.4.20, using the BDB Java API on Debian, Linux kernel
2.6.15-1-486.

Here are my methods that open and write to the database:
public void open(String databaseName) throws Exception {
databaseName = ENVIRONMENT_NAME + "/" + databaseName;
EnvironmentConfig environmentConfig = new EnvironmentConfig();
environmentConfig.setTransactional(true);
environmentConfig.setInitializeCache(true);
environmentConfig.setInitializeLocking(true);
environmentConfig.setInitializeLogging(true);
environmentConfig.setAllowCreate(true);
environmentConfig.setEncrypted("password");
environment = new Environment(new File(ENVIRONMENT_NAME),
environmentConfig);
DatabaseConfig databaseConfig = new DatabaseConfig();
databaseConfig.setAllowCreate(true);
databaseConfig.setType(DatabaseType.HASH);
database = new Database(databaseName, null, databaseConfig);
Transaction transaction = environment.beginTransaction(null, null);
database = environment.openDatabase(transaction, databaseName, null,
databaseConfig);
transaction.commit();
database.truncate(null, false);
}

public void write(String key, String value) throws Exception {
DatabaseEntry databaseEntryKey = new
DatabaseEntry(key.getBytes("UTF-8"));
DatabaseEntry databaseEntryValue = new
DatabaseEntry(value.getBytes("UTF-8"));
Transaction transaction = environment.beginTransaction(null, null);
try {
if (database.putNoOverwrite(transaction, databaseEntryKey,
databaseEntryValue) == OperationStatus.KEYEXIST) {
throw new Exception("Key already exists.");
}
transaction.commit();
} catch (DatabaseException e) {
transaction.abort();
e.printStackTrace();
}
}

Thanks, Dave
Back to top
dtuttle1@gmail.com
*nix forums beginner


Joined: 20 Jul 2006
Posts: 2

PostPosted: Fri Jul 21, 2006 5:46 am    Post subject: Re: Encryption Question Reply with quote

Hi Alex,

Thanks - that's helps me a lot! I appreciate it.
Regarding your second point, I'll look at
environmentConfig.setSystemMemory(true);
to avoid unencrypted data in the files.

My goal is to use MySQL with BDB as the storage engine. I have it
working except that there's no way to tell MySQL to tell BDB to use
encryption.
I've been looking for a place in the BDB source to hard-code it. I
found the __dbenv_open method in env_open.c, and I added
dbenv->set_encrypt(dbenv, "some-password", DB_ENCRYPT_AES);
It's not working yet, and I'm not sure if it's the right approach. Can
you make a recommendation?

Thanks again, Dave

Alex wrote:
Quote:
Hi Dave,

I was not able to run your program as posted - since the open is not
doing the correct thing.

You have two database opens assigning to the same object. The first is
opening outside of an environment, encryption is not supported unless
an environment is being used.

The second open within the environment is failing because the code is
explicitly prepending the environment directory to the DB name.

Once I changed the open method to be:
public void open(String databaseName) throws Exception {
EnvironmentConfig environmentConfig = new EnvironmentConfig();
environmentConfig.setTransactional(true);
environmentConfig.setInitializeCache(true);
environmentConfig.setInitializeLocking(true);
environmentConfig.setInitializeLogging(true);
environmentConfig.setAllowCreate(true);
environmentConfig.setEncrypted("password");
environment = new Environment(new File(ENVIRONMENT_NAME),
environmentConfig);
DatabaseConfig databaseConfig = new DatabaseConfig();
databaseConfig.setAllowCreate(true);
databaseConfig.setType(DatabaseType.HASH);
Transaction transaction = environment.beginTransaction(null, null);
database = environment.openDatabase(transaction, databaseName, null,
databaseConfig);
transaction.commit();
database.truncate(null, false);
}

The open works and the DB is encrypted.

It is worth noting that the memory mapped regions contain data that is
not encrypted. So the __db.XXXX files might contain references to
unencrypted data. See here:
http://www.sleepycat.com/docs/ref/env/encrypt.html
For more information.

I hope this helps,
Alex

dtuttle1@gmail.com wrote:

Hi,

I've enabled encryption, and I can read and write without errors using
the correct password. However, if I view the .db file I can see the
plain text so it seems that the encryption isn't working.
This is db-4.4.20, using the BDB Java API on Debian, Linux kernel
2.6.15-1-486.

Here are my methods that open and write to the database:
public void open(String databaseName) throws Exception {
databaseName = ENVIRONMENT_NAME + "/" + databaseName;
EnvironmentConfig environmentConfig = new EnvironmentConfig();
environmentConfig.setTransactional(true);
environmentConfig.setInitializeCache(true);
environmentConfig.setInitializeLocking(true);
environmentConfig.setInitializeLogging(true);
environmentConfig.setAllowCreate(true);
environmentConfig.setEncrypted("password");
environment = new Environment(new File(ENVIRONMENT_NAME),
environmentConfig);
DatabaseConfig databaseConfig = new DatabaseConfig();
databaseConfig.setAllowCreate(true);
databaseConfig.setType(DatabaseType.HASH);
database = new Database(databaseName, null, databaseConfig);
Transaction transaction = environment.beginTransaction(null, null);
database = environment.openDatabase(transaction, databaseName, null,
databaseConfig);
transaction.commit();
database.truncate(null, false);
}

public void write(String key, String value) throws Exception {
DatabaseEntry databaseEntryKey = new
DatabaseEntry(key.getBytes("UTF-8"));
DatabaseEntry databaseEntryValue = new
DatabaseEntry(value.getBytes("UTF-8"));
Transaction transaction = environment.beginTransaction(null, null);
try {
if (database.putNoOverwrite(transaction, databaseEntryKey,
databaseEntryValue) == OperationStatus.KEYEXIST) {
throw new Exception("Key already exists.");
}
transaction.commit();
} catch (DatabaseException e) {
transaction.abort();
e.printStackTrace();
}
}

Thanks, Dave
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Sun Nov 23, 2008 2:51 pm | All times are GMT
navigation Forum index » Databases » Berkeley DB
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Newbie question: How to forward a domain to a mailbox? leei Postfix 0 Fri Aug 24, 2007 4:55 pm
No new posts configuration question for httpd Karl Wang Apache 1 Fri Jul 21, 2006 2:10 pm
No new posts nim problem/question Ron AIX 0 Fri Jul 21, 2006 1:57 pm
No new posts question for JAVA developer who r using postgres sql as b... deepak pal PostgreSQL 1 Fri Jul 21, 2006 9:00 am
No new posts Question about using copy constructor of parent class? LJB C++ 4 Thu Jul 20, 2006 9:32 pm

Loans | Credit Cards | Share Prices | Personal Loans | Property in Spain
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2469s ][ Queries: 16 (0.1200s) ][ GZIP on - Debug on ]