Sfoglia il codice sorgente

compdfkit(win) - 证书信息 -> 信任

weixiangjie 1 anno fa
parent
commit
0f854b4ff1

+ 2 - 0
Demo/Examples/Compdfkit_Tools/DigitalSignature/CPDFSignatureListControl/CPDFSignatureListControl.xaml.cs

@@ -43,6 +43,8 @@ namespace Compdfkit_Tools.DigitalSignature.CPDFSignatureListControl
             deleteMenu.Header = "Delete";
             deleteMenu.Click += DeleteMenu_Click;
             popContextMenu.Items.Add(deleteMenu);
+            
+            CPDFSignature.SignCertTrustedFolder = @"TrustedFolder\";
         }
         
         private void ViewSignatureDetailsMenu_Click(object sender, RoutedEventArgs e)

+ 8 - 1
Demo/Examples/Compdfkit_Tools/DigitalSignature/ViewCertificationControl/CertificateDetailControl.xaml.cs

@@ -158,6 +158,7 @@ namespace Compdfkit_Tools.PDFControl
             string crlDistributionPointText = string.Empty;
             string authorityInfoAccessText = string.Empty;
             string keyUsageText = string.Empty;
+            var usageList = DictionaryValueConverter.GetUsage(certificate);
 
             foreach (var policy in certificate.CertificatePolicies)
             {
@@ -174,6 +175,12 @@ namespace Compdfkit_Tools.PDFControl
                 crlDistributionPointText += crl + "\n";
             }
             
+            for(int i = 0; i < usageList.Count; i++)
+            {
+                keyUsageText += usageList[i];
+                keyUsageText += (i == usageList.Count - 1) ? "" : ", ";
+            }
+            
             Version = certificate.Version.ToString();
             Algorithm = certificate.SignatureAlgorithmType.ToString().Substring(26) + "(" + certificate.SignatureAlgorithmOID + ")";
             Subject = certificate.Subject;
@@ -188,7 +195,7 @@ namespace Compdfkit_Tools.PDFControl
             AuthorityKeyIdentifier = certificate.AuthorityKeyIdentifier;
             SubjectKeyIdentifier = certificate.SubjectKeyIdentifier;
             BasicConstraints = certificate.BasicConstraints;
-            //KeyUsage = certificate.KeyUsage;
+            KeyUsage = keyUsageText;
             PublicKey = certificate.PublicKey;
             SHA1Digest = certificate.SHA1Digest;
             MD5Digest = certificate.MD5Digest;

+ 3 - 3
Demo/Examples/Compdfkit_Tools/DigitalSignature/ViewCertificationControl/CertificateInfoControl.xaml

@@ -20,7 +20,7 @@
                 Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Grid}}}">
             <TabItem Header="Abstract" Style="{StaticResource LineTabItemStyle}">
                 <Grid>
-                    <local:SummaryControl x:Name="SummaryControl" Height="150" VerticalAlignment="Top"></local:SummaryControl>
+                    <local:SummaryControl x:Name="SummaryControl" Height="160" VerticalAlignment="Top"></local:SummaryControl>
                 </Grid>
             </TabItem>
             <TabItem Header="Detailed Info"  Style="{StaticResource LineTabItemStyle}">
@@ -31,10 +31,10 @@
             <TabItem Header="Confidence"  Style="{StaticResource LineTabItemStyle}">
                 <Grid>
                     <Grid.RowDefinitions>
-                        <RowDefinition Height="100"></RowDefinition>
+                        <RowDefinition Height="150"></RowDefinition>
                         <RowDefinition></RowDefinition>
                     </Grid.RowDefinitions>
-                    <local:ConfidenceControl></local:ConfidenceControl>
+                    <local:ConfidenceControl x:Name="ConfidenceControl"></local:ConfidenceControl>
                 </Grid>
             </TabItem>
         </TabControl>

+ 1 - 0
Demo/Examples/Compdfkit_Tools/DigitalSignature/ViewCertificationControl/CertificateInfoControl.xaml.cs

