Re: Interceptable ExtendedType
On Mar 13, 2014, at 3:13 PM, Mike Kienenberger wrote: > We found that trying to encrypt individual fields wasn't as helpful > since the length and variety of individual columns tended not to be > all that unique. > Padding with random characters can help, but encrypting more fields > together in a single column seemed more appropriate in our case, > especially since you can't do any meaningful sql on the encrypted data > anyway. Thanks for sharing! I agree. While the encryption mechanism can be made more or less transparent from the ORM perspective, there are certainly design ramifications. I am also looking at combining together a bunch of values in a single BLOB/CLOB column. Andrus
Re: Interceptable ExtendedType
Whoops. hit send too soon. Then an a superclass for all entities:
/**
* do nothing, override in subclass
*/
protected EncryptionVersionProvider getEncryptionVersionProvider()
{
throw new RuntimeException("getEncryptionVersionProvider()
must be overridden in subclass");
}
protected char[] decryptDataBlock(String encryptedData, int itemIndex)
throws EncryptionException
{
DataBlockEncryptionManager dataBlockEncryptionManager = new
DataBlockEncryptionManager(getEncryptionVersionProvider());
return dataBlockEncryptionManager.decryptDataBlock(encryptedData,
itemIndex);
}
protected String encryptDataBlock(String encryptedData, int
itemIndex, char[] newValue)
throws EncryptionException
{
DataBlockEncryptionManager dataBlockEncryptionManager = new
DataBlockEncryptionManager(getEncryptionVersionProvider());
return dataBlockEncryptionManager.encryptDataBlock(encryptedData,
itemIndex, newValue);
}
Obviously, you can do whatever you like to for
getEncryptionVersionProvider(), but we went with this to allow each
entity to have a separate encryption provider.
On Thu, Mar 13, 2014 at 8:13 AM, Mike Kienenberger wrote:
> For what it's worth, I'm doing the same thing for our JPA app.
>
> I store the encryption version number (unencrypted), then an encrypted
> set of data fields.
>
> We found that trying to encrypt individual fields wasn't as helpful
> since the length and variety of individual columns tended not to be
> all that unique.
> Padding with random characters can help, but encrypting more fields
> together in a single column seemed more appropriate in our case,
> especially since you can't do any meaningful sql on the encrypted data
> anyway.
>
> Here's the api I ended up going with:
>
> class DataBlockEncryptionManager {
>
> public DataBlockEncryptionManager(EncryptionVersionProvider
> encryptionVersionProvider)
>
> /**
> * encrypt item in encrypted data block.
> *
> * @param encryptedData String containing previous encrypted
> block, null to create new block
> * @param itemIndex from 0 to last item of item to encrypt
> * @param newValue to add to block
> * @return String containing encrypted block
> * @throws EncryptionException
> */
> public String encryptDataBlock(String encryptedData, int
> itemIndex, char[] newValue);
>
> public char[] decryptDataBlock(String encryptedData, int
> itemIndex) throws EncryptionException;
>
> public interface EncryptionVersionProvider
> {
> /** Default version to use for new encryptions */
> public String getDefaultVersion();
>
> // with a few methods like these depending on our encryption
> public String _xyzEncryptionProperty_ForVersion(String version);
>
> }
>
> }
>
> then, assuming your column is named ENCRYPTED_DATA, your individual
> attributes look like this:
>
> public char[] getName() throws EncryptionException {
> return decryptDataBlock(getEncryptedData(), ITEM_INDEX__NAME);
> }
> public void setName(char[] holderFirstName) throws EncryptionException {
> String newData = encryptDataBlock(getEncryptedData(),
> ITEM_INDEX__NAME, name);
> setEncryptedData(newData);
> }
>
>
>
>
> On Thu, Mar 13, 2014 at 4:18 AM, Andrus Adamchik
> wrote:
>>
>>
>> On Mar 13, 2014, at 11:06 AM, Aristedes Maniatis wrote:
>>
>>> On 13/03/2014 6:31pm, Andrus Adamchik wrote:
On Mar 13, 2014, at 10:05 AM, Aristedes Maniatis wrote:
>>>
> It would be nice public relations to have "Cayenne has out-of-the-box
> crypto support" as a feature. Are you storing a key version as part of
> the encrypted data stream?
I am still working on this piece actually. It has to be attached to the
record. The question is whether we keep it unencrypted (simplifies
management and migration between keys), or encrypt it together with the
data (more secure).
>>>
>>>
>>> I don't see any value in encrypting it. What security does that create?
>>> Also, keeping it in the same database column makes for simpler storage and
>>> robustness. Much like storing the salt with a password hash, or the hashing
>>> algorithm with the password in LDAP:
>>>
>>> 86gwfku:tgiynv45zpyqaqqpucnp3f8k8uk3dzqy
>>>
>>> {SSHA}ddrd686254iteu9gqsz4aztufkgbctuz
>>
>> yeah, perhaps you are right. Encrypting it doesn't provide better protection
>> from brute-force attacks on the key. Just some obfuscation.
>>
>> Andrus
Re: Interceptable ExtendedType
For what it's worth, I'm doing the same thing for our JPA app.
I store the encryption version number (unencrypted), then an encrypted
set of data fields.
We found that trying to encrypt individual fields wasn't as helpful
since the length and variety of individual columns tended not to be
all that unique.
Padding with random characters can help, but encrypting more fields
together in a single column seemed more appropriate in our case,
especially since you can't do any meaningful sql on the encrypted data
anyway.
Here's the api I ended up going with:
class DataBlockEncryptionManager {
public DataBlockEncryptionManager(EncryptionVersionProvider
encryptionVersionProvider)
/**
* encrypt item in encrypted data block.
*
* @param encryptedData String containing previous encrypted
block, null to create new block
* @param itemIndex from 0 to last item of item to encrypt
* @param newValue to add to block
* @return String containing encrypted block
* @throws EncryptionException
*/
public String encryptDataBlock(String encryptedData, int
itemIndex, char[] newValue);
public char[] decryptDataBlock(String encryptedData, int
itemIndex) throws EncryptionException;
public interface EncryptionVersionProvider
{
/** Default version to use for new encryptions */
public String getDefaultVersion();
// with a few methods like these depending on our encryption
public String _xyzEncryptionProperty_ForVersion(String version);
}
}
then, assuming your column is named ENCRYPTED_DATA, your individual
attributes look like this:
public char[] getName() throws EncryptionException {
return decryptDataBlock(getEncryptedData(), ITEM_INDEX__NAME);
}
public void setName(char[] holderFirstName) throws EncryptionException {
String newData = encryptDataBlock(getEncryptedData(),
ITEM_INDEX__NAME, name);
setEncryptedData(newData);
}
On Thu, Mar 13, 2014 at 4:18 AM, Andrus Adamchik wrote:
>
>
> On Mar 13, 2014, at 11:06 AM, Aristedes Maniatis wrote:
>
>> On 13/03/2014 6:31pm, Andrus Adamchik wrote:
>>>
>>> On Mar 13, 2014, at 10:05 AM, Aristedes Maniatis wrote:
>>
It would be nice public relations to have "Cayenne has out-of-the-box
crypto support" as a feature. Are you storing a key version as part of the
encrypted data stream?
>>>
>>> I am still working on this piece actually. It has to be attached to the
>>> record. The question is whether we keep it unencrypted (simplifies
>>> management and migration between keys), or encrypt it together with the
>>> data (more secure).
>>
>>
>> I don't see any value in encrypting it. What security does that create?
>> Also, keeping it in the same database column makes for simpler storage and
>> robustness. Much like storing the salt with a password hash, or the hashing
>> algorithm with the password in LDAP:
>>
>> 86gwfku:tgiynv45zpyqaqqpucnp3f8k8uk3dzqy
>>
>> {SSHA}ddrd686254iteu9gqsz4aztufkgbctuz
>
> yeah, perhaps you are right. Encrypting it doesn't provide better protection
> from brute-force attacks on the key. Just some obfuscation.
>
> Andrus
Re: Interceptable ExtendedType
On Mar 13, 2014, at 11:06 AM, Aristedes Maniatis wrote:
> On 13/03/2014 6:31pm, Andrus Adamchik wrote:
>>
>> On Mar 13, 2014, at 10:05 AM, Aristedes Maniatis wrote:
>
>>> It would be nice public relations to have "Cayenne has out-of-the-box
>>> crypto support" as a feature. Are you storing a key version as part of the
>>> encrypted data stream?
>>
>> I am still working on this piece actually. It has to be attached to the
>> record. The question is whether we keep it unencrypted (simplifies
>> management and migration between keys), or encrypt it together with the data
>> (more secure).
>
>
> I don't see any value in encrypting it. What security does that create? Also,
> keeping it in the same database column makes for simpler storage and
> robustness. Much like storing the salt with a password hash, or the hashing
> algorithm with the password in LDAP:
>
> 86gwfku:tgiynv45zpyqaqqpucnp3f8k8uk3dzqy
>
> {SSHA}ddrd686254iteu9gqsz4aztufkgbctuz
yeah, perhaps you are right. Encrypting it doesn’t provide better protection
from brute-force attacks on the key. Just some obfuscation.
Andrus
Re: Interceptable ExtendedType
On 13/03/2014 6:31pm, Andrus Adamchik wrote:
>
> On Mar 13, 2014, at 10:05 AM, Aristedes Maniatis wrote:
>
>> It would be nice public relations to have "Cayenne has out-of-the-box crypto
>> support" as a feature. Are you storing a key version as part of the
>> encrypted data stream?
>
> I am still working on this piece actually. It has to be attached to the
> record. The question is whether we keep it unencrypted (simplifies management
> and migration between keys), or encrypt it together with the data (more
> secure).
I don't see any value in encrypting it. What security does that create? Also,
keeping it in the same database column makes for simpler storage and
robustness. Much like storing the salt with a password hash, or the hashing
algorithm with the password in LDAP:
86gwfku:tgiynv45zpyqaqqpucnp3f8k8uk3dzqy
{SSHA}ddrd686254iteu9gqsz4aztufkgbctuz
Ari
--
-->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
Re: Interceptable ExtendedType
On Mar 13, 2014, at 10:05 AM, Aristedes Maniatis wrote: >> >> Yes, you are exactly right about that. For now planning on using normal java >> keystore facility. Starting the servers will require an admin to enter >> password which will unlock the keystore. There will likely be additional >> security enhancements protecting the keystore. > > Ah, the automatic failover at 3am is going to be fun for some sysadmin :-) Nobody says security is going to be transparent :) For the client in question, we have lots of redundancy. Also we don’t start appservers from /etc/init.d anyways. So everyone is accustomed to (remotely-scripted) manual restarts. >> The important thing is to move all these concerns outside Cayenne, so that >> each org could make their own decisions as to the levels of security >> required. Cayenne will provide an abstract way to do transparent per-column >> crypto. I am thinking of a very simple Cayenne-side “cayenne-crypto” >> Maven/DI module, free of key management code and defining 2 abstract >> services: (1) Cypher - a pluggable encryption mechanism with ability to >> version keys (2) Metadata - telling Cayenne which columns are encrypted. And >> also declaring overrides of RowReaderFactory and other relevant services to >> enable encryption. > > It would be nice public relations to have "Cayenne has out-of-the-box crypto > support" as a feature. Are you storing a key version as part of the encrypted > data stream? I am still working on this piece actually. It has to be attached to the record. The question is whether we keep it unencrypted (simplifies management and migration between keys), or encrypt it together with the data (more secure). Andrus
Re: Interceptable ExtendedType
On 13/03/2014 5:25pm, Andrus Adamchik wrote: > > > On Mar 13, 2014, at 1:55 AM, Aristedes Maniatis wrote: > >> On 12/03/2014 6:13pm, Andrus Adamchik wrote: >>> A heads up. I am looking to extend ExtendedType API to be a little more >>> context-aware (know which attribute is being read/written). My motivation >>> is quite interesting on its own - I need to implement generic data >>> encryption extensions that would encrypt/decrypt certain columns on the >>> fly. And I feel like ExtendedType is a place that is low-level enough to >>> make the encryption transparent to the rest of the stack. Very excited >>> about this project :) >> >> Out of interest, what are you doing for key storage? That's often the most >> complex part of the problem. > > Yes, you are exactly right about that. For now planning on using normal java > keystore facility. Starting the servers will require an admin to enter > password which will unlock the keystore. There will likely be additional > security enhancements protecting the keystore. Ah, the automatic failover at 3am is going to be fun for some sysadmin :-) > The important thing is to move all these concerns outside Cayenne, so that > each org could make their own decisions as to the levels of security > required. Cayenne will provide an abstract way to do transparent per-column > crypto. I am thinking of a very simple Cayenne-side “cayenne-crypto” Maven/DI > module, free of key management code and defining 2 abstract services: (1) > Cypher - a pluggable encryption mechanism with ability to version keys (2) > Metadata - telling Cayenne which columns are encrypted. And also declaring > overrides of RowReaderFactory and other relevant services to enable > encryption. It would be nice public relations to have "Cayenne has out-of-the-box crypto support" as a feature. Are you storing a key version as part of the encrypted data stream? Ari -- --> Aristedes Maniatis GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
Re: Interceptable ExtendedType
On Mar 13, 2014, at 1:55 AM, Aristedes Maniatis wrote: > On 12/03/2014 6:13pm, Andrus Adamchik wrote: >> A heads up. I am looking to extend ExtendedType API to be a little more >> context-aware (know which attribute is being read/written). My motivation is >> quite interesting on its own - I need to implement generic data encryption >> extensions that would encrypt/decrypt certain columns on the fly. And I feel >> like ExtendedType is a place that is low-level enough to make the encryption >> transparent to the rest of the stack. Very excited about this project :) > > Out of interest, what are you doing for key storage? That's often the most > complex part of the problem. Yes, you are exactly right about that. For now planning on using normal java keystore facility. Starting the servers will require an admin to enter password which will unlock the keystore. There will likely be additional security enhancements protecting the keystore. The important thing is to move all these concerns outside Cayenne, so that each org could make their own decisions as to the levels of security required. Cayenne will provide an abstract way to do transparent per-column crypto. I am thinking of a very simple Cayenne-side “cayenne-crypto” Maven/DI module, free of key management code and defining 2 abstract services: (1) Cypher - a pluggable encryption mechanism with ability to version keys (2) Metadata - telling Cayenne which columns are encrypted. And also declaring overrides of RowReaderFactory and other relevant services to enable encryption. Andrus
Re: Interceptable ExtendedType
> I think ExtendedType already provides that, so just making sure it isn't > overlooked. Did you mean “DON’T think .. “? ExtendedType is completely free of the mapping context: http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/access/types/ExtendedType.html I already started committing some code. Looks like I found a better place for reads that has all the metadata and does not require changing ExtendedType - RowReader. So I created RowReaderFactory that should allow to intercept read data one row at a time. Haven’t looked at writes yet. Andrus On Mar 12, 2014, at 11:06 PM, Michael Gentry wrote: > In addition to the attribute being read/written, I think it would (or > could) also be helpful to know which entity, too. I think ExtendedType > already provides that, so just making sure it isn't overlooked. > > mrg > > > > On Wed, Mar 12, 2014 at 3:13 AM, Andrus Adamchik > wrote: > >> A heads up. I am looking to extend ExtendedType API to be a little more >> context-aware (know which attribute is being read/written). My motivation >> is quite interesting on its own - I need to implement generic data >> encryption extensions that would encrypt/decrypt certain columns on the >> fly. And I feel like ExtendedType is a place that is low-level enough to >> make the encryption transparent to the rest of the stack. Very excited >> about this project :) >> >> A.
Re: Interceptable ExtendedType
On 12/03/2014 6:13pm, Andrus Adamchik wrote: > A heads up. I am looking to extend ExtendedType API to be a little more > context-aware (know which attribute is being read/written). My motivation is > quite interesting on its own - I need to implement generic data encryption > extensions that would encrypt/decrypt certain columns on the fly. And I feel > like ExtendedType is a place that is low-level enough to make the encryption > transparent to the rest of the stack. Very excited about this project :) Out of interest, what are you doing for key storage? That's often the most complex part of the problem. Ari -- --> Aristedes Maniatis GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
Re: Interceptable ExtendedType
In addition to the attribute being read/written, I think it would (or could) also be helpful to know which entity, too. I think ExtendedType already provides that, so just making sure it isn't overlooked. mrg On Wed, Mar 12, 2014 at 3:13 AM, Andrus Adamchik wrote: > A heads up. I am looking to extend ExtendedType API to be a little more > context-aware (know which attribute is being read/written). My motivation > is quite interesting on its own - I need to implement generic data > encryption extensions that would encrypt/decrypt certain columns on the > fly. And I feel like ExtendedType is a place that is low-level enough to > make the encryption transparent to the rest of the stack. Very excited > about this project :) > > A.
