I'll preface this with, im volunteering to write this myself as it probably has a decent work effort involved and I just did a bunch of this recently for the ShieldTV binding. I am however looking for input on how best to structure it.
Over the past few weeks of working on the ShieldTV binding I've encountered a few decent learning curves. The biggest was working with crypto functions (specifically PKI, not transport). Several bindings need to create, store, and interact with devices using specific keys and certificates. Unfortunately, we don't have a centralized set of functions to help the developers/maintainers easily perform these functions. This came up during a separate discussion I was having with @kaikreuzer and he suggested opening an issue here for a larger discussion.
I propose a new addition to the core (looking for suggestions as to where it's most appropriate). Forgive the bad pseudocode but I would envision it working something like this:
CryptoStore myCrypto = new CryptoStore(); //add a variety of different options to accept keys, filenames, etc at creation
myCrypto.generateKey(Int keyLength, String algorithm); // Generate a private key of requested length and with stated algorithm
myCrypto.generateSelfSignedCert(String name); //use the private key and the certificate name/data to create a self signed certificate
myCrypto.loadFromFile(String fileName);
myCrypto.writeToFile(String fileName);
myCrypto.getKeyStore() //Return a KeyStore that's properly initialized and populated.
myCrypto.setKey(String myKey); //Store a base64 encoded private key
myCrypto.setCert(String myCert); //Store a base64 encoded certificate
Keys and certs would be held as base64 encoded strings when not directly in the KeyStore format. There's probably a dozen functions I'm not listing, as well as variants of those above which need to be mapped out (e.g. to return the private key as a Key instead of a String if that's what's needed, get and set functions for each variable, some sort of consolidated exception catch/throw to a single CryptoException, etc.). By doing it this way you also can have multiple sets of keys being used without adding confusion.
Assuming this gets accepted/merged, we would then need to petition the developers to make the necessary changes to remove their crypto bits and adopt this as a standard. Documentation will be obviously necessary. I'd volunteer to adapt the ShieldTV first so it can be used as an example to others.
Thoughts?
I'll preface this with, im volunteering to write this myself as it probably has a decent work effort involved and I just did a bunch of this recently for the ShieldTV binding. I am however looking for input on how best to structure it.
Over the past few weeks of working on the ShieldTV binding I've encountered a few decent learning curves. The biggest was working with crypto functions (specifically PKI, not transport). Several bindings need to create, store, and interact with devices using specific keys and certificates. Unfortunately, we don't have a centralized set of functions to help the developers/maintainers easily perform these functions. This came up during a separate discussion I was having with @kaikreuzer and he suggested opening an issue here for a larger discussion.
I propose a new addition to the core (looking for suggestions as to where it's most appropriate). Forgive the bad pseudocode but I would envision it working something like this:
CryptoStore myCrypto = new CryptoStore(); //add a variety of different options to accept keys, filenames, etc at creation
myCrypto.generateKey(Int keyLength, String algorithm); // Generate a private key of requested length and with stated algorithm
myCrypto.generateSelfSignedCert(String name); //use the private key and the certificate name/data to create a self signed certificate
myCrypto.loadFromFile(String fileName);
myCrypto.writeToFile(String fileName);
myCrypto.getKeyStore() //Return a KeyStore that's properly initialized and populated.
myCrypto.setKey(String myKey); //Store a base64 encoded private key
myCrypto.setCert(String myCert); //Store a base64 encoded certificate
Keys and certs would be held as base64 encoded strings when not directly in the KeyStore format. There's probably a dozen functions I'm not listing, as well as variants of those above which need to be mapped out (e.g. to return the private key as a Key instead of a String if that's what's needed, get and set functions for each variable, some sort of consolidated exception catch/throw to a single CryptoException, etc.). By doing it this way you also can have multiple sets of keys being used without adding confusion.
Assuming this gets accepted/merged, we would then need to petition the developers to make the necessary changes to remove their crypto bits and adopt this as a standard. Documentation will be obviously necessary. I'd volunteer to adapt the ShieldTV first so it can be used as an example to others.
Thoughts?