summaryrefslogtreecommitdiff
path: root/devobsserver/script/ca.sh
blob: a9c9fe926d54ee6621bd75b3f30048f573741fa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh
#===============================================================================
# Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
# Author onstudy@samsung.com
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; version 2 of the License
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#===============================================================================

echo "HOSTNAME:"$HOSTNAME

if [ ! -z "$1" ]
then
    outputfolder=$1
else
    outputfolder="/srv/obs/certs"
fi

if [ ! -e "$outputfolder" ]
then
   mkdir -p $outputfolder
fi

if [ ! -z "$SSL_SUBJECT" ]
then 
   subject=$SSL_SUBJECT
else
   subject="/CN="$HOSTNAME
fi

cd $outputfolder

if [ -e server.pem ] 
then
   exit
fi

echo "Certs start!!!"
echo $subject
touch .rnd
export RANDFILE=.rnd

openssl genrsa -out server.key 1024

echo "openssl req -subj "$subject" -new -key server.key -out server.csr"
openssl req -subj "$subject" -new -key server.key -out server.csr

echo "openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt"
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

echo "copy server.pem to /etc/ssl/certs"
cat server.key server.crt > server.pem

cp server.pem /etc/ssl/certs/

c_rehash /etc/ssl/certs/

echo "Certs end!!!"