Where does one place the Always Encrypted Certificate on an IIS 7.5 web server?

隐身守侯 提交于 2019-12-05 08:21:34

IIS can't recognize the certificate from local user, while creating the certificate in SQL server, by default it's putting in to the local user store, do the following things and make sure the certificate generated under local machine -> current user certificate store

  1. Generate the encrypted columns with default certificates
  2. Undo all encrypted columns in to plain text
  3. Go to the certificate and key from the table security "Your DB - > Tables - > Security -> Always Encrypted Keys" and right click the "CEK_Auto 1" -> Script Column Encryption Key as -> Create to new window, keep this generated script
  4. Delete the CEK_Auto 1
  5. Do the step 3 for "CMK_Auto 1" certificate and delete this as well
  6. in the "CMK_Auto 1" script change the certificate path "CurrentUser" in to "LocalMachine"
  7. you example path will be like this "N'LocalMachine/my/G4452V8ERH035D2557N235B29MWR0SV834263G26'"
  8. execute the CMK_Auto 1 and CEK_Auto 1 script
  9. make sure the certificate generated local machine personal directory
  10. it will work, if not test with IIS express that means still your certificate held in local user personal directory
  11. rest all same make sure the "Column Encryption Setting = Enabled" added in the connection string.

Thanks

John Rajesh J

Always Encrypted requires that the user that is accessing the database to have both the public and private key, which is what it appears to require you to use the account to generate the certificate as they will have this key.

What I usually do is generate the certificate and export the cert with a private key and secure passphrase. Then import the cert with key into the personal store of the account you use to run the app pool. This cannot be a generic integrated account and must be a service account you specify.

run a powershell script as the user:

whoami
COMPUTER\myIISPoolUser
Set-Location -Path cert:\localMachine\my
Import-PfxCertificate –FilePath c:\AlwaysEncrypt.pfx

or use mmc.

whoami
COMPUTER\myIISPoolUser
certmgr.msc

You must also allow the APP Pool user load user profile

Running on IIS Express is different from running on IIS.

when we create Column Master Key (CMK) from SSMS at that time it generates Always Encrypted Certificate based on which location we have set while creating CEK.

For IIS, you have to generate certificate under MyLocalMachine, and then install certificate on hosting server with administrator rights. this will work for you.

You also need to give access of that certificate to IIS User. This can be done by right click on certificate and then click on manage primary key and add IUSR.

To all who also stumbled upon adding the certificate to a certificate storage of a custom app pool user created following other instructions such as ones from the answers on this page.

(posting as an answer since do not have enough reputation to comment)

I was able to do this via the steps below:

  1. Run "Local User and Groups" utility.

    It can be run via Win + R -> lusrmgr.msc or other way, such as searching for "Edit Local User and Groups" in the apps menu. If you have already created a custom app pool user then this step may be familliar to you.

  2. Add the app pool user (let it be CustomAppPoolUser) to the "Administrators" group of the machine. (Actually this step might not be needed, but I used mmc.exe to manage certificates and it was required for me).

  3. Run powershell as CustomAppPoolUser.

    (Search for Powershell in apps menu, right click, "Run as different user". If there is no such line in the context menu, choose "Open file location", then press Shift + right click. If there is still no "Run as different user" line, then it may be another shortcut that you are currently looking at, so choose "Open file location" in it's context menu and repeat previous steps until you see an actual Powershell executable with "Run as different user" in it's context menu (don't forget to press Shift while invoking said menu)).

  4. Run certmgr.msc (or mmc.exe with Current User Certificates snap-in) and import your Always Encrypted Certificate.

  5. Go to IIS manager, ensure that the app pool has set to run as your custom app pool user and that "Load User Profile" setting is set to True.

  6. Go to "Local User and Groups" utility and remove the user from Administrators group.

Also I've restarted after the whole process to be sure that it works as expected, but it may not be needed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!