Access violation in nhttp

I have a form that calls an agent on webqueryopen. The agent makes some calls to a third-party dll (cryptlib) and updates a field on the documentcontext document. It all works fine, except that the server immediately crashes as soon as the code is done running. Yes, that’s right, my form loads in the browser with the results of the external dll calls, and then the server dies. An excerpt from an NSD log is below.

The problem sounds like one on record about a background agent updating a field of type currency. But, there are no currency fields on this form, and the problem is supposedly fixed in 6.5.3FP1, which is what the server is running.

Now, this is my first time making calls to an external DLL from LS, so it’s possible I’m missing something fundamental. All I did was copy the DLL to the \lotus\domino directory on the Win2003 server.

Any help would be appreciated.

############################################################

FATAL THREAD 56/57 [ nhttp:0554:1498]

FP=0x181dffb8, PC=0x1a272567, SP=0x181dff64, stksize=84

EAX=0x1a300000, EBX=0x00000002, ECX=0x77e48441, EDX=0x00360001

ESI=0x1a2e8bac, EDI=0x00000000, CS=0x0000001b, SS=0x00000023

DS=0x00000023, ES=0x00000023, FS=0x00000038, GS=0x00000000 Flags=0x00010246

Exception code: c0000005 (ACCESS_VIOLATION)

############################################################

[ 1] 0x1a272567 (a25a9a0,0,0,a25a9a0)

[ 2] 0x77e4a990 KERNEL32.FlsSetValue+1913

############################################################

PASS 2 : FATAL THREAD with STACK FRAMES 56/57 [ nhttp:0554:1498]

FP=181dffb8, PC=1a272567, SP=181dff64, stksize=84

Exception code: c0000005 (ACCESS_VIOLATION)

############################################################

---------- Top of the Stack ----------

   # 181dff64  1a2b5350 1a2bbe87 00000002 0a26ca58  |PS+...+.....X.&.|

   # 181dff74  0a25a9a0 00000000 1a2bbe4c 1a2e8bac  |..%.....L.+.....|

   # 181dff84  00000002 77bc91ed 00000000 00000000  |.......w........|

   # 181dff94  00000000 0a25a9a0 c0000005 181dff90  |......%.........|

   # 181dffa4  181dfb8c 181dffdc 77bc4d50 77ba4050  |........PM.wP@.w|

   # 181dffb4  00000000 181dffec 77e4a990 0a25a9a0  |...........w..%.|

[ 1] 0x1a272567 (a25a9a0,0,0,a25a9a0)

   # 181dffb8  181dffec 77e4a990 0a25a9a0 00000000  |.......w..%.....|

   # 181dffc8  00000000 0a25a9a0 00000000 181dffc4  |......%.........|

   # 181dffd8  00dcdb70 ffffffff 77e70abc 77e80110  |p..........w...w|

   # 181dffe8  00000000 00000000 00000000 77bc917e  |............~..w|

[ 2] 0x77e4a990 KERNEL32.FlsSetValue+1913

Subject: access violation in nhttp

Post the prototype of the function you are calling from their doco, and post your LotusScript declaration of that function. Most likely that is the problem.

Subject: RE: access violation in nhttp

Below are the function references from the cryptlib manual. Below that is my code, which I’ve stripped down to the essentials. TIA.==============================================

cryptInit

The cryptInit function is used to initialise cryptlib before use. This function should be called before any other cryptlib function is called.

int cryptInit( void );

Parameters None


cryptCreateContext

The cryptCreateContext function is used to create an encryption context for a given encryption algorithm.

int cryptCreateContext( CRYPT_CONTEXT *cryptContext, const CRYPT_USER cryptUser, const CRYPT_ALGO_TYPE cryptAlgo );

Parameters cryptContext

The address of the encryption context to be created.

cryptUser

The user who is to own the encryption context or CRYPT_UNUSED for the

default, normal user.

cryptAlgo

The encryption algorithm to be used in the context.


cryptSetAttributeString

The cryptSetAttributeString function is used to add text or binary strings or time

values to an object.

int cryptSetAttributeString( const CRYPT_HANDLE cryptObject, const

CRYPT_ATTRIBUTE_TYPE attributeType, const void *value, const int

valueLength );

Parameters cryptObject

The object to which to add the text or binary string or time value.

attributeType

The attribute which is being added.

value

The address of the data being added.

valueLength

The length in bytes of the data being added.


cryptDecrypt

The cryptDecrypt function is used to decrypt or hash data.

int cryptDecrypt( const CRYPT_CONTEXT cryptContext, void *buffer, const int length );

