Exemplo n.º 1
0
        public void DeleteObject(Pkcs11ObjectInfo objectInfo)
        {
            if (this._disposed)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            if (objectInfo == null)
            {
                throw new ArgumentNullException("objectInfo");
            }

            using (Session session = _slot.OpenSession(SessionType.ReadWrite))
                session.DestroyObject(objectInfo.ObjectHandle);
        }
Exemplo n.º 2
0
        public void SaveObjectAttributes(Pkcs11ObjectInfo objectInfo, List <ObjectAttribute> objectAttributes)
        {
            if (this._disposed)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            if (objectInfo == null)
            {
                throw new ArgumentNullException("objectInfo");
            }

            if (objectAttributes == null)
            {
                throw new ArgumentNullException("objectAttributes");
            }

            using (Session session = _slot.OpenSession(SessionType.ReadWrite))
                session.SetAttributeValue(objectInfo.ObjectHandle, objectAttributes);
        }
Exemplo n.º 3
0
        public List <ObjectAttribute> LoadObjectAttributes(Pkcs11ObjectInfo objectInfo, List <ulong> attributes)
        {
            if (this._disposed)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            if (objectInfo == null)
            {
                throw new ArgumentNullException("objectInfo");
            }

            if (attributes == null)
            {
                throw new ArgumentNullException("objectAttributes");
            }

            using (Session session = _slot.OpenSession(SessionType.ReadWrite))
                return(session.GetAttributeValue(objectInfo.ObjectHandle, attributes));
        }
Exemplo n.º 4
0
        public Pkcs11Uri(Pkcs11Library pkcs11Library, Pkcs11Slot pkcs11Slot, Pkcs11ObjectInfo pkcs11ObjectInfo)
        {
            if (pkcs11Library != null)
            {
                // Module definition
                this.ModulePath        = pkcs11Library.Info.LibraryPath;
                this.ModulePathPresent = true;
                this.ModuleName        = null;
                this.ModuleNamePresent = false;

                // Library definition
                this.LibraryManufacturer        = pkcs11Library.Info.ManufacturerId;
                this.LibraryManufacturerPresent = false;
                this.LibraryDescription         = pkcs11Library.Info.LibraryDescription;
                this.LibraryDescriptionPresent  = false;
                this.LibraryVersion             = pkcs11Library.Info.LibraryVersion;
                this.LibraryVersionPresent      = false;
            }

            if (pkcs11Slot != null)
            {
                // Slot definition
                this.SlotManufacturer        = pkcs11Slot.SlotInfo.ManufacturerId;
                this.SlotManufacturerPresent = false;
                this.SlotDescription         = pkcs11Slot.SlotInfo.SlotDescription;
                this.SlotDescriptionPresent  = false;
                this.SlotId        = pkcs11Slot.SlotInfo.SlotId;
                this.SlotIdPresent = false;

                if (pkcs11Slot.TokenInfo != null)
                {
                    // Token definition
                    this.Manufacturer        = pkcs11Slot.TokenInfo.ManufacturerId;
                    this.ManufacturerPresent = false;
                    this.Model         = pkcs11Slot.TokenInfo.Model;
                    this.ModelPresent  = false;
                    this.Serial        = pkcs11Slot.TokenInfo.SerialNumber;
                    this.SerialPresent = true;
                    this.Token         = pkcs11Slot.TokenInfo.Label;
                    this.TokenPresent  = true;

                    // Token PIN definition
                    this.PinValue         = null;
                    this.PinSourcePresent = false;
                    this.PinSource        = null;
                    this.PinSourcePresent = false;

                    if (pkcs11ObjectInfo != null)
                    {
                        // Object definition
                        this.Type = (CKO)pkcs11Slot.LoadObjectAttributes(pkcs11ObjectInfo, new List <ulong> {
                            (ulong)CKA.CKA_CLASS
                        })[0].GetValueAsUlong();
                        this.TypePresent = true;

                        this.Object = pkcs11Slot.LoadObjectAttributes(pkcs11ObjectInfo, new List <ulong> {
                            (ulong)CKA.CKA_LABEL
                        })[0].GetValueAsString();
                        this.ObjectPresent = true;

                        if (this.Type == CKO.CKO_DATA)
                        {
                            this.Id        = null;
                            this.IdPresent = false;
                        }
                        else
                        {
                            this.Id = StringUtils.BytesToHexString(pkcs11Slot.LoadObjectAttributes(pkcs11ObjectInfo, new List <ulong> {
                                (ulong)CKA.CKA_ID
                            })[0].GetValueAsByteArray());
                            this.IdPresent = true;
                        }
                    }
                }
            }
        }