I have a desktop application which contains an App.config (program.exe.config at release) with clearly visible elements which define my WCF endpoints and WCF implementation.
I would ideally like to hide this from the users eyes, from simple hacking, view and change.
Should I: –
- Programmatically create and store my WCF endpoints and binding configuration in code. or;
- Implement some protection scheme over the App.config (if so, what, how), effectively obfuscating/encrypting these elements from public view, but understandable from my code?
I already utilise .NET Reactor to obfuscate and protect my program from reflection techniques.
Update 13-May-09 3:32 GMT+10
Alright well I managed to encrypt system.serviceModel but then it proved unusable when the app went to launch as an exception was thrown (System.TypeInitializationException: The type initializer for ‘System.ServiceModel.DiagnosticUtility’ threw an exception.)
<system.serviceModel>
<!-- [bindings] -->
<bindings configProtectionProvider="DPAPIProtection">
<EncryptedData>
<CipherData>
<CipherValue>AQAAANCMnd8BFdERjHoAwE/Cl+...
So there goes that idea. I’ll either ditch this idea, or set my endpoints in code which is behind encryption.
Isn’t anybody else concerned about their endpoint addresses clearly visible in config???
Protecting it from change is easier that protecting it from view.
If it is simply change/hacking you are worried about, you can just compute a digital signature on the XML elements that comprise your unchangeable WCF settings, using your public key. If the customer changes anything, the sig won’t match.
I don’t know a good way to protect it from view, really, because a determined person is going to be able to find out what you are doing in WCF (as the previous poster pointed out). You could make it more difficult, but that wouldn’t be preventing someone from viewing or learning the information.
UPDATE:
You need to use your own RSA private key for signing. Maybe you have an RSA keypair already. If not, you might generate a keypair, once, to do the signing. Like this.
Once you have that, you can export and save it. For your own use, signing, you want the private key. For verification, apps will use the public key. This is how you get them.
Store these. If you ever want to sign something again using the same private key, get the RSA CSP with the FromXmlString() method, passing the PrivateKeyXml. If you want to verify, use FromXmlString() passing the PublicKeyXml.
Once you have the key and the XML to be signed, you can do the signing. This happens just during packaging and deployment, when you create and finalize the configuration.
Then, embed the signed XML into app.config or as a string in the app, or whatever. When the app runs, you verify the signature at runtime, using the public key blob.
Here’s some code that does signature verification:
To test that your signature and verification actually does work, modify either the signature or the xml content that has been signed. You should see the verification fail. In the case of failed verification, your app might throw, or exit, or whatever.