Skip to content

Commit 0f2b89f

Browse files
committed
MB-69030: Add a script to generate self-signed-certs
Add a script which allows for creating self signed certificates and uploads them to a Couchbase server. This is primarily used for testing of the server when you want to test the behavior with a given set of bits, specific digest algorithm etc Change-Id: Ie37e49ffc75cedefbbd081664ab07202d23e0b98 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/232034 Tested-by: Trond Norbye <[email protected]> Reviewed-by: Paolo Cocchi <[email protected]>
1 parent 1c173c8 commit 0f2b89f

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#! /bin/bash
2+
3+
# Small script to allow for creating self signed certificates with a custom
4+
# configuration (number of bits, digest algorithm, server IP etc).
5+
6+
# Update the following to match your environment
7+
server=127.0.0.1:8091
8+
server_ip=192.168.101.139
9+
user=Administrator
10+
password=asdfasdf
11+
ROOT=/Users/trond.norbye/compile/trunk/cmake-install-debug/var/lib/couchbase/inbox
12+
digest=sha512
13+
bits=4096
14+
15+
set -e
16+
mkdir -p /tmp/self-signed-certs
17+
cd /tmp/self-signed-certs
18+
19+
rm -rf servercertfiles
20+
mkdir servercertfiles
21+
cd servercertfiles
22+
mkdir -p {public,private,requests,clientcertfiles}
23+
24+
openssl genrsa -out ca.key ${bits}
25+
openssl req -new -x509 -days 3650 -${digest} -key ca.key -out ca.pem \
26+
-subj "/CN=Couchbase Root CA"
27+
28+
openssl genrsa -out private/couchbase.default.svc.key ${bits}
29+
openssl req -new -key private/couchbase.default.svc.key \
30+
-out requests/couchbase.default.svc.csr -subj "/CN=Couchbase Server"
31+
32+
cat > server.ext <<EOF
33+
basicConstraints=CA:FALSE
34+
subjectKeyIdentifier = hash
35+
authorityKeyIdentifier = keyid,issuer:always
36+
extendedKeyUsage=serverAuth
37+
keyUsage = digitalSignature,keyEncipherment
38+
EOF
39+
40+
cp ./server.ext ./server.ext.tmp
41+
42+
echo "subjectAltName = IP:${server_ip}" >> ./server.ext.tmp
43+
44+
openssl x509 -CA ca.pem -CAkey ca.key -CAcreateserial -days 365 -req \
45+
-in requests/couchbase.default.svc.csr \
46+
-out public/couchbase.default.svc.pem \
47+
-extfile server.ext.tmp
48+
49+
cd ./public
50+
mv couchbase.default.svc.pem chain.pem
51+
cd ../private
52+
mv couchbase.default.svc.key pkey.key
53+
cd ..
54+
55+
rm -rf $ROOT
56+
mkdir -p $ROOT
57+
chmod go-rwx $ROOT
58+
cp ./public/chain.pem ./private/pkey.key $ROOT
59+
60+
mkdir -p ${ROOT}/CA
61+
cp ca.pem ${ROOT}/CA
62+
63+
curl -X POST http://${server}/node/controller/loadTrustedCAs -u ${user}:${password}
64+
curl -X POST http://${server}/node/controller/reloadCertificate -u ${user}:${password}

0 commit comments

Comments
 (0)