├── OTP.Provider ├── Registration.txt ├── tile.bmp ├── credential_provider_key.reg ├── CredentialFlag.cs ├── Constants.cs ├── Common.cs ├── OTP.Provider.csproj ├── Logger.cs ├── PInvoke.cs ├── CredentialProvider.cs ├── CredentialView.cs ├── CredentialProviderBase.cs └── CredentialProviderCredential.cs ├── midl ├── TlbImp2.exe ├── CoreRuleEngine.dll ├── TlbImpRuleEngine.dll ├── OTP.Provider.Interop.dll ├── TypeLibTypes.Interop.dll └── credentialprovider.idl ├── CustomProvider.jpg ├── OTP.Provider.Helper ├── framework.h ├── pch.cpp ├── dllmain.cpp ├── pch.h ├── helper.h ├── OTP.Provider.Helper.vcxproj.filters ├── OTP.Provider.Helper.vcxproj └── helper.cpp ├── README.md ├── .gitattributes ├── OTP.sln ├── .gitignore └── LICENSE /OTP.Provider/Registration.txt: -------------------------------------------------------------------------------- 1 | regSvr32 .\OTP.Provider\bin\Debug\net6.0-windows\OTP.Provider.comhost.dll -------------------------------------------------------------------------------- /midl/TlbImp2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuku147/Credential-Provider-Demo/HEAD/midl/TlbImp2.exe -------------------------------------------------------------------------------- /CustomProvider.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuku147/Credential-Provider-Demo/HEAD/CustomProvider.jpg -------------------------------------------------------------------------------- /OTP.Provider/tile.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuku147/Credential-Provider-Demo/HEAD/OTP.Provider/tile.bmp -------------------------------------------------------------------------------- /midl/CoreRuleEngine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuku147/Credential-Provider-Demo/HEAD/midl/CoreRuleEngine.dll -------------------------------------------------------------------------------- /midl/TlbImpRuleEngine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuku147/Credential-Provider-Demo/HEAD/midl/TlbImpRuleEngine.dll -------------------------------------------------------------------------------- /midl/OTP.Provider.Interop.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuku147/Credential-Provider-Demo/HEAD/midl/OTP.Provider.Interop.dll -------------------------------------------------------------------------------- /midl/TypeLibTypes.Interop.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuku147/Credential-Provider-Demo/HEAD/midl/TypeLibTypes.Interop.dll -------------------------------------------------------------------------------- /OTP.Provider.Helper/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 4 | // Windows Header Files 5 | #include 6 | -------------------------------------------------------------------------------- /OTP.Provider.Helper/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: source file corresponding to the pre-compiled header 2 | 3 | #include "pch.h" 4 | 5 | // When you are using pre-compiled headers, this source file is necessary for compilation to succeed. 6 | -------------------------------------------------------------------------------- /OTP.Provider/credential_provider_key.reg: -------------------------------------------------------------------------------- 1 | Windows Registry Editor Version 5.00 2 | 3 | [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Providers\{D26F523C-A346-4FC8-B9B4-2B57EAEDA723}] 4 | @="OTP.Provider" 5 | [HKEY_CLASSES_ROOT\OTP.Provider\CLSID] 6 | @="{D26F523C-A346-4FC8-B9B4-2B57EAEDA723}" -------------------------------------------------------------------------------- /OTP.Provider.Helper/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include "pch.h" 3 | 4 | BOOL APIENTRY DllMain( HMODULE hModule, 5 | DWORD ul_reason_for_call, 6 | LPVOID lpReserved 7 | ) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /OTP.Provider.Helper/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: This is a precompiled header file. 2 | // Files listed below are compiled only once, improving build performance for future builds. 3 | // This also affects IntelliSense performance, including code completion and many code browsing features. 4 | // However, files listed here are ALL re-compiled if any one of them is updated between builds. 5 | // Do not add files here that you will be updating frequently as this negates the performance advantage. 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // add headers that you want to pre-compile here 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /OTP.Provider/CredentialFlag.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace OTP.Provider 8 | { 9 | [Flags] 10 | public enum CredentialFlag 11 | { 12 | CREDUIWIN_GENERIC = 0x1, 13 | CREDUIWIN_CHECKBOX = 0x2, 14 | CREDUIWIN_AUTHPACKAGE_ONLY = 0x10, 15 | CREDUIWIN_IN_CRED_ONLY = 0x20, 16 | CREDUIWIN_ENUMERATE_ADMINS = 0x100, 17 | CREDUIWIN_ENUMERATE_CURRENT_USER = 0x200, 18 | CREDUIWIN_SECURE_PROMPT = 0x1000, 19 | CREDUIWIN_PACK_32_WOW = 0x10000000, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Credential Provider Demo on C# 2 | 3 | ![Credential Provider Demo](CustomProvider.jpg) 4 | 5 | ## Testing 6 | 7 | For testing, you need: 8 | - Checking the path to the OTP.Provider.Helper.dll library 9 | - Compile the project 10 | - Register your Credential Provider in the system using the credential_provider_key.reg file 11 | - Register your DLL use command 12 | ``` 13 | regSvr32 .\OTP.Provider\bin\Debug\net6.0-windows\OTP.Provider.comhost.dll 14 | ``` 15 | 16 | ## ATTENTION 17 | When testing, you can access your workstation, after testing in your machine. 18 | Run tests in a virtual machine 19 | 20 | ## Remove 21 | If you need to remove the provider from the system: 22 | - delete the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Providers\{D26F523C-A346-4FC8-B9B4-2B57EAEDA723}] branch from the registry 23 | - Unregister your DLL use command 24 | ``` 25 | regSvr32 /U .\OTP.Provider\bin\Debug\net6.0-windows\OTP.Provider.comhost.dll 26 | ``` 27 | -------------------------------------------------------------------------------- /OTP.Provider.Helper/helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #define SECURITY_WIN32 7 | #include 8 | #include 9 | 10 | #define MAX_ULONG ((ULONG)(-1)) 11 | 12 | #pragma warning(push) 13 | #pragma warning(disable : 4995) 14 | #include 15 | #pragma warning(pop) 16 | 17 | //encrypt a password (if necessary) and copy it; if not, just copy it 18 | extern "C" __declspec(dllexport) HRESULT ProtectIfNecessaryAndCopyPassword( 19 | LPWSTR pwzPassword, 20 | CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 21 | LPWSTR * ppwzProtectedPassword 22 | ); 23 | 24 | //creates a UNICODE_STRING from a NULL-terminated string 25 | HRESULT UnicodeStringInitWithString( 26 | LPWSTR pwz, 27 | UNICODE_STRING* pus 28 | ); 29 | 30 | //initializes a KERB_INTERACTIVE_UNLOCK_LOGON with weak references to the provided credentials 31 | extern "C" __declspec(dllexport) HRESULT KerbInteractiveUnlockLogonInit( 32 | LPWSTR pwzDomain, 33 | LPWSTR pwzUsername, 34 | LPWSTR pwzPassword, 35 | CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 36 | BYTE * *prgb, 37 | DWORD * pcb 38 | //KERB_INTERACTIVE_UNLOCK_LOGON* pkiul 39 | ); -------------------------------------------------------------------------------- /OTP.Provider/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace OTP.Provider 8 | { 9 | internal static class Constants 10 | { 11 | public static class HRESULT 12 | { 13 | // https://msdn.microsoft.com/en-us/library/windows/desktop/ff485842(v=vs.85).aspx 14 | 15 | public const int S_OK = 0x00000000; 16 | public const int S_FALSE = 0x00000001; 17 | 18 | public const int E_ACCESSDENIED = unchecked((int)0x80070005); 19 | public const int E_FAIL = unchecked((int)0x80004005); 20 | public const int E_INVALIDARG = unchecked((int)0x80070057); 21 | public const int E_OUTOFMEMORY = unchecked((int)0x8007000E); 22 | public const int E_POINTER = unchecked((int)0x80004003); 23 | public const int E_UNEXPECTED = unchecked((int)0x8000FFFF); 24 | 25 | // https://msdn.microsoft.com/en-us/library/windows/desktop/aa378137(v=vs.85).aspx 26 | 27 | public const int E_ABORT = unchecked((int)0x80004004); 28 | public const int E_HANDLE = unchecked((int)0x80070006); 29 | public const int E_NOINTERFACE = unchecked((int)0x80004002); 30 | public const int E_NOTIMPL = unchecked((int)0x80004001); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /OTP.Provider/Common.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Security.Principal; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace OTP.Provider 9 | { 10 | static class Common 11 | { 12 | //Determine authentication package required 13 | public static int RetrieveNegotiateAuthPackage(out uint authPackage) 14 | { 15 | Logger.Write(); 16 | 17 | var status = PInvoke.LsaConnectUntrusted(out var lsaHandle); 18 | 19 | //Use Negotiate to allow LSA to decide whether to use local or Kerberos authentication package. 20 | //Yubikey sub auth module link: https://github.com/Yubico/yubico-windows-auth 21 | using (var name = new PInvoke.LsaStringWrapper("Negotiate")) 22 | { 23 | status = PInvoke.LsaLookupAuthenticationPackage(lsaHandle, ref name._string, out authPackage); 24 | } 25 | 26 | PInvoke.LsaDeregisterLogonProcess(lsaHandle); 27 | 28 | Logger.Write($"Using authentication package id: {authPackage}"); 29 | 30 | return (int)status; 31 | } 32 | 33 | public static string GetNameFromSid(string value) 34 | { 35 | Logger.Write(); 36 | 37 | var sid = new SecurityIdentifier(value); 38 | var ntAccount = (NTAccount)sid.Translate(typeof(NTAccount)); 39 | 40 | return ntAccount.ToString(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /OTP.Provider/OTP.Provider.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-windows 5 | enable 6 | annotations 7 | true 8 | x64 9 | true 10 | True 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | ..\midl\OTP.Provider.Interop.dll 32 | 33 | 34 | 35 | 36 | 37 | Always 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /OTP.Provider.Helper/OTP.Provider.Helper.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | 29 | 30 | Source Files 31 | 32 | 33 | Source Files 34 | 35 | 36 | Source Files 37 | 38 | 39 | -------------------------------------------------------------------------------- /OTP.Provider/Logger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace OTP.Provider 9 | { 10 | internal static class Logger 11 | { 12 | private static string path; 13 | private static readonly object signal = new object(); 14 | 15 | static Logger() 16 | { 17 | AppDomain.CurrentDomain.UnhandledException += (s, e) => 18 | { 19 | try 20 | { 21 | Write(e.ExceptionObject.ToString()); 22 | } 23 | catch (Exception ex) 24 | { 25 | Debug.WriteLine(ex); 26 | } 27 | }; 28 | } 29 | 30 | public static TextWriter Out 31 | { 32 | get { return Console.Out; } 33 | set { Console.SetOut(value); } 34 | } 35 | 36 | public static void Write(string line = null, string caller = null) 37 | { 38 | if (string.IsNullOrWhiteSpace(caller)) 39 | { 40 | var method = new StackTrace().GetFrame(1).GetMethod(); 41 | 42 | caller = $"{method.DeclaringType?.Name}.{method.Name}"; 43 | } 44 | 45 | var log = $"{DateTimeOffset.UtcNow:u} [{caller}]"; 46 | 47 | if (!string.IsNullOrWhiteSpace(line)) 48 | { 49 | log += " " + line; 50 | } 51 | 52 | //Just in case multiple threads try to write to the log 53 | lock (signal) 54 | { 55 | var filePath = GetFilePath(); 56 | 57 | Console.WriteLine(log); 58 | File.AppendAllText(filePath, log + Environment.NewLine); 59 | } 60 | } 61 | 62 | private static string GetFilePath() 63 | { 64 | if (path == null) 65 | { 66 | var folder = $"{Environment.GetFolderPath(Environment.SpecialFolder.Windows)}\\Logs\\OTP.Provider"; 67 | 68 | if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); 69 | 70 | path = $"{folder}\\Log-{DateTime.Now.Ticks}.txt"; 71 | } 72 | 73 | return path; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /OTP.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.31911.260 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OTP.Provider", "OTP.Provider\OTP.Provider.csproj", "{7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OTP.Provider.Helper", "OTP.Provider.Helper\OTP.Provider.Helper.vcxproj", "{C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Debug|x64.ActiveCfg = Debug|Any CPU 23 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Debug|x64.Build.0 = Debug|Any CPU 24 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Debug|x86.ActiveCfg = Debug|Any CPU 25 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Debug|x86.Build.0 = Debug|Any CPU 26 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Release|x64.ActiveCfg = Release|Any CPU 29 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Release|x64.Build.0 = Release|Any CPU 30 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Release|x86.ActiveCfg = Release|Any CPU 31 | {7AFE2F37-58EE-4E82-9FE7-DF8E9272BAB0}.Release|x86.Build.0 = Release|Any CPU 32 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Debug|Any CPU.ActiveCfg = Debug|x64 33 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Debug|Any CPU.Build.0 = Debug|x64 34 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Debug|x64.ActiveCfg = Debug|x64 35 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Debug|x64.Build.0 = Debug|x64 36 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Debug|x86.ActiveCfg = Debug|Win32 37 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Debug|x86.Build.0 = Debug|Win32 38 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Release|Any CPU.ActiveCfg = Release|x64 39 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Release|Any CPU.Build.0 = Release|x64 40 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Release|x64.ActiveCfg = Release|x64 41 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Release|x64.Build.0 = Release|x64 42 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Release|x86.ActiveCfg = Release|Win32 43 | {C9B1A7FB-D93D-4357-8C78-506FAAFFF0D2}.Release|x86.Build.0 = Release|Win32 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {27845588-DA98-42CD-9081-2F1A7F54A3F1} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /OTP.Provider/PInvoke.cs: -------------------------------------------------------------------------------- 1 | using OTP.Provider.Interop; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace OTP.Provider 10 | { 11 | static class PInvoke 12 | { 13 | //http://www.pinvoke.net/default.aspx/secur32/LsaLogonUser.html 14 | [StructLayout(LayoutKind.Sequential)] 15 | public struct LSA_STRING 16 | { 17 | public UInt16 Length; 18 | public UInt16 MaximumLength; 19 | public /*PCHAR*/ IntPtr Buffer; 20 | } 21 | 22 | public class LsaStringWrapper : IDisposable 23 | { 24 | public LSA_STRING _string; 25 | 26 | public LsaStringWrapper(string value) 27 | { 28 | _string = new LSA_STRING(); 29 | _string.Length = (ushort)value.Length; 30 | _string.MaximumLength = (ushort)value.Length; 31 | _string.Buffer = Marshal.StringToHGlobalAnsi(value); 32 | } 33 | 34 | ~LsaStringWrapper() 35 | { 36 | Dispose(false); 37 | } 38 | 39 | private void Dispose(bool disposing) 40 | { 41 | if (_string.Buffer != IntPtr.Zero) 42 | { 43 | Marshal.FreeHGlobal(_string.Buffer); 44 | _string.Buffer = IntPtr.Zero; 45 | } 46 | if (disposing) 47 | GC.SuppressFinalize(this); 48 | } 49 | 50 | public void Dispose() 51 | { 52 | Dispose(true); 53 | } 54 | } 55 | 56 | [DllImport("secur32.dll", SetLastError = false)] 57 | public static extern uint LsaConnectUntrusted([Out] out IntPtr lsaHandle); 58 | 59 | [DllImport("secur32.dll", SetLastError = false)] 60 | public static extern uint LsaLookupAuthenticationPackage([In] IntPtr lsaHandle, [In] ref LSA_STRING packageName, [Out] out UInt32 authenticationPackage); 61 | 62 | [DllImport("secur32.dll", SetLastError = false)] 63 | public static extern uint LsaDeregisterLogonProcess([In] IntPtr lsaHandle); 64 | 65 | [DllImport("credui.dll", CharSet = CharSet.Unicode, SetLastError = true)] 66 | public static extern bool CredPackAuthenticationBuffer( 67 | int dwFlags, 68 | string pszUserName, 69 | string pszPassword, 70 | IntPtr pPackedCredentials, 71 | ref int pcbPackedCredentials 72 | ); 73 | 74 | [DllImport("./OTP.Provider.Helper.dll", CharSet = CharSet.Unicode, SetLastError = true)] 75 | public static extern uint ProtectIfNecessaryAndCopyPassword( 76 | string pwzPassword, 77 | _CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 78 | ref string ppwzProtectedPassword 79 | ); 80 | 81 | [DllImport("./OTP.Provider.Helper.dll", CharSet = CharSet.Unicode, SetLastError = true)] 82 | public static extern uint KerbInteractiveUnlockLogonInit( 83 | string pwzDomain, 84 | string pwzUsername, 85 | string pwzPassword, 86 | _CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 87 | ref IntPtr prgb, 88 | ref int pcb 89 | ); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /OTP.Provider/CredentialProvider.cs: -------------------------------------------------------------------------------- 1 | using OTP.Provider.Interop; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace OTP.Provider 10 | { 11 | [ComVisible(true)] 12 | [Guid("D26F523C-A346-4FC8-B9B4-2B57EAEDA723")] 13 | [ClassInterface(ClassInterfaceType.None)] 14 | [ProgId("OTP.Provider")] 15 | public class CredentialProvider : CredentialProviderBase 16 | { 17 | public static CredentialView NotActive; 18 | 19 | public CredentialProvider() 20 | { 21 | 22 | } 23 | 24 | protected override CredentialView Initialize(_CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, uint dwFlags) 25 | { 26 | var flags = (CredentialFlag)dwFlags; 27 | 28 | Logger.Write($"cpus: {cpus}; dwFlags: {flags}"); 29 | 30 | var isSupported = IsSupportedScenario(cpus); 31 | 32 | if (!isSupported) 33 | { 34 | if (NotActive == null) NotActive = new CredentialView(this) { Active = false }; 35 | return NotActive; 36 | } 37 | 38 | var view = new CredentialView(this) { Active = true }; 39 | var userNameState = (cpus == _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_CREDUI) ? 40 | _CREDENTIAL_PROVIDER_FIELD_STATE.CPFS_DISPLAY_IN_SELECTED_TILE : _CREDENTIAL_PROVIDER_FIELD_STATE.CPFS_HIDDEN; 41 | var confirmPasswordState = (cpus == _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_CHANGE_PASSWORD) ? 42 | _CREDENTIAL_PROVIDER_FIELD_STATE.CPFS_DISPLAY_IN_BOTH : _CREDENTIAL_PROVIDER_FIELD_STATE.CPFS_HIDDEN; 43 | 44 | view.AddField( 45 | cpft: _CREDENTIAL_PROVIDER_FIELD_TYPE.CPFT_TILE_IMAGE, 46 | pszLabel: "Icon", 47 | state: _CREDENTIAL_PROVIDER_FIELD_STATE.CPFS_DISPLAY_IN_BOTH, 48 | guidFieldType: Guid.Parse(CredentialView.CPFG_CREDENTIAL_PROVIDER_LOGO) 49 | ); 50 | 51 | view.AddField( 52 | cpft: _CREDENTIAL_PROVIDER_FIELD_TYPE.CPFT_EDIT_TEXT, 53 | pszLabel: "Username", 54 | state: userNameState 55 | ); 56 | 57 | view.AddField( 58 | cpft: _CREDENTIAL_PROVIDER_FIELD_TYPE.CPFT_PASSWORD_TEXT, 59 | pszLabel: "Password", 60 | state: _CREDENTIAL_PROVIDER_FIELD_STATE.CPFS_DISPLAY_IN_SELECTED_TILE, 61 | guidFieldType: Guid.Parse(CredentialView.CPFG_LOGON_PASSWORD_GUID) 62 | ); 63 | 64 | view.AddField( 65 | cpft: _CREDENTIAL_PROVIDER_FIELD_TYPE.CPFT_PASSWORD_TEXT, 66 | pszLabel: "Confirm password", 67 | state: confirmPasswordState, 68 | guidFieldType: Guid.Parse(CredentialView.CPFG_LOGON_PASSWORD_GUID) 69 | ); 70 | 71 | view.AddField( 72 | cpft: _CREDENTIAL_PROVIDER_FIELD_TYPE.CPFT_LARGE_TEXT, 73 | pszLabel: "Click Me!", 74 | defaultValue: "Click Me!", 75 | state: _CREDENTIAL_PROVIDER_FIELD_STATE.CPFS_DISPLAY_IN_DESELECTED_TILE 76 | ); 77 | 78 | return view; 79 | } 80 | 81 | private static bool IsSupportedScenario(_CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus) 82 | { 83 | switch (cpus) 84 | { 85 | case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_CREDUI: 86 | case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_UNLOCK_WORKSTATION: 87 | case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_LOGON: 88 | case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_CHANGE_PASSWORD: 89 | return true; 90 | 91 | case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_PLAP: 92 | case _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_INVALID: 93 | default: 94 | return false; 95 | } 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /OTP.Provider/CredentialView.cs: -------------------------------------------------------------------------------- 1 | using OTP.Provider.Interop; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace OTP.Provider 10 | { 11 | public class CredentialDescriptor 12 | { 13 | public _CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR Descriptor { get; set; } 14 | 15 | public _CREDENTIAL_PROVIDER_FIELD_STATE State { get; set; } 16 | 17 | public object Value { get; set; } 18 | } 19 | 20 | public class CredentialView 21 | { 22 | private readonly List fields 23 | = new List(); 24 | 25 | public CredentialProviderBase Provider { get; private set; } 26 | 27 | public const string CPFG_LOGON_PASSWORD_GUID = "60624cfa-a477-47b1-8a8e-3a4a19981827"; 28 | public const string CPFG_CREDENTIAL_PROVIDER_LOGO = "2d837775-f6cd-464e-a745-482fd0b47493"; 29 | public const string CPFG_CREDENTIAL_PROVIDER_LABEL = "286bbff3-bad4-438f-b007-79b7267c3d48"; 30 | 31 | public bool Active { get; set; } 32 | 33 | public int DescriptorCount { get { return fields.Count; } } 34 | 35 | public virtual int CredentialCount { get { return 1; } } 36 | 37 | public virtual int DefaultCredential { get { return 0; } } 38 | 39 | public CredentialView(CredentialProviderBase provider) 40 | { 41 | Provider = provider; 42 | } 43 | 44 | public virtual void AddField( 45 | _CREDENTIAL_PROVIDER_FIELD_TYPE cpft, 46 | string pszLabel, 47 | _CREDENTIAL_PROVIDER_FIELD_STATE state, 48 | string defaultValue = null, 49 | Guid guidFieldType = default(Guid) 50 | ) 51 | { 52 | if (!Active) 53 | { 54 | throw new NotSupportedException(); 55 | } 56 | 57 | fields.Add(new CredentialDescriptor 58 | { 59 | State = state, 60 | Value = defaultValue, 61 | Descriptor = new _CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR 62 | { 63 | dwFieldID = (uint)fields.Count, 64 | cpft = cpft, 65 | pszLabel = pszLabel, 66 | guidFieldType = guidFieldType 67 | } 68 | }); 69 | } 70 | 71 | public virtual bool GetField(int dwIndex, [Out] IntPtr ppcpfd) 72 | { 73 | Logger.Write($"dwIndex: {dwIndex}; descriptors: {fields.Count}"); 74 | 75 | if (dwIndex >= fields.Count) 76 | { 77 | return false; 78 | } 79 | 80 | var field = fields[dwIndex]; 81 | 82 | var pcpfd = Marshal.AllocHGlobal(Marshal.SizeOf(field.Descriptor)); 83 | 84 | Marshal.StructureToPtr(field.Descriptor, pcpfd, false); 85 | Marshal.StructureToPtr(pcpfd, ppcpfd, false); 86 | 87 | return true; 88 | } 89 | 90 | public string GetValue(int dwFieldId) 91 | { 92 | return (string)fields[dwFieldId].Value; 93 | } 94 | 95 | public void SetValue(int dwFieldId, string val) 96 | { 97 | fields[dwFieldId].Value = val; 98 | } 99 | 100 | public void GetFieldState( 101 | int dwFieldId, 102 | out _CREDENTIAL_PROVIDER_FIELD_STATE pcpfs, 103 | out _CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE pcpfis 104 | ) 105 | { 106 | Logger.Write(); 107 | 108 | var field = fields[dwFieldId]; 109 | 110 | Logger.Write($"Returning field state: {field.State}, interactiveState: None"); 111 | 112 | pcpfs = field.State; 113 | pcpfis = _CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE.CPFIS_NONE; 114 | } 115 | 116 | private readonly Dictionary credentials 117 | = new Dictionary(); 118 | 119 | public virtual ICredentialProviderCredential CreateCredential(int dwIndex) 120 | { 121 | Logger.Write(); 122 | 123 | if (credentials.TryGetValue(dwIndex, out ICredentialProviderCredential credential)) 124 | { 125 | Logger.Write("Returning existing credential."); 126 | return credential; 127 | } 128 | 129 | //Get the sid for this credential from the index 130 | var sid = this.Provider.GetUserSid(dwIndex); 131 | 132 | credential = new CredentialProviderCredential(this, sid); 133 | 134 | credentials[dwIndex] = credential; 135 | 136 | Logger.Write("Returning new credential."); 137 | return credential; 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /OTP.Provider/CredentialProviderBase.cs: -------------------------------------------------------------------------------- 1 | using OTP.Provider.Interop; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using static OTP.Provider.Constants; 9 | 10 | namespace OTP.Provider 11 | { 12 | public abstract class CredentialProviderBase : ICredentialProvider, ICredentialProviderSetUserArray 13 | { 14 | private ICredentialProviderEvents events; 15 | 16 | protected abstract CredentialView Initialize(_CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, uint dwFlags); 17 | 18 | private CredentialView view; 19 | private _CREDENTIAL_PROVIDER_USAGE_SCENARIO usage; 20 | 21 | private List providerUsers; 22 | 23 | public virtual int SetUsageScenario(_CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, uint dwFlags) 24 | { 25 | view = Initialize(cpus, dwFlags); 26 | usage = cpus; 27 | 28 | if (view.Active) 29 | { 30 | return HRESULT.S_OK; 31 | } 32 | 33 | return HRESULT.E_NOTIMPL; 34 | } 35 | 36 | public virtual int SetSerialization(ref _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION pcpcs) 37 | { 38 | Logger.Write($"ulAuthenticationPackage: {pcpcs.ulAuthenticationPackage}"); 39 | 40 | return HRESULT.S_OK; 41 | } 42 | 43 | public virtual int Advise(ICredentialProviderEvents pcpe, ulong upAdviseContext) 44 | { 45 | Logger.Write($"upAdviseContext: {upAdviseContext}"); 46 | 47 | if (pcpe != null) 48 | { 49 | events = pcpe; 50 | 51 | Marshal.AddRef(Marshal.GetIUnknownForObject(pcpe)); 52 | } 53 | 54 | return HRESULT.S_OK; 55 | } 56 | 57 | public virtual int UnAdvise() 58 | { 59 | Logger.Write(); 60 | 61 | if (events != null) 62 | { 63 | //Marshal.Release(Marshal.GetIUnknownForObject(events)); 64 | events = null; 65 | } 66 | 67 | return HRESULT.S_OK; 68 | } 69 | 70 | public virtual int GetFieldDescriptorCount(out uint pdwCount) 71 | { 72 | Logger.Write(); 73 | 74 | pdwCount = (uint)view.DescriptorCount; 75 | 76 | Logger.Write($"Returning field count: {pdwCount}"); 77 | 78 | return HRESULT.S_OK; 79 | } 80 | 81 | public virtual int GetFieldDescriptorAt(uint dwIndex, [Out] IntPtr ppcpfd) 82 | { 83 | if (view.GetField((int)dwIndex, ppcpfd)) 84 | { 85 | return HRESULT.S_OK; 86 | } 87 | 88 | return HRESULT.E_INVALIDARG; 89 | } 90 | 91 | public virtual int GetCredentialCount( 92 | out uint pdwCount, 93 | out uint pdwDefault, 94 | out int pbAutoLogonWithDefault 95 | ) 96 | { 97 | Logger.Write(); 98 | 99 | pdwCount = (uint)view.CredentialCount; 100 | 101 | pdwDefault = (uint)view.DefaultCredential; 102 | 103 | pbAutoLogonWithDefault = 0; 104 | 105 | return HRESULT.S_OK; 106 | } 107 | 108 | public virtual int GetCredentialAt(uint dwIndex, out ICredentialProviderCredential ppcpc) 109 | { 110 | Logger.Write($"dwIndex: {dwIndex}"); 111 | 112 | ppcpc = view.CreateCredential((int)dwIndex); 113 | 114 | return HRESULT.S_OK; 115 | } 116 | 117 | public virtual _CREDENTIAL_PROVIDER_USAGE_SCENARIO GetUsage() 118 | { 119 | return usage; 120 | } 121 | 122 | public virtual int SetUserArray(ICredentialProviderUserArray users) 123 | { 124 | this.providerUsers = new List(); 125 | 126 | users.GetCount(out uint count); 127 | users.GetAccountOptions(out CREDENTIAL_PROVIDER_ACCOUNT_OPTIONS options); 128 | 129 | Logger.Write($"count: {count}; options: {options}"); 130 | 131 | for (uint i = 0; i < count; i++) 132 | { 133 | users.GetAt(i, out ICredentialProviderUser user); 134 | 135 | user.GetProviderID(out Guid providerId); 136 | user.GetSid(out string sid); 137 | 138 | this.providerUsers.Add(user); 139 | 140 | Logger.Write($"providerId: {providerId}; sid: {sid}"); 141 | } 142 | 143 | return HRESULT.S_OK; 144 | } 145 | 146 | //Lookup the user by index and return the sid 147 | public virtual string GetUserSid(int dwIndex) 148 | { 149 | Logger.Write(); 150 | 151 | //CredUI does not provide user sids, so return null 152 | if (this.providerUsers.Count < dwIndex + 1) return null; 153 | 154 | this.providerUsers[dwIndex].GetSid(out string sid); 155 | return sid; 156 | } 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /OTP.Provider.Helper/OTP.Provider.Helper.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {c9b1a7fb-d93d-4357-8c78-506faafff0d2} 25 | OTPProviderHelper 26 | 10.0 27 | 28 | 29 | 30 | DynamicLibrary 31 | true 32 | v143 33 | Unicode 34 | 35 | 36 | DynamicLibrary 37 | false 38 | v143 39 | true 40 | Unicode 41 | 42 | 43 | DynamicLibrary 44 | true 45 | v143 46 | Unicode 47 | 48 | 49 | DynamicLibrary 50 | false 51 | v143 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | $(ProjectDir)bin\$(Configuration)\ 82 | 83 | 84 | false 85 | 86 | 87 | 88 | Level3 89 | true 90 | WIN32;_DEBUG;OTPPROVIDERHELPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 91 | true 92 | Use 93 | pch.h 94 | 95 | 96 | Windows 97 | true 98 | false 99 | 100 | 101 | 102 | 103 | Level3 104 | true 105 | true 106 | true 107 | WIN32;NDEBUG;OTPPROVIDERHELPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 108 | true 109 | Use 110 | pch.h 111 | 112 | 113 | Windows 114 | true 115 | true 116 | true 117 | false 118 | 119 | 120 | 121 | 122 | Level3 123 | true 124 | _DEBUG;OTPPROVIDERHELPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 125 | true 126 | Use 127 | pch.h 128 | 129 | 130 | Windows 131 | true 132 | false 133 | secur32.lib;shlwapi.lib;%(AdditionalDependencies) 134 | 135 | 136 | 137 | 138 | Level3 139 | true 140 | true 141 | true 142 | NDEBUG;OTPPROVIDERHELPER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 143 | true 144 | Use 145 | pch.h 146 | 147 | 148 | Windows 149 | true 150 | true 151 | true 152 | false 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | Create 165 | Create 166 | Create 167 | Create 168 | 169 | 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /OTP.Provider/CredentialProviderCredential.cs: -------------------------------------------------------------------------------- 1 | using OTP.Provider.Interop; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Drawing; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using static OTP.Provider.Constants; 11 | 12 | namespace OTP.Provider 13 | { 14 | public class CredentialProviderCredential : ICredentialProviderCredential2 15 | { 16 | private readonly CredentialView view; 17 | private string sid; 18 | 19 | public CredentialProviderCredential(CredentialView view, string sid) 20 | { 21 | Logger.Write(); 22 | 23 | this.view = view; 24 | this.sid = sid; 25 | } 26 | 27 | public virtual int Advise(ICredentialProviderCredentialEvents pcpce) 28 | { 29 | Logger.Write(); 30 | 31 | if (pcpce is ICredentialProviderCredentialEvents2 ev2) 32 | { 33 | Logger.Write("pcpce is ICredentialProviderCredentialEvents2"); 34 | } 35 | 36 | return HRESULT.S_OK; 37 | } 38 | 39 | public virtual int UnAdvise() 40 | { 41 | Logger.Write(); 42 | 43 | return HRESULT.E_NOTIMPL; 44 | } 45 | 46 | public virtual int SetSelected(out int pbAutoLogon) 47 | { 48 | Logger.Write(); 49 | 50 | //Set this to 1 if you would like GetSerialization called immediately on selection 51 | pbAutoLogon = 0; 52 | 53 | return HRESULT.S_OK; 54 | } 55 | 56 | public virtual int SetDeselected() 57 | { 58 | Logger.Write(); 59 | 60 | return HRESULT.E_NOTIMPL; 61 | } 62 | 63 | public virtual int GetFieldState( 64 | uint dwFieldID, 65 | out _CREDENTIAL_PROVIDER_FIELD_STATE pcpfs, 66 | out _CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE pcpfis 67 | ) 68 | { 69 | Logger.Write($"dwFieldID: {dwFieldID}"); 70 | 71 | view.GetFieldState((int)dwFieldID, out pcpfs, out pcpfis); 72 | 73 | return HRESULT.S_OK; 74 | } 75 | 76 | public virtual int GetStringValue(uint dwFieldID, out string ppsz) 77 | { 78 | Logger.Write($"dwFieldID: {dwFieldID}"); 79 | 80 | ppsz = view.GetValue((int)dwFieldID); 81 | 82 | return HRESULT.S_OK; 83 | } 84 | 85 | private Bitmap tileIcon; 86 | 87 | public virtual int GetBitmapValue(uint dwFieldID, out IntPtr phbmp) 88 | { 89 | Logger.Write($"dwFieldID: {dwFieldID}"); 90 | 91 | try 92 | { 93 | TryLoadUserIcon(); 94 | } 95 | catch (Exception ex) 96 | { 97 | Logger.Write("Error: " + ex); 98 | } 99 | 100 | phbmp = tileIcon?.GetHbitmap() ?? IntPtr.Zero; 101 | 102 | return HRESULT.S_OK; 103 | } 104 | 105 | private void TryLoadUserIcon() 106 | { 107 | if (tileIcon == null) 108 | { 109 | var fileName = "OTP.Provider.tile.bmp"; 110 | var assembly = Assembly.GetExecutingAssembly(); 111 | var stream = assembly.GetManifestResourceStream(fileName); 112 | 113 | tileIcon = (Bitmap)Image.FromStream(stream); 114 | } 115 | } 116 | 117 | public virtual int GetCheckboxValue(uint dwFieldID, out int pbChecked, out string ppszLabel) 118 | { 119 | Logger.Write($"dwFieldID: {dwFieldID}"); 120 | 121 | pbChecked = 0; 122 | ppszLabel = ""; 123 | 124 | return HRESULT.E_NOTIMPL; 125 | } 126 | 127 | public virtual int GetSubmitButtonValue(uint dwFieldID, out uint pdwAdjacentTo) 128 | { 129 | Logger.Write($"dwFieldID: {dwFieldID}"); 130 | 131 | pdwAdjacentTo = 0; 132 | 133 | return HRESULT.E_NOTIMPL; 134 | } 135 | 136 | public virtual int GetComboBoxValueCount(uint dwFieldID, out uint pcItems, out uint pdwSelectedItem) 137 | { 138 | Logger.Write($"dwFieldID: {dwFieldID}"); 139 | 140 | pcItems = 0; 141 | pdwSelectedItem = 0; 142 | 143 | return HRESULT.E_NOTIMPL; 144 | } 145 | 146 | public virtual int GetComboBoxValueAt(uint dwFieldID, uint dwItem, out string ppszItem) 147 | { 148 | Logger.Write($"dwFieldID: {dwFieldID}; dwItem: {dwItem}"); 149 | 150 | ppszItem = ""; 151 | 152 | return HRESULT.E_NOTIMPL; 153 | } 154 | 155 | public virtual int SetStringValue(uint dwFieldID, string psz) 156 | { 157 | Logger.Write($"dwFieldID: {dwFieldID}; psz: {psz}"); 158 | 159 | view.SetValue((int)dwFieldID, psz); 160 | 161 | return HRESULT.S_OK; 162 | } 163 | 164 | public virtual int SetCheckboxValue(uint dwFieldID, int bChecked) 165 | { 166 | Logger.Write($"dwFieldID: {dwFieldID}; bChecked: {bChecked}"); 167 | 168 | return HRESULT.E_NOTIMPL; 169 | } 170 | 171 | public virtual int SetComboBoxSelectedValue(uint dwFieldID, uint dwSelectedItem) 172 | { 173 | Logger.Write($"dwFieldID: {dwFieldID}; dwSelectedItem: {dwSelectedItem}"); 174 | 175 | return HRESULT.E_NOTIMPL; 176 | } 177 | 178 | public virtual int CommandLinkClicked(uint dwFieldID) 179 | { 180 | Logger.Write($"dwFieldID: {dwFieldID}"); 181 | 182 | return HRESULT.E_NOTIMPL; 183 | } 184 | 185 | public virtual int GetSerialization( 186 | out _CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE pcpgsr, 187 | out _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION pcpcs, 188 | out string ppszOptionalStatusText, 189 | out _CREDENTIAL_PROVIDER_STATUS_ICON pcpsiOptionalStatusIcon 190 | ) 191 | { 192 | Logger.Write(); 193 | 194 | var usage = this.view.Provider.GetUsage(); 195 | 196 | pcpgsr = _CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE.CPGSR_NO_CREDENTIAL_NOT_FINISHED; 197 | pcpcs = new _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION(); 198 | ppszOptionalStatusText = ""; 199 | pcpsiOptionalStatusIcon = _CREDENTIAL_PROVIDER_STATUS_ICON.CPSI_NONE; 200 | 201 | //Serialization can be called before the user has entered any values. Only applies to logon usage scenarios 202 | if (usage == _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_LOGON || usage == _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_UNLOCK_WORKSTATION) 203 | { 204 | //Determine the authentication package 205 | Common.RetrieveNegotiateAuthPackage(out var authPackage); 206 | 207 | //Only credential packing for msv1_0 is supported using this code 208 | Logger.Write($"Got authentication package: {authPackage}. Only local authenticsation package 0 (msv1_0) is supported."); 209 | 210 | //Get username and password 211 | var username = Common.GetNameFromSid(this.sid); 212 | GetStringValue(2, out var password); 213 | 214 | Logger.Write($"Preparing to serialise credential with password..."); 215 | 216 | int positionOfNewLine = username.IndexOf("\\"); 217 | var domain = username.Substring(0, positionOfNewLine); 218 | var usernameLength = username.Length; 219 | var shortUsername = username.Substring(positionOfNewLine + 1, usernameLength - positionOfNewLine - 1); 220 | 221 | string protectedPassword = ""; 222 | 223 | try 224 | { 225 | Logger.Write("Start ProtectIfNecessaryAndCopyPassword"); 226 | PInvoke.ProtectIfNecessaryAndCopyPassword(password, usage, ref protectedPassword); 227 | Logger.Write(protectedPassword); 228 | Logger.Write("Finish ProtectIfNecessaryAndCopyPassword"); 229 | } 230 | catch (Exception ex) 231 | { 232 | Logger.Write(ex.Message); 233 | } 234 | 235 | var inCredSize = 0; 236 | var inCredBuffer = Marshal.AllocCoTaskMem(0); 237 | try 238 | { 239 | Logger.Write("Start KerbInteractiveUnlockLogonInit"); 240 | 241 | Marshal.FreeCoTaskMem(inCredBuffer); 242 | inCredBuffer = Marshal.AllocCoTaskMem(inCredSize); 243 | 244 | Logger.Write("Input Params"); 245 | Logger.Write("Domain:" + domain); 246 | Logger.Write("Username:" + shortUsername); 247 | Logger.Write("protectedPassword:" + protectedPassword); 248 | 249 | PInvoke.KerbInteractiveUnlockLogonInit(domain, shortUsername, protectedPassword, usage, ref inCredBuffer, ref inCredSize); 250 | //PInvoke.KerbInteractiveUnlockLogonInit(domain, username, password, usage, ref inCredBuffer, ref inCredSize); 251 | Logger.Write("KerbInteractiveUnlockLogonInit Finish"); 252 | 253 | pcpcs.clsidCredentialProvider = Guid.Parse("D26F523C-A346-4FC8-B9B4-2B57EAEDA723"); 254 | pcpcs.rgbSerialization = inCredBuffer; 255 | pcpcs.cbSerialization = (uint)inCredSize; 256 | pcpcs.ulAuthenticationPackage = authPackage; 257 | pcpgsr = _CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE.CPGSR_RETURN_CREDENTIAL_FINISHED; 258 | 259 | 260 | Logger.Write(inCredSize.ToString()); 261 | 262 | return HRESULT.S_OK; 263 | 264 | } 265 | catch (Exception ex) 266 | { 267 | Logger.Write("Exception KerbInteractiveUnlockLogonInit"); 268 | Logger.Write(ex.Message); 269 | } 270 | 271 | pcpgsr = _CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE.CPGSR_RETURN_CREDENTIAL_FINISHED; 272 | pcpcs = new _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION(); 273 | 274 | } 275 | //Implement code to change password here. This is not handled natively. 276 | else if (usage == _CREDENTIAL_PROVIDER_USAGE_SCENARIO.CPUS_CHANGE_PASSWORD) 277 | { 278 | pcpgsr = _CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE.CPGSR_NO_CREDENTIAL_FINISHED; 279 | pcpcs = new _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION(); 280 | ppszOptionalStatusText = "Password changed success message."; 281 | pcpsiOptionalStatusIcon = _CREDENTIAL_PROVIDER_STATUS_ICON.CPSI_SUCCESS; 282 | } 283 | 284 | Logger.Write("Returning S_OK"); 285 | return HRESULT.S_OK; 286 | } 287 | 288 | public virtual int ReportResult( 289 | int ntsStatus, 290 | int ntsSubstatus, 291 | out string ppszOptionalStatusText, 292 | out _CREDENTIAL_PROVIDER_STATUS_ICON pcpsiOptionalStatusIcon 293 | ) 294 | { 295 | Logger.Write($"ntsStatus: {ntsStatus}; ntsSubstatus: {ntsSubstatus}"); 296 | 297 | ppszOptionalStatusText = ""; 298 | pcpsiOptionalStatusIcon = _CREDENTIAL_PROVIDER_STATUS_ICON.CPSI_NONE; 299 | 300 | return HRESULT.S_OK; 301 | } 302 | 303 | public virtual int GetUserSid(out string sid) 304 | { 305 | Logger.Write(); 306 | 307 | sid = this.sid; 308 | 309 | Console.WriteLine($"Returning sid: {sid}"); 310 | return HRESULT.S_OK; 311 | } 312 | } 313 | } 314 | -------------------------------------------------------------------------------- /OTP.Provider.Helper/helper.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | 3 | #include "helper.h" 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | 11 | // 12 | // Return a copy of pwzToProtect encrypted with the CredProtect API. 13 | // 14 | // pwzToProtect must not be NULL or the empty string. 15 | // 16 | static HRESULT ProtectAndCopyString( 17 | LPWSTR pwzToProtect, 18 | LPWSTR* ppwzProtected 19 | ) 20 | { 21 | *ppwzProtected = NULL; 22 | 23 | HRESULT hr = E_FAIL; 24 | 25 | // The first call to CredProtect determines the length of the encrypted string. 26 | // Because we pass a NULL output buffer, we expect the call to fail. 27 | // 28 | // Note that the third parameter to CredProtect, the number of characters of pwzToProtect 29 | // to encrypt, must include the NULL terminator! 30 | DWORD cchProtected = 0; 31 | if (!CredProtectW(FALSE, pwzToProtect, (DWORD)wcslen(pwzToProtect) + 1, NULL, &cchProtected, NULL)) 32 | { 33 | DWORD dwErr = GetLastError(); 34 | 35 | if ((ERROR_INSUFFICIENT_BUFFER == dwErr) && (0 < cchProtected)) 36 | { 37 | // Allocate a buffer long enough for the encrypted string. 38 | LPWSTR pwzProtected = (LPWSTR)CoTaskMemAlloc(cchProtected * sizeof(WCHAR)); 39 | 40 | if (pwzProtected) 41 | { 42 | // The second call to CredProtect actually encrypts the string. 43 | if (CredProtectW(FALSE, pwzToProtect, (DWORD)wcslen(pwzToProtect) + 1, pwzProtected, &cchProtected, NULL)) 44 | { 45 | *ppwzProtected = pwzProtected; 46 | hr = S_OK; 47 | } 48 | else 49 | { 50 | CoTaskMemFree(pwzProtected); 51 | 52 | dwErr = GetLastError(); 53 | hr = HRESULT_FROM_WIN32(dwErr); 54 | } 55 | } 56 | else 57 | { 58 | hr = E_OUTOFMEMORY; 59 | } 60 | } 61 | else 62 | { 63 | hr = HRESULT_FROM_WIN32(dwErr); 64 | } 65 | } 66 | 67 | return hr; 68 | } 69 | 70 | // 71 | // If pwzPassword should be encrypted, return a copy encrypted with CredProtect. 72 | // 73 | // If not, just return a copy. 74 | // 75 | HRESULT ProtectIfNecessaryAndCopyPassword( 76 | LPWSTR pwzPassword, 77 | CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 78 | LPWSTR* ppwzProtectedPassword 79 | ) 80 | { 81 | *ppwzProtectedPassword = NULL; 82 | 83 | HRESULT hr; 84 | 85 | // ProtectAndCopyString is intended for non-empty strings only. Empty passwords 86 | // do not need to be encrypted. 87 | if (pwzPassword && *pwzPassword) 88 | { 89 | bool bCredAlreadyEncrypted = false; 90 | CRED_PROTECTION_TYPE protectionType; 91 | 92 | // If the password is already encrypted, we should not encrypt it again. 93 | // An encrypted password may be received through SetSerialization in the 94 | // CPUS_LOGON scenario during a Terminal Services connection, for instance. 95 | if (CredIsProtectedW(pwzPassword, &protectionType)) 96 | { 97 | if (CredUnprotected != protectionType) 98 | { 99 | bCredAlreadyEncrypted = true; 100 | } 101 | } 102 | 103 | // Passwords should not be encrypted in the CPUS_CREDUI scenario. We 104 | // cannot know if our caller expects or can handle an encryped password. 105 | if (CPUS_CREDUI == cpus || bCredAlreadyEncrypted) 106 | { 107 | hr = SHStrDupW(pwzPassword, ppwzProtectedPassword); 108 | } 109 | else 110 | { 111 | hr = ProtectAndCopyString(pwzPassword, ppwzProtectedPassword); 112 | } 113 | } 114 | else 115 | { 116 | hr = SHStrDupW(L"", ppwzProtectedPassword); 117 | } 118 | 119 | return hr; 120 | } 121 | 122 | // 123 | // This function copies the length of pwz and the pointer pwz into the UNICODE_STRING structure 124 | // This function is intended for serializing a credential in GetSerialization only. 125 | // Note that this function just makes a copy of the string pointer. It DOES NOT ALLOCATE storage! 126 | // Be very, very sure that this is what you want, because it probably isn't outside of the 127 | // exact GetSerialization call where the sample uses it. 128 | // 129 | HRESULT UnicodeStringInitWithString( 130 | LPWSTR pwz, 131 | UNICODE_STRING* pus 132 | ) 133 | { 134 | HRESULT hr; 135 | if (pwz) 136 | { 137 | size_t lenString; 138 | hr = StringCchLengthW(pwz, USHORT_MAX, &(lenString)); 139 | 140 | if (SUCCEEDED(hr)) 141 | { 142 | USHORT usCharCount; 143 | hr = SizeTToUShort(lenString, &usCharCount); 144 | if (SUCCEEDED(hr)) 145 | { 146 | USHORT usSize; 147 | hr = SizeTToUShort(sizeof(WCHAR), &usSize); 148 | if (SUCCEEDED(hr)) 149 | { 150 | hr = UShortMult(usCharCount, usSize, &(pus->Length)); // Explicitly NOT including NULL terminator 151 | if (SUCCEEDED(hr)) 152 | { 153 | pus->MaximumLength = pus->Length; 154 | pus->Buffer = pwz; 155 | hr = S_OK; 156 | } 157 | else 158 | { 159 | hr = HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW); 160 | } 161 | } 162 | } 163 | } 164 | } 165 | else 166 | { 167 | hr = E_INVALIDARG; 168 | } 169 | return hr; 170 | } 171 | 172 | // 173 | // The following function is intended to be used ONLY with the Kerb*Pack functions. It does 174 | // no bounds-checking because its callers have precise requirements and are written to respect 175 | // its limitations. 176 | // You can read more about the UNICODE_STRING type at: 177 | // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secauthn/security/unicode_string.asp 178 | // 179 | 180 | static void _UnicodeStringPackedUnicodeStringCopy( 181 | const UNICODE_STRING& rus, 182 | LPWSTR pwzBuffer, 183 | UNICODE_STRING* pus 184 | ) 185 | { 186 | pus->Length = rus.Length; 187 | pus->MaximumLength = rus.Length; 188 | pus->Buffer = pwzBuffer; 189 | 190 | CopyMemory(pus->Buffer, rus.Buffer, pus->Length); 191 | } 192 | 193 | HRESULT KerbInteractiveUnlockLogonPack( 194 | const KERB_INTERACTIVE_UNLOCK_LOGON& rkiulIn, 195 | BYTE** prgb, 196 | DWORD* pcb 197 | ) 198 | { 199 | HRESULT hr; 200 | 201 | const KERB_INTERACTIVE_LOGON* pkilIn = &rkiulIn.Logon; 202 | 203 | // alloc space for struct plus extra for the three strings 204 | DWORD cb = sizeof(rkiulIn) + 205 | pkilIn->LogonDomainName.Length + 206 | pkilIn->UserName.Length + 207 | pkilIn->Password.Length; 208 | 209 | KERB_INTERACTIVE_UNLOCK_LOGON* pkiulOut = (KERB_INTERACTIVE_UNLOCK_LOGON*)CoTaskMemAlloc(cb); 210 | 211 | if (pkiulOut) 212 | { 213 | ZeroMemory(&pkiulOut->LogonId, sizeof(LUID)); 214 | 215 | // 216 | // point pbBuffer at the beginning of the extra space 217 | // 218 | BYTE* pbBuffer = (BYTE*)pkiulOut + sizeof(*pkiulOut); 219 | 220 | // 221 | // set up the Logon structure within the KERB_INTERACTIVE_UNLOCK_LOGON 222 | // 223 | KERB_INTERACTIVE_LOGON* pkilOut = &pkiulOut->Logon; 224 | 225 | pkilOut->MessageType = pkilIn->MessageType; 226 | 227 | // 228 | // copy each string, 229 | // fix up appropriate buffer pointer to be offset, 230 | // advance buffer pointer over copied characters in extra space 231 | // 232 | _UnicodeStringPackedUnicodeStringCopy(pkilIn->LogonDomainName, (PWSTR)pbBuffer, &pkilOut->LogonDomainName); 233 | pkilOut->LogonDomainName.Buffer = (PWSTR)(pbBuffer - (BYTE*)pkiulOut); 234 | pbBuffer += pkilOut->LogonDomainName.Length; 235 | 236 | _UnicodeStringPackedUnicodeStringCopy(pkilIn->UserName, (PWSTR)pbBuffer, &pkilOut->UserName); 237 | pkilOut->UserName.Buffer = (PWSTR)(pbBuffer - (BYTE*)pkiulOut); 238 | pbBuffer += pkilOut->UserName.Length; 239 | 240 | _UnicodeStringPackedUnicodeStringCopy(pkilIn->Password, (PWSTR)pbBuffer, &pkilOut->Password); 241 | pkilOut->Password.Buffer = (PWSTR)(pbBuffer - (BYTE*)pkiulOut); 242 | 243 | *prgb = (BYTE*)pkiulOut; 244 | *pcb = cb; 245 | 246 | hr = S_OK; 247 | } 248 | else 249 | { 250 | hr = E_OUTOFMEMORY; 251 | } 252 | 253 | return hr; 254 | } 255 | 256 | // 257 | // Initialize the members of a KERB_INTERACTIVE_UNLOCK_LOGON with weak references to the 258 | // passed-in strings. This is useful if you will later use KerbInteractiveUnlockLogonPack 259 | // to serialize the structure. 260 | // 261 | // The password is stored in encrypted form for CPUS_LOGON and CPUS_UNLOCK_WORKSTATION 262 | // because the system can accept encrypted credentials. It is not encrypted in CPUS_CREDUI 263 | // because we cannot know whether our caller can accept encrypted credentials. 264 | // 265 | HRESULT KerbInteractiveUnlockLogonInit( 266 | LPWSTR pwzDomain, 267 | LPWSTR pwzUsername, 268 | LPWSTR pwzPassword, 269 | CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 270 | BYTE** prgb, 271 | DWORD* pcb 272 | //KERB_INTERACTIVE_UNLOCK_LOGON* pkiul 273 | ) 274 | { 275 | KERB_INTERACTIVE_UNLOCK_LOGON kiul; 276 | ZeroMemory(&kiul, sizeof(kiul)); 277 | 278 | KERB_INTERACTIVE_LOGON* pkil = &kiul.Logon; 279 | 280 | // Note: this method uses custom logic to pack a KERB_INTERACTIVE_UNLOCK_LOGON with a 281 | // serialized credential. We could replace the calls to UnicodeStringInitWithString 282 | // and KerbInteractiveUnlockLogonPack with a single cal to CredPackAuthenticationBuffer, 283 | // but that API has a drawback: it returns a KERB_INTERACTIVE_UNLOCK_LOGON whose 284 | // MessageType is always KerbInteractiveLogon. 285 | // 286 | // If we only handled CPUS_LOGON, this drawback would not be a problem. For 287 | // CPUS_UNLOCK_WORKSTATION, we could cast the output buffer of CredPackAuthenticationBuffer 288 | // to KERB_INTERACTIVE_UNLOCK_LOGON and modify the MessageType to KerbWorkstationUnlockLogon, 289 | // but such a cast would be unsupported -- the output format of CredPackAuthenticationBuffer 290 | // is not officially documented. 291 | 292 | // Initialize the UNICODE_STRINGS to share our username and password strings. 293 | HRESULT hr = UnicodeStringInitWithString(pwzDomain, &pkil->LogonDomainName); 294 | if (SUCCEEDED(hr)) 295 | { 296 | hr = UnicodeStringInitWithString(pwzUsername, &pkil->UserName); 297 | 298 | if (SUCCEEDED(hr)) 299 | { 300 | if (SUCCEEDED(hr)) 301 | { 302 | hr = UnicodeStringInitWithString(pwzPassword, &pkil->Password); 303 | } 304 | 305 | if (SUCCEEDED(hr)) 306 | { 307 | // Set a MessageType based on the usage scenario. 308 | switch (cpus) 309 | { 310 | case CPUS_UNLOCK_WORKSTATION: 311 | pkil->MessageType = KerbWorkstationUnlockLogon; 312 | hr = S_OK; 313 | break; 314 | 315 | case CPUS_LOGON: 316 | pkil->MessageType = KerbInteractiveLogon; 317 | hr = S_OK; 318 | break; 319 | 320 | case CPUS_CREDUI: 321 | pkil->MessageType = (KERB_LOGON_SUBMIT_TYPE)0; // MessageType does not apply to CredUI 322 | hr = S_OK; 323 | break; 324 | 325 | default: 326 | hr = E_FAIL; 327 | break; 328 | } 329 | 330 | if (SUCCEEDED(hr)) 331 | { 332 | // KERB_INTERACTIVE_UNLOCK_LOGON is just a series of structures. A 333 | // flat copy will properly initialize the output parameter. 334 | //CopyMemory(pkiul, &kiul, sizeof(*pkiul)); 335 | } 336 | } 337 | } 338 | } 339 | 340 | const KERB_INTERACTIVE_LOGON* pkilIn = &kiul.Logon; 341 | 342 | DWORD cb = sizeof(kiul) + 343 | pkilIn->LogonDomainName.Length + 344 | pkilIn->UserName.Length + 345 | pkilIn->Password.Length; 346 | 347 | KERB_INTERACTIVE_UNLOCK_LOGON* pkiulOut = (KERB_INTERACTIVE_UNLOCK_LOGON*)CoTaskMemAlloc(cb); 348 | 349 | if (pkiulOut) 350 | { 351 | ZeroMemory(&pkiulOut->LogonId, sizeof(LUID)); 352 | 353 | // 354 | // point pbBuffer at the beginning of the extra space 355 | // 356 | BYTE* pbBuffer = (BYTE*)pkiulOut + sizeof(*pkiulOut); 357 | 358 | // 359 | // set up the Logon structure within the KERB_INTERACTIVE_UNLOCK_LOGON 360 | // 361 | KERB_INTERACTIVE_LOGON* pkilOut = &pkiulOut->Logon; 362 | 363 | pkilOut->MessageType = pkilIn->MessageType; 364 | 365 | // 366 | // copy each string, 367 | // fix up appropriate buffer pointer to be offset, 368 | // advance buffer pointer over copied characters in extra space 369 | // 370 | _UnicodeStringPackedUnicodeStringCopy(pkilIn->LogonDomainName, (PWSTR)pbBuffer, &pkilOut->LogonDomainName); 371 | pkilOut->LogonDomainName.Buffer = (PWSTR)(pbBuffer - (BYTE*)pkiulOut); 372 | pbBuffer += pkilOut->LogonDomainName.Length; 373 | 374 | _UnicodeStringPackedUnicodeStringCopy(pkilIn->UserName, (PWSTR)pbBuffer, &pkilOut->UserName); 375 | pkilOut->UserName.Buffer = (PWSTR)(pbBuffer - (BYTE*)pkiulOut); 376 | pbBuffer += pkilOut->UserName.Length; 377 | 378 | _UnicodeStringPackedUnicodeStringCopy(pkilIn->Password, (PWSTR)pbBuffer, &pkilOut->Password); 379 | pkilOut->Password.Buffer = (PWSTR)(pbBuffer - (BYTE*)pkiulOut); 380 | 381 | *prgb = (BYTE*)pkiulOut; 382 | *pcb = cb; 383 | 384 | hr = S_OK; 385 | } 386 | else 387 | { 388 | hr = E_OUTOFMEMORY; 389 | } 390 | 391 | return hr; 392 | } 393 | 394 | -------------------------------------------------------------------------------- /midl/credentialprovider.idl: -------------------------------------------------------------------------------- 1 | // 2 | // This typelib contains the CLSIDs of Microsoft's ICredentialProvider implementations. 3 | // 4 | [ 5 | uuid(d545db01-e522-4a63-af83-d8ddf954004f), // LIBID_CredentialProviders 6 | ] 7 | library CredentialProviders 8 | { 9 | cpp_quote("#include ") 10 | 11 | #pragma region Desktop Family 12 | cpp_quote("#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)") 13 | 14 | import "wtypes.idl"; 15 | import "shobjidl_core.idl"; 16 | import "propsys.idl"; 17 | import "unknwn.idl"; 18 | 19 | [v1_enum] typedef enum _CREDENTIAL_PROVIDER_USAGE_SCENARIO 20 | { 21 | CPUS_INVALID = 0, 22 | CPUS_LOGON, 23 | CPUS_UNLOCK_WORKSTATION, 24 | CPUS_CHANGE_PASSWORD, 25 | CPUS_CREDUI, 26 | CPUS_PLAP, 27 | } CREDENTIAL_PROVIDER_USAGE_SCENARIO; 28 | 29 | [v1_enum] typedef enum _CREDENTIAL_PROVIDER_FIELD_TYPE 30 | { 31 | CPFT_INVALID = 0, 32 | CPFT_LARGE_TEXT, 33 | CPFT_SMALL_TEXT, 34 | CPFT_COMMAND_LINK, 35 | CPFT_EDIT_TEXT, 36 | CPFT_PASSWORD_TEXT, 37 | CPFT_TILE_IMAGE, 38 | CPFT_CHECKBOX, 39 | CPFT_COMBOBOX, 40 | CPFT_SUBMIT_BUTTON, 41 | } CREDENTIAL_PROVIDER_FIELD_TYPE; 42 | 43 | [v1_enum] typedef enum _CREDENTIAL_PROVIDER_FIELD_STATE 44 | { 45 | CPFS_HIDDEN = 0, 46 | CPFS_DISPLAY_IN_SELECTED_TILE, 47 | CPFS_DISPLAY_IN_DESELECTED_TILE, 48 | CPFS_DISPLAY_IN_BOTH, 49 | } CREDENTIAL_PROVIDER_FIELD_STATE; 50 | 51 | [v1_enum] typedef enum _CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE 52 | { 53 | CPFIS_NONE = 0, 54 | CPFIS_READONLY, 55 | CPFIS_DISABLED, 56 | CPFIS_FOCUSED, 57 | } CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE; 58 | 59 | // 60 | // Note: values for guidFieldType used by Microsoft implementations of ICredentialProvider 61 | // can be found in shlguid.h. 62 | // 63 | typedef struct _CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR 64 | { 65 | DWORD dwFieldID; 66 | CREDENTIAL_PROVIDER_FIELD_TYPE cpft; 67 | LPWSTR pszLabel; 68 | GUID guidFieldType; 69 | } CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR; 70 | 71 | [v1_enum] typedef enum _CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE 72 | { 73 | CPGSR_NO_CREDENTIAL_NOT_FINISHED, 74 | CPGSR_NO_CREDENTIAL_FINISHED, 75 | CPGSR_RETURN_CREDENTIAL_FINISHED, 76 | CPGSR_RETURN_NO_CREDENTIAL_FINISHED, 77 | } CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE; 78 | 79 | [v1_enum] typedef enum _CREDENTIAL_PROVIDER_STATUS_ICON 80 | { 81 | CPSI_NONE = 0, 82 | CPSI_ERROR, 83 | CPSI_WARNING, 84 | CPSI_SUCCESS, 85 | } CREDENTIAL_PROVIDER_STATUS_ICON; 86 | 87 | typedef struct _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION 88 | { 89 | ULONG ulAuthenticationPackage; 90 | GUID clsidCredentialProvider; 91 | ULONG cbSerialization; 92 | [size_is(cbSerialization)] byte* rgbSerialization; 93 | } CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION; 94 | 95 | cpp_quote("#if (NTDDI_VERSION >= NTDDI_WIN8)") 96 | [v1_enum] typedef enum CREDENTIAL_PROVIDER_ACCOUNT_OPTIONS 97 | { 98 | CPAO_NONE = 0x00000000, // Default 99 | CPAO_EMPTY_LOCAL = 0x00000001, // Need to enumerate the local empty tile 100 | CPAO_EMPTY_CONNECTED = 0x00000002, // Need to enumerate the connected empty tile 101 | } CREDENTIAL_PROVIDER_ACCOUNT_OPTIONS; 102 | cpp_quote("DEFINE_ENUM_FLAG_OPERATORS(CREDENTIAL_PROVIDER_ACCOUNT_OPTIONS)") 103 | 104 | [v1_enum] typedef enum CREDENTIAL_PROVIDER_CREDENTIAL_FIELD_OPTIONS 105 | { 106 | CPCFO_NONE = 0x00000000, // Default 107 | CPCFO_ENABLE_PASSWORD_REVEAL = 0x00000001, // Enable the "password reveal" button in the modern control 108 | CPCFO_IS_EMAIL_ADDRESS = 0x00000002, // This is a email address, so set the keyboard input scope appropriately 109 | CPCFO_ENABLE_TOUCH_KEYBOARD_AUTO_INVOKE = 0x00000004, // Touch keyboard will be invoked automatically on the provider. This should be only set on the CPFG_CREDENTIAL_PROVIDER_LOGO field 110 | CPCFO_NUMBERS_ONLY = 0x00000008, // The edit field will show numbers only. This should be only set on the CPFT_PASSWORD_TEXT field 111 | CPCFO_SHOW_ENGLISH_KEYBOARD = 0x00000010, // The edit field will show English keyboard. 112 | } CREDENTIAL_PROVIDER_CREDENTIAL_FIELD_OPTIONS; 113 | cpp_quote("DEFINE_ENUM_FLAG_OPERATORS(CREDENTIAL_PROVIDER_CREDENTIAL_FIELD_OPTIONS)") 114 | cpp_quote("#endif // (NTDDI_VERSION >= NTDDI_WIN8)") 115 | 116 | // 117 | // No idl files contain NTSTATUS. Therefore we mirror its definition in ntdef.h. 118 | // 119 | cpp_quote("#ifdef __midl") 120 | typedef LONG NTSTATUS; 121 | cpp_quote("#else // __midl") 122 | cpp_quote("#ifndef NTSTATUS") 123 | cpp_quote("typedef _Return_type_success_(return >= 0) LONG NTSTATUS;") 124 | cpp_quote("#endif // NTSTATUS") 125 | cpp_quote("#endif // __midl") 126 | 127 | cpp_quote("#define CREDENTIAL_PROVIDER_NO_DEFAULT ((DWORD)-1)") 128 | 129 | interface ICredentialProviderCredentialEvents; // forward 130 | 131 | [ 132 | local, 133 | object, 134 | pointer_default(ref), 135 | uuid(63913a93-40c1-481a-818d-4072ff8c70cc), 136 | ] 137 | interface ICredentialProviderCredential : IUnknown 138 | { 139 | HRESULT Advise([in, annotation("_In_")] ICredentialProviderCredentialEvents* pcpce); 140 | HRESULT UnAdvise(); 141 | 142 | HRESULT SetSelected([out, annotation("_Out_")] BOOL* pbAutoLogon); 143 | HRESULT SetDeselected(); 144 | 145 | HRESULT GetFieldState([in] DWORD dwFieldID, 146 | [out, annotation("_Out_")] CREDENTIAL_PROVIDER_FIELD_STATE* pcpfs, 147 | [out, annotation("_Out_")] CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE* pcpfis); 148 | 149 | HRESULT GetStringValue([in] DWORD dwFieldID, [out, string, annotation("_Outptr_result_nullonfailure_")] LPWSTR* ppsz); 150 | HRESULT GetBitmapValue([in] DWORD dwFieldID, [out, annotation("_Outptr_result_nullonfailure_")] HANDLE* phbmp); 151 | HRESULT GetCheckboxValue([in] DWORD dwFieldID, [out, annotation("_Out_")] BOOL* pbChecked, [out, string, annotation("_Outptr_result_nullonfailure_")] LPWSTR* ppszLabel); 152 | HRESULT GetSubmitButtonValue([in] DWORD dwFieldID, [out, annotation("_Out_")] DWORD* pdwAdjacentTo); 153 | 154 | HRESULT GetComboBoxValueCount([in] DWORD dwFieldID, [out, annotation("_Out_")] DWORD* pcItems, [out, annotation("_Out_")] DWORD* pdwSelectedItem); 155 | HRESULT GetComboBoxValueAt([in] DWORD dwFieldID, DWORD dwItem, [out, string, annotation("_Outptr_result_nullonfailure_")] LPWSTR* ppszItem); 156 | 157 | HRESULT SetStringValue([in] DWORD dwFieldID, [in, string, annotation("_In_")] LPCWSTR psz); 158 | HRESULT SetCheckboxValue([in] DWORD dwFieldID, [in] BOOL bChecked); 159 | HRESULT SetComboBoxSelectedValue([in] DWORD dwFieldID, [in] DWORD dwSelectedItem); 160 | HRESULT CommandLinkClicked([in] DWORD dwFieldID); 161 | 162 | HRESULT GetSerialization([out, annotation("_Out_")] CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE* pcpgsr, 163 | [out, annotation("_Out_")] CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs, 164 | [out, annotation("_Outptr_result_maybenull_")] LPWSTR* ppszOptionalStatusText, 165 | [out, annotation("_Out_")] CREDENTIAL_PROVIDER_STATUS_ICON* pcpsiOptionalStatusIcon); 166 | HRESULT ReportResult([in] NTSTATUS ntsStatus, 167 | [in] NTSTATUS ntsSubstatus, 168 | [out, annotation("_Outptr_result_maybenull_")] LPWSTR* ppszOptionalStatusText, 169 | [out, annotation("_Out_")] CREDENTIAL_PROVIDER_STATUS_ICON* pcpsiOptionalStatusIcon); 170 | }; 171 | 172 | [ 173 | local, 174 | object, 175 | pointer_default(ref), 176 | uuid(9090be5b-502b-41fb-bccc-0049a6c7254b), 177 | ] 178 | interface IQueryContinueWithStatus : IQueryContinue 179 | { 180 | HRESULT SetStatusMessage([in, string, annotation("_In_")] LPCWSTR psz); 181 | }; 182 | 183 | [ 184 | local, 185 | object, 186 | pointer_default(ref), 187 | uuid(9387928b-ac75-4bf9-8ab2-2b93c4a55290), 188 | ] 189 | interface IConnectableCredentialProviderCredential : ICredentialProviderCredential 190 | { 191 | HRESULT Connect([in, annotation("_In_")] IQueryContinueWithStatus* pqcws); 192 | HRESULT Disconnect(); 193 | }; 194 | 195 | [ 196 | object, 197 | pointer_default(ref), 198 | uuid(fa6fa76b-66b7-4b11-95f1-86171118e816), 199 | ] 200 | interface ICredentialProviderCredentialEvents : IUnknown 201 | { 202 | // ICredentialProviderCredential *pcpc parameters on all methods are deprecated, should pass nullptr. 203 | HRESULT SetFieldState([in] ICredentialProviderCredential* pcpc, 204 | [in] DWORD dwFieldID, 205 | [in] CREDENTIAL_PROVIDER_FIELD_STATE cpfs); 206 | HRESULT SetFieldInteractiveState([in] ICredentialProviderCredential* pcpc, 207 | [in] DWORD dwFieldID, 208 | [in] CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE cpfis); 209 | 210 | HRESULT SetFieldString([in] ICredentialProviderCredential* pcpc, 211 | [in] DWORD dwFieldID, 212 | [in, string, unique] LPCWSTR psz); 213 | HRESULT SetFieldCheckbox([in] ICredentialProviderCredential* pcpc, 214 | [in] DWORD dwFieldID, 215 | [in] BOOL bChecked, 216 | [in] LPCWSTR pszLabel); 217 | HRESULT SetFieldBitmap([in] ICredentialProviderCredential* pcpc, 218 | [in] DWORD dwFieldID, 219 | [in] HBITMAP hbmp); 220 | 221 | HRESULT SetFieldComboBoxSelectedItem([in] ICredentialProviderCredential* pcpc, 222 | [in] DWORD dwFieldID, 223 | [in] DWORD dwSelectedItem); 224 | HRESULT DeleteFieldComboBoxItem([in] ICredentialProviderCredential* pcpc, 225 | [in] DWORD dwFieldID, 226 | [in] DWORD dwItem); 227 | HRESULT AppendFieldComboBoxItem([in] ICredentialProviderCredential* pcpc, 228 | [in] DWORD dwFieldID, 229 | [in, string] LPCWSTR pszItem); 230 | 231 | HRESULT SetFieldSubmitButton([in] ICredentialProviderCredential* pcpc, 232 | [in] DWORD dwFieldID, 233 | [in] DWORD dwAdjacentTo); 234 | HRESULT OnCreatingWindow([out] HWND* phwndOwner); 235 | }; 236 | 237 | interface ICredentialProviderEvents; // forward 238 | 239 | [ 240 | local, 241 | object, 242 | pointer_default(ref), 243 | uuid(d27c3481-5a1c-45b2-8aaa-c20ebbe8229e), 244 | ] 245 | interface ICredentialProvider : IUnknown 246 | { 247 | HRESULT SetUsageScenario([in] CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 248 | [in] DWORD dwFlags); 249 | HRESULT SetSerialization([in, annotation("_In_")] const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs); 250 | 251 | HRESULT Advise([in, annotation("_In_")] ICredentialProviderEvents* pcpe, [in, annotation("_In_")] UINT_PTR upAdviseContext); 252 | HRESULT UnAdvise(); 253 | 254 | HRESULT GetFieldDescriptorCount([out, annotation("_Out_")] DWORD* pdwCount); 255 | HRESULT GetFieldDescriptorAt([in] DWORD dwIndex, 256 | [out, annotation("_Outptr_result_nullonfailure_")] CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR** ppcpfd); 257 | 258 | HRESULT GetCredentialCount([out, annotation("_Out_")] DWORD* pdwCount, 259 | [out, annotation("_Out_")] DWORD* pdwDefault, 260 | [out, annotation("_Out_")] BOOL* pbAutoLogonWithDefault); 261 | HRESULT GetCredentialAt([in] DWORD dwIndex, 262 | [out, annotation("_COM_Outptr_")] ICredentialProviderCredential** ppcpc); 263 | }; 264 | 265 | [ 266 | object, 267 | pointer_default(ref), 268 | uuid(34201e5a-a787-41a3-a5a4-bd6dcf2a854e), 269 | ] 270 | interface ICredentialProviderEvents : IUnknown 271 | { 272 | HRESULT CredentialsChanged([in] UINT_PTR upAdviseContext); 273 | }; 274 | 275 | [ 276 | local, 277 | object, 278 | pointer_default(ref), 279 | uuid(a5da53f9-d475-4080-a120-910c4a739880), 280 | ] 281 | interface ICredentialProviderFilter : IUnknown 282 | { 283 | HRESULT Filter([in] CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, 284 | [in] DWORD dwFlags, 285 | [in, size_is(cProviders), annotation("_In_reads_(cProviders)")] GUID* rgclsidProviders, 286 | [in, out, size_is(cProviders), annotation("_Inout_updates_(cProviders)")] BOOL* rgbAllow, 287 | [in] DWORD cProviders); 288 | HRESULT UpdateRemoteCredential([in, annotation("_In_")] const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsIn, 289 | [out, annotation("_Out_")] CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsOut); 290 | }; 291 | 292 | //cpp_quote("#if (NTDDI_VERSION >= NTDDI_WIN8)") 293 | [ 294 | local, 295 | object, 296 | pointer_default(ref), 297 | uuid(fd672c54-40ea-4d6e-9b49-cfb1a7507bd7), 298 | ] 299 | interface ICredentialProviderCredential2 : ICredentialProviderCredential 300 | { 301 | HRESULT GetUserSid([out, string, annotation("_Outptr_result_maybenull_")] LPWSTR *sid); 302 | }; 303 | 304 | [ 305 | local, 306 | object, 307 | pointer_default(ref), 308 | uuid(DBC6FB30-C843-49E3-A645-573E6F39446A), 309 | ] 310 | interface ICredentialProviderCredentialWithFieldOptions : IUnknown 311 | { 312 | HRESULT GetFieldOptions([in] DWORD fieldID, 313 | [out, annotation("_Out_")] CREDENTIAL_PROVIDER_CREDENTIAL_FIELD_OPTIONS *options); 314 | }; 315 | 316 | [ 317 | object, 318 | pointer_default(ref), 319 | uuid(B53C00B6-9922-4B78-B1F4-DDFE774DC39B), 320 | ] 321 | interface ICredentialProviderCredentialEvents2 : ICredentialProviderCredentialEvents 322 | { 323 | HRESULT BeginFieldUpdates(); 324 | HRESULT EndFieldUpdates(); 325 | HRESULT SetFieldOptions([in] ICredentialProviderCredential *credential, 326 | [in] DWORD fieldID, 327 | [in] CREDENTIAL_PROVIDER_CREDENTIAL_FIELD_OPTIONS options); 328 | }; 329 | 330 | [ 331 | local, 332 | uuid(13793285-3ea6-40fd-b420-15f47da41fbb), 333 | object, 334 | pointer_default(ref), 335 | ] 336 | interface ICredentialProviderUser : IUnknown 337 | { 338 | HRESULT GetSid([out, string, annotation("_Outptr_result_nullonfailure_")] LPWSTR *sid); 339 | HRESULT GetProviderID([out, annotation("_Out_")] GUID *providerID); 340 | HRESULT GetStringValue([in, annotation("_In_")] REFPROPERTYKEY key, [out, string, annotation("_Outptr_result_nullonfailure_")] LPWSTR *stringValue); 341 | HRESULT GetValue([in, annotation("_In_")] REFPROPERTYKEY key, [out, annotation("_Out_")] PROPVARIANT *value); 342 | }; 343 | 344 | // Identity_LocalUserProvider: {A198529B-730F-4089-B646-A12557F5665E} 345 | // Define the provider GUID to pass as guidProivderToFilterTo in ICredentialProviderUserArray::SetProviderFilter() to populate local users. 346 | cpp_quote("DEFINE_GUID(Identity_LocalUserProvider, 0xA198529B, 0x730F, 0x4089, 0xB6, 0x46, 0xA1, 0x25, 0x57, 0xF5, 0x66, 0x5E);") 347 | 348 | [ 349 | local, 350 | uuid(90C119AE-0F18-4520-A1F1-114366A40FE8), 351 | object, 352 | pointer_default(ref), 353 | ] 354 | interface ICredentialProviderUserArray : IUnknown 355 | { 356 | HRESULT SetProviderFilter([in] REFGUID guidProviderToFilterTo); 357 | HRESULT GetAccountOptions([out, annotation("_Out_")] CREDENTIAL_PROVIDER_ACCOUNT_OPTIONS *credentialProviderAccountOptions); 358 | HRESULT GetCount([out, annotation("_Out_")] DWORD *userCount); 359 | HRESULT GetAt([in] DWORD userIndex, [out, annotation("_COM_Outptr_")] ICredentialProviderUser **user); 360 | }; 361 | 362 | [ 363 | local, 364 | uuid(095c1484-1c0c-4388-9c6d-500e61bf84bd), 365 | object, 366 | pointer_default(ref), 367 | ] 368 | interface ICredentialProviderSetUserArray : IUnknown 369 | { 370 | HRESULT SetUserArray([in, annotation("_In_")] ICredentialProviderUserArray *users); 371 | }; 372 | 373 | cpp_quote("#endif // (NTDDI_VERSION >= NTDDI_WIN8)") 374 | 375 | 376 | // CLSID_PasswordCredentialProvider 377 | [ uuid(60b78e88-ead8-445c-9cfd-0b87f74ea6cd) ] coclass PasswordCredentialProvider { interface ICredentialProvider; } 378 | 379 | // CLSID_V1PasswordCredentialProvider 380 | [ uuid(6f45dc1e-5384-457a-bc13-2cd81b0d28ed) ] coclass V1PasswordCredentialProvider { interface ICredentialProvider; } 381 | 382 | // CLSID_PINLogonCredentialProvider 383 | [ uuid(cb82ea12-9f71-446d-89e1-8d0924e1256e) ] coclass PINLogonCredentialProvider { interface ICredentialProvider; } 384 | 385 | // CLSID_NPCredentialProvider 386 | [ uuid(3dd6bec0-8193-4ffe-ae25-e08e39ea4063) ] coclass NPCredentialProvider { interface ICredentialProvider; } 387 | 388 | // CLSID_SmartcardCredentialProvider 389 | [ uuid(8FD7E19C-3BF7-489B-A72C-846AB3678C96) ] coclass SmartcardCredentialProvider { interface ICredentialProvider; } 390 | 391 | // CLSID_V1SmartcardCredentialProvider 392 | [ uuid(8bf9a910-a8ff-457f-999f-a5ca10b4a885) ] coclass V1SmartcardCredentialProvider { interface ICredentialProvider; } 393 | 394 | // CLSID_SmartcardPinProvider 395 | [ uuid(94596c7e-3744-41ce-893e-bbf09122f76a) ] coclass SmartcardPinProvider { interface ICredentialProvider; } 396 | 397 | // CLSID_SmartcardReaderSelectionProvider 398 | [ uuid(1b283861-754f-4022-ad47-a5eaaa618894) ] coclass SmartcardReaderSelectionProvider { interface ICredentialProvider; } 399 | 400 | // CLSID_SmartcardWinRTProvider 401 | [ uuid(1ee7337f-85ac-45e2-a23c-37c753209769) ] coclass SmartcardWinRTProvider { interface ICredentialProvider; } 402 | 403 | // CLSID_GenericCredentialProvider 404 | [ uuid(25CBB996-92ED-457e-B28C-4774084BD562) ] coclass GenericCredentialProvider { interface ICredentialProvider; } 405 | 406 | // CLSID_RASProvider 407 | [ uuid(5537E283-B1E7-4EF8-9C6E-7AB0AFE5056D) ] coclass RASProvider { interface ICredentialProvider; } 408 | 409 | // CLSID_OnexCredentialProvider 410 | [ uuid(07AA0886-CC8D-4e19-A410-1C75AF686E62) ] coclass OnexCredentialProvider { interface ICredentialProvider; } 411 | 412 | // CLSID_OnexPlapSmartcardCredentialProvider 413 | [ uuid(33c86cd6-705f-4ba1-9adb-67070b837775) ] coclass OnexPlapSmartcardCredentialProvider { interface ICredentialProvider; } 414 | 415 | // CLSID_VaultProvider 416 | [ uuid(503739d0-4c5e-4cfd-b3ba-d881334f0df2) ] coclass VaultProvider { interface ICredentialProvider; } 417 | 418 | // CLSID_WinBioCredentialProvider 419 | [ uuid(BEC09223-B018-416D-A0AC-523971B639F5) ] coclass WinBioCredentialProvider { interface ICredentialProvider; } 420 | 421 | // CLSID_V1WinBioCredentialProvider 422 | [ uuid(AC3AC249-E820-4343-A65B-377AC634DC09) ] coclass V1WinBioCredentialProvider { interface ICredentialProvider; } 423 | }; 424 | 425 | cpp_quote("#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */") 426 | #pragma endregion 427 | 428 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------