China Open source community
站内导航:
站内排行前50热点文章

精华文章  GDB调试精粹及使用实例
普通文章  STL中map用法详解
精华文章  负载均衡软件比较(Hapr...
普通文章  头文件的重复引用
普通文章  递归函数的调用过程
普通文章  TCP三次握手/四次挥手详解
普通文章  贪心策略的理论基础——...
普通文章  BMH算法原理与实现(模...
普通文章  排列组合与回溯算法
普通文章  DP动态规划
精华文章  Android线程模型
普通文章  Linux socket编程之套接字
普通文章  Linux内核中的红黑树
精华文章  linux下使用minicom的几...
普通文章  Java开源Html解析类库
精华文章  enum类型的本质
普通文章  memcached server LRU ...
普通文章  linux设置环境变量的方法
普通文章  android核心模块及相关...
普通文章  linux源代码包(.tar.g...
普通文章  L.A.M.P配置过程
普通文章  在ubuntu9.10下安装QT4...
普通文章  C/C++程序员常见面试题...
普通文章  gcc编译过程概述
普通文章  python的memcache和jso...
普通文章  应用程序二进制接口---ABI
普通文章  linux内核编译问题
普通文章  Java多线程实现简单实例
普通文章  Python程序员常用的IDE...
普通文章  brk和sbrk详述
普通文章  优化C语言代码(程序员必...
普通文章  python非贪婪,多行匹配...
普通文章  函数指针传递和全局指针...
普通文章  Unix操作系统的历史演变
普通文章  网络编程之C10K问题
普通文章  发行版发布:CentOS 5.4
普通文章  在windows中构建gtk开发...
普通文章  i++循环与i--循环的执行...
普通文章  关于Qvariant类--万能的...
普通文章  Debian sudo 设置
普通文章  busybox1.15.x 交叉编译
普通文章  关于僵死进程zombie
普通文章  递归思想的妙用
普通文章  判断链表是否存在环并找...
普通文章  Android Porting Exper...
普通文章  关于/etc/bashrc和$HOM...
普通文章  [翻译]Django初窥
普通文章  Python list的排序
普通文章  Django实现大数据量分页...
普通文章  Debug方式取代printf满...

 
 
 
当前位置: 首页 >> 应用软件 >> 网络相关 >> OpenVPN在Windows下使用User/Pass验证
 
 

OpenVPN在Windows下使用User/Pass验证

作者:wenzk      来源:cublog     发表时间:2006-07-27     浏览次数:      字号:    

OpenVPN在Windows下使用User/Pass验证

对于Windows下使用User/Pass验证已经是很久以前的承诺了,因为一开始一直都是在找寻
使用CMD(bat)文件检查用户名/密码的方式,但是一直没有结果,最后使用C写了一个小程
序实现用户名/密码验证。

转载请注明出处,如有疑问访问: http://wenzk.cublog.cn 反馈。

Windows安装OpenVPN是很容易的,OpenVPN GUI下载网址:
http://openvpn.se/files/install_packages/openvpn-2.0.7-gui-1.0.3-install.exe

记得选上easy-rsa这部分脚本,安装完毕后,easy-rsa在C:\Program Files\OpenVPN\目录下。

把easy-rsa目录下的vars.bat.sample改名为vars.bat,并且修改其内容:
==================================
set KEY_COUNTRY=CN
set KEY_PROVINCE=Liaoning
set KEY_CITY=Shenyang
set KEY_ORG=OpenVPN
set KEY_EMAIL=elm@elm.freetcp.com
==================================
其它部分就不用修改了,上面部分修改成你自己的配置。

把easy-rsa下的openssl.cnf.sample改成openssl.cnf。

然后进入cmd.exe
=============================================
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>cd "\Program Files\OpenVPN\easy-rsa"

C:\Program Files\OpenVPN\easy-rsa>vars

C:\Program Files\OpenVPN\easy-rsa>clean-all.bat
系统找不到指定的文件。
已复制         1 个文件。
已复制         1 个文件。

C:\Program Files\OpenVPN\easy-rsa>

生成Root CA
格式: build-ca.bat
输出: keys/ca.crt keys/ca.key
======================================================================
C:\Program Files\OpenVPN\easy-rsa>build-ca.bat
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
................................................................................
....++++++
....................................++++++
writing new private key to 'keys\ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [OpenVPN]:
Organizational Unit Name (eg, section) []:OpenVPN ORG
Common Name (eg, your name or your server's hostname) []:OpenVPN ROOTCA
Email Address [elm@elm.freetcp.com]:


生成dh1024.pem文件,Server使用TLS必须使用的一个文件。
格式: build-dh.bat
输出: keys/dh1024.pem
============================================================================
C:\Program Files\OpenVPN\easy-rsa>build-dh.bat
Loading 'screen' into random state - done
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
............................................................+.................+.
................................................................................
................................................................................
....+..................+...........................+..........................+.
.........................+............................+.+.......................
............................................+......+...+...............+........
..+...........+............+.....................+...+.........................+
.....+..............................................................+...........
...............+....................................+.......................+...
.....................................................+..........................
..................................................+.............................
......................................+..............+.+........................
+..........................................................................+....
................................................................+...............
......................................+...+.............................+.......
............+...........+................+......................................
.........+...........................................+..........................
................................................................................
.+.......+....+..............+..................................................
.........................................................................+......
..........+.....................................................................
................................................................................
...........................+....................................................
........+.......................................................................
...................................................+..............+.........+...
........................................+.........+...................+.........
.............+.......+..........+............+................+.................
................................................................................
................................................................................
.................................+.................................++*++*++*

C:\Program Files\OpenVPN\easy-rsa>

下面开始生成Server使用的证书:
格式: build-key-server.bat <filename>
输出: keys/<filename>.crt <filename>.csr <filename>.key
================================================================================
C:\Program Files\OpenVPN\easy-rsa>build-key-server.bat server01
Loading 'screen' into random state - done
Generating a 1024 bit RSA private key
...............++++++
...........++++++
writing new private key to 'keys\server01.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:
State or Province Name (full name) [Liaoning]:
Locality Name (eg, city) [Shenyang]:
Organization Name (eg, company) [OpenVPN]:
Organizational Unit Name (eg, section) []:OpenVPN ORG
Common Name (eg, your name or your server's hostname) []:Server01
Email Address [elm@elm.freetcp.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from openssl.cnf
Loading 'screen' into random state - done
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'CN'
stateOrProvinceName   :PRINTABLE:'Liaoning'
localityName          :PRINTABLE:'Shenyang'
organizationName      :PRINTABLE:'OpenVPN'
organizationalUnitName:PRINTABLE:'OpenVPN ORG'
commonName            :PRINTABLE:'Server01'
emailAddress          :IA5STRING:'elm@elm.freetcp.com'
Certificate is to be certified until Jul  7 13:33:23 2016 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

C:\Program Files\OpenVPN\easy-rsa>

下面生成ta.key文件
格式: openvpn --genkey --secret keys/ta.key
输出: keys/ta.key
=========================================================================
C:\Program Files\OpenVPN\easy-rsa>openvpn --genkey --secret keys/ta.key

C:\Program Files\OpenVPN\easy-rsa>

OK,那些keys就搞定了,下面开始写配置文件。
server01.ovpn内容:
----------------CUT Here-------------
port 1194
; proto tcp
proto udp
; dev tap
dev tun
;dev-node MyTap
ca ca.crt
cert server01.crt
key server01.key  # This file should be kept secret
dh dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
client-to-client
;duplicate-cn
keepalive 10 120
tls-auth ta.key 0 # This file is secret
auth-user-pass-verify checkpsw.exe via-env
client-cert-not-required
username-as-common-name
;cipher BF-CBC        # Blowfish (default)
;cipher AES-128-CBC   # AES
;cipher DES-EDE3-CBC  # Triple-DES
comp-lzo
;max-clients 100
user nobody
group nobody
persist-key
persist-tun
status status.log
;log         /var/log/openvpn.log
;log-append  /var/log/TCP_openvpn.log
verb 4
;mute 20
----------------CUT Here-------------
把配置文件放到C:\Program Files\OpenVPN\config\目录下。
把easy-rsa\keys\下的 ca.crt server01.crt server01.key ta.key dh1024.pem
复制到server01.ovpn所在目录。

同时下载本人写的破烂验证程序(checkpsw.exe)[不要仍砖块]放到OpenVPN配置目录下
程序在Windows XP SP2下测试通过,其他系统如果有问题,可以用源文件进行编译
程序在压缩包里面:
文件: checkpsw.rar
大小: 9KB
下载: 下载

在checkpsw.exe目录下建立password.txt[用于存放用户名&密码]文件:
password.txt文件格式:
用户名           密码            是否活动(0/1) 中间用空格隔开
Username     Password    Active
-------------Cut Here---------------------
wzk         wzk         1
-------------Cut Here---------------------



Server的配置已经结束,可以启动Server了,在右下角OpenVPN-gui上点右键,然后选择connected。
需要服务器启动后自动运行,修改 "控制面板" 下面的 "管理工具" 下的 "服务" 把OpenVPN设置成自动启动。

Client的配置文件:
client.ovpn
-------------Cut Here---------------------
client
dev tun
proto udp

remote 61.1.1.2 1194
;remote my-server-2 1194

;remote-random

resolv-retry infinite
nobind
user nobody
group nobody
route 192.168.0.0 255.255.252.0
persist-key
persist-tun

;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

ca ca.crt
auth-user-pass

ns-cert-type server
tls-auth ta.key 1
comp-lzo
# Set log file verbosity.
verb 4
--------------Cut Here---------------------
并且把easy-rsa/keys下的ca.crt ta.key一起放到Client的
<OPENVPN_HOME>\config目录下。

Client的配置已经结束,可以连接Server了,在右下角OpenVPN-gui上点右键,然后选择connected。


OK,整个配置就完成了。

编辑 webmaster

 
 
 
评论
 
非常好 The countryName field needed to be the same in the CA certificate (cn) and the request (CN) 找不到 C:\Program Files\OpenVPN\easy-rsa\keys\*.old 这是什么错误! The countryName field needed to be the same in the CA certificate (cn) and the request (CN) 找不到 C:\Program Files\OpenVPN\easy-rsa\keys\*.old 这是什么啊!
 
发表
 
姓名: QQ:
性别: MSN:
E-mail: 主页:
评分: 1 2 3 4 5
评论内容:
验证码:
  
  • 请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
  • 严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容的评论 。
  • 用户需对自己在使用本站服务过程中的行为承担法律责任(直接或间接导致的)。
  • 本站管理员有权保留或删除评论内容。
  • 评论内容只代表网友个人观点,与本网站立场无关。
  •  
    中国源码网 - www.YuanMa.org - 中国 开放源代码+编程 社区