Skip to content
Merged
7 changes: 6 additions & 1 deletion src/Files.App/Data/Enums/PropertiesNavigationViewItemType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ public enum PropertiesNavigationViewItemType
/// Shortcut page type
/// </summary>
Shortcut,
}

/// <summary>
/// Signatures page type
/// </summary>
Signatures,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,15 @@ public static ObservableCollection<NavigationViewItemButtonStyleItem> Initialize
ItemType = PropertiesNavigationViewItemType.Compatibility,
ThemedIconStyle = (Style)Application.Current.Resources["App.ThemedIcons.Properties.Compatability"],
};
var signaturesItem = new NavigationViewItemButtonStyleItem()
{
Name = Strings.Signatures.GetLocalizedResource(),
ItemType = PropertiesNavigationViewItemType.Signatures,
ThemedIconStyle = (Style)Application.Current.Resources["App.ThemedIcons.Properties.Signatures"],
};

PropertiesNavigationViewItems.Add(generalItem);
PropertiesNavigationViewItems.Add(signaturesItem);
PropertiesNavigationViewItems.Add(securityItem);
PropertiesNavigationViewItems.Add(hashesItem);
PropertiesNavigationViewItems.Add(shortcutItem);
Expand All @@ -89,6 +96,7 @@ public static ObservableCollection<NavigationViewItemButtonStyleItem> Initialize
PropertiesNavigationViewItems.Remove(securityItem);
PropertiesNavigationViewItems.Remove(customizationItem);
PropertiesNavigationViewItems.Remove(hashesItem);
PropertiesNavigationViewItems.Remove(signaturesItem);
}
else if (item is ListedItem listedItem)
{
Expand All @@ -107,7 +115,10 @@ public static ObservableCollection<NavigationViewItemButtonStyleItem> Initialize
PropertiesNavigationViewItems.Remove(securityItem);

if (!hashItemEnabled)
{
PropertiesNavigationViewItems.Remove(hashesItem);
PropertiesNavigationViewItems.Remove(signaturesItem);
}

if (!isShortcut)
PropertiesNavigationViewItems.Remove(shortcutItem);
Expand All @@ -132,6 +143,7 @@ public static ObservableCollection<NavigationViewItemButtonStyleItem> Initialize
PropertiesNavigationViewItems.Remove(detailsItem);
PropertiesNavigationViewItems.Remove(customizationItem);
PropertiesNavigationViewItems.Remove(compatibilityItem);
PropertiesNavigationViewItems.Remove(signaturesItem);
}

return PropertiesNavigationViewItems;
Expand Down
18 changes: 18 additions & 0 deletions src/Files.App/Data/Items/CertNodeInfoItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

namespace Files.App.Data.Items
{
public class CertNodeInfoItem
{
public string IssuedTo { get; set; } = string.Empty;

public string IssuedBy { get; set; } = string.Empty;

public string Version { get; set; } = string.Empty;

public string ValidFrom { get; set; } = string.Empty;

public string ValidTo { get; set; } = string.Empty;
}
}
91 changes: 91 additions & 0 deletions src/Files.App/Data/Models/SignatureInfoItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.Utils.Signatures;
using System.Windows.Input;

