Forum Post: RE: Accessing DLL

  • Thread starter Thread starter Marian Edu
  • Start date Start date
Status
Not open for further replies.
M

Marian Edu

Guest
don't remember the exact details but think we got better results using the interop wrapper ( http://www.pkcs11interop.net) instead of the one from sf.net (http://sf.net/p/pkcs11net/)... using Progress.Lang.*. using Net.Pkcs11Interop.Common.*. using Net.Pkcs11Interop.HighLevelAPI.*. using System.BitConverter. using System.Collections.IEnumerator. using System.Collections.ArrayList. routine-level on error undo, throw. class com.xpower.beid.ReadDataInterop: define private variable moduleFile as character no-undo. define private variable pkcsModule as Pkcs11 no-undo. constructor public ReadDataInterop ( ): this-object('beidpkcs11.dll':u). end constructor. constructor public ReadDataInterop ( moduleFile as character ): this-object:moduleFile = moduleFile. end constructor. destructor public ReadDataInterop ( ): if valid-object(pkcsModule) then pkcsModule:Dispose() no-error. delete object pkcsModule no-error. end destructor. method public character GetSurname(): return GetData('surname':u). end method. method public character GetFirstName(): return GetData('firstnames':u). end method. method public character GetNameInitials(): return GetData('first_letter_of_third_given_name':u). end method. method public character GetNationality(): return GetData('nationality':u). end method. method public character GetCardNumber(): return GetData('card_number':u, true). end method. method public character GetChipNumber(): return GetData('chip_number':u). end method. method public character GetSerialNumber(): return GetData('carddata_serialnumber':u). end method. method public character GetNationalNumber(): return GetData('national_number':u). end method. method public character GetDocumentType(): return GetData('document_type':u). end method. method public character GetAddressStreet(): return GetData('address_street_and_number':u). end method. method public character GetAddressZip(): return GetData('address_zip':u). end method. method public character GetAddressMunicipality(): return GetData('address_municipality':u). end method. method public character GetPhoto(): return GetData('photo_hash':u). end method. method public character GetDateOfBirth(): return GetData('date_of_birth':u). end method. method public character GetPlaceOfBirth(): return GetData('location_of_birth':u). end method. method public character GetValidityDateStart(): return GetData('validity_begin_date':u). end method. method public character GetValidityDateEnd(): return GetData('validity_end_date':u). end method. method public character GetGender(): return GetData('gender':u). end method. method public character GetData(labelName as character): return GetData(labelName, false). end method. method public character GetData(labelName as character, displayBytes as logical): define variable retValue as character no-undo. define variable numItem as integer no-undo. define variable pkcsSession as Session no-undo. define variable classAttribute as ObjectAttribute no-undo. define variable labelAttribute as ObjectAttribute no-undo. define variable readAttribute as ObjectAttribute no-undo. define variable pkcsObject as ObjectHandle no-undo. define variable colEnum as IEnumerator no-undo. define variable attrEnum as IEnumerator no-undo. define variable slotList as 'System.Collections.Generic.List Slot ' no-undo. define variable attrArray as 'System.Collections.Generic.List ObjectAttribute ' no-undo. define variable foundObjects as 'System.Collections.Generic.List ObjectHandle ' no-undo. define variable objAttr as 'System.Collections.Generic.List CKA ' no-undo. if not valid-object(pkcsModule) then pkcsModule = new Pkcs11(moduleFile, true). /* Get the first slot (cardreader) with a token */ slotList = pkcsModule:GetSlotList(true). if slotlist:Count 0 then do: colEnum = slotList:GetEnumerator(). if colEnum:MoveNext() then pkcsSession = cast(colEnum:Current, 'Slot'):OpenSession(true). delete object colEnum. /* Search for objects First, define a search template */ /* 'The label attribute of the objects should equal ...' */ classAttribute = new ObjectAttribute(CKA:CKA_CLASS, CKO:CKO_DATA). labelAttribute = new ObjectAttribute(CKA:CKA_LABEL, labelName). attrArray = new 'System.Collections.Generic.List ObjectAttribute ' (2). attrArray:Add(classAttribute). attrArray:Add(labelAttribute). pkcsSession:FindObjectsInit(attrArray). delete object classAttribute. delete object labelAttribute. delete object attrArray. foundObjects = pkcsSession:FindObjects(1). message 'found objects' skip foundObjects:Count view-as alert-box. colEnum = foundObjects:GetEnumerator(). objAttr = new 'System.Collections.Generic.List CKA ' (2). objAttr:Add(CKA:CKA_LABEL). objAttr:Add(CKA:CKA_VALUE). do while colEnum:MoveNext(): pkcsObject = cast(colEnum:current, 'ObjectHandle':u). if not valid-object(pkcsObject) or pkcsObject:ObjectId eq 0 then do: message 'invalid object' view-as alert-box. next. end. message 'object' skip pkcsObject:ToString() view-as alert-box. attrArray = pkcsSession:GetAttributeValue(pkcsObject, objAttr). message 'attributes list' skip attrArray:count view-as alert-box. if attrArray:count 0 then do: attrEnum = attrArray:GetEnumerator(). do while attrEnum:MoveNext(): readAttribute = cast(attrEnum:Current, 'ObjectAttribute'). message 'attribute' skip readAttribute:GetValueAsString() view-as alert-box. end. delete object attrEnum no-error. return readAttribute:GetValueAsString(). end. delete object pkcsObject no-error. delete object attrArray no-error. end. delete object colEnum. delete object objAttr. delete object foundObjects. pkcsSession:FindObjectsFinal(). end. undo, throw new AppError('Can not read card slot', -1). finally: if valid-object (pkcsSession) then do: if valid-object(pkcsObject) then pkcsSession:DestroyObject(pkcsObject) no-error. pkcsSession:CloseSession() no-error. end. if valid-object (pkcsModule) then pkcsModule:Dispose() no-error. delete object pkcsObject no-error. delete object pkcsSession no-error. delete object pkcsModule no-error. delete object attrArray no-error. delete object attrEnum no-error. delete object colEnum no-error. delete object objAttr no-error. delete object foundObjects no-error. end. end method. end class.

Continue reading...
 
Status
Not open for further replies.
Back
Top