Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
131 lines (121 sloc) 3.84 KB
*** Makefile 2009-07-14 23:45:19.000000000 +0900
--- Makefile.ePass2k 2009-07-14 23:57:02.000000000 +0900
***************
*** 193,199 ****
CPPFLAGS =
CYGPATH_W = echo
DEFAULT_PCSC_PROVIDER =
! DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
DLLTOOL = dlltool
DSYMUTIL =
--- 193,199 ----
CPPFLAGS =
CYGPATH_W = echo
DEFAULT_PCSC_PROVIDER =
! DEFS = -DHAVE_CONFIG_H -DPKCS11_EPASS2000_HACK
DEPDIR = .deps
DLLTOOL = dlltool
DSYMUTIL =
*** pkcs11-tool.c 2009-05-07 22:20:14.000000000 +0900
--- pkcs11-tool.c.ePass2k 2009-07-14 23:53:31.000000000 +0900
***************
*** 931,936 ****
--- 931,940 ----
CK_RV rv;
CK_ULONG sig_len;
int fd, r;
+ #ifdef PKCS11_EPASS2000_HACK
+ unsigned char* cipher;
+ unsigned long cipher_len;
+ #endif
if (opt_mechanism == NO_MECHANISM) {
opt_mechanism = find_mechanism(slot, CKF_SIGN|CKF_HW, 1);
***************
*** 950,979 ****
else if ((fd = open(opt_input, O_RDONLY|O_BINARY)) < 0)
util_fatal("Cannot open %s: %m", opt_input);
! while ((r = read(fd, buffer, sizeof(buffer))) > 0) {
! rv = p11->C_SignUpdate(session, buffer, r);
! if (rv != CKR_OK)
! p11_fatal("C_SignUpdate", rv);
! }
! if (fd != 0)
! close(fd);
!
! sig_len = sizeof(buffer);
! rv = p11->C_SignFinal(session, buffer, &sig_len);
! if (rv != CKR_OK)
! p11_fatal("C_SignFinal", rv);
! if (opt_output == NULL)
! fd = 1;
! else if ((fd = open(opt_output, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, S_IRUSR|S_IWUSR)) < 0) {
! util_fatal("failed to open %s: %m", opt_output);
! }
- r = write(fd, buffer, sig_len);
- if (r < 0)
- util_fatal("Failed to write to %s: %m", opt_output);
- if (fd != 1)
- close(fd);
}
static void hash_data(CK_SLOT_ID slot, CK_SESSION_HANDLE session)
--- 954,1016 ----
else if ((fd = open(opt_input, O_RDONLY|O_BINARY)) < 0)
util_fatal("Cannot open %s: %m", opt_input);
! #ifdef PKCS11_EPASS2000_HACK
! r = read(fd, buffer, sizeof(buffer));
! if (fd != 0)
! close(fd);
!
! /* get cipher length */
! rv = p11->C_Sign(session, (CK_BYTE_PTR)buffer, r, NULL_PTR, &cipher_len);
! if (rv != CKR_OK )
! p11_fatal("C_Sign for get length", rv);
!
! cipher = malloc(cipher_len);
!
! /* get cipher */
! rv = p11->C_Sign(session, (CK_BYTE_PTR)buffer, r, cipher, &cipher_len);
! if (rv != CKR_OK )
! p11_fatal("C_Sign for get cipher", rv);
!
! if (opt_output == NULL)
! fd = 1;
! else if ((fd = open(opt_output, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, S_IRUSR|S_IWUSR)) < 0) {
! util_fatal("failed to open %s: %m", opt_output);
! }
!
! r = write(fd, cipher, cipher_len);
! if (r < 0)
! util_fatal("Failed to write to %s: %m", opt_output);
! if (fd != 1)
! close(fd);
! free(cipher);
! #else
! while ((r = read(fd, buffer, sizeof(buffer))) > 0) {
! rv = p11->C_SignUpdate(session, buffer, r);
! if (rv != CKR_OK)
! p11_fatal("C_SignUpdate", rv);
! }
! if (fd != 0)
! close(fd);
!
! sig_len = sizeof(buffer);
! rv = p11->C_SignFinal(session, buffer, &sig_len);
! if (rv != CKR_OK)
! p11_fatal("C_SignFinal", rv);
!
! if (opt_output == NULL)
! fd = 1;
! else if ((fd = open(opt_output, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, S_IRUSR|S_IWUSR)) < 0) {
! util_fatal("failed to open %s: %m", opt_output);
! }
!
! r = write(fd, buffer, sig_len);
! if (r < 0)
! util_fatal("Failed to write to %s: %m", opt_output);
! if (fd != 1)
! close(fd);
! #endif
}
static void hash_data(CK_SLOT_ID slot, CK_SESSION_HANDLE session)