Archive for 10月, 2007

配置windows下的curl来获取https页面内容

星期五, 10月 26th, 2007

刚刚看到了javayou提到了可以在windows下使用的curl命令,
http://www.javayou.com/html/diary/showlog.vm?sid=2&log_id=13985

于是下载了支持ssl的curl来使用:
下载连接为: http://www.execve.net/--escaped_anchor:5d46c217459898ec8972155e71509b97--/curl-7.17.0-win32-ssl.zip

解压到D:\Programs\curl-7.17.0
下载OpenSSL组件:
http://618119.com/--escaped_anchor:5e81b97d5483ae9cc4d410a319552617--/libeay32.dll
http://618119.com/--escaped_anchor:5e81b97d5483ae9cc4d410a319552617--/libssl32.dll
libssl32.dll和libeay32.dll复制到D:\Programs\curl-7.17.0,

否则运行curl.exe会被提示:

—————————
curl.exe - 无法找到组件
—————————
没有找到 libeay32.dll,因此这个应用程序未能启动。重新安装应用程序可能会修复此问题。
—————————
确定
—————————

—————————
curl.exe - 无法找到组件
—————————
没有找到 libssl32.dll,因此这个应用程序未能启动。重新安装应用程序可能会修复此问题。
—————————
确定
—————————
(参考: http://618119.com/archives/2007/10/26/15.html)
如果需要连接的网站使用的证书不是操作系统已经信任的证书,则需要指定ca根证书文件.
并且服务器的证书CN必须与url里的host一致,否则无法下载.

测试命令示例如下:

curl https://www.google.com/

curl https://www.618119.com/

curl https://lizongbo.618119.com/cacert ca.crt

D:\Programs\curl-7.17.0>curl https://www.google.com/
<HTML><HEAD><meta http-equiv=”content-type” content=”text/html;charset=utf-8″>
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A href=”http://www.google.com”>here</A>.
</BODY></HTML>

D:\Programs\curl-7.17.0>curl https://618119.com/
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify faile
d
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a “bundle”
of Certificate Authority (CA) public keys (CA certs). The default
bundle is named curl-ca-bundle.crt; you can specify an alternate file
using the –cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you’d like to turn off curl’s verification of the certificate, use
the -k (or –insecure) option.

D:\Programs\curl-7.17.0>curl https://lizongbo.618119.com/cacert ca.crt
curl: (51) SSL: certificate subject name ‘618119.com’ does not match target host name ‘lizongbo.618119.com’

Tags: cacert, curl, libssl32.dll, openssl

Related posts

关于OpenSSL里libssl32.dll与ssleay32.dll的区别

星期五, 10月 26th, 2007

现在很多程序都提供了ssl功能,但是在安装程序中并未自带OpenSSL组件,需要额外下载,因此选择不同版本OpenSSL的时候,可能会遇到如下的错误信息:

—————————
curl.exe - 无法找到组件
—————————
没有找到 libssl32.dll,因此这个应用程序未能启动。重新安装应用程序可能会修复此问题。
—————————
确定
—————————

或者:

—————————
lighttpd.exe - 无法找到组件
—————————
没有找到 SSLEAY32.dll,因此这个应用程序未能启动。重新安装应用程序可能会修复此问题。
—————————
确定
—————————

网上相关的问题有:
http://curl.haxx.se/mail/archive-2002-09/0063.html

libssl32.dllssleay32.dll的实际内容是没有任何区别,只是openssl在版本升级之后,
将在win32平台上编译生成的文件名libssl32.dll修改成了ssleay32.dll,libeay32.dll的名字则没改变.
(OpenSSL的changelog里并没有提到文件名变化的问题,参见: http://www.--escaped_anchor:50fe2dfc15a50670285e5a19657fe3b0--.org/news/changelog.html )
而很多依赖openssl的程序里,在加载OpenSSL的dll时,使用了固定的文件名字.只加载libssl32.dll或者ssleay32.dll,
因此在找不到文件的时候不会尝试另外一个文件名,就直接提示出错信息.

解决的办法也很简单,就是根据程序需要调用的dll名字,将libssl32.dll修改成ssleay32.dll,或者将ssleay32.dll修改成libssl32.dll.

对于开发者来说,为了让使用者少走弯路,在加载dll的时候,代码可以改成下面这个样子:
(参考这里的讨论: http://forums.miranda-im.org/showthread.php?t=4545)
if (( hLibSSL = LoadLibrary( “SSLEAY32.DLL” )) == NULL ) {
if (( hLibSSL = LoadLibrary( “LIBSSL32.DLL” )) == NULL ) { //the oldname

MSN_ShowError( “Valid %s must be installed to perform the SSL login”, “SSLEAY32.DLL” );
return 1;
}       } }

OpenSSL当前最新版本为OpenSSL 0.9.8g ,也就是OpenSSL 0.9.8.7 ,
编译好的 dll文件可以在这里下载
http://www.apachelounge.com/download/binaries/OpenSSL_0.9.8g.zip
来源: http://www.apachelounge.com/download/

如果只想下载就使用,懒得重命名的话:
可以直接下载我放在服务器上的文件:
(libssl32.dllssleay32.dll是一样的)
http://618119.com/--escaped_anchor:5e81b97d5483ae9cc4d410a319552617--/libeay32.dll
http://618119.com/--escaped_anchor:5e81b97d5483ae9cc4d410a319552617--/libssl32.dll
http://618119.com/--escaped_anchor:5e81b97d5483ae9cc4d410a319552617--/ssleay32.dll

除了将OpenSSL的dll加载的方式来使用OpenSSL,也可以采取直接编译进程序的方法来使用OpenSSL,比如
Tomcat的APR组件,就是将APR和OpenSSL直接编译进来,使用非常方便:
参考: http://tomcat.apache.org/tomcat-6.0-doc/apr.html

Tags: libssl32.dll, openssl, ssleay32.dll, win32

Related posts

Windows系统中使用jvmstat查看Java虚拟机信息

星期四, 10月 25th, 2007

0.jdk必须1.5以上,临时文件夹所在的磁盘分区必须为NTFS格式 (命令行下用 set PATH 察看临时文件夹)

1.下载jvmstat-3_0.zip
参考http://java.sun.com/performance/jvmstat/#Download

2.解压到:E:\Java\jvmstat

3.启动tomcat ,然后在任务管理器中查看到进程id(例如3866)
(或者使用jps命令)

4.启动 E:\Java\jvmstat\bat>visualgc.cmd 3866

5.新出现的三个图形窗口有统计数据.

参考:http://java.sun.com/performance/jvmstat/windows.html

http://java.sun.com/performance/jvmstat/faq.html

命令行执行示例:

D:\Documents and Settings\lizongbo>set TMP
TMP=D:\DOCUME~1\lizongbo\LOCALS~1\Temp

D:\Documents and Settings\lizongbo>set TEMP
TEMP=D:\DOCUME~1\lizongbo\LOCALS~1\Temp

D:\Documents and Settings\lizongbo>cd D:\Java\jvmstat\bat

D:\Java\jvmstat\bat>d:

D:\Java\jvmstat\bat>jps
1212 Jps

D:\Java\jvmstat\bat>jps
1896
1088 Jps

D:\Java\jvmstat\bat>visualgc.cmd 1896

在启动的信息窗口中,可以得到的相关信息

Java Command Line:

Java VM Arguments: -Dexe4j.isInstall4j=true -Dexe4j.moduleName=D:\Java\DbVisualizer-6.0.6\dbvis.exe -Dexe4j.tempDir= -Dexe4j.unextractedPosition=0 -Dexe4j.consoleCodepage=cp0 -Xmx256m -Ddbvis.home=D:\Java\DbVisualizer-6.0.6\ -Dapple.laf.useScreenMenuBar=true -Xmx256m

Java VM Flags:

java.home=d:\java\jdk1.6.0_03\jre

java.class.path=D:\Java\DbVisualizer-6.0.6\.install4j\i4jruntime.jar;D:\Java\DbVisualizer-6.0.6\.\resources;D:\Java\DbVisualizer-6.0.6\.\lib\alloy.jar;D:\Java\DbVisualizer-6.0.6\.\lib\commons-lang.jar;D:\Java\DbVisualizer-6.0.6\.\lib\crimson.jar;D:\Java\DbVisualizer-6.0.6\.\lib\dbvis.jar;D:\Java\DbVisualizer-6.0.6\.\lib\forms.jar;D:\Java\DbVisualizer-6.0.6\.\lib\jai-imageio.jar;D:\Java\DbVisualizer-6.0.6\.\lib\jcchart.jar;D:\Java\DbVisualizer-6.0.6\.\lib\jdom.jar;D:\Java\DbVisualizer-6.0.6\.\lib\jide.jar;D:\Java\DbVisualizer-6.0.6\.\lib\log4j.jar;D:\Java\DbVisualizer-6.0.6\.\lib\nb-editor.jar;D:\Java\DbVisualizer-6.0.6\.\lib\ognl.jar;D:\Java\DbVisualizer-6.0.6\.\lib\openide-util.jar;D:\Java\DbVisualizer-6.0.6\.\lib\poi.jar;D:\Java\DbVisualizer-6.0.6\.\lib\yFiles.jar;

java.library.path=D:\Java\DbVisualizer-6.0.6;.;D:\WINDOWS\Sun\Java\bin;D:\WINDOWS\system32;D:\WINDOWS;D:\Java\apache-ant-1.7.0\bin;d:\oracle\product\10.2.0\client_1\bin;D:\Java\jdk1.6.0_03\bin;D:\WINDOWS\system32;D:\WINDOWS;D:\WINDOWS\System32\Wbem;D:\Program Files\Microsoft Network Monitor 3\;d:\java\jdk1.6.0_03\jre\bin

java.endorsed.dirs=d:\java\jdk1.6.0_03\jre\lib\endorsed

java.ext.dirs=d:\java\jdk1.6.0_03\jre\lib\ext;D:\WINDOWS\Sun\Java\lib\ext

sun.boot.class.path=d:\java\jdk1.6.0_03\jre\lib\resources.jar;d:\java\jdk1.6.0_03\jre\lib\rt.jar;d:\java\jdk1.6.0_03\jre\lib\sunrsasign.jar;d:\java\jdk1.6.0_03\jre\lib\jsse.jar;d:\java\jdk1.6.0_03\jre\lib\jce.jar;d:\java\jdk1.6.0_03\jre\lib\charsets.jar;d:\java\jdk1.6.0_03\jre\classes

sun.boot.library.path=d:\java\jdk1.6.0_03\jre\bin

java.vm.name=Java HotSpot(TM) Client VM

java.vm.info=mixed mode, sharing

java.vm.vendor=Sun Microsystems Inc.

java.vm.version=1.6.0_03-b05

java.vm.specification.name=Java Virtual Machine Specification

java.vm.specification.vendor=Sun Microsystems Inc.

java.vm.specification.version=1.0

Tags: DbVisualizer, Java, JDK, jps, jvmstat, visualgc

Related posts