Parameters cryptContext

The encryption context to use to decrypt or hash the data.

buffer

The address of the data to be decrypted or hashed.

length

The length in bytes of the data to be decrypted or hashed.

Remarks Public-key encryption and signature algorithms have special data formatting requirements that need to be taken into account when this function is called. You shouldn’t use this function with these algorithm types, but instead should use the higher-level functions cryptCreateSignature, cryptCheckSignature, cryptExportKey, and cryptImportKey.


cryptDestroyContext

The cryptDestroyContext function is used to destroy an encryption context after use.

This erases all keying and security information used by the context and frees up any memory it uses.

int cryptDestroyContext( const CRYPT_CONTEXT cryptContext );

Parameters cryptContext

The encryption context to be destroyed.

==============================================

DECLARATIONS

Declare Function cryptInit Lib “cl32.dll” () As Integer

Declare Function cryptCreateContext Lib “cl32.dll” (cryptHandle As Long, Byval cryptUser As Integer, Byval cryptAlgo As Integer) As Integer

Declare Function cryptSetAttributeString Lib “cl32.dll” (Byval cryptHandle As Long, Byval cryptAttribute As Integer, Byval cryptValue As String, Byval cryptLength As Integer ) As Integer

Declare Function cryptDecrypt Lib “cl32.dll” (Byval cryptHandle As Long, Byval cryptData As String, Byval cryptLength As Integer ) As Integer

Declare Function cryptDestroyContext Lib “cl32.dll” (Byval cryptHandle As Long ) As Integer

Declare Function cryptEnd Lib “cl32.dll” () As Integer

Const CRYPT_OK = 0

Const CRYPT_UNUSED = -11

Const CRYPT_ALGO_3DES = 2

Const CRYPT_MODE_CBC = 2

Const CRYPT_CTXINFO_ALGO = 1001

Const CRYPT_CTXINFO_MODE = 1002

Const CRYPT_CTXINFO_KEYSIZE = 1005

Const CRYPT_CTXINFO_IVSIZE = 1007

Const CRYPT_CTXINFO_KEY = 1012

Const CRYPT_CTXINFO_IV = 1014


Sub Initialize

Dim nsSession As New NotesSession

Dim ndDoc As NotesDocument

Dim cEncodedString As String

Dim cEncryptedString As String

Dim cDecryptedString As String

Dim cEncodedKey As String

Dim cDecodedKey As String

Dim cEncodedInitVector As String

Dim cDecodedInitVector As String



Set ndDoc = nsSession.DocumentContext

cEncodedString = ndDoc.EncStr( 0 )

cEncodedKey = ndDoc.TDESKey( 0 )

cEncodedInitVector = ndDoc.IV( 0 )



cDecodedKey = Base64Decode( cEncodedKey )

cDecodedInitVector = Base64Decode( cEncodedInitVector )

cEncryptedString = Base64Decode( cEncodedString )



If cDecodedKey = "" Or cDecodedInitVector = "" Or cEncryptedString = "" Then

	ndDoc.rslt = ""

Else

	ndDoc.rslt = TripleDESDecrypt( cEncryptedString, cDecodedKey, cDecodedInitVector )

End If

End Sub


Function TripleDESDecrypt( cEncrypted As String, cryptKey As String, cryptIV As String ) As String

Dim result As Integer

Dim cryptContext As Long

Dim cryptKeyLen As Integer

Dim cryptIVLen As Integer

Dim cryptString As String * 16

Dim cryptStringLen As Integer

Dim cryptAttribute As Integer



result = cryptInit()

result = cryptCreateContext( cryptContext, CRYPT_UNUSED, CRYPT_ALGO_3DES )

cryptKeyLen = Len( cryptKey )

result = cryptSetAttributeString( cryptContext, CRYPT_CTXINFO_KEY, cryptKey, cryptKeyLen )

cryptIVLen = Len( cryptIV )

result = cryptSetAttributeString( cryptContext, CRYPT_CTXINFO_IV, cryptIV, cryptIVLen )

cryptString = cEncrypted

cryptStringLen = Len( cryptString )

result = cryptDecrypt( cryptContext, cryptString, cryptStringLen ) 

TripleDESDecrypt = cryptString

result = cryptDestroyContext( cryptContext )

End Function

Subject: RE: access violation in nhttp

Declarations look fine.

I noticed theres a CryptEnd() function, this supposed to be called when you are finished to match CryptInit()?

Also just a thought, make the fixed length string one char longer than you need in case they need an extra for a null byte. Not so likely tho. e.g cryptStringLen = len(cryptString) - 1.