Hosting Asp.net Core 6 Web API with SSL on a Specific Port - asp.net-web-api

I have developed Asp.net Core 6 Web Api and want to host it on my Windows server on a specific port that has SSL installed. Here is what I have done so far -
I have an SSL certificate which I added in the Personal store using certificate manager.
I installed this SSL certificate on Port 10001 and it got added successfully.
I created a subdomain and pointed it to this web server.
I want to run this API as an EXE hosted with Kestrel. I tried -
app.run("https://api.xxxxxx.com:10001")
I get an error that SSL Certificate could not be located.
Please help me with how to do this.

It would be useful if you provided the commands used for adding the port reservation and how you added the certificate to Windows, but anyways, my personal experience dealing with self-hosted apps and SSL is the following:
Add the certificate used for https to the Windows Certificates Store -> Local Computer (this is important, don't use the Current User store) -> Personal store
If NOT using localhost as the server address, as in your case, a Url mapping must be done with netsh.exe (with an elevated command window):
netsh.exe http add urlacl url=https://+:10001/ user=Users (*)
Next, make a port reservation using also netsh.exe:
netsh.exe http add sslcert ipport=0.0.0.0:10001 certhash=[your cert hash here] appid={your app id here}
(*) If your Windows language is other than English, use the name of the translated Users group. For instance, in spanish it would be "Usuarios".
If all these procedures are done correctly, you should be able to launch a server that binds to the specified port with https enabled.
Good luck

Related

Running ASP.Net Web Api inside intranet - cert authority invalid

I made simple API for which is running on my "server" inside local network. When I want to call api from another PC internet browser inside my intranet over https://xxx.xxx.xxx.xxx:9100/ShowList i get warning from my browser that my connection is not private NET:ERR_CERT_AUTHORITY_INVALID. I can proceed as unsafe but i would like to avoid that. The question is what I have to do to have save connection inside my intranet? I'm totally new in that so i'm aware of thing I have to do.
You just need to add a ssl certificate to the hosting IIS server (assuming you are using IIS as the server). You can create a Self-Signed Certificate, buy from the vendors or use free services. Take a look at
https://learn.microsoft.com/en-us/iis/manage/configuring-security/how-to-set-up-ssl-on-iis

Performance Testing for Hybird App

I am supposed to do a performance test for a Hybrid App.
First, from my adroid device i have modified the proxy settings by choosing Manual option and entered my system IP address as proxy server 192.168.1.10 and entered Port as 8080.
And then from Jmeter 3 i took Recording Controller Template from HTTPS Script Recorder I entered the port as 8080.
After Starting HTTPS Script Recorder when i opened my hybrid app it was not working. "Unfortunately we cannot find your account information". This means that Hybrid apps is not connecting internet through Proxy mode.
But i am able to get response from other apps installed in my android device.
I tried Neoload, Blazemeter as well https://guide.blazemeter.com/hc/en-us/articles/207420545-BlazeMeter-Proxy-Recorder-Mobile-and-web-.
But the same issue i faced every where.
Please provide me a solution to make the Hybird App work even after connecting internet through Proxy Mode.
Thanks
N Ali
You need to find out the main error using i.e. Logcat Command to narrow down the possible reasons as there could be too may of them.
The below hints are applicable for HTTPS traffic only, however I'm pretty sure that modern applications use HTTPS protocol.
You may need to use a 3rd-party application in order to set up HTTPS proxy, i.e. ProxyDroid
You will definitely need to install JMeter's self-signed certificate onto device so JMeter could decrypt and record secure traffic.
Locate ApacheJMeterTemporaryRootCA.crt under "bin" folder of your JMeter installation and transfer it to your android device (i.e. send it to yourself via the email)
Click at the attached certificate
Follow android system certificate installation dialog to get it set up
Be aware that JMeter's certificate has limited life time (7 days) so you won't be able to record secure traffic if it is expired.
More information:
HTTPS recording and certificates
Load Testing Mobile Apps Made Easy
In addition to Dimitri's answer reg JMeter, NeoLoad also has a similar CA certificate which needs to be added to the device.
You can locate this certificate from
C drive -> Users -> Username -> Appdata -> Roaming -> Neotys -> CA certificate
Copy this certificate to your device (or mail it to yourself) and install it either by directly selecting it or from the security settings.
Once the certificate is installed in the device, you should be able to record the HTTPs traffic from the application via proxy.
P.S. Ensure that you are able to view all hidden files coz by default Appdata is hidden.

SSL certificate - Use Client certificate installed on server for local testing - Mutual authentication

I have been working with web services connecting to URLs provided by different clients and so far it has all been done using one-way authentication. Now I'm asked to enable 2-way (mutual) authentication for one of the clients. I did a lot of research and reading but still confused about a lot of things.
I could test successfully on my local machine following instructions from various different articles. But the problem is now to deploy it in production.
Here's what I did for testing: I created a test Web service Host and assigned it a self-signed certificate and created a client to test this. After this I created a client certificate using makecert and verified that this is installed via MMC. I then modified my Host app to only allow clients with certificate and tested from client to see the connection refused due to not providing the client certificate. Then I modified the bindings in the client application to include the certificate name and I was able to connect to the Host successfully. So this completes local hosting.
Now the real problem. The tech team is going to create a certificate in "cert store" on the server. And I need to test again to make sure everything works as expected. We have a few different developers who all want to test on their machines on their local code. Can we all use the same certificate somehow? I don't think we would be allowed to import the certificate but what suggestions could I give them so all of us can use the same certificate?
I'm also confused about issues like difference between windows certificate and IIS certificate. What advantages would the IIS certificate provide?
Thanks for help!
Edit: Could one of the differences between installing on IIS be so that the hosted sites be accessed via SSL connection? This would mean we don't really need to install on IIS if it's just a client certificate. Is this correct?

Accessing HTTPS content from out-of browser Silverlight 4 applications

I am using some of the local machine's resources using COM interop functionality provided in Silverlight 4.0. Hence, naturally I need OOB with elevated permissions. However, in my case I am consuming the WCF services hosted on HTTPS channel. Here is where I am facing the problem. The OOB with elevated permissions applied, doesn't allow me consuming the HTTPS service hosted on either different or the same domain, giving me a NotFound exception. Please note that I have used the self-signed certificate for the development environment. The same is also installed in the Trusted Root folder of the client machine on which I am testing.
Interestingly, when I set the Fiddler options (in Fiddler session, Toos -> Fiddler Options -> HTTPS tab) to intercept the HTTPS traffic, with Decrypt HTTPS traffic checkbox set, I am able to use the same HTTPS service without any exception. But for that, I was told by Fiddler to store a temporary certificate inside my user profile's Fiddler directory, and I must have at least one Fiddler session at that time. Hence, it seems to be a certification issue. But does it relate in anyway to signing of the XAP file with the required certificate ? I am not sure. I tried with a self-signed certificate and bind my layer service URL to use that certificate. Then I install the same certificate to Trusted root folder of the client. But i was not successful in signing the XAP with that certificate.
Please let me know if you have any work-around.
If the code is running in a different user's context, you need to put your "Self-signed" certificate into the Machine Trusted Root store. Start mmc.exe. On the File menu, choose to Add a Snap-in. Add the Certificates snap-in. Pick Local Machine. Import the Self-signed root into the Trusted Root store.
I had the same problem and found out, that the SSL settings in IIS were wrong.
I configured IIS 7.5 to SSL only and to accept client certificates. With this settings, I ended up with the service not found error in OOB. After setting IIS to ignoring client certificates the OOB Application works fine.

Creating a web service that requires client certificates

I am currently working on a project that has the following components (all .NET 2.0)
Client Application
Web Service Invocation API
Web Service
In summary the Client Application creates and instance of the API and this calls the Web Service. Nice and simple and this all works exactly as I want it to.
The next stage of the project was to secure the Web Service with SSL. So I have created a "Self Signed CA" and from this signed a server certificate for IIS. Again, nice and simple and this all works exactly as I want it to.
The next stage of the project is to secure the Web Service by requiring the invoker to supply a client certificate. So I have created a client certificate (via the Self Signed CA). I am then adding this to the Web Service invocation call in the API:
WSBridge.Processor processor = new WSBridge.Processor();
processor.Url = this.endpoint;
processor.ClientCertificates.AddRange(this.clientCertificates);
processor.Timeout = (int)Settings.Default["DefaultTimeout"];
In debug I can see that this.clientCertificates contains the certificate I created. So in theory it is being presented to the web server.
However, when I attempt to call the Web Service I get the following exception in the API:
The request failed with HTTP status 403: Forbidden.
Fairly self explantory, but I have no idea what is causing the problem.
Other relevant information:
In my dev environment Client, API & Web Service are all running on the same machine
If I attempt to access the Web Service Description in IIS I get the following error (I am not prompted to choose a client certificate):
HTTP Error 403.7 - Forbidden
The page you are attempting to access requires your browser to have a Secure Sockets Layer (SSL) client certificate that the Web server recognizes.
The client certificate is loaded into the Personal store for the current user, the CA root is in trusted root for the local machine and current user.
If I switch off "Require SSL" and put "Client Certificates" on accept in IIS I can make my request. However when I look at HttpContext.Current.Request.ClientCertificate.Count in the Web Service this comes back as 0.
I need to be able to run my development with client certificates as portions of the service code use the CN of the client certificate to perform various actions. I could hack it in but it would be nice to be able to do a real end to end.
All the certificates mention here were generated using OpenSSL. I am developing on Windows 7 so I do not have the facility to install Microsoft CA
So, does anybody have any ideas as to the cause of this problem?
As an aside (not worth creating a new question for this) - for some reason when I enable SSL for the Web Service Visual Studio is no longer able to debug the service.
EDIT : Some more information
The client certificate has an intended purpose of <All>
Although I am working on localhost the server certificate for the web server was issued to devserver.xyz.com so I have changed my hosts file to point that to localhost. As such I can now browse (with client certs switched off in IIS) to my service descriptor page without seeing any SSL certificate warnings.
Well I have solved the problem, in summary this was due to the format of the client certificate this should have been PKCS12.
More Detail
Although the MMC Certificate plugin was showing the client certificate in the personal store for the current userm I noticed that when viewing the same store via Internet Explorer (Tools -> Internet Options -> Content -> Certificates) the certificate was not present.
After a little Googling it seems that IE will only accepts PKCS12 format for client certificates, so I convert the certificate with the following OpenSSL command:
openssl pkcs12 -export -in client_alpha.cer -inkey client_alpha.key -out client_alpha.p12
I then imported the p12 file into IE which allowed me to browse to the Web Service description page with full client/server certificated TLS.
Once I had made this change, I then retried by client application and this now works aswell. This is due to the fact that IIS, like IE, will only accept client certificates in PKCS12 format.

Resources