David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2016, Google Inc. |
| 2 | * |
| 3 | * Permission to use, copy, modify, and/or distribute this software for any |
| 4 | * purpose with or without fee is hereby granted, provided that the above |
| 5 | * copyright notice and this permission notice appear in all copies. |
| 6 | * |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 | |
Robert Sloan | 11c28bd | 2018-12-17 12:09:20 -0800 | [diff] [blame] | 15 | #include <algorithm> |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 16 | #include <functional> |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 17 | #include <string> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 20 | #include <gtest/gtest.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 21 | |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 22 | #include <openssl/bio.h> |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 23 | #include <openssl/bytestring.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 24 | #include <openssl/crypto.h> |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 25 | #include <openssl/curve25519.h> |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 26 | #include <openssl/digest.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 27 | #include <openssl/err.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 28 | #include <openssl/pem.h> |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 29 | #include <openssl/pool.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 30 | #include <openssl/x509.h> |
Robert Sloan | a815d5a | 2017-12-04 11:49:16 -0800 | [diff] [blame] | 31 | #include <openssl/x509v3.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 32 | |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 33 | #include "../internal.h" |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 34 | #include "../test/test_util.h" |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 35 | #include "../x509v3/internal.h" |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 36 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 37 | |
Robert Sloan | 2e9e66a | 2017-09-25 09:08:29 -0700 | [diff] [blame] | 38 | std::string GetTestData(const char *path); |
| 39 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 40 | static const char kCrossSigningRootPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 41 | "-----BEGIN CERTIFICATE-----\n" |
| 42 | "MIICcTCCAdqgAwIBAgIIagJHiPvE0MowDQYJKoZIhvcNAQELBQAwPDEaMBgGA1UE\n" |
| 43 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxHjAcBgNVBAMTFUNyb3NzLXNpZ25pbmcgUm9v\n" |
| 44 | "dCBDQTAgFw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAwMFowPDEaMBgGA1UE\n" |
| 45 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxHjAcBgNVBAMTFUNyb3NzLXNpZ25pbmcgUm9v\n" |
| 46 | "dCBDQTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwo3qFvSB9Zmlbpzn9wJp\n" |
| 47 | "ikI75Rxkatez8VkLqyxbOhPYl2Haz8F5p1gDG96dCI6jcLGgu3AKT9uhEQyyUko5\n" |
| 48 | "EKYasazSeA9CQrdyhPg0mkTYVETnPM1W/ebid1YtqQbq1CMWlq2aTDoSGAReGFKP\n" |
| 49 | "RTdXAbuAXzpCfi/d8LqV13UCAwEAAaN6MHgwDgYDVR0PAQH/BAQDAgIEMB0GA1Ud\n" |
| 50 | "JQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAPBgNVHRMBAf8EBTADAQH/MBkGA1Ud\n" |
| 51 | "DgQSBBBHKHC7V3Z/3oLvEZx0RZRwMBsGA1UdIwQUMBKAEEcocLtXdn/egu8RnHRF\n" |
| 52 | "lHAwDQYJKoZIhvcNAQELBQADgYEAnglibsy6mGtpIXivtlcz4zIEnHw/lNW+r/eC\n" |
| 53 | "CY7evZTmOoOuC/x9SS3MF9vawt1HFUummWM6ZgErqVBOXIB4//ykrcCgf5ZbF5Hr\n" |
| 54 | "+3EFprKhBqYiXdD8hpBkrBoXwn85LPYWNd2TceCrx0YtLIprE2R5MB2RIq8y4Jk3\n" |
| 55 | "YFXvkME=\n" |
| 56 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 57 | |
| 58 | static const char kRootCAPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 59 | "-----BEGIN CERTIFICATE-----\n" |
| 60 | "MIICVTCCAb6gAwIBAgIIAj5CwoHlWuYwDQYJKoZIhvcNAQELBQAwLjEaMBgGA1UE\n" |
| 61 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxEDAOBgNVBAMTB1Jvb3QgQ0EwIBcNMTUwMTAx\n" |
| 62 | "MDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMC4xGjAYBgNVBAoTEUJvcmluZ1NTTCBU\n" |
| 63 | "RVNUSU5HMRAwDgYDVQQDEwdSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n" |
| 64 | "iQKBgQDpDn8RDOZa5oaDcPZRBy4CeBH1siSSOO4mYgLHlPE+oXdqwI/VImi2XeJM\n" |
| 65 | "2uCFETXCknJJjYG0iJdrt/yyRFvZTQZw+QzGj+mz36NqhGxDWb6dstB2m8PX+plZ\n" |
| 66 | "w7jl81MDvUnWs8yiQ/6twgu5AbhWKZQDJKcNKCEpqa6UW0r5nwIDAQABo3oweDAO\n" |
| 67 | "BgNVHQ8BAf8EBAMCAgQwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMA8G\n" |
| 68 | "A1UdEwEB/wQFMAMBAf8wGQYDVR0OBBIEEEA31wH7QC+4HH5UBCeMWQEwGwYDVR0j\n" |
| 69 | "BBQwEoAQQDfXAftAL7gcflQEJ4xZATANBgkqhkiG9w0BAQsFAAOBgQDXylEK77Za\n" |
| 70 | "kKeY6ZerrScWyZhrjIGtHFu09qVpdJEzrk87k2G7iHHR9CAvSofCgEExKtWNS9dN\n" |
| 71 | "+9WiZp/U48iHLk7qaYXdEuO07No4BYtXn+lkOykE+FUxmA4wvOF1cTd2tdj3MzX2\n" |
| 72 | "kfGIBAYhzGZWhY3JbhIfTEfY1PNM1pWChQ==\n" |
| 73 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 74 | |
| 75 | static const char kRootCrossSignedPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 76 | "-----BEGIN CERTIFICATE-----\n" |
| 77 | "MIICYzCCAcygAwIBAgIIAj5CwoHlWuYwDQYJKoZIhvcNAQELBQAwPDEaMBgGA1UE\n" |
| 78 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxHjAcBgNVBAMTFUNyb3NzLXNpZ25pbmcgUm9v\n" |
| 79 | "dCBDQTAgFw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAwMFowLjEaMBgGA1UE\n" |
| 80 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxEDAOBgNVBAMTB1Jvb3QgQ0EwgZ8wDQYJKoZI\n" |
| 81 | "hvcNAQEBBQADgY0AMIGJAoGBAOkOfxEM5lrmhoNw9lEHLgJ4EfWyJJI47iZiAseU\n" |
| 82 | "8T6hd2rAj9UiaLZd4kza4IURNcKSckmNgbSIl2u3/LJEW9lNBnD5DMaP6bPfo2qE\n" |
| 83 | "bENZvp2y0Habw9f6mVnDuOXzUwO9SdazzKJD/q3CC7kBuFYplAMkpw0oISmprpRb\n" |
| 84 | "SvmfAgMBAAGjejB4MA4GA1UdDwEB/wQEAwICBDAdBgNVHSUEFjAUBggrBgEFBQcD\n" |
| 85 | "AQYIKwYBBQUHAwIwDwYDVR0TAQH/BAUwAwEB/zAZBgNVHQ4EEgQQQDfXAftAL7gc\n" |
| 86 | "flQEJ4xZATAbBgNVHSMEFDASgBBHKHC7V3Z/3oLvEZx0RZRwMA0GCSqGSIb3DQEB\n" |
| 87 | "CwUAA4GBAErTxYJ0en9HVRHAAr5OO5wuk5Iq3VMc79TMyQLCXVL8YH8Uk7KEwv+q\n" |
| 88 | "9MEKZv2eR/Vfm4HlXlUuIqfgUXbwrAYC/YVVX86Wnbpy/jc73NYVCq8FEZeO+0XU\n" |
| 89 | "90SWAPDdp+iL7aZdimnMtG1qlM1edmz8AKbrhN/R3IbA2CL0nCWV\n" |
| 90 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 91 | |
| 92 | static const char kIntermediatePEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 93 | "-----BEGIN CERTIFICATE-----\n" |
| 94 | "MIICXjCCAcegAwIBAgIJAKJMH+7rscPcMA0GCSqGSIb3DQEBCwUAMC4xGjAYBgNV\n" |
| 95 | "BAoTEUJvcmluZ1NTTCBURVNUSU5HMRAwDgYDVQQDEwdSb290IENBMCAXDTE1MDEw\n" |
| 96 | "MTAwMDAwMFoYDzIxMDAwMTAxMDAwMDAwWjA2MRowGAYDVQQKExFCb3JpbmdTU0wg\n" |
| 97 | "VEVTVElORzEYMBYGA1UEAxMPSW50ZXJtZWRpYXRlIENBMIGfMA0GCSqGSIb3DQEB\n" |
| 98 | "AQUAA4GNADCBiQKBgQC7YtI0l8ocTYJ0gKyXTtPL4iMJCNY4OcxXl48jkncVG1Hl\n" |
| 99 | "blicgNUa1r9m9YFtVkxvBinb8dXiUpEGhVg4awRPDcatlsBSEBuJkiZGYbRcAmSu\n" |
| 100 | "CmZYnf6u3aYQ18SU8WqVERPpE4cwVVs+6kwlzRw0+XDoZAczu8ZezVhCUc6NbQID\n" |
| 101 | "AQABo3oweDAOBgNVHQ8BAf8EBAMCAgQwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsG\n" |
| 102 | "AQUFBwMCMA8GA1UdEwEB/wQFMAMBAf8wGQYDVR0OBBIEEIwaaKi1dttdV3sfjRSy\n" |
| 103 | "BqMwGwYDVR0jBBQwEoAQQDfXAftAL7gcflQEJ4xZATANBgkqhkiG9w0BAQsFAAOB\n" |
| 104 | "gQCvnolNWEHuQS8PFVVyuLR+FKBeUUdrVbSfHSzTqNAqQGp0C9fk5oCzDq6ZgTfY\n" |
| 105 | "ESXM4cJhb3IAnW0UM0NFsYSKQJ50JZL2L3z5ZLQhHdbs4RmODGoC40BVdnJ4/qgB\n" |
| 106 | "aGSh09eQRvAVmbVCviDK2ipkWNegdyI19jFfNP5uIkGlYg==\n" |
| 107 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 108 | |
| 109 | static const char kIntermediateSelfSignedPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 110 | "-----BEGIN CERTIFICATE-----\n" |
| 111 | "MIICZjCCAc+gAwIBAgIJAKJMH+7rscPcMA0GCSqGSIb3DQEBCwUAMDYxGjAYBgNV\n" |
| 112 | "BAoTEUJvcmluZ1NTTCBURVNUSU5HMRgwFgYDVQQDEw9JbnRlcm1lZGlhdGUgQ0Ew\n" |
| 113 | "IBcNMTUwMTAxMDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMDYxGjAYBgNVBAoTEUJv\n" |
| 114 | "cmluZ1NTTCBURVNUSU5HMRgwFgYDVQQDEw9JbnRlcm1lZGlhdGUgQ0EwgZ8wDQYJ\n" |
| 115 | "KoZIhvcNAQEBBQADgY0AMIGJAoGBALti0jSXyhxNgnSArJdO08viIwkI1jg5zFeX\n" |
| 116 | "jyOSdxUbUeVuWJyA1RrWv2b1gW1WTG8GKdvx1eJSkQaFWDhrBE8Nxq2WwFIQG4mS\n" |
| 117 | "JkZhtFwCZK4KZlid/q7dphDXxJTxapURE+kThzBVWz7qTCXNHDT5cOhkBzO7xl7N\n" |
| 118 | "WEJRzo1tAgMBAAGjejB4MA4GA1UdDwEB/wQEAwICBDAdBgNVHSUEFjAUBggrBgEF\n" |
| 119 | "BQcDAQYIKwYBBQUHAwIwDwYDVR0TAQH/BAUwAwEB/zAZBgNVHQ4EEgQQjBpoqLV2\n" |
| 120 | "211Xex+NFLIGozAbBgNVHSMEFDASgBCMGmiotXbbXVd7H40UsgajMA0GCSqGSIb3\n" |
| 121 | "DQEBCwUAA4GBALcccSrAQ0/EqQBsx0ZDTUydHXXNP2DrUkpUKmAXIe8McqIVSlkT\n" |
| 122 | "6H4xz7z8VRKBo9j+drjjtCw2i0CQc8aOLxRb5WJ8eVLnaW2XRlUqAzhF0CrulfVI\n" |
| 123 | "E4Vs6ZLU+fra1WAuIj6qFiigRja+3YkZArG8tMA9vtlhTX/g7YBZIkqH\n" |
| 124 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 125 | |
| 126 | static const char kLeafPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 127 | "-----BEGIN CERTIFICATE-----\n" |
| 128 | "MIICXjCCAcegAwIBAgIIWjO48ufpunYwDQYJKoZIhvcNAQELBQAwNjEaMBgGA1UE\n" |
| 129 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxGDAWBgNVBAMTD0ludGVybWVkaWF0ZSBDQTAg\n" |
| 130 | "Fw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAwMFowMjEaMBgGA1UEChMRQm9y\n" |
| 131 | "aW5nU1NMIFRFU1RJTkcxFDASBgNVBAMTC2V4YW1wbGUuY29tMIGfMA0GCSqGSIb3\n" |
| 132 | "DQEBAQUAA4GNADCBiQKBgQDD0U0ZYgqShJ7oOjsyNKyVXEHqeafmk/bAoPqY/h1c\n" |
| 133 | "oPw2E8KmeqiUSoTPjG5IXSblOxcqpbAXgnjPzo8DI3GNMhAf8SYNYsoH7gc7Uy7j\n" |
| 134 | "5x8bUrisGnuTHqkqH6d4/e7ETJ7i3CpR8bvK16DggEvQTudLipz8FBHtYhFakfdh\n" |
| 135 | "TwIDAQABo3cwdTAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEG\n" |
| 136 | "CCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwGQYDVR0OBBIEEKN5pvbur7mlXjeMEYA0\n" |
| 137 | "4nUwGwYDVR0jBBQwEoAQjBpoqLV2211Xex+NFLIGozANBgkqhkiG9w0BAQsFAAOB\n" |
| 138 | "gQBj/p+JChp//LnXWC1k121LM/ii7hFzQzMrt70bny406SGz9jAjaPOX4S3gt38y\n" |
| 139 | "rhjpPukBlSzgQXFg66y6q5qp1nQTD1Cw6NkKBe9WuBlY3iYfmsf7WT8nhlT1CttU\n" |
| 140 | "xNCwyMX9mtdXdQicOfNjIGUCD5OLV5PgHFPRKiHHioBAhg==\n" |
| 141 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 142 | |
| 143 | static const char kLeafNoKeyUsagePEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 144 | "-----BEGIN CERTIFICATE-----\n" |
| 145 | "MIICNTCCAZ6gAwIBAgIJAIFQGaLQ0G2mMA0GCSqGSIb3DQEBCwUAMDYxGjAYBgNV\n" |
| 146 | "BAoTEUJvcmluZ1NTTCBURVNUSU5HMRgwFgYDVQQDEw9JbnRlcm1lZGlhdGUgQ0Ew\n" |
| 147 | "IBcNMTUwMTAxMDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMDcxGjAYBgNVBAoTEUJv\n" |
| 148 | "cmluZ1NTTCBURVNUSU5HMRkwFwYDVQQDExBldmlsLmV4YW1wbGUuY29tMIGfMA0G\n" |
| 149 | "CSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOKoZe75NPz77EOaMMl4/0s3PyQw++zJvp\n" |
| 150 | "ejHAxZiTPCJgMbEHLrSzNoHdopg+CLUH5bE4wTXM8w9Inv5P8OAFJt7gJuPUunmk\n" |
| 151 | "j+NoU3QfzOR6BroePcz1vXX9jyVHRs087M/sLqWRHu9IR+/A+UTcBaWaFiDVUxtJ\n" |
| 152 | "YOwFMwjNPQIDAQABo0gwRjAMBgNVHRMBAf8EAjAAMBkGA1UdDgQSBBBJfLEUWHq1\n" |
| 153 | "27rZ1AVx2J5GMBsGA1UdIwQUMBKAEIwaaKi1dttdV3sfjRSyBqMwDQYJKoZIhvcN\n" |
| 154 | "AQELBQADgYEALVKN2Y3LZJOtu6SxFIYKxbLaXhTGTdIjxipZhmbBRDFjbZjZZOTe\n" |
| 155 | "6Oo+VDNPYco4rBexK7umYXJyfTqoY0E8dbiImhTcGTEj7OAB3DbBomgU1AYe+t2D\n" |
| 156 | "uwBqh4Y3Eto+Zn4pMVsxGEfUpjzjZDel7bN1/oU/9KWPpDfywfUmjgk=\n" |
| 157 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 158 | |
| 159 | static const char kForgeryPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 160 | "-----BEGIN CERTIFICATE-----\n" |
| 161 | "MIICZzCCAdCgAwIBAgIIdTlMzQoKkeMwDQYJKoZIhvcNAQELBQAwNzEaMBgGA1UE\n" |
| 162 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxGTAXBgNVBAMTEGV2aWwuZXhhbXBsZS5jb20w\n" |
| 163 | "IBcNMTUwMTAxMDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMDoxGjAYBgNVBAoTEUJv\n" |
| 164 | "cmluZ1NTTCBURVNUSU5HMRwwGgYDVQQDExNmb3JnZXJ5LmV4YW1wbGUuY29tMIGf\n" |
| 165 | "MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDADTwruBQZGb7Ay6s9HiYv5d1lwtEy\n" |
| 166 | "xQdA2Sy8Rn8uA20Q4KgqwVY7wzIZ+z5Butrsmwb70gdG1XU+yRaDeE7XVoW6jSpm\n" |
| 167 | "0sw35/5vJbTcL4THEFbnX0OPZnvpuZDFUkvVtq5kxpDWsVyM24G8EEq7kPih3Sa3\n" |
| 168 | "OMhXVXF8kso6UQIDAQABo3cwdTAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYI\n" |
| 169 | "KwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwGQYDVR0OBBIEEEYJ/WHM\n" |
| 170 | "8p64erPWIg4/liwwGwYDVR0jBBQwEoAQSXyxFFh6tdu62dQFcdieRjANBgkqhkiG\n" |
| 171 | "9w0BAQsFAAOBgQA+zH7bHPElWRWJvjxDqRexmYLn+D3Aivs8XgXQJsM94W0EzSUf\n" |
| 172 | "DSLfRgaQwcb2gg2xpDFoG+W0vc6O651uF23WGt5JaFFJJxqjII05IexfCNhuPmp4\n" |
| 173 | "4UZAXPttuJXpn74IY1tuouaM06B3vXKZR+/ityKmfJvSwxacmFcK+2ziAg==\n" |
| 174 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 175 | |
| 176 | // kExamplePSSCert is an example RSA-PSS self-signed certificate, signed with |
| 177 | // the default hash functions. |
| 178 | static const char kExamplePSSCert[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 179 | "-----BEGIN CERTIFICATE-----\n" |
| 180 | "MIICYjCCAcagAwIBAgIJAI3qUyT6SIfzMBIGCSqGSIb3DQEBCjAFogMCAWowRTEL\n" |
| 181 | "MAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVy\n" |
| 182 | "bmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0xNDEwMDkxOTA5NTVaFw0xNTEwMDkxOTA5\n" |
| 183 | "NTVaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQK\n" |
| 184 | "DBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwgZ8wDQYJKoZIhvcNAQEBBQADgY0A\n" |
| 185 | "MIGJAoGBAPi4bIO0vNmoV8CltFl2jFQdeesiUgR+0zfrQf2D+fCmhRU0dXFahKg8\n" |
| 186 | "0u9aTtPel4rd/7vPCqqGkr64UOTNb4AzMHYTj8p73OxaymPHAyXvqIqDWHYg+hZ3\n" |
| 187 | "13mSYwFIGth7Z/FSVUlO1m5KXNd6NzYM3t2PROjCpywrta9kS2EHAgMBAAGjUDBO\n" |
| 188 | "MB0GA1UdDgQWBBTQQfuJQR6nrVrsNF1JEflVgXgfEzAfBgNVHSMEGDAWgBTQQfuJ\n" |
| 189 | "QR6nrVrsNF1JEflVgXgfEzAMBgNVHRMEBTADAQH/MBIGCSqGSIb3DQEBCjAFogMC\n" |
| 190 | "AWoDgYEASUy2RZcgNbNQZA0/7F+V1YTLEXwD16bm+iSVnzGwtexmQVEYIZG74K/w\n" |
| 191 | "xbdZQdTbpNJkp1QPjPfh0zsatw6dmt5QoZ8K8No0DjR9dgf+Wvv5WJvJUIQBoAVN\n" |
| 192 | "Z0IL+OQFz6+LcTHxD27JJCebrATXZA0wThGTQDm7crL+a+SujBY=\n" |
| 193 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 194 | |
| 195 | // kBadPSSCertPEM is a self-signed RSA-PSS certificate with bad parameters. |
| 196 | static const char kBadPSSCertPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 197 | "-----BEGIN CERTIFICATE-----\n" |
| 198 | "MIIDdjCCAjqgAwIBAgIJANcwZLyfEv7DMD4GCSqGSIb3DQEBCjAxoA0wCwYJYIZI\n" |
| 199 | "AWUDBAIBoRowGAYJKoZIhvcNAQEIMAsGCWCGSAFlAwQCAaIEAgIA3jAnMSUwIwYD\n" |
| 200 | "VQQDDBxUZXN0IEludmFsaWQgUFNTIGNlcnRpZmljYXRlMB4XDTE1MTEwNDE2MDIz\n" |
| 201 | "NVoXDTE1MTIwNDE2MDIzNVowJzElMCMGA1UEAwwcVGVzdCBJbnZhbGlkIFBTUyBj\n" |
| 202 | "ZXJ0aWZpY2F0ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMTaM7WH\n" |
| 203 | "qVCAGAIA+zL1KWvvASTrhlq+1ePdO7wsrWX2KiYoTYrJYTnxhLnn0wrHqApt79nL\n" |
| 204 | "IBG7cfShyZqFHOY/IzlYPMVt+gPo293gw96Fds5JBsjhjkyGnOyr9OUntFqvxDbT\n" |
| 205 | "IIFU7o9IdxD4edaqjRv+fegVE+B79pDk4s0ujsk6dULtCg9Rst0ucGFo19mr+b7k\n" |
| 206 | "dbfn8pZ72ZNDJPueVdrUAWw9oll61UcYfk75XdrLk6JlL41GrYHc8KlfXf43gGQq\n" |
| 207 | "QfrpHkg4Ih2cI6Wt2nhFGAzrlcorzLliQIUJRIhM8h4IgDfpBpaPdVQLqS2pFbXa\n" |
| 208 | "5eQjqiyJwak2vJ8CAwEAAaNQME4wHQYDVR0OBBYEFCt180N4oGUt5LbzBwQ4Ia+2\n" |
| 209 | "4V97MB8GA1UdIwQYMBaAFCt180N4oGUt5LbzBwQ4Ia+24V97MAwGA1UdEwQFMAMB\n" |
| 210 | "Af8wMQYJKoZIhvcNAQEKMCSgDTALBglghkgBZQMEAgGhDTALBgkqhkiG9w0BAQii\n" |
| 211 | "BAICAN4DggEBAAjBtm90lGxgddjc4Xu/nbXXFHVs2zVcHv/mqOZoQkGB9r/BVgLb\n" |
| 212 | "xhHrFZ2pHGElbUYPfifdS9ztB73e1d4J+P29o0yBqfd4/wGAc/JA8qgn6AAEO/Xn\n" |
| 213 | "plhFeTRJQtLZVl75CkHXgUGUd3h+ADvKtcBuW9dSUncaUrgNKR8u/h/2sMG38RWY\n" |
| 214 | "DzBddC/66YTa3r7KkVUfW7yqRQfELiGKdcm+bjlTEMsvS+EhHup9CzbpoCx2Fx9p\n" |
| 215 | "NPtFY3yEObQhmL1JyoCRWqBE75GzFPbRaiux5UpEkns+i3trkGssZzsOuVqHNTNZ\n" |
| 216 | "lC9+9hPHIoc9UMmAQNo1vGIW3NWVoeGbaJ8=\n" |
| 217 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 218 | |
| 219 | static const char kRSAKey[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 220 | "-----BEGIN RSA PRIVATE KEY-----\n" |
| 221 | "MIICXgIBAAKBgQDYK8imMuRi/03z0K1Zi0WnvfFHvwlYeyK9Na6XJYaUoIDAtB92\n" |
| 222 | "kWdGMdAQhLciHnAjkXLI6W15OoV3gA/ElRZ1xUpxTMhjP6PyY5wqT5r6y8FxbiiF\n" |
| 223 | "KKAnHmUcrgfVW28tQ+0rkLGMryRtrukXOgXBv7gcrmU7G1jC2a7WqmeI8QIDAQAB\n" |
| 224 | "AoGBAIBy09Fd4DOq/Ijp8HeKuCMKTHqTW1xGHshLQ6jwVV2vWZIn9aIgmDsvkjCe\n" |
| 225 | "i6ssZvnbjVcwzSoByhjN8ZCf/i15HECWDFFh6gt0P5z0MnChwzZmvatV/FXCT0j+\n" |
| 226 | "WmGNB/gkehKjGXLLcjTb6dRYVJSCZhVuOLLcbWIV10gggJQBAkEA8S8sGe4ezyyZ\n" |
| 227 | "m4e9r95g6s43kPqtj5rewTsUxt+2n4eVodD+ZUlCULWVNAFLkYRTBCASlSrm9Xhj\n" |
| 228 | "QpmWAHJUkQJBAOVzQdFUaewLtdOJoPCtpYoY1zd22eae8TQEmpGOR11L6kbxLQsk\n" |
| 229 | "aMly/DOnOaa82tqAGTdqDEZgSNmCeKKknmECQAvpnY8GUOVAubGR6c+W90iBuQLj\n" |
| 230 | "LtFp/9ihd2w/PoDwrHZaoUYVcT4VSfJQog/k7kjE4MYXYWL8eEKg3WTWQNECQQDk\n" |
| 231 | "104Wi91Umd1PzF0ijd2jXOERJU1wEKe6XLkYYNHWQAe5l4J4MWj9OdxFXAxIuuR/\n" |
| 232 | "tfDwbqkta4xcux67//khAkEAvvRXLHTaa6VFzTaiiO8SaFsHV3lQyXOtMrBpB5jd\n" |
| 233 | "moZWgjHvB2W9Ckn7sDqsPB+U2tyX0joDdQEyuiMECDY8oQ==\n" |
| 234 | "-----END RSA PRIVATE KEY-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 235 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 236 | // kCRLTestRoot is a test root certificate. It has private key: |
| 237 | // |
| 238 | // -----BEGIN RSA PRIVATE KEY----- |
| 239 | // MIIEpAIBAAKCAQEAo16WiLWZuaymsD8n5SKPmxV1y6jjgr3BS/dUBpbrzd1aeFzN |
| 240 | // lI8l2jfAnzUyp+I21RQ+nh/MhqjGElkTtK9xMn1Y+S9GMRh+5R/Du0iCb1tCZIPY |
| 241 | // 07Tgrb0KMNWe0v2QKVVruuYSgxIWodBfxlKO64Z8AJ5IbnWpuRqO6rctN9qUoMlT |
| 242 | // IAB6dL4G0tDJ/PGFWOJYwOMEIX54bly2wgyYJVBKiRRt4f7n8H922qmvPNA9idmX |
| 243 | // 9G1VAtgV6x97XXi7ULORIQvn9lVQF6nTYDBJhyuPB+mLThbLP2o9orxGx7aCtnnB |
| 244 | // ZUIxUvHNOI0FaSaZH7Fi0xsZ/GkG2HZe7ImPJwIDAQABAoIBAQCJF9MTHfHGkk+/ |
| 245 | // DwCXlA0Wg0e6hBuHl10iNobYkMWIl/xXjOknhYiqOqb181py76472SVC5ERprC+r |
| 246 | // Lf0PXzqKuA117mnkwT2bYLCL9Skf8WEhoFLQNbVlloF6wYjqXcYgKYKh8HgQbZl4 |
| 247 | // aLg2YQl2NADTNABsUWj/4H2WEelsODVviqfFs725lFg9KHDI8zxAZXLzDt/M9uVL |
| 248 | // GxJiX12tr0AwaeAFZ1oPM/y+LznM3N3+Ht3jHHw3jZ/u8Z1RdAmdpu3bZ6tbwGBr |
| 249 | // 9edsH5rKkm9aBvMrY7eX5VHqaqyRNFyG152ZOJh4XiiFG7EmgTPCpaHo50Y018Re |
| 250 | // grVtk+FBAoGBANY3lY+V8ZOwMxSHes+kTnoimHO5Ob7nxrOC71i27x+4HHsYUeAr |
| 251 | // /zOOghiDIn+oNkuiX5CIOWZKx159Bp65CPpCbTb/fh+HYnSgXFgCw7XptycO7LXM |
| 252 | // 5GwR5jSfpfzBFdYxjxoUzDMFBwTEYRTm0HkUHkH+s+ajjw5wqqbcGLcfAoGBAMM8 |
| 253 | // DKW6Tb66xsf708f0jonAjKYTLZ+WOcwsBEWSFHoY8dUjvW5gqx5acHTEsc5ZTeh4 |
| 254 | // BCFLa+Mn9cuJWVJNs09k7Xb2PNl92HQ4GN2vbdkJhExbkT6oLDHg1hVD0w8KLfz1 |
| 255 | // lTAW6pS+6CdOHMEJpvqx89EgU/1GgIQ1fXYczE75AoGAKeJoXdDFkUjsU+FBhAPu |
| 256 | // TDcjc80Nm2QaF9NMFR5/lsYa236f06MGnQAKM9zADBHJu/Qdl1brUjLg1HrBppsr |
| 257 | // RDNkw1IlSOjhuUf5hkPUHGd8Jijm440SRIcjabqla8wdBupdvo2+d2NOQgJbsQiI |
| 258 | // ToQ+fkzcxAXK3Nnuo/1436UCgYBjLH7UNOZHS8OsVM0I1r8NVKVdu4JCfeJQR8/H |
| 259 | // s2P5ffBir+wLRMnH+nMDreMQiibcPxMCArkERAlE4jlgaJ38Z62E76KLbLTmnJRt |
| 260 | // EC9Bv+bXjvAiHvWMRMUbOj/ddPNVez7Uld+FvdBaHwDWQlvzHzBWfBCOKSEhh7Z6 |
| 261 | // qDhUqQKBgQDPMDx2i5rfmQp3imV9xUcCkIRsyYQVf8Eo7NV07IdUy/otmksgn4Zt |
| 262 | // Lbf3v2dvxOpTNTONWjp2c+iUQo8QxJCZr5Sfb21oQ9Ktcrmc/CY7LeBVDibXwxdM |
| 263 | // vRG8kBzvslFWh7REzC3u06GSVhyKDfW93kN2cKVwGoahRlhj7oHuZQ== |
| 264 | // -----END RSA PRIVATE KEY----- |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 265 | static const char kCRLTestRoot[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 266 | "-----BEGIN CERTIFICATE-----\n" |
| 267 | "MIIDbzCCAlegAwIBAgIJAODri7v0dDUFMA0GCSqGSIb3DQEBCwUAME4xCzAJBgNV\n" |
| 268 | "BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1Nb3VudGFpbiBW\n" |
| 269 | "aWV3MRIwEAYDVQQKDAlCb3JpbmdTU0wwHhcNMTYwOTI2MTUwNjI2WhcNMjYwOTI0\n" |
| 270 | "MTUwNjI2WjBOMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQG\n" |
| 271 | "A1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJQm9yaW5nU1NMMIIBIjANBgkq\n" |
| 272 | "hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo16WiLWZuaymsD8n5SKPmxV1y6jjgr3B\n" |
| 273 | "S/dUBpbrzd1aeFzNlI8l2jfAnzUyp+I21RQ+nh/MhqjGElkTtK9xMn1Y+S9GMRh+\n" |
| 274 | "5R/Du0iCb1tCZIPY07Tgrb0KMNWe0v2QKVVruuYSgxIWodBfxlKO64Z8AJ5IbnWp\n" |
| 275 | "uRqO6rctN9qUoMlTIAB6dL4G0tDJ/PGFWOJYwOMEIX54bly2wgyYJVBKiRRt4f7n\n" |
| 276 | "8H922qmvPNA9idmX9G1VAtgV6x97XXi7ULORIQvn9lVQF6nTYDBJhyuPB+mLThbL\n" |
| 277 | "P2o9orxGx7aCtnnBZUIxUvHNOI0FaSaZH7Fi0xsZ/GkG2HZe7ImPJwIDAQABo1Aw\n" |
| 278 | "TjAdBgNVHQ4EFgQUWPt3N5cZ/CRvubbrkqfBnAqhq94wHwYDVR0jBBgwFoAUWPt3\n" |
| 279 | "N5cZ/CRvubbrkqfBnAqhq94wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC\n" |
| 280 | "AQEAORu6M0MOwXy+3VEBwNilfTxyqDfruQsc1jA4PT8Oe8zora1WxE1JB4q2FJOz\n" |
| 281 | "EAuM3H/NXvEnBuN+ITvKZAJUfm4NKX97qmjMJwLKWe1gVv+VQTr63aR7mgWJReQN\n" |
| 282 | "XdMztlVeZs2dppV6uEg3ia1X0G7LARxGpA9ETbMyCpb39XxlYuTClcbA5ftDN99B\n" |
| 283 | "3Xg9KNdd++Ew22O3HWRDvdDpTO/JkzQfzi3sYwUtzMEonENhczJhGf7bQMmvL/w5\n" |
| 284 | "24Wxj4Z7KzzWIHsNqE/RIs6RV3fcW61j/mRgW2XyoWnMVeBzvcJr9NXp4VQYmFPw\n" |
| 285 | "amd8GKMZQvP0ufGnUn7D7uartA==\n" |
| 286 | "-----END CERTIFICATE-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 287 | |
| 288 | static const char kCRLTestLeaf[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 289 | "-----BEGIN CERTIFICATE-----\n" |
| 290 | "MIIDkDCCAnigAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwTjELMAkGA1UEBhMCVVMx\n" |
| 291 | "EzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxEjAQ\n" |
| 292 | "BgNVBAoMCUJvcmluZ1NTTDAeFw0xNjA5MjYxNTA4MzFaFw0xNzA5MjYxNTA4MzFa\n" |
| 293 | "MEsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQKDAlC\n" |
| 294 | "b3JpbmdTU0wxEzARBgNVBAMMCmJvcmluZy5zc2wwggEiMA0GCSqGSIb3DQEBAQUA\n" |
| 295 | "A4IBDwAwggEKAoIBAQDc5v1S1M0W+QWM+raWfO0LH8uvqEwuJQgODqMaGnSlWUx9\n" |
| 296 | "8iQcnWfjyPja3lWg9K62hSOFDuSyEkysKHDxijz5R93CfLcfnVXjWQDJe7EJTTDP\n" |
| 297 | "ozEvxN6RjAeYv7CF000euYr3QT5iyBjg76+bon1p0jHZBJeNPP1KqGYgyxp+hzpx\n" |
| 298 | "e0gZmTlGAXd8JQK4v8kpdYwD6PPifFL/jpmQpqOtQmH/6zcLjY4ojmqpEdBqIKIX\n" |
| 299 | "+saA29hMq0+NK3K+wgg31RU+cVWxu3tLOIiesETkeDgArjWRS1Vkzbi4v9SJxtNu\n" |
| 300 | "OZuAxWiynRJw3JwH/OFHYZIvQqz68ZBoj96cepjPAgMBAAGjezB5MAkGA1UdEwQC\n" |
| 301 | "MAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRl\n" |
| 302 | "MB0GA1UdDgQWBBTGn0OVVh/aoYt0bvEKG+PIERqnDzAfBgNVHSMEGDAWgBRY+3c3\n" |
| 303 | "lxn8JG+5tuuSp8GcCqGr3jANBgkqhkiG9w0BAQsFAAOCAQEAd2nM8gCQN2Dc8QJw\n" |
| 304 | "XSZXyuI3DBGGCHcay/3iXu0JvTC3EiQo8J6Djv7WLI0N5KH8mkm40u89fJAB2lLZ\n" |
| 305 | "ShuHVtcC182bOKnePgwp9CNwQ21p0rDEu/P3X46ZvFgdxx82E9xLa0tBB8PiPDWh\n" |
| 306 | "lV16jbaKTgX5AZqjnsyjR5o9/mbZVupZJXx5Syq+XA8qiJfstSYJs4KyKK9UOjql\n" |
| 307 | "ICkJVKpi2ahDBqX4MOH4SLfzVk8pqSpviS6yaA1RXqjpkxiN45WWaXDldVHMSkhC\n" |
| 308 | "5CNXsXi4b1nAntu89crwSLA3rEwzCWeYj+BX7e1T9rr3oJdwOU/2KQtW1js1yQUG\n" |
| 309 | "tjJMFw==\n" |
| 310 | "-----END CERTIFICATE-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 311 | |
| 312 | static const char kBasicCRL[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 313 | "-----BEGIN X509 CRL-----\n" |
| 314 | "MIIBpzCBkAIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 315 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 316 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoA4wDDAKBgNV\n" |
| 317 | "HRQEAwIBATANBgkqhkiG9w0BAQsFAAOCAQEAnrBKKgvd9x9zwK9rtUvVeFeJ7+LN\n" |
| 318 | "ZEAc+a5oxpPNEsJx6hXoApYEbzXMxuWBQoCs5iEBycSGudct21L+MVf27M38KrWo\n" |
| 319 | "eOkq0a2siqViQZO2Fb/SUFR0k9zb8xl86Zf65lgPplALun0bV/HT7MJcl04Tc4os\n" |
| 320 | "dsAReBs5nqTGNEd5AlC1iKHvQZkM//MD51DspKnDpsDiUVi54h9C1SpfZmX8H2Vv\n" |
| 321 | "diyu0fZ/bPAM3VAGawatf/SyWfBMyKpoPXEG39oAzmjjOj8en82psn7m474IGaho\n" |
| 322 | "/vBbhl1ms5qQiLYPjm4YELtnXQoFyC72tBjbdFd/ZE9k4CNKDbxFUXFbkw==\n" |
| 323 | "-----END X509 CRL-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 324 | |
| 325 | static const char kRevokedCRL[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 326 | "-----BEGIN X509 CRL-----\n" |
| 327 | "MIIBvjCBpwIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 328 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 329 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEyNDRaFw0xNjEwMjYxNTEyNDRaMBUwEwICEAAX\n" |
| 330 | "DTE2MDkyNjE1MTIyNlqgDjAMMAoGA1UdFAQDAgECMA0GCSqGSIb3DQEBCwUAA4IB\n" |
| 331 | "AQCUGaM4DcWzlQKrcZvI8TMeR8BpsvQeo5BoI/XZu2a8h//PyRyMwYeaOM+3zl0d\n" |
| 332 | "sjgCT8b3C1FPgT+P2Lkowv7rJ+FHJRNQkogr+RuqCSPTq65ha4WKlRGWkMFybzVH\n" |
| 333 | "NloxC+aU3lgp/NlX9yUtfqYmJek1CDrOOGPrAEAwj1l/BUeYKNGqfBWYJQtPJu+5\n" |
| 334 | "OaSvIYGpETCZJscUWODmLEb/O3DM438vLvxonwGqXqS0KX37+CHpUlyhnSovxXxp\n" |
| 335 | "Pz4aF+L7OtczxL0GYtD2fR9B7TDMqsNmHXgQrixvvOY7MUdLGbd4RfJL3yA53hyO\n" |
| 336 | "xzfKY2TzxLiOmctG0hXFkH5J\n" |
| 337 | "-----END X509 CRL-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 338 | |
| 339 | static const char kBadIssuerCRL[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 340 | "-----BEGIN X509 CRL-----\n" |
| 341 | "MIIBwjCBqwIBATANBgkqhkiG9w0BAQsFADBSMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 342 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzEWMBQGA1UECgwN\n" |
| 343 | "Tm90IEJvcmluZ1NTTBcNMTYwOTI2MTUxMjQ0WhcNMTYxMDI2MTUxMjQ0WjAVMBMC\n" |
| 344 | "AhAAFw0xNjA5MjYxNTEyMjZaoA4wDDAKBgNVHRQEAwIBAjANBgkqhkiG9w0BAQsF\n" |
| 345 | "AAOCAQEAlBmjOA3Fs5UCq3GbyPEzHkfAabL0HqOQaCP12btmvIf/z8kcjMGHmjjP\n" |
| 346 | "t85dHbI4Ak/G9wtRT4E/j9i5KML+6yfhRyUTUJKIK/kbqgkj06uuYWuFipURlpDB\n" |
| 347 | "cm81RzZaMQvmlN5YKfzZV/clLX6mJiXpNQg6zjhj6wBAMI9ZfwVHmCjRqnwVmCUL\n" |
| 348 | "TybvuTmkryGBqREwmSbHFFjg5ixG/ztwzON/Ly78aJ8Bql6ktCl9+/gh6VJcoZ0q\n" |
| 349 | "L8V8aT8+Ghfi+zrXM8S9BmLQ9n0fQe0wzKrDZh14EK4sb7zmOzFHSxm3eEXyS98g\n" |
| 350 | "Od4cjsc3ymNk88S4jpnLRtIVxZB+SQ==\n" |
| 351 | "-----END X509 CRL-----\n"; |
| 352 | |
| 353 | // kKnownCriticalCRL is kBasicCRL but with a critical issuing distribution point |
| 354 | // extension. |
| 355 | static const char kKnownCriticalCRL[] = |
| 356 | "-----BEGIN X509 CRL-----\n" |
| 357 | "MIIBujCBowIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 358 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 359 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoCEwHzAKBgNV\n" |
| 360 | "HRQEAwIBATARBgNVHRwBAf8EBzAFoQMBAf8wDQYJKoZIhvcNAQELBQADggEBAA+3\n" |
| 361 | "i+5e5Ub8sccfgOBs6WVJFI9c8gvJjrJ8/dYfFIAuCyeocs7DFXn1n13CRZ+URR/Q\n" |
| 362 | "mVWgU28+xeusuSPYFpd9cyYTcVyNUGNTI3lwgcE/yVjPaOmzSZKdPakApRxtpKKQ\n" |
| 363 | "NN/56aQz3bnT/ZSHQNciRB8U6jiD9V30t0w+FDTpGaG+7bzzUH3UVF9xf9Ctp60A\n" |
| 364 | "3mfLe0scas7owSt4AEFuj2SPvcE7yvdOXbu+IEv21cEJUVExJAbhvIweHXh6yRW+\n" |
| 365 | "7VVeiNzdIjkZjyTmAzoXGha4+wbxXyBRbfH+XWcO/H+8nwyG8Gktdu2QB9S9nnIp\n" |
| 366 | "o/1TpfOMSGhMyMoyPrk=\n" |
| 367 | "-----END X509 CRL-----\n"; |
| 368 | |
| 369 | // kUnknownCriticalCRL is kBasicCRL but with an unknown critical extension. |
| 370 | static const char kUnknownCriticalCRL[] = |
| 371 | "-----BEGIN X509 CRL-----\n" |
| 372 | "MIIBvDCBpQIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 373 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 374 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoCMwITAKBgNV\n" |
| 375 | "HRQEAwIBATATBgwqhkiG9xIEAYS3CQABAf8EADANBgkqhkiG9w0BAQsFAAOCAQEA\n" |
| 376 | "GvBP0xqL509InMj/3493YVRV+ldTpBv5uTD6jewzf5XdaxEQ/VjTNe5zKnxbpAib\n" |
| 377 | "Kf7cwX0PMSkZjx7k7kKdDlEucwVvDoqC+O9aJcqVmM6GDyNb9xENxd0XCXja6MZC\n" |
| 378 | "yVgP4AwLauB2vSiEprYJyI1APph3iAEeDm60lTXX/wBM/tupQDDujKh2GPyvBRfJ\n" |
| 379 | "+wEDwGg3ICwvu4gO4zeC5qnFR+bpL9t5tOMAQnVZ0NWv+k7mkd2LbHdD44dxrfXC\n" |
| 380 | "nhtfERx99SDmC/jtUAJrGhtCO8acr7exCeYcduN7KKCm91OeCJKK6OzWst0Og1DB\n" |
| 381 | "kwzzU2rL3G65CrZ7H0SZsQ==\n" |
| 382 | "-----END X509 CRL-----\n"; |
| 383 | |
| 384 | // kUnknownCriticalCRL2 is kBasicCRL but with a critical issuing distribution |
| 385 | // point extension followed by an unknown critical extension |
| 386 | static const char kUnknownCriticalCRL2[] = |
| 387 | "-----BEGIN X509 CRL-----\n" |
| 388 | "MIIBzzCBuAIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 389 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 390 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoDYwNDAKBgNV\n" |
| 391 | "HRQEAwIBATARBgNVHRwBAf8EBzAFoQMBAf8wEwYMKoZIhvcSBAGEtwkAAQH/BAAw\n" |
| 392 | "DQYJKoZIhvcNAQELBQADggEBACTcpQC8jXL12JN5YzOcQ64ubQIe0XxRAd30p7qB\n" |
| 393 | "BTXGpgqBjrjxRfLms7EBYodEXB2oXMsDq3km0vT1MfYdsDD05S+SQ9CDsq/pUfaC\n" |
| 394 | "E2WNI5p8WircRnroYvbN2vkjlRbMd1+yNITohXYXCJwjEOAWOx3XIM10bwPYBv4R\n" |
| 395 | "rDobuLHoMgL3yHgMHmAkP7YpkBucNqeBV8cCdeAZLuhXFWi6yfr3r/X18yWbC/r2\n" |
| 396 | "2xXdkrSqXLFo7ToyP8YKTgiXpya4x6m53biEYwa2ULlas0igL6DK7wjYZX95Uy7H\n" |
| 397 | "GKljn9weIYiMPV/BzGymwfv2EW0preLwtyJNJPaxbdin6Jc=\n" |
| 398 | "-----END X509 CRL-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 399 | |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 400 | // kEd25519Cert is a self-signed Ed25519 certificate. |
| 401 | static const char kEd25519Cert[] = |
| 402 | "-----BEGIN CERTIFICATE-----\n" |
| 403 | "MIIBkTCCAUOgAwIBAgIJAJwooam0UCDmMAUGAytlcDBFMQswCQYDVQQGEwJBVTET\n" |
| 404 | "MBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ\n" |
| 405 | "dHkgTHRkMB4XDTE0MDQyMzIzMjE1N1oXDTE0MDUyMzIzMjE1N1owRTELMAkGA1UE\n" |
| 406 | "BhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdp\n" |
| 407 | "ZGdpdHMgUHR5IEx0ZDAqMAUGAytlcAMhANdamAGCsQq31Uv+08lkBzoO4XLz2qYj\n" |
| 408 | "Ja8CGmj3B1Eao1AwTjAdBgNVHQ4EFgQUoux7eV+fJK2v3ah6QPU/lj1/+7UwHwYD\n" |
| 409 | "VR0jBBgwFoAUoux7eV+fJK2v3ah6QPU/lj1/+7UwDAYDVR0TBAUwAwEB/zAFBgMr\n" |
| 410 | "ZXADQQBuCzqji8VP9xU8mHEMjXGChX7YP5J664UyVKHKH9Z1u4wEbB8dJ3ScaWSL\n" |
| 411 | "r+VHVKUhsrvcdCelnXRrrSD7xWAL\n" |
| 412 | "-----END CERTIFICATE-----\n"; |
| 413 | |
| 414 | // kEd25519CertNull is an invalid self-signed Ed25519 with an explicit NULL in |
| 415 | // the signature algorithm. |
| 416 | static const char kEd25519CertNull[] = |
| 417 | "-----BEGIN CERTIFICATE-----\n" |
| 418 | "MIIBlTCCAUWgAwIBAgIJAJwooam0UCDmMAcGAytlcAUAMEUxCzAJBgNVBAYTAkFV\n" |
| 419 | "MRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRz\n" |
| 420 | "IFB0eSBMdGQwHhcNMTQwNDIzMjMyMTU3WhcNMTQwNTIzMjMyMTU3WjBFMQswCQYD\n" |
| 421 | "VQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQg\n" |
| 422 | "V2lkZ2l0cyBQdHkgTHRkMCowBQYDK2VwAyEA11qYAYKxCrfVS/7TyWQHOg7hcvPa\n" |
| 423 | "piMlrwIaaPcHURqjUDBOMB0GA1UdDgQWBBSi7Ht5X58kra/dqHpA9T+WPX/7tTAf\n" |
| 424 | "BgNVHSMEGDAWgBSi7Ht5X58kra/dqHpA9T+WPX/7tTAMBgNVHRMEBTADAQH/MAcG\n" |
| 425 | "AytlcAUAA0EA70uefNocdJohkKPNROKVyBuBD3LXMyvmdTklsaxSRY3PcZdOohlr\n" |
| 426 | "recgVPpVS7B+d9g4EwtZXIh4lodTBDHBBw==\n" |
| 427 | "-----END CERTIFICATE-----\n"; |
| 428 | |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 429 | // kSANTypesLeaf is a leaf certificate (signed by |kSANTypesRoot|) which |
| 430 | // contains SANS for example.com, test@example.com, 127.0.0.1, and |
| 431 | // https://example.com/. (The latter is useless for now since crypto/x509 |
| 432 | // doesn't deal with URI SANs directly.) |
| 433 | static const char kSANTypesLeaf[] = |
| 434 | "-----BEGIN CERTIFICATE-----\n" |
| 435 | "MIIClzCCAgCgAwIBAgIJAOjwnT/iW+qmMA0GCSqGSIb3DQEBCwUAMCsxFzAVBgNV\n" |
| 436 | "BAoTDkJvcmluZ1NTTCBUZXN0MRAwDgYDVQQDEwdSb290IENBMB4XDTE1MDEwMTAw\n" |
| 437 | "MDAwMFoXDTI1MDEwMTAwMDAwMFowLzEXMBUGA1UEChMOQm9yaW5nU1NMIFRlc3Qx\n" |
| 438 | "FDASBgNVBAMTC2V4YW1wbGUuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\n" |
| 439 | "gQDbRn2TLhInBki8Bighq37EtqJd/h5SRYh6NkelCA2SQlvCgcC+l3mYQPtPbRT9\n" |
| 440 | "KxOLwqUuZ9jUCZ7WIji3Sgt0cyvCNPHRk+WW2XR781ifbGE8wLBB1NkrKyQjd1sc\n" |
| 441 | "O711Xc4gVM+hY4cdHiTE8x0aUIuqthRD7ZendWL0FMhS1wIDAQABo4G+MIG7MA4G\n" |
| 442 | "A1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwDAYD\n" |
| 443 | "VR0TAQH/BAIwADAZBgNVHQ4EEgQQn5EWH0NDPkmm3m22gNefYDAbBgNVHSMEFDAS\n" |
| 444 | "gBBAN9cB+0AvuBx+VAQnjFkBMEQGA1UdEQQ9MDuCC2V4YW1wbGUuY29tgRB0ZXN0\n" |
| 445 | "QGV4YW1wbGUuY29thwR/AAABhhRodHRwczovL2V4YW1wbGUuY29tLzANBgkqhkiG\n" |
| 446 | "9w0BAQsFAAOBgQBtwJvY6+Tk6D6DOtDVaNoJ5y8E25CCuE/Ga4OuIcYJas+yLckf\n" |
| 447 | "dZwUV3GUG2oBXl2MrpUFxXd4hKBO1CmlBY+hZEeIx0Yp6QWK9P/vnZeydOTP26mk\n" |
| 448 | "jusJ2PqSmtKNU1Zcaba4d29oFejmOAfeguhR8AHpsc/zHEaS5Q9cJsuJcw==\n" |
| 449 | "-----END CERTIFICATE-----\n"; |
| 450 | |
| 451 | // -----BEGIN RSA PRIVATE KEY----- |
| 452 | // MIICWwIBAAKBgQDbRn2TLhInBki8Bighq37EtqJd/h5SRYh6NkelCA2SQlvCgcC+ |
| 453 | // l3mYQPtPbRT9KxOLwqUuZ9jUCZ7WIji3Sgt0cyvCNPHRk+WW2XR781ifbGE8wLBB |
| 454 | // 1NkrKyQjd1scO711Xc4gVM+hY4cdHiTE8x0aUIuqthRD7ZendWL0FMhS1wIDAQAB |
| 455 | // AoGACwf7z0i1DxOI2zSwFimLghfyCSp8mgT3fbZ3Wj0SebYu6ZUffjceneM/AVrq |
| 456 | // gGYHYLOVHcWJqfkl7X3hPo9SDhzLx0mM545/q21ZWCwjhswH7WiCEqV2/zeDO9WU |
| 457 | // NIO1VU0VoLm0AQ7ZvwnyB+fpgF9kkkDtbBJW7XWrfNVtlnECQQD97YENpEJ3X1kj |
| 458 | // 3rrkrHWDkKAyoWWY1i8Fm7LnganC9Bv6AVwgn5ZlE/479aWHF8vbOFEA3pFPiNZJ |
| 459 | // t9FTCfpJAkEA3RCXjGI0Y6GALFLwEs+nL/XZAfJaIpJEZVLCVosYQOSaMS4SchfC |
| 460 | // GGYVquT7ZgKk9uvz89Fg87OtBMWS9lrkHwJADGkGLKeBhBoJ3kHtem2fVK3F1pOi |
| 461 | // xoR5SdnhNYVVyaxqjZ5xZTrHe+stOrr3uxGDqhQniVZXXb6/Ul0Egv1y2QJAVg/h |
| 462 | // kAujba4wIhFf2VLyOZ+yjil1ocPj0LZ5Zgvcs1bMGJ1hHP3W2HzVrqRaowoggui1 |
| 463 | // HpTC891dXGA2qKYV7QJAFDmT2A7OVvh3y4AEgzVwHrDmCMwMHKjCIntS7fjxrJnF |
| 464 | // YvJUG1zoHwUVrxxbR3DbpTODlktLcl/0b97D0IkH3w== |
| 465 | // -----END RSA PRIVATE KEY----- |
| 466 | |
| 467 | static const char kSANTypesRoot[] = |
| 468 | "-----BEGIN CERTIFICATE-----\n" |
| 469 | "MIICTTCCAbagAwIBAgIIAj5CwoHlWuYwDQYJKoZIhvcNAQELBQAwKzEXMBUGA1UE\n" |
| 470 | "ChMOQm9yaW5nU1NMIFRlc3QxEDAOBgNVBAMTB1Jvb3QgQ0EwHhcNMTUwMTAxMDAw\n" |
| 471 | "MDAwWhcNMjUwMTAxMDAwMDAwWjArMRcwFQYDVQQKEw5Cb3JpbmdTU0wgVGVzdDEQ\n" |
| 472 | "MA4GA1UEAxMHUm9vdCBDQTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA6Q5/\n" |
| 473 | "EQzmWuaGg3D2UQcuAngR9bIkkjjuJmICx5TxPqF3asCP1SJotl3iTNrghRE1wpJy\n" |
| 474 | "SY2BtIiXa7f8skRb2U0GcPkMxo/ps9+jaoRsQ1m+nbLQdpvD1/qZWcO45fNTA71J\n" |
| 475 | "1rPMokP+rcILuQG4VimUAySnDSghKamulFtK+Z8CAwEAAaN6MHgwDgYDVR0PAQH/\n" |
| 476 | "BAQDAgIEMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAPBgNVHRMBAf8E\n" |
| 477 | "BTADAQH/MBkGA1UdDgQSBBBAN9cB+0AvuBx+VAQnjFkBMBsGA1UdIwQUMBKAEEA3\n" |
| 478 | "1wH7QC+4HH5UBCeMWQEwDQYJKoZIhvcNAQELBQADgYEAc4N6hTE62/3gwg+kyc2f\n" |
| 479 | "c/Jj1mHrOt+0NRaBnmvbmNpsEjHS96Ef4Wt/ZlPXPkkv1C1VosJnOIMF3Q522wRH\n" |
| 480 | "bqaxARldS12VAa3gcWisDWD+SqSyDxjyojz0XDiJkTrFuCTCUiZO+1GLB7SO10Ms\n" |
| 481 | "d5YVX0c90VMnUhF/dlrqS9U=\n" |
| 482 | "-----END CERTIFICATE-----\n"; |
| 483 | |
| 484 | // -----BEGIN RSA PRIVATE KEY----- |
| 485 | // MIICXAIBAAKBgQDpDn8RDOZa5oaDcPZRBy4CeBH1siSSOO4mYgLHlPE+oXdqwI/V |
| 486 | // Imi2XeJM2uCFETXCknJJjYG0iJdrt/yyRFvZTQZw+QzGj+mz36NqhGxDWb6dstB2 |
| 487 | // m8PX+plZw7jl81MDvUnWs8yiQ/6twgu5AbhWKZQDJKcNKCEpqa6UW0r5nwIDAQAB |
| 488 | // AoGALEF5daZqc+aEsp8X1yky3nsoheyPL0kqSBWii33IFemZgKcSaRnAoqjPWWLS |
| 489 | // 8dHj0I/4rej2MW8iuezVSpDak9tK5boHORC3w4p/wifkizQkLt1DANxTVbzcKvrt |
| 490 | // aZ7LjVaKkhjRJbLddniowFHkkWVbUccjvzcUd7Y2VuLbAhECQQDq4FE88aHio8zg |
| 491 | // bxSd0PwjEFwLYQTR19u812SoR8PmR6ofIL+pDwOV+fVs+OGcAAOgkhIukOrksQ4A |
| 492 | // 1cKtnyhXAkEA/gRI+u3tZ7UE1twIkBfZ6IvCdRodkPqHAYIxMRLzL+MhyZt4MEGc |
| 493 | // Ngb/F6U9/WOBFnoR/PI7IwE3ejutzKcL+QJBAKh+6eilk7QKPETZi1m3/dmNt+p1 |
| 494 | // 3EZJ65pqjwxmB3Rg/vs7vCMk4TarTdSyKu+F1xRPFfoP/mK3Xctdjj6NyhsCQAYF |
| 495 | // 7/0TOzfkUPMPUJyqFB6xgbDpJ55ScnUUsznoqx+NkTWInDb4t02IqO/UmT2y6FKy |
| 496 | // Hk8TJ1fTJY+ebqaVp3ECQApx9gQ+n0zIhx97FMUuiRse73xkcW4+pZ8nF+8DmeQL |
| 497 | // /JKuuFGmzkG+rUbXFmo/Zg2ozVplw71NnQJ4znPsf7A= |
| 498 | // -----END RSA PRIVATE KEY----- |
| 499 | |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 500 | // The following four certificates were generated with this Go program, varying |
| 501 | // |includeNetscapeExtension| and defining rootKeyPEM and rootCertPEM to be |
| 502 | // strings containing the kSANTypesRoot, above. |
| 503 | |
| 504 | // package main |
| 505 | |
| 506 | // import ( |
| 507 | // "crypto/ecdsa" |
| 508 | // "crypto/elliptic" |
| 509 | // "crypto/rand" |
| 510 | // "crypto/x509" |
| 511 | // "crypto/x509/pkix" |
| 512 | // "encoding/asn1" |
| 513 | // "encoding/pem" |
| 514 | // "math/big" |
| 515 | // "os" |
| 516 | // "time" |
| 517 | // ) |
| 518 | |
| 519 | // const includeNetscapeExtension = true |
| 520 | |
| 521 | // func main() { |
| 522 | // block, _ := pem.Decode([]byte(rootKeyPEM)) |
| 523 | // rootPriv, _ := x509.ParsePKCS1PrivateKey(block.Bytes) |
| 524 | // block, _ = pem.Decode([]byte(rootCertPEM)) |
| 525 | // root, _ := x509.ParseCertificate(block.Bytes) |
| 526 | |
| 527 | // interTemplate := &x509.Certificate{ |
| 528 | // SerialNumber: big.NewInt(2), |
| 529 | // Subject: pkix.Name{ |
| 530 | // CommonName: "No Basic Constraints (Netscape)", |
| 531 | // }, |
| 532 | // NotBefore: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC), |
| 533 | // NotAfter: time.Date(2099, time.January, 1, 0, 0, 0, 0, time.UTC), |
| 534 | // } |
| 535 | |
| 536 | // if includeNetscapeExtension { |
| 537 | // interTemplate.ExtraExtensions = []pkix.Extension{ |
| 538 | // pkix.Extension{ |
| 539 | // Id: asn1.ObjectIdentifier([]int{2, 16, 840, 1, 113730, 1, 1}), |
| 540 | // Value: []byte{0x03, 0x02, 2, 0x04}, |
| 541 | // }, |
| 542 | // } |
| 543 | // } else { |
| 544 | // interTemplate.KeyUsage = x509.KeyUsageCertSign |
| 545 | // } |
| 546 | |
| 547 | // interKey, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) |
| 548 | |
| 549 | // interDER, err := x509.CreateCertificate(rand.Reader, interTemplate, root, &interKey.PublicKey, rootPriv) |
| 550 | // if err != nil { |
| 551 | // panic(err) |
| 552 | // } |
| 553 | |
| 554 | // pem.Encode(os.Stdout, &pem.Block{Type: "CERTIFICATE", Bytes: interDER}) |
| 555 | |
| 556 | // inter, _ := x509.ParseCertificate(interDER) |
| 557 | |
| 558 | // leafTemplate := &x509.Certificate{ |
| 559 | // SerialNumber: big.NewInt(3), |
| 560 | // Subject: pkix.Name{ |
| 561 | // CommonName: "Leaf from CA with no Basic Constraints", |
| 562 | // }, |
| 563 | // NotBefore: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC), |
| 564 | // NotAfter: time.Date(2099, time.January, 1, 0, 0, 0, 0, time.UTC), |
| 565 | // BasicConstraintsValid: true, |
| 566 | // } |
| 567 | // leafKey, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) |
| 568 | |
| 569 | // leafDER, err := x509.CreateCertificate(rand.Reader, leafTemplate, inter, &leafKey.PublicKey, interKey) |
| 570 | // if err != nil { |
| 571 | // panic(err) |
| 572 | // } |
| 573 | |
| 574 | // pem.Encode(os.Stdout, &pem.Block{Type: "CERTIFICATE", Bytes: leafDER}) |
| 575 | // } |
| 576 | |
| 577 | // kNoBasicConstraintsCertSignIntermediate doesn't have isCA set, but contains |
| 578 | // certSign in the keyUsage. |
| 579 | static const char kNoBasicConstraintsCertSignIntermediate[] = |
| 580 | "-----BEGIN CERTIFICATE-----\n" |
| 581 | "MIIBqjCCAROgAwIBAgIBAjANBgkqhkiG9w0BAQsFADArMRcwFQYDVQQKEw5Cb3Jp\n" |
| 582 | "bmdTU0wgVGVzdDEQMA4GA1UEAxMHUm9vdCBDQTAgFw0wMDAxMDEwMDAwMDBaGA8y\n" |
| 583 | "MDk5MDEwMTAwMDAwMFowHzEdMBsGA1UEAxMUTm8gQmFzaWMgQ29uc3RyYWludHMw\n" |
| 584 | "WTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASEFMblfxIEDO8My7wHtHWTuDzNyID1\n" |
| 585 | "OsPkMGkn32O/pSyXxXuAqDeFoMVffUMTyfm8JcYugSEbrv2qEXXM4bZRoy8wLTAO\n" |
| 586 | "BgNVHQ8BAf8EBAMCAgQwGwYDVR0jBBQwEoAQQDfXAftAL7gcflQEJ4xZATANBgkq\n" |
| 587 | "hkiG9w0BAQsFAAOBgQC1Lh6hIAm3K5kRh5iIydU0YAEm7eV6ZSskERDUq3DLJyl9\n" |
| 588 | "ZUZCHUzvb464dkwZjeNzaUVS1pdElJslwX3DtGgeJLJGCnk8zUjBjaNrrDm0kzPW\n" |
| 589 | "xKt/6oif1ci/KCKqKNXJAIFbc4e+IiBpenwpxHk3If4NM+Ek0nKoO8Uj0NkgTQ==\n" |
| 590 | "-----END CERTIFICATE-----\n"; |
| 591 | |
| 592 | static const char kNoBasicConstraintsCertSignLeaf[] = |
| 593 | "-----BEGIN CERTIFICATE-----\n" |
| 594 | "MIIBUDCB96ADAgECAgEDMAoGCCqGSM49BAMCMB8xHTAbBgNVBAMTFE5vIEJhc2lj\n" |
| 595 | "IENvbnN0cmFpbnRzMCAXDTAwMDEwMTAwMDAwMFoYDzIwOTkwMTAxMDAwMDAwWjAx\n" |
| 596 | "MS8wLQYDVQQDEyZMZWFmIGZyb20gQ0Egd2l0aCBubyBCYXNpYyBDb25zdHJhaW50\n" |
| 597 | "czBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABEsYPMwzdJKjB+2gpC90ib2ilHoB\n" |
| 598 | "w/arQ6ikUX0CNUDDaKaOu/jF39ogzVlg4lDFrjCKShSfCCcrwgONv70IZGijEDAO\n" |
| 599 | "MAwGA1UdEwEB/wQCMAAwCgYIKoZIzj0EAwIDSAAwRQIgbV7R99yM+okXSIs6Fp3o\n" |
| 600 | "eCOXiDL60IBxaTOcLS44ywcCIQDbn87Gj5cFgHBYAkzdHqDsyGXkxQTHDq9jmX24\n" |
| 601 | "Djy3Zw==\n" |
| 602 | "-----END CERTIFICATE-----\n"; |
| 603 | |
| 604 | // kNoBasicConstraintsNetscapeCAIntermediate doesn't have isCA set, but contains |
| 605 | // a Netscape certificate-type extension that asserts a type of "SSL CA". |
| 606 | static const char kNoBasicConstraintsNetscapeCAIntermediate[] = |
| 607 | "-----BEGIN CERTIFICATE-----\n" |
| 608 | "MIIBuDCCASGgAwIBAgIBAjANBgkqhkiG9w0BAQsFADArMRcwFQYDVQQKEw5Cb3Jp\n" |
| 609 | "bmdTU0wgVGVzdDEQMA4GA1UEAxMHUm9vdCBDQTAgFw0wMDAxMDEwMDAwMDBaGA8y\n" |
| 610 | "MDk5MDEwMTAwMDAwMFowKjEoMCYGA1UEAxMfTm8gQmFzaWMgQ29uc3RyYWludHMg\n" |
| 611 | "KE5ldHNjYXBlKTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABCeMbmCaOtMzXBqi\n" |
| 612 | "PrCdNOH23CkaawUA+pAezitAN4RXS1O2CGK5sJjGPVVeogROU8G7/b+mU+ciZIzH\n" |
| 613 | "1PP8FJKjMjAwMBsGA1UdIwQUMBKAEEA31wH7QC+4HH5UBCeMWQEwEQYJYIZIAYb4\n" |
| 614 | "QgEBBAQDAgIEMA0GCSqGSIb3DQEBCwUAA4GBAAgNWjh7cfBTClTAk+Ml//5xb9Ju\n" |
| 615 | "tkBhG6Rm+kkMD+qiSMO6t7xS7CsA0+jIBjkdEYaLZ3oxtQCBdZsVNxUvRxZ0AUfF\n" |
| 616 | "G3DtRFTsrI1f7IQhpMuqEMF4shPW+5x54hrq0Fo6xMs6XoinJZcTUaaB8EeXRF6M\n" |
| 617 | "P9p6HuyLrmn0c/F0\n" |
| 618 | "-----END CERTIFICATE-----\n"; |
| 619 | |
| 620 | static const char kNoBasicConstraintsNetscapeCALeaf[] = |
| 621 | "-----BEGIN CERTIFICATE-----\n" |
| 622 | "MIIBXDCCAQKgAwIBAgIBAzAKBggqhkjOPQQDAjAqMSgwJgYDVQQDEx9ObyBCYXNp\n" |
| 623 | "YyBDb25zdHJhaW50cyAoTmV0c2NhcGUpMCAXDTAwMDEwMTAwMDAwMFoYDzIwOTkw\n" |
| 624 | "MTAxMDAwMDAwWjAxMS8wLQYDVQQDEyZMZWFmIGZyb20gQ0Egd2l0aCBubyBCYXNp\n" |
| 625 | "YyBDb25zdHJhaW50czBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABDlJKolDu3R2\n" |
| 626 | "tPqSDycr0QJcWhxdBv76V0EEVflcHRxED6vAioTEcnQszt1OfKtBZvjlo0yp6i6Q\n" |
| 627 | "DaYit0ZInmWjEDAOMAwGA1UdEwEB/wQCMAAwCgYIKoZIzj0EAwIDSAAwRQIhAJsh\n" |
| 628 | "aZL6BHeEfoUBj1oZ2Ln91qzj3UCVMJ+vrmwAFdYyAiA3wp2JphgchvmoUFuzPXwj\n" |
| 629 | "XyPwWPbymSTpzKhB4xB7qQ==\n" |
| 630 | "-----END CERTIFICATE-----\n"; |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 631 | |
Robert Sloan | 036981b | 2018-09-24 10:20:02 -0700 | [diff] [blame] | 632 | static const char kSelfSignedMismatchAlgorithms[] = |
| 633 | "-----BEGIN CERTIFICATE-----\n" |
| 634 | "MIIFMjCCAxqgAwIBAgIJAL0mG5fOeJ7xMA0GCSqGSIb3DQEBDQUAMC0xCzAJBgNV\n" |
| 635 | "BAYTAkdCMQ8wDQYDVQQHDAZMb25kb24xDTALBgNVBAoMBFRlc3QwIBcNMTgwOTE3\n" |
| 636 | "MTIxNzU3WhgPMjExODA4MjQxMjE3NTdaMC0xCzAJBgNVBAYTAkdCMQ8wDQYDVQQH\n" |
| 637 | "DAZMb25kb24xDTALBgNVBAoMBFRlc3QwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAw\n" |
| 638 | "ggIKAoICAQDCMhBrRAGGw+n2GdctBr/cEK4FZA6ajiHjihgpCHoSBdyL4R2jGKLS\n" |
| 639 | "g0WgaMXa1HpkKN7LcIySosEBPlmcRkr1RqbEvQStOSvoFCXYvtx3alM6HTbXMcDR\n" |
| 640 | "mqoKoABP6LXsPSoMWIgqMtP2X9EOppzHVIK1yFYFfbIlvYUV2Ka+MuMe0Vh5wvD1\n" |
| 641 | "4GanPb+cWSKgdRSVQovCCMY3yWtZKVEaxRpCsk/mYYIFWz0tcgMjIKwDx1XXgiAV\n" |
| 642 | "nU6NK43xbaw3XhtnaD/pv9lhTTbNrlcln9LjTD097BaK4R+1AEPHnpfxA9Ui3upn\n" |
| 643 | "kbsNUdGdOB0ksZi/vd7lh833YgquQUIAhYrbfvq/HFCpVV1gljzlS3sqULYpLE//\n" |
| 644 | "i3OsuL2mE+CYIJGpIi2GeJJWXciNMTJDOqTn+fRDtVb4RPp4Y70DJirp7XzaBi3q\n" |
| 645 | "H0edANCzPSRCDbZsOhzIXhXshldiXVRX666DDlbMQgLTEnNKrkwv6DmU8o15XQsb\n" |
| 646 | "8k1Os2YwXmkEOxUQ7AJZXVTZSf6UK9Znmdq1ZrHjybMfRUkHVxJcnKvrxfryralv\n" |
| 647 | "gzfvu+D6HuxrCo3Ojqa+nDgIbxKEBtdrcsMhq1jWPFhjwo1fSadAkKOfdCAuXJRD\n" |
| 648 | "THg3b4Sf+W7Cpc570YHrIpBf7WFl2XsPcEM0mJZ5+yATASCubNozQwIDAQABo1Mw\n" |
| 649 | "UTAdBgNVHQ4EFgQUES0hupZSqY21JOba10QyZuxm91EwHwYDVR0jBBgwFoAUES0h\n" |
| 650 | "upZSqY21JOba10QyZuxm91EwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsF\n" |
| 651 | "AAOCAgEABTN5S30ng/RMpBweDm2N561PdpaCdiRXtAFCRVWR2mkDYC/Xj9Vqe6be\n" |
| 652 | "PyM7L/5OKYVjzF1yJu67z/dx+ja5o+41g17jdqla7hyPx+9B4uRyDh+1KJTa+duj\n" |
| 653 | "mw/aA1LCr6O6W4WizDOsChJ6FaB2Y1+GlFnKWb5nUdhVJqXQE1WOX9dZnw8Y4Npd\n" |
| 654 | "VmAsjWot0BZorJrt3fwfcv3QfA896twkbo7Llv/8qzg4sXZXZ4ZtgAOqnPngiSn+\n" |
| 655 | "JT/vYCXZ406VvAFpFqMcVz2dO/VGuL8lGIMHRKNyafrsV81EzH1W/XmRWOgvgj6r\n" |
| 656 | "yQI63ln/AMY72HQ97xLkE1xKunGz6bK5Ug5+O43Uftc4Mb6MUgzo+ZqEQ3Ob+cAV\n" |
| 657 | "cvjmtwDaPO/O39O5Xq0tLTlkn2/cKf4OQ6S++GDxzyRVHh5JXgP4j9+jfZY57Woy\n" |
| 658 | "R1bE7N50JjY4cDermBJKdlBIjL7UPhqmLyaG7V0hBitFlgGBUCcJtJOV0xYd5aF3\n" |
| 659 | "pxNkvMXhBmh95fjxJ0cJjpO7tN1RAwtMMNgsl7OUbuVRQCHOPW5DgP5qY21jDeRn\n" |
| 660 | "BY82382l+9QzykmJLI5MZnmj4BA9uIDCwMtoTTvP++SsvhUAbuvh7MOOUQL0EY4m\n" |
| 661 | "KStYq7X9PKseN+PvmfeoffIKc5R/Ha39oi7cGMVHCr8aiEhsf94=\n" |
| 662 | "-----END CERTIFICATE-----\n"; |
| 663 | |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 664 | // kCommonNameWithSANs is a leaf certificate signed by kSANTypesRoot, with |
| 665 | // *.host1.test as the common name and a SAN list of *.host2.test and |
| 666 | // foo.host3.test. |
| 667 | static const char kCommonNameWithSANs[] = |
| 668 | "-----BEGIN CERTIFICATE-----\n" |
| 669 | "MIIB2zCCAUSgAwIBAgIBAzANBgkqhkiG9w0BAQsFADArMRcwFQYDVQQKEw5Cb3Jp\n" |
| 670 | "bmdTU0wgVGVzdDEQMA4GA1UEAxMHUm9vdCBDQTAgFw0wMDAxMDEwMDAwMDBaGA8y\n" |
| 671 | "MDk5MDEwMTAwMDAwMFowNzEeMBwGA1UEChMVQ29tbW9uIG5hbWUgd2l0aCBTQU5z\n" |
| 672 | "MRUwEwYDVQQDDAwqLmhvc3QxLnRlc3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNC\n" |
| 673 | "AASgWzfnFnpQrokSLIC+LhCKJDUAY/2usfIDpOnafYoYCasbYetkmOslgyY4Nn07\n" |
| 674 | "zjvjNROprA/0bdULXAkdL9bNo0gwRjAbBgNVHSMEFDASgBBAN9cB+0AvuBx+VAQn\n" |
| 675 | "jFkBMCcGA1UdEQQgMB6CDCouaG9zdDIudGVzdIIOZm9vLmhvc3QzLnRlc3QwDQYJ\n" |
| 676 | "KoZIhvcNAQELBQADgYEAtv2e3hBhsslXB1HTxgusjoschWOVtvGZUaYlhkKzKTCL\n" |
| 677 | "4YpDn50BccnucBU/b9phYvaEZtyzOv4ZXhxTGyLnLrIVB9x5ikfCcfl+LNYNjDwM\n" |
| 678 | "enm/h1zOfJ7wXLyscD4kU29Wc/zxBd70thIgLYn16CC1S9NtXKsXXDXv5VVH/bg=\n" |
| 679 | "-----END CERTIFICATE-----\n"; |
| 680 | |
| 681 | // kCommonNameWithSANs is a leaf certificate signed by kSANTypesRoot, with |
| 682 | // *.host1.test as the common name and no SAN list. |
| 683 | static const char kCommonNameWithoutSANs[] = |
| 684 | "-----BEGIN CERTIFICATE-----\n" |
| 685 | "MIIBtTCCAR6gAwIBAgIBAzANBgkqhkiG9w0BAQsFADArMRcwFQYDVQQKEw5Cb3Jp\n" |
| 686 | "bmdTU0wgVGVzdDEQMA4GA1UEAxMHUm9vdCBDQTAgFw0wMDAxMDEwMDAwMDBaGA8y\n" |
| 687 | "MDk5MDEwMTAwMDAwMFowOjEhMB8GA1UEChMYQ29tbW9uIG5hbWUgd2l0aG91dCBT\n" |
| 688 | "QU5zMRUwEwYDVQQDDAwqLmhvc3QxLnRlc3QwWTATBgcqhkjOPQIBBggqhkjOPQMB\n" |
| 689 | "BwNCAARt2vjlIrPE+kr11VS1rRP/AYQu4fvf1bNw/K9rwYlVBhmLMPYasEmpCtKE\n" |
| 690 | "0bDIFydtDYC3wZDpSS+YiaG40sdAox8wHTAbBgNVHSMEFDASgBBAN9cB+0AvuBx+\n" |
| 691 | "VAQnjFkBMA0GCSqGSIb3DQEBCwUAA4GBAHRbIeaCEytOpJpw9O2dlB656AHe1+t5\n" |
| 692 | "4JiS5mvtzoVOLn7fFk5EFQtZS7sG1Uc2XjlSw+iyvFoTFEqfKyU/mIdc2vBuPwA2\n" |
| 693 | "+YXT8aE4S+UZ9oz5j0gDpikGnkSCW0cyHD8L8fntNjaQRSaM482JpmtdmuxClmWO\n" |
| 694 | "pFFXI2B5usgI\n" |
| 695 | "-----END CERTIFICATE-----\n"; |
| 696 | |
| 697 | // kCommonNameWithEmailSAN is a leaf certificate signed by kSANTypesRoot, with |
| 698 | // *.host1.test as the common name and the email address test@host2.test in the |
| 699 | // SAN list. |
| 700 | static const char kCommonNameWithEmailSAN[] = |
| 701 | "-----BEGIN CERTIFICATE-----\n" |
| 702 | "MIIBvDCCASWgAwIBAgIBAjANBgkqhkiG9w0BAQsFADArMRcwFQYDVQQKEw5Cb3Jp\n" |
| 703 | "bmdTU0wgVGVzdDEQMA4GA1UEAxMHUm9vdCBDQTAgFw0wMDAxMDEwMDAwMDBaGA8y\n" |
| 704 | "MDk5MDEwMTAwMDAwMFowFzEVMBMGA1UEAwwMKi5ob3N0MS50ZXN0MFkwEwYHKoZI\n" |
| 705 | "zj0CAQYIKoZIzj0DAQcDQgAEtevOxcTjpPzlNGoUMFfZyr1k03/Hiuh+EsnuScDs\n" |
| 706 | "8XLKi6fDkvSaDClI99ycabQZRPIrvyT+dglDC6ugQd+CYqNJMEcwDAYDVR0TAQH/\n" |
| 707 | "BAIwADAbBgNVHSMEFDASgBBAN9cB+0AvuBx+VAQnjFkBMBoGA1UdEQQTMBGBD3Rl\n" |
| 708 | "c3RAaG9zdDIudGVzdDANBgkqhkiG9w0BAQsFAAOBgQCGbqb78OWJWl4zb+qw0Dz2\n" |
| 709 | "HJgZZJt6/+nNG/XJKdaYeS4eofsbwsJI4fuuOF6ZvYCJxVNtGqdfZDgycvFA9hjv\n" |
| 710 | "NGosBF1/spP17cmzTahLjxs71jDvHV/EQJbKGl/Zpta1Em1VrzSrwoOFabPXzZTJ\n" |
| 711 | "aet/mER21Z/9ZsTUoJQPJw==\n" |
| 712 | "-----END CERTIFICATE-----\n"; |
| 713 | |
| 714 | // kCommonNameWithIPSAN is a leaf certificate signed by kSANTypesRoot, with |
| 715 | // *.host1.test as the common name and the IP address 127.0.0.1 in the |
| 716 | // SAN list. |
| 717 | static const char kCommonNameWithIPSAN[] = |
| 718 | "-----BEGIN CERTIFICATE-----\n" |
| 719 | "MIIBsTCCARqgAwIBAgIBAjANBgkqhkiG9w0BAQsFADArMRcwFQYDVQQKEw5Cb3Jp\n" |
| 720 | "bmdTU0wgVGVzdDEQMA4GA1UEAxMHUm9vdCBDQTAgFw0wMDAxMDEwMDAwMDBaGA8y\n" |
| 721 | "MDk5MDEwMTAwMDAwMFowFzEVMBMGA1UEAwwMKi5ob3N0MS50ZXN0MFkwEwYHKoZI\n" |
| 722 | "zj0CAQYIKoZIzj0DAQcDQgAEFKrgkxm8PysXbwnHQeTD3p8YY0+sY4ssnZgmj8wX\n" |
| 723 | "KTyn893fdBHWlz71GO6t82wMTF5d+ZYwI2XU52pfl4SB2aM+MDwwDAYDVR0TAQH/\n" |
| 724 | "BAIwADAbBgNVHSMEFDASgBBAN9cB+0AvuBx+VAQnjFkBMA8GA1UdEQQIMAaHBH8A\n" |
| 725 | "AAEwDQYJKoZIhvcNAQELBQADgYEAQWZ8Oj059ZjS109V/ijMYT28xuAN5n6HHxCO\n" |
| 726 | "DopTP56Zu9+gme5wTETWEfocspZvgecoUOcedTFoKSQ7JafO09NcVLA+D6ddYpju\n" |
| 727 | "mgfuiLy9dDhqvX/NHaLBMxOBWWbOLwWE+ibyX+pOzjWRCw1L7eUXOr6PhZAOQsmU\n" |
| 728 | "D0+O6KI=\n" |
| 729 | "-----END CERTIFICATE-----\n"; |
| 730 | |
| 731 | // kConstrainedIntermediate is an intermediate signed by kSANTypesRoot, with |
| 732 | // permitted DNS names of permitted1.test and foo.permitted2.test and an |
| 733 | // excluded DNS name of excluded.permitted1.test. Its private key is: |
| 734 | // |
| 735 | // -----BEGIN PRIVATE KEY----- |
| 736 | // MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgTXUM4tJWM7OzATty |
| 737 | // JhNOfIv/d8heWFBeKOfMR+RfaROhRANCAASbbbWYiN6mn+BCpg4XNpibOH0D/DN4 |
| 738 | // kZ5C/Ml2YVomC9T83OKk2CzB8fPAabPb4P4Vv+fIabpEfjWS5nzKLY1y |
| 739 | // -----END PRIVATE KEY----- |
| 740 | static const char kConstrainedIntermediate[] = |
| 741 | "-----BEGIN CERTIFICATE-----\n" |
| 742 | "MIICDjCCAXegAwIBAgIBAjANBgkqhkiG9w0BAQsFADArMRcwFQYDVQQKEw5Cb3Jp\n" |
| 743 | "bmdTU0wgVGVzdDEQMA4GA1UEAxMHUm9vdCBDQTAgFw0wMDAxMDEwMDAwMDBaGA8y\n" |
| 744 | "MDk5MDEwMTAwMDAwMFowKDEmMCQGA1UEAxMdTmFtZSBDb25zdHJhaW50cyBJbnRl\n" |
| 745 | "cm1lZGlhdGUwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASbbbWYiN6mn+BCpg4X\n" |
| 746 | "NpibOH0D/DN4kZ5C/Ml2YVomC9T83OKk2CzB8fPAabPb4P4Vv+fIabpEfjWS5nzK\n" |
| 747 | "LY1yo4GJMIGGMA8GA1UdEwEB/wQFMAMBAf8wGwYDVR0jBBQwEoAQQDfXAftAL7gc\n" |
| 748 | "flQEJ4xZATBWBgNVHR4BAf8ETDBKoCowEYIPcGVybWl0dGVkMS50ZXN0MBWCE2Zv\n" |
| 749 | "by5wZXJtaXR0ZWQyLnRlc3ShHDAaghhleGNsdWRlZC5wZXJtaXR0ZWQxLnRlc3Qw\n" |
| 750 | "DQYJKoZIhvcNAQELBQADgYEAFq1Ka05hiKREwRpSceQPzIIH4B5a5IVBg5/EvmQI\n" |
| 751 | "9V0fXyAE1GmahPt70sIBxIgzNTEaY8P/IoOuCdlZWe0msmyEO3S6YSAzOWR5Van6\n" |
| 752 | "cXmFM1uMd95TlkxUMRdV+jKJTvG6R/BM2zltaV7Xt662k5HtzT5Svw0rZlFaggZz\n" |
| 753 | "UyM=\n" |
| 754 | "-----END CERTIFICATE-----\n"; |
| 755 | |
| 756 | // kCommonNamePermittedLeaf is a leaf certificate signed by |
| 757 | // kConstrainedIntermediate. Its common name is permitted by the name |
| 758 | // constraints. |
| 759 | static const char kCommonNamePermittedLeaf[] = |
| 760 | "-----BEGIN CERTIFICATE-----\n" |
| 761 | "MIIBaDCCAQ2gAwIBAgIBAzAKBggqhkjOPQQDAjAoMSYwJAYDVQQDEx1OYW1lIENv\n" |
| 762 | "bnN0cmFpbnRzIEludGVybWVkaWF0ZTAgFw0wMDAxMDEwMDAwMDBaGA8yMDk5MDEw\n" |
| 763 | "MTAwMDAwMFowPjEeMBwGA1UEChMVQ29tbW9uIG5hbWUgcGVybWl0dGVkMRwwGgYD\n" |
| 764 | "VQQDExNmb28ucGVybWl0dGVkMS50ZXN0MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcD\n" |
| 765 | "QgAENX5Ycs8q8MRzPYUz6DqLHhJR3wcmniFRgkiEa7MxE/mRe00y0VGwH7xi7Aoc\n" |
| 766 | "emXPrtD4JwN5bssbcxWGAKYYzaMQMA4wDAYDVR0TAQH/BAIwADAKBggqhkjOPQQD\n" |
| 767 | "AgNJADBGAiEAtsnWuRQXtw2xbieC78Y8SVEtTjcZUx8uZyQe1GPLfGICIQDR4fNY\n" |
| 768 | "yg3PC94ydPNQZVsFxAne32CbonWWsokalTFpUQ==\n" |
| 769 | "-----END CERTIFICATE-----\n"; |
| 770 | static const char kCommonNamePermitted[] = "foo.permitted1.test"; |
| 771 | |
| 772 | // kCommonNameNotPermittedLeaf is a leaf certificate signed by |
| 773 | // kConstrainedIntermediate. Its common name is not permitted by the name |
| 774 | // constraints. |
| 775 | static const char kCommonNameNotPermittedLeaf[] = |
| 776 | "-----BEGIN CERTIFICATE-----\n" |
| 777 | "MIIBazCCARCgAwIBAgIBBDAKBggqhkjOPQQDAjAoMSYwJAYDVQQDEx1OYW1lIENv\n" |
| 778 | "bnN0cmFpbnRzIEludGVybWVkaWF0ZTAgFw0wMDAxMDEwMDAwMDBaGA8yMDk5MDEw\n" |
| 779 | "MTAwMDAwMFowQTEiMCAGA1UEChMZQ29tbW9uIG5hbWUgbm90IHBlcm1pdHRlZDEb\n" |
| 780 | "MBkGA1UEAxMSbm90LXBlcm1pdHRlZC50ZXN0MFkwEwYHKoZIzj0CAQYIKoZIzj0D\n" |
| 781 | "AQcDQgAEzfghKuWf0JoXb0Drp09C3yXMSQQ1byt+AUaymvsHOWsxQ9v1Q+vkF/IM\n" |
| 782 | "HRqGTk2TyxrB2iClVEn/Uu+YtYox1KMQMA4wDAYDVR0TAQH/BAIwADAKBggqhkjO\n" |
| 783 | "PQQDAgNJADBGAiEAxaUslxmoWL1tIvnDz7gDkto/HcmdU0jHVuUQLXcCG8wCIQCN\n" |
| 784 | "5xZjitlCQU8UB5qSu9wH4B+0JcVO3Ss4Az76HEJWMw==\n" |
| 785 | "-----END CERTIFICATE-----\n"; |
| 786 | static const char kCommonNameNotPermitted[] = "not-permitted.test"; |
| 787 | |
| 788 | // kCommonNameNotPermittedWithSANsLeaf is a leaf certificate signed by |
| 789 | // kConstrainedIntermediate. Its common name is not permitted by the name |
| 790 | // constraints but it has a SAN list. |
| 791 | static const char kCommonNameNotPermittedWithSANsLeaf[] = |
| 792 | "-----BEGIN CERTIFICATE-----\n" |
| 793 | "MIIBqTCCAU+gAwIBAgIBBjAKBggqhkjOPQQDAjAoMSYwJAYDVQQDEx1OYW1lIENv\n" |
| 794 | "bnN0cmFpbnRzIEludGVybWVkaWF0ZTAgFw0wMDAxMDEwMDAwMDBaGA8yMDk5MDEw\n" |
| 795 | "MTAwMDAwMFowSzEsMCoGA1UEChMjQ29tbW9uIG5hbWUgbm90IHBlcm1pdHRlZCB3\n" |
| 796 | "aXRoIFNBTlMxGzAZBgNVBAMTEm5vdC1wZXJtaXR0ZWQudGVzdDBZMBMGByqGSM49\n" |
| 797 | "AgEGCCqGSM49AwEHA0IABKsn9wOApXFHrqhLdQgbFSeaSoAIbxgO0zVSRZUb5naR\n" |
| 798 | "93zoL3MFOvZEF8xiEqh7le+l3XuUig0fwqpcsZzRNJajRTBDMAwGA1UdEwEB/wQC\n" |
| 799 | "MAAwMwYDVR0RBCwwKoITZm9vLnBlcm1pdHRlZDEudGVzdIITZm9vLnBlcm1pdHRl\n" |
| 800 | "ZDIudGVzdDAKBggqhkjOPQQDAgNIADBFAiACk+1f184KkKAXuntmrz+Ygcq8MiZl\n" |
| 801 | "4delx44FtcNaegIhAIA5nYfzxNcTXxDo3U+x1vSLH6Y7faLvHiFySp7O//q+\n" |
| 802 | "-----END CERTIFICATE-----\n"; |
| 803 | static const char kCommonNameNotPermittedWithSANs[] = "not-permitted.test"; |
| 804 | |
| 805 | // kCommonNameNotDNSLeaf is a leaf certificate signed by |
| 806 | // kConstrainedIntermediate. Its common name is not a DNS name. |
| 807 | static const char kCommonNameNotDNSLeaf[] = |
| 808 | "-----BEGIN CERTIFICATE-----\n" |
| 809 | "MIIBYTCCAQagAwIBAgIBCDAKBggqhkjOPQQDAjAoMSYwJAYDVQQDEx1OYW1lIENv\n" |
| 810 | "bnN0cmFpbnRzIEludGVybWVkaWF0ZTAgFw0wMDAxMDEwMDAwMDBaGA8yMDk5MDEw\n" |
| 811 | "MTAwMDAwMFowNzEcMBoGA1UEChMTQ29tbW9uIG5hbWUgbm90IEROUzEXMBUGA1UE\n" |
| 812 | "AxMOTm90IGEgRE5TIG5hbWUwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASnueyc\n" |
| 813 | "Zxtnw5ke2J2T0/LwAK37auQP/RSFd9mem+BJVbgviawtAlignJmafp7Zw4/GdYEJ\n" |
| 814 | "Vm8qlriOJtluvXGcoxAwDjAMBgNVHRMBAf8EAjAAMAoGCCqGSM49BAMCA0kAMEYC\n" |
| 815 | "IQChUAmVNI39VHe0zemRE09VDcSEgOxr1nTvjLcg/Q8pVQIhAJYZnJI0YZAi05QH\n" |
| 816 | "RHNlAkTK2TnUaVn3fGSylaLiFS1r\n" |
| 817 | "-----END CERTIFICATE-----\n"; |
| 818 | static const char kCommonNameNotDNS[] = "Not a DNS name"; |
| 819 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 820 | // CertFromPEM parses the given, NUL-terminated pem block and returns an |
| 821 | // |X509*|. |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 822 | static bssl::UniquePtr<X509> CertFromPEM(const char *pem) { |
| 823 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(pem, strlen(pem))); |
| 824 | return bssl::UniquePtr<X509>( |
| 825 | PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 826 | } |
| 827 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 828 | // CRLFromPEM parses the given, NUL-terminated pem block and returns an |
| 829 | // |X509_CRL*|. |
| 830 | static bssl::UniquePtr<X509_CRL> CRLFromPEM(const char *pem) { |
| 831 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(pem, strlen(pem))); |
| 832 | return bssl::UniquePtr<X509_CRL>( |
| 833 | PEM_read_bio_X509_CRL(bio.get(), nullptr, nullptr, nullptr)); |
| 834 | } |
| 835 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 836 | // PrivateKeyFromPEM parses the given, NUL-terminated pem block and returns an |
| 837 | // |EVP_PKEY*|. |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 838 | static bssl::UniquePtr<EVP_PKEY> PrivateKeyFromPEM(const char *pem) { |
| 839 | bssl::UniquePtr<BIO> bio( |
| 840 | BIO_new_mem_buf(const_cast<char *>(pem), strlen(pem))); |
| 841 | return bssl::UniquePtr<EVP_PKEY>( |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 842 | PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr)); |
| 843 | } |
| 844 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 845 | // CertsToStack converts a vector of |X509*| to an OpenSSL STACK_OF(X509), |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 846 | // bumping the reference counts for each certificate in question. |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 847 | static bssl::UniquePtr<STACK_OF(X509)> CertsToStack( |
| 848 | const std::vector<X509 *> &certs) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 849 | bssl::UniquePtr<STACK_OF(X509)> stack(sk_X509_new_null()); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 850 | if (!stack) { |
| 851 | return nullptr; |
| 852 | } |
| 853 | for (auto cert : certs) { |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 854 | if (!bssl::PushToStack(stack.get(), bssl::UpRef(cert))) { |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 855 | return nullptr; |
| 856 | } |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 857 | } |
| 858 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 859 | return stack; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 860 | } |
| 861 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 862 | // CRLsToStack converts a vector of |X509_CRL*| to an OpenSSL |
| 863 | // STACK_OF(X509_CRL), bumping the reference counts for each CRL in question. |
| 864 | static bssl::UniquePtr<STACK_OF(X509_CRL)> CRLsToStack( |
| 865 | const std::vector<X509_CRL *> &crls) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 866 | bssl::UniquePtr<STACK_OF(X509_CRL)> stack(sk_X509_CRL_new_null()); |
| 867 | if (!stack) { |
| 868 | return nullptr; |
| 869 | } |
| 870 | for (auto crl : crls) { |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 871 | if (!bssl::PushToStack(stack.get(), bssl::UpRef(crl))) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 872 | return nullptr; |
| 873 | } |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 874 | } |
| 875 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 876 | return stack; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | static int Verify(X509 *leaf, const std::vector<X509 *> &roots, |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 880 | const std::vector<X509 *> &intermediates, |
| 881 | const std::vector<X509_CRL *> &crls, unsigned long flags, |
| 882 | bool use_additional_untrusted, |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 883 | std::function<void(X509_VERIFY_PARAM *)> configure_callback, |
| 884 | int (*verify_callback)(int, X509_STORE_CTX *) = nullptr) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 885 | bssl::UniquePtr<STACK_OF(X509)> roots_stack(CertsToStack(roots)); |
| 886 | bssl::UniquePtr<STACK_OF(X509)> intermediates_stack( |
| 887 | CertsToStack(intermediates)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 888 | bssl::UniquePtr<STACK_OF(X509_CRL)> crls_stack(CRLsToStack(crls)); |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 889 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 890 | if (!roots_stack || |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 891 | !intermediates_stack || |
| 892 | !crls_stack) { |
| 893 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 894 | } |
| 895 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 896 | bssl::UniquePtr<X509_STORE_CTX> ctx(X509_STORE_CTX_new()); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 897 | bssl::UniquePtr<X509_STORE> store(X509_STORE_new()); |
| 898 | if (!ctx || |
| 899 | !store) { |
| 900 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 901 | } |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 902 | |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 903 | if (use_additional_untrusted) { |
| 904 | X509_STORE_set0_additional_untrusted(store.get(), |
| 905 | intermediates_stack.get()); |
| 906 | } |
| 907 | |
| 908 | if (!X509_STORE_CTX_init( |
| 909 | ctx.get(), store.get(), leaf, |
| 910 | use_additional_untrusted ? nullptr : intermediates_stack.get())) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 911 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | X509_STORE_CTX_trusted_stack(ctx.get(), roots_stack.get()); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 915 | X509_STORE_CTX_set0_crls(ctx.get(), crls_stack.get()); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 916 | |
| 917 | X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new(); |
| 918 | if (param == nullptr) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 919 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 920 | } |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 921 | X509_VERIFY_PARAM_set_time(param, 1474934400 /* Sep 27th, 2016 */); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 922 | X509_VERIFY_PARAM_set_depth(param, 16); |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 923 | if (configure_callback) { |
| 924 | configure_callback(param); |
| 925 | } |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 926 | if (flags) { |
| 927 | X509_VERIFY_PARAM_set_flags(param, flags); |
| 928 | } |
| 929 | X509_STORE_CTX_set0_param(ctx.get(), param); |
| 930 | |
| 931 | ERR_clear_error(); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 932 | if (X509_verify_cert(ctx.get()) != 1) { |
| 933 | return X509_STORE_CTX_get_error(ctx.get()); |
| 934 | } |
| 935 | |
| 936 | return X509_V_OK; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 937 | } |
| 938 | |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 939 | static int Verify(X509 *leaf, const std::vector<X509 *> &roots, |
| 940 | const std::vector<X509 *> &intermediates, |
| 941 | const std::vector<X509_CRL *> &crls, |
| 942 | unsigned long flags = 0) { |
Robert Sloan | ab8b888 | 2018-03-26 11:39:51 -0700 | [diff] [blame] | 943 | const int r1 = |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 944 | Verify(leaf, roots, intermediates, crls, flags, false, nullptr); |
Robert Sloan | ab8b888 | 2018-03-26 11:39:51 -0700 | [diff] [blame] | 945 | const int r2 = |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 946 | Verify(leaf, roots, intermediates, crls, flags, true, nullptr); |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 947 | |
| 948 | if (r1 != r2) { |
| 949 | fprintf(stderr, |
| 950 | "Verify with, and without, use_additional_untrusted gave different " |
| 951 | "results: %d vs %d.\n", |
| 952 | r1, r2); |
| 953 | return false; |
| 954 | } |
| 955 | |
| 956 | return r1; |
| 957 | } |
| 958 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 959 | TEST(X509Test, TestVerify) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 960 | bssl::UniquePtr<X509> cross_signing_root(CertFromPEM(kCrossSigningRootPEM)); |
| 961 | bssl::UniquePtr<X509> root(CertFromPEM(kRootCAPEM)); |
| 962 | bssl::UniquePtr<X509> root_cross_signed(CertFromPEM(kRootCrossSignedPEM)); |
| 963 | bssl::UniquePtr<X509> intermediate(CertFromPEM(kIntermediatePEM)); |
| 964 | bssl::UniquePtr<X509> intermediate_self_signed( |
| 965 | CertFromPEM(kIntermediateSelfSignedPEM)); |
| 966 | bssl::UniquePtr<X509> leaf(CertFromPEM(kLeafPEM)); |
| 967 | bssl::UniquePtr<X509> leaf_no_key_usage(CertFromPEM(kLeafNoKeyUsagePEM)); |
| 968 | bssl::UniquePtr<X509> forgery(CertFromPEM(kForgeryPEM)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 969 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 970 | ASSERT_TRUE(cross_signing_root); |
| 971 | ASSERT_TRUE(root); |
| 972 | ASSERT_TRUE(root_cross_signed); |
| 973 | ASSERT_TRUE(intermediate); |
| 974 | ASSERT_TRUE(intermediate_self_signed); |
| 975 | ASSERT_TRUE(leaf); |
| 976 | ASSERT_TRUE(forgery); |
| 977 | ASSERT_TRUE(leaf_no_key_usage); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 978 | |
| 979 | std::vector<X509*> empty; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 980 | std::vector<X509_CRL*> empty_crls; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 981 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, |
| 982 | Verify(leaf.get(), empty, empty, empty_crls)); |
| 983 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, |
| 984 | Verify(leaf.get(), empty, {intermediate.get()}, empty_crls)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 985 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 986 | ASSERT_EQ(X509_V_OK, |
| 987 | Verify(leaf.get(), {root.get()}, {intermediate.get()}, empty_crls)); |
| 988 | ASSERT_EQ(X509_V_OK, |
| 989 | Verify(leaf.get(), {cross_signing_root.get()}, |
| 990 | {intermediate.get(), root_cross_signed.get()}, empty_crls)); |
| 991 | ASSERT_EQ(X509_V_OK, |
| 992 | Verify(leaf.get(), {cross_signing_root.get(), root.get()}, |
| 993 | {intermediate.get(), root_cross_signed.get()}, empty_crls)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 994 | |
| 995 | /* This is the “altchains” test – we remove the cross-signing CA but include |
| 996 | * the cross-sign in the intermediates. */ |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 997 | ASSERT_EQ(X509_V_OK, |
| 998 | Verify(leaf.get(), {root.get()}, |
| 999 | {intermediate.get(), root_cross_signed.get()}, empty_crls)); |
| 1000 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, |
| 1001 | Verify(leaf.get(), {root.get()}, |
| 1002 | {intermediate.get(), root_cross_signed.get()}, empty_crls, |
| 1003 | X509_V_FLAG_NO_ALT_CHAINS)); |
| 1004 | ASSERT_EQ(X509_V_ERR_INVALID_CA, |
| 1005 | Verify(forgery.get(), {intermediate_self_signed.get()}, |
| 1006 | {leaf_no_key_usage.get()}, empty_crls)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1007 | |
| 1008 | /* Test that one cannot skip Basic Constraints checking with a contorted set |
| 1009 | * of roots and intermediates. This is a regression test for CVE-2015-1793. */ |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1010 | ASSERT_EQ(X509_V_ERR_INVALID_CA, |
| 1011 | Verify(forgery.get(), |
| 1012 | {intermediate_self_signed.get(), root_cross_signed.get()}, |
| 1013 | {leaf_no_key_usage.get(), intermediate.get()}, empty_crls)); |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 1014 | } |
Robert Sloan | ab8b888 | 2018-03-26 11:39:51 -0700 | [diff] [blame] | 1015 | |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 1016 | static const char kHostname[] = "example.com"; |
| 1017 | static const char kWrongHostname[] = "example2.com"; |
| 1018 | static const char kEmail[] = "test@example.com"; |
| 1019 | static const char kWrongEmail[] = "test2@example.com"; |
| 1020 | static const uint8_t kIP[4] = {127, 0, 0, 1}; |
| 1021 | static const uint8_t kWrongIP[4] = {127, 0, 0, 2}; |
| 1022 | static const char kIPString[] = "127.0.0.1"; |
| 1023 | static const char kWrongIPString[] = "127.0.0.2"; |
| 1024 | |
| 1025 | TEST(X509Test, ZeroLengthsWithX509PARAM) { |
| 1026 | bssl::UniquePtr<X509> leaf(CertFromPEM(kSANTypesLeaf)); |
| 1027 | bssl::UniquePtr<X509> root(CertFromPEM(kSANTypesRoot)); |
| 1028 | ASSERT_TRUE(leaf); |
| 1029 | ASSERT_TRUE(root); |
| 1030 | |
| 1031 | std::vector<X509_CRL *> empty_crls; |
| 1032 | |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 1033 | struct X509Test { |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 1034 | const char *correct_value; |
| 1035 | size_t correct_value_len; |
| 1036 | const char *incorrect_value; |
| 1037 | size_t incorrect_value_len; |
| 1038 | int (*func)(X509_VERIFY_PARAM *, const char *, size_t); |
| 1039 | int mismatch_error; |
| 1040 | }; |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 1041 | const std::vector<X509Test> kTests = { |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 1042 | {kHostname, strlen(kHostname), kWrongHostname, strlen(kWrongHostname), |
| 1043 | X509_VERIFY_PARAM_set1_host, X509_V_ERR_HOSTNAME_MISMATCH}, |
| 1044 | {kEmail, strlen(kEmail), kWrongEmail, strlen(kWrongEmail), |
| 1045 | X509_VERIFY_PARAM_set1_email, X509_V_ERR_EMAIL_MISMATCH}, |
| 1046 | }; |
| 1047 | |
| 1048 | for (size_t i = 0; i < kTests.size(); i++) { |
| 1049 | SCOPED_TRACE(i); |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 1050 | const X509Test &test = kTests[i]; |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 1051 | |
| 1052 | // The correct value should work. |
| 1053 | ASSERT_EQ(X509_V_OK, |
| 1054 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 1055 | [&test](X509_VERIFY_PARAM *param) { |
| 1056 | ASSERT_TRUE(test.func(param, test.correct_value, |
| 1057 | test.correct_value_len)); |
| 1058 | })); |
| 1059 | |
| 1060 | // The wrong value should trigger a verification error. |
| 1061 | ASSERT_EQ(test.mismatch_error, |
| 1062 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 1063 | [&test](X509_VERIFY_PARAM *param) { |
| 1064 | ASSERT_TRUE(test.func(param, test.incorrect_value, |
| 1065 | test.incorrect_value_len)); |
| 1066 | })); |
| 1067 | |
| 1068 | // Passing zero as the length, unlike OpenSSL, should trigger an error and |
| 1069 | // should cause verification to fail. |
| 1070 | ASSERT_EQ(X509_V_ERR_INVALID_CALL, |
| 1071 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 1072 | [&test](X509_VERIFY_PARAM *param) { |
| 1073 | ASSERT_FALSE(test.func(param, test.correct_value, 0)); |
| 1074 | })); |
| 1075 | |
| 1076 | // Passing an empty value should be an error when setting and should cause |
| 1077 | // verification to fail. |
| 1078 | ASSERT_EQ(X509_V_ERR_INVALID_CALL, |
| 1079 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 1080 | [&test](X509_VERIFY_PARAM *param) { |
| 1081 | ASSERT_FALSE(test.func(param, nullptr, 0)); |
| 1082 | })); |
| 1083 | |
| 1084 | // Passing a value with embedded NULs should also be an error and should |
| 1085 | // also cause verification to fail. |
| 1086 | ASSERT_EQ(X509_V_ERR_INVALID_CALL, |
| 1087 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 1088 | [&test](X509_VERIFY_PARAM *param) { |
| 1089 | ASSERT_FALSE(test.func(param, "a", 2)); |
| 1090 | })); |
| 1091 | } |
| 1092 | |
| 1093 | // IP addresses work slightly differently: |
| 1094 | |
| 1095 | // The correct value should still work. |
| 1096 | ASSERT_EQ(X509_V_OK, Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, |
| 1097 | false, [](X509_VERIFY_PARAM *param) { |
| 1098 | ASSERT_TRUE(X509_VERIFY_PARAM_set1_ip( |
| 1099 | param, kIP, sizeof(kIP))); |
| 1100 | })); |
| 1101 | |
| 1102 | // Incorrect values should still fail. |
| 1103 | ASSERT_EQ(X509_V_ERR_IP_ADDRESS_MISMATCH, |
| 1104 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 1105 | [](X509_VERIFY_PARAM *param) { |
| 1106 | ASSERT_TRUE(X509_VERIFY_PARAM_set1_ip(param, kWrongIP, |
| 1107 | sizeof(kWrongIP))); |
| 1108 | })); |
| 1109 | |
| 1110 | // Zero length values should trigger an error when setting and cause |
| 1111 | // verification to always fail. |
| 1112 | ASSERT_EQ(X509_V_ERR_INVALID_CALL, |
| 1113 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 1114 | [](X509_VERIFY_PARAM *param) { |
| 1115 | ASSERT_FALSE(X509_VERIFY_PARAM_set1_ip(param, kIP, 0)); |
| 1116 | })); |
| 1117 | |
| 1118 | // ... and so should NULL values. |
| 1119 | ASSERT_EQ(X509_V_ERR_INVALID_CALL, |
| 1120 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 1121 | [](X509_VERIFY_PARAM *param) { |
| 1122 | ASSERT_FALSE(X509_VERIFY_PARAM_set1_ip(param, nullptr, 0)); |
| 1123 | })); |
| 1124 | |
| 1125 | // Zero bytes in an IP address are, of course, fine. This is tested above |
| 1126 | // because |kIP| contains zeros. |
| 1127 | } |
| 1128 | |
| 1129 | TEST(X509Test, ZeroLengthsWithCheckFunctions) { |
| 1130 | bssl::UniquePtr<X509> leaf(CertFromPEM(kSANTypesLeaf)); |
| 1131 | |
| 1132 | EXPECT_EQ( |
| 1133 | 1, X509_check_host(leaf.get(), kHostname, strlen(kHostname), 0, nullptr)); |
| 1134 | EXPECT_NE(1, X509_check_host(leaf.get(), kWrongHostname, |
| 1135 | strlen(kWrongHostname), 0, nullptr)); |
| 1136 | |
| 1137 | EXPECT_EQ(1, X509_check_email(leaf.get(), kEmail, strlen(kEmail), 0)); |
| 1138 | EXPECT_NE(1, |
| 1139 | X509_check_email(leaf.get(), kWrongEmail, strlen(kWrongEmail), 0)); |
| 1140 | |
| 1141 | EXPECT_EQ(1, X509_check_ip(leaf.get(), kIP, sizeof(kIP), 0)); |
| 1142 | EXPECT_NE(1, X509_check_ip(leaf.get(), kWrongIP, sizeof(kWrongIP), 0)); |
| 1143 | |
| 1144 | EXPECT_EQ(1, X509_check_ip_asc(leaf.get(), kIPString, 0)); |
| 1145 | EXPECT_NE(1, X509_check_ip_asc(leaf.get(), kWrongIPString, 0)); |
| 1146 | |
| 1147 | // OpenSSL supports passing zero as the length for host and email. We do not |
| 1148 | // and it should always fail. |
| 1149 | EXPECT_NE(1, X509_check_host(leaf.get(), kHostname, 0, 0, nullptr)); |
| 1150 | EXPECT_NE(1, X509_check_host(leaf.get(), kWrongHostname, 0, 0, nullptr)); |
| 1151 | |
| 1152 | EXPECT_NE(1, X509_check_email(leaf.get(), kEmail, 0, 0)); |
| 1153 | EXPECT_NE(1, X509_check_email(leaf.get(), kWrongEmail, 0, 0)); |
| 1154 | |
| 1155 | EXPECT_NE(1, X509_check_ip(leaf.get(), kIP, 0, 0)); |
| 1156 | EXPECT_NE(1, X509_check_ip(leaf.get(), kWrongIP, 0, 0)); |
| 1157 | |
| 1158 | // Unlike all the other functions, |X509_check_ip_asc| doesn't take a length, |
| 1159 | // so it cannot be zero. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1160 | } |
| 1161 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1162 | TEST(X509Test, TestCRL) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1163 | bssl::UniquePtr<X509> root(CertFromPEM(kCRLTestRoot)); |
| 1164 | bssl::UniquePtr<X509> leaf(CertFromPEM(kCRLTestLeaf)); |
| 1165 | bssl::UniquePtr<X509_CRL> basic_crl(CRLFromPEM(kBasicCRL)); |
| 1166 | bssl::UniquePtr<X509_CRL> revoked_crl(CRLFromPEM(kRevokedCRL)); |
| 1167 | bssl::UniquePtr<X509_CRL> bad_issuer_crl(CRLFromPEM(kBadIssuerCRL)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1168 | bssl::UniquePtr<X509_CRL> known_critical_crl(CRLFromPEM(kKnownCriticalCRL)); |
| 1169 | bssl::UniquePtr<X509_CRL> unknown_critical_crl( |
| 1170 | CRLFromPEM(kUnknownCriticalCRL)); |
| 1171 | bssl::UniquePtr<X509_CRL> unknown_critical_crl2( |
| 1172 | CRLFromPEM(kUnknownCriticalCRL2)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1173 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1174 | ASSERT_TRUE(root); |
| 1175 | ASSERT_TRUE(leaf); |
| 1176 | ASSERT_TRUE(basic_crl); |
| 1177 | ASSERT_TRUE(revoked_crl); |
| 1178 | ASSERT_TRUE(bad_issuer_crl); |
| 1179 | ASSERT_TRUE(known_critical_crl); |
| 1180 | ASSERT_TRUE(unknown_critical_crl); |
| 1181 | ASSERT_TRUE(unknown_critical_crl2); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1182 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1183 | ASSERT_EQ(X509_V_OK, Verify(leaf.get(), {root.get()}, {root.get()}, |
| 1184 | {basic_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 1185 | ASSERT_EQ( |
| 1186 | X509_V_ERR_CERT_REVOKED, |
| 1187 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 1188 | {basic_crl.get(), revoked_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1189 | |
| 1190 | std::vector<X509_CRL *> empty_crls; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1191 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_CRL, |
| 1192 | Verify(leaf.get(), {root.get()}, {root.get()}, empty_crls, |
| 1193 | X509_V_FLAG_CRL_CHECK)); |
| 1194 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_CRL, |
| 1195 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 1196 | {bad_issuer_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 1197 | ASSERT_EQ(X509_V_OK, |
| 1198 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 1199 | {known_critical_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 1200 | ASSERT_EQ(X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION, |
| 1201 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 1202 | {unknown_critical_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 1203 | ASSERT_EQ(X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION, |
| 1204 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 1205 | {unknown_critical_crl2.get()}, X509_V_FLAG_CRL_CHECK)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1206 | } |
| 1207 | |
Robert Sloan | 2e9e66a | 2017-09-25 09:08:29 -0700 | [diff] [blame] | 1208 | TEST(X509Test, ManyNamesAndConstraints) { |
| 1209 | bssl::UniquePtr<X509> many_constraints( |
| 1210 | CertFromPEM(GetTestData("crypto/x509/many_constraints.pem").c_str())); |
| 1211 | ASSERT_TRUE(many_constraints); |
| 1212 | bssl::UniquePtr<X509> many_names1( |
| 1213 | CertFromPEM(GetTestData("crypto/x509/many_names1.pem").c_str())); |
| 1214 | ASSERT_TRUE(many_names1); |
| 1215 | bssl::UniquePtr<X509> many_names2( |
| 1216 | CertFromPEM(GetTestData("crypto/x509/many_names2.pem").c_str())); |
| 1217 | ASSERT_TRUE(many_names2); |
| 1218 | bssl::UniquePtr<X509> many_names3( |
| 1219 | CertFromPEM(GetTestData("crypto/x509/many_names3.pem").c_str())); |
| 1220 | ASSERT_TRUE(many_names3); |
| 1221 | bssl::UniquePtr<X509> some_names1( |
| 1222 | CertFromPEM(GetTestData("crypto/x509/some_names1.pem").c_str())); |
| 1223 | ASSERT_TRUE(some_names1); |
| 1224 | bssl::UniquePtr<X509> some_names2( |
| 1225 | CertFromPEM(GetTestData("crypto/x509/some_names2.pem").c_str())); |
| 1226 | ASSERT_TRUE(some_names2); |
| 1227 | bssl::UniquePtr<X509> some_names3( |
| 1228 | CertFromPEM(GetTestData("crypto/x509/some_names3.pem").c_str())); |
| 1229 | ASSERT_TRUE(some_names3); |
| 1230 | |
| 1231 | EXPECT_EQ(X509_V_ERR_UNSPECIFIED, |
| 1232 | Verify(many_names1.get(), {many_constraints.get()}, |
| 1233 | {many_constraints.get()}, {})); |
| 1234 | EXPECT_EQ(X509_V_ERR_UNSPECIFIED, |
| 1235 | Verify(many_names2.get(), {many_constraints.get()}, |
| 1236 | {many_constraints.get()}, {})); |
| 1237 | EXPECT_EQ(X509_V_ERR_UNSPECIFIED, |
| 1238 | Verify(many_names3.get(), {many_constraints.get()}, |
| 1239 | {many_constraints.get()}, {})); |
| 1240 | |
| 1241 | EXPECT_EQ(X509_V_OK, Verify(some_names1.get(), {many_constraints.get()}, |
| 1242 | {many_constraints.get()}, {})); |
| 1243 | EXPECT_EQ(X509_V_OK, Verify(some_names2.get(), {many_constraints.get()}, |
| 1244 | {many_constraints.get()}, {})); |
| 1245 | EXPECT_EQ(X509_V_OK, Verify(some_names3.get(), {many_constraints.get()}, |
| 1246 | {many_constraints.get()}, {})); |
| 1247 | } |
| 1248 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1249 | TEST(X509Test, TestPSS) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1250 | bssl::UniquePtr<X509> cert(CertFromPEM(kExamplePSSCert)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1251 | ASSERT_TRUE(cert); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1252 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1253 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1254 | ASSERT_TRUE(pkey); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1255 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1256 | ASSERT_TRUE(X509_verify(cert.get(), pkey.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1257 | } |
| 1258 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1259 | TEST(X509Test, TestPSSBadParameters) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1260 | bssl::UniquePtr<X509> cert(CertFromPEM(kBadPSSCertPEM)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1261 | ASSERT_TRUE(cert); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1262 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1263 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1264 | ASSERT_TRUE(pkey); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1265 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1266 | ASSERT_FALSE(X509_verify(cert.get(), pkey.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1267 | ERR_clear_error(); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1268 | } |
| 1269 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1270 | TEST(X509Test, TestEd25519) { |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1271 | bssl::UniquePtr<X509> cert(CertFromPEM(kEd25519Cert)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1272 | ASSERT_TRUE(cert); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1273 | |
| 1274 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1275 | ASSERT_TRUE(pkey); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1276 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1277 | ASSERT_TRUE(X509_verify(cert.get(), pkey.get())); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1280 | TEST(X509Test, TestEd25519BadParameters) { |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1281 | bssl::UniquePtr<X509> cert(CertFromPEM(kEd25519CertNull)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1282 | ASSERT_TRUE(cert); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1283 | |
| 1284 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1285 | ASSERT_TRUE(pkey); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1286 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1287 | ASSERT_FALSE(X509_verify(cert.get(), pkey.get())); |
| 1288 | |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1289 | uint32_t err = ERR_get_error(); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1290 | ASSERT_EQ(ERR_LIB_X509, ERR_GET_LIB(err)); |
| 1291 | ASSERT_EQ(X509_R_INVALID_PARAMETER, ERR_GET_REASON(err)); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1292 | ERR_clear_error(); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1295 | static bool SignatureRoundTrips(EVP_MD_CTX *md_ctx, EVP_PKEY *pkey) { |
| 1296 | // Make a certificate like signed with |md_ctx|'s settings.' |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1297 | bssl::UniquePtr<X509> cert(CertFromPEM(kLeafPEM)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1298 | if (!cert || !X509_sign_ctx(cert.get(), md_ctx)) { |
| 1299 | return false; |
| 1300 | } |
| 1301 | |
| 1302 | // Ensure that |pkey| may still be used to verify the resulting signature. All |
| 1303 | // settings in |md_ctx| must have been serialized appropriately. |
| 1304 | return !!X509_verify(cert.get(), pkey); |
| 1305 | } |
| 1306 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1307 | TEST(X509Test, RSASign) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1308 | bssl::UniquePtr<EVP_PKEY> pkey(PrivateKeyFromPEM(kRSAKey)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1309 | ASSERT_TRUE(pkey); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1310 | // Test PKCS#1 v1.5. |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1311 | bssl::ScopedEVP_MD_CTX md_ctx; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1312 | ASSERT_TRUE( |
| 1313 | EVP_DigestSignInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get())); |
| 1314 | ASSERT_TRUE(SignatureRoundTrips(md_ctx.get(), pkey.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1315 | |
| 1316 | // Test RSA-PSS with custom parameters. |
| 1317 | md_ctx.Reset(); |
| 1318 | EVP_PKEY_CTX *pkey_ctx; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1319 | ASSERT_TRUE(EVP_DigestSignInit(md_ctx.get(), &pkey_ctx, EVP_sha256(), NULL, |
| 1320 | pkey.get())); |
| 1321 | ASSERT_TRUE(EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING)); |
| 1322 | ASSERT_TRUE(EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, EVP_sha512())); |
| 1323 | ASSERT_TRUE(SignatureRoundTrips(md_ctx.get(), pkey.get())); |
| 1324 | } |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1325 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1326 | TEST(X509Test, Ed25519Sign) { |
| 1327 | uint8_t pub_bytes[32], priv_bytes[64]; |
| 1328 | ED25519_keypair(pub_bytes, priv_bytes); |
| 1329 | |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 1330 | bssl::UniquePtr<EVP_PKEY> pub( |
| 1331 | EVP_PKEY_new_raw_public_key(EVP_PKEY_ED25519, nullptr, pub_bytes, 32)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1332 | ASSERT_TRUE(pub); |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 1333 | bssl::UniquePtr<EVP_PKEY> priv( |
| 1334 | EVP_PKEY_new_raw_private_key(EVP_PKEY_ED25519, nullptr, priv_bytes, 32)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1335 | ASSERT_TRUE(priv); |
| 1336 | |
| 1337 | bssl::ScopedEVP_MD_CTX md_ctx; |
| 1338 | ASSERT_TRUE( |
| 1339 | EVP_DigestSignInit(md_ctx.get(), nullptr, nullptr, nullptr, priv.get())); |
| 1340 | ASSERT_TRUE(SignatureRoundTrips(md_ctx.get(), pub.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1341 | } |
| 1342 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1343 | static bool PEMToDER(bssl::UniquePtr<uint8_t> *out, size_t *out_len, |
| 1344 | const char *pem) { |
| 1345 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(pem, strlen(pem))); |
| 1346 | if (!bio) { |
| 1347 | return false; |
| 1348 | } |
| 1349 | |
| 1350 | char *name, *header; |
| 1351 | uint8_t *data; |
| 1352 | long data_len; |
| 1353 | if (!PEM_read_bio(bio.get(), &name, &header, &data, &data_len)) { |
| 1354 | fprintf(stderr, "failed to read PEM data.\n"); |
| 1355 | return false; |
| 1356 | } |
| 1357 | OPENSSL_free(name); |
| 1358 | OPENSSL_free(header); |
| 1359 | |
| 1360 | out->reset(data); |
| 1361 | *out_len = data_len; |
| 1362 | |
| 1363 | return true; |
| 1364 | } |
| 1365 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1366 | TEST(X509Test, TestFromBuffer) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1367 | size_t data_len; |
| 1368 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1369 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1370 | |
| 1371 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 1372 | CRYPTO_BUFFER_new(data.get(), data_len, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1373 | ASSERT_TRUE(buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1374 | bssl::UniquePtr<X509> root(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1375 | ASSERT_TRUE(root); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1376 | |
| 1377 | const uint8_t *enc_pointer = root->cert_info->enc.enc; |
| 1378 | const uint8_t *buf_pointer = CRYPTO_BUFFER_data(buf.get()); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1379 | ASSERT_GE(enc_pointer, buf_pointer); |
| 1380 | ASSERT_LT(enc_pointer, buf_pointer + CRYPTO_BUFFER_len(buf.get())); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1381 | buf.reset(); |
| 1382 | |
| 1383 | /* This ensures the X509 took a reference to |buf|, otherwise this will be a |
| 1384 | * reference to free memory and ASAN should notice. */ |
Robert Sloan | 0da4395 | 2018-01-03 15:13:14 -0800 | [diff] [blame] | 1385 | ASSERT_EQ(0x30, enc_pointer[0]); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1386 | } |
| 1387 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1388 | TEST(X509Test, TestFromBufferWithTrailingData) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1389 | size_t data_len; |
| 1390 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1391 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1392 | |
| 1393 | std::unique_ptr<uint8_t[]> trailing_data(new uint8_t[data_len + 1]); |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 1394 | OPENSSL_memcpy(trailing_data.get(), data.get(), data_len); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1395 | |
| 1396 | bssl::UniquePtr<CRYPTO_BUFFER> buf_trailing_data( |
| 1397 | CRYPTO_BUFFER_new(trailing_data.get(), data_len + 1, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1398 | ASSERT_TRUE(buf_trailing_data); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1399 | |
| 1400 | bssl::UniquePtr<X509> root_trailing_data( |
| 1401 | X509_parse_from_buffer(buf_trailing_data.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1402 | ASSERT_FALSE(root_trailing_data); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1403 | } |
| 1404 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1405 | TEST(X509Test, TestFromBufferModified) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1406 | size_t data_len; |
| 1407 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1408 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1409 | |
| 1410 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 1411 | CRYPTO_BUFFER_new(data.get(), data_len, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1412 | ASSERT_TRUE(buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1413 | |
| 1414 | bssl::UniquePtr<X509> root(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1415 | ASSERT_TRUE(root); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1416 | |
| 1417 | bssl::UniquePtr<ASN1_INTEGER> fourty_two(ASN1_INTEGER_new()); |
| 1418 | ASN1_INTEGER_set(fourty_two.get(), 42); |
| 1419 | X509_set_serialNumber(root.get(), fourty_two.get()); |
| 1420 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1421 | ASSERT_EQ(static_cast<long>(data_len), i2d_X509(root.get(), nullptr)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1422 | |
| 1423 | X509_CINF_set_modified(root->cert_info); |
| 1424 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1425 | ASSERT_NE(static_cast<long>(data_len), i2d_X509(root.get(), nullptr)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1426 | } |
| 1427 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1428 | TEST(X509Test, TestFromBufferReused) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1429 | size_t data_len; |
| 1430 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1431 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1432 | |
| 1433 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 1434 | CRYPTO_BUFFER_new(data.get(), data_len, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1435 | ASSERT_TRUE(buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1436 | |
| 1437 | bssl::UniquePtr<X509> root(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1438 | ASSERT_TRUE(root); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1439 | |
| 1440 | size_t data2_len; |
| 1441 | bssl::UniquePtr<uint8_t> data2; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1442 | ASSERT_TRUE(PEMToDER(&data2, &data2_len, kLeafPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1443 | |
| 1444 | X509 *x509p = root.get(); |
| 1445 | const uint8_t *inp = data2.get(); |
| 1446 | X509 *ret = d2i_X509(&x509p, &inp, data2_len); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1447 | ASSERT_EQ(root.get(), ret); |
| 1448 | ASSERT_EQ(nullptr, root->buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1449 | |
| 1450 | // Free |data2| and ensure that |root| took its own copy. Otherwise the |
| 1451 | // following will trigger a use-after-free. |
| 1452 | data2.reset(); |
| 1453 | |
| 1454 | uint8_t *i2d = nullptr; |
| 1455 | int i2d_len = i2d_X509(root.get(), &i2d); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1456 | ASSERT_GE(i2d_len, 0); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1457 | bssl::UniquePtr<uint8_t> i2d_storage(i2d); |
| 1458 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1459 | ASSERT_TRUE(PEMToDER(&data2, &data2_len, kLeafPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1460 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1461 | ASSERT_EQ(static_cast<long>(data2_len), i2d_len); |
| 1462 | ASSERT_EQ(0, OPENSSL_memcmp(data2.get(), i2d, i2d_len)); |
| 1463 | ASSERT_EQ(nullptr, root->buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1464 | } |
| 1465 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1466 | TEST(X509Test, TestFailedParseFromBuffer) { |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1467 | static const uint8_t kNonsense[] = {1, 2, 3, 4, 5}; |
| 1468 | |
| 1469 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 1470 | CRYPTO_BUFFER_new(kNonsense, sizeof(kNonsense), nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1471 | ASSERT_TRUE(buf); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1472 | |
| 1473 | bssl::UniquePtr<X509> cert(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1474 | ASSERT_FALSE(cert); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1475 | ERR_clear_error(); |
| 1476 | |
| 1477 | // Test a buffer with trailing data. |
| 1478 | size_t data_len; |
| 1479 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1480 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1481 | |
| 1482 | std::unique_ptr<uint8_t[]> data_with_trailing_byte(new uint8_t[data_len + 1]); |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 1483 | OPENSSL_memcpy(data_with_trailing_byte.get(), data.get(), data_len); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1484 | data_with_trailing_byte[data_len] = 0; |
| 1485 | |
| 1486 | bssl::UniquePtr<CRYPTO_BUFFER> buf_with_trailing_byte( |
| 1487 | CRYPTO_BUFFER_new(data_with_trailing_byte.get(), data_len + 1, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1488 | ASSERT_TRUE(buf_with_trailing_byte); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1489 | |
| 1490 | bssl::UniquePtr<X509> root( |
| 1491 | X509_parse_from_buffer(buf_with_trailing_byte.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1492 | ASSERT_FALSE(root); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1493 | ERR_clear_error(); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1494 | } |
| 1495 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1496 | TEST(X509Test, TestPrintUTCTIME) { |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 1497 | static const struct { |
| 1498 | const char *val, *want; |
| 1499 | } asn1_utctime_tests[] = { |
| 1500 | {"", "Bad time value"}, |
| 1501 | |
| 1502 | // Correct RFC 5280 form. Test years < 2000 and > 2000. |
| 1503 | {"090303125425Z", "Mar 3 12:54:25 2009 GMT"}, |
| 1504 | {"900303125425Z", "Mar 3 12:54:25 1990 GMT"}, |
| 1505 | {"000303125425Z", "Mar 3 12:54:25 2000 GMT"}, |
| 1506 | |
| 1507 | // Correct form, bad values. |
| 1508 | {"000000000000Z", "Bad time value"}, |
| 1509 | {"999999999999Z", "Bad time value"}, |
| 1510 | |
| 1511 | // Missing components. Not legal RFC 5280, but permitted. |
| 1512 | {"090303125425", "Mar 3 12:54:25 2009"}, |
| 1513 | {"9003031254", "Mar 3 12:54:00 1990"}, |
| 1514 | {"9003031254Z", "Mar 3 12:54:00 1990 GMT"}, |
| 1515 | |
| 1516 | // GENERALIZEDTIME confused for UTCTIME. |
| 1517 | {"20090303125425Z", "Bad time value"}, |
| 1518 | |
| 1519 | // Legal ASN.1, but not legal RFC 5280. |
| 1520 | {"9003031254+0800", "Bad time value"}, |
| 1521 | {"9003031254-0800", "Bad time value"}, |
| 1522 | |
| 1523 | // Trailing garbage. |
| 1524 | {"9003031254Z ", "Bad time value"}, |
| 1525 | }; |
| 1526 | |
| 1527 | for (auto t : asn1_utctime_tests) { |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1528 | SCOPED_TRACE(t.val); |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 1529 | bssl::UniquePtr<ASN1_UTCTIME> tm(ASN1_UTCTIME_new()); |
| 1530 | bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem())); |
| 1531 | |
| 1532 | // Use this instead of ASN1_UTCTIME_set() because some callers get |
| 1533 | // type-confused and pass ASN1_GENERALIZEDTIME to ASN1_UTCTIME_print(). |
| 1534 | // ASN1_UTCTIME_set_string() is stricter, and would reject the inputs in |
| 1535 | // question. |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1536 | ASSERT_TRUE(ASN1_STRING_set(tm.get(), t.val, strlen(t.val))); |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 1537 | const int ok = ASN1_UTCTIME_print(bio.get(), tm.get()); |
| 1538 | |
| 1539 | const uint8_t *contents; |
| 1540 | size_t len; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1541 | ASSERT_TRUE(BIO_mem_contents(bio.get(), &contents, &len)); |
| 1542 | EXPECT_EQ(ok, (strcmp(t.want, "Bad time value") != 0) ? 1 : 0); |
| 1543 | EXPECT_EQ(t.want, |
| 1544 | std::string(reinterpret_cast<const char *>(contents), len)); |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 1545 | } |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1546 | } |
Robert Sloan | a815d5a | 2017-12-04 11:49:16 -0800 | [diff] [blame] | 1547 | |
| 1548 | TEST(X509Test, PrettyPrintIntegers) { |
| 1549 | static const char *kTests[] = { |
| 1550 | // Small numbers are pretty-printed in decimal. |
| 1551 | "0", |
| 1552 | "-1", |
| 1553 | "1", |
| 1554 | "42", |
| 1555 | "-42", |
| 1556 | "256", |
| 1557 | "-256", |
| 1558 | // Large numbers are pretty-printed in hex to avoid taking quadratic time. |
| 1559 | "0x0123456789", |
| 1560 | "-0x0123456789", |
| 1561 | }; |
| 1562 | for (const char *in : kTests) { |
| 1563 | SCOPED_TRACE(in); |
| 1564 | BIGNUM *bn = nullptr; |
| 1565 | ASSERT_TRUE(BN_asc2bn(&bn, in)); |
| 1566 | bssl::UniquePtr<BIGNUM> free_bn(bn); |
| 1567 | |
| 1568 | { |
| 1569 | bssl::UniquePtr<ASN1_INTEGER> asn1(BN_to_ASN1_INTEGER(bn, nullptr)); |
| 1570 | ASSERT_TRUE(asn1); |
| 1571 | bssl::UniquePtr<char> out(i2s_ASN1_INTEGER(nullptr, asn1.get())); |
| 1572 | ASSERT_TRUE(out.get()); |
| 1573 | EXPECT_STREQ(in, out.get()); |
| 1574 | } |
| 1575 | |
| 1576 | { |
| 1577 | bssl::UniquePtr<ASN1_ENUMERATED> asn1(BN_to_ASN1_ENUMERATED(bn, nullptr)); |
| 1578 | ASSERT_TRUE(asn1); |
| 1579 | bssl::UniquePtr<char> out(i2s_ASN1_ENUMERATED(nullptr, asn1.get())); |
| 1580 | ASSERT_TRUE(out.get()); |
| 1581 | EXPECT_STREQ(in, out.get()); |
| 1582 | } |
| 1583 | } |
| 1584 | } |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 1585 | |
| 1586 | TEST(X509Test, X509NameSet) { |
| 1587 | bssl::UniquePtr<X509_NAME> name(X509_NAME_new()); |
| 1588 | EXPECT_TRUE(X509_NAME_add_entry_by_txt( |
| 1589 | name.get(), "C", MBSTRING_ASC, reinterpret_cast<const uint8_t *>("US"), |
| 1590 | -1, -1, 0)); |
| 1591 | EXPECT_EQ(X509_NAME_entry_count(name.get()), 1); |
| 1592 | EXPECT_TRUE(X509_NAME_add_entry_by_txt( |
| 1593 | name.get(), "C", MBSTRING_ASC, reinterpret_cast<const uint8_t *>("CA"), |
| 1594 | -1, -1, 0)); |
| 1595 | EXPECT_EQ(X509_NAME_entry_count(name.get()), 2); |
| 1596 | EXPECT_TRUE(X509_NAME_add_entry_by_txt( |
| 1597 | name.get(), "C", MBSTRING_ASC, reinterpret_cast<const uint8_t *>("UK"), |
| 1598 | -1, -1, 0)); |
| 1599 | EXPECT_EQ(X509_NAME_entry_count(name.get()), 3); |
| 1600 | EXPECT_TRUE(X509_NAME_add_entry_by_txt( |
| 1601 | name.get(), "C", MBSTRING_ASC, reinterpret_cast<const uint8_t *>("JP"), |
| 1602 | -1, 1, 0)); |
| 1603 | EXPECT_EQ(X509_NAME_entry_count(name.get()), 4); |
| 1604 | |
| 1605 | // Check that the correct entries get incremented when inserting new entry. |
| 1606 | EXPECT_EQ(X509_NAME_ENTRY_set(X509_NAME_get_entry(name.get(), 1)), 1); |
| 1607 | EXPECT_EQ(X509_NAME_ENTRY_set(X509_NAME_get_entry(name.get(), 2)), 2); |
| 1608 | } |
| 1609 | |
| 1610 | TEST(X509Test, StringDecoding) { |
| 1611 | static const struct { |
| 1612 | std::vector<uint8_t> in; |
| 1613 | int type; |
| 1614 | const char *expected; |
| 1615 | } kTests[] = { |
| 1616 | // Non-minimal, two-byte UTF-8. |
| 1617 | {{0xc0, 0x81}, V_ASN1_UTF8STRING, nullptr}, |
| 1618 | // Non-minimal, three-byte UTF-8. |
| 1619 | {{0xe0, 0x80, 0x81}, V_ASN1_UTF8STRING, nullptr}, |
| 1620 | // Non-minimal, four-byte UTF-8. |
| 1621 | {{0xf0, 0x80, 0x80, 0x81}, V_ASN1_UTF8STRING, nullptr}, |
| 1622 | // Truncated, four-byte UTF-8. |
| 1623 | {{0xf0, 0x80, 0x80}, V_ASN1_UTF8STRING, nullptr}, |
| 1624 | // Low-surrogate value. |
| 1625 | {{0xed, 0xa0, 0x80}, V_ASN1_UTF8STRING, nullptr}, |
| 1626 | // High-surrogate value. |
| 1627 | {{0xed, 0xb0, 0x81}, V_ASN1_UTF8STRING, nullptr}, |
| 1628 | // Initial BOMs should be rejected from UCS-2 and UCS-4. |
| 1629 | {{0xfe, 0xff, 0, 88}, V_ASN1_BMPSTRING, nullptr}, |
| 1630 | {{0, 0, 0xfe, 0xff, 0, 0, 0, 88}, V_ASN1_UNIVERSALSTRING, nullptr}, |
| 1631 | // Otherwise, BOMs should pass through. |
| 1632 | {{0, 88, 0xfe, 0xff}, V_ASN1_BMPSTRING, "X\xef\xbb\xbf"}, |
| 1633 | {{0, 0, 0, 88, 0, 0, 0xfe, 0xff}, V_ASN1_UNIVERSALSTRING, |
| 1634 | "X\xef\xbb\xbf"}, |
| 1635 | // The maximum code-point should pass though. |
| 1636 | {{0, 16, 0xff, 0xfd}, V_ASN1_UNIVERSALSTRING, "\xf4\x8f\xbf\xbd"}, |
| 1637 | // Values outside the Unicode space should not. |
| 1638 | {{0, 17, 0, 0}, V_ASN1_UNIVERSALSTRING, nullptr}, |
| 1639 | // Non-characters should be rejected. |
| 1640 | {{0, 1, 0xff, 0xff}, V_ASN1_UNIVERSALSTRING, nullptr}, |
| 1641 | {{0, 1, 0xff, 0xfe}, V_ASN1_UNIVERSALSTRING, nullptr}, |
| 1642 | {{0, 0, 0xfd, 0xd5}, V_ASN1_UNIVERSALSTRING, nullptr}, |
| 1643 | // BMPString is UCS-2, not UTF-16, so surrogate pairs are invalid. |
| 1644 | {{0xd8, 0, 0xdc, 1}, V_ASN1_BMPSTRING, nullptr}, |
| 1645 | }; |
| 1646 | |
| 1647 | for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kTests); i++) { |
| 1648 | SCOPED_TRACE(i); |
| 1649 | const auto& test = kTests[i]; |
| 1650 | ASN1_STRING s; |
| 1651 | s.type = test.type; |
| 1652 | s.data = const_cast<uint8_t*>(test.in.data()); |
| 1653 | s.length = test.in.size(); |
| 1654 | |
| 1655 | uint8_t *utf8; |
| 1656 | const int utf8_len = ASN1_STRING_to_UTF8(&utf8, &s); |
| 1657 | EXPECT_EQ(utf8_len < 0, test.expected == nullptr); |
| 1658 | if (utf8_len >= 0) { |
| 1659 | if (test.expected != nullptr) { |
| 1660 | EXPECT_EQ(Bytes(test.expected), Bytes(utf8, utf8_len)); |
| 1661 | } |
| 1662 | OPENSSL_free(utf8); |
| 1663 | } else { |
| 1664 | ERR_clear_error(); |
| 1665 | } |
| 1666 | } |
| 1667 | } |
| 1668 | |
| 1669 | TEST(X509Test, NoBasicConstraintsCertSign) { |
| 1670 | bssl::UniquePtr<X509> root(CertFromPEM(kSANTypesRoot)); |
| 1671 | bssl::UniquePtr<X509> intermediate( |
| 1672 | CertFromPEM(kNoBasicConstraintsCertSignIntermediate)); |
| 1673 | bssl::UniquePtr<X509> leaf(CertFromPEM(kNoBasicConstraintsCertSignLeaf)); |
| 1674 | |
| 1675 | ASSERT_TRUE(root); |
| 1676 | ASSERT_TRUE(intermediate); |
| 1677 | ASSERT_TRUE(leaf); |
| 1678 | |
| 1679 | // The intermediate has keyUsage certSign, but is not marked as a CA in the |
| 1680 | // basicConstraints. |
| 1681 | EXPECT_EQ(X509_V_ERR_INVALID_CA, |
| 1682 | Verify(leaf.get(), {root.get()}, {intermediate.get()}, {}, 0)); |
| 1683 | } |
| 1684 | |
| 1685 | TEST(X509Test, NoBasicConstraintsNetscapeCA) { |
| 1686 | bssl::UniquePtr<X509> root(CertFromPEM(kSANTypesRoot)); |
| 1687 | bssl::UniquePtr<X509> intermediate( |
| 1688 | CertFromPEM(kNoBasicConstraintsNetscapeCAIntermediate)); |
| 1689 | bssl::UniquePtr<X509> leaf(CertFromPEM(kNoBasicConstraintsNetscapeCALeaf)); |
| 1690 | |
| 1691 | ASSERT_TRUE(root); |
| 1692 | ASSERT_TRUE(intermediate); |
| 1693 | ASSERT_TRUE(leaf); |
| 1694 | |
| 1695 | // The intermediate has a Netscape certificate type of "SSL CA", but is not |
| 1696 | // marked as a CA in the basicConstraints. |
| 1697 | EXPECT_EQ(X509_V_ERR_INVALID_CA, |
| 1698 | Verify(leaf.get(), {root.get()}, {intermediate.get()}, {}, 0)); |
| 1699 | } |
Robert Sloan | 036981b | 2018-09-24 10:20:02 -0700 | [diff] [blame] | 1700 | |
| 1701 | TEST(X509Test, MismatchAlgorithms) { |
| 1702 | bssl::UniquePtr<X509> cert(CertFromPEM(kSelfSignedMismatchAlgorithms)); |
| 1703 | ASSERT_TRUE(cert); |
| 1704 | |
| 1705 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
| 1706 | ASSERT_TRUE(pkey); |
| 1707 | |
| 1708 | EXPECT_FALSE(X509_verify(cert.get(), pkey.get())); |
| 1709 | uint32_t err = ERR_get_error(); |
| 1710 | EXPECT_EQ(ERR_LIB_X509, ERR_GET_LIB(err)); |
| 1711 | EXPECT_EQ(X509_R_SIGNATURE_ALGORITHM_MISMATCH, ERR_GET_REASON(err)); |
| 1712 | } |
Robert Sloan | f068def | 2018-10-10 18:45:40 -0700 | [diff] [blame] | 1713 | |
| 1714 | TEST(X509Test, PEMX509Info) { |
| 1715 | std::string cert = kRootCAPEM; |
| 1716 | auto cert_obj = CertFromPEM(kRootCAPEM); |
| 1717 | ASSERT_TRUE(cert_obj); |
| 1718 | |
| 1719 | std::string rsa = kRSAKey; |
| 1720 | auto rsa_obj = PrivateKeyFromPEM(kRSAKey); |
| 1721 | ASSERT_TRUE(rsa_obj); |
| 1722 | |
| 1723 | std::string crl = kBasicCRL; |
| 1724 | auto crl_obj = CRLFromPEM(kBasicCRL); |
| 1725 | ASSERT_TRUE(crl_obj); |
| 1726 | |
| 1727 | std::string unknown = |
| 1728 | "-----BEGIN UNKNOWN-----\n" |
| 1729 | "AAAA\n" |
| 1730 | "-----END UNKNOWN-----\n"; |
| 1731 | |
| 1732 | std::string invalid = |
| 1733 | "-----BEGIN CERTIFICATE-----\n" |
| 1734 | "AAAA\n" |
| 1735 | "-----END CERTIFICATE-----\n"; |
| 1736 | |
| 1737 | // Each X509_INFO contains at most one certificate, CRL, etc. The format |
| 1738 | // creates a new X509_INFO when a repeated type is seen. |
| 1739 | std::string pem = |
| 1740 | // The first few entries have one of everything in different orders. |
| 1741 | cert + rsa + crl + |
| 1742 | rsa + crl + cert + |
| 1743 | // Unknown types are ignored. |
| 1744 | crl + unknown + cert + rsa + |
| 1745 | // Seeing a new certificate starts a new entry, so now we have a bunch of |
| 1746 | // certificate-only entries. |
| 1747 | cert + cert + cert + |
| 1748 | // The key folds into the certificate's entry. |
| 1749 | cert + rsa + |
| 1750 | // Doubled keys also start new entries. |
| 1751 | rsa + rsa + rsa + rsa + crl + |
| 1752 | // As do CRLs. |
| 1753 | crl + crl; |
| 1754 | |
| 1755 | const struct ExpectedInfo { |
| 1756 | const X509 *cert; |
| 1757 | const EVP_PKEY *key; |
| 1758 | const X509_CRL *crl; |
| 1759 | } kExpected[] = { |
| 1760 | {cert_obj.get(), rsa_obj.get(), crl_obj.get()}, |
| 1761 | {cert_obj.get(), rsa_obj.get(), crl_obj.get()}, |
| 1762 | {cert_obj.get(), rsa_obj.get(), crl_obj.get()}, |
| 1763 | {cert_obj.get(), nullptr, nullptr}, |
| 1764 | {cert_obj.get(), nullptr, nullptr}, |
| 1765 | {cert_obj.get(), nullptr, nullptr}, |
| 1766 | {cert_obj.get(), rsa_obj.get(), nullptr}, |
| 1767 | {nullptr, rsa_obj.get(), nullptr}, |
| 1768 | {nullptr, rsa_obj.get(), nullptr}, |
| 1769 | {nullptr, rsa_obj.get(), nullptr}, |
| 1770 | {nullptr, rsa_obj.get(), crl_obj.get()}, |
| 1771 | {nullptr, nullptr, crl_obj.get()}, |
| 1772 | {nullptr, nullptr, crl_obj.get()}, |
| 1773 | }; |
| 1774 | |
| 1775 | auto check_info = [](const ExpectedInfo *expected, const X509_INFO *info) { |
| 1776 | if (expected->cert != nullptr) { |
| 1777 | EXPECT_EQ(0, X509_cmp(expected->cert, info->x509)); |
| 1778 | } else { |
| 1779 | EXPECT_EQ(nullptr, info->x509); |
| 1780 | } |
| 1781 | if (expected->crl != nullptr) { |
| 1782 | EXPECT_EQ(0, X509_CRL_cmp(expected->crl, info->crl)); |
| 1783 | } else { |
| 1784 | EXPECT_EQ(nullptr, info->crl); |
| 1785 | } |
| 1786 | if (expected->key != nullptr) { |
| 1787 | ASSERT_NE(nullptr, info->x_pkey); |
| 1788 | // EVP_PKEY_cmp returns one if the keys are equal. |
| 1789 | EXPECT_EQ(1, EVP_PKEY_cmp(expected->key, info->x_pkey->dec_pkey)); |
| 1790 | } else { |
| 1791 | EXPECT_EQ(nullptr, info->x_pkey); |
| 1792 | } |
| 1793 | }; |
| 1794 | |
| 1795 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(pem.data(), pem.size())); |
| 1796 | ASSERT_TRUE(bio); |
| 1797 | bssl::UniquePtr<STACK_OF(X509_INFO)> infos( |
| 1798 | PEM_X509_INFO_read_bio(bio.get(), nullptr, nullptr, nullptr)); |
| 1799 | ASSERT_TRUE(infos); |
| 1800 | ASSERT_EQ(OPENSSL_ARRAY_SIZE(kExpected), sk_X509_INFO_num(infos.get())); |
| 1801 | for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kExpected); i++) { |
| 1802 | SCOPED_TRACE(i); |
| 1803 | check_info(&kExpected[i], sk_X509_INFO_value(infos.get(), i)); |
| 1804 | } |
| 1805 | |
| 1806 | // Passing an existing stack appends to it. |
| 1807 | bio.reset(BIO_new_mem_buf(pem.data(), pem.size())); |
| 1808 | ASSERT_TRUE(bio); |
| 1809 | ASSERT_EQ(infos.get(), |
| 1810 | PEM_X509_INFO_read_bio(bio.get(), infos.get(), nullptr, nullptr)); |
| 1811 | ASSERT_EQ(2 * OPENSSL_ARRAY_SIZE(kExpected), sk_X509_INFO_num(infos.get())); |
| 1812 | for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kExpected); i++) { |
| 1813 | SCOPED_TRACE(i); |
| 1814 | check_info(&kExpected[i], sk_X509_INFO_value(infos.get(), i)); |
| 1815 | check_info( |
| 1816 | &kExpected[i], |
| 1817 | sk_X509_INFO_value(infos.get(), i + OPENSSL_ARRAY_SIZE(kExpected))); |
| 1818 | } |
| 1819 | |
| 1820 | // Gracefully handle errors in both the append and fresh cases. |
| 1821 | std::string bad_pem = cert + cert + invalid; |
| 1822 | |
| 1823 | bio.reset(BIO_new_mem_buf(bad_pem.data(), bad_pem.size())); |
| 1824 | ASSERT_TRUE(bio); |
| 1825 | bssl::UniquePtr<STACK_OF(X509_INFO)> infos2( |
| 1826 | PEM_X509_INFO_read_bio(bio.get(), nullptr, nullptr, nullptr)); |
| 1827 | EXPECT_FALSE(infos2); |
| 1828 | |
| 1829 | bio.reset(BIO_new_mem_buf(bad_pem.data(), bad_pem.size())); |
| 1830 | ASSERT_TRUE(bio); |
| 1831 | EXPECT_FALSE( |
| 1832 | PEM_X509_INFO_read_bio(bio.get(), infos.get(), nullptr, nullptr)); |
| 1833 | EXPECT_EQ(2 * OPENSSL_ARRAY_SIZE(kExpected), sk_X509_INFO_num(infos.get())); |
| 1834 | } |
Robert Sloan | 23894f8 | 2018-10-15 10:03:22 -0700 | [diff] [blame] | 1835 | |
| 1836 | TEST(X509Test, ReadBIOEmpty) { |
| 1837 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(nullptr, 0)); |
| 1838 | ASSERT_TRUE(bio); |
| 1839 | |
| 1840 | // CPython expects |ASN1_R_HEADER_TOO_LONG| on EOF, to terminate a series of |
| 1841 | // certificates. |
| 1842 | bssl::UniquePtr<X509> x509(d2i_X509_bio(bio.get(), nullptr)); |
| 1843 | EXPECT_FALSE(x509); |
| 1844 | uint32_t err = ERR_get_error(); |
| 1845 | EXPECT_EQ(ERR_LIB_ASN1, ERR_GET_LIB(err)); |
| 1846 | EXPECT_EQ(ASN1_R_HEADER_TOO_LONG, ERR_GET_REASON(err)); |
| 1847 | } |
Robert Sloan | 11c28bd | 2018-12-17 12:09:20 -0800 | [diff] [blame] | 1848 | |
| 1849 | TEST(X509Test, ReadBIOOneByte) { |
| 1850 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf("\x30", 1)); |
| 1851 | ASSERT_TRUE(bio); |
| 1852 | |
| 1853 | // CPython expects |ASN1_R_HEADER_TOO_LONG| on EOF, to terminate a series of |
| 1854 | // certificates. This EOF appeared after some data, however, so we do not wish |
| 1855 | // to signal EOF. |
| 1856 | bssl::UniquePtr<X509> x509(d2i_X509_bio(bio.get(), nullptr)); |
| 1857 | EXPECT_FALSE(x509); |
| 1858 | uint32_t err = ERR_get_error(); |
| 1859 | EXPECT_EQ(ERR_LIB_ASN1, ERR_GET_LIB(err)); |
| 1860 | EXPECT_EQ(ASN1_R_NOT_ENOUGH_DATA, ERR_GET_REASON(err)); |
| 1861 | } |
| 1862 | |
| 1863 | TEST(X509Test, PartialBIOReturn) { |
| 1864 | // Create a filter BIO that only reads and writes one byte at a time. |
| 1865 | bssl::UniquePtr<BIO_METHOD> method(BIO_meth_new(0, nullptr)); |
| 1866 | ASSERT_TRUE(method); |
| 1867 | ASSERT_TRUE(BIO_meth_set_create(method.get(), [](BIO *b) -> int { |
| 1868 | BIO_set_init(b, 1); |
| 1869 | return 1; |
| 1870 | })); |
| 1871 | ASSERT_TRUE( |
| 1872 | BIO_meth_set_read(method.get(), [](BIO *b, char *out, int len) -> int { |
| 1873 | return BIO_read(BIO_next(b), out, std::min(len, 1)); |
| 1874 | })); |
| 1875 | ASSERT_TRUE(BIO_meth_set_write( |
| 1876 | method.get(), [](BIO *b, const char *in, int len) -> int { |
| 1877 | return BIO_write(BIO_next(b), in, std::min(len, 1)); |
| 1878 | })); |
| 1879 | |
| 1880 | bssl::UniquePtr<BIO> bio(BIO_new(method.get())); |
| 1881 | ASSERT_TRUE(bio); |
| 1882 | BIO *mem_bio = BIO_new(BIO_s_mem()); |
| 1883 | ASSERT_TRUE(mem_bio); |
| 1884 | BIO_push(bio.get(), mem_bio); // BIO_push takes ownership. |
| 1885 | |
| 1886 | bssl::UniquePtr<X509> cert(CertFromPEM(kLeafPEM)); |
| 1887 | ASSERT_TRUE(cert); |
| 1888 | uint8_t *der = nullptr; |
| 1889 | int der_len = i2d_X509(cert.get(), &der); |
| 1890 | ASSERT_GT(der_len, 0); |
| 1891 | bssl::UniquePtr<uint8_t> free_der(der); |
| 1892 | |
| 1893 | // Write the certificate into the BIO. Though we only write one byte at a |
| 1894 | // time, the write should succeed. |
| 1895 | ASSERT_EQ(1, i2d_X509_bio(bio.get(), cert.get())); |
| 1896 | const uint8_t *der2; |
| 1897 | size_t der2_len; |
| 1898 | ASSERT_TRUE(BIO_mem_contents(mem_bio, &der2, &der2_len)); |
| 1899 | EXPECT_EQ(Bytes(der, static_cast<size_t>(der_len)), Bytes(der2, der2_len)); |
| 1900 | |
| 1901 | // Read the certificate back out of the BIO. Though we only read one byte at a |
| 1902 | // time, the read should succeed. |
| 1903 | bssl::UniquePtr<X509> cert2(d2i_X509_bio(bio.get(), nullptr)); |
| 1904 | ASSERT_TRUE(cert2); |
| 1905 | EXPECT_EQ(0, X509_cmp(cert.get(), cert2.get())); |
| 1906 | } |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 1907 | |
| 1908 | TEST(X509Test, CommonNameFallback) { |
| 1909 | bssl::UniquePtr<X509> root = CertFromPEM(kSANTypesRoot); |
| 1910 | ASSERT_TRUE(root); |
| 1911 | bssl::UniquePtr<X509> with_sans = CertFromPEM(kCommonNameWithSANs); |
| 1912 | ASSERT_TRUE(with_sans); |
| 1913 | bssl::UniquePtr<X509> without_sans = CertFromPEM(kCommonNameWithoutSANs); |
| 1914 | ASSERT_TRUE(without_sans); |
| 1915 | bssl::UniquePtr<X509> with_email = CertFromPEM(kCommonNameWithEmailSAN); |
| 1916 | ASSERT_TRUE(with_email); |
| 1917 | bssl::UniquePtr<X509> with_ip = CertFromPEM(kCommonNameWithIPSAN); |
| 1918 | ASSERT_TRUE(with_ip); |
| 1919 | |
| 1920 | auto verify_cert = [&](X509 *leaf, unsigned flags, const char *host) { |
| 1921 | return Verify( |
| 1922 | leaf, {root.get()}, {}, {}, 0, false, [&](X509_VERIFY_PARAM *param) { |
| 1923 | ASSERT_TRUE(X509_VERIFY_PARAM_set1_host(param, host, strlen(host))); |
| 1924 | X509_VERIFY_PARAM_set_hostflags(param, flags); |
| 1925 | }); |
| 1926 | }; |
| 1927 | |
| 1928 | // By default, the common name is ignored if the SAN list is present but |
| 1929 | // otherwise is checked. |
| 1930 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 1931 | verify_cert(with_sans.get(), 0 /* no flags */, "foo.host1.test")); |
| 1932 | EXPECT_EQ(X509_V_OK, |
| 1933 | verify_cert(with_sans.get(), 0 /* no flags */, "foo.host2.test")); |
| 1934 | EXPECT_EQ(X509_V_OK, |
| 1935 | verify_cert(with_sans.get(), 0 /* no flags */, "foo.host3.test")); |
| 1936 | EXPECT_EQ(X509_V_OK, verify_cert(without_sans.get(), 0 /* no flags */, |
| 1937 | "foo.host1.test")); |
| 1938 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 1939 | verify_cert(with_email.get(), 0 /* no flags */, "foo.host1.test")); |
| 1940 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 1941 | verify_cert(with_ip.get(), 0 /* no flags */, "foo.host1.test")); |
| 1942 | |
| 1943 | // X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT is ignored. |
| 1944 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 1945 | verify_cert(with_sans.get(), X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT, |
| 1946 | "foo.host1.test")); |
| 1947 | EXPECT_EQ(X509_V_OK, |
| 1948 | verify_cert(with_sans.get(), X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT, |
| 1949 | "foo.host2.test")); |
| 1950 | EXPECT_EQ(X509_V_OK, |
| 1951 | verify_cert(with_sans.get(), X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT, |
| 1952 | "foo.host3.test")); |
| 1953 | EXPECT_EQ(X509_V_OK, verify_cert(without_sans.get(), |
| 1954 | X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT, |
| 1955 | "foo.host1.test")); |
| 1956 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 1957 | verify_cert(with_email.get(), X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT, |
| 1958 | "foo.host1.test")); |
| 1959 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 1960 | verify_cert(with_ip.get(), X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT, |
| 1961 | "foo.host1.test")); |
| 1962 | |
| 1963 | // X509_CHECK_FLAG_NEVER_CHECK_SUBJECT implements the correct behavior: the |
| 1964 | // common name is never checked. |
| 1965 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 1966 | verify_cert(with_sans.get(), X509_CHECK_FLAG_NEVER_CHECK_SUBJECT, |
| 1967 | "foo.host1.test")); |
| 1968 | EXPECT_EQ(X509_V_OK, |
| 1969 | verify_cert(with_sans.get(), X509_CHECK_FLAG_NEVER_CHECK_SUBJECT, |
| 1970 | "foo.host2.test")); |
| 1971 | EXPECT_EQ(X509_V_OK, |
| 1972 | verify_cert(with_sans.get(), X509_CHECK_FLAG_NEVER_CHECK_SUBJECT, |
| 1973 | "foo.host3.test")); |
| 1974 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 1975 | verify_cert(without_sans.get(), X509_CHECK_FLAG_NEVER_CHECK_SUBJECT, |
| 1976 | "foo.host1.test")); |
| 1977 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 1978 | verify_cert(with_email.get(), X509_CHECK_FLAG_NEVER_CHECK_SUBJECT, |
| 1979 | "foo.host1.test")); |
| 1980 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 1981 | verify_cert(with_ip.get(), X509_CHECK_FLAG_NEVER_CHECK_SUBJECT, |
| 1982 | "foo.host1.test")); |
| 1983 | } |
| 1984 | |
| 1985 | TEST(X509Test, LooksLikeDNSName) { |
| 1986 | static const char *kValid[] = { |
| 1987 | "example.com", |
| 1988 | "eXample123-.com", |
| 1989 | "*.example.com", |
| 1990 | "exa_mple.com", |
| 1991 | "example.com.", |
| 1992 | "project-dev:us-central1:main", |
| 1993 | }; |
| 1994 | static const char *kInvalid[] = { |
| 1995 | "-eXample123-.com", |
| 1996 | "", |
| 1997 | ".", |
| 1998 | "*", |
| 1999 | "*.", |
| 2000 | "example..com", |
| 2001 | ".example.com", |
| 2002 | "example.com..", |
| 2003 | "*foo.example.com", |
| 2004 | "foo.*.example.com", |
| 2005 | "foo,bar", |
| 2006 | }; |
| 2007 | |
| 2008 | for (const char *str : kValid) { |
| 2009 | SCOPED_TRACE(str); |
| 2010 | EXPECT_TRUE(x509v3_looks_like_dns_name( |
| 2011 | reinterpret_cast<const uint8_t *>(str), strlen(str))); |
| 2012 | } |
| 2013 | for (const char *str : kInvalid) { |
| 2014 | SCOPED_TRACE(str); |
| 2015 | EXPECT_FALSE(x509v3_looks_like_dns_name( |
| 2016 | reinterpret_cast<const uint8_t *>(str), strlen(str))); |
| 2017 | } |
| 2018 | } |
| 2019 | |
| 2020 | TEST(X509Test, CommonNameAndNameConstraints) { |
| 2021 | bssl::UniquePtr<X509> root = CertFromPEM(kSANTypesRoot); |
| 2022 | ASSERT_TRUE(root); |
| 2023 | bssl::UniquePtr<X509> intermediate = CertFromPEM(kConstrainedIntermediate); |
| 2024 | ASSERT_TRUE(intermediate); |
| 2025 | bssl::UniquePtr<X509> permitted = CertFromPEM(kCommonNamePermittedLeaf); |
| 2026 | ASSERT_TRUE(permitted); |
| 2027 | bssl::UniquePtr<X509> not_permitted = |
| 2028 | CertFromPEM(kCommonNameNotPermittedLeaf); |
| 2029 | ASSERT_TRUE(not_permitted); |
| 2030 | bssl::UniquePtr<X509> not_permitted_with_sans = |
| 2031 | CertFromPEM(kCommonNameNotPermittedWithSANsLeaf); |
| 2032 | ASSERT_TRUE(not_permitted_with_sans); |
| 2033 | bssl::UniquePtr<X509> not_dns = CertFromPEM(kCommonNameNotDNSLeaf); |
| 2034 | ASSERT_TRUE(not_dns); |
| 2035 | |
| 2036 | auto verify_cert = [&](X509 *leaf, unsigned flags, const char *host) { |
| 2037 | return Verify( |
| 2038 | leaf, {root.get()}, {intermediate.get()}, {}, 0, false, |
| 2039 | [&](X509_VERIFY_PARAM *param) { |
| 2040 | ASSERT_TRUE(X509_VERIFY_PARAM_set1_host(param, host, strlen(host))); |
| 2041 | X509_VERIFY_PARAM_set_hostflags(param, flags); |
| 2042 | }); |
| 2043 | }; |
| 2044 | |
| 2045 | // Certificates which would otherwise trigger the common name fallback are |
| 2046 | // rejected whenever there are name constraints. We do this whether or not |
| 2047 | // the common name matches the constraints. |
| 2048 | EXPECT_EQ( |
| 2049 | X509_V_ERR_NAME_CONSTRAINTS_WITHOUT_SANS, |
| 2050 | verify_cert(permitted.get(), 0 /* no flags */, kCommonNamePermitted)); |
| 2051 | EXPECT_EQ(X509_V_ERR_NAME_CONSTRAINTS_WITHOUT_SANS, |
| 2052 | verify_cert(not_permitted.get(), 0 /* no flags */, |
| 2053 | kCommonNameNotPermitted)); |
| 2054 | |
| 2055 | // This occurs even if the built-in name checks aren't used. The caller may |
| 2056 | // separately call |X509_check_host|. |
| 2057 | EXPECT_EQ(X509_V_ERR_NAME_CONSTRAINTS_WITHOUT_SANS, |
| 2058 | Verify(not_permitted.get(), {root.get()}, {intermediate.get()}, {}, |
| 2059 | 0 /* no flags */, false, nullptr)); |
| 2060 | |
| 2061 | // If the leaf certificate has SANs, the common name fallback is always |
| 2062 | // disabled, so the name constraints do not apply. |
| 2063 | EXPECT_EQ(X509_V_OK, Verify(not_permitted_with_sans.get(), {root.get()}, |
| 2064 | {intermediate.get()}, {}, 0, false, nullptr)); |
| 2065 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 2066 | verify_cert(not_permitted_with_sans.get(), 0 /* no flags */, |
| 2067 | kCommonNameNotPermittedWithSANs)); |
| 2068 | |
| 2069 | // If the common name does not look like a DNS name, we apply neither name |
| 2070 | // constraints nor common name fallback. |
| 2071 | EXPECT_EQ(X509_V_OK, Verify(not_dns.get(), {root.get()}, {intermediate.get()}, |
| 2072 | {}, 0, false, nullptr)); |
| 2073 | EXPECT_EQ(X509_V_ERR_HOSTNAME_MISMATCH, |
| 2074 | verify_cert(not_dns.get(), 0 /* no flags */, kCommonNameNotDNS)); |
| 2075 | } |