Browse Source

Signing

pull/30/head
PeterForstmeier 13 years ago
parent
commit
e1ce528d58
  1. 5
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. 74
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKeyXaml.xaml
  3. 170
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKeyXaml.xaml.cs
  4. 37
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/SigningXaml.xaml
  5. 137
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/SigningXaml.xaml.cs

5
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -274,6 +274,10 @@ @@ -274,6 +274,10 @@
<DependentUpon>ApplicationSettings.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\CreateKeyXaml.xaml.cs">
<DependentUpon>CreateKeyXaml.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\DebugOptions.xaml.cs">
<DependentUpon>DebugOptions.xaml</DependentUpon>
<SubType>Code</SubType>
@ -908,6 +912,7 @@ @@ -908,6 +912,7 @@
<Page Include="Src\Gui\Dialogs\OptionPanels\IDEOptions\TaskListOptionsl.xaml" />
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\ApplicationSettings.xaml" />
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\BuildEvents.xaml" />
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\CreateKeyXaml.xaml" />
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\DebugOptions.xaml" />
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\ProjectOptionPanel.xaml">
<DependentUpon>ProjectOptionPanel.cs</DependentUpon>

74
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKeyXaml.xaml

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
<Window x:Class="ICSharpCode.SharpDevelop.Gui.OptionPanels.CreateKeyXaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:core="http://icsharpcode.net/sharpdevelop/core"
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets"
Title="{core:Localize Dialog.ProjectOptions.Signing.CreateKey.Title}"
Height="Auto" Width="450">
<Window.Resources>
<GridLength x:Key="VerticalSpacing"> 25</GridLength>
</Window.Resources>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="{StaticResource VerticalSpacing}"></RowDefinition>
<RowDefinition Height="{StaticResource VerticalSpacing}"></RowDefinition>
<RowDefinition Height="{StaticResource VerticalSpacing}"></RowDefinition>
<RowDefinition Height="{StaticResource VerticalSpacing}"></RowDefinition>
<RowDefinition Height="{StaticResource VerticalSpacing}"></RowDefinition>
<RowDefinition Height="{StaticResource VerticalSpacing}" ></RowDefinition>
<RowDefinition Height="{StaticResource VerticalSpacing}"></RowDefinition>
<RowDefinition Height="10"></RowDefinition>
<RowDefinition Height="35"></RowDefinition>
<RowDefinition Height="10"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="10"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Row="1" Grid.Column="1"
Content="{core:Localize Dialog.ProjectOptions.Signing.CreateKey.KeyName}"></Label>
<TextBox x:Name="keyFileTextBox" Grid.Row="2" Grid.Column="1"
Text="{Binding Path=KeyFile}">
</TextBox>
<CheckBox Grid.Row="3" Grid.Column="1" IsChecked="{Binding Path=CheckBoxChecked, Mode=OneWayToSource}"
Content="{core:Localize Dialog.ProjectOptions.Signing.CreateKey.UsePassword}"></CheckBox>
<Label Grid.Row="4" Grid.Column="1"
Content="{core:Localize Dialog.ProjectOptions.Signing.CreateKey.EnterPassword}"></Label>
<TextBox x:Name="passwordTextBox" Grid.Row="5" Grid.Column="1"
IsEnabled="{Binding Path=CheckBoxChecked}"
></TextBox>
<Label Grid.Row="6" Grid.Column="1"
Content="{core:Localize Dialog.ProjectOptions.Signing.CreateKey.ConfirmPassword}"></Label>
<TextBox x:Name="confirmPasswordTextBox" Grid.Row="7" Grid.Column="1"
IsEnabled="{Binding Path=CheckBoxChecked}"
></TextBox>
<!-- http://betterwpfcontrols.codeplex.com/
http://navigationpane.codeplex.com/
-->
<widgets:StackPanelWithSpacing Orientation="Horizontal" Grid.Row="9" Grid.Column="1"
SpaceBetweenItems="5" HorizontalAlignment="Right">
<Button Content="{core:Localize Global.OKButtonText}"
IsDefault="True"
Click="okButtonClick"
Style="{x:Static core:GlobalStyles.ButtonStyle}" >
</Button>
<Button Content="{core:Localize Global.CancelButtonText}"
IsCancel="True"
Click="cancelButtonClick"
Style="{x:Static core:GlobalStyles.ButtonStyle}">
</Button>
</widgets:StackPanelWithSpacing>
</Grid>
</Window>

