Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#131 공동인증서 선택 대화 상자 UI 개선 #144

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/TableCloth.Shared/Models/Configuration/X509CertPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using TableCloth.Resources;

namespace TableCloth.Models.Configuration
{
Expand Down Expand Up @@ -84,6 +85,34 @@ public X509CertPair(byte[] publicKey, byte[] privateKey)
public DateTime NotAfter { get; }
public DateTime NotBefore { get; }

public bool IsValid
=> NotBefore <= DateTime.Now && DateTime.Now <= NotAfter;

public bool HasExpired
=> DateTime.Now > NotAfter;

public bool SoonExpire
=> DateTime.Now > NotAfter.Add(StringResources.Cert_ExpireWindow);

public string Availability
{
get
{
var now = DateTime.Now;
var expireWindow = StringResources.Cert_ExpireWindow;

if (now < NotBefore)
return StringResources.Cert_Availability_MayTooEarly(now, NotBefore);

if (now > NotAfter)
return StringResources.Cert_Availability_Expired;
else if (now > NotAfter.Add(expireWindow))
return StringResources.Cert_Availability_ExpireSoon(now, NotAfter, expireWindow);

return StringResources.Cert_Availability_Available;
}
}

public string SubjectNameForNpkiApp
=> string.Join(",", Subject.Select(x => $"{x.Key.ToLowerInvariant()}={x.Value}"));

Expand Down
34 changes: 25 additions & 9 deletions src/TableCloth.Shared/Resources/StringResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,31 @@ internal static string Get_AppVersion()
}
}

// 공동 인증서 관련 문자열들
partial class StringResources
{
internal static readonly TimeSpan Cert_ExpireWindow = TimeSpan.FromDays(-3d);

internal static string Cert_Availability_MayTooEarly(DateTime now, DateTime notBefore)
=> $"{(int)Math.Truncate((notBefore - now).TotalDays)}일 후 사용 가능";

internal static string Cert_Availability_ExpireSoon(DateTime now, DateTime notAfter, TimeSpan expireWindow)
=> $"{(int)Math.Truncate((now - (notAfter - expireWindow)).TotalDays)}일 후 만료";

internal static readonly string Cert_Availability_Expired = "만료됨";

internal static readonly string Cert_Availability_Available = "사용 가능";

internal static string Error_Cert_MayTooEarly(DateTime now, DateTime notBefore)
=> $"선택하신 공동 인증서는 {(int)Math.Truncate((notBefore - now).TotalDays)}일 후부터 사용 가능합니다.";

internal static string Error_Cert_ExpireSoon(DateTime now, DateTime notAfter, TimeSpan expireWindow)
=> $"{(int)Math.Truncate((now - (notAfter - expireWindow)).TotalDays)}일 후에 만료됩니다. 새로운 공동 인증서로 교체가 필요합니다.";

internal static readonly string Error_Cert_Expired
= $"선택하신 공동 인증서는 만료되었습니다. 다른 공동 인증서를 선택하거나, 새로운 공동 인증서로 교체 발급해야 합니다.";
}

// 비 사용자 인터페이스 문자열들
partial class StringResources
{
Expand Down Expand Up @@ -301,15 +326,6 @@ internal static string Error_Cannot_Prepare_AppContents(Exception ex)

internal static readonly string Info_ShortcutSuccess =
"바탕 화면에 바로 가기를 생성했습니다.";

internal static string Error_Cert_MayTooEarly(DateTime notBefore)
=> $"선택하신 공동 인증서는 {notBefore:yyyy년 M월 d일 tt h시 m분} 이후부터 사용 가능한 공동 인증서입니다. 인증서 사용이 불가능할 수 있습니다.";

internal static string Error_Cert_MayExpired(DateTime notAfter)
=> $"선택하신 공동 인증서는 {notAfter:yyyy년 M월 d일 tt h시 m분} 이후부터는 사용이 불가능한 공동 인증서입니다. 인증서 사용이 불가능할 수 있습니다.";

internal static string Error_Cert_ExpireSoon(DateTime notAfter)
=> $"선택하신 공동 인증서는 {notAfter:yyyy년 M월 d일 tt h시 m분} 이후부터는 사용이 불가능한 공동 인증서입니다. 공동 인증서 갱신을 준비하는 것이 좋습니다.";
}

// 스크립트 내에서 사용되는 문자열들
Expand Down
22 changes: 18 additions & 4 deletions src/TableCloth/CertSelectWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
mc:Ignorable="d"
Style="{DynamicResource MainWindowStyle}"
Title="{StaticResource CertSelectWindow_Title}" Width="480" Height="320"
MinWidth="480" MinHeight="320"
MinWidth="640" MinHeight="480"
DataContext="{Binding CertSelectWindowViewModel, Source={StaticResource ViewModelLocator}}"
TextOptions.TextFormattingMode="Display" TextOptions.TextRenderingMode="ClearType">
<Grid>
Expand All @@ -26,9 +26,23 @@

