blob: 188ed726e97efc8dea8499ce6f3777d31393b1b2 [file] [log] [blame]
Instrumental7a1817b2018-11-05 11:11:15 -06001#!/bin/bash
2#########
3# ============LICENSE_START====================================================
4# org.onap.aaf
5# ===========================================================================
6# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7# ===========================================================================
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19# ============LICENSE_END====================================================
20#
Manjunath Ranganathaiah54944fe2018-04-03 16:29:45 -070021#
22# Import the keys and certs to pkcs11 based softhsm
23#
24
25if [ "$#" -ne 3 ]; then
26 echo "Usage: p11.sh <user pin> <so pin> <id>"
27 exit 1
28fi
29
30LIB_PATH=/usr/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so
31
32mkdir -p p11key p11crt cacerts
33# Conver the keys and certs to DER format
34# key to der
35openssl rsa -in private/ca.key -outform DER -out p11key/cakey.der
36# cert to der
37cp certs/ca.crt cacerts
38DLIST=`ls -d intermediate_*`
39for DIR in $DLIST; do
40 cp $DIR/certs/ca.crt cacerts/$DIR.crt
41done
42for CA in `ls cacerts`; do
43 openssl x509 -in cacerts/$CA -outform DER -out p11crt/$CA
44done
45
46# create token directory
47mkdir /var/lib/softhsm/tokens
48# create slot
49softhsm2-util --init-token --slot 0 --label "ca token" --pin $1 --so-pin $2
50# import key into softhsm
51pkcs11-tool --module $LIB_PATH -l --pin $1 --write-object p11key/cakey.der --type privkey --id $3
52# import certs into softhsm
53for CRT in `ls cacerts`; do
54 pkcs11-tool --module $LIB_PATH -l --pin $1 --write-object p11crt/$CRT --type cert --id $3
55done
56
57rm -r p11key
58rm -r p11crt
59rm -r cacerts