2016-09-09 14 views
0

私は、私たちの機関プロジェクトにPkcs11Interopライブラリを使用しようとしています。しかし、問題は、私がトークンカードから価値を得ようとすると、 "保護されたメモリを読み書きしようとしましたが、これは他のメモリが壊れていることを示すものです"というエラーがPkcs11Interopから出ています。私は解決策を見つけることができませんでした。お手伝いをしてください、ありがとうございます。PDF Signing with Pkcs11Interop

プロジェクトは、.NET Frameworkを使用して書かれているWindowsフォームアプリケーションである4.5

エラー:system.accessviolationexception {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}

エラースタックトレース:

at Net.Pkcs11Interop.HighLevelAPI40.Session.GetAttributeValue(ObjectHandle objectHandle, List`1 attributes) 
    at Net.Pkcs11Interop.HighLevelAPI40.Session.GetAttributeValue(ObjectHandle objectHandle, List`1 attributes) 
    at EFinImza.Program.Main() in c:\HttpRoot\EFinImza\EFinImza\Program.cs:line 56 
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Threading.ThreadHelper.ThreadStart() 

コードは、このようなものです:

static void Main() 
    { 
     try 
     { 
      string pkcs11Library = @"C:\Windows\System32\akisp11.dll"; 
      using (var pkcs11 = new Net.Pkcs11Interop.HighLevelAPI40.Pkcs11(pkcs11Library, false, false)) 
      { 
       LibraryInfo info = pkcs11.GetInfo(); 
       foreach (Slot slot in pkcs11.GetSlotList(false)) 
       { 
        SlotInfo slotInfo = slot.GetSlotInfo(); 
        if (slotInfo.SlotFlags.TokenPresent) 
        { 
         TokenInfo tokenInfo = slot.GetTokenInfo(); 

         Session session = slot.OpenSession(false); 
         String pin = "*****"; 
         session.Login(CKU.CKU_USER, pin); 

         // get all objects using empty ObjectAttributes list 
         List<ObjectHandle> handles = session.FindAllObjects(new List<ObjectAttribute>()); 
         List<CKA> attrs = new List<CKA>(); 
         attrs.Add(CKA.CKA_LABEL); 

         foreach (ObjectHandle handle in handles) 
         { 
          List<ObjectAttribute> oAttrs = session.GetAttributeValue(handle, attrs); **//Error is getting here** 
         } 

         session.CloseSession(); 
        } 
       } 

       pkcs11.Dispose(); 
      } 

      Application.EnableVisualStyles(); 
      Application.SetCompatibleTextRenderingDefault(false); 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 

    } 

答えて

0

official documentationで推奨されているように、あなたがPkcs11Interopの使用を開始する前に、少なくとも「第2章 - 適用範囲」に慣れる必要があるPKCS#11 v2.20 specificationを、「第6章 - - 一般的な概要」「オブジェクト第10章」 。

あなたのコードは、まずそのタイプ(キー、証明書など)に関係なくすべてのオブジェクトを見つけてから、個々のオブジェクトの属性を読み込もうとします。 はすべてのオブジェクトタイプに対して有効な属性ではありません。これが原因で問題が発生している可能性があります。もちろん、管理されていないPKCS#11ライブラリは、segfaultingの代わりにCKR_ATTRIBUTE_TYPE_INVALIDエラーを返しますが、そのようなコーナーケースをうまく処理できない品質の低いPKCS#11ライブラリが数多くあります。

私は最初だけで、あなたが本当に興味を持っている特定のオブジェクトタイプを検索するためにFindAllObjects()メソッドに渡された検索テンプレートを変更後、仕様の言及の章を読んでする。

ことをお勧めします
関連する問題