@@ -55,6 +55,7 @@ namespace Compdfkit_Tools.PDFControl {
         {
             SummaryControl.LoadSummaryInfo(certificate);
             CertificateDetailControl.LoadDetailInfo(certificate);
+            ConfidenceControl.LoadConfidenceInfo(certificate);
         }
     }
 }

+ 35 - 17
Demo/Examples/Compdfkit_Tools/DigitalSignature/ViewCertificationControl/ConfidenceControl.xaml

@@ -5,39 +5,57 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl"
              mc:Ignorable="d" 
-             d:DesignHeight="100" d:DesignWidth="600">
+             d:DesignHeight="150" d:DesignWidth="600" x:Name="UserControl1">
+    
+    <UserControl.Resources>
+        <ResourceDictionary>
+            <Viewbox x:Key="ValidPath" Width="20" Height="20" x:Shared="False">
+                <Canvas Width="20" Height="20">
+                    <Path Data="M10 17.5C14.1421 17.5 17.5 14.1421 17.5 10C17.5 5.85786 14.1421 2.5 10 2.5C5.85786 2.5 2.5 5.85786 2.5 10C2.5 14.1421 5.85786 17.5 10 17.5ZM9.74283 12.9801L13.9095 7.98014L12.7572 7.01986L9.11627 11.3889L7.197 9.46967L6.13634 10.5303L8.63634 13.0303L9.21707 13.6111L9.74283 12.9801Z" 
+                          Fill="#3CCD75"/>
+                </Canvas>
+            </Viewbox>
+            
+            <Viewbox x:Key="InvalidPath" Width="20" Height="20" x:Shared="False">
+                <Canvas Width="20" Height="20">
+                    <Path Data="M17.5 10C17.5 14.1421 14.1421 17.5 10 17.5C5.85786 17.5 2.5 14.1421 2.5 10C2.5 5.85786 5.85786 2.5 10 2.5C14.1421 2.5 17.5 5.85786 17.5 10Z" 
+                          Fill="#FF6666"/>
+                    <Path Data="M12 8L8 12" Stroke="White" StrokeThickness="1.5" StrokeLineJoin="Round"/>
+                    <Path Data="M8 8L12 12" Stroke="White" StrokeThickness="1.5" StrokeLineJoin="Round"/>
+                </Canvas>
+            </Viewbox>
+            <local:ConfidenceStatusToPathConverter x:Key="ConfidenceStatusToPathConverter" />
+        </ResourceDictionary>
+    </UserControl.Resources>
+    
     <Grid>
         <Grid.RowDefinitions>
-            
+            <RowDefinition Height="112"></RowDefinition>
+            <RowDefinition Height="auto"></RowDefinition>
         </Grid.RowDefinitions>
         <Grid Background="#ffffff"  Margin="20,0,0,0"  Panel.ZIndex="1" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top">
-            <TextBlock Text="This certificate is trusted for" FontWeight="Bold" FontSize="16"></TextBlock>
+            <TextBlock Text="This Certificate Is Trusted to" FontWeight="Bold" FontSize="16"></TextBlock>
         </Grid>
         <Border Margin="12" BorderBrush="#33000000" BorderThickness="1" >
             <StackPanel VerticalAlignment="Center" Margin="20,0,0,0">
 
                 <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
-                    <Viewbox Width="20" Height="20" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
-                        <Canvas Width="20" Height="20">
-                            <Path Data="M10 17.5C14.1421 17.5 17.5 14.1421 17.5 10C17.5 5.85786 14.1421 2.5 10 2.5C5.85786 2.5 2.5 5.85786 2.5 10C2.5 14.1421 5.85786 17.5 10 17.5ZM9.74283 12.9801L13.9095 7.98014L12.7572 7.01986L9.11627 11.3889L7.197 9.46967L6.13634 10.5303L8.63634 13.0303L9.21707 13.6111L9.74283 12.9801Z" 
-              Fill="#3CCD75"/>
-                        </Canvas>
-                    </Viewbox>
+                    <Canvas Height="20" Width="20">
+                        <ContentControl Content="{Binding IsTrusted, Converter={StaticResource ConfidenceStatusToPathConverter}}" />
+                    </Canvas>
+                    <TextBlock Text="Sign document or data" VerticalAlignment="Center"></TextBlock>
                 </StackPanel>
 
                 <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
