File: generatecert.sh

package info (click to toggle)
node-mqtt 4.3.7-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,948 kB
  • sloc: javascript: 7,764; xml: 104; sh: 64; makefile: 17
file content (42 lines) | stat: -rwxr-xr-x 1,198 bytes parent folder | download | duplicates (3)
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
#!/bin/sh

backup() {
    if [ ! -e test/helpers/tls-key.pem.orig ]; then
	cp -a test/helpers/tls-key.pem test/helpers/tls-key.pem.orig
    fi
    if [ ! -e test/helpers/tls-csr.pem.orig ]; then
	cp -a test/helpers/tls-csr.pem test/helpers/tls-csr.pem.orig
    fi
    if [ ! -e test/helpers/tls-cert.pem.orig ]; then
	cp -a test/helpers/tls-cert.pem test/helpers/tls-cert.pem.orig
    fi
}

restore() {
    if [ -e test/helpers/tls-key.pem.orig ]; then
	mv test/helpers/tls-key.pem.orig test/helpers/tls-key.pem
    fi
    if [ -e test/helpers/tls-csr.pem.orig ]; then
	mv test/helpers/tls-csr.pem.orig test/helpers/tls-csr.pem
    fi
    if [ -e test/helpers/tls-cert.pem.orig ]; then
	mv test/helpers/tls-cert.pem.orig test/helpers/tls-cert.pem
    fi
}

generate1() {
    openssl genrsa -out test/helpers/tls-key.pem 4096
    openssl req -new -subj /C=AU/ST=Some-State/O="Internet Widgits Pty Ltd"/CN=localhost -key test/helpers/tls-key.pem -out test/helpers/tls-csr.pem
    openssl req -in test/helpers/tls-csr.pem -x509 -nodes -key test/helpers/tls-key.pem -out test/helpers/tls-cert.pem -days 10 -sha256
}

case "$1" in
    patch)
	backup
	generate1
    ;;

    unpatch)
	restore
    ;;
esac