namespace Files.App.Data.Models
{
public sealed partial class SignatureInfoItem : ObservableObject
{
private readonly string _fileName;

private readonly IntPtr _hwndParent;

private readonly int _index;

private string _Version = string.Empty;
public string Version
{
get => _Version;
set => SetProperty(ref _Version, value);
}

private string _IssuedBy = string.Empty;
public string IssuedBy
{
get => _IssuedBy;
set => SetProperty(ref _IssuedBy, value);
}

private string _IssuedTo = string.Empty;
public string IssuedTo
{
get => _IssuedTo;
set => SetProperty(ref _IssuedTo, value);
}

private string _ValidFromTimestamp = string.Empty;
public string ValidFromTimestamp
{
get => _ValidFromTimestamp;
set => SetProperty(ref _ValidFromTimestamp, value);
}

private string _ValidToTimestamp = string.Empty;
public string ValidToTimestamp
{
get => _ValidToTimestamp;
set => SetProperty(ref _ValidToTimestamp, value);
}

private string _VerifiedTimestamp = string.Empty;
public string VerifiedTimestamp
{
get => _VerifiedTimestamp;
set => SetProperty(ref _VerifiedTimestamp, value);
}

private bool _Verified = false;
public bool Verified
{
get => _Verified;
set
{
if (SetProperty(ref _Verified, value))
OnPropertyChanged(nameof(Glyph));
}
}

public List<CertNodeInfoItem> SignChain { get; }

public string Glyph => Verified ? "\uE930" : "\uEA39";

public ICommand OpenDetailsCommand { get; }

public SignatureInfoItem(string fileName, int index, IntPtr hWnd, List<CertNodeInfoItem> chain)
{
_fileName = fileName;
_hwndParent = hWnd;
_index = index;
SignChain = chain ?? new List<CertNodeInfoItem>();
OpenDetailsCommand = new AsyncRelayCommand(DoOpenDetails);
}

private Task DoOpenDetails()
{
DigitalSignaturesUtil.DisplaySignerInfoDialog(_fileName, _hwndParent, _index);
return Task.CompletedTask;
}
}
}
4 changes: 2 additions & 2 deletions src/Files.App/Helpers/Win32/Win32Helper.Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -902,13 +902,13 @@ public static SafeFileHandle OpenFileForRead(string filePath, bool readWrite = f
(uint)FILE_ACCESS_RIGHTS.FILE_GENERIC_READ | (uint)(readWrite ? FILE_ACCESS_RIGHTS.FILE_GENERIC_WRITE : 0u), (uint)(Win32PInvoke.FILE_SHARE_READ | (readWrite ? 0 : Win32PInvoke.FILE_SHARE_WRITE)), IntPtr.Zero, Win32PInvoke.OPEN_EXISTING, (uint)Win32PInvoke.File_Attributes.BackupSemantics | flags, IntPtr.Zero), true);
}

public static bool GetFileDateModified(string filePath, out FILETIME dateModified)
public static bool GetFileDateModified(string filePath, out System.Runtime.InteropServices.ComTypes.FILETIME dateModified)
{
using var hFile = new SafeFileHandle(Win32PInvoke.CreateFileFromApp(filePath, (uint)FILE_ACCESS_RIGHTS.FILE_GENERIC_READ, Win32PInvoke.FILE_SHARE_READ, IntPtr.Zero, Win32PInvoke.OPEN_EXISTING, (uint)Win32PInvoke.File_Attributes.BackupSemantics, IntPtr.Zero), true);
return Win32PInvoke.GetFileTime(hFile.DangerousGetHandle(), out _, out _, out dateModified);
}

