diff --git a/NSspi/Contexts/Context.cs b/NSspi/Contexts/Context.cs index 67525bd..3014f75 100644 --- a/NSspi/Contexts/Context.cs +++ b/NSspi/Contexts/Context.cs @@ -83,6 +83,11 @@ namespace NSspi.Contexts /// public bool Disposed { get; private set; } + /// + /// Constant for wrapping only...no encryption + /// + protected uint KERB_WRAP_NO_ENCRYPT = 0x80000001; + /// /// Marks the context as having completed the initialization process, ie, exchanging of authentication tokens. /// @@ -230,8 +235,9 @@ namespace NSspi.Contexts /// - The padding buffer. /// /// The raw message to encrypt. + /// Only wrap the message, no encryption /// The packed and encrypted message. - public byte[] Encrypt( byte[] input ) + public byte[] Encrypt( byte[] input, bool wrapOnly = false ) { // The message is encrypted in place in the buffer we provide to Win32 EncryptMessage SecPkgContext_Sizes sizes; @@ -256,9 +262,14 @@ namespace NSspi.Contexts using( adapter = new SecureBufferAdapter( new[] { trailerBuffer, dataBuffer, paddingBuffer } ) ) { + uint qualityOfProtection = 0u; + if (wrapOnly) + { + qualityOfProtection = KERB_WRAP_NO_ENCRYPT; + } status = ContextNativeMethods.SafeEncryptMessage( this.ContextHandle, - 0, + qualityOfProtection, adapter, 0 ); @@ -312,8 +323,9 @@ namespace NSspi.Contexts /// - The padding buffer. /// /// The packed and encrypted data. + /// Only wrap the message, no encryption /// The original plaintext message. - public byte[] Decrypt( byte[] input ) + public byte[] Decrypt( byte[] input, bool unwrapOnly = false) { SecPkgContext_Sizes sizes; @@ -393,9 +405,14 @@ namespace NSspi.Contexts using( adapter = new SecureBufferAdapter( new[] { trailerBuffer, dataBuffer, paddingBuffer } ) ) { + uint qualityOfProtection = 0u; + if (unwrapOnly) + { + qualityOfProtection = KERB_WRAP_NO_ENCRYPT; + } status = ContextNativeMethods.SafeDecryptMessage( this.ContextHandle, - 0, + qualityOfProtection, adapter, 0 ); diff --git a/NSspi/Contexts/ContextNativeMethods.cs b/NSspi/Contexts/ContextNativeMethods.cs index 1d090d2..5e3153a 100644 --- a/NSspi/Contexts/ContextNativeMethods.cs +++ b/NSspi/Contexts/ContextNativeMethods.cs @@ -106,9 +106,9 @@ namespace NSspi.Contexts [DllImport( "Secur32.dll", EntryPoint = "EncryptMessage", CharSet = CharSet.Unicode )] internal static extern SecurityStatus EncryptMessage( ref RawSspiHandle contextHandle, - int qualityOfProtection, + uint qualityOfProtection, IntPtr bufferDescriptor, - int sequenceNumber + uint sequenceNumber ); [ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail )] @@ -116,17 +116,17 @@ namespace NSspi.Contexts internal static extern SecurityStatus DecryptMessage( ref RawSspiHandle contextHandle, IntPtr bufferDescriptor, - int sequenceNumber, - int qualityOfProtection + uint sequenceNumber, + uint qualityOfProtection ); [ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail )] [DllImport( "Secur32.dll", EntryPoint = "MakeSignature", CharSet = CharSet.Unicode )] internal static extern SecurityStatus MakeSignature( ref RawSspiHandle contextHandle, - int qualityOfProtection, + uint qualityOfProtection, IntPtr bufferDescriptor, - int sequenceNumber + uint sequenceNumber ); [ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail )] @@ -134,8 +134,8 @@ namespace NSspi.Contexts internal static extern SecurityStatus VerifySignature( ref RawSspiHandle contextHandle, IntPtr bufferDescriptor, - int sequenceNumber, - int qualityOfProtection + uint sequenceNumber, + uint qualityOfProtection ); [ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )] @@ -255,9 +255,9 @@ namespace NSspi.Contexts /// internal static SecurityStatus SafeEncryptMessage( SafeContextHandle handle, - int qualityOfProtection, + uint qualityOfProtection, SecureBufferAdapter bufferAdapter, - int sequenceNumber ) + uint sequenceNumber ) { SecurityStatus status = SecurityStatus.InternalError; bool gotRef = false; @@ -306,9 +306,9 @@ namespace NSspi.Contexts /// internal static SecurityStatus SafeDecryptMessage( SafeContextHandle handle, - int qualityOfProtection, + uint qualityOfProtection, SecureBufferAdapter bufferAdapter, - int sequenceNumber ) + uint sequenceNumber ) { SecurityStatus status = SecurityStatus.InvalidHandle; bool gotRef = false; @@ -357,9 +357,9 @@ namespace NSspi.Contexts /// internal static SecurityStatus SafeMakeSignature( SafeContextHandle handle, - int qualityOfProtection, + uint qualityOfProtection, SecureBufferAdapter adapter, - int sequenceNumber ) + uint sequenceNumber ) { bool gotRef = false; SecurityStatus status = SecurityStatus.InternalError; @@ -408,9 +408,9 @@ namespace NSspi.Contexts /// internal static SecurityStatus SafeVerifySignature( SafeContextHandle handle, - int qualityOfProtection, + uint qualityOfProtection, SecureBufferAdapter adapter, - int sequenceNumber ) + uint sequenceNumber ) { bool gotRef = false; SecurityStatus status = SecurityStatus.InternalError; diff --git a/NsspiDemo/App.config b/NsspiDemo/App.config index 08b4571..282e032 100644 --- a/NsspiDemo/App.config +++ b/NsspiDemo/App.config @@ -1,6 +1,6 @@ - + diff --git a/NsspiDemo/NsspiDemo.csproj b/NsspiDemo/NsspiDemo.csproj index 52eb0e4..9913990 100644 --- a/NsspiDemo/NsspiDemo.csproj +++ b/NsspiDemo/NsspiDemo.csproj @@ -9,7 +9,7 @@ Properties NsspiDemo NsspiDemo - v4.6.1 + v4.8 512 diff --git a/NsspiDemo/Properties/Resources.Designer.cs b/NsspiDemo/Properties/Resources.Designer.cs index 7f1389b..142d56f 100644 --- a/NsspiDemo/Properties/Resources.Designer.cs +++ b/NsspiDemo/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace NsspiDemo.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/NsspiDemo/Properties/Settings.Designer.cs b/NsspiDemo/Properties/Settings.Designer.cs index c0075b3..be2234d 100644 --- a/NsspiDemo/Properties/Settings.Designer.cs +++ b/NsspiDemo/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace NsspiDemo.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/TestClient/App.config b/TestClient/App.config index 08b4571..282e032 100644 --- a/TestClient/App.config +++ b/TestClient/App.config @@ -1,6 +1,6 @@ - + diff --git a/TestClient/Properties/Resources.Designer.cs b/TestClient/Properties/Resources.Designer.cs index 160f262..a7ac6f2 100644 --- a/TestClient/Properties/Resources.Designer.cs +++ b/TestClient/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace TestClient.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/TestClient/Properties/Settings.Designer.cs b/TestClient/Properties/Settings.Designer.cs index 3d6351b..b808a32 100644 --- a/TestClient/Properties/Settings.Designer.cs +++ b/TestClient/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace TestClient.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/TestClient/TestClient.csproj b/TestClient/TestClient.csproj index 7da633b..fa91b15 100644 --- a/TestClient/TestClient.csproj +++ b/TestClient/TestClient.csproj @@ -9,7 +9,7 @@ Properties TestClient TestClient - v4.6.1 + v4.8 512 diff --git a/TestProtocol/App.config b/TestProtocol/App.config index 08b4571..282e032 100644 --- a/TestProtocol/App.config +++ b/TestProtocol/App.config @@ -1,6 +1,6 @@ - + diff --git a/TestProtocol/Properties/Resources.Designer.cs b/TestProtocol/Properties/Resources.Designer.cs index 503090d..076cbb2 100644 --- a/TestProtocol/Properties/Resources.Designer.cs +++ b/TestProtocol/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace TestProtocol.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/TestProtocol/Properties/Settings.Designer.cs b/TestProtocol/Properties/Settings.Designer.cs index 30cae6c..caa9857 100644 --- a/TestProtocol/Properties/Settings.Designer.cs +++ b/TestProtocol/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace TestProtocol.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/TestProtocol/TestProtocol.csproj b/TestProtocol/TestProtocol.csproj index 7036c35..eb7d033 100644 --- a/TestProtocol/TestProtocol.csproj +++ b/TestProtocol/TestProtocol.csproj @@ -9,7 +9,7 @@ Properties TestProtocol TestProtocol - v4.6.1 + v4.8 512 diff --git a/TestServer/App.config b/TestServer/App.config index 08b4571..282e032 100644 --- a/TestServer/App.config +++ b/TestServer/App.config @@ -1,6 +1,6 @@ - + diff --git a/TestServer/Properties/Resources.Designer.cs b/TestServer/Properties/Resources.Designer.cs index 0f17dd7..4c0635d 100644 --- a/TestServer/Properties/Resources.Designer.cs +++ b/TestServer/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace TestServer.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/TestServer/Properties/Settings.Designer.cs b/TestServer/Properties/Settings.Designer.cs index b20c6e6..b657ac0 100644 --- a/TestServer/Properties/Settings.Designer.cs +++ b/TestServer/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace TestServer.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/TestServer/TestServer.csproj b/TestServer/TestServer.csproj index 3f6ff18..5d39cac 100644 --- a/TestServer/TestServer.csproj +++ b/TestServer/TestServer.csproj @@ -9,7 +9,7 @@ Properties TestServer TestServer - v4.6.1 + v4.8 512