Ejemplo n.º 1
0
 /// <summary>
 /// Clear content from a secure store.
 /// </summary>
 public void ClearContent()
 {
     if (CommonUtils.IsLinuxPlatform())
     {
         int key = LibKeyUtils.request_key(LinuxKeyType, $"{KeyIdentifier}:{KeyStorageConfig.ClientId}", (int)KeyStorageConfig.LinuxKeyring);
         if (key != -1)
         {
             LibKeyUtils.keyctl("invalidate", key);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get stored content using Linux Kernel Key management API.
        /// see: https://www.kernel.org/doc/html/latest/security/keys/core.html#id2
        /// </summary>
        private byte[] ReadLinuxContent()
        {
            int key = LibKeyUtils.request_key(LinuxKeyType, $"{KeyIdentifier}:{KeyStorageConfig.ClientId}", (int)KeyStorageConfig.LinuxKeyring);

            if (key == -1)
            {
                return(new byte[0]);
            }

            long   contentLength = LibKeyUtils.keyctl_read_alloc(key, out IntPtr contentPtr);
            string content       = Marshal.PtrToStringAuto(contentPtr);

            Marshal.FreeHGlobal(contentPtr);

            if (String.IsNullOrEmpty(content))
            {
                return(new byte[0]);
            }

            return(Convert.FromBase64String(content));
        }