<TextBlock Grid.Row="0" TextWrapping="Wrap" Text="{StaticResource CertSelectWindow_InstructionLabel}" />
<ListView Grid.Row="1" ItemsSource="{Binding Path='CertPairs'}" SelectedItem="{Binding Path='SelectedCertPair'}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Style.Triggers>
<DataTrigger Binding="{Binding HasExpired}" Value="True">
<Setter Property="Background">
<Setter.Value>
<Brush>#ffadad</Brush>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="{StaticResource CertSelectWindow_CertList_CommonName}" Width="100" DisplayMemberBinding="{Binding CommonName}" />
<GridViewColumn Header="{StaticResource CertSelectWindow_CertList_Available}" Width="100" DisplayMemberBinding="{Binding Availability}" />
<GridViewColumn Header="{StaticResource CertSelectWindow_CertList_OrganizationalUnits}" Width="100" DisplayMemberBinding="{Binding OrganizationalUnit}" />
<GridViewColumn Header="{StaticResource CertSelectWindow_CertList_Organization}" Width="100" DisplayMemberBinding="{Binding Organization}" />
<GridViewColumn Header="{StaticResource CertSelectWindow_CertList_CountryName}" Width="100" DisplayMemberBinding="{Binding CountryName}" />
Expand All @@ -40,11 +54,11 @@
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Button x:Name="ConvertToPfxButton" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Content="{StaticResource CertSelectWindow_ConvertToPfxButtonText}" Click="ConvertToPfxButton_Click" />
<Button x:Name="RefreshCertPairsButton" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Content="{StaticResource CertSelectWindow_RefreshButtonText}" Click="RefreshCertPairsButton_Click" />
<Button x:Name="ConvertToPfxButton" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Content="{StaticResource CertSelectWindow_ConvertToPfxButtonText}" Click="ConvertToPfxButton_Click" Padding="5" />
<Button x:Name="RefreshCertPairsButton" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Content="{StaticResource CertSelectWindow_RefreshButtonText}" Click="RefreshCertPairsButton_Click" Padding="5" />
</Grid>
<TextBlock Grid.Row="3" TextWrapping="Wrap" Text="{StaticResource CertSelectWindow_ManualInstructionLabelText}" />
<Button x:Name="OpenCertPairManuallyButton" Grid.Row="4" HorizontalAlignment="Left" VerticalAlignment="Top" Content="{StaticResource CertSelectWindow_OpenNpkiCertButton}" Margin="0 5 0 5" Click="OpenCertPairManuallyButton_Click" />
<Button x:Name="OpenCertPairManuallyButton" Grid.Row="4" HorizontalAlignment="Left" VerticalAlignment="Top" Content="{StaticResource CertSelectWindow_OpenNpkiCertButton}" Margin="0 5 0 5" Click="OpenCertPairManuallyButton_Click" Padding="5" />
</Grid>

<Grid Grid.Row="1">
Expand Down
15 changes: 8 additions & 7 deletions src/TableCloth/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,16 @@ private void RunSandbox(TableClothConfiguration config)
{
if (config.CertPair != null)
{
var today = DateTime.Now;
var now = DateTime.Now;
var expireWindow = StringResources.Cert_ExpireWindow;

if (today < config.CertPair.NotBefore)
ViewModel.AppMessageBox.DisplayError(StringResources.Error_Cert_MayTooEarly(config.CertPair.NotBefore), false);
if (now < config.CertPair.NotBefore)
ViewModel.AppMessageBox.DisplayError(StringResources.Error_Cert_MayTooEarly(now, config.CertPair.NotBefore), false);

if (today > config.CertPair.NotAfter)
ViewModel.AppMessageBox.DisplayError(StringResources.Error_Cert_MayExpired(config.CertPair.NotAfter), false);
else if (today > config.CertPair.NotAfter.AddDays(-3d))
ViewModel.AppMessageBox.DisplayInfo(StringResources.Error_Cert_ExpireSoon(config.CertPair.NotAfter));
if (now > config.CertPair.NotAfter)
ViewModel.AppMessageBox.DisplayError(StringResources.Error_Cert_Expired, false);
else if (now > config.CertPair.NotAfter.Add(expireWindow))
ViewModel.AppMessageBox.DisplayInfo(StringResources.Error_Cert_ExpireSoon(now, config.CertPair.NotAfter, expireWindow));
}

var tempPath = ViewModel.SharedLocations.GetTempPath();
Expand Down
15 changes: 8 additions & 7 deletions src/TableCloth/Pages/DetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ private void RunSandbox(TableClothConfiguration config)
{
if (config.CertPair != null)
{
var today = DateTime.Now;
var now = DateTime.Now;
var expireWindow = StringResources.Cert_ExpireWindow;

if (today < config.CertPair.NotBefore)
ViewModel.AppMessageBox.DisplayError(StringResources.Error_Cert_MayTooEarly(config.CertPair.NotBefore), false);
if (now < config.CertPair.NotBefore)
ViewModel.AppMessageBox.DisplayError(StringResources.Error_Cert_MayTooEarly(now, config.CertPair.NotBefore), false);

if (today > config.CertPair.NotAfter)
ViewModel.AppMessageBox.DisplayError(StringResources.Error_Cert_MayExpired(config.CertPair.NotAfter), false);
else if (today > config.CertPair.NotAfter.AddDays(-3d))
ViewModel.AppMessageBox.DisplayInfo(StringResources.Error_Cert_ExpireSoon(config.CertPair.NotAfter));
if (now > config.CertPair.NotAfter)
ViewModel.AppMessageBox.DisplayError(StringResources.Error_Cert_Expired, false);
else if (now > config.CertPair.NotAfter.Add(expireWindow))
ViewModel.AppMessageBox.DisplayInfo(StringResources.Error_Cert_ExpireSoon(now, config.CertPair.NotAfter, expireWindow));
}

var tempPath = ViewModel.SharedLocations.GetTempPath();
Expand Down
4 changes: 4 additions & 0 deletions src/TableCloth/UIStringResources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@
소유자
</system:String>

<system:String x:Key="CertSelectWindow_CertList_Available">
사용 가능 여부
</system:String>

<system:String x:Key="CertSelectWindow_CertList_OrganizationalUnits">
기관
</system:String>
Expand Down
Loading