asymmetric key creation over network

家住魔仙堡 提交于 2020-01-14 09:26:26

问题


I'm attempting to add an assembly to a database in SQL2008 using an asymmetric key.

We're adding the assembly using a hex string (adding assemblies to servers through sql queries only)

USE [master] 
GO

IF NOT EXISTS (SELECT * from sys.asymmetric_keys where name = 'ManagedAsymmetricKey')
 BEGIN
  CREATE ASYMMETRIC KEY ManagedAsymmetricKey FROM FILE = 'C:\Managed.dll'
  CREATE LOGIN CLRLogin FROM ASYMMETRIC KEY ManagedAsymmetricKey
  GRANT UNSAFE ASSEMBLY TO CLRLogin
 END
GO

USE [$dbName]
GO
CREATE ASSEMBLY [Managed]
AUTHORIZATION [dbo]
FROM 0x4D5A....
WITH PERMISSION_SET = UNSAFE
GO

This will work on a local instance however over the network we receive; The certificate, asymmetric key, or private key file does not exist or has invalid format.

I may be assuming wrongly that I should be adding the key first, should I be adding the assembly then doing something along the lines of CREATE ASYMMETRIC KEY ManagedAsymmetricKey FROM ASSEMBLY [workingDB].[dbo].[Managed] ?


回答1:


You can use the following steps to get it working:

  • run your create assembly statement with SAFE permission_set (even if the assembly needs UNSAFE for execution)
  • create the asymmetric key from the assembly
  • drop your assembly
  • create a login from the asymmetric key
  • grant the login unsafe assembly rights

    CREATE ASSEMBLY [Managed]
    AUTHORIZATION [dbo]
    FROM 0x4D5A....
    WITH PERMISSION_SET = SAFE
    
    CREATE ASYMMETRIC KEY ManagedAsymmetricKey FROM ASSEMBLY [Managed]
    
    DROP ASSEMBLY [Managed]
    
    CREATE LOGIN CLRLogin FROM ASYMMETRIC KEY ManagedAsymmetricKey
    
    GRANT UNSAFE ASSEMBLY TO CLRLogin
    



回答2:


The FROM FILE = is always from the perspective of SQL Server. You would have copy the certificate to a local drive on the database server.



来源:https://stackoverflow.com/questions/9059912/asymmetric-key-creation-over-network

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