-                    <Viewbox Width="20" Height="20" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
-                        <Canvas Width="20" Height="20">
-                            <Path Data="M17.5 10C17.5 14.1421 14.1421 17.5 10 17.5C5.85786 17.5 2.5 14.1421 2.5 10C2.5 5.85786 5.85786 2.5 10 2.5C14.1421 2.5 17.5 5.85786 17.5 10Z" 
-              Fill="#FF6666"/>
-                            <Path Data="M12 8L8 12" Stroke="White" StrokeThickness="1.5" StrokeLineJoin="Round"/>
-                            <Path Data="M8 8L12 12" Stroke="White" StrokeThickness="1.5" StrokeLineJoin="Round"/>
-                        </Canvas>
-                    </Viewbox>
+                    <Canvas Height="20" Width="20">
+                        <ContentControl Content="{Binding IsTrusted, Converter={StaticResource ConfidenceStatusToPathConverter}}" />
+                    </Canvas>
+                    <TextBlock Text="Certify document" VerticalAlignment="Center"></TextBlock>
                 </StackPanel>
 
 
             </StackPanel>
         </Border>
+        <Button Grid.Row="1" Content="Click to add a creditable certificate" Click="ButtonBase_OnClick" Height="32" Width="230" HorizontalAlignment="Right" Margin="0,0,12,12"></Button>
     </Grid>
 </UserControl>

+ 80 - 1
Demo/Examples/Compdfkit_Tools/DigitalSignature/ViewCertificationControl/ConfidenceControl.xaml.cs

@@ -1,6 +1,9 @@
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
+using System.Globalization;
 using System.Linq;
+using System.Runtime.CompilerServices;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
@@ -12,17 +15,93 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using Compdfkit_Tools.DigitalSignature.CPDFSignatureListControl;
+using Compdfkit_Tools.Properties;
+using ComPDFKit.DigitalSign;
 
 namespace Compdfkit_Tools.PDFControl
 {
     /// <summary>
     /// ConfidenceControl.xaml 的交互逻辑
     /// </summary>
-    public partial class ConfidenceControl : UserControl
+    public partial class ConfidenceControl : UserControl, INotifyPropertyChanged
     {
+        public static ResourceDictionary ResourceDictionary { get; set; }
+        private bool isTrusted;
+        private CPDFSignatureCertificate cpdfCertificate;
+        public bool IsTrusted
+        {
+            get => isTrusted;
+            set => UpdateProper(ref isTrusted, value);
+        }
+        
         public ConfidenceControl()
         {
             InitializeComponent();
+            DataContext = this;
+            ResourceDictionary = this.Resources;
+        }
+        
+        public void LoadConfidenceInfo(CPDFSignatureCertificate certificate)
+        {
+            cpdfCertificate = certificate;
+            VerifyCertificate();
+        }
+        
+        public void VerifyCertificate()
+        {
+            if (cpdfCertificate != null)
+            {
+                cpdfCertificate.CheckCertificateIsTrusted();
+                IsTrusted = cpdfCertificate.IsTrusted;
+            }
+        }
+        
+        public event PropertyChangedEventHandler PropertyChanged;
+        protected void UpdateProper<T>(ref T properValue,
+            T newValue,
+            [CallerMemberName] string properName = "")
+        {
+            if (object.Equals(properValue, newValue))
+                return;
+
+            properValue = newValue;
+            OnPropertyChanged(properName);
+        }
+
+        protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        
+        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
+        {
+            cpdfCertificate.AddToTrustedCertificates();
+            VerifyCertificate();
+        }
+    }
+    
+    public class ConfidenceStatusToPathConverter : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            ResourceDictionary resourceDictionary = ConfidenceControl.ResourceDictionary;
+            if (value is bool isTrusted)
+            {
+                if (isTrusted)
+                {
+                    return resourceDictionary["ValidPath"];
+                    
+                }
+                else
+                {
+                    return resourceDictionary["InvalidPath"];
+                }
+            }
+            return null;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            return null;
         }
     }
 }