public static bool SetFileDateModified(string filePath, FILETIME dateModified)
public static bool SetFileDateModified(string filePath, System.Runtime.InteropServices.ComTypes.FILETIME dateModified)
{
using var hFile = new SafeFileHandle(Win32PInvoke.CreateFileFromApp(filePath, (uint)FILE_ACCESS_RIGHTS.FILE_WRITE_ATTRIBUTES, 0, IntPtr.Zero, Win32PInvoke.OPEN_EXISTING, (uint)Win32PInvoke.File_Attributes.BackupSemantics, IntPtr.Zero), true);
return Win32PInvoke.SetFileTime(hFile.DangerousGetHandle(), new(), new(), dateModified);
Expand Down
155 changes: 145 additions & 10 deletions src/Files.App/Helpers/Win32/Win32PInvoke.Methods.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.
// Copyright (c) Files Community
// Licensed under the MIT License.

using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using Windows.Win32.Foundation;
using Windows.Win32.System.Com;
Expand Down Expand Up @@ -232,17 +231,17 @@ public static extern bool WriteFileEx(
[DllImport("api-ms-win-core-file-l1-2-1.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public static extern bool GetFileTime(
[In] IntPtr hFile,
out FILETIME lpCreationTime,
out FILETIME lpLastAccessTime,
out FILETIME lpLastWriteTime
out System.Runtime.InteropServices.ComTypes.FILETIME lpCreationTime,
out System.Runtime.InteropServices.ComTypes.FILETIME lpLastAccessTime,
out System.Runtime.InteropServices.ComTypes.FILETIME lpLastWriteTime
);

[DllImport("api-ms-win-core-file-l1-2-1.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public static extern bool SetFileTime(
[In] IntPtr hFile,
in FILETIME lpCreationTime,
in FILETIME lpLastAccessTime,
in FILETIME lpLastWriteTime
in System.Runtime.InteropServices.ComTypes.FILETIME lpCreationTime,
in System.Runtime.InteropServices.ComTypes.FILETIME lpLastAccessTime,
in System.Runtime.InteropServices.ComTypes.FILETIME lpLastWriteTime
);

[DllImport("api-ms-win-core-file-l2-1-1.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
Expand Down Expand Up @@ -288,7 +287,7 @@ IntPtr hFindFile

[DllImport("api-ms-win-core-timezone-l1-1-0.dll", SetLastError = true)]
public static extern bool FileTimeToSystemTime(
ref FILETIME lpFileTime,
ref System.Runtime.InteropServices.ComTypes.FILETIME lpFileTime,
out SYSTEMTIME lpSystemTime
);

Expand Down Expand Up @@ -347,5 +346,141 @@ public static extern int SHGetKnownFolderPath(
IntPtr hToken,
out IntPtr pszPath
);

// crypt32.dll
[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern uint CertGetNameStringA(
IntPtr pCertContext,
uint dwType,
uint dwFlags,
IntPtr pvTypePara,
IntPtr pszNameString,
uint cchNameString
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CertFreeCertificateContext(
IntPtr pCertContext
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CryptMsgGetParam(
IntPtr hCryptMsg,
uint dwParamType,
uint dwIndex,
IntPtr pParam,
ref uint dwOutSize
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CryptMsgClose(
IntPtr hCryptMsg
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr CryptMsgOpenToDecode(
uint dwMsgEncodingType,
uint dwFlags,
uint dwMsgType,
IntPtr hCryptProv,
IntPtr pRecipientInfo,
IntPtr pStreamInfo
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CryptMsgUpdate(
IntPtr hCryptMsg,
IntPtr pbData,
uint cbDatam,
bool fFinal
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr CertOpenStore(
IntPtr lpszStoreProvider,
uint dwEncodingType,
IntPtr hCryptProv,
uint dwFlags,
IntPtr pvPara
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CryptDecodeObject(
uint dwCertEncodingType,
IntPtr lpszStructType,
IntPtr pbEncoded,
uint cbEncoded,
uint dwFlags,
IntPtr pvStructInfo,
ref uint pcbStructInfo
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr CertFindCertificateInStore(
IntPtr hCertStore,
uint dwCertEncodingType,
uint dwFindFlags,
uint dwFindType,
IntPtr pvFindPara,
IntPtr pPrevCertContext
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CertComparePublicKeyInfo(
uint dwCertEncodingType,
IntPtr pPublicKey1,
IntPtr pPublicKey2
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CryptQueryObject(
uint dwObjectType,
IntPtr pvObject,
uint dwExpectedContentTypeFlags,
uint dwExpectedFormatTypeFlags,
uint dwFlags,
ref uint pdwMsgAndCertEncodingType,
ref uint pdwContentType,
ref uint pdwFormatType,
ref IntPtr phCertStore,
ref IntPtr phMsg,
ref IntPtr ppvContext
);

[DllImport("crypt32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CertCloseStore(
IntPtr hCertStore,
uint dwFlags
);

[DllImport("wintrust.dll")]
public static extern long WinVerifyTrust(
IntPtr hwnd,
IntPtr pgActionID,
IntPtr pWVTData
);

// kernel32.dll
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool FileTimeToSystemTime(
IntPtr lpFileTime,
IntPtr lpSystemTime
);

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool FileTimeToLocalFileTime(
IntPtr lpFileTime,
IntPtr lpLocalFileTime
);

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool SystemTimeToFileTime(
IntPtr lpSystemTime,
IntPtr lpFileTime
);

// cryptui.dll
[DllImport("cryptui.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool CryptUIDlgViewSignerInfo(IntPtr pViewInfo);
}
}
Loading
Loading