GithubHelp home page GithubHelp logo

Comments (11)

inorton avatar inorton commented on May 28, 2024

Does ObjectId map to CKA_ID ? If so, your objects might just have no CKA_ID value?

from pkcs11interop.

armando-basile avatar armando-basile commented on May 28, 2024

Hi Ian, i tryed also to set attributes.Add(CKA.CKA_ID) instead LABEL but i had always value empty

from pkcs11interop.

jariq avatar jariq commented on May 28, 2024

Hello Armando. I can see you are using 64-bit Linux that is currently considered to be an unsupported plaform. I will publish my experimental "Linux-x86_64" branch in few hours so you can test with it. I will let you know here when it is ready.

from pkcs11interop.

armando-basile avatar armando-basile commented on May 28, 2024

Great :)

from pkcs11interop.

inorton avatar inorton commented on May 28, 2024

Ooh cool! a few of us at work were hoping for that today :D

from pkcs11interop.

jariq avatar jariq commented on May 28, 2024

I have just committed the first version of Pkcs11Interop that runs on 64bit Linux into Linux-x86_64 branch. It can be easily downloaded as a ZIP archive. Please note that this version is compatible only with Linux x86_64 and it breaks compatibility with all the other platforms including 64bit Windows. Please use Master branch or official releases for other platforms. It is possible that Linux-x86_64 and Master branches will be merged one day but I need to perform more tests before that can happen. Sadly I have only a few PKCS#11 implementations available for testing on this platform and all of them "break standards" in some way.

Armando: Could you please test this version and let me know if it solves your problem?
Ian: Your feedback is also greatly appreciated!

from pkcs11interop.

armando-basile avatar armando-basile commented on May 28, 2024

Hi Jariq, i tested it with follow code and WORK FINE :-) for object find and get attributes value. i'm going to test enc/dec now. Also i had some problem with 64/32 bit arch with my monosim / comex-project and i solved using intptr for DllImport and ulong to reading value https://code.google.com/p/comex-project/source/browse/trunk/comex-base/Src/Readers/PcscReader.cs

Thanks, i post news here after my other tests

using System;
using System.Collections.Generic;
using Net.Pkcs11Interop.HighLevelAPI;
using Net.Pkcs11Interop.Common;

namespace Pkcs11InteropConsole
{
class MainClass
{
private static Dictionary<ulong, Slot> slots = new Dictionary<ulong, Slot>();

    public static void Main(string[] args)
    {
        // init pkcs11 utimaco library
        Pkcs11 pkcs11 = new Pkcs11(@"/usr/lib64/libcs2_pkcs11.so", false);

        // Get list of available slots
        List<Slot> slotList = pkcs11.GetSlotList(false);

        // generate slot dictionary
        foreach (Slot slot in slotList)
        {
            // check for slot id already present
            if (!slots.ContainsKey(slot.SlotId))
            {
                Console.WriteLine("ID: " + slot.SlotId.ToString());
                slots.Add(slot.SlotId, slot);
            }
        }

        ParseSlot(slots[0]);

        pkcs11.Dispose();

    }



    private static void ParseSlot(Slot slotObj)
    {
        // open session
        Session session = slotObj.OpenSession(false);

        // login user
        session.Login(CKU.CKU_USER, "<user pin>");

        // get all token objects
        List<ObjectAttribute> attributesToFind = new List<ObjectAttribute>();
        attributesToFind.Add(new ObjectAttribute(CKA.CKA_TOKEN, true));
        attributesToFind.Add(new ObjectAttribute(CKA.CKA_KEY_TYPE, (ulong)CKK.CKK_DES2));

        List<ObjectHandle> foundObjects = session.FindAllObjects(attributesToFind);

        Console.WriteLine("Objects Founded: " + foundObjects.Count.ToString());

        // set CKA_LABEL to obtain
        List<CKA> attributes = new List<CKA>();
        attributes.Add(CKA.CKA_LABEL);
        attributes.Add(CKA.CKA_KEY_TYPE);
        attributes.Add(CKA.CKA_MODIFIABLE);
        attributes.Add(CKA.CKA_SENSITIVE);
        attributes.Add(CKA.CKA_EXTRACTABLE);
        attributes.Add(CKA.CKA_CHECK_VALUE);

        // loop for each object founded into selected slot
        foreach (ObjectHandle oh in foundObjects)
        {
            if (oh.ObjectId != 0)
            {
                Console.WriteLine("\r\nObjectHandle: " + oh.ObjectId.ToString("X8"));                        
                List<ObjectAttribute> oAttr = session.GetAttributeValue(oh, attributes);
                Console.WriteLine("  LABEL       : " + oAttr[0].GetValueAsString());
                Console.WriteLine("  KEY_TYPE    : " + oAttr[1].GetValueAsUint().ToString());
                Console.WriteLine("  MODIFIABLE  : " + oAttr[2].GetValueAsBool().ToString());
                Console.WriteLine("  SENSITIVE   : " + oAttr[3].GetValueAsBool().ToString());
                Console.WriteLine("  EXTRACTABLE : " + oAttr[4].GetValueAsBool().ToString());
                Console.WriteLine("  CHECK_VALUE : " + BitConverter.ToString((oAttr[5].GetValueAsByteArray())));

            }
        }

        // logout close and dispose pkcs11 instance
        session.Logout();
        session.CloseSession();

    }
}

}

from pkcs11interop.

inorton avatar inorton commented on May 28, 2024

On linux, CK_ULONG is the same size as a pointer ( UIntPtr )
On windows, CK_ULONG is always 32bits

I have a half baked approach to doing this using generics but I've not tried it yet.

from pkcs11interop.

armando-basile avatar armando-basile commented on May 28, 2024

Hi all,
i tryed also enc/dec with founded secret key object and it work fine :)

thanks

from pkcs11interop.

jariq avatar jariq commented on May 28, 2024

Thanks for letting me know.

from pkcs11interop.

jariq avatar jariq commented on May 28, 2024

FYI: Pkcs11Interop 2.0 has just been released. It supports platforms with 32-bit C 'long' type (Win32, Win64 and Linux32) and also platforms with 64-bit C 'long' type (Linux64).

from pkcs11interop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.