Permalink
Browse files

restructured to build rubygems-packages based on hoe and rake-compiler

add win32 and cross-compilation support

add PKCS11::VERSION string
  • Loading branch information...
1 parent f414c39 commit c5d3bca639493e05c63f10e1cf840d0e3c982dfc Kanis-Küche committed May 3, 2010
View
@@ -0,0 +1,23 @@
+# -*- ruby -*-
+
+require 'autotest/restart'
+
+# Autotest.add_hook :initialize do |at|
+# at.extra_files << "../some/external/dependency.rb"
+#
+# at.libs << ":../some/external"
+#
+# at.add_exception 'vendor'
+#
+# at.add_mapping(/dependency.rb/) do |f, _|
+# at.files_matching(/test_.*rb$/)
+# end
+#
+# %w(TestA TestB).each do |klass|
+# at.extra_class_map[klass] = "test/test_misc.rb"
+# end
+# end
+
+# Autotest.add_hook :run_command do |at|
+# system "rake build"
+# end
View
@@ -0,0 +1,3 @@
+=== 0.1.0 / 2010-05-03
+
+* first rubygem version
View
@@ -0,0 +1,20 @@
+.autotest
+History.txt
+MIT-LICENSE
+Manifest.txt
+README.txt
+Rakefile
+ext/pkcs11/extconf.rb
+ext/pkcs11/include/cryptoki.h
+ext/pkcs11/include/ct-kip.h
+ext/pkcs11/include/otp-pkcs11.h
+ext/pkcs11/include/pkcs-11v2-20a3.h
+ext/pkcs11/include/pkcs11.h
+ext/pkcs11/include/pkcs11f.h
+ext/pkcs11/include/pkcs11t.h
+ext/pkcs11/pk11.c
+ext/pkcs11/pk11.h
+ext/pkcs11/pk11_const.c
+sample/firefox_certs.rb
+sample/nssckbi.rb
+test/test_pkcs11.rb
View
@@ -1,30 +1,33 @@
= PKCS #11/Ruby Interface
+* http://coderepos.org/share/log/lang/ruby/pkcs11-ruby
+
This module allows Ruby programs to interface with "RSA Security Inc.
PKCS #11 Cryptographic Token Interface (Cryptoki)".
You must have the PKCS #11 v2.20 implementation library installed in
order to use this module.
-Right now, this module works on the Unix like operating systems.
+Right now, this module works on the Unix like operating systems and win32.
+
+== Compilation
-== Compilation and Installation
+ rake native gem
-Simply do the following.
+== Installation
- shell> ruby extconf.rb
- shell> make
- shell> make install
+ gem install pkcs11
== Usage
PKCS11.new requires suitable PKCS #11 implementation for your smart-cards.
+ require "rubygems"
require "pkcs11"
pkcs11 = PKCS11.new("/path/to/pkcs11.so")
slots = pkcs11.C_GetSlotList(true)
- slot = slot.first
- info = p11.C_GetSlotInfo(slot)
+ slot = slots.first
+ info = pkcs11.C_GetSlotInfo(slot)
p [info.slotDescription, info.manufacturerID,
info.flags, info.firmwareVersion, info.hardwareVersion]
flags = PKCS11::CKF_SERIAL_SESSION|PKCS11::CKF_RW_SESSION
@@ -42,7 +45,6 @@ Please refer the URL: http://www.rsa.com/rsalabs/node.asp?id=2133.
* unit testing (with mozilla softoken)
* implement all functions/structs
* sample code
- * RubyGems package
== Development Status
View
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# -*- ruby -*-
+
+require 'rubygems'
+require 'hoe'
+require 'rake/extensiontask'
+
+hoe = Hoe.spec 'pkcs11' do
+ developer('Ryosuke Kutsuna', 'ryosuke@deer-n-horse.jp')
+ developer('GOTOU Yuuzou', 'gotoyuzo@notwork.org')
+ developer('Lars Kanis', 'kanis@comcard.de')
+
+ require_paths = ['lib']
+end
+
+Rake::ExtensionTask.new('pkcs11', hoe.spec) do |ext|
+ ext.cross_compile = true # enable cross compilation (requires cross compile toolchain)
+ ext.cross_platform = ['i386-mswin32', 'i386-mingw32'] # forces the Windows platform instead of the default one
+end
+
+# vim: syntax=ruby
View
@@ -0,0 +1,6 @@
+require "mkmf"
+
+basedir = File.dirname(__FILE__)
+$CPPFLAGS += " -I \"#{basedir}/include\""
+have_func("rb_str_set_len")
+create_makefile("pkcs11");
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,5 +1,13 @@
#include "pk11.h"
-#include <dlfcn.h>
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+ #include <winbase.h> /* for LoadLibrary() */
+ #define windows
+#else
+ #include <dlfcn.h>
+#endif
+
+static const char *VERSION = "0.1.0";
static ID sNEW;
static VALUE cPKCS11;
@@ -47,7 +55,11 @@ static void
pkcs11_ctx_free(pkcs11_ctx *ctx)
{
if(ctx->functions) ctx->functions->C_Finalize(NULL_PTR);
- if(ctx->module) dlclose(ctx->module);
+#ifdef windows
+ if(ctx->module) FreeLibrary(ctx->module);
+#else
+ if(ctx->module) dlclose(ctx->module);
+#endif
free(ctx);
}
@@ -81,11 +93,29 @@ pkcs11_initialize(int argc, VALUE *argv, VALUE self)
args = NIL_P(init_args) ? NULL_PTR : DATA_PTR(init_args);
Data_Get_Struct(self, pkcs11_ctx, ctx);
+#ifdef windows
+ if((ctx->module = LoadLibrary(so_path)) == NULL) {
+ char error_text[999] = "LoadLibrary() error";
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK,
+ NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR)&error_text, sizeof(error_text), NULL);
+ rb_raise(ePKCS11Error, error_text);
+ }
+ func = (CK_C_GetFunctionList)GetProcAddress(ctx->module, "C_GetFunctionList");
+ if(!func){
+ char error_text[999] = "GetProcAddress() error";
+ FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK,
+ NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR)&error_text, sizeof(error_text), NULL);
+ rb_raise(ePKCS11Error, error_text);
+ }
+#else
if((ctx->module = dlopen(so_path, RTLD_NOW)) == NULL) {
rb_raise(ePKCS11Error, dlerror());
}
func = (CK_C_GetFunctionList)dlsym(ctx->module, "C_GetFunctionList");
if(!func) rb_raise(ePKCS11Error, dlerror());
+#endif
if((rv = func(&(ctx->functions))) != CKR_OK) pkcs11_raise(rv);
if ((rv = ctx->functions->C_Initialize(args)) != CKR_OK) pkcs11_raise(rv);
@@ -1433,6 +1463,10 @@ Init_pkcs11()
{
sNEW = rb_intern("new");
cPKCS11 = rb_define_class("PKCS11", rb_cObject);
+
+ /* Library version */
+ rb_define_const( cPKCS11, "VERSION", rb_str_new2(VERSION) );
+
ePKCS11Error = rb_define_class_under(cPKCS11, "Error", rb_eStandardError);
rb_define_alloc_func(cPKCS11, pkcs11_s_alloc);
rb_define_method(cPKCS11, "initialize", pkcs11_initialize, -1);
File renamed without changes.
File renamed without changes.
View
@@ -1,5 +0,0 @@
-require "mkmf"
-
-$CPPFLAGS += " -I./include"
-have_func("rb_str_set_len")
-create_makefile("pkcs11");
View
@@ -0,0 +1,8 @@
+require "test/unit"
+require "pkcs11"
+
+class TestPkcs11 < Test::Unit::TestCase
+ def test_sanity
+ flunk "write tests or I will kneecap you"
+ end
+end

0 comments on commit c5d3bca

Please sign in to comment.