开发者

Using a CREATEd ASSEMBLY causes SQL Server to hang permanently

this one's a bit difficult to explain, especially for a non-native english speaker:

I want to use some elliptic-curve-based digital signature functions of the C# implementation of the BouncyCastle crypto library. I wrote a small C# wrapper class that has the following methods:

public static void generateKeyPair(out byte[] private_key, out byte[] public_key)

public static void SignData(byte[] data, byte[] private_key, out byte[] signature)

public static void VerifyData(byte[] signature, byte[] data, byte[] public_key, out bool ok)

which all access the actual BouncyCastle library, BouncyCastle.Crypto.dll. Then I created a "Visual Studio Strong Name Key File" and compiled the wrapper class file with the original BouncyCastle DLL as resource and the just created keyfile.

In SQL Server I did the following:

USE ACS  
EXEC sp_configure 'show advanced options', 1;  
RECONFIGURE WITH OVERRIDE;  
EXEC sp_configure 'xp_cmdshell', 1  
EXEC sp_configure 'CLR enabled', 1;  
RECONFIGURE WITH OVERRIDE;  
ALTER DATABASE ACS SET TRUSTWORTHY OFF  

USE master  
CREATE ASYMMETRIC KEY CLR_Key_Wrapper FROM EXECUTABLE FILE = 'C:\Wrapper.dll'  
CREATE ASYMMETRIC KEY CLR_Key_BouncyCastle FROM EXECUTABLE FILE = 'C:\BouncyCastle.Crypto.dll'  
CREATE LOGIN CLR_Login_Wrapper FROM ASYMMETRIC KEY CLR_Key_Wrapper  
CREATE LOGIN CLR_Login_BouncyCastle FROM ASYMMETRIC KEY CLR开发者_JAVA技巧_Key_BouncyCastle  
GRANT UNSAFE ASSEMBLY TO CLR_Login_Wrapper  
GRANT UNSAFE ASSEMBLY TO CLR_Login_BouncyCastle  

USE ACS  
CREATE ASSEMBLY CLR FROM 'C:\Wrapper.dll' WITH PERMISSION_SET = UNSAFE  
GO

CREATE PROCEDURE Generate_Keypair  
(  
  @BSI_or_NIST  BIT,  
  @Private_Key  VARBINARY(64)  OUTPUT,  
  @Public_Key  VARBINARY(128)  OUTPUT  
)  
AS EXTERNAL NAME CLR.Wrapper.generateKeyPair  
GO  

CREATE PROCEDURE Sign_Data  
(  
  @BSI_or_NIST  BIT,  
  @Data  VARBINARY(8000),  
  @Private_Key  VARBINARY(64),  
  @Signature  VARBINARY(128)  OUTPUT  
)  
AS EXTERNAL NAME CLR.Wrapper.SignData  
GO  

CREATE PROCEDURE Verify_Data  
(  
  @BSI_or_NIST  BIT,  
  @Signature  VARBINARY(128),  
  @Data  VARBINARY(8000),  
  @Public_Key  VARBINARY(128),  
  @OK  BIT  OUTPUT  
)  
AS EXTERNAL NAME CLR.Wrapper.VerifyData  

Now, using the three procedures Generate_Keypair, Sign_Data and Verify_Data in a TSQL batch or via a procedure call from e.g. a .Net client application sometimes works fine, but sometimes it causes the MSSQLSERVER service to go into something like an endless loop while using 100% CPU, especially when I try to install all this on a different machine than my own where I developed the code above (nevertheless, on my own machine it happens too, but less often).

The only thing that can be done is to cancel the executing query and drop the assembly which takes quite long when the CPU is in 100% use.

Can anyone tell me what I have done wrong? Thanks in advance,

Jan


Your stored procedures declare a BIT parameter which the C# methods lack.

To find out whether your assemblies are causing 100% CPU usage, you should log whenever your code executes, and check the generated log file (log4net, BareTail).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