Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: net/data/ssl/scripts/generate-bad-self-signed.sh

Issue 1988993002: Check self-signed certificate names and signatures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatting nits Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/data/ssl/scripts/generate-bad-self-signed.sh
diff --git a/net/data/ssl/scripts/generate-bad-self-signed.sh b/net/data/ssl/scripts/generate-bad-self-signed.sh
new file mode 100755
index 0000000000000000000000000000000000000000..6f354b87c3a9246396a0d44381f82ebaa6e1dab1
--- /dev/null
+++ b/net/data/ssl/scripts/generate-bad-self-signed.sh
@@ -0,0 +1,73 @@
+#!/bin/bash
+
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This script generates self-signed-invalid-name.pem and
+# self-signed-invalid-sig.pem, which are "self-signed" test certificates with
+# invalid names/signatures, respectively.
+
+try() {
+ "$@" || (e=$?; echo "$@" > /dev/stderr; exit $e)
+}
Ryan Sleevi 2016/05/26 07:57:08 The new files have been using "set -e" (yeah, welc
dadrian 2016/05/27 01:05:02 Done.
+
+try rm -rf out
+try mkdir out
+
+openssl genrsa -out out/bad-self-signed.key 2048
+touch out/bad-self-signed-index.txt
+
+# Create two certificate requests with the same key, but different subjects
+SUBJECT_NAME="req_self_signed_a" \
+ try openssl req \
+ -new \
+ -key out/bad-self-signed.key \
+ -out out/ss-a.req \
+ -config ee.cnf
+
+SUBJECT_NAME="req_self_signed_b" \
+ try openssl req \
+ -new \
+ -key out/bad-self-signed.key \
+ -out out/ss-b.req \
+ -config ee.cnf
+
+# Create a normal self-signed certificate from one of these requests
+try openssl x509 \
+ -req \
+ -in out/ss-a.req \
+ -out out/bad-self-signed-root-a.pem \
+ -signkey out/bad-self-signed.key \
+ -days 3650
+
+# Now, for the crazy part. We need to find a section of the signature to modify
+# so that the names match but the signature doesn't. We do this by replacing the
+# first four bytes of the signature with the bytes 0xdead.
Ryan Sleevi 2016/05/26 07:57:08 We try to avoid "we" in comments (https://groups.g
dadrian 2016/05/27 01:05:02 Done.
+
+# Find the first four hex-encoded bytes of the signature
+bytes=$(
+ openssl x509 -in out/bad-self-signed-root-a.pem -text -noout \
+ | grep -A 1 sha256WithRSA \
+ | tail -n 1 \
+ | tr -d ' ' \
+ | tr -d ':' \
+ | head -c 4)
+
+# Find those bytes in the DER-encoded certificate, and replace them with 'dead'
+openssl x509 -in out/bad-self-signed-root-a.pem -outform DER \
+ | xxd \
+ | sed "s|$bytes|dead|g" \
+ | xxd -r \
+ | openssl x509 -inform DER -outform PEM -out out/self-signed-invalid-sig.pem
Ryan Sleevi 2016/05/26 07:57:08 Why do we need to generate a certificate file with
estark 2016/05/26 16:26:51 Ahh, I didn't think of that, that does seem better
Ryan Sleevi 2016/05/26 16:34:56 On 2016/05/26 16:26:51, estark wrote: > Ahh, I di
dadrian 2016/05/26 18:41:36 I'm less familiar with Chrome development, so take
estark 2016/05/27 00:59:13 Hrm, I am struggling to come up with a strong opin
dadrian 2016/05/27 01:22:57 OpenSSL anything is pretty gross. I'd argue that m
+
+# Make a "self-signed" certificate with mismatched names
+try openssl x509 \
+ -req \
+ -in out/ss-b.req \
+ -out out/self-signed-invalid-name.pem \
+ -days 3650 \
+ -CA out/bad-self-signed-root-a.pem \
+ -CAkey out/bad-self-signed.key \
+ -CAserial out/bad-self-signed-serial.txt \
+ -CAcreateserial

Powered by Google App Engine
This is Rietveld 408576698