170
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/CreateKeyXaml.xaml.cs

@ -0,0 +1,170 @@ @@ -0,0 +1,170 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 01.06.2012
* Time: 20:20
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{
/// <summary>
/// Interaction logic for CreateKeyXaml.xaml
/// </summary>
public partial class CreateKeyXaml : Window,INotifyPropertyChanged
{
private bool checkBoxChecked;
private string keyFile;
private string baseDirectory;
public CreateKeyXaml()
{
InitializeComponent();
DataContext = this;
}
public CreateKeyXaml (string baseDirectory):this()
{
this.baseDirectory = baseDirectory;
}
public bool CheckBoxChecked {
get { return checkBoxChecked; }
set { checkBoxChecked = value;
OnPropertyChange("CheckBoxChecked");
}
}
public string KeyFile {
get { return keyFile; }
set { keyFile = value;
OnPropertyChange("KeyFile"); }
}
/// <summary>
/// Gets the path of the "strong named" executable. This is used to create keys for strongly signing
/// .NET assemblies.
/// </summary>
public static string StrongNameTool {
get {
return FileUtility.GetSdkPath("sn.exe");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChange (string propertyName)
{
if (PropertyChanged != null) {
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
void okButtonClick(object sender, RoutedEventArgs e)
{
KeyFile = KeyFile.Trim();
if (KeyFile.Length == 0) {
MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.EnterKeyName}");
return;
}
if (CheckBoxChecked) {
if (!CheckPassword(this.passwordTextBox.Text.Trim(),this.confirmPasswordTextBox.Text.Trim()))
{
return;
}
MessageService.ShowMessage("Creating a key file with a password is currently not supported.");
return;
}
if (!KeyFile.EndsWith(".snk") && !KeyFile.EndsWith(".pfx"))
KeyFile += ".snk";
if (CreateKey(Path.Combine(baseDirectory, KeyFile))) {
this.DialogResult = true;
Close();
}
}
/// <summary>
/// Creates a key with the sn.exe utility.
/// </summary>
/// <param name="keyPath">The path of the key to create.</param>
/// <returns>True if the key was created correctly.</returns>
private static bool CreateKey(string keyPath)
{
if (File.Exists(keyPath)) {
string question = "${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion}";
question = StringParser.Parse(question, new StringTagPair("fileNames", keyPath));
if (!MessageService.AskQuestion(question, "${res:ICSharpCode.SharpDevelop.Internal.Templates.ProjectDescriptor.OverwriteQuestion.InfoName}")) {
return false;
}
}
Process p = Process.Start(StrongNameTool, "-k \"" + keyPath + "\"");
p.WaitForExit();
if (p.ExitCode != 0) {
MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.ErrorCreatingKey}");
return false;
}
return true;
}
public static bool CheckPassword(string password, string confirm)
{
// if (password.Text.Length < 6) {
// MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.PasswordTooShort}");
// password.Focus();
// return false;
// }
// if (password.Text != confirm.Text) {
// MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.PasswordsDontMatch}");
// return false;
// }
return true;
}
// private static bool CheckPassword(Control password, Control confirm)
// {
// password.Text = password.Text.Trim();
// confirm.Text = confirm.Text.Trim();
// if (password.Text.Length < 6) {
// MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.PasswordTooShort}");
// password.Focus();
// return false;
// }
// if (password.Text != confirm.Text) {
// MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.PasswordsDontMatch}");
// return false;
// }
// return true;
// }
void cancelButtonClick(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
Close();
}
}
}

37
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/SigningXaml.xaml

@ -15,8 +15,7 @@ @@ -15,8 +15,7 @@
Orientation="Vertical">
<GroupBox
Header="{core:Localize Dialog.ProjectOptions.Signing.StrongName}">
<Grid
ShowGridLines="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="30"></RowDefinition>
@ -37,19 +36,13 @@ @@ -37,19 +36,13 @@
<ColumnDefinition
Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--
Command="{Binding DataContext.Cmd, RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked}"
-->
<CheckBox
x:Name="signAssemblyCheckBox"
Grid.Column="1"
VerticalAlignment="Center"
IsChecked="{Binding SignAssembly.Value,Converter={StaticResource strTobool}}"
>
<CheckBox x:Name="signAssemblyCheckBox"
Grid.Column="1" VerticalAlignment="Center"
Content="{core:Localize Dialog.ProjectOptions.Signing.SignAssembly}"
IsChecked="{Binding SignAssembly.Value,Converter={StaticResource strTobool}}">
</CheckBox>
<Label
Grid.Row="1"
Grid.Column="1"
@ -60,22 +53,32 @@ Command="{Binding DataContext.Cmd, RelativeSource={RelativeSource FindAncestor, @@ -60,22 +53,32 @@ Command="{Binding DataContext.Cmd, RelativeSource={RelativeSource FindAncestor,
x:Name="keyFileComboBox"
Grid.Row="2"
Grid.Column="1"
Margin="0,0,0,0"></ComboBox>
Margin="3,3,3,3"
IsEnabled="{Binding ElementName=signAssemblyCheckBox, Path=IsChecked}"
SelectionChanged="KeyFileComboBox_SelectionChanged"
ItemsSource="{Binding KeyFile}"
SelectedValue="{Binding Path=SelectedKey}">
</ComboBox>
<Button
x:Name="changePasswordButton"
Grid.Row="2"
Grid.Column="3"
IsEnabled="False"
Content="{core:Localize Dialog.ProjectOptions.Signing.ChangePassword}"
Margin="10,0,10,0"></Button>
Margin="10,3,10,3"></Button>
<CheckBox
x:Name="delaySignOnlyCheckBox"
Grid.Row="3"
Grid.Column="1"
VerticalAlignment="Center"
Content="{core:Localize Dialog.ProjectOptions.Signing.DelaySignOnly}"></CheckBox>
IsEnabled="{Binding ElementName=signAssemblyCheckBox, Path=IsChecked}"
Content="{core:Localize Dialog.ProjectOptions.Signing.DelaySignOnly}"
IsChecked="{Binding DelaySign.Value,Converter={StaticResource strTobool}}">
</CheckBox>
<Label
Grid.Row="4"
Grid.Column="1"
IsEnabled="{Binding ElementName=signAssemblyCheckBox, Path=IsChecked}"
Content="{core:Localize Dialog.ProjectOptions.Signing.DelaySignWarning}"></Label>
</Grid>
</GroupBox>

137
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/SigningXaml.xaml.cs

@ -8,14 +8,17 @@ @@ -8,14 +8,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Widgets;
@ -26,13 +29,29 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -26,13 +29,29 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
/// </summary>
public partial class SigningXaml : ProjectOptionPanel
{
// private const string KeyFileExtensions = "*.snk;*.pfx;*.key";
// private MSBuildBasedProject project;
private const string KeyFileExtensions = "*.snk;*.pfx;*.key";
private List<string> keyFile = new List<string>();
private MSBuildBasedProject project;
public SigningXaml()
{
InitializeComponent();
}
private void Initialize()
{
FindKeys(base.BaseDirectory);
SelectedKey = AssemblyOriginatorKeyFile.Value;
if (SelectedKey != null) {
if (!KeyFile.Contains(SelectedKey)) {
keyFile.Add(SelectedKey);
}
}
keyFile.Add(StringParser.Parse("<${res:Global.CreateButtonText}...>"));
keyFile.Add(StringParser.Parse("<${res:Global.BrowseText}...>"));
}
public ProjectProperty<String> SignAssembly {
@ -44,5 +63,115 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -44,5 +63,115 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
get { return GetProperty("AssemblyOriginatorKeyFile","", TextBoxEditMode.EditEvaluatedProperty); }
}
public ProjectProperty<string> DelaySign {
get { return GetProperty("DelaySign","", TextBoxEditMode.EditEvaluatedProperty); }
}
public ProjectProperty<string> AssemblyOriginatorKeyMode {
get { return GetProperty("AssemblyOriginatorKeyMode","", TextBoxEditMode.EditEvaluatedProperty); }
}
#region overrides
protected override void Load(MSBuildBasedProject project, string configuration, string platform)
{
base.Load(project, configuration, platform);
this.project = project;
Initialize();
}
protected override bool Save(MSBuildBasedProject project, string configuration, string platform)
{
if (signAssemblyCheckBox.IsChecked) {
this.AssemblyOriginatorKeyFile.Value = "File";
}
return base.Save(project, configuration, platform);
}
#endregion
#region keyFile
public List<string> KeyFile {
get { return keyFile; }
set {
keyFile = value;
base.RaisePropertyChanged(() => KeyFile);
}
}
public string SelectedKey {get;set;}
void FindKeys(string directory)
{
directory = FileUtility.NormalizePath(directory);
while (true) {
try {
// var files = from file in new DirectoryInfo(@"C:\").GetFiles()
// where file..Name.StartsWith("_")
// select file;
foreach (string fileName in Directory.GetFiles(directory, "*.snk")) {
keyFile.Add(MSBuildInternals.Escape(FileUtility.GetRelativePath(base.BaseDirectory, fileName)));
}
foreach (string fileName in Directory.GetFiles(directory, "*.pfx")) {
keyFile.Add(MSBuildInternals.Escape(FileUtility.GetRelativePath(base.BaseDirectory, fileName)));
}
foreach (string fileName in Directory.GetFiles(directory, "*.key")) {
keyFile.Add(MSBuildInternals.Escape(FileUtility.GetRelativePath(base.BaseDirectory, fileName)));
}
} catch {
// can happen for networked drives / network locations
break;
}
int pos = directory.LastIndexOf(Path.DirectorySeparatorChar);
if (pos < 0)
break;
directory = directory.Substring(0, pos);
}
}
void KeyFileComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var cbo = (ComboBox) sender;
if (cbo.SelectedIndex == keyFile.Count - 1) {
BrowseKeyFile();
}
if (cbo.SelectedIndex == keyFile.Count - 2) {
CreateKeyFile();
}
}
void BrowseKeyFile()
{
string str = OptionsHelper.OpenFile("${res:SharpDevelop.FileFilter.KeyFiles} (" + KeyFileExtensions + ")|" + KeyFileExtensions + "|${res:SharpDevelop.FileFilter.AllFiles}|*.*");
if (!String.IsNullOrEmpty(str)) {
this.AssemblyOriginatorKeyFile.Value = str;
}
}
private void CreateKeyFile()
{
if (File.Exists(CreateKeyXaml.StrongNameTool)) {
CreateKeyXaml createKey = new CreateKeyXaml(base.BaseDirectory);
createKey.KeyFile = project.Name;
createKey.ShowDialog();
if (createKey.DialogResult.HasValue && createKey.DialogResult.Value)
{
SelectedKey = MSBuildInternals.Escape(createKey.KeyFile);
} else{
SelectedKey = String.Empty;
}
} else {
MessageService.ShowMessage("${res:Dialog.ProjectOptions.Signing.SNnotFound}");
}
}
#endregion
}
}
Loading…
Cancel
Save