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 | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 15 | #include <functional> |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 16 | #include <string> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 19 | #include <gtest/gtest.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 20 | |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 21 | #include <openssl/bio.h> |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 22 | #include <openssl/bytestring.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 23 | #include <openssl/crypto.h> |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 24 | #include <openssl/curve25519.h> |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 25 | #include <openssl/digest.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 26 | #include <openssl/err.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 27 | #include <openssl/pem.h> |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 28 | #include <openssl/pool.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 29 | #include <openssl/x509.h> |
Robert Sloan | a815d5a | 2017-12-04 11:49:16 -0800 | [diff] [blame] | 30 | #include <openssl/x509v3.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 31 | |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 32 | #include "../internal.h" |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 33 | #include "../test/test_util.h" |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 34 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 35 | |
Robert Sloan | 2e9e66a | 2017-09-25 09:08:29 -0700 | [diff] [blame] | 36 | std::string GetTestData(const char *path); |
| 37 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 38 | static const char kCrossSigningRootPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 39 | "-----BEGIN CERTIFICATE-----\n" |
| 40 | "MIICcTCCAdqgAwIBAgIIagJHiPvE0MowDQYJKoZIhvcNAQELBQAwPDEaMBgGA1UE\n" |
| 41 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxHjAcBgNVBAMTFUNyb3NzLXNpZ25pbmcgUm9v\n" |
| 42 | "dCBDQTAgFw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAwMFowPDEaMBgGA1UE\n" |
| 43 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxHjAcBgNVBAMTFUNyb3NzLXNpZ25pbmcgUm9v\n" |
| 44 | "dCBDQTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwo3qFvSB9Zmlbpzn9wJp\n" |
| 45 | "ikI75Rxkatez8VkLqyxbOhPYl2Haz8F5p1gDG96dCI6jcLGgu3AKT9uhEQyyUko5\n" |
| 46 | "EKYasazSeA9CQrdyhPg0mkTYVETnPM1W/ebid1YtqQbq1CMWlq2aTDoSGAReGFKP\n" |
| 47 | "RTdXAbuAXzpCfi/d8LqV13UCAwEAAaN6MHgwDgYDVR0PAQH/BAQDAgIEMB0GA1Ud\n" |
| 48 | "JQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAPBgNVHRMBAf8EBTADAQH/MBkGA1Ud\n" |
| 49 | "DgQSBBBHKHC7V3Z/3oLvEZx0RZRwMBsGA1UdIwQUMBKAEEcocLtXdn/egu8RnHRF\n" |
| 50 | "lHAwDQYJKoZIhvcNAQELBQADgYEAnglibsy6mGtpIXivtlcz4zIEnHw/lNW+r/eC\n" |
| 51 | "CY7evZTmOoOuC/x9SS3MF9vawt1HFUummWM6ZgErqVBOXIB4//ykrcCgf5ZbF5Hr\n" |
| 52 | "+3EFprKhBqYiXdD8hpBkrBoXwn85LPYWNd2TceCrx0YtLIprE2R5MB2RIq8y4Jk3\n" |
| 53 | "YFXvkME=\n" |
| 54 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 55 | |
| 56 | static const char kRootCAPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 57 | "-----BEGIN CERTIFICATE-----\n" |
| 58 | "MIICVTCCAb6gAwIBAgIIAj5CwoHlWuYwDQYJKoZIhvcNAQELBQAwLjEaMBgGA1UE\n" |
| 59 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxEDAOBgNVBAMTB1Jvb3QgQ0EwIBcNMTUwMTAx\n" |
| 60 | "MDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMC4xGjAYBgNVBAoTEUJvcmluZ1NTTCBU\n" |
| 61 | "RVNUSU5HMRAwDgYDVQQDEwdSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n" |
| 62 | "iQKBgQDpDn8RDOZa5oaDcPZRBy4CeBH1siSSOO4mYgLHlPE+oXdqwI/VImi2XeJM\n" |
| 63 | "2uCFETXCknJJjYG0iJdrt/yyRFvZTQZw+QzGj+mz36NqhGxDWb6dstB2m8PX+plZ\n" |
| 64 | "w7jl81MDvUnWs8yiQ/6twgu5AbhWKZQDJKcNKCEpqa6UW0r5nwIDAQABo3oweDAO\n" |
| 65 | "BgNVHQ8BAf8EBAMCAgQwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMA8G\n" |
| 66 | "A1UdEwEB/wQFMAMBAf8wGQYDVR0OBBIEEEA31wH7QC+4HH5UBCeMWQEwGwYDVR0j\n" |
| 67 | "BBQwEoAQQDfXAftAL7gcflQEJ4xZATANBgkqhkiG9w0BAQsFAAOBgQDXylEK77Za\n" |
| 68 | "kKeY6ZerrScWyZhrjIGtHFu09qVpdJEzrk87k2G7iHHR9CAvSofCgEExKtWNS9dN\n" |
| 69 | "+9WiZp/U48iHLk7qaYXdEuO07No4BYtXn+lkOykE+FUxmA4wvOF1cTd2tdj3MzX2\n" |
| 70 | "kfGIBAYhzGZWhY3JbhIfTEfY1PNM1pWChQ==\n" |
| 71 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 72 | |
| 73 | static const char kRootCrossSignedPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 74 | "-----BEGIN CERTIFICATE-----\n" |
| 75 | "MIICYzCCAcygAwIBAgIIAj5CwoHlWuYwDQYJKoZIhvcNAQELBQAwPDEaMBgGA1UE\n" |
| 76 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxHjAcBgNVBAMTFUNyb3NzLXNpZ25pbmcgUm9v\n" |
| 77 | "dCBDQTAgFw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAwMFowLjEaMBgGA1UE\n" |
| 78 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxEDAOBgNVBAMTB1Jvb3QgQ0EwgZ8wDQYJKoZI\n" |
| 79 | "hvcNAQEBBQADgY0AMIGJAoGBAOkOfxEM5lrmhoNw9lEHLgJ4EfWyJJI47iZiAseU\n" |
| 80 | "8T6hd2rAj9UiaLZd4kza4IURNcKSckmNgbSIl2u3/LJEW9lNBnD5DMaP6bPfo2qE\n" |
| 81 | "bENZvp2y0Habw9f6mVnDuOXzUwO9SdazzKJD/q3CC7kBuFYplAMkpw0oISmprpRb\n" |
| 82 | "SvmfAgMBAAGjejB4MA4GA1UdDwEB/wQEAwICBDAdBgNVHSUEFjAUBggrBgEFBQcD\n" |
| 83 | "AQYIKwYBBQUHAwIwDwYDVR0TAQH/BAUwAwEB/zAZBgNVHQ4EEgQQQDfXAftAL7gc\n" |
| 84 | "flQEJ4xZATAbBgNVHSMEFDASgBBHKHC7V3Z/3oLvEZx0RZRwMA0GCSqGSIb3DQEB\n" |
| 85 | "CwUAA4GBAErTxYJ0en9HVRHAAr5OO5wuk5Iq3VMc79TMyQLCXVL8YH8Uk7KEwv+q\n" |
| 86 | "9MEKZv2eR/Vfm4HlXlUuIqfgUXbwrAYC/YVVX86Wnbpy/jc73NYVCq8FEZeO+0XU\n" |
| 87 | "90SWAPDdp+iL7aZdimnMtG1qlM1edmz8AKbrhN/R3IbA2CL0nCWV\n" |
| 88 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 89 | |
| 90 | static const char kIntermediatePEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 91 | "-----BEGIN CERTIFICATE-----\n" |
| 92 | "MIICXjCCAcegAwIBAgIJAKJMH+7rscPcMA0GCSqGSIb3DQEBCwUAMC4xGjAYBgNV\n" |
| 93 | "BAoTEUJvcmluZ1NTTCBURVNUSU5HMRAwDgYDVQQDEwdSb290IENBMCAXDTE1MDEw\n" |
| 94 | "MTAwMDAwMFoYDzIxMDAwMTAxMDAwMDAwWjA2MRowGAYDVQQKExFCb3JpbmdTU0wg\n" |
| 95 | "VEVTVElORzEYMBYGA1UEAxMPSW50ZXJtZWRpYXRlIENBMIGfMA0GCSqGSIb3DQEB\n" |
| 96 | "AQUAA4GNADCBiQKBgQC7YtI0l8ocTYJ0gKyXTtPL4iMJCNY4OcxXl48jkncVG1Hl\n" |
| 97 | "blicgNUa1r9m9YFtVkxvBinb8dXiUpEGhVg4awRPDcatlsBSEBuJkiZGYbRcAmSu\n" |
| 98 | "CmZYnf6u3aYQ18SU8WqVERPpE4cwVVs+6kwlzRw0+XDoZAczu8ZezVhCUc6NbQID\n" |
| 99 | "AQABo3oweDAOBgNVHQ8BAf8EBAMCAgQwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsG\n" |
| 100 | "AQUFBwMCMA8GA1UdEwEB/wQFMAMBAf8wGQYDVR0OBBIEEIwaaKi1dttdV3sfjRSy\n" |
| 101 | "BqMwGwYDVR0jBBQwEoAQQDfXAftAL7gcflQEJ4xZATANBgkqhkiG9w0BAQsFAAOB\n" |
| 102 | "gQCvnolNWEHuQS8PFVVyuLR+FKBeUUdrVbSfHSzTqNAqQGp0C9fk5oCzDq6ZgTfY\n" |
| 103 | "ESXM4cJhb3IAnW0UM0NFsYSKQJ50JZL2L3z5ZLQhHdbs4RmODGoC40BVdnJ4/qgB\n" |
| 104 | "aGSh09eQRvAVmbVCviDK2ipkWNegdyI19jFfNP5uIkGlYg==\n" |
| 105 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 106 | |
| 107 | static const char kIntermediateSelfSignedPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 108 | "-----BEGIN CERTIFICATE-----\n" |
| 109 | "MIICZjCCAc+gAwIBAgIJAKJMH+7rscPcMA0GCSqGSIb3DQEBCwUAMDYxGjAYBgNV\n" |
| 110 | "BAoTEUJvcmluZ1NTTCBURVNUSU5HMRgwFgYDVQQDEw9JbnRlcm1lZGlhdGUgQ0Ew\n" |
| 111 | "IBcNMTUwMTAxMDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMDYxGjAYBgNVBAoTEUJv\n" |
| 112 | "cmluZ1NTTCBURVNUSU5HMRgwFgYDVQQDEw9JbnRlcm1lZGlhdGUgQ0EwgZ8wDQYJ\n" |
| 113 | "KoZIhvcNAQEBBQADgY0AMIGJAoGBALti0jSXyhxNgnSArJdO08viIwkI1jg5zFeX\n" |
| 114 | "jyOSdxUbUeVuWJyA1RrWv2b1gW1WTG8GKdvx1eJSkQaFWDhrBE8Nxq2WwFIQG4mS\n" |
| 115 | "JkZhtFwCZK4KZlid/q7dphDXxJTxapURE+kThzBVWz7qTCXNHDT5cOhkBzO7xl7N\n" |
| 116 | "WEJRzo1tAgMBAAGjejB4MA4GA1UdDwEB/wQEAwICBDAdBgNVHSUEFjAUBggrBgEF\n" |
| 117 | "BQcDAQYIKwYBBQUHAwIwDwYDVR0TAQH/BAUwAwEB/zAZBgNVHQ4EEgQQjBpoqLV2\n" |
| 118 | "211Xex+NFLIGozAbBgNVHSMEFDASgBCMGmiotXbbXVd7H40UsgajMA0GCSqGSIb3\n" |
| 119 | "DQEBCwUAA4GBALcccSrAQ0/EqQBsx0ZDTUydHXXNP2DrUkpUKmAXIe8McqIVSlkT\n" |
| 120 | "6H4xz7z8VRKBo9j+drjjtCw2i0CQc8aOLxRb5WJ8eVLnaW2XRlUqAzhF0CrulfVI\n" |
| 121 | "E4Vs6ZLU+fra1WAuIj6qFiigRja+3YkZArG8tMA9vtlhTX/g7YBZIkqH\n" |
| 122 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 123 | |
| 124 | static const char kLeafPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 125 | "-----BEGIN CERTIFICATE-----\n" |
| 126 | "MIICXjCCAcegAwIBAgIIWjO48ufpunYwDQYJKoZIhvcNAQELBQAwNjEaMBgGA1UE\n" |
| 127 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxGDAWBgNVBAMTD0ludGVybWVkaWF0ZSBDQTAg\n" |
| 128 | "Fw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAwMFowMjEaMBgGA1UEChMRQm9y\n" |
| 129 | "aW5nU1NMIFRFU1RJTkcxFDASBgNVBAMTC2V4YW1wbGUuY29tMIGfMA0GCSqGSIb3\n" |
| 130 | "DQEBAQUAA4GNADCBiQKBgQDD0U0ZYgqShJ7oOjsyNKyVXEHqeafmk/bAoPqY/h1c\n" |
| 131 | "oPw2E8KmeqiUSoTPjG5IXSblOxcqpbAXgnjPzo8DI3GNMhAf8SYNYsoH7gc7Uy7j\n" |
| 132 | "5x8bUrisGnuTHqkqH6d4/e7ETJ7i3CpR8bvK16DggEvQTudLipz8FBHtYhFakfdh\n" |
| 133 | "TwIDAQABo3cwdTAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEG\n" |
| 134 | "CCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwGQYDVR0OBBIEEKN5pvbur7mlXjeMEYA0\n" |
| 135 | "4nUwGwYDVR0jBBQwEoAQjBpoqLV2211Xex+NFLIGozANBgkqhkiG9w0BAQsFAAOB\n" |
| 136 | "gQBj/p+JChp//LnXWC1k121LM/ii7hFzQzMrt70bny406SGz9jAjaPOX4S3gt38y\n" |
| 137 | "rhjpPukBlSzgQXFg66y6q5qp1nQTD1Cw6NkKBe9WuBlY3iYfmsf7WT8nhlT1CttU\n" |
| 138 | "xNCwyMX9mtdXdQicOfNjIGUCD5OLV5PgHFPRKiHHioBAhg==\n" |
| 139 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 140 | |
| 141 | static const char kLeafNoKeyUsagePEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 142 | "-----BEGIN CERTIFICATE-----\n" |
| 143 | "MIICNTCCAZ6gAwIBAgIJAIFQGaLQ0G2mMA0GCSqGSIb3DQEBCwUAMDYxGjAYBgNV\n" |
| 144 | "BAoTEUJvcmluZ1NTTCBURVNUSU5HMRgwFgYDVQQDEw9JbnRlcm1lZGlhdGUgQ0Ew\n" |
| 145 | "IBcNMTUwMTAxMDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMDcxGjAYBgNVBAoTEUJv\n" |
| 146 | "cmluZ1NTTCBURVNUSU5HMRkwFwYDVQQDExBldmlsLmV4YW1wbGUuY29tMIGfMA0G\n" |
| 147 | "CSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOKoZe75NPz77EOaMMl4/0s3PyQw++zJvp\n" |
| 148 | "ejHAxZiTPCJgMbEHLrSzNoHdopg+CLUH5bE4wTXM8w9Inv5P8OAFJt7gJuPUunmk\n" |
| 149 | "j+NoU3QfzOR6BroePcz1vXX9jyVHRs087M/sLqWRHu9IR+/A+UTcBaWaFiDVUxtJ\n" |
| 150 | "YOwFMwjNPQIDAQABo0gwRjAMBgNVHRMBAf8EAjAAMBkGA1UdDgQSBBBJfLEUWHq1\n" |
| 151 | "27rZ1AVx2J5GMBsGA1UdIwQUMBKAEIwaaKi1dttdV3sfjRSyBqMwDQYJKoZIhvcN\n" |
| 152 | "AQELBQADgYEALVKN2Y3LZJOtu6SxFIYKxbLaXhTGTdIjxipZhmbBRDFjbZjZZOTe\n" |
| 153 | "6Oo+VDNPYco4rBexK7umYXJyfTqoY0E8dbiImhTcGTEj7OAB3DbBomgU1AYe+t2D\n" |
| 154 | "uwBqh4Y3Eto+Zn4pMVsxGEfUpjzjZDel7bN1/oU/9KWPpDfywfUmjgk=\n" |
| 155 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 156 | |
| 157 | static const char kForgeryPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 158 | "-----BEGIN CERTIFICATE-----\n" |
| 159 | "MIICZzCCAdCgAwIBAgIIdTlMzQoKkeMwDQYJKoZIhvcNAQELBQAwNzEaMBgGA1UE\n" |
| 160 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxGTAXBgNVBAMTEGV2aWwuZXhhbXBsZS5jb20w\n" |
| 161 | "IBcNMTUwMTAxMDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMDoxGjAYBgNVBAoTEUJv\n" |
| 162 | "cmluZ1NTTCBURVNUSU5HMRwwGgYDVQQDExNmb3JnZXJ5LmV4YW1wbGUuY29tMIGf\n" |
| 163 | "MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDADTwruBQZGb7Ay6s9HiYv5d1lwtEy\n" |
| 164 | "xQdA2Sy8Rn8uA20Q4KgqwVY7wzIZ+z5Butrsmwb70gdG1XU+yRaDeE7XVoW6jSpm\n" |
| 165 | "0sw35/5vJbTcL4THEFbnX0OPZnvpuZDFUkvVtq5kxpDWsVyM24G8EEq7kPih3Sa3\n" |
| 166 | "OMhXVXF8kso6UQIDAQABo3cwdTAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYI\n" |
| 167 | "KwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwGQYDVR0OBBIEEEYJ/WHM\n" |
| 168 | "8p64erPWIg4/liwwGwYDVR0jBBQwEoAQSXyxFFh6tdu62dQFcdieRjANBgkqhkiG\n" |
| 169 | "9w0BAQsFAAOBgQA+zH7bHPElWRWJvjxDqRexmYLn+D3Aivs8XgXQJsM94W0EzSUf\n" |
| 170 | "DSLfRgaQwcb2gg2xpDFoG+W0vc6O651uF23WGt5JaFFJJxqjII05IexfCNhuPmp4\n" |
| 171 | "4UZAXPttuJXpn74IY1tuouaM06B3vXKZR+/ityKmfJvSwxacmFcK+2ziAg==\n" |
| 172 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 173 | |
| 174 | // kExamplePSSCert is an example RSA-PSS self-signed certificate, signed with |
| 175 | // the default hash functions. |
| 176 | static const char kExamplePSSCert[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 177 | "-----BEGIN CERTIFICATE-----\n" |
| 178 | "MIICYjCCAcagAwIBAgIJAI3qUyT6SIfzMBIGCSqGSIb3DQEBCjAFogMCAWowRTEL\n" |
| 179 | "MAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVy\n" |
| 180 | "bmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0xNDEwMDkxOTA5NTVaFw0xNTEwMDkxOTA5\n" |
| 181 | "NTVaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQK\n" |
| 182 | "DBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwgZ8wDQYJKoZIhvcNAQEBBQADgY0A\n" |
| 183 | "MIGJAoGBAPi4bIO0vNmoV8CltFl2jFQdeesiUgR+0zfrQf2D+fCmhRU0dXFahKg8\n" |
| 184 | "0u9aTtPel4rd/7vPCqqGkr64UOTNb4AzMHYTj8p73OxaymPHAyXvqIqDWHYg+hZ3\n" |
| 185 | "13mSYwFIGth7Z/FSVUlO1m5KXNd6NzYM3t2PROjCpywrta9kS2EHAgMBAAGjUDBO\n" |
| 186 | "MB0GA1UdDgQWBBTQQfuJQR6nrVrsNF1JEflVgXgfEzAfBgNVHSMEGDAWgBTQQfuJ\n" |
| 187 | "QR6nrVrsNF1JEflVgXgfEzAMBgNVHRMEBTADAQH/MBIGCSqGSIb3DQEBCjAFogMC\n" |
| 188 | "AWoDgYEASUy2RZcgNbNQZA0/7F+V1YTLEXwD16bm+iSVnzGwtexmQVEYIZG74K/w\n" |
| 189 | "xbdZQdTbpNJkp1QPjPfh0zsatw6dmt5QoZ8K8No0DjR9dgf+Wvv5WJvJUIQBoAVN\n" |
| 190 | "Z0IL+OQFz6+LcTHxD27JJCebrATXZA0wThGTQDm7crL+a+SujBY=\n" |
| 191 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 192 | |
| 193 | // kBadPSSCertPEM is a self-signed RSA-PSS certificate with bad parameters. |
| 194 | static const char kBadPSSCertPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 195 | "-----BEGIN CERTIFICATE-----\n" |
| 196 | "MIIDdjCCAjqgAwIBAgIJANcwZLyfEv7DMD4GCSqGSIb3DQEBCjAxoA0wCwYJYIZI\n" |
| 197 | "AWUDBAIBoRowGAYJKoZIhvcNAQEIMAsGCWCGSAFlAwQCAaIEAgIA3jAnMSUwIwYD\n" |
| 198 | "VQQDDBxUZXN0IEludmFsaWQgUFNTIGNlcnRpZmljYXRlMB4XDTE1MTEwNDE2MDIz\n" |
| 199 | "NVoXDTE1MTIwNDE2MDIzNVowJzElMCMGA1UEAwwcVGVzdCBJbnZhbGlkIFBTUyBj\n" |
| 200 | "ZXJ0aWZpY2F0ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMTaM7WH\n" |
| 201 | "qVCAGAIA+zL1KWvvASTrhlq+1ePdO7wsrWX2KiYoTYrJYTnxhLnn0wrHqApt79nL\n" |
| 202 | "IBG7cfShyZqFHOY/IzlYPMVt+gPo293gw96Fds5JBsjhjkyGnOyr9OUntFqvxDbT\n" |
| 203 | "IIFU7o9IdxD4edaqjRv+fegVE+B79pDk4s0ujsk6dULtCg9Rst0ucGFo19mr+b7k\n" |
| 204 | "dbfn8pZ72ZNDJPueVdrUAWw9oll61UcYfk75XdrLk6JlL41GrYHc8KlfXf43gGQq\n" |
| 205 | "QfrpHkg4Ih2cI6Wt2nhFGAzrlcorzLliQIUJRIhM8h4IgDfpBpaPdVQLqS2pFbXa\n" |
| 206 | "5eQjqiyJwak2vJ8CAwEAAaNQME4wHQYDVR0OBBYEFCt180N4oGUt5LbzBwQ4Ia+2\n" |
| 207 | "4V97MB8GA1UdIwQYMBaAFCt180N4oGUt5LbzBwQ4Ia+24V97MAwGA1UdEwQFMAMB\n" |
| 208 | "Af8wMQYJKoZIhvcNAQEKMCSgDTALBglghkgBZQMEAgGhDTALBgkqhkiG9w0BAQii\n" |
| 209 | "BAICAN4DggEBAAjBtm90lGxgddjc4Xu/nbXXFHVs2zVcHv/mqOZoQkGB9r/BVgLb\n" |
| 210 | "xhHrFZ2pHGElbUYPfifdS9ztB73e1d4J+P29o0yBqfd4/wGAc/JA8qgn6AAEO/Xn\n" |
| 211 | "plhFeTRJQtLZVl75CkHXgUGUd3h+ADvKtcBuW9dSUncaUrgNKR8u/h/2sMG38RWY\n" |
| 212 | "DzBddC/66YTa3r7KkVUfW7yqRQfELiGKdcm+bjlTEMsvS+EhHup9CzbpoCx2Fx9p\n" |
| 213 | "NPtFY3yEObQhmL1JyoCRWqBE75GzFPbRaiux5UpEkns+i3trkGssZzsOuVqHNTNZ\n" |
| 214 | "lC9+9hPHIoc9UMmAQNo1vGIW3NWVoeGbaJ8=\n" |
| 215 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 216 | |
| 217 | static const char kRSAKey[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 218 | "-----BEGIN RSA PRIVATE KEY-----\n" |
| 219 | "MIICXgIBAAKBgQDYK8imMuRi/03z0K1Zi0WnvfFHvwlYeyK9Na6XJYaUoIDAtB92\n" |
| 220 | "kWdGMdAQhLciHnAjkXLI6W15OoV3gA/ElRZ1xUpxTMhjP6PyY5wqT5r6y8FxbiiF\n" |
| 221 | "KKAnHmUcrgfVW28tQ+0rkLGMryRtrukXOgXBv7gcrmU7G1jC2a7WqmeI8QIDAQAB\n" |
| 222 | "AoGBAIBy09Fd4DOq/Ijp8HeKuCMKTHqTW1xGHshLQ6jwVV2vWZIn9aIgmDsvkjCe\n" |
| 223 | "i6ssZvnbjVcwzSoByhjN8ZCf/i15HECWDFFh6gt0P5z0MnChwzZmvatV/FXCT0j+\n" |
| 224 | "WmGNB/gkehKjGXLLcjTb6dRYVJSCZhVuOLLcbWIV10gggJQBAkEA8S8sGe4ezyyZ\n" |
| 225 | "m4e9r95g6s43kPqtj5rewTsUxt+2n4eVodD+ZUlCULWVNAFLkYRTBCASlSrm9Xhj\n" |
| 226 | "QpmWAHJUkQJBAOVzQdFUaewLtdOJoPCtpYoY1zd22eae8TQEmpGOR11L6kbxLQsk\n" |
| 227 | "aMly/DOnOaa82tqAGTdqDEZgSNmCeKKknmECQAvpnY8GUOVAubGR6c+W90iBuQLj\n" |
| 228 | "LtFp/9ihd2w/PoDwrHZaoUYVcT4VSfJQog/k7kjE4MYXYWL8eEKg3WTWQNECQQDk\n" |
| 229 | "104Wi91Umd1PzF0ijd2jXOERJU1wEKe6XLkYYNHWQAe5l4J4MWj9OdxFXAxIuuR/\n" |
| 230 | "tfDwbqkta4xcux67//khAkEAvvRXLHTaa6VFzTaiiO8SaFsHV3lQyXOtMrBpB5jd\n" |
| 231 | "moZWgjHvB2W9Ckn7sDqsPB+U2tyX0joDdQEyuiMECDY8oQ==\n" |
| 232 | "-----END RSA PRIVATE KEY-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 233 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 234 | // kCRLTestRoot is a test root certificate. It has private key: |
| 235 | // |
| 236 | // -----BEGIN RSA PRIVATE KEY----- |
| 237 | // MIIEpAIBAAKCAQEAo16WiLWZuaymsD8n5SKPmxV1y6jjgr3BS/dUBpbrzd1aeFzN |
| 238 | // lI8l2jfAnzUyp+I21RQ+nh/MhqjGElkTtK9xMn1Y+S9GMRh+5R/Du0iCb1tCZIPY |
| 239 | // 07Tgrb0KMNWe0v2QKVVruuYSgxIWodBfxlKO64Z8AJ5IbnWpuRqO6rctN9qUoMlT |
| 240 | // IAB6dL4G0tDJ/PGFWOJYwOMEIX54bly2wgyYJVBKiRRt4f7n8H922qmvPNA9idmX |
| 241 | // 9G1VAtgV6x97XXi7ULORIQvn9lVQF6nTYDBJhyuPB+mLThbLP2o9orxGx7aCtnnB |
| 242 | // ZUIxUvHNOI0FaSaZH7Fi0xsZ/GkG2HZe7ImPJwIDAQABAoIBAQCJF9MTHfHGkk+/ |
| 243 | // DwCXlA0Wg0e6hBuHl10iNobYkMWIl/xXjOknhYiqOqb181py76472SVC5ERprC+r |
| 244 | // Lf0PXzqKuA117mnkwT2bYLCL9Skf8WEhoFLQNbVlloF6wYjqXcYgKYKh8HgQbZl4 |
| 245 | // aLg2YQl2NADTNABsUWj/4H2WEelsODVviqfFs725lFg9KHDI8zxAZXLzDt/M9uVL |
| 246 | // GxJiX12tr0AwaeAFZ1oPM/y+LznM3N3+Ht3jHHw3jZ/u8Z1RdAmdpu3bZ6tbwGBr |
| 247 | // 9edsH5rKkm9aBvMrY7eX5VHqaqyRNFyG152ZOJh4XiiFG7EmgTPCpaHo50Y018Re |
| 248 | // grVtk+FBAoGBANY3lY+V8ZOwMxSHes+kTnoimHO5Ob7nxrOC71i27x+4HHsYUeAr |
| 249 | // /zOOghiDIn+oNkuiX5CIOWZKx159Bp65CPpCbTb/fh+HYnSgXFgCw7XptycO7LXM |
| 250 | // 5GwR5jSfpfzBFdYxjxoUzDMFBwTEYRTm0HkUHkH+s+ajjw5wqqbcGLcfAoGBAMM8 |
| 251 | // DKW6Tb66xsf708f0jonAjKYTLZ+WOcwsBEWSFHoY8dUjvW5gqx5acHTEsc5ZTeh4 |
| 252 | // BCFLa+Mn9cuJWVJNs09k7Xb2PNl92HQ4GN2vbdkJhExbkT6oLDHg1hVD0w8KLfz1 |
| 253 | // lTAW6pS+6CdOHMEJpvqx89EgU/1GgIQ1fXYczE75AoGAKeJoXdDFkUjsU+FBhAPu |
| 254 | // TDcjc80Nm2QaF9NMFR5/lsYa236f06MGnQAKM9zADBHJu/Qdl1brUjLg1HrBppsr |
| 255 | // RDNkw1IlSOjhuUf5hkPUHGd8Jijm440SRIcjabqla8wdBupdvo2+d2NOQgJbsQiI |
| 256 | // ToQ+fkzcxAXK3Nnuo/1436UCgYBjLH7UNOZHS8OsVM0I1r8NVKVdu4JCfeJQR8/H |
| 257 | // s2P5ffBir+wLRMnH+nMDreMQiibcPxMCArkERAlE4jlgaJ38Z62E76KLbLTmnJRt |
| 258 | // EC9Bv+bXjvAiHvWMRMUbOj/ddPNVez7Uld+FvdBaHwDWQlvzHzBWfBCOKSEhh7Z6 |
| 259 | // qDhUqQKBgQDPMDx2i5rfmQp3imV9xUcCkIRsyYQVf8Eo7NV07IdUy/otmksgn4Zt |
| 260 | // Lbf3v2dvxOpTNTONWjp2c+iUQo8QxJCZr5Sfb21oQ9Ktcrmc/CY7LeBVDibXwxdM |
| 261 | // vRG8kBzvslFWh7REzC3u06GSVhyKDfW93kN2cKVwGoahRlhj7oHuZQ== |
| 262 | // -----END RSA PRIVATE KEY----- |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 263 | static const char kCRLTestRoot[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 264 | "-----BEGIN CERTIFICATE-----\n" |
| 265 | "MIIDbzCCAlegAwIBAgIJAODri7v0dDUFMA0GCSqGSIb3DQEBCwUAME4xCzAJBgNV\n" |
| 266 | "BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1Nb3VudGFpbiBW\n" |
| 267 | "aWV3MRIwEAYDVQQKDAlCb3JpbmdTU0wwHhcNMTYwOTI2MTUwNjI2WhcNMjYwOTI0\n" |
| 268 | "MTUwNjI2WjBOMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQG\n" |
| 269 | "A1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJQm9yaW5nU1NMMIIBIjANBgkq\n" |
| 270 | "hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo16WiLWZuaymsD8n5SKPmxV1y6jjgr3B\n" |
| 271 | "S/dUBpbrzd1aeFzNlI8l2jfAnzUyp+I21RQ+nh/MhqjGElkTtK9xMn1Y+S9GMRh+\n" |
| 272 | "5R/Du0iCb1tCZIPY07Tgrb0KMNWe0v2QKVVruuYSgxIWodBfxlKO64Z8AJ5IbnWp\n" |
| 273 | "uRqO6rctN9qUoMlTIAB6dL4G0tDJ/PGFWOJYwOMEIX54bly2wgyYJVBKiRRt4f7n\n" |
| 274 | "8H922qmvPNA9idmX9G1VAtgV6x97XXi7ULORIQvn9lVQF6nTYDBJhyuPB+mLThbL\n" |
| 275 | "P2o9orxGx7aCtnnBZUIxUvHNOI0FaSaZH7Fi0xsZ/GkG2HZe7ImPJwIDAQABo1Aw\n" |
| 276 | "TjAdBgNVHQ4EFgQUWPt3N5cZ/CRvubbrkqfBnAqhq94wHwYDVR0jBBgwFoAUWPt3\n" |
| 277 | "N5cZ/CRvubbrkqfBnAqhq94wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC\n" |
| 278 | "AQEAORu6M0MOwXy+3VEBwNilfTxyqDfruQsc1jA4PT8Oe8zora1WxE1JB4q2FJOz\n" |
| 279 | "EAuM3H/NXvEnBuN+ITvKZAJUfm4NKX97qmjMJwLKWe1gVv+VQTr63aR7mgWJReQN\n" |
| 280 | "XdMztlVeZs2dppV6uEg3ia1X0G7LARxGpA9ETbMyCpb39XxlYuTClcbA5ftDN99B\n" |
| 281 | "3Xg9KNdd++Ew22O3HWRDvdDpTO/JkzQfzi3sYwUtzMEonENhczJhGf7bQMmvL/w5\n" |
| 282 | "24Wxj4Z7KzzWIHsNqE/RIs6RV3fcW61j/mRgW2XyoWnMVeBzvcJr9NXp4VQYmFPw\n" |
| 283 | "amd8GKMZQvP0ufGnUn7D7uartA==\n" |
| 284 | "-----END CERTIFICATE-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 285 | |
| 286 | static const char kCRLTestLeaf[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 287 | "-----BEGIN CERTIFICATE-----\n" |
| 288 | "MIIDkDCCAnigAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwTjELMAkGA1UEBhMCVVMx\n" |
| 289 | "EzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxEjAQ\n" |
| 290 | "BgNVBAoMCUJvcmluZ1NTTDAeFw0xNjA5MjYxNTA4MzFaFw0xNzA5MjYxNTA4MzFa\n" |
| 291 | "MEsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQKDAlC\n" |
| 292 | "b3JpbmdTU0wxEzARBgNVBAMMCmJvcmluZy5zc2wwggEiMA0GCSqGSIb3DQEBAQUA\n" |
| 293 | "A4IBDwAwggEKAoIBAQDc5v1S1M0W+QWM+raWfO0LH8uvqEwuJQgODqMaGnSlWUx9\n" |
| 294 | "8iQcnWfjyPja3lWg9K62hSOFDuSyEkysKHDxijz5R93CfLcfnVXjWQDJe7EJTTDP\n" |
| 295 | "ozEvxN6RjAeYv7CF000euYr3QT5iyBjg76+bon1p0jHZBJeNPP1KqGYgyxp+hzpx\n" |
| 296 | "e0gZmTlGAXd8JQK4v8kpdYwD6PPifFL/jpmQpqOtQmH/6zcLjY4ojmqpEdBqIKIX\n" |
| 297 | "+saA29hMq0+NK3K+wgg31RU+cVWxu3tLOIiesETkeDgArjWRS1Vkzbi4v9SJxtNu\n" |
| 298 | "OZuAxWiynRJw3JwH/OFHYZIvQqz68ZBoj96cepjPAgMBAAGjezB5MAkGA1UdEwQC\n" |
| 299 | "MAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRl\n" |
| 300 | "MB0GA1UdDgQWBBTGn0OVVh/aoYt0bvEKG+PIERqnDzAfBgNVHSMEGDAWgBRY+3c3\n" |
| 301 | "lxn8JG+5tuuSp8GcCqGr3jANBgkqhkiG9w0BAQsFAAOCAQEAd2nM8gCQN2Dc8QJw\n" |
| 302 | "XSZXyuI3DBGGCHcay/3iXu0JvTC3EiQo8J6Djv7WLI0N5KH8mkm40u89fJAB2lLZ\n" |
| 303 | "ShuHVtcC182bOKnePgwp9CNwQ21p0rDEu/P3X46ZvFgdxx82E9xLa0tBB8PiPDWh\n" |
| 304 | "lV16jbaKTgX5AZqjnsyjR5o9/mbZVupZJXx5Syq+XA8qiJfstSYJs4KyKK9UOjql\n" |
| 305 | "ICkJVKpi2ahDBqX4MOH4SLfzVk8pqSpviS6yaA1RXqjpkxiN45WWaXDldVHMSkhC\n" |
| 306 | "5CNXsXi4b1nAntu89crwSLA3rEwzCWeYj+BX7e1T9rr3oJdwOU/2KQtW1js1yQUG\n" |
| 307 | "tjJMFw==\n" |
| 308 | "-----END CERTIFICATE-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 309 | |
| 310 | static const char kBasicCRL[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 311 | "-----BEGIN X509 CRL-----\n" |
| 312 | "MIIBpzCBkAIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 313 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 314 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoA4wDDAKBgNV\n" |
| 315 | "HRQEAwIBATANBgkqhkiG9w0BAQsFAAOCAQEAnrBKKgvd9x9zwK9rtUvVeFeJ7+LN\n" |
| 316 | "ZEAc+a5oxpPNEsJx6hXoApYEbzXMxuWBQoCs5iEBycSGudct21L+MVf27M38KrWo\n" |
| 317 | "eOkq0a2siqViQZO2Fb/SUFR0k9zb8xl86Zf65lgPplALun0bV/HT7MJcl04Tc4os\n" |
| 318 | "dsAReBs5nqTGNEd5AlC1iKHvQZkM//MD51DspKnDpsDiUVi54h9C1SpfZmX8H2Vv\n" |
| 319 | "diyu0fZ/bPAM3VAGawatf/SyWfBMyKpoPXEG39oAzmjjOj8en82psn7m474IGaho\n" |
| 320 | "/vBbhl1ms5qQiLYPjm4YELtnXQoFyC72tBjbdFd/ZE9k4CNKDbxFUXFbkw==\n" |
| 321 | "-----END X509 CRL-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 322 | |
| 323 | static const char kRevokedCRL[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 324 | "-----BEGIN X509 CRL-----\n" |
| 325 | "MIIBvjCBpwIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 326 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 327 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEyNDRaFw0xNjEwMjYxNTEyNDRaMBUwEwICEAAX\n" |
| 328 | "DTE2MDkyNjE1MTIyNlqgDjAMMAoGA1UdFAQDAgECMA0GCSqGSIb3DQEBCwUAA4IB\n" |
| 329 | "AQCUGaM4DcWzlQKrcZvI8TMeR8BpsvQeo5BoI/XZu2a8h//PyRyMwYeaOM+3zl0d\n" |
| 330 | "sjgCT8b3C1FPgT+P2Lkowv7rJ+FHJRNQkogr+RuqCSPTq65ha4WKlRGWkMFybzVH\n" |
| 331 | "NloxC+aU3lgp/NlX9yUtfqYmJek1CDrOOGPrAEAwj1l/BUeYKNGqfBWYJQtPJu+5\n" |
| 332 | "OaSvIYGpETCZJscUWODmLEb/O3DM438vLvxonwGqXqS0KX37+CHpUlyhnSovxXxp\n" |
| 333 | "Pz4aF+L7OtczxL0GYtD2fR9B7TDMqsNmHXgQrixvvOY7MUdLGbd4RfJL3yA53hyO\n" |
| 334 | "xzfKY2TzxLiOmctG0hXFkH5J\n" |
| 335 | "-----END X509 CRL-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 336 | |
| 337 | static const char kBadIssuerCRL[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 338 | "-----BEGIN X509 CRL-----\n" |
| 339 | "MIIBwjCBqwIBATANBgkqhkiG9w0BAQsFADBSMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 340 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzEWMBQGA1UECgwN\n" |
| 341 | "Tm90IEJvcmluZ1NTTBcNMTYwOTI2MTUxMjQ0WhcNMTYxMDI2MTUxMjQ0WjAVMBMC\n" |
| 342 | "AhAAFw0xNjA5MjYxNTEyMjZaoA4wDDAKBgNVHRQEAwIBAjANBgkqhkiG9w0BAQsF\n" |
| 343 | "AAOCAQEAlBmjOA3Fs5UCq3GbyPEzHkfAabL0HqOQaCP12btmvIf/z8kcjMGHmjjP\n" |
| 344 | "t85dHbI4Ak/G9wtRT4E/j9i5KML+6yfhRyUTUJKIK/kbqgkj06uuYWuFipURlpDB\n" |
| 345 | "cm81RzZaMQvmlN5YKfzZV/clLX6mJiXpNQg6zjhj6wBAMI9ZfwVHmCjRqnwVmCUL\n" |
| 346 | "TybvuTmkryGBqREwmSbHFFjg5ixG/ztwzON/Ly78aJ8Bql6ktCl9+/gh6VJcoZ0q\n" |
| 347 | "L8V8aT8+Ghfi+zrXM8S9BmLQ9n0fQe0wzKrDZh14EK4sb7zmOzFHSxm3eEXyS98g\n" |
| 348 | "Od4cjsc3ymNk88S4jpnLRtIVxZB+SQ==\n" |
| 349 | "-----END X509 CRL-----\n"; |
| 350 | |
| 351 | // kKnownCriticalCRL is kBasicCRL but with a critical issuing distribution point |
| 352 | // extension. |
| 353 | static const char kKnownCriticalCRL[] = |
| 354 | "-----BEGIN X509 CRL-----\n" |
| 355 | "MIIBujCBowIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 356 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 357 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoCEwHzAKBgNV\n" |
| 358 | "HRQEAwIBATARBgNVHRwBAf8EBzAFoQMBAf8wDQYJKoZIhvcNAQELBQADggEBAA+3\n" |
| 359 | "i+5e5Ub8sccfgOBs6WVJFI9c8gvJjrJ8/dYfFIAuCyeocs7DFXn1n13CRZ+URR/Q\n" |
| 360 | "mVWgU28+xeusuSPYFpd9cyYTcVyNUGNTI3lwgcE/yVjPaOmzSZKdPakApRxtpKKQ\n" |
| 361 | "NN/56aQz3bnT/ZSHQNciRB8U6jiD9V30t0w+FDTpGaG+7bzzUH3UVF9xf9Ctp60A\n" |
| 362 | "3mfLe0scas7owSt4AEFuj2SPvcE7yvdOXbu+IEv21cEJUVExJAbhvIweHXh6yRW+\n" |
| 363 | "7VVeiNzdIjkZjyTmAzoXGha4+wbxXyBRbfH+XWcO/H+8nwyG8Gktdu2QB9S9nnIp\n" |
| 364 | "o/1TpfOMSGhMyMoyPrk=\n" |
| 365 | "-----END X509 CRL-----\n"; |
| 366 | |
| 367 | // kUnknownCriticalCRL is kBasicCRL but with an unknown critical extension. |
| 368 | static const char kUnknownCriticalCRL[] = |
| 369 | "-----BEGIN X509 CRL-----\n" |
| 370 | "MIIBvDCBpQIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 371 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 372 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoCMwITAKBgNV\n" |
| 373 | "HRQEAwIBATATBgwqhkiG9xIEAYS3CQABAf8EADANBgkqhkiG9w0BAQsFAAOCAQEA\n" |
| 374 | "GvBP0xqL509InMj/3493YVRV+ldTpBv5uTD6jewzf5XdaxEQ/VjTNe5zKnxbpAib\n" |
| 375 | "Kf7cwX0PMSkZjx7k7kKdDlEucwVvDoqC+O9aJcqVmM6GDyNb9xENxd0XCXja6MZC\n" |
| 376 | "yVgP4AwLauB2vSiEprYJyI1APph3iAEeDm60lTXX/wBM/tupQDDujKh2GPyvBRfJ\n" |
| 377 | "+wEDwGg3ICwvu4gO4zeC5qnFR+bpL9t5tOMAQnVZ0NWv+k7mkd2LbHdD44dxrfXC\n" |
| 378 | "nhtfERx99SDmC/jtUAJrGhtCO8acr7exCeYcduN7KKCm91OeCJKK6OzWst0Og1DB\n" |
| 379 | "kwzzU2rL3G65CrZ7H0SZsQ==\n" |
| 380 | "-----END X509 CRL-----\n"; |
| 381 | |
| 382 | // kUnknownCriticalCRL2 is kBasicCRL but with a critical issuing distribution |
| 383 | // point extension followed by an unknown critical extension |
| 384 | static const char kUnknownCriticalCRL2[] = |
| 385 | "-----BEGIN X509 CRL-----\n" |
| 386 | "MIIBzzCBuAIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 387 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 388 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoDYwNDAKBgNV\n" |
| 389 | "HRQEAwIBATARBgNVHRwBAf8EBzAFoQMBAf8wEwYMKoZIhvcSBAGEtwkAAQH/BAAw\n" |
| 390 | "DQYJKoZIhvcNAQELBQADggEBACTcpQC8jXL12JN5YzOcQ64ubQIe0XxRAd30p7qB\n" |
| 391 | "BTXGpgqBjrjxRfLms7EBYodEXB2oXMsDq3km0vT1MfYdsDD05S+SQ9CDsq/pUfaC\n" |
| 392 | "E2WNI5p8WircRnroYvbN2vkjlRbMd1+yNITohXYXCJwjEOAWOx3XIM10bwPYBv4R\n" |
| 393 | "rDobuLHoMgL3yHgMHmAkP7YpkBucNqeBV8cCdeAZLuhXFWi6yfr3r/X18yWbC/r2\n" |
| 394 | "2xXdkrSqXLFo7ToyP8YKTgiXpya4x6m53biEYwa2ULlas0igL6DK7wjYZX95Uy7H\n" |
| 395 | "GKljn9weIYiMPV/BzGymwfv2EW0preLwtyJNJPaxbdin6Jc=\n" |
| 396 | "-----END X509 CRL-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 397 | |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 398 | // kEd25519Cert is a self-signed Ed25519 certificate. |
| 399 | static const char kEd25519Cert[] = |
| 400 | "-----BEGIN CERTIFICATE-----\n" |
| 401 | "MIIBkTCCAUOgAwIBAgIJAJwooam0UCDmMAUGAytlcDBFMQswCQYDVQQGEwJBVTET\n" |
| 402 | "MBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ\n" |
| 403 | "dHkgTHRkMB4XDTE0MDQyMzIzMjE1N1oXDTE0MDUyMzIzMjE1N1owRTELMAkGA1UE\n" |
| 404 | "BhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdp\n" |
| 405 | "ZGdpdHMgUHR5IEx0ZDAqMAUGAytlcAMhANdamAGCsQq31Uv+08lkBzoO4XLz2qYj\n" |
| 406 | "Ja8CGmj3B1Eao1AwTjAdBgNVHQ4EFgQUoux7eV+fJK2v3ah6QPU/lj1/+7UwHwYD\n" |
| 407 | "VR0jBBgwFoAUoux7eV+fJK2v3ah6QPU/lj1/+7UwDAYDVR0TBAUwAwEB/zAFBgMr\n" |
| 408 | "ZXADQQBuCzqji8VP9xU8mHEMjXGChX7YP5J664UyVKHKH9Z1u4wEbB8dJ3ScaWSL\n" |
| 409 | "r+VHVKUhsrvcdCelnXRrrSD7xWAL\n" |
| 410 | "-----END CERTIFICATE-----\n"; |
| 411 | |
| 412 | // kEd25519CertNull is an invalid self-signed Ed25519 with an explicit NULL in |
| 413 | // the signature algorithm. |
| 414 | static const char kEd25519CertNull[] = |
| 415 | "-----BEGIN CERTIFICATE-----\n" |
| 416 | "MIIBlTCCAUWgAwIBAgIJAJwooam0UCDmMAcGAytlcAUAMEUxCzAJBgNVBAYTAkFV\n" |
| 417 | "MRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRz\n" |
| 418 | "IFB0eSBMdGQwHhcNMTQwNDIzMjMyMTU3WhcNMTQwNTIzMjMyMTU3WjBFMQswCQYD\n" |
| 419 | "VQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQg\n" |
| 420 | "V2lkZ2l0cyBQdHkgTHRkMCowBQYDK2VwAyEA11qYAYKxCrfVS/7TyWQHOg7hcvPa\n" |
| 421 | "piMlrwIaaPcHURqjUDBOMB0GA1UdDgQWBBSi7Ht5X58kra/dqHpA9T+WPX/7tTAf\n" |
| 422 | "BgNVHSMEGDAWgBSi7Ht5X58kra/dqHpA9T+WPX/7tTAMBgNVHRMEBTADAQH/MAcG\n" |
| 423 | "AytlcAUAA0EA70uefNocdJohkKPNROKVyBuBD3LXMyvmdTklsaxSRY3PcZdOohlr\n" |
| 424 | "recgVPpVS7B+d9g4EwtZXIh4lodTBDHBBw==\n" |
| 425 | "-----END CERTIFICATE-----\n"; |
| 426 | |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 427 | // kSANTypesLeaf is a leaf certificate (signed by |kSANTypesRoot|) which |
| 428 | // contains SANS for example.com, test@example.com, 127.0.0.1, and |
| 429 | // https://example.com/. (The latter is useless for now since crypto/x509 |
| 430 | // doesn't deal with URI SANs directly.) |
| 431 | static const char kSANTypesLeaf[] = |
| 432 | "-----BEGIN CERTIFICATE-----\n" |
| 433 | "MIIClzCCAgCgAwIBAgIJAOjwnT/iW+qmMA0GCSqGSIb3DQEBCwUAMCsxFzAVBgNV\n" |
| 434 | "BAoTDkJvcmluZ1NTTCBUZXN0MRAwDgYDVQQDEwdSb290IENBMB4XDTE1MDEwMTAw\n" |
| 435 | "MDAwMFoXDTI1MDEwMTAwMDAwMFowLzEXMBUGA1UEChMOQm9yaW5nU1NMIFRlc3Qx\n" |
| 436 | "FDASBgNVBAMTC2V4YW1wbGUuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\n" |
| 437 | "gQDbRn2TLhInBki8Bighq37EtqJd/h5SRYh6NkelCA2SQlvCgcC+l3mYQPtPbRT9\n" |
| 438 | "KxOLwqUuZ9jUCZ7WIji3Sgt0cyvCNPHRk+WW2XR781ifbGE8wLBB1NkrKyQjd1sc\n" |
| 439 | "O711Xc4gVM+hY4cdHiTE8x0aUIuqthRD7ZendWL0FMhS1wIDAQABo4G+MIG7MA4G\n" |
| 440 | "A1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwDAYD\n" |
| 441 | "VR0TAQH/BAIwADAZBgNVHQ4EEgQQn5EWH0NDPkmm3m22gNefYDAbBgNVHSMEFDAS\n" |
| 442 | "gBBAN9cB+0AvuBx+VAQnjFkBMEQGA1UdEQQ9MDuCC2V4YW1wbGUuY29tgRB0ZXN0\n" |
| 443 | "QGV4YW1wbGUuY29thwR/AAABhhRodHRwczovL2V4YW1wbGUuY29tLzANBgkqhkiG\n" |
| 444 | "9w0BAQsFAAOBgQBtwJvY6+Tk6D6DOtDVaNoJ5y8E25CCuE/Ga4OuIcYJas+yLckf\n" |
| 445 | "dZwUV3GUG2oBXl2MrpUFxXd4hKBO1CmlBY+hZEeIx0Yp6QWK9P/vnZeydOTP26mk\n" |
| 446 | "jusJ2PqSmtKNU1Zcaba4d29oFejmOAfeguhR8AHpsc/zHEaS5Q9cJsuJcw==\n" |
| 447 | "-----END CERTIFICATE-----\n"; |
| 448 | |
| 449 | // -----BEGIN RSA PRIVATE KEY----- |
| 450 | // MIICWwIBAAKBgQDbRn2TLhInBki8Bighq37EtqJd/h5SRYh6NkelCA2SQlvCgcC+ |
| 451 | // l3mYQPtPbRT9KxOLwqUuZ9jUCZ7WIji3Sgt0cyvCNPHRk+WW2XR781ifbGE8wLBB |
| 452 | // 1NkrKyQjd1scO711Xc4gVM+hY4cdHiTE8x0aUIuqthRD7ZendWL0FMhS1wIDAQAB |
| 453 | // AoGACwf7z0i1DxOI2zSwFimLghfyCSp8mgT3fbZ3Wj0SebYu6ZUffjceneM/AVrq |
| 454 | // gGYHYLOVHcWJqfkl7X3hPo9SDhzLx0mM545/q21ZWCwjhswH7WiCEqV2/zeDO9WU |
| 455 | // NIO1VU0VoLm0AQ7ZvwnyB+fpgF9kkkDtbBJW7XWrfNVtlnECQQD97YENpEJ3X1kj |
| 456 | // 3rrkrHWDkKAyoWWY1i8Fm7LnganC9Bv6AVwgn5ZlE/479aWHF8vbOFEA3pFPiNZJ |
| 457 | // t9FTCfpJAkEA3RCXjGI0Y6GALFLwEs+nL/XZAfJaIpJEZVLCVosYQOSaMS4SchfC |
| 458 | // GGYVquT7ZgKk9uvz89Fg87OtBMWS9lrkHwJADGkGLKeBhBoJ3kHtem2fVK3F1pOi |
| 459 | // xoR5SdnhNYVVyaxqjZ5xZTrHe+stOrr3uxGDqhQniVZXXb6/Ul0Egv1y2QJAVg/h |
| 460 | // kAujba4wIhFf2VLyOZ+yjil1ocPj0LZ5Zgvcs1bMGJ1hHP3W2HzVrqRaowoggui1 |
| 461 | // HpTC891dXGA2qKYV7QJAFDmT2A7OVvh3y4AEgzVwHrDmCMwMHKjCIntS7fjxrJnF |
| 462 | // YvJUG1zoHwUVrxxbR3DbpTODlktLcl/0b97D0IkH3w== |
| 463 | // -----END RSA PRIVATE KEY----- |
| 464 | |
| 465 | static const char kSANTypesRoot[] = |
| 466 | "-----BEGIN CERTIFICATE-----\n" |
| 467 | "MIICTTCCAbagAwIBAgIIAj5CwoHlWuYwDQYJKoZIhvcNAQELBQAwKzEXMBUGA1UE\n" |
| 468 | "ChMOQm9yaW5nU1NMIFRlc3QxEDAOBgNVBAMTB1Jvb3QgQ0EwHhcNMTUwMTAxMDAw\n" |
| 469 | "MDAwWhcNMjUwMTAxMDAwMDAwWjArMRcwFQYDVQQKEw5Cb3JpbmdTU0wgVGVzdDEQ\n" |
| 470 | "MA4GA1UEAxMHUm9vdCBDQTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA6Q5/\n" |
| 471 | "EQzmWuaGg3D2UQcuAngR9bIkkjjuJmICx5TxPqF3asCP1SJotl3iTNrghRE1wpJy\n" |
| 472 | "SY2BtIiXa7f8skRb2U0GcPkMxo/ps9+jaoRsQ1m+nbLQdpvD1/qZWcO45fNTA71J\n" |
| 473 | "1rPMokP+rcILuQG4VimUAySnDSghKamulFtK+Z8CAwEAAaN6MHgwDgYDVR0PAQH/\n" |
| 474 | "BAQDAgIEMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAPBgNVHRMBAf8E\n" |
| 475 | "BTADAQH/MBkGA1UdDgQSBBBAN9cB+0AvuBx+VAQnjFkBMBsGA1UdIwQUMBKAEEA3\n" |
| 476 | "1wH7QC+4HH5UBCeMWQEwDQYJKoZIhvcNAQELBQADgYEAc4N6hTE62/3gwg+kyc2f\n" |
| 477 | "c/Jj1mHrOt+0NRaBnmvbmNpsEjHS96Ef4Wt/ZlPXPkkv1C1VosJnOIMF3Q522wRH\n" |
| 478 | "bqaxARldS12VAa3gcWisDWD+SqSyDxjyojz0XDiJkTrFuCTCUiZO+1GLB7SO10Ms\n" |
| 479 | "d5YVX0c90VMnUhF/dlrqS9U=\n" |
| 480 | "-----END CERTIFICATE-----\n"; |
| 481 | |
| 482 | // -----BEGIN RSA PRIVATE KEY----- |
| 483 | // MIICXAIBAAKBgQDpDn8RDOZa5oaDcPZRBy4CeBH1siSSOO4mYgLHlPE+oXdqwI/V |
| 484 | // Imi2XeJM2uCFETXCknJJjYG0iJdrt/yyRFvZTQZw+QzGj+mz36NqhGxDWb6dstB2 |
| 485 | // m8PX+plZw7jl81MDvUnWs8yiQ/6twgu5AbhWKZQDJKcNKCEpqa6UW0r5nwIDAQAB |
| 486 | // AoGALEF5daZqc+aEsp8X1yky3nsoheyPL0kqSBWii33IFemZgKcSaRnAoqjPWWLS |
| 487 | // 8dHj0I/4rej2MW8iuezVSpDak9tK5boHORC3w4p/wifkizQkLt1DANxTVbzcKvrt |
| 488 | // aZ7LjVaKkhjRJbLddniowFHkkWVbUccjvzcUd7Y2VuLbAhECQQDq4FE88aHio8zg |
| 489 | // bxSd0PwjEFwLYQTR19u812SoR8PmR6ofIL+pDwOV+fVs+OGcAAOgkhIukOrksQ4A |
| 490 | // 1cKtnyhXAkEA/gRI+u3tZ7UE1twIkBfZ6IvCdRodkPqHAYIxMRLzL+MhyZt4MEGc |
| 491 | // Ngb/F6U9/WOBFnoR/PI7IwE3ejutzKcL+QJBAKh+6eilk7QKPETZi1m3/dmNt+p1 |
| 492 | // 3EZJ65pqjwxmB3Rg/vs7vCMk4TarTdSyKu+F1xRPFfoP/mK3Xctdjj6NyhsCQAYF |
| 493 | // 7/0TOzfkUPMPUJyqFB6xgbDpJ55ScnUUsznoqx+NkTWInDb4t02IqO/UmT2y6FKy |
| 494 | // Hk8TJ1fTJY+ebqaVp3ECQApx9gQ+n0zIhx97FMUuiRse73xkcW4+pZ8nF+8DmeQL |
| 495 | // /JKuuFGmzkG+rUbXFmo/Zg2ozVplw71NnQJ4znPsf7A= |
| 496 | // -----END RSA PRIVATE KEY----- |
| 497 | |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 498 | // The following four certificates were generated with this Go program, varying |
| 499 | // |includeNetscapeExtension| and defining rootKeyPEM and rootCertPEM to be |
| 500 | // strings containing the kSANTypesRoot, above. |
| 501 | |
| 502 | // package main |
| 503 | |
| 504 | // import ( |
| 505 | // "crypto/ecdsa" |
| 506 | // "crypto/elliptic" |
| 507 | // "crypto/rand" |
| 508 | // "crypto/x509" |
| 509 | // "crypto/x509/pkix" |
| 510 | // "encoding/asn1" |
| 511 | // "encoding/pem" |
| 512 | // "math/big" |
| 513 | // "os" |
| 514 | // "time" |
| 515 | // ) |
| 516 | |
| 517 | // const includeNetscapeExtension = true |
| 518 | |
| 519 | // func main() { |
| 520 | // block, _ := pem.Decode([]byte(rootKeyPEM)) |
| 521 | // rootPriv, _ := x509.ParsePKCS1PrivateKey(block.Bytes) |
| 522 | // block, _ = pem.Decode([]byte(rootCertPEM)) |
| 523 | // root, _ := x509.ParseCertificate(block.Bytes) |
| 524 | |
| 525 | // interTemplate := &x509.Certificate{ |
| 526 | // SerialNumber: big.NewInt(2), |
| 527 | // Subject: pkix.Name{ |
| 528 | // CommonName: "No Basic Constraints (Netscape)", |
| 529 | // }, |
| 530 | // NotBefore: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC), |
| 531 | // NotAfter: time.Date(2099, time.January, 1, 0, 0, 0, 0, time.UTC), |
| 532 | // } |
| 533 | |
| 534 | // if includeNetscapeExtension { |
| 535 | // interTemplate.ExtraExtensions = []pkix.Extension{ |
| 536 | // pkix.Extension{ |
| 537 | // Id: asn1.ObjectIdentifier([]int{2, 16, 840, 1, 113730, 1, 1}), |
| 538 | // Value: []byte{0x03, 0x02, 2, 0x04}, |
| 539 | // }, |
| 540 | // } |
| 541 | // } else { |
| 542 | // interTemplate.KeyUsage = x509.KeyUsageCertSign |
| 543 | // } |
| 544 | |
| 545 | // interKey, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) |
| 546 | |
| 547 | // interDER, err := x509.CreateCertificate(rand.Reader, interTemplate, root, &interKey.PublicKey, rootPriv) |
| 548 | // if err != nil { |
| 549 | // panic(err) |
| 550 | // } |
| 551 | |
| 552 | // pem.Encode(os.Stdout, &pem.Block{Type: "CERTIFICATE", Bytes: interDER}) |
| 553 | |
| 554 | // inter, _ := x509.ParseCertificate(interDER) |
| 555 | |
| 556 | // leafTemplate := &x509.Certificate{ |
| 557 | // SerialNumber: big.NewInt(3), |
| 558 | // Subject: pkix.Name{ |
| 559 | // CommonName: "Leaf from CA with no Basic Constraints", |
| 560 | // }, |
| 561 | // NotBefore: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC), |
| 562 | // NotAfter: time.Date(2099, time.January, 1, 0, 0, 0, 0, time.UTC), |
| 563 | // BasicConstraintsValid: true, |
| 564 | // } |
| 565 | // leafKey, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) |
| 566 | |
| 567 | // leafDER, err := x509.CreateCertificate(rand.Reader, leafTemplate, inter, &leafKey.PublicKey, interKey) |
| 568 | // if err != nil { |
| 569 | // panic(err) |
| 570 | // } |
| 571 | |
| 572 | // pem.Encode(os.Stdout, &pem.Block{Type: "CERTIFICATE", Bytes: leafDER}) |
| 573 | // } |
| 574 | |
| 575 | // kNoBasicConstraintsCertSignIntermediate doesn't have isCA set, but contains |
| 576 | // certSign in the keyUsage. |
| 577 | static const char kNoBasicConstraintsCertSignIntermediate[] = |
| 578 | "-----BEGIN CERTIFICATE-----\n" |
| 579 | "MIIBqjCCAROgAwIBAgIBAjANBgkqhkiG9w0BAQsFADArMRcwFQYDVQQKEw5Cb3Jp\n" |
| 580 | "bmdTU0wgVGVzdDEQMA4GA1UEAxMHUm9vdCBDQTAgFw0wMDAxMDEwMDAwMDBaGA8y\n" |
| 581 | "MDk5MDEwMTAwMDAwMFowHzEdMBsGA1UEAxMUTm8gQmFzaWMgQ29uc3RyYWludHMw\n" |
| 582 | "WTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASEFMblfxIEDO8My7wHtHWTuDzNyID1\n" |
| 583 | "OsPkMGkn32O/pSyXxXuAqDeFoMVffUMTyfm8JcYugSEbrv2qEXXM4bZRoy8wLTAO\n" |
| 584 | "BgNVHQ8BAf8EBAMCAgQwGwYDVR0jBBQwEoAQQDfXAftAL7gcflQEJ4xZATANBgkq\n" |
| 585 | "hkiG9w0BAQsFAAOBgQC1Lh6hIAm3K5kRh5iIydU0YAEm7eV6ZSskERDUq3DLJyl9\n" |
| 586 | "ZUZCHUzvb464dkwZjeNzaUVS1pdElJslwX3DtGgeJLJGCnk8zUjBjaNrrDm0kzPW\n" |
| 587 | "xKt/6oif1ci/KCKqKNXJAIFbc4e+IiBpenwpxHk3If4NM+Ek0nKoO8Uj0NkgTQ==\n" |
| 588 | "-----END CERTIFICATE-----\n"; |
| 589 | |
| 590 | static const char kNoBasicConstraintsCertSignLeaf[] = |
| 591 | "-----BEGIN CERTIFICATE-----\n" |
| 592 | "MIIBUDCB96ADAgECAgEDMAoGCCqGSM49BAMCMB8xHTAbBgNVBAMTFE5vIEJhc2lj\n" |
| 593 | "IENvbnN0cmFpbnRzMCAXDTAwMDEwMTAwMDAwMFoYDzIwOTkwMTAxMDAwMDAwWjAx\n" |
| 594 | "MS8wLQYDVQQDEyZMZWFmIGZyb20gQ0Egd2l0aCBubyBCYXNpYyBDb25zdHJhaW50\n" |
| 595 | "czBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABEsYPMwzdJKjB+2gpC90ib2ilHoB\n" |
| 596 | "w/arQ6ikUX0CNUDDaKaOu/jF39ogzVlg4lDFrjCKShSfCCcrwgONv70IZGijEDAO\n" |
| 597 | "MAwGA1UdEwEB/wQCMAAwCgYIKoZIzj0EAwIDSAAwRQIgbV7R99yM+okXSIs6Fp3o\n" |
| 598 | "eCOXiDL60IBxaTOcLS44ywcCIQDbn87Gj5cFgHBYAkzdHqDsyGXkxQTHDq9jmX24\n" |
| 599 | "Djy3Zw==\n" |
| 600 | "-----END CERTIFICATE-----\n"; |
| 601 | |
| 602 | // kNoBasicConstraintsNetscapeCAIntermediate doesn't have isCA set, but contains |
| 603 | // a Netscape certificate-type extension that asserts a type of "SSL CA". |
| 604 | static const char kNoBasicConstraintsNetscapeCAIntermediate[] = |
| 605 | "-----BEGIN CERTIFICATE-----\n" |
| 606 | "MIIBuDCCASGgAwIBAgIBAjANBgkqhkiG9w0BAQsFADArMRcwFQYDVQQKEw5Cb3Jp\n" |
| 607 | "bmdTU0wgVGVzdDEQMA4GA1UEAxMHUm9vdCBDQTAgFw0wMDAxMDEwMDAwMDBaGA8y\n" |
| 608 | "MDk5MDEwMTAwMDAwMFowKjEoMCYGA1UEAxMfTm8gQmFzaWMgQ29uc3RyYWludHMg\n" |
| 609 | "KE5ldHNjYXBlKTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABCeMbmCaOtMzXBqi\n" |
| 610 | "PrCdNOH23CkaawUA+pAezitAN4RXS1O2CGK5sJjGPVVeogROU8G7/b+mU+ciZIzH\n" |
| 611 | "1PP8FJKjMjAwMBsGA1UdIwQUMBKAEEA31wH7QC+4HH5UBCeMWQEwEQYJYIZIAYb4\n" |
| 612 | "QgEBBAQDAgIEMA0GCSqGSIb3DQEBCwUAA4GBAAgNWjh7cfBTClTAk+Ml//5xb9Ju\n" |
| 613 | "tkBhG6Rm+kkMD+qiSMO6t7xS7CsA0+jIBjkdEYaLZ3oxtQCBdZsVNxUvRxZ0AUfF\n" |
| 614 | "G3DtRFTsrI1f7IQhpMuqEMF4shPW+5x54hrq0Fo6xMs6XoinJZcTUaaB8EeXRF6M\n" |
| 615 | "P9p6HuyLrmn0c/F0\n" |
| 616 | "-----END CERTIFICATE-----\n"; |
| 617 | |
| 618 | static const char kNoBasicConstraintsNetscapeCALeaf[] = |
| 619 | "-----BEGIN CERTIFICATE-----\n" |
| 620 | "MIIBXDCCAQKgAwIBAgIBAzAKBggqhkjOPQQDAjAqMSgwJgYDVQQDEx9ObyBCYXNp\n" |
| 621 | "YyBDb25zdHJhaW50cyAoTmV0c2NhcGUpMCAXDTAwMDEwMTAwMDAwMFoYDzIwOTkw\n" |
| 622 | "MTAxMDAwMDAwWjAxMS8wLQYDVQQDEyZMZWFmIGZyb20gQ0Egd2l0aCBubyBCYXNp\n" |
| 623 | "YyBDb25zdHJhaW50czBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABDlJKolDu3R2\n" |
| 624 | "tPqSDycr0QJcWhxdBv76V0EEVflcHRxED6vAioTEcnQszt1OfKtBZvjlo0yp6i6Q\n" |
| 625 | "DaYit0ZInmWjEDAOMAwGA1UdEwEB/wQCMAAwCgYIKoZIzj0EAwIDSAAwRQIhAJsh\n" |
| 626 | "aZL6BHeEfoUBj1oZ2Ln91qzj3UCVMJ+vrmwAFdYyAiA3wp2JphgchvmoUFuzPXwj\n" |
| 627 | "XyPwWPbymSTpzKhB4xB7qQ==\n" |
| 628 | "-----END CERTIFICATE-----\n"; |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 629 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 630 | // CertFromPEM parses the given, NUL-terminated pem block and returns an |
| 631 | // |X509*|. |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 632 | static bssl::UniquePtr<X509> CertFromPEM(const char *pem) { |
| 633 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(pem, strlen(pem))); |
| 634 | return bssl::UniquePtr<X509>( |
| 635 | PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 636 | } |
| 637 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 638 | // CRLFromPEM parses the given, NUL-terminated pem block and returns an |
| 639 | // |X509_CRL*|. |
| 640 | static bssl::UniquePtr<X509_CRL> CRLFromPEM(const char *pem) { |
| 641 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(pem, strlen(pem))); |
| 642 | return bssl::UniquePtr<X509_CRL>( |
| 643 | PEM_read_bio_X509_CRL(bio.get(), nullptr, nullptr, nullptr)); |
| 644 | } |
| 645 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 646 | // PrivateKeyFromPEM parses the given, NUL-terminated pem block and returns an |
| 647 | // |EVP_PKEY*|. |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 648 | static bssl::UniquePtr<EVP_PKEY> PrivateKeyFromPEM(const char *pem) { |
| 649 | bssl::UniquePtr<BIO> bio( |
| 650 | BIO_new_mem_buf(const_cast<char *>(pem), strlen(pem))); |
| 651 | return bssl::UniquePtr<EVP_PKEY>( |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 652 | PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr)); |
| 653 | } |
| 654 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 655 | // CertsToStack converts a vector of |X509*| to an OpenSSL STACK_OF(X509), |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 656 | // bumping the reference counts for each certificate in question. |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 657 | static bssl::UniquePtr<STACK_OF(X509)> CertsToStack( |
| 658 | const std::vector<X509 *> &certs) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 659 | bssl::UniquePtr<STACK_OF(X509)> stack(sk_X509_new_null()); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 660 | if (!stack) { |
| 661 | return nullptr; |
| 662 | } |
| 663 | for (auto cert : certs) { |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 664 | if (!bssl::PushToStack(stack.get(), bssl::UpRef(cert))) { |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 665 | return nullptr; |
| 666 | } |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 667 | } |
| 668 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 669 | return stack; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 670 | } |
| 671 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 672 | // CRLsToStack converts a vector of |X509_CRL*| to an OpenSSL |
| 673 | // STACK_OF(X509_CRL), bumping the reference counts for each CRL in question. |
| 674 | static bssl::UniquePtr<STACK_OF(X509_CRL)> CRLsToStack( |
| 675 | const std::vector<X509_CRL *> &crls) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 676 | bssl::UniquePtr<STACK_OF(X509_CRL)> stack(sk_X509_CRL_new_null()); |
| 677 | if (!stack) { |
| 678 | return nullptr; |
| 679 | } |
| 680 | for (auto crl : crls) { |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 681 | if (!bssl::PushToStack(stack.get(), bssl::UpRef(crl))) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 682 | return nullptr; |
| 683 | } |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 684 | } |
| 685 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 686 | return stack; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | static int Verify(X509 *leaf, const std::vector<X509 *> &roots, |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 690 | const std::vector<X509 *> &intermediates, |
| 691 | const std::vector<X509_CRL *> &crls, unsigned long flags, |
| 692 | bool use_additional_untrusted, |
| 693 | std::function<void(X509_VERIFY_PARAM *)> configure_callback) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 694 | bssl::UniquePtr<STACK_OF(X509)> roots_stack(CertsToStack(roots)); |
| 695 | bssl::UniquePtr<STACK_OF(X509)> intermediates_stack( |
| 696 | CertsToStack(intermediates)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 697 | bssl::UniquePtr<STACK_OF(X509_CRL)> crls_stack(CRLsToStack(crls)); |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 698 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 699 | if (!roots_stack || |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 700 | !intermediates_stack || |
| 701 | !crls_stack) { |
| 702 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 703 | } |
| 704 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 705 | bssl::UniquePtr<X509_STORE_CTX> ctx(X509_STORE_CTX_new()); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 706 | bssl::UniquePtr<X509_STORE> store(X509_STORE_new()); |
| 707 | if (!ctx || |
| 708 | !store) { |
| 709 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 710 | } |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 711 | |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 712 | if (use_additional_untrusted) { |
| 713 | X509_STORE_set0_additional_untrusted(store.get(), |
| 714 | intermediates_stack.get()); |
| 715 | } |
| 716 | |
| 717 | if (!X509_STORE_CTX_init( |
| 718 | ctx.get(), store.get(), leaf, |
| 719 | use_additional_untrusted ? nullptr : intermediates_stack.get())) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 720 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | X509_STORE_CTX_trusted_stack(ctx.get(), roots_stack.get()); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 724 | X509_STORE_CTX_set0_crls(ctx.get(), crls_stack.get()); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 725 | |
| 726 | X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new(); |
| 727 | if (param == nullptr) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 728 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 729 | } |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 730 | X509_VERIFY_PARAM_set_time(param, 1474934400 /* Sep 27th, 2016 */); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 731 | X509_VERIFY_PARAM_set_depth(param, 16); |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 732 | if (configure_callback) { |
| 733 | configure_callback(param); |
| 734 | } |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 735 | if (flags) { |
| 736 | X509_VERIFY_PARAM_set_flags(param, flags); |
| 737 | } |
| 738 | X509_STORE_CTX_set0_param(ctx.get(), param); |
| 739 | |
| 740 | ERR_clear_error(); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 741 | if (X509_verify_cert(ctx.get()) != 1) { |
| 742 | return X509_STORE_CTX_get_error(ctx.get()); |
| 743 | } |
| 744 | |
| 745 | return X509_V_OK; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 746 | } |
| 747 | |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 748 | static int Verify(X509 *leaf, const std::vector<X509 *> &roots, |
| 749 | const std::vector<X509 *> &intermediates, |
| 750 | const std::vector<X509_CRL *> &crls, |
| 751 | unsigned long flags = 0) { |
Robert Sloan | ab8b888 | 2018-03-26 11:39:51 -0700 | [diff] [blame] | 752 | const int r1 = |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 753 | Verify(leaf, roots, intermediates, crls, flags, false, nullptr); |
Robert Sloan | ab8b888 | 2018-03-26 11:39:51 -0700 | [diff] [blame] | 754 | const int r2 = |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 755 | Verify(leaf, roots, intermediates, crls, flags, true, nullptr); |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 756 | |
| 757 | if (r1 != r2) { |
| 758 | fprintf(stderr, |
| 759 | "Verify with, and without, use_additional_untrusted gave different " |
| 760 | "results: %d vs %d.\n", |
| 761 | r1, r2); |
| 762 | return false; |
| 763 | } |
| 764 | |
| 765 | return r1; |
| 766 | } |
| 767 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 768 | TEST(X509Test, TestVerify) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 769 | bssl::UniquePtr<X509> cross_signing_root(CertFromPEM(kCrossSigningRootPEM)); |
| 770 | bssl::UniquePtr<X509> root(CertFromPEM(kRootCAPEM)); |
| 771 | bssl::UniquePtr<X509> root_cross_signed(CertFromPEM(kRootCrossSignedPEM)); |
| 772 | bssl::UniquePtr<X509> intermediate(CertFromPEM(kIntermediatePEM)); |
| 773 | bssl::UniquePtr<X509> intermediate_self_signed( |
| 774 | CertFromPEM(kIntermediateSelfSignedPEM)); |
| 775 | bssl::UniquePtr<X509> leaf(CertFromPEM(kLeafPEM)); |
| 776 | bssl::UniquePtr<X509> leaf_no_key_usage(CertFromPEM(kLeafNoKeyUsagePEM)); |
| 777 | bssl::UniquePtr<X509> forgery(CertFromPEM(kForgeryPEM)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 778 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 779 | ASSERT_TRUE(cross_signing_root); |
| 780 | ASSERT_TRUE(root); |
| 781 | ASSERT_TRUE(root_cross_signed); |
| 782 | ASSERT_TRUE(intermediate); |
| 783 | ASSERT_TRUE(intermediate_self_signed); |
| 784 | ASSERT_TRUE(leaf); |
| 785 | ASSERT_TRUE(forgery); |
| 786 | ASSERT_TRUE(leaf_no_key_usage); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 787 | |
| 788 | std::vector<X509*> empty; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 789 | std::vector<X509_CRL*> empty_crls; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 790 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, |
| 791 | Verify(leaf.get(), empty, empty, empty_crls)); |
| 792 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, |
| 793 | Verify(leaf.get(), empty, {intermediate.get()}, empty_crls)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 794 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 795 | ASSERT_EQ(X509_V_OK, |
| 796 | Verify(leaf.get(), {root.get()}, {intermediate.get()}, empty_crls)); |
| 797 | ASSERT_EQ(X509_V_OK, |
| 798 | Verify(leaf.get(), {cross_signing_root.get()}, |
| 799 | {intermediate.get(), root_cross_signed.get()}, empty_crls)); |
| 800 | ASSERT_EQ(X509_V_OK, |
| 801 | Verify(leaf.get(), {cross_signing_root.get(), root.get()}, |
| 802 | {intermediate.get(), root_cross_signed.get()}, empty_crls)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 803 | |
| 804 | /* This is the “altchains” test – we remove the cross-signing CA but include |
| 805 | * the cross-sign in the intermediates. */ |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 806 | ASSERT_EQ(X509_V_OK, |
| 807 | Verify(leaf.get(), {root.get()}, |
| 808 | {intermediate.get(), root_cross_signed.get()}, empty_crls)); |
| 809 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, |
| 810 | Verify(leaf.get(), {root.get()}, |
| 811 | {intermediate.get(), root_cross_signed.get()}, empty_crls, |
| 812 | X509_V_FLAG_NO_ALT_CHAINS)); |
| 813 | ASSERT_EQ(X509_V_ERR_INVALID_CA, |
| 814 | Verify(forgery.get(), {intermediate_self_signed.get()}, |
| 815 | {leaf_no_key_usage.get()}, empty_crls)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 816 | |
| 817 | /* Test that one cannot skip Basic Constraints checking with a contorted set |
| 818 | * 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] | 819 | ASSERT_EQ(X509_V_ERR_INVALID_CA, |
| 820 | Verify(forgery.get(), |
| 821 | {intermediate_self_signed.get(), root_cross_signed.get()}, |
| 822 | {leaf_no_key_usage.get(), intermediate.get()}, empty_crls)); |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 823 | } |
Robert Sloan | ab8b888 | 2018-03-26 11:39:51 -0700 | [diff] [blame] | 824 | |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 825 | static const char kHostname[] = "example.com"; |
| 826 | static const char kWrongHostname[] = "example2.com"; |
| 827 | static const char kEmail[] = "test@example.com"; |
| 828 | static const char kWrongEmail[] = "test2@example.com"; |
| 829 | static const uint8_t kIP[4] = {127, 0, 0, 1}; |
| 830 | static const uint8_t kWrongIP[4] = {127, 0, 0, 2}; |
| 831 | static const char kIPString[] = "127.0.0.1"; |
| 832 | static const char kWrongIPString[] = "127.0.0.2"; |
| 833 | |
| 834 | TEST(X509Test, ZeroLengthsWithX509PARAM) { |
| 835 | bssl::UniquePtr<X509> leaf(CertFromPEM(kSANTypesLeaf)); |
| 836 | bssl::UniquePtr<X509> root(CertFromPEM(kSANTypesRoot)); |
| 837 | ASSERT_TRUE(leaf); |
| 838 | ASSERT_TRUE(root); |
| 839 | |
| 840 | std::vector<X509_CRL *> empty_crls; |
| 841 | |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 842 | struct X509Test { |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 843 | const char *correct_value; |
| 844 | size_t correct_value_len; |
| 845 | const char *incorrect_value; |
| 846 | size_t incorrect_value_len; |
| 847 | int (*func)(X509_VERIFY_PARAM *, const char *, size_t); |
| 848 | int mismatch_error; |
| 849 | }; |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 850 | const std::vector<X509Test> kTests = { |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 851 | {kHostname, strlen(kHostname), kWrongHostname, strlen(kWrongHostname), |
| 852 | X509_VERIFY_PARAM_set1_host, X509_V_ERR_HOSTNAME_MISMATCH}, |
| 853 | {kEmail, strlen(kEmail), kWrongEmail, strlen(kWrongEmail), |
| 854 | X509_VERIFY_PARAM_set1_email, X509_V_ERR_EMAIL_MISMATCH}, |
| 855 | }; |
| 856 | |
| 857 | for (size_t i = 0; i < kTests.size(); i++) { |
| 858 | SCOPED_TRACE(i); |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 859 | const X509Test &test = kTests[i]; |
Robert Sloan | 49d063b | 2018-04-03 11:30:38 -0700 | [diff] [blame] | 860 | |
| 861 | // The correct value should work. |
| 862 | ASSERT_EQ(X509_V_OK, |
| 863 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 864 | [&test](X509_VERIFY_PARAM *param) { |
| 865 | ASSERT_TRUE(test.func(param, test.correct_value, |
| 866 | test.correct_value_len)); |
| 867 | })); |
| 868 | |
| 869 | // The wrong value should trigger a verification error. |
| 870 | ASSERT_EQ(test.mismatch_error, |
| 871 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 872 | [&test](X509_VERIFY_PARAM *param) { |
| 873 | ASSERT_TRUE(test.func(param, test.incorrect_value, |
| 874 | test.incorrect_value_len)); |
| 875 | })); |
| 876 | |
| 877 | // Passing zero as the length, unlike OpenSSL, should trigger an error and |
| 878 | // should cause verification to fail. |
| 879 | ASSERT_EQ(X509_V_ERR_INVALID_CALL, |
| 880 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 881 | [&test](X509_VERIFY_PARAM *param) { |
| 882 | ASSERT_FALSE(test.func(param, test.correct_value, 0)); |
| 883 | })); |
| 884 | |
| 885 | // Passing an empty value should be an error when setting and should cause |
| 886 | // verification to fail. |
| 887 | ASSERT_EQ(X509_V_ERR_INVALID_CALL, |
| 888 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 889 | [&test](X509_VERIFY_PARAM *param) { |
| 890 | ASSERT_FALSE(test.func(param, nullptr, 0)); |
| 891 | })); |
| 892 | |
| 893 | // Passing a value with embedded NULs should also be an error and should |
| 894 | // also cause verification to fail. |
| 895 | ASSERT_EQ(X509_V_ERR_INVALID_CALL, |
| 896 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 897 | [&test](X509_VERIFY_PARAM *param) { |
| 898 | ASSERT_FALSE(test.func(param, "a", 2)); |
| 899 | })); |
| 900 | } |
| 901 | |
| 902 | // IP addresses work slightly differently: |
| 903 | |
| 904 | // The correct value should still work. |
| 905 | ASSERT_EQ(X509_V_OK, Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, |
| 906 | false, [](X509_VERIFY_PARAM *param) { |
| 907 | ASSERT_TRUE(X509_VERIFY_PARAM_set1_ip( |
| 908 | param, kIP, sizeof(kIP))); |
| 909 | })); |
| 910 | |
| 911 | // Incorrect values should still fail. |
| 912 | ASSERT_EQ(X509_V_ERR_IP_ADDRESS_MISMATCH, |
| 913 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 914 | [](X509_VERIFY_PARAM *param) { |
| 915 | ASSERT_TRUE(X509_VERIFY_PARAM_set1_ip(param, kWrongIP, |
| 916 | sizeof(kWrongIP))); |
| 917 | })); |
| 918 | |
| 919 | // Zero length values should trigger an error when setting and cause |
| 920 | // verification to always fail. |
| 921 | ASSERT_EQ(X509_V_ERR_INVALID_CALL, |
| 922 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 923 | [](X509_VERIFY_PARAM *param) { |
| 924 | ASSERT_FALSE(X509_VERIFY_PARAM_set1_ip(param, kIP, 0)); |
| 925 | })); |
| 926 | |
| 927 | // ... and so should NULL values. |
| 928 | ASSERT_EQ(X509_V_ERR_INVALID_CALL, |
| 929 | Verify(leaf.get(), {root.get()}, {}, empty_crls, 0, false, |
| 930 | [](X509_VERIFY_PARAM *param) { |
| 931 | ASSERT_FALSE(X509_VERIFY_PARAM_set1_ip(param, nullptr, 0)); |
| 932 | })); |
| 933 | |
| 934 | // Zero bytes in an IP address are, of course, fine. This is tested above |
| 935 | // because |kIP| contains zeros. |
| 936 | } |
| 937 | |
| 938 | TEST(X509Test, ZeroLengthsWithCheckFunctions) { |
| 939 | bssl::UniquePtr<X509> leaf(CertFromPEM(kSANTypesLeaf)); |
| 940 | |
| 941 | EXPECT_EQ( |
| 942 | 1, X509_check_host(leaf.get(), kHostname, strlen(kHostname), 0, nullptr)); |
| 943 | EXPECT_NE(1, X509_check_host(leaf.get(), kWrongHostname, |
| 944 | strlen(kWrongHostname), 0, nullptr)); |
| 945 | |
| 946 | EXPECT_EQ(1, X509_check_email(leaf.get(), kEmail, strlen(kEmail), 0)); |
| 947 | EXPECT_NE(1, |
| 948 | X509_check_email(leaf.get(), kWrongEmail, strlen(kWrongEmail), 0)); |
| 949 | |
| 950 | EXPECT_EQ(1, X509_check_ip(leaf.get(), kIP, sizeof(kIP), 0)); |
| 951 | EXPECT_NE(1, X509_check_ip(leaf.get(), kWrongIP, sizeof(kWrongIP), 0)); |
| 952 | |
| 953 | EXPECT_EQ(1, X509_check_ip_asc(leaf.get(), kIPString, 0)); |
| 954 | EXPECT_NE(1, X509_check_ip_asc(leaf.get(), kWrongIPString, 0)); |
| 955 | |
| 956 | // OpenSSL supports passing zero as the length for host and email. We do not |
| 957 | // and it should always fail. |
| 958 | EXPECT_NE(1, X509_check_host(leaf.get(), kHostname, 0, 0, nullptr)); |
| 959 | EXPECT_NE(1, X509_check_host(leaf.get(), kWrongHostname, 0, 0, nullptr)); |
| 960 | |
| 961 | EXPECT_NE(1, X509_check_email(leaf.get(), kEmail, 0, 0)); |
| 962 | EXPECT_NE(1, X509_check_email(leaf.get(), kWrongEmail, 0, 0)); |
| 963 | |
| 964 | EXPECT_NE(1, X509_check_ip(leaf.get(), kIP, 0, 0)); |
| 965 | EXPECT_NE(1, X509_check_ip(leaf.get(), kWrongIP, 0, 0)); |
| 966 | |
| 967 | // Unlike all the other functions, |X509_check_ip_asc| doesn't take a length, |
| 968 | // so it cannot be zero. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 969 | } |
| 970 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 971 | TEST(X509Test, TestCRL) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 972 | bssl::UniquePtr<X509> root(CertFromPEM(kCRLTestRoot)); |
| 973 | bssl::UniquePtr<X509> leaf(CertFromPEM(kCRLTestLeaf)); |
| 974 | bssl::UniquePtr<X509_CRL> basic_crl(CRLFromPEM(kBasicCRL)); |
| 975 | bssl::UniquePtr<X509_CRL> revoked_crl(CRLFromPEM(kRevokedCRL)); |
| 976 | bssl::UniquePtr<X509_CRL> bad_issuer_crl(CRLFromPEM(kBadIssuerCRL)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 977 | bssl::UniquePtr<X509_CRL> known_critical_crl(CRLFromPEM(kKnownCriticalCRL)); |
| 978 | bssl::UniquePtr<X509_CRL> unknown_critical_crl( |
| 979 | CRLFromPEM(kUnknownCriticalCRL)); |
| 980 | bssl::UniquePtr<X509_CRL> unknown_critical_crl2( |
| 981 | CRLFromPEM(kUnknownCriticalCRL2)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 982 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 983 | ASSERT_TRUE(root); |
| 984 | ASSERT_TRUE(leaf); |
| 985 | ASSERT_TRUE(basic_crl); |
| 986 | ASSERT_TRUE(revoked_crl); |
| 987 | ASSERT_TRUE(bad_issuer_crl); |
| 988 | ASSERT_TRUE(known_critical_crl); |
| 989 | ASSERT_TRUE(unknown_critical_crl); |
| 990 | ASSERT_TRUE(unknown_critical_crl2); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 991 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 992 | ASSERT_EQ(X509_V_OK, Verify(leaf.get(), {root.get()}, {root.get()}, |
| 993 | {basic_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 994 | ASSERT_EQ( |
| 995 | X509_V_ERR_CERT_REVOKED, |
| 996 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 997 | {basic_crl.get(), revoked_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 998 | |
| 999 | std::vector<X509_CRL *> empty_crls; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1000 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_CRL, |
| 1001 | Verify(leaf.get(), {root.get()}, {root.get()}, empty_crls, |
| 1002 | X509_V_FLAG_CRL_CHECK)); |
| 1003 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_CRL, |
| 1004 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 1005 | {bad_issuer_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 1006 | ASSERT_EQ(X509_V_OK, |
| 1007 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 1008 | {known_critical_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 1009 | ASSERT_EQ(X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION, |
| 1010 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 1011 | {unknown_critical_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 1012 | ASSERT_EQ(X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION, |
| 1013 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 1014 | {unknown_critical_crl2.get()}, X509_V_FLAG_CRL_CHECK)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 1015 | } |
| 1016 | |
Robert Sloan | 2e9e66a | 2017-09-25 09:08:29 -0700 | [diff] [blame] | 1017 | TEST(X509Test, ManyNamesAndConstraints) { |
| 1018 | bssl::UniquePtr<X509> many_constraints( |
| 1019 | CertFromPEM(GetTestData("crypto/x509/many_constraints.pem").c_str())); |
| 1020 | ASSERT_TRUE(many_constraints); |
| 1021 | bssl::UniquePtr<X509> many_names1( |
| 1022 | CertFromPEM(GetTestData("crypto/x509/many_names1.pem").c_str())); |
| 1023 | ASSERT_TRUE(many_names1); |
| 1024 | bssl::UniquePtr<X509> many_names2( |
| 1025 | CertFromPEM(GetTestData("crypto/x509/many_names2.pem").c_str())); |
| 1026 | ASSERT_TRUE(many_names2); |
| 1027 | bssl::UniquePtr<X509> many_names3( |
| 1028 | CertFromPEM(GetTestData("crypto/x509/many_names3.pem").c_str())); |
| 1029 | ASSERT_TRUE(many_names3); |
| 1030 | bssl::UniquePtr<X509> some_names1( |
| 1031 | CertFromPEM(GetTestData("crypto/x509/some_names1.pem").c_str())); |
| 1032 | ASSERT_TRUE(some_names1); |
| 1033 | bssl::UniquePtr<X509> some_names2( |
| 1034 | CertFromPEM(GetTestData("crypto/x509/some_names2.pem").c_str())); |
| 1035 | ASSERT_TRUE(some_names2); |
| 1036 | bssl::UniquePtr<X509> some_names3( |
| 1037 | CertFromPEM(GetTestData("crypto/x509/some_names3.pem").c_str())); |
| 1038 | ASSERT_TRUE(some_names3); |
| 1039 | |
| 1040 | EXPECT_EQ(X509_V_ERR_UNSPECIFIED, |
| 1041 | Verify(many_names1.get(), {many_constraints.get()}, |
| 1042 | {many_constraints.get()}, {})); |
| 1043 | EXPECT_EQ(X509_V_ERR_UNSPECIFIED, |
| 1044 | Verify(many_names2.get(), {many_constraints.get()}, |
| 1045 | {many_constraints.get()}, {})); |
| 1046 | EXPECT_EQ(X509_V_ERR_UNSPECIFIED, |
| 1047 | Verify(many_names3.get(), {many_constraints.get()}, |
| 1048 | {many_constraints.get()}, {})); |
| 1049 | |
| 1050 | EXPECT_EQ(X509_V_OK, Verify(some_names1.get(), {many_constraints.get()}, |
| 1051 | {many_constraints.get()}, {})); |
| 1052 | EXPECT_EQ(X509_V_OK, Verify(some_names2.get(), {many_constraints.get()}, |
| 1053 | {many_constraints.get()}, {})); |
| 1054 | EXPECT_EQ(X509_V_OK, Verify(some_names3.get(), {many_constraints.get()}, |
| 1055 | {many_constraints.get()}, {})); |
| 1056 | } |
| 1057 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1058 | TEST(X509Test, TestPSS) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1059 | bssl::UniquePtr<X509> cert(CertFromPEM(kExamplePSSCert)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1060 | ASSERT_TRUE(cert); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1061 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1062 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1063 | ASSERT_TRUE(pkey); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1064 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1065 | ASSERT_TRUE(X509_verify(cert.get(), pkey.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1066 | } |
| 1067 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1068 | TEST(X509Test, TestPSSBadParameters) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1069 | bssl::UniquePtr<X509> cert(CertFromPEM(kBadPSSCertPEM)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1070 | ASSERT_TRUE(cert); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1071 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1072 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1073 | ASSERT_TRUE(pkey); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1074 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1075 | ASSERT_FALSE(X509_verify(cert.get(), pkey.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1076 | ERR_clear_error(); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1077 | } |
| 1078 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1079 | TEST(X509Test, TestEd25519) { |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1080 | bssl::UniquePtr<X509> cert(CertFromPEM(kEd25519Cert)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1081 | ASSERT_TRUE(cert); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1082 | |
| 1083 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1084 | ASSERT_TRUE(pkey); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1085 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1086 | ASSERT_TRUE(X509_verify(cert.get(), pkey.get())); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1089 | TEST(X509Test, TestEd25519BadParameters) { |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1090 | bssl::UniquePtr<X509> cert(CertFromPEM(kEd25519CertNull)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1091 | ASSERT_TRUE(cert); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1092 | |
| 1093 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1094 | ASSERT_TRUE(pkey); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1095 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1096 | ASSERT_FALSE(X509_verify(cert.get(), pkey.get())); |
| 1097 | |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1098 | uint32_t err = ERR_get_error(); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1099 | ASSERT_EQ(ERR_LIB_X509, ERR_GET_LIB(err)); |
| 1100 | ASSERT_EQ(X509_R_INVALID_PARAMETER, ERR_GET_REASON(err)); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1101 | ERR_clear_error(); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1104 | static bool SignatureRoundTrips(EVP_MD_CTX *md_ctx, EVP_PKEY *pkey) { |
| 1105 | // Make a certificate like signed with |md_ctx|'s settings.' |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1106 | bssl::UniquePtr<X509> cert(CertFromPEM(kLeafPEM)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1107 | if (!cert || !X509_sign_ctx(cert.get(), md_ctx)) { |
| 1108 | return false; |
| 1109 | } |
| 1110 | |
| 1111 | // Ensure that |pkey| may still be used to verify the resulting signature. All |
| 1112 | // settings in |md_ctx| must have been serialized appropriately. |
| 1113 | return !!X509_verify(cert.get(), pkey); |
| 1114 | } |
| 1115 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1116 | TEST(X509Test, RSASign) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 1117 | bssl::UniquePtr<EVP_PKEY> pkey(PrivateKeyFromPEM(kRSAKey)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1118 | ASSERT_TRUE(pkey); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1119 | // Test PKCS#1 v1.5. |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1120 | bssl::ScopedEVP_MD_CTX md_ctx; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1121 | ASSERT_TRUE( |
| 1122 | EVP_DigestSignInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get())); |
| 1123 | ASSERT_TRUE(SignatureRoundTrips(md_ctx.get(), pkey.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1124 | |
| 1125 | // Test RSA-PSS with custom parameters. |
| 1126 | md_ctx.Reset(); |
| 1127 | EVP_PKEY_CTX *pkey_ctx; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1128 | ASSERT_TRUE(EVP_DigestSignInit(md_ctx.get(), &pkey_ctx, EVP_sha256(), NULL, |
| 1129 | pkey.get())); |
| 1130 | ASSERT_TRUE(EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING)); |
| 1131 | ASSERT_TRUE(EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, EVP_sha512())); |
| 1132 | ASSERT_TRUE(SignatureRoundTrips(md_ctx.get(), pkey.get())); |
| 1133 | } |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1134 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1135 | TEST(X509Test, Ed25519Sign) { |
| 1136 | uint8_t pub_bytes[32], priv_bytes[64]; |
| 1137 | ED25519_keypair(pub_bytes, priv_bytes); |
| 1138 | |
| 1139 | bssl::UniquePtr<EVP_PKEY> pub(EVP_PKEY_new_ed25519_public(pub_bytes)); |
| 1140 | ASSERT_TRUE(pub); |
| 1141 | bssl::UniquePtr<EVP_PKEY> priv(EVP_PKEY_new_ed25519_private(priv_bytes)); |
| 1142 | ASSERT_TRUE(priv); |
| 1143 | |
| 1144 | bssl::ScopedEVP_MD_CTX md_ctx; |
| 1145 | ASSERT_TRUE( |
| 1146 | EVP_DigestSignInit(md_ctx.get(), nullptr, nullptr, nullptr, priv.get())); |
| 1147 | ASSERT_TRUE(SignatureRoundTrips(md_ctx.get(), pub.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1148 | } |
| 1149 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1150 | static bool PEMToDER(bssl::UniquePtr<uint8_t> *out, size_t *out_len, |
| 1151 | const char *pem) { |
| 1152 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(pem, strlen(pem))); |
| 1153 | if (!bio) { |
| 1154 | return false; |
| 1155 | } |
| 1156 | |
| 1157 | char *name, *header; |
| 1158 | uint8_t *data; |
| 1159 | long data_len; |
| 1160 | if (!PEM_read_bio(bio.get(), &name, &header, &data, &data_len)) { |
| 1161 | fprintf(stderr, "failed to read PEM data.\n"); |
| 1162 | return false; |
| 1163 | } |
| 1164 | OPENSSL_free(name); |
| 1165 | OPENSSL_free(header); |
| 1166 | |
| 1167 | out->reset(data); |
| 1168 | *out_len = data_len; |
| 1169 | |
| 1170 | return true; |
| 1171 | } |
| 1172 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1173 | TEST(X509Test, TestFromBuffer) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1174 | size_t data_len; |
| 1175 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1176 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1177 | |
| 1178 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 1179 | CRYPTO_BUFFER_new(data.get(), data_len, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1180 | ASSERT_TRUE(buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1181 | bssl::UniquePtr<X509> root(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1182 | ASSERT_TRUE(root); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1183 | |
| 1184 | const uint8_t *enc_pointer = root->cert_info->enc.enc; |
| 1185 | const uint8_t *buf_pointer = CRYPTO_BUFFER_data(buf.get()); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1186 | ASSERT_GE(enc_pointer, buf_pointer); |
| 1187 | ASSERT_LT(enc_pointer, buf_pointer + CRYPTO_BUFFER_len(buf.get())); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1188 | buf.reset(); |
| 1189 | |
| 1190 | /* This ensures the X509 took a reference to |buf|, otherwise this will be a |
| 1191 | * reference to free memory and ASAN should notice. */ |
Robert Sloan | 0da4395 | 2018-01-03 15:13:14 -0800 | [diff] [blame] | 1192 | ASSERT_EQ(0x30, enc_pointer[0]); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1193 | } |
| 1194 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1195 | TEST(X509Test, TestFromBufferWithTrailingData) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1196 | size_t data_len; |
| 1197 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1198 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1199 | |
| 1200 | 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] | 1201 | OPENSSL_memcpy(trailing_data.get(), data.get(), data_len); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1202 | |
| 1203 | bssl::UniquePtr<CRYPTO_BUFFER> buf_trailing_data( |
| 1204 | CRYPTO_BUFFER_new(trailing_data.get(), data_len + 1, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1205 | ASSERT_TRUE(buf_trailing_data); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1206 | |
| 1207 | bssl::UniquePtr<X509> root_trailing_data( |
| 1208 | X509_parse_from_buffer(buf_trailing_data.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1209 | ASSERT_FALSE(root_trailing_data); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1210 | } |
| 1211 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1212 | TEST(X509Test, TestFromBufferModified) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1213 | size_t data_len; |
| 1214 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1215 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1216 | |
| 1217 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 1218 | CRYPTO_BUFFER_new(data.get(), data_len, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1219 | ASSERT_TRUE(buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1220 | |
| 1221 | bssl::UniquePtr<X509> root(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1222 | ASSERT_TRUE(root); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1223 | |
| 1224 | bssl::UniquePtr<ASN1_INTEGER> fourty_two(ASN1_INTEGER_new()); |
| 1225 | ASN1_INTEGER_set(fourty_two.get(), 42); |
| 1226 | X509_set_serialNumber(root.get(), fourty_two.get()); |
| 1227 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1228 | ASSERT_EQ(static_cast<long>(data_len), i2d_X509(root.get(), nullptr)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1229 | |
| 1230 | X509_CINF_set_modified(root->cert_info); |
| 1231 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1232 | ASSERT_NE(static_cast<long>(data_len), i2d_X509(root.get(), nullptr)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1233 | } |
| 1234 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1235 | TEST(X509Test, TestFromBufferReused) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1236 | size_t data_len; |
| 1237 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1238 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1239 | |
| 1240 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 1241 | CRYPTO_BUFFER_new(data.get(), data_len, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1242 | ASSERT_TRUE(buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1243 | |
| 1244 | bssl::UniquePtr<X509> root(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1245 | ASSERT_TRUE(root); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1246 | |
| 1247 | size_t data2_len; |
| 1248 | bssl::UniquePtr<uint8_t> data2; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1249 | ASSERT_TRUE(PEMToDER(&data2, &data2_len, kLeafPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1250 | |
| 1251 | X509 *x509p = root.get(); |
| 1252 | const uint8_t *inp = data2.get(); |
| 1253 | X509 *ret = d2i_X509(&x509p, &inp, data2_len); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1254 | ASSERT_EQ(root.get(), ret); |
| 1255 | ASSERT_EQ(nullptr, root->buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1256 | |
| 1257 | // Free |data2| and ensure that |root| took its own copy. Otherwise the |
| 1258 | // following will trigger a use-after-free. |
| 1259 | data2.reset(); |
| 1260 | |
| 1261 | uint8_t *i2d = nullptr; |
| 1262 | int i2d_len = i2d_X509(root.get(), &i2d); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1263 | ASSERT_GE(i2d_len, 0); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1264 | bssl::UniquePtr<uint8_t> i2d_storage(i2d); |
| 1265 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1266 | ASSERT_TRUE(PEMToDER(&data2, &data2_len, kLeafPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1267 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1268 | ASSERT_EQ(static_cast<long>(data2_len), i2d_len); |
| 1269 | ASSERT_EQ(0, OPENSSL_memcmp(data2.get(), i2d, i2d_len)); |
| 1270 | ASSERT_EQ(nullptr, root->buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 1271 | } |
| 1272 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1273 | TEST(X509Test, TestFailedParseFromBuffer) { |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1274 | static const uint8_t kNonsense[] = {1, 2, 3, 4, 5}; |
| 1275 | |
| 1276 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 1277 | CRYPTO_BUFFER_new(kNonsense, sizeof(kNonsense), nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1278 | ASSERT_TRUE(buf); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1279 | |
| 1280 | bssl::UniquePtr<X509> cert(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1281 | ASSERT_FALSE(cert); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1282 | ERR_clear_error(); |
| 1283 | |
| 1284 | // Test a buffer with trailing data. |
| 1285 | size_t data_len; |
| 1286 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1287 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1288 | |
| 1289 | 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] | 1290 | OPENSSL_memcpy(data_with_trailing_byte.get(), data.get(), data_len); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1291 | data_with_trailing_byte[data_len] = 0; |
| 1292 | |
| 1293 | bssl::UniquePtr<CRYPTO_BUFFER> buf_with_trailing_byte( |
| 1294 | CRYPTO_BUFFER_new(data_with_trailing_byte.get(), data_len + 1, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1295 | ASSERT_TRUE(buf_with_trailing_byte); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1296 | |
| 1297 | bssl::UniquePtr<X509> root( |
| 1298 | X509_parse_from_buffer(buf_with_trailing_byte.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1299 | ASSERT_FALSE(root); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1300 | ERR_clear_error(); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 1301 | } |
| 1302 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1303 | TEST(X509Test, TestPrintUTCTIME) { |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 1304 | static const struct { |
| 1305 | const char *val, *want; |
| 1306 | } asn1_utctime_tests[] = { |
| 1307 | {"", "Bad time value"}, |
| 1308 | |
| 1309 | // Correct RFC 5280 form. Test years < 2000 and > 2000. |
| 1310 | {"090303125425Z", "Mar 3 12:54:25 2009 GMT"}, |
| 1311 | {"900303125425Z", "Mar 3 12:54:25 1990 GMT"}, |
| 1312 | {"000303125425Z", "Mar 3 12:54:25 2000 GMT"}, |
| 1313 | |
| 1314 | // Correct form, bad values. |
| 1315 | {"000000000000Z", "Bad time value"}, |
| 1316 | {"999999999999Z", "Bad time value"}, |
| 1317 | |
| 1318 | // Missing components. Not legal RFC 5280, but permitted. |
| 1319 | {"090303125425", "Mar 3 12:54:25 2009"}, |
| 1320 | {"9003031254", "Mar 3 12:54:00 1990"}, |
| 1321 | {"9003031254Z", "Mar 3 12:54:00 1990 GMT"}, |
| 1322 | |
| 1323 | // GENERALIZEDTIME confused for UTCTIME. |
| 1324 | {"20090303125425Z", "Bad time value"}, |
| 1325 | |
| 1326 | // Legal ASN.1, but not legal RFC 5280. |
| 1327 | {"9003031254+0800", "Bad time value"}, |
| 1328 | {"9003031254-0800", "Bad time value"}, |
| 1329 | |
| 1330 | // Trailing garbage. |
| 1331 | {"9003031254Z ", "Bad time value"}, |
| 1332 | }; |
| 1333 | |
| 1334 | for (auto t : asn1_utctime_tests) { |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1335 | SCOPED_TRACE(t.val); |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 1336 | bssl::UniquePtr<ASN1_UTCTIME> tm(ASN1_UTCTIME_new()); |
| 1337 | bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem())); |
| 1338 | |
| 1339 | // Use this instead of ASN1_UTCTIME_set() because some callers get |
| 1340 | // type-confused and pass ASN1_GENERALIZEDTIME to ASN1_UTCTIME_print(). |
| 1341 | // ASN1_UTCTIME_set_string() is stricter, and would reject the inputs in |
| 1342 | // question. |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1343 | ASSERT_TRUE(ASN1_STRING_set(tm.get(), t.val, strlen(t.val))); |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 1344 | const int ok = ASN1_UTCTIME_print(bio.get(), tm.get()); |
| 1345 | |
| 1346 | const uint8_t *contents; |
| 1347 | size_t len; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 1348 | ASSERT_TRUE(BIO_mem_contents(bio.get(), &contents, &len)); |
| 1349 | EXPECT_EQ(ok, (strcmp(t.want, "Bad time value") != 0) ? 1 : 0); |
| 1350 | EXPECT_EQ(t.want, |
| 1351 | std::string(reinterpret_cast<const char *>(contents), len)); |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 1352 | } |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 1353 | } |
Robert Sloan | a815d5a | 2017-12-04 11:49:16 -0800 | [diff] [blame] | 1354 | |
| 1355 | TEST(X509Test, PrettyPrintIntegers) { |
| 1356 | static const char *kTests[] = { |
| 1357 | // Small numbers are pretty-printed in decimal. |
| 1358 | "0", |
| 1359 | "-1", |
| 1360 | "1", |
| 1361 | "42", |
| 1362 | "-42", |
| 1363 | "256", |
| 1364 | "-256", |
| 1365 | // Large numbers are pretty-printed in hex to avoid taking quadratic time. |
| 1366 | "0x0123456789", |
| 1367 | "-0x0123456789", |
| 1368 | }; |
| 1369 | for (const char *in : kTests) { |
| 1370 | SCOPED_TRACE(in); |
| 1371 | BIGNUM *bn = nullptr; |
| 1372 | ASSERT_TRUE(BN_asc2bn(&bn, in)); |
| 1373 | bssl::UniquePtr<BIGNUM> free_bn(bn); |
| 1374 | |
| 1375 | { |
| 1376 | bssl::UniquePtr<ASN1_INTEGER> asn1(BN_to_ASN1_INTEGER(bn, nullptr)); |
| 1377 | ASSERT_TRUE(asn1); |
| 1378 | bssl::UniquePtr<char> out(i2s_ASN1_INTEGER(nullptr, asn1.get())); |
| 1379 | ASSERT_TRUE(out.get()); |
| 1380 | EXPECT_STREQ(in, out.get()); |
| 1381 | } |
| 1382 | |
| 1383 | { |
| 1384 | bssl::UniquePtr<ASN1_ENUMERATED> asn1(BN_to_ASN1_ENUMERATED(bn, nullptr)); |
| 1385 | ASSERT_TRUE(asn1); |
| 1386 | bssl::UniquePtr<char> out(i2s_ASN1_ENUMERATED(nullptr, asn1.get())); |
| 1387 | ASSERT_TRUE(out.get()); |
| 1388 | EXPECT_STREQ(in, out.get()); |
| 1389 | } |
| 1390 | } |
| 1391 | } |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 1392 | |
| 1393 | TEST(X509Test, X509NameSet) { |
| 1394 | bssl::UniquePtr<X509_NAME> name(X509_NAME_new()); |
| 1395 | EXPECT_TRUE(X509_NAME_add_entry_by_txt( |
| 1396 | name.get(), "C", MBSTRING_ASC, reinterpret_cast<const uint8_t *>("US"), |
| 1397 | -1, -1, 0)); |
| 1398 | EXPECT_EQ(X509_NAME_entry_count(name.get()), 1); |
| 1399 | EXPECT_TRUE(X509_NAME_add_entry_by_txt( |
| 1400 | name.get(), "C", MBSTRING_ASC, reinterpret_cast<const uint8_t *>("CA"), |
| 1401 | -1, -1, 0)); |
| 1402 | EXPECT_EQ(X509_NAME_entry_count(name.get()), 2); |
| 1403 | EXPECT_TRUE(X509_NAME_add_entry_by_txt( |
| 1404 | name.get(), "C", MBSTRING_ASC, reinterpret_cast<const uint8_t *>("UK"), |
| 1405 | -1, -1, 0)); |
| 1406 | EXPECT_EQ(X509_NAME_entry_count(name.get()), 3); |
| 1407 | EXPECT_TRUE(X509_NAME_add_entry_by_txt( |
| 1408 | name.get(), "C", MBSTRING_ASC, reinterpret_cast<const uint8_t *>("JP"), |
| 1409 | -1, 1, 0)); |
| 1410 | EXPECT_EQ(X509_NAME_entry_count(name.get()), 4); |
| 1411 | |
| 1412 | // Check that the correct entries get incremented when inserting new entry. |
| 1413 | EXPECT_EQ(X509_NAME_ENTRY_set(X509_NAME_get_entry(name.get(), 1)), 1); |
| 1414 | EXPECT_EQ(X509_NAME_ENTRY_set(X509_NAME_get_entry(name.get(), 2)), 2); |
| 1415 | } |
| 1416 | |
| 1417 | TEST(X509Test, StringDecoding) { |
| 1418 | static const struct { |
| 1419 | std::vector<uint8_t> in; |
| 1420 | int type; |
| 1421 | const char *expected; |
| 1422 | } kTests[] = { |
| 1423 | // Non-minimal, two-byte UTF-8. |
| 1424 | {{0xc0, 0x81}, V_ASN1_UTF8STRING, nullptr}, |
| 1425 | // Non-minimal, three-byte UTF-8. |
| 1426 | {{0xe0, 0x80, 0x81}, V_ASN1_UTF8STRING, nullptr}, |
| 1427 | // Non-minimal, four-byte UTF-8. |
| 1428 | {{0xf0, 0x80, 0x80, 0x81}, V_ASN1_UTF8STRING, nullptr}, |
| 1429 | // Truncated, four-byte UTF-8. |
| 1430 | {{0xf0, 0x80, 0x80}, V_ASN1_UTF8STRING, nullptr}, |
| 1431 | // Low-surrogate value. |
| 1432 | {{0xed, 0xa0, 0x80}, V_ASN1_UTF8STRING, nullptr}, |
| 1433 | // High-surrogate value. |
| 1434 | {{0xed, 0xb0, 0x81}, V_ASN1_UTF8STRING, nullptr}, |
| 1435 | // Initial BOMs should be rejected from UCS-2 and UCS-4. |
| 1436 | {{0xfe, 0xff, 0, 88}, V_ASN1_BMPSTRING, nullptr}, |
| 1437 | {{0, 0, 0xfe, 0xff, 0, 0, 0, 88}, V_ASN1_UNIVERSALSTRING, nullptr}, |
| 1438 | // Otherwise, BOMs should pass through. |
| 1439 | {{0, 88, 0xfe, 0xff}, V_ASN1_BMPSTRING, "X\xef\xbb\xbf"}, |
| 1440 | {{0, 0, 0, 88, 0, 0, 0xfe, 0xff}, V_ASN1_UNIVERSALSTRING, |
| 1441 | "X\xef\xbb\xbf"}, |
| 1442 | // The maximum code-point should pass though. |
| 1443 | {{0, 16, 0xff, 0xfd}, V_ASN1_UNIVERSALSTRING, "\xf4\x8f\xbf\xbd"}, |
| 1444 | // Values outside the Unicode space should not. |
| 1445 | {{0, 17, 0, 0}, V_ASN1_UNIVERSALSTRING, nullptr}, |
| 1446 | // Non-characters should be rejected. |
| 1447 | {{0, 1, 0xff, 0xff}, V_ASN1_UNIVERSALSTRING, nullptr}, |
| 1448 | {{0, 1, 0xff, 0xfe}, V_ASN1_UNIVERSALSTRING, nullptr}, |
| 1449 | {{0, 0, 0xfd, 0xd5}, V_ASN1_UNIVERSALSTRING, nullptr}, |
| 1450 | // BMPString is UCS-2, not UTF-16, so surrogate pairs are invalid. |
| 1451 | {{0xd8, 0, 0xdc, 1}, V_ASN1_BMPSTRING, nullptr}, |
| 1452 | }; |
| 1453 | |
| 1454 | for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kTests); i++) { |
| 1455 | SCOPED_TRACE(i); |
| 1456 | const auto& test = kTests[i]; |
| 1457 | ASN1_STRING s; |
| 1458 | s.type = test.type; |
| 1459 | s.data = const_cast<uint8_t*>(test.in.data()); |
| 1460 | s.length = test.in.size(); |
| 1461 | |
| 1462 | uint8_t *utf8; |
| 1463 | const int utf8_len = ASN1_STRING_to_UTF8(&utf8, &s); |
| 1464 | EXPECT_EQ(utf8_len < 0, test.expected == nullptr); |
| 1465 | if (utf8_len >= 0) { |
| 1466 | if (test.expected != nullptr) { |
| 1467 | EXPECT_EQ(Bytes(test.expected), Bytes(utf8, utf8_len)); |
| 1468 | } |
| 1469 | OPENSSL_free(utf8); |
| 1470 | } else { |
| 1471 | ERR_clear_error(); |
| 1472 | } |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | TEST(X509Test, NoBasicConstraintsCertSign) { |
| 1477 | bssl::UniquePtr<X509> root(CertFromPEM(kSANTypesRoot)); |
| 1478 | bssl::UniquePtr<X509> intermediate( |
| 1479 | CertFromPEM(kNoBasicConstraintsCertSignIntermediate)); |
| 1480 | bssl::UniquePtr<X509> leaf(CertFromPEM(kNoBasicConstraintsCertSignLeaf)); |
| 1481 | |
| 1482 | ASSERT_TRUE(root); |
| 1483 | ASSERT_TRUE(intermediate); |
| 1484 | ASSERT_TRUE(leaf); |
| 1485 | |
| 1486 | // The intermediate has keyUsage certSign, but is not marked as a CA in the |
| 1487 | // basicConstraints. |
| 1488 | EXPECT_EQ(X509_V_ERR_INVALID_CA, |
| 1489 | Verify(leaf.get(), {root.get()}, {intermediate.get()}, {}, 0)); |
| 1490 | } |
| 1491 | |
| 1492 | TEST(X509Test, NoBasicConstraintsNetscapeCA) { |
| 1493 | bssl::UniquePtr<X509> root(CertFromPEM(kSANTypesRoot)); |
| 1494 | bssl::UniquePtr<X509> intermediate( |
| 1495 | CertFromPEM(kNoBasicConstraintsNetscapeCAIntermediate)); |
| 1496 | bssl::UniquePtr<X509> leaf(CertFromPEM(kNoBasicConstraintsNetscapeCALeaf)); |
| 1497 | |
| 1498 | ASSERT_TRUE(root); |
| 1499 | ASSERT_TRUE(intermediate); |
| 1500 | ASSERT_TRUE(leaf); |
| 1501 | |
| 1502 | // The intermediate has a Netscape certificate type of "SSL CA", but is not |
| 1503 | // marked as a CA in the basicConstraints. |
| 1504 | EXPECT_EQ(X509_V_ERR_INVALID_CA, |
| 1505 | Verify(leaf.get(), {root.get()}, {intermediate.get()}, {}, 0)); |
| 1506 | } |