For my Xamarin.Forms application I've created a ASP.NET Web API as a backend to handle serverside stuff.
When it comes to security I'm pretty much lost.
I've read alot of articles containing alot of possibilities such as HCMA, OAuth and others.
For my purpose I think just SSL/Https will do the job.
I just have no idea where to start. All the documentation I've read didn't help me...
Does anyone know a place where I can get some help or can anyone describe what to do to get this done ?
As far as I know I got to create a SelfSignedCertificate.
But where do I put it ?
Inside of my App(Resources)?
Please provide me some help.
Anything is highly appreciated.
EDIT 1:
As by now I have create a Custom Attribute EnforceSSL in my WebAPI.
All my WebRequests in my App are now HttpsWebRequests.
Does this mean all my traffic is secured ?
As far as I could find out in order to secure my API/Website I need a SSL-Certificate. I can either create one or buy one ... (is this correct) ?
I guess I need to inclued this in my IIS, where my API runs.
Do I need any Client Certificate which I have to install on the phones which use my app ?
I dont want this to go unanswered, in future for general security questions http://security.stackexchange.com is the place.
For my purpose I think just SSL/Https will do the job.
That's right use HTTPS (HTTP Secure). You can configure the webserver to redirect all http:// to https:// automatically. Follow this TechNet guide to Configuring Server Certificates in IIS 7.
I'd also recommend you test your web services out with https://www.ssllabs.com/ssltest/ that grades how secure your web site/service is. SSLLabs mainly catches TLS 1.1 vulnerabilities so make sure you're on the latest TLS to get a Grade A. TLS is basically the same thing as SSL. SSL 3.0 was the last version of SSL. TLS – Transport Layer Security, a new name for SSL. TLS 1.0 is colloquially considered “SSL 3.1”. Created and maintained by Internet Engineering Task Force. The latest version is TLS 1.2 and TLS 1.3 is currently in draft format.
All my WebRequests in my App are now HttpsWebRequests. Does this mean all my traffic is secured?
Nothing is 100% secure, but it sounds like you're following the recommended practices: https://developer.xamarin.com/guides/cross-platform/macios/http-stack/
Do I need any Client Certificate which I have to install on the phones which use my app?
What you're thinking of is called Certificate Pinning and https://forums.xamarin.com/discussion/8743/self-signed-cert-using-httpclient
The 3 most common mistakes to securing a mobile app are:
Hardcoding keys into source code:
Not using encryption correctly:
Not using HTTPS.
Securing Mobile Apps is such a large subject - there are entire books on the topic. At the very least read up on:
OWASP Mobile Security Project:
https://www.owasp.org/index.php/OWASP_Mobile_Security_Project and
Secure Coding Guidelines for iOS and Android: https://mgovlab.government.ae/uploads/SecureCodingGuidelines.pdf and make sure you've covered off the top 10 vulnerabilities:
Store local data securely
Protect remote data transportation
Implement appropriate authentication
Audit third-party code and services
Respect user data
Protect from reverse engineering
Secure web services and servers
Validate input and interprocess
communications
Avoid exploitable code errors
Distribute an application securely
When you package your application follow the offical Xamarin guide, pay attention to ProGuard.
https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/
Related
I have a c#-based program that can send messages and files to our SlackWorkspace via my SlackApp (I'm using HttpClient to communicate with Slack).
Now, to distribute this program in my workspace and to make it so that every user will have his own identity, it says that I have to use OAuth and create verification-tokens, specific for each user.
It says in the Slack-documentation I have to use a redirect-URL (as per docs) to my own server.
We have a server that I potentially could use for this. But I have never done anything like this before and I am unclear on what "answer" I have to provide from our server. I thought the verification-process would be handled by Slack.
Anyone has an idea on how to approach this?
And before anyone asks - yes we need to install it for everyone and make them identifiable as themselves. We can't use the "SlackApp" as user. :)
I would be very grateful for code examples(in c#) and explanations on how this whole redirect-thing is working.
Slack uses the standard Oauth 2.0 protocol to authenticate apps, similar to Google and Facebook.
So the "verification-process" is indeed mostly handled by Slack (as outlined here), but your Slack app needs to initiate it and handle the responses properly. Also its a multi-step process and includes the user having to login into Slack with their credentials. This why you need a web app to handle the whole process.
To enable a Slack app to generate tokens via Oauth a web app is needed:
can be reached from the Internet
able to handle HTTP requests like a web server
has persistent storage for the newly generated tokens
This is probably easier to implement with ASP.NET Web Pages, which can utilize many functions from an existing web server.
But for this answer, lets look on an implementation in .NET Core. For that we need to create our own web server and some rudimentary session handling. Main concepts include:
HttpListener class for providing fundamental ability to listen and respond to HTTP requests
Handle multiple requests in parallel
Cookies / Session handling
MD5 hashes
The details go a bit beyond the scope of one answer. But I am happy to share a working example implementation on this GitHubGist.
Btw: For the local development of such a web app its recommend to use a VPN tunnel like ngrok, that allows one to expose a local machine securely to the Internet and Slack.
I have 2 seperate web services that currently use HTTP. (C#)
1 is a Soap web service (asmx)
1 is a WebAPI restful service.
Is there anything particular that I will need to do code wise to make both of these web services SSL only?
Would all of the configuration to SSL take part on the server?
It depends on the environment.
First you need to purchase a certificate. If you search for Comodo cert, you'll find many resellers for them including folks like namecheap.com
Then, you'll have to see how to install. If using Azure or Google Cloud, etc, they usually install on a separate Load Balancer. In general, large systems usually terminate the SSL link well before hitting any application servers, but for your setup may be easiest to just leverage IIS for now.
If it's your own IIS setup, take a look at DigiCert's instructions. While their certs are very expensive, they do have good documentation/tools. https://www.digicert.com/ssl-certificate-installation-microsoft-iis-7.htm
There are some tools like Let's Encrypt that try to make SSL Cert issuance easier, but for now it's sometimes more complicated to set up. I usually like just buying a wildcard cert so you can easily have subdomains like blog.example.com, etc.
I am going to be creating a web service that will be passing confidential information across the network.
What would be the best way to secure the web service?
how do I know if the application requesting the information is who it says it is, and it's not another application that is using another's user name and password?
Use WCF for your web service! It has tons of security capabilities:
You can
secure your clients via Certificates - only those that have the appropriate certificate will be allowed to get their calls processed
secure your clients by looking them up in your internal Active Directory domain - only those with AD accounts will be allowed to get their requests processed
secure your clients with custom username/passwords which you can look up against anything you want (this is the most flexible, but also the most complicated option, and offer the most potential for failure if you get something wrong)
Plus, with WCF, you also have loads of options to secure the transport between client and service, or encrypt and sign the messages going back and forth.
See the WCF Developer Center as a great starting point for all things WCF.
If you're serious about safely and securely programming WCF services, grab a copy of the Programming WCF Services book by Juval Lowy - it's the bible for WCF.
I've done this once or twice in the past:
Use SSL
Write the webservice to require a token which is retrieved from a method on the webservice.
Have the token returned from a method which requires a login and password.
After a certain number of webservice requests, or at random intervals, change the token required, thus forcing a re-authentication.
If you want to, encrypt the data in the ssl stream, by using an encryption method which both parties understand. (if you're paranoid.)
You don't write which implementation technology you intent to use, so let me start by recommending that you use Windows Communication Foundation (WCF) instead of asmx web services.
With WCF you can select between many different bindings, many of which offer data protection. Overall, there are two different styles of data protection for web services:
Transport protection, where the transport mechanism itself offers protection in form of encryption. The best known version of this is HTTPS/SSL. However, note that unless you employ client certificates, the service has no guarantee that the client is what it says it is.
Message protection, where the message itself is encrypted and signed. Such messages can travel over otherwise unprotected networks and still be protected.
The WsHttpBinding offers message protection according to open standards. That's where I would start.
Have a look at WIF (aka Geneva framework). Its purpose is to solve the exact problem you describe.
http://msdn.microsoft.com/en-us/security/aa570351.aspx
I am building a proxy server in C# and I am trying to figure out how to support HTTPS requests, and read through them. Can you suggest any articles, tutorials, or open source projects where I can learn more on how to implement this feature?
If by "read through them" you mean "decrypt the contents of the request", the answer is "You can't". What you describe is a so called "man in the middle attack" (MITM). Obviously, SSL is protected from this.
Now, if you have control over the clients using your proxy (some kind of enterprise environment, or you are creating a competitor to Fiddler), you can subvert SSL by making clients trust your certificates, and then implement your MITM using standard .NET crypto APIs.
PS. For an exellent example of this approach, look at Fiddler with Reflector. :)
Disclaimer: I've tried Googling for something that will do what I want, but no luck there. I'm hoping someone here might be able to lend a hand.
Background
I have a .NET class library that accesses a secure web service with the WSE 2.0 library. The web service provides a front-end to a central database (it's actually part of a data-sharing network spanning multiple customers) and the class library provides a simple wrapper around the web service calls to make it accessible from a legacy VB6 application. The legacy application uses the class library to retrieve and publish information to the web service. Currently, the application and class library DLL are both installed client-side on multiple workstations.
The Problem
The catch is that the web service we are accessing uses HTTPS and a valid X509 client certificate needs to be presented to the web service in order to access it. Since all of our components live on the client machine, this has led to deployment problems. For example, we have to download and install per-user certificates on each client machine, one for each user who might need to access the web service through our application. What's more, the web server itself must be accessed through a VPN (OpenVPN in particular), which means a VPN client has to be installed and configured on every client machine. It is a major pain (some of our customers have dozens of workstations).
The Proposed Solution
The proposed solution is to move all of this logic to a central server on the customer site. In this scenario, our legacy application would communicate with a local server, which will then go off and forward requests to the real web service. In addition, all of the X509 certificates would be installed on the server, instead of on each individual client computer, as part of the effort to simplify and centralize deployment.
So far, we've come up with three options:
Find a ready-made SOAP proxy server which can take incoming HTTP-based SOAP requests, modify the Host header and routing-related parts of the SOAP message (so they are pointing to the real web server), open an SSL connection to the real web server, present the correct client certificate to the server (based on a username-to-certificate mapping), forward the modified request, read the response, convert it back to plaintext, and send it back to the client.
Write a proxy server by hand that does everything I just mentioned.
Think of completely different and hopefully better way to solve this problem.
Rationale
The rationale for trying to find and/or write a SOAP proxy server is that our existing .NET wrapper library wouldn't have to be modified at all. We would simply point it at the proxy server instead of the real web service endpoint, using a plain HTTP connection instead of HTTPS. The proxy server will handle the request, modify it to so that the real web service will accept it (i.e. things like changing the SOAPAction header so that it is correct), handle the SSL/certificate handshake, and send the raw response data back to the client.
However, this sounds like an awful hack to me me at best. So, what our my options here?
Do I bite the bullet and write my own HTTP/SSL/SOAP/X509 aware proxy server to do all this?
Or...is there a ready-made solution with an extensible enough API that I can easily make it do what I want
Or...should I take a completely different approach?
The key issues we are trying to solve are (a) centralizing where certificates are stored to simplify installation and management of certificates and (b) setting things up so that the VPN connection to the web server only occurs from a single machine, instead of needing every client to have VPN client software installed.
Note we do not control the web server that is hosting the web service.
EDIT: To clarify, I have already implemented a (rather crappy) proxy server in C# that does meet the requirements, but something feels fundamentally wrong to me about this whole approach to the problem. So, ultimately, I am looking either for reassurance that I am on the right track, or helpful advice telling me I'm going about this the completely wrong way, and any tips for doing it a better way (if there is one, which I suspect there is).
Apache Camel would fit the bill perfectly. Camel is a lightweight framework for doing exactly this kind of application integration. I've used it to do some similar http proxying in the past.
Camel uses a very expressive DSL for defining routes between endpoint. In your case you want to stand up a server that is visible to all the client machines at your customer site and whatever requests it receives you want to route 'from' this endpoint 'to' your secure endpoint via https.
You'll need to create a simple class that defines the route. It should extend RouteBuilder and override the configure method
public class WebServiceProxy extends RouteBuilder
{
public void configure()
{
from("jetty:http://0.0.0.0:8080/myServicePath")
.to("https://mysecureserver/myServicePath");
}
}
Add this to a Camel context and you'll be good to go.
CamelContext context = new DefaultCamelContext();
context.addRoute(new WebServiceProxy());
context.start();
This route will create a webserver using jetty bound to 8080 on all local interfaces. Any requests sent to /myServicePath will get routed directly to your webservice defined by the uri https://mysecureserver/myServicePath. You define the endpoints using simple uris and the dsl and camel takes care of the heavy lifting.
You may need to configure a keystore with your certs in in and make it available to the http component. Post again if you've trouble here ;)
I'd read the camel docs for the http component for more details, check the unit tests for the project too as they are chock full of examples and best practices.
HTH.
FYI: To have the http component use your keystore, you'll need to set the following properties
System.setProperty("javax.net.ssl.trustStore", "path/to/keystore");
System.setProperty("javax.net.ssl.trustStorePassword", "keystore-password");
You should look into WCF, which supports the WS-Addressing protocol. I believe I've seen articles (in MSDN, I think) on writing routers using WCF.
You should also get rid of WSE 2.0 as soon as possible. It's very badly obsolete (having been replaced by WSE 3.0, which is also obsolete). All of its functions have been superceded by WCF.
I believe an ESB (Enterprise Service Bus) could be a viable, robust solution to your problem. There is an open source ESB called Mule, which I've never used. I did mess around with ALSB (AquaLogic Service Bus) a while back, but it would be expensive for what you are describing. Anyway, the thing that you would want to look at in particular is the routing. I'm not sure it would be a simple plug 'n play, but it is indeed another option.
You can also do this with Microsoft ISA Server, a commercial Proxy/Cache server. It will do many of the things you need out of the box. For anything that is not possible out of the box, you can write an extension to the server to get it done.
ISA Server is not free.
ISA is now being renamed to "Microsoft Forefront Threat Management Gateway".
It is much more than a web proxy server, though - it has support for many protocols and
lots of features. Maybe more than you need.
There is a service virtualization tool from Microsoft available on Codeplex called the Managed Service Engine which is intended to decouple the client from the web service implementation. It might fill the bill or give you a running start. I haven't really investigated it thoroughly, just skimmed an article in MSDN and your description reminded me of it.
http://www.codeplex.com/servicesengine
http://msdn.microsoft.com/en-us/magazine/dd727511.aspx
Your security model doesn't make sense to me. What is the purpose of using HTTPS? Usually it is to authenticate the service to the clients. In that case, why does the server need to keep the clients' certificates? It is the clients who should be keeping the server's X509 Certificate.
Why do you need to go through VPN? If you need to authenticate clients, there are better ways to do that. You can either enable mutual authentication in SSL, or use XML-Security and possibly WS-Security to secure the service at the SOAP level. Even if you do use SSL to authenticate clients, you still shouldn't keep all the client certificates on the server, but rather use PKI and verify the client certificates to a trusted root.
Finally, specifically for your proposed proxy-based solution, I don't see why you need anything SOAP-specific. Don't you just need a web server that can forward any HTTP request to a remote HTTPS server? I don't know how to do this offhand, but I'd be investigating the likes of Apache and IIS...