Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/bin/bash | |
| 2 | |
| 3 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 # This script generates self-signed-invalid-name.pem and | |
| 8 # self-signed-invalid-sig.pem, which are "self-signed" test certificates with | |
| 9 # invalid names/signatures, respectively. | |
| 10 | |
| 11 try() { | |
| 12 "$@" || (e=$?; echo "$@" > /dev/stderr; exit $e) | |
| 13 } | |
|
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.
| |
| 14 | |
| 15 try rm -rf out | |
| 16 try mkdir out | |
| 17 | |
| 18 openssl genrsa -out out/bad-self-signed.key 2048 | |
| 19 touch out/bad-self-signed-index.txt | |
| 20 | |
| 21 # Create two certificate requests with the same key, but different subjects | |
| 22 SUBJECT_NAME="req_self_signed_a" \ | |
| 23 try openssl req \ | |
| 24 -new \ | |
| 25 -key out/bad-self-signed.key \ | |
| 26 -out out/ss-a.req \ | |
| 27 -config ee.cnf | |
| 28 | |
| 29 SUBJECT_NAME="req_self_signed_b" \ | |
| 30 try openssl req \ | |
| 31 -new \ | |
| 32 -key out/bad-self-signed.key \ | |
| 33 -out out/ss-b.req \ | |
| 34 -config ee.cnf | |
| 35 | |
| 36 # Create a normal self-signed certificate from one of these requests | |
| 37 try openssl x509 \ | |
| 38 -req \ | |
| 39 -in out/ss-a.req \ | |
| 40 -out out/bad-self-signed-root-a.pem \ | |
| 41 -signkey out/bad-self-signed.key \ | |
| 42 -days 3650 | |
| 43 | |
| 44 # Now, for the crazy part. We need to find a section of the signature to modify | |
| 45 # so that the names match but the signature doesn't. We do this by replacing the | |
| 46 # 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.
| |
| 47 | |
| 48 # Find the first four hex-encoded bytes of the signature | |
| 49 bytes=$( | |
| 50 openssl x509 -in out/bad-self-signed-root-a.pem -text -noout \ | |
| 51 | grep -A 1 sha256WithRSA \ | |
| 52 | tail -n 1 \ | |
| 53 | tr -d ' ' \ | |
| 54 | tr -d ':' \ | |
| 55 | head -c 4) | |
| 56 | |
| 57 # Find those bytes in the DER-encoded certificate, and replace them with 'dead' | |
| 58 openssl x509 -in out/bad-self-signed-root-a.pem -outform DER \ | |
| 59 | xxd \ | |
| 60 | sed "s|$bytes|dead|g" \ | |
| 61 | xxd -r \ | |
| 62 | 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
| |
| 63 | |
| 64 # Make a "self-signed" certificate with mismatched names | |
| 65 try openssl x509 \ | |
| 66 -req \ | |
| 67 -in out/ss-b.req \ | |
| 68 -out out/self-signed-invalid-name.pem \ | |
| 69 -days 3650 \ | |
| 70 -CA out/bad-self-signed-root-a.pem \ | |
| 71 -CAkey out/bad-self-signed.key \ | |
| 72 -CAserial out/bad-self-signed-serial.txt \ | |
| 73 -CAcreateserial | |
| OLD | NEW |