شرح جزئیات
fiogf49gjkf0d
همیشه از HTTPS استفاده کنید. تنظیم سرویس https در IIS:
برای تنظیم سرویس ssl در IIS، باید certificate ای داشته باشید تا از آن برای encode و decode کردن اطلاعات ردوبدلی در سطح شبکه استفاده شود. ابتدا فرض می کنیم که سایت شما به یک certificate ، assign شده، حال باید تنظیمات آن را انجام دهید، در آپاچی، certificate را از یک فایل source توسط SSLCACertificateFile می خواند ولی در IIS باید certificate را با استفاده از تب Directory Security در Web site یا folder properties بصورت زیر تنظیم کنید:
1. Log on to the Web server computer as an administrator.
2. Click Start, point to Settings, and then click Control Panel.
3. Double-click Administrative Tools, and then double click Internet Services Manager.
4. Select the Web site from the list of different served sites in the left pane.
5. Right-click the Web site, folder, or file for which you want to configure SSL communication, and then click Properties.
6. Click the Directory Security tab.
7. Click Edit.
8. Click Require secure-channel (SSL) if you want the Web site, folder, or file to require SSL communications.
9. Click Require 128-bit encryption to configure 128-bit (instead of 40-bit) encryption support.
10. To allow users to connect without supplying their own certificate, click Ignore client certificates.
Alternatively, to allow a user to supply their own certificate, use Accept client certificates.
11. To configure client mapping, click Enable client certificate mapping, and then click Edit to map client certificates to users.
If you configure this functionality, you can map client certificates to individual users in Active Directory. You can use this functionality to automatically identify a user according to the certificate they supplied when they access the Web site. You can map users to certificates on a one-to-one basis (one certificate identifies one user) or you can map many certificates to one user (a list of certificates is matched against a specific user according to specific rules. The first valid match becomes the mapping).
12. Click OK.
برای اطلاعات بیشتر برای IIS7 می توانید به لینک زیر مراجعه کنید:
http://www.iis.net/learn/manage/configuring-security/how-to-set-up-ssl-on-iis
چند نکته :
1- چگونه می توانم ارتباط امن ssl را در Asp.Net Web API اعمال نماییم ؟
اگر از IIS استفاده می کنید، کار خاصی نباید انجام دهید، تنها در IIS، SSL را تنظیم کنید و نرم افزارتان را برای استفاده از https اجبار کنید، این کار را می توانید به شکل های مختلف مثلا استفاده از ماژول IIS URL Redirect module انجام دهید، اما می توانید این کار را درسطح نرم افزار با یک message handler انجام دهید:
public class RequireHttpsMessageHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.RequestUri.Scheme != Uri.UriSchemeHttps) {
var forbiddenResponse = request.CreateResponse(HttpStatusCode.Forbidden);
forbiddenResponse.ReasonPhrase = "SSL Required";
return Task.FromResult<HttpResponseMessage>(forbiddenResponse);
}
return base.SendAsync(request, cancellationToken);
}
}
2- چگونه می توانم لاگین امن را در asp.net و سی شارپ اعمال نمایم ؟
برای SSL یک certificate خریداری کنید و سپس آنرا نصب کنید: (لینک زیر یک نمونه)
http://www.instantssl.com/ssl-certificate-support/cert_installation/iis_ssl_certificate_5x.html
سپس با دستور زیر اطمینان حاصل کنید که صفحه login ، redirect می شود به https بجای http :
if (!Request.IsSecureConnection)
{
Response.Redirect(Request.Url.AbsoluteUri.ToLower().Replace("http", "https"), true);
}
3- چگونه می توانم ارتباط امن ssl را در MVC اعمال نمایم ؟
ابتدا تنظیم SSL در IIS و سپس force کردن ssl به Web API بصورت زیر:
public class RequireHttpsAttribute : AuthorizationFilterAttribute
{
public override void OnAuthorization(HttpActionContext actionContext)
{
if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
{
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)
{
ReasonPhrase = "HTTPS Required"
};
}
else
{
base.OnAuthorization(actionContext);
}
}
اضافه کردن فیلتر زیر به هر Web API action ای که باید require ssl بشود:
public class ValuesController : ApiController
{
[RequireHttps]
public HttpResponseMessage Get() { ... }
}
برای تنظیم کردن IIS به پذیرفتن client certificate ها:
ابتدا IIS Manager را باز کنید و سپس مراحل زیر را انجام دهید:
1. Click the site node in the tree view.
2. Double-click the SSL Settings feature in the middle pane.
3. Under Client Certificates, select one of these options:
o Accept: IIS will accept a certificate from the client, but does not require one.
o Require: Require a client certificate. (To enable this option, you must also select "Require SSL")
می توانید این کار را از طریق تنظیمات در فایل ApplicationHost.config هم انجام دهید:
<system.webServer>
<security>
<access sslFlags="Ssl, SslNegotiateCert" />
<!-- To require a client cert: -->
<!-- <access sslFlags="Ssl, SslRequireCert" /> -->
</security>
</system.webServer>
o SslNegotiateCert = Accept
o SslRequireCert = Require