<meta name="ProgId" content="Word.Document"> <meta name="Generator" content="Microsoft Word 11"> <meta name="Originator" content="Microsoft Word 11"> <link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C03%5Cclip_filelist.xml"> <link rel="Edit-Time-Data" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C03%5Cclip_editdata.mso"> <!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--><!--[if gte mso 9]><xml> <w:worddocument> <w:view>Normal</w:view> <w:zoom>0</w:zoom> <w:punctuationkerning/> <w:drawinggridverticalspacing>7.8 磅</w:drawinggridverticalspacing> <w:displayhorizontaldrawinggridevery>0</w:displayhorizontaldrawinggridevery> <w:displayverticaldrawinggridevery>2</w:displayverticaldrawinggridevery> <w:validateagainstschemas/> <w:saveifxmlinvalid>false</w:saveifxmlinvalid> <w:ignoremixedcontent>false</w:ignoremixedcontent> <w:alwaysshowplaceholdertext>false</w:alwaysshowplaceholdertext> <w:compatibility> <w:spaceforul/> <w:balancesinglebytedoublebytewidth/> <w:donotleavebackslashalone/> <w:ultrailspace/> <w:donotexpandshiftreturn/> <w:adjustlineheightintable/> <w:breakwrappedtables/> <w:snaptogridincell/> <w:wraptextwithpunct/> <w:useasianbreakrules/> <w:dontgrowautofit/> <w:usefelayout/> </w:compatibility> <w:browserlevel>MicrosoftInternetExplorer4</w:browserlevel> </w:worddocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:latentstyles deflockedstate="false" latentstylecount="156"> </w:latentstyles> </xml><![endif]--><style> <!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"\@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} h4 {mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; mso-outline-level:4; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:宋体;} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} pre {margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:宋体;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->
Windows Credential Management with the .net Framework 2.0
Kenny kerr
January 2006
Applies to:
Microsoft .NET Framework 2.0
NET Framework Security
Windows XP
概叙:这篇文章主要是介绍Credential Management API怎样处理界面和用户的凭证集合。同时也提供了一个能够做一些简单凭证管理的类库,可以被c#和vb.net调用。
下载相关的例程:KerrCredentialsSample.exe
内容
介绍
请求凭证
托管代码的请求凭证
一个工具:请求凭证生成器
SecureString 基础
凭证集合
在托管代码中使用凭证集合
工具:凭证集合管理器
结论
介绍
管理用户凭证是一件非常困难的事情。理想上你的windows域凭证应该有足够的权限来访问你可能需要的资源。但是有这么简单吗?你可能不可避免的要去处理不同的安全权限,包括 windows域,Microsoft Passport和应用程序指定的验证策略。好像那些还不够挑战,凭证可能来自不同的form,包括smart cards, certificates 和密码。
自从2001年windows xp发布,windows包含了credential management api去管理用户凭证。这些api 的设计是为了简化内部程序用户凭证管理,也为你自己的相关凭证管理提供了一致的安全的方法。她也可以被用来请求不需要被持久化的凭证,或者持久化你的应用程序的凭证,比如用数据保护api(Data Protection API).
在这篇文章我会介绍windows credential management api, 包括界面处理,凭证集合管理。介绍这些api的一个挑战是依赖你的背景知识和你怎么去用她,这些是一个c-style 的api,适用于visual c++或者任何一款支持windows的编译器。因为流行.net 框架的原因,一个理想的解决方案还应该包括.net 框架的支持托管代码的集合。所以也提供了一个功.net 框架调用的类库。
最后要说明的是: 当我解释windows credential management用到的不同的函数,结构,也包括列在表格中的相关的选项,标志和属性。虽然这些选项我的解释很多都是依赖与sdk和msndn类库,但是我不止是简单的从文档中copy说明,我是尽力想你说明她的一些你可能不能完全掌握的细节。这些都是基于我写credential management经验的积累。
请求凭证
如果你所需要得是你得域凭证,那么你不需要请求凭证。因为在你登陆会话时已经被验证,你可以访问你可能能访问的所有资源。明显的这是一个不现实的例子。所以你需要请求用户的凭证。在过去,不用的应用程序创建不用的用户界面来请求用户的凭证,但是在windows xp上,应用程序可以依靠内建的,简单的,安全的用户界面给用户输入。
Windows提供了CredUIPromptForCredentials函数显示一个可以配置的窗体去接收用户的凭证信息。
DWORD WINAPI CredUIPromptForCredentialsW(PCREDUI_INFOW info,
PCWSTR targetName,
PCtxtHandle reserved,
DWORD errorCode,
PWSTR userName,
ULONG userNameBufferSize,
PWSTR password,
ULONG passwordBufferSize,
PBOOL saveChecked,
DWORD flags);
因为这篇文章不是关于用c或者非托管的c++来管理用户凭证,所以我不对这个函数做过多细节的描叙。
第一个参数只向一个CREDUI_INFO结构的指针,它允许你指定它的父窗体和默认的图标,标题,信息。
targetName参数用来读取和写入凭证时的唯一定义,也被用来作为标题和信息的一部分,如果CREDUI_INFO没有被重写的话,晚些在我们讨论persisting凭证的时候你会对她认识的更深刻。
Errorcode 参数允许窗体提供相应的错误代码,但是sdk没有提供相应的链接,所以这个参数几乎没什么用。
username 和 userNameBufferSize参数用来指定初始化时的用户名。相应的password和passwordBufferSize用来指定初始化的用户密码。这些使得用c和非托管的c++编程相当困难,你必须非常小心的处理这些字符串,像你在下一章看到的,托管代码可以非常简单的写出非常优秀的代码。
这个窗体可以显示一个check box提供给用户来选择是否保存凭证。saveChecked 参数就是用来初始化这个check box 的状态用的。这个check box也可以在用户关闭窗体的时候来判断用户的喜好。注意的是这个参数被忽略,当凭证不是generic凭证的时候。
最好,falgs参数允许你指定一个联合的标识。这里的问题是错误的混合不同的标识也会导致程序的错误。
相比探索这个函数的更多细节,我将会提供一些为简单任务的解决方案给你,用托管代码写的。在那之前,我们先来看一看一个用C++写的例子。这个例子调用CredUIPromptForCredentials
CREDUI_INFO info = { sizeof (CREDUI_INFO) };
info.hwndParent = GetSafeHwnd();
info.pszCaptionText = L"Title";
info.pszMessageText = L"Message";
CBitmap bitmap;
VERIFY(bitmap.LoadBitmap(IDB_PROMPT_BITMAP));
info.hbmBanner = bitmap;
CString target;
const DWORD errorCode = 0;
wchar_t userName[CREDUI_MAX_USERNAME_LENGTH + 1] = { 0 };
wcscpy_s(userName,
_countof(userName),
L"initial user name");
wchar_t password[CREDUI_MAX_PASSWORD_LENGTH + 1] = { 0 };
BOOL saveChecked = false;
Const DWORD flags = CREDUI_FLAGS_DO_NOT_PERSIST |
CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX ;
DWORD result = ::CredUIPromptForCredentials(&info,
target,
0, // reserved
errorCode,
userName,
_countof(userName)
password,
_countof(password)
&saveChecked,
flags);
switch (result)
{
case NO_ERROR:
{
// User chose OK...
break;
}
case ERROR_CANCELLED:
{
// User chose Cancel...
break;
}
default:
{
// Handle all other errors...
}
}
::SecureZeroMemory(password,
sizeof (password));
这段代码的结果是显示一下的窗体:
<!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="_x0000_i1025" type="#_x0000_t75" style="'width:246pt; height:218.25pt'"> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\03\clip_image001.png" o:title=""/> </v:shape><![endif]--><!--[if !vml]--><!--[endif]-->
正像你所看到的,有一大段代码是为了调用这个函数不会出错,首先,你要熟悉结构CREDUI_INFO去控制这个窗体的不同元素。接下来,你要为接收的用户名合密码准备缓冲区。和显示初始值。CREDUI_MAX_USERNAME_LENGTH常量表示用户名的最大长度。相同的CREDUI_MAX_PASSWORD_LENGTH表示密码的可能最大长度。在用户名和密码长度后面加1是为了加上介绍字符串NULL, 调用wcscpy_s函数是为了显示用户名和密码的初始值。最后,我指定了两个标识,意思是,我不想persist 这个凭证但是我想让保存密码的check box 显示。saveChecked将会包括用户的选项。
显然在这里你很容易出错。
请求凭证,用托管代码
因为CredUIPromptForCredentials
[C++]
ref class MainWindow : Windows::Forms::Form
{
public:
void Prompt()
{
PromptForCredentials dialog;
dialog.Title = "Title";
dialog.Message = "Message";
dialog.Banner = Images::Banner;
dialog.UserName = "initial user name";
dialog.DoNotPersist = true;
dialog.ShowSaveCheckBox = true;
if (Windows::Forms::DialogResult::OK == dialog.ShowDialog(this))
{
// Use credentials wisely...
}
}
};
[C#]
class MainWindow : Form
{
public void Prompt()
{
using (PromptForCredentials dialog = new PromptForCredentials())
{
dialog.Title = "Title";
dialog.Message = "Message";
dialog.Banner = Images.Banner;
dialog.UserName = "initial user name";
dialog.DoNotPersist = true;
dialog.ShowSaveCheckBox = true;
if (DialogResult.OK == dialog.ShowDialog(this))
{
// Use credentials wisely...
}
}
}
}
发表评论
-
STL 中Map容器的跨动态库调用 zz
2007-03-29 16:06 628主题:STL 中Map容器的跨 ... -
VC8 VS VC6
2007-05-20 14:22 670VC8 VS VC6 Why need we migrat ... -
new delete 非常奇怪的内存问题
2007-06-06 12:14 673代码如下:<!--<br><br> ... -
Navigate2 compare with Navigate
2007-08-17 19:43 890CWebBrowser2 ctrl provide two m ... -
Contribute some useful custom control: XListCtrl
2007-08-24 11:22 859In my VC MFC develop expericenc ... -
boost 的安装
2007-10-15 16:35 669vc8 下用到boost 类库,没找到安装的办法,google ... -
注册表操作类 vc++
2008-04-18 17:12 671这个其实发在这里有点不合适,因为在.NET环境下本身很多数据 ...
相关推荐
适合车联网安全的初学者,详细描述了车联网安全消息及处理流程,非常实用,网上很稀有,欢迎大家下载学习,也欢迎大家一起交流国内外车联网发展趋势
换句话说,如果你的项目使用OWIN实现OAuth 2.0 之客户端模式,但是没有配置machineKey,也没有在认证服务中自定义认证。那么我就可以利用OWIN实现OAuth 2.0 之客户端模式的基本原理生成一个token,你会发现我这个...
该文件简称“GCMW-1.20.0.exe”,是微软官方提供的为了解决“git push命令出现HttpRequestException encountered”的问题的软件,github:https://github.com/microsoft/Git-Credential-Manager-for-Windows,下载页...
Credential Provider : 自定义windows登录 修改Register.reg中CredentialProvider dll的文件路径,双击注册. 实现了标准的Credential Provider的登录机制. 安装此Provider,会自动屏蔽windows原有的登录入口, 如果...
The control users (or the Page developers) must provide an event handler for Logon event so the form s Postback can authenticate the user input credential. An optional Register button can be ...
windows cp 认证代码 Credential_Provide
英文版的大项目经理认证手册Program management professional credential handbook,权威!
Git for Windows now ships with the Git Credential Manager for Windows. bug修复: We now handle UTF-8 merge and squash messages correctly in Git GUI. When trying to modify a repository config outside ...
This is a complete study guide for candidates wishing to sit and pass the Project Management Professional (PMP) credential from the Project Management Institute (PMI). Pass the PMP Exam contains all ...
Windows的Git Credential Manager已不再维护。 跨平台的是官方的替代品。 GCM Core作为Windows 2.28的Git的可选组件包括在内,它将成为Windows 2.29的Git的默认凭据帮助程序。 也可以从此手动安装GCM Core。 注意...
4. Populate InitAllApplications.xaml from the Framework folder with Invoking the Login to ACME and navigation to the Work Items. 5. Populate CloseAllApplications.xaml from the Framework folder with ...
Design of a Role-based Trust-management Framework Abstract We introduce the RT framework, a family of Rolebased Trust-management languages for representing policies and credentials in distributed ...
语言:English (United States) 提供将凭证(如证书)的凭据置入智能卡等...WorkforceID Digital Credential Manager使组织能够从基于云的解决方案中发行和管理凭据(智能卡,USB令牌)。 浏览器扩展用于连接到凭据。
Git for Windows now ships with the Git Credential Manager for Windows. bug修复: We now handle UTF-8 merge and squash messages correctly in Git GUI. When trying to modify a repository config outside ...
CredProvider.NET 用C#编写的Windows凭据提供程序入门看到这个
Git Credential Manager for Windows 提供安全的 Git 认证存储,是 Windows Credential Store for Git (git-credential-winstore) 的成功实践,不过 git-credential-winstore 已经不再维护了。相比 Windows 平台 Git...
但是,.NET 框架中有适用于 Windows 8 StoreApops 的类,它不仅允许 StoreApps,还允许 PowerShell 超级轻松地管理其凭据。 用法 设置凭据 下面的示例代码会将您的凭据保存为 hoge。 Set-WindowsCredential - ...