Шифрование конфигурации
Пока строка подключения к SQL выглядит так, это никого не смущает. Но такую строку подключения выложить на Web-сервер никак невозможно. Что же делать?
Для этого в состав ASP2 включена утилита AspNet_RegIIS, через которую осуществляется доступ к АПИ, шифрующий строки подключения и другие параметры WEB.CONFIG:
-- CONFIGURATION ENCRYPTION OPTIONS --
-pe section Encrypt the configuration section. Optional arguments:
[-prov provider] Use this provider to encrypt.
[-app virtual-path] Encrypt at this virtual path. Virtual
path must begin with a forward slash. If it is '/', then it
refers to the root of the site. If -app is not specified,
the root web.config will be encrypted.
[-site site-name-or-ID] The site of the virtual path
specified in -app. If not specified, the default web site
will be used.
[-location sub-path] Location sub path.
[-pkm] Encrypt/decrypt the machine.config instead of
web.config.
-pd section Decrypt the configuration section. Optional arguments:
[-app virtual-path] Decrypt at this virtual path. Virtual
path must begin with a forward slash. If it is '/', then it
refers to the root of the site. If -app is not specified,
the root web.config will be decrypted.
[-site site-name-or-ID] The site of the virtual path
specified in -app. If not specified, the default web site
will be used.
[-location sub-path] Location sub path.
[-pkm] Encrypt/decrypt the machine.config instead of
web.config.
-pef section web-app-physical-dir
Encrypt the configuration section. Optional arguments:
[-prov provider] Use this provider to encrypt.
-pdf section web-app-physical-dir
Decrypt the configuration section.
-pc container Create an RSA keypair in ContainerName. Optional arguments:
[-size key-size] Key-size. Default is 1024.
[-pku] User container instead of machine container.
[-exp] Make the private keys exportable.
[-csp provider] Csp Provider to use.
-pz container Delete the ContainerName. Optional arguments:
[-pku] User container instead of machine container.
-pi container file Import an RSA keypair from the Xml file. Optional
arguments:
[-pku] User container instead of machine container.
[-exp] Create exportable keys.
[-csp provider] Csp Provider to use.
-px container file Export an RSA keypair to the Xml file. Optional arguments:
[-pku] User container instead of machine container.
[-pri] Include private keys.
[-csp provider] Csp Provider to use.
-pa container account
Add access for the account to the container. Arguments:
[-pku] User container instead of machine container.
[-csp provider] Csp Provider to use.
[-full] Add full access (default is Read access).
-pr container account
Remove access for the account from the container.
Arguments:
[-pku] User container instead of machine container.
[-csp provider] Csp Provider to use.
В проинципе те же действия можно выполнить и самому, обратившись к классам шифрования:

Как мы видим, мы получаем прекрасную криптованную секцию (причем совершенно разную каждый раз), которую мы можем включить в конфигурационый файл.
То же действие утилитой выполняется или с параметром -PE (с указанием имени IIS-приложения), или с параметром -PEF (с указанием месторасположения конфигурационного файла.

Единственная фишка теперь в том, чтобы учетной записи ASP.NET (конкретно NETWORK SERVICE) дать доступ к ключам шифрования (RSA key container) , иначе нас ждет разочарование:

Именно для этого и предназначены все остальные ключи шифрования в вышеуказанной утилите.

Кстати, не забудьте рестартануть IIS - его заглючивает после этого действия. В случае необходимости и сами ключи для RSA провайдера могут быть заменены. Для этого предназначен ключ <machineKey в разделе <system.web>. Но это уже более глубокие подробности, вникать в которые стоит при одном-единственном Web.config на нескольких серверах.
AspNetClassic context:
NetLearning context:
)
|
|