+ 1 - 1
Demo/Examples/Compdfkit_Tools/DigitalSignature/ViewCertificationControl/SummaryControl.xaml

@@ -35,7 +35,7 @@
 
                     <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
                         <TextBlock Text="Intended Usage: " Foreground="Black"  FontSize="14"></TextBlock>
-                        <TextBlock Text="{Binding AnticipatedUse}" Foreground="#666"  FontSize="14"></TextBlock>
+                        <TextBlock Text="{Binding IntendedUsage}" Foreground="#666"  FontSize="14"></TextBlock>
                     </StackPanel>
                 </StackPanel>
             </ScrollViewer>

+ 14 - 5
Demo/Examples/Compdfkit_Tools/DigitalSignature/ViewCertificationControl/SummaryControl.xaml.cs

@@ -51,11 +51,11 @@ namespace Compdfkit_Tools.PDFControl
             set => UpdateProper(ref validityTo, value);
         }
         
-        private string anticipatedUse;
-        public string AnticipatedUse
+        private string intendedUsage;
+        public string IntendedUsage
         {
-            get => anticipatedUse;
-            set => UpdateProper(ref anticipatedUse, value);
+            get => intendedUsage;
+            set => UpdateProper(ref intendedUsage, value);
         }
 
         public SummaryControl()
@@ -69,6 +69,9 @@ namespace Compdfkit_Tools.PDFControl
             string awardText;
             string grantorText = DictionaryValueConverter.GetGrantorFormDictionary(certificate.SubjectDict);
             string email = DictionaryValueConverter.GetEmailFormDictionary(certificate.SubjectDict);
+            var usageList = DictionaryValueConverter.GetUsage(certificate);
+            string keyUsageText = "";
+            
             if(email != null)
             {
                 awardText = grantorText + " <" + email + ">";
@@ -77,10 +80,16 @@ namespace Compdfkit_Tools.PDFControl
             {
                 awardText = grantorText;
             }
+            
+            for(int i = 0; i < usageList.Count; i++)
+            {
+                keyUsageText += usageList[i];
+                keyUsageText += (i == usageList.Count - 1) ? "" : ", ";
+            }
             Award = awardText;
             Grantor = grantorText;
             ValidityFrom = certificate.ValidityEnds;
-            //SummaryInfo.AnticipatedUse = certificate.AnticipatedUse;
+            IntendedUsage = keyUsageText;
         }
         
         public event PropertyChangedEventHandler PropertyChanged;

+ 44 - 0
Demo/Examples/Compdfkit_Tools/DigitalSignature/ViewCertificationControl/ViewCertificateDialog.xaml.cs

@@ -81,5 +81,49 @@ namespace Compdfkit_Tools.PDFControl
             dictionary.TryGetValue("emailAddress", out email);
             return email;
         }
+
+        public static List<string> GetUsage(CPDFSignatureCertificate certificate)
+        {
+            int usage = certificate.KeyUsage;
+            List<string> usageList = new List<string>();
+            if ((usage & 1 << 0) != 0)
+            {
+                usageList.Add("Encipher Only");
+            }
+            if ((usage & 1 << 1) != 0)
+            {
+                usageList.Add("CRL Signature");
+            }
+            if ((usage & 1 << 2) != 0)
+            {
+                usageList.Add("Certificate Signature");
+            }
+            if ((usage & 1 << 3) != 0)
+            {
+                usageList.Add("Key Agreement");
+            }
+            if ((usage & 1 << 4) != 0)
+            {
+                usageList.Add("Data Encipherment");
+            }
+            if ((usage & 1 << 5) != 0)
+            {
+                usageList.Add("Key Encipherment");
+            }
+            if ((usage & 1 << 6) != 0)
+            {
+                usageList.Add("Non Repudiation");
+            }
+            if ((usage & 1 << 7) != 0)
+            {
+                usageList.Add("Digital Signature");
+            }
+            if ((usage & 1 << 15) != 0)
+            {
+                usageList.Add("Decipher Only");
+            }
+
+            return usageList;
+        }
     }
 }