嵌入式系统NTLM/NTLMV2身份认证的C语言实现

嵌入式系统NTLM/NTLMV2身份认证的C语言实现

前一段时间在嵌入式系统下做通过 NTLM 身份认证的代理服务器上网的程序,原本可以使用ntlmaps来穿透代理服务器,但是ntlmaps依赖于python,而我的程序要在嵌入式系统( ARM7TDMI + uClinux)中运行,尝试了先移植python到目标系统中,发现占用的空间太大,只好自己用C语言实现了这个身份认证协议。主要参考了 sourceforge.net 上的
The NTLM Authentication Protocol and Security Support Provider 这篇文章(虽然是En文,但是不难理解,幸好有这篇文章,不然的话……)。 代码较多,如果有需要的话联系我: ysb148@tom.com

 

关于NTLM 的更多内容可以上google搜索,很多这方面的信息。

本文原文在我的blog :www.info-life.cn

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HTTP PROXY中NTLM的客户端的C源代码。包含相关的DES等算法在内。Base64的算法,是通过网上共产主义获取,MD4,MD5,HMAC MD5的算法是RFC中提供的,其余的可以根据下面链接的步骤进行编写。我提供一个源代码的例子。其中arith_开头的相关算法,httppc_ntlmNTLM的type1、type2、type3消息的应答构成,test_httppc_connect是一个测试的例子,里面没有main函数,但是另外构造一个main函数,在wei_set_proxy_info之后,调用wei_httppc_connect就可以了。详细见http://blog.csdn.net/flowingflying/archive/2009/03/03/3952796.aspx 有朋友说少了头文件,我查了一下,不好意思,少了md.h。请参考下面。 /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved. License to copy and use this software is granted provided that it is identified as the "RSA Data Security, Inc. MD4 Message-Digest Algorithm" in all material mentioning or referencing this software or this function. License is also granted to make and use derivative works provided that such works are identified as "derived from the RSA Data Security, Inc. MD4 Message-Digest Algorithm" in all material mentioning or referencing the derived work. RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided "as is" without express or implied warranty of any kind. These notices must be retained in any copies of any part of this documentation and/or software. */ #ifdef __cplusplus extern "C" { #endif #ifndef WEI_MD_H #define WEI_MD_H #ifndef IN #define IN #endif #ifndef OUT #define OUT #endif /************************************ 算法:MD4和MD5 *********************************/ //从RFC1320 The MD4 Message-Digest Algorithm的附录 //从RFC1321 The MD5 Message-Digest Algorithm的附录 /* PROTOTYPES should be set to one if and only if the compiler supports function * argument prototyping.The following makes PROTOTYPES default to 0 if it has not * already been defined with C compiler flags. */ #ifndef PROTOTYPES #define PROTOTYPES 0 #endif /* POINTER defines a generic pointer type */ typedef unsigned char * POINTER; /* UINT2 defines a two byte word */ typedef unsigned short int UINT2; /* UINT4 defines a four byte word */ typedef unsigned long int UINT4; /* PROTO_LIST is defined depending on how PROTOTYPES is defined above.If using PROTOTYPES, * then PROTO_LIST returns the list, otherwise it returns an empty list. */ #if PROTOTYPES #define PROTO_LIST(list) list #else #define PROTO_LIST(list) () #endif /* MD4 context. */ typedef struct { UINT4 state[4]; /* state (ABCD) */ UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ unsigned char buffer[64]; /* input buffer */ } MD4_CTX; void MD4Init PROTO_LIST ((MD4_CTX *)); void MD4Update PROTO_LIST ((MD4_CTX *, unsigned char *, unsigned int)); void MD4Final PROTO_LIST ((unsigned char [16], MD4_CTX *)); /* MD5 context. */ typedef struct { UINT4 state[4]; /* state (ABCD) */ UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ unsigned char buffer[64]; /* input buffer */ } MD5_CTX; void MD5Init PROTO_LIST ((MD5_CTX *)); void MD5Update PROTO_LIST ((MD5_CTX *, unsigned char *, unsigned int)); void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *)); #endif #ifdef __cplusplus } #endif 因为我没有认真地打包封装,而是从我的一个project中抽出了,有些遗漏,请大家原谅。今天又有网友来问PRIVATE在哪里定义。因为代码不在手头的机器上,没法仔细看,PRIVATE的定义如下 #define PRIVATE 定义为空,这是模仿C++的private,说明这个函数不会被其他文件引用,只用于本文件。 最近又收到网友的来信,说少了几个util文件。这个是不在ntlm的算法中,而是在验证例子test_httppc_connect.cpp中使用。查了一下,我确实没有放到网上。汗啊,因为验证例子是从某个程序中抽取出来,里面包含一个很简单的http的解析。我本来想update资源,没有找到 update的方法。需要说明的是这部分和真正的算法没有直接关系。放在这里,太长了,如果需要的网友,请到http://blog.csdn.net/flowingflying/archive/2009/03/03/3952796.aspx 那里下载。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值