IT点滴

我不去想是否能够成功 既然选择了远方 便只顾风雨兼程
  博客园  :: 首页  :: 联系 :: 订阅 订阅  :: 管理

[原创]开源opensc工程windows平台下编译

Posted on 2008-09-23 09:28  Ady Lee  阅读(3088)  评论(3编辑  收藏  举报

 在Google上搜了一下opensc的简介,没有,算了还是自己说吧。

opensc官方网站http://www.opensc-project.org/

工程简介:对于智能卡的访问,opensc工程提供了一套库和工具。opensc重点放在了卡片的密码操作,推进卡片的应用如邮件加密、认证和签名。opensc实现了PKCS#11的API以便支持Mozilla FireFox(浏览器)和Thunderbird(邮件客户端)能使用它。opensc实现了PKCS#15标准以便兼容所有的应用。

opensc支持以下卡片:

 

National ID Cards

Smart Cards

USB Tokens

二、编译环境

操作系统:Windows XP SP3

开发工具:vistual studio 2003 sp1

代码:opensc-0.11.6.tar.gz

库:openssl 0.9.7e.tar.gz、libtool-1.5.26-bin.zip

 

三、编译过程

libtool:把zip包解压至c:\(或者别的目录)下

openssl:把tar.gz包解压至c:\下,编译之,步骤略(google上有很多在windows下编译openssl的例子)

opensc:把tar.gz包解压至c:\下,编辑 win32/Make.rules.mak。下面贴出编辑好的文件:

 

# Note: these instructions obsolete the instructions in opensc.html

# You first need to download the gnuwin32 libtool (e.g. the "Binaries" and "Developer
# files" from http://gnuwin32.sourceforge.net/packages/libtool.htm)
# Then fill in the directory path to ltdl.h on the LIBLTDL_INCL line below, preceeded
# by an "/I"; and fill in the path to the libltdl.lib on the LIBLTDL_LIB line below.
# Then you can build this OpenSC package; and afterwards you'll need to copy the
# libltdl3.dll somewhere on your execution path.
LIBLTDL_INCL = /IC:\libtool-1.5.26-bin\include    # E.g. /IC:\libtool-1.5.8-lib\include (这里改成你自己的路径,我的是c盘)
LIBLTDL_LIB = C:\libtool-1.5.26-bin\lib\ltdl.lib    # E.g. C:\libtool-1.5.8-lib\lib\libltdl.lib(这里改成你自己的路径,我的是c盘)

OPENSC_FEATURES = pcsc

# If you want support for OpenSSL (needed for a.o. pkcs15-init tool and openssl engine):
# - download and build OpenSSL
# - uncomment the line starting with OPENSSL_DEF
# - set the OPENSSL_INCL_DIR below to your openssl include directory, preceded by "/I"
# - set the OPENSSL_LIB below to your openssl lib file
OPENSSL_DEF = /DENABLE_OPENSSL  #把这个选项打开,源代码中使用了openssl,不然会报错
!IF "$(OPENSSL_DEF)" == "/DENABLE_OPENSSL"
OPENSSL_INCL_DIR = /IE:\软件\加密库\openssl\openssl-0.9.7c\include      #改这里的路径
OPENSSL_LIB = E:\软件\加密库\openssl\openssl-0.9.7c\out32dll\Debug\libeay32.lib #指向编译好的libeay32.lib
PROGRAMS_OPENSSL = pkcs15-init.exe cryptoflex-tool.exe netkey-tool.exe piv-tool.exe
OPENSC_FEATURES = $(OPENSC_FEATURES) openssl
!ENDIF

# If you want support for zlib (Used for PIV, infocamere and actalis:
# - Download zlib and build
# - uncomment the line starting with ZLIB_DEF
# - set the ZLIB_INCL_DIR below to the zlib include lib proceeded by "/I"
# - set the ZLIB_LIB  below to your zlib lib file
#ZLIB_DEF = /DENABLE_ZLIB
!IF "$(ZLIB_DEF)" == "/DENABLE_ZLIB"
ZLIB_INCL_DIR = /IC:\ZLIB\INCLUDE
ZLIB_LIB = C:\ZLIB\LIB\zlib.lib
OPENSC_FEATURES = $(OPENSC_FEATURES) zlib
!ENDIF


COPTS = /D_CRT_SECURE_NO_DEPRECATE /Zi /MD /nologo /DHAVE_CONFIG_H /I$(TOPDIR)\src\include /I$(TOPDIR)\src\include\opensc /I$(TOPDIR)\src\common $(OPENSSL_INCL_DIR) $(ZLIB_INCL_DIR) $(LIBLTDL_INCL) /D_WIN32_WINNT=0x0400 /DWIN32_LEAN_AND_MEAN $(OPENSSL_DEF) $(ZLIB_DEF) /DOPENSC_FEATURES="\"$(OPENSC_FEATURES)\""
LINKFLAGS = /DEBUG /NOLOGO /INCREMENTAL:NO /MACHINE:IX86


install-headers:
 @for %i in ( $(HEADERS) ) do \
  @xcopy /d /q /y %i $(HEADERSDIR) > nul

install-headers-dir:
 @for %i in ( $(HEADERSDIRFROM2) ) do \
  @xcopy /d /q /y %i\*.h $(HEADERSDIR2)\*.h > nul

.c.obj::
 cl $(COPTS) /c $<

.rc.res::
 rc /l 0x0409 /r $<

clean::
 del /Q *.obj *.dll *.exe *.pdb *.lib *.def

 

打开vistudio studio .net 2003 command prompt 窗口,然后在opensc根目录下执行 nmake -f Makefile.mak,编译成功!

最后向大家推荐一个信息安全专业论坛 http://www.infosec-china.cn