From 0c89b3ccba7c9b7332ab67ae1936aff51ca62367 Mon Sep 17 00:00:00 2001 From: NingSun Date: Thu, 8 Feb 2018 08:34:03 -0800 Subject: Initial sshsm project structure Issue-ID: AAF-94 Change-Id: I5e82fff418e7567b161acf9b98013a9b85ffc5b4 Signed-off-by: NingSun --- SoftHSMv2/src/bin/migrate/Makefile.am | 20 + SoftHSMv2/src/bin/migrate/softhsm2-migrate.1 | 67 +++ SoftHSMv2/src/bin/migrate/softhsm2-migrate.cpp | 798 +++++++++++++++++++++++++ SoftHSMv2/src/bin/migrate/softhsm2-migrate.h | 68 +++ 4 files changed, 953 insertions(+) create mode 100644 SoftHSMv2/src/bin/migrate/Makefile.am create mode 100644 SoftHSMv2/src/bin/migrate/softhsm2-migrate.1 create mode 100644 SoftHSMv2/src/bin/migrate/softhsm2-migrate.cpp create mode 100644 SoftHSMv2/src/bin/migrate/softhsm2-migrate.h (limited to 'SoftHSMv2/src/bin/migrate') diff --git a/SoftHSMv2/src/bin/migrate/Makefile.am b/SoftHSMv2/src/bin/migrate/Makefile.am new file mode 100644 index 0000000..020c6a7 --- /dev/null +++ b/SoftHSMv2/src/bin/migrate/Makefile.am @@ -0,0 +1,20 @@ +MAINTAINERCLEANFILES = $(srcdir)/Makefile.in + +AM_CPPFLAGS = -I$(srcdir)/../../lib/pkcs11 \ + -I$(srcdir)/../common \ + @SQLITE3_INCLUDES@ + +dist_man_MANS = softhsm2-migrate.1 + +bin_PROGRAMS = softhsm2-migrate + +AUTOMAKE_OPTIONS = subdir-objects + +softhsm2_migrate_SOURCES = softhsm2-migrate.cpp \ + ../common/findslot.cpp \ + ../common/getpw.cpp \ + ../common/library.cpp +softhsm2_migrate_LDADD = @SQLITE3_LIBS@ \ + @YIELD_LIB@ + +EXTRA_DIST = $(srcdir)/*.h diff --git a/SoftHSMv2/src/bin/migrate/softhsm2-migrate.1 b/SoftHSMv2/src/bin/migrate/softhsm2-migrate.1 new file mode 100644 index 0000000..65dc00c --- /dev/null +++ b/SoftHSMv2/src/bin/migrate/softhsm2-migrate.1 @@ -0,0 +1,67 @@ +.TH SOFTHSM2-MIGRATE 1 "20 April 2016" "SoftHSM" +.SH NAME +softhsm2-migrate \- SoftHSM v1 migration tool +.SH SYNOPSIS +.PP +.B softhsm2-migrate \-\-db +.I path +.B \-\-token +.I label +.RB [ \-\-pin +.I PIN +.B \-\-no\-public\-key] +.SH DESCRIPTION +.B softhsm2-migrate +is a tool that can migrate SoftHSM v1 databases to PKCS#11. +The default HSM is SoftHSM v2, but can be used with other +PKCS#11 libraries by using the option +.B \-\-module +.LP +.SH OPTIONS +.TP +.B \-\-db \fIpath\fR +The SoftHSM v1 database that is going to be migrated. +The location of the token database can be found in +the configuration file for SoftHSM v1. +.TP +.B \-\-help\fR, \fB\-h\fR +Show the help information. +.TP +.B \-\-module \fIpath\fR +Use another PKCS#11 library than SoftHSM. +.TP +.B \-\-no\-public\-key +Do not migrate the public key. +.TP +.B \-\-pin \fIPIN\fR +The +.I PIN +for the normal user. +.TP +.B \-\-serial \fInumber\fR +Will use the token with a matching serial number. +.TP +.B \-\-slot \fInumber\fR +The database will be migrated to this slot. +.TP +.B \-\-token \fIlabel\fR +Will use the token with a matching token label. +.TP +.B \-\-version\fR, \fB\-v\fR +Show the version info. +.SH EXAMPLE +.LP +A token database can be migrated with the following command: +.LP +.RS +.nf +softhsm2-migrate \-\-db /home/user/token.db \-\-token mytoken +.fi +.RE +.SH AUTHORS +Written by Rickard Bellgrim, Francis Dupont, René Post, and Roland van Rijswijk. +.LP +.SH "SEE ALSO" +.IR softhsm2-keyconv (1), +.IR softhsm2-util (1), +.IR softhsm2.conf (5) diff --git a/SoftHSMv2/src/bin/migrate/softhsm2-migrate.cpp b/SoftHSMv2/src/bin/migrate/softhsm2-migrate.cpp new file mode 100644 index 0000000..0e6dc90 --- /dev/null +++ b/SoftHSMv2/src/bin/migrate/softhsm2-migrate.cpp @@ -0,0 +1,798 @@ +/* + * Copyright (c) 2010 .SE (The Internet Infrastructure Foundation) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/***************************************************************************** + softhsm2-migrate.cpp + + This program can be used for migrating SoftHSM v1 databases to any + PKCS#11 library. The default library is the libsofthsm2.so + *****************************************************************************/ + +#include +#include "softhsm2-migrate.h" +#include "findslot.h" +#include "getpw.h" +#include "library.h" + +#include +#include +#include +#include +#ifndef _WIN32 +#include +#endif +#include +#include +#include + +#ifdef _WIN32 +#define sched_yield() SleepEx(0, 0) +#endif + +// Display the usage +void usage() +{ + printf("SoftHSM migration tool. From SoftHSM v1 database to PKCS#11.\n"); + printf("Usage: softhsm2-migrate [OPTIONS]\n"); + printf("Options:\n"); + printf(" -h Shows this help screen.\n"); + printf(" --help Shows this help screen.\n"); + printf(" --db The SoftHSM v1 database that is going to be migrated.\n"); + printf(" --module Use another PKCS#11 library than SoftHSM.\n"); + printf(" --no-public-key Do not migrate the public key.\n"); + printf(" --pin The PIN for the normal user.\n"); + printf(" --serial Will use the token with a matching serial number.\n"); + printf(" --slot The slot where the token is located.\n"); + printf(" --token