Browse Source

sign request for server cert with gpgsm

Fabian Peter Hammerle 5 years ago
commit
934c546138
7 changed files with 95 additions and 0 deletions
  1. 6 0
      .gitignore
  2. 3 0
      .gitmodules
  3. 8 0
      LICENSE
  4. 24 0
      Makefile
  5. 27 0
      README.md
  6. 26 0
      gpgsm-params.template
  7. 1 0
      sexp-gen

+ 6 - 0
.gitignore

@@ -0,0 +1,6 @@
+/*.key
+/cert-request.pem
+/cert.der
+/cert.pem
+/gpgsm-params
+/keygrip.hex

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "sexp-gen"]
+	path = sexp-gen
+	url = https://git.hammerle.me/fphammerle/gpg-shadow-key-from-x509-cert-req.git

+ 8 - 0
LICENSE

@@ -0,0 +1,8 @@
+MIT License
+Copyright (c) 2018 Fabian Peter Hammerle
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 24 - 0
Makefile

@@ -0,0 +1,24 @@
+all : cert.pem cert-openssl-text
+
+keygrip.hex : cert-request.pem
+	./sexp-gen/create-gpg-shadow-key-from-x509-cert-req.py \
+  		--gpg-key-output-path '{keygrip_hex}.key' \
+		--keygrip-hex-output-path '$@' \
+		$^
+
+gpgsm-params : gpgsm-params.template keygrip.hex
+	sed "s/{{keygrip}}/$(shell cat keygrip.hex)/" $< > $@
+
+cert.der : gpgsm-params keygrip.hex
+	cat $^
+	ln --symbolic --backup "${PWD}/$(shell cat keygrip.hex).key" ~/.gnupg/private-keys-v1.d/
+	gpgsm --gen-key --batch --output $@ < $<
+
+cert.pem : cert.der
+	openssl x509 -inform DER -in $< -outform PEM -out $@
+
+cert-openssl-text : cert.pem
+	openssl x509 -in $< -text -noout 
+
+clean :
+	-rm keygrip.hex "$(shell cat keygrip.hex).key" gpgsm-params cert.der cert.pem

+ 27 - 0
README.md

@@ -0,0 +1,27 @@
+## 1. Clone
+
+```sh
+git clone --recursive \
+    --origin template \
+    --branch gpgsm/server \
+    https://git.hammerle.me/fphammerle/template-x509-cert-signing.git \
+    new-cert-signing
+```
+
+## 2. Copy
+
+Copy *cert-request.pem* to folder.
+
+## 3. Configure
+
+Edit *gpgsm-params.template*.
+
+```sh
+vim gpgsm-params.template
+```
+
+## 4. Sign
+
+```sh
+make
+```

+ 26 - 0
gpgsm-params.template

@@ -0,0 +1,26 @@
+Key-Type: RSA
+Key-Grip: {{keygrip}}
+# X509v3 Key Usage: critical
+#   Digital Signature, Non Repudiation, Key Encipherment, Data Encipherment
+# Google Chrome 56.0.2924.87 on Linux Mint 18.2 reports
+#   [...]:ERROR:cert_verify_proc_nss.cc(942)] CERT_PKIXVerifyCert for whatever.hammerle.me failed err=-810
+# if flag 'encrypt' is not set.
+Key-Usage: sign,encrypt
+Serial: random
+Name-DN: CN=example.hammerle.me,C=AT
+Name-DNS: example.hammerle.me
+Hash-Algo: SHA256
+Issuer-DN: CN=Fabian Peter Hammerle,C=AT
+Not-After: 2019-08-01 12:34:56
+Subject-Key-Id: {{keygrip}}
+Signing-Key: C2E04B00B3F087DB143B4BB6411813BA220ED4BA
+Authority-Key-Id: C2E04B00B3F087DB143B4BB6411813BA220ED4BA
+# X509v3 Basic Constraints: critical
+#   CA:FALSE
+Extension: 2.5.29.19 c 3003010100
+# X509v3 Extended Key Usage:
+#   TLS Web Server Authentication, TLS Web Client Authentication
+Extension: 2.5.29.37 n 301406082B0601050507030106082B06010505070302
+# Netscape Cert Type:
+#   SSL Client, SSL Server
+Extension: 2.16.840.1.113730.1.1 n 030206C0

+ 1 - 0
sexp-gen

@@ -0,0 +1 @@
+Subproject commit 07cd4119b7c347cece7e3a8b4ea641a39703addc