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 | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 15 | #include <string> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 18 | #include <gtest/gtest.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 19 | |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 20 | #include <openssl/bio.h> |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 21 | #include <openssl/bytestring.h> |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 22 | #include <openssl/curve25519.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 23 | #include <openssl/crypto.h> |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 24 | #include <openssl/digest.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 25 | #include <openssl/err.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 26 | #include <openssl/pem.h> |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 27 | #include <openssl/pool.h> |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 28 | #include <openssl/x509.h> |
| 29 | |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 30 | #include "../internal.h" |
| 31 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 32 | |
| 33 | static const char kCrossSigningRootPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 34 | "-----BEGIN CERTIFICATE-----\n" |
| 35 | "MIICcTCCAdqgAwIBAgIIagJHiPvE0MowDQYJKoZIhvcNAQELBQAwPDEaMBgGA1UE\n" |
| 36 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxHjAcBgNVBAMTFUNyb3NzLXNpZ25pbmcgUm9v\n" |
| 37 | "dCBDQTAgFw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAwMFowPDEaMBgGA1UE\n" |
| 38 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxHjAcBgNVBAMTFUNyb3NzLXNpZ25pbmcgUm9v\n" |
| 39 | "dCBDQTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwo3qFvSB9Zmlbpzn9wJp\n" |
| 40 | "ikI75Rxkatez8VkLqyxbOhPYl2Haz8F5p1gDG96dCI6jcLGgu3AKT9uhEQyyUko5\n" |
| 41 | "EKYasazSeA9CQrdyhPg0mkTYVETnPM1W/ebid1YtqQbq1CMWlq2aTDoSGAReGFKP\n" |
| 42 | "RTdXAbuAXzpCfi/d8LqV13UCAwEAAaN6MHgwDgYDVR0PAQH/BAQDAgIEMB0GA1Ud\n" |
| 43 | "JQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAPBgNVHRMBAf8EBTADAQH/MBkGA1Ud\n" |
| 44 | "DgQSBBBHKHC7V3Z/3oLvEZx0RZRwMBsGA1UdIwQUMBKAEEcocLtXdn/egu8RnHRF\n" |
| 45 | "lHAwDQYJKoZIhvcNAQELBQADgYEAnglibsy6mGtpIXivtlcz4zIEnHw/lNW+r/eC\n" |
| 46 | "CY7evZTmOoOuC/x9SS3MF9vawt1HFUummWM6ZgErqVBOXIB4//ykrcCgf5ZbF5Hr\n" |
| 47 | "+3EFprKhBqYiXdD8hpBkrBoXwn85LPYWNd2TceCrx0YtLIprE2R5MB2RIq8y4Jk3\n" |
| 48 | "YFXvkME=\n" |
| 49 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 50 | |
| 51 | static const char kRootCAPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 52 | "-----BEGIN CERTIFICATE-----\n" |
| 53 | "MIICVTCCAb6gAwIBAgIIAj5CwoHlWuYwDQYJKoZIhvcNAQELBQAwLjEaMBgGA1UE\n" |
| 54 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxEDAOBgNVBAMTB1Jvb3QgQ0EwIBcNMTUwMTAx\n" |
| 55 | "MDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMC4xGjAYBgNVBAoTEUJvcmluZ1NTTCBU\n" |
| 56 | "RVNUSU5HMRAwDgYDVQQDEwdSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n" |
| 57 | "iQKBgQDpDn8RDOZa5oaDcPZRBy4CeBH1siSSOO4mYgLHlPE+oXdqwI/VImi2XeJM\n" |
| 58 | "2uCFETXCknJJjYG0iJdrt/yyRFvZTQZw+QzGj+mz36NqhGxDWb6dstB2m8PX+plZ\n" |
| 59 | "w7jl81MDvUnWs8yiQ/6twgu5AbhWKZQDJKcNKCEpqa6UW0r5nwIDAQABo3oweDAO\n" |
| 60 | "BgNVHQ8BAf8EBAMCAgQwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMA8G\n" |
| 61 | "A1UdEwEB/wQFMAMBAf8wGQYDVR0OBBIEEEA31wH7QC+4HH5UBCeMWQEwGwYDVR0j\n" |
| 62 | "BBQwEoAQQDfXAftAL7gcflQEJ4xZATANBgkqhkiG9w0BAQsFAAOBgQDXylEK77Za\n" |
| 63 | "kKeY6ZerrScWyZhrjIGtHFu09qVpdJEzrk87k2G7iHHR9CAvSofCgEExKtWNS9dN\n" |
| 64 | "+9WiZp/U48iHLk7qaYXdEuO07No4BYtXn+lkOykE+FUxmA4wvOF1cTd2tdj3MzX2\n" |
| 65 | "kfGIBAYhzGZWhY3JbhIfTEfY1PNM1pWChQ==\n" |
| 66 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 67 | |
| 68 | static const char kRootCrossSignedPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 69 | "-----BEGIN CERTIFICATE-----\n" |
| 70 | "MIICYzCCAcygAwIBAgIIAj5CwoHlWuYwDQYJKoZIhvcNAQELBQAwPDEaMBgGA1UE\n" |
| 71 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxHjAcBgNVBAMTFUNyb3NzLXNpZ25pbmcgUm9v\n" |
| 72 | "dCBDQTAgFw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAwMFowLjEaMBgGA1UE\n" |
| 73 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxEDAOBgNVBAMTB1Jvb3QgQ0EwgZ8wDQYJKoZI\n" |
| 74 | "hvcNAQEBBQADgY0AMIGJAoGBAOkOfxEM5lrmhoNw9lEHLgJ4EfWyJJI47iZiAseU\n" |
| 75 | "8T6hd2rAj9UiaLZd4kza4IURNcKSckmNgbSIl2u3/LJEW9lNBnD5DMaP6bPfo2qE\n" |
| 76 | "bENZvp2y0Habw9f6mVnDuOXzUwO9SdazzKJD/q3CC7kBuFYplAMkpw0oISmprpRb\n" |
| 77 | "SvmfAgMBAAGjejB4MA4GA1UdDwEB/wQEAwICBDAdBgNVHSUEFjAUBggrBgEFBQcD\n" |
| 78 | "AQYIKwYBBQUHAwIwDwYDVR0TAQH/BAUwAwEB/zAZBgNVHQ4EEgQQQDfXAftAL7gc\n" |
| 79 | "flQEJ4xZATAbBgNVHSMEFDASgBBHKHC7V3Z/3oLvEZx0RZRwMA0GCSqGSIb3DQEB\n" |
| 80 | "CwUAA4GBAErTxYJ0en9HVRHAAr5OO5wuk5Iq3VMc79TMyQLCXVL8YH8Uk7KEwv+q\n" |
| 81 | "9MEKZv2eR/Vfm4HlXlUuIqfgUXbwrAYC/YVVX86Wnbpy/jc73NYVCq8FEZeO+0XU\n" |
| 82 | "90SWAPDdp+iL7aZdimnMtG1qlM1edmz8AKbrhN/R3IbA2CL0nCWV\n" |
| 83 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 84 | |
| 85 | static const char kIntermediatePEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 86 | "-----BEGIN CERTIFICATE-----\n" |
| 87 | "MIICXjCCAcegAwIBAgIJAKJMH+7rscPcMA0GCSqGSIb3DQEBCwUAMC4xGjAYBgNV\n" |
| 88 | "BAoTEUJvcmluZ1NTTCBURVNUSU5HMRAwDgYDVQQDEwdSb290IENBMCAXDTE1MDEw\n" |
| 89 | "MTAwMDAwMFoYDzIxMDAwMTAxMDAwMDAwWjA2MRowGAYDVQQKExFCb3JpbmdTU0wg\n" |
| 90 | "VEVTVElORzEYMBYGA1UEAxMPSW50ZXJtZWRpYXRlIENBMIGfMA0GCSqGSIb3DQEB\n" |
| 91 | "AQUAA4GNADCBiQKBgQC7YtI0l8ocTYJ0gKyXTtPL4iMJCNY4OcxXl48jkncVG1Hl\n" |
| 92 | "blicgNUa1r9m9YFtVkxvBinb8dXiUpEGhVg4awRPDcatlsBSEBuJkiZGYbRcAmSu\n" |
| 93 | "CmZYnf6u3aYQ18SU8WqVERPpE4cwVVs+6kwlzRw0+XDoZAczu8ZezVhCUc6NbQID\n" |
| 94 | "AQABo3oweDAOBgNVHQ8BAf8EBAMCAgQwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsG\n" |
| 95 | "AQUFBwMCMA8GA1UdEwEB/wQFMAMBAf8wGQYDVR0OBBIEEIwaaKi1dttdV3sfjRSy\n" |
| 96 | "BqMwGwYDVR0jBBQwEoAQQDfXAftAL7gcflQEJ4xZATANBgkqhkiG9w0BAQsFAAOB\n" |
| 97 | "gQCvnolNWEHuQS8PFVVyuLR+FKBeUUdrVbSfHSzTqNAqQGp0C9fk5oCzDq6ZgTfY\n" |
| 98 | "ESXM4cJhb3IAnW0UM0NFsYSKQJ50JZL2L3z5ZLQhHdbs4RmODGoC40BVdnJ4/qgB\n" |
| 99 | "aGSh09eQRvAVmbVCviDK2ipkWNegdyI19jFfNP5uIkGlYg==\n" |
| 100 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 101 | |
| 102 | static const char kIntermediateSelfSignedPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 103 | "-----BEGIN CERTIFICATE-----\n" |
| 104 | "MIICZjCCAc+gAwIBAgIJAKJMH+7rscPcMA0GCSqGSIb3DQEBCwUAMDYxGjAYBgNV\n" |
| 105 | "BAoTEUJvcmluZ1NTTCBURVNUSU5HMRgwFgYDVQQDEw9JbnRlcm1lZGlhdGUgQ0Ew\n" |
| 106 | "IBcNMTUwMTAxMDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMDYxGjAYBgNVBAoTEUJv\n" |
| 107 | "cmluZ1NTTCBURVNUSU5HMRgwFgYDVQQDEw9JbnRlcm1lZGlhdGUgQ0EwgZ8wDQYJ\n" |
| 108 | "KoZIhvcNAQEBBQADgY0AMIGJAoGBALti0jSXyhxNgnSArJdO08viIwkI1jg5zFeX\n" |
| 109 | "jyOSdxUbUeVuWJyA1RrWv2b1gW1WTG8GKdvx1eJSkQaFWDhrBE8Nxq2WwFIQG4mS\n" |
| 110 | "JkZhtFwCZK4KZlid/q7dphDXxJTxapURE+kThzBVWz7qTCXNHDT5cOhkBzO7xl7N\n" |
| 111 | "WEJRzo1tAgMBAAGjejB4MA4GA1UdDwEB/wQEAwICBDAdBgNVHSUEFjAUBggrBgEF\n" |
| 112 | "BQcDAQYIKwYBBQUHAwIwDwYDVR0TAQH/BAUwAwEB/zAZBgNVHQ4EEgQQjBpoqLV2\n" |
| 113 | "211Xex+NFLIGozAbBgNVHSMEFDASgBCMGmiotXbbXVd7H40UsgajMA0GCSqGSIb3\n" |
| 114 | "DQEBCwUAA4GBALcccSrAQ0/EqQBsx0ZDTUydHXXNP2DrUkpUKmAXIe8McqIVSlkT\n" |
| 115 | "6H4xz7z8VRKBo9j+drjjtCw2i0CQc8aOLxRb5WJ8eVLnaW2XRlUqAzhF0CrulfVI\n" |
| 116 | "E4Vs6ZLU+fra1WAuIj6qFiigRja+3YkZArG8tMA9vtlhTX/g7YBZIkqH\n" |
| 117 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 118 | |
| 119 | static const char kLeafPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 120 | "-----BEGIN CERTIFICATE-----\n" |
| 121 | "MIICXjCCAcegAwIBAgIIWjO48ufpunYwDQYJKoZIhvcNAQELBQAwNjEaMBgGA1UE\n" |
| 122 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxGDAWBgNVBAMTD0ludGVybWVkaWF0ZSBDQTAg\n" |
| 123 | "Fw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAwMFowMjEaMBgGA1UEChMRQm9y\n" |
| 124 | "aW5nU1NMIFRFU1RJTkcxFDASBgNVBAMTC2V4YW1wbGUuY29tMIGfMA0GCSqGSIb3\n" |
| 125 | "DQEBAQUAA4GNADCBiQKBgQDD0U0ZYgqShJ7oOjsyNKyVXEHqeafmk/bAoPqY/h1c\n" |
| 126 | "oPw2E8KmeqiUSoTPjG5IXSblOxcqpbAXgnjPzo8DI3GNMhAf8SYNYsoH7gc7Uy7j\n" |
| 127 | "5x8bUrisGnuTHqkqH6d4/e7ETJ7i3CpR8bvK16DggEvQTudLipz8FBHtYhFakfdh\n" |
| 128 | "TwIDAQABo3cwdTAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEG\n" |
| 129 | "CCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwGQYDVR0OBBIEEKN5pvbur7mlXjeMEYA0\n" |
| 130 | "4nUwGwYDVR0jBBQwEoAQjBpoqLV2211Xex+NFLIGozANBgkqhkiG9w0BAQsFAAOB\n" |
| 131 | "gQBj/p+JChp//LnXWC1k121LM/ii7hFzQzMrt70bny406SGz9jAjaPOX4S3gt38y\n" |
| 132 | "rhjpPukBlSzgQXFg66y6q5qp1nQTD1Cw6NkKBe9WuBlY3iYfmsf7WT8nhlT1CttU\n" |
| 133 | "xNCwyMX9mtdXdQicOfNjIGUCD5OLV5PgHFPRKiHHioBAhg==\n" |
| 134 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 135 | |
| 136 | static const char kLeafNoKeyUsagePEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 137 | "-----BEGIN CERTIFICATE-----\n" |
| 138 | "MIICNTCCAZ6gAwIBAgIJAIFQGaLQ0G2mMA0GCSqGSIb3DQEBCwUAMDYxGjAYBgNV\n" |
| 139 | "BAoTEUJvcmluZ1NTTCBURVNUSU5HMRgwFgYDVQQDEw9JbnRlcm1lZGlhdGUgQ0Ew\n" |
| 140 | "IBcNMTUwMTAxMDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMDcxGjAYBgNVBAoTEUJv\n" |
| 141 | "cmluZ1NTTCBURVNUSU5HMRkwFwYDVQQDExBldmlsLmV4YW1wbGUuY29tMIGfMA0G\n" |
| 142 | "CSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOKoZe75NPz77EOaMMl4/0s3PyQw++zJvp\n" |
| 143 | "ejHAxZiTPCJgMbEHLrSzNoHdopg+CLUH5bE4wTXM8w9Inv5P8OAFJt7gJuPUunmk\n" |
| 144 | "j+NoU3QfzOR6BroePcz1vXX9jyVHRs087M/sLqWRHu9IR+/A+UTcBaWaFiDVUxtJ\n" |
| 145 | "YOwFMwjNPQIDAQABo0gwRjAMBgNVHRMBAf8EAjAAMBkGA1UdDgQSBBBJfLEUWHq1\n" |
| 146 | "27rZ1AVx2J5GMBsGA1UdIwQUMBKAEIwaaKi1dttdV3sfjRSyBqMwDQYJKoZIhvcN\n" |
| 147 | "AQELBQADgYEALVKN2Y3LZJOtu6SxFIYKxbLaXhTGTdIjxipZhmbBRDFjbZjZZOTe\n" |
| 148 | "6Oo+VDNPYco4rBexK7umYXJyfTqoY0E8dbiImhTcGTEj7OAB3DbBomgU1AYe+t2D\n" |
| 149 | "uwBqh4Y3Eto+Zn4pMVsxGEfUpjzjZDel7bN1/oU/9KWPpDfywfUmjgk=\n" |
| 150 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 151 | |
| 152 | static const char kForgeryPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 153 | "-----BEGIN CERTIFICATE-----\n" |
| 154 | "MIICZzCCAdCgAwIBAgIIdTlMzQoKkeMwDQYJKoZIhvcNAQELBQAwNzEaMBgGA1UE\n" |
| 155 | "ChMRQm9yaW5nU1NMIFRFU1RJTkcxGTAXBgNVBAMTEGV2aWwuZXhhbXBsZS5jb20w\n" |
| 156 | "IBcNMTUwMTAxMDAwMDAwWhgPMjEwMDAxMDEwMDAwMDBaMDoxGjAYBgNVBAoTEUJv\n" |
| 157 | "cmluZ1NTTCBURVNUSU5HMRwwGgYDVQQDExNmb3JnZXJ5LmV4YW1wbGUuY29tMIGf\n" |
| 158 | "MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDADTwruBQZGb7Ay6s9HiYv5d1lwtEy\n" |
| 159 | "xQdA2Sy8Rn8uA20Q4KgqwVY7wzIZ+z5Butrsmwb70gdG1XU+yRaDeE7XVoW6jSpm\n" |
| 160 | "0sw35/5vJbTcL4THEFbnX0OPZnvpuZDFUkvVtq5kxpDWsVyM24G8EEq7kPih3Sa3\n" |
| 161 | "OMhXVXF8kso6UQIDAQABo3cwdTAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYI\n" |
| 162 | "KwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwGQYDVR0OBBIEEEYJ/WHM\n" |
| 163 | "8p64erPWIg4/liwwGwYDVR0jBBQwEoAQSXyxFFh6tdu62dQFcdieRjANBgkqhkiG\n" |
| 164 | "9w0BAQsFAAOBgQA+zH7bHPElWRWJvjxDqRexmYLn+D3Aivs8XgXQJsM94W0EzSUf\n" |
| 165 | "DSLfRgaQwcb2gg2xpDFoG+W0vc6O651uF23WGt5JaFFJJxqjII05IexfCNhuPmp4\n" |
| 166 | "4UZAXPttuJXpn74IY1tuouaM06B3vXKZR+/ityKmfJvSwxacmFcK+2ziAg==\n" |
| 167 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 168 | |
| 169 | // kExamplePSSCert is an example RSA-PSS self-signed certificate, signed with |
| 170 | // the default hash functions. |
| 171 | static const char kExamplePSSCert[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 172 | "-----BEGIN CERTIFICATE-----\n" |
| 173 | "MIICYjCCAcagAwIBAgIJAI3qUyT6SIfzMBIGCSqGSIb3DQEBCjAFogMCAWowRTEL\n" |
| 174 | "MAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVy\n" |
| 175 | "bmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0xNDEwMDkxOTA5NTVaFw0xNTEwMDkxOTA5\n" |
| 176 | "NTVaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQK\n" |
| 177 | "DBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwgZ8wDQYJKoZIhvcNAQEBBQADgY0A\n" |
| 178 | "MIGJAoGBAPi4bIO0vNmoV8CltFl2jFQdeesiUgR+0zfrQf2D+fCmhRU0dXFahKg8\n" |
| 179 | "0u9aTtPel4rd/7vPCqqGkr64UOTNb4AzMHYTj8p73OxaymPHAyXvqIqDWHYg+hZ3\n" |
| 180 | "13mSYwFIGth7Z/FSVUlO1m5KXNd6NzYM3t2PROjCpywrta9kS2EHAgMBAAGjUDBO\n" |
| 181 | "MB0GA1UdDgQWBBTQQfuJQR6nrVrsNF1JEflVgXgfEzAfBgNVHSMEGDAWgBTQQfuJ\n" |
| 182 | "QR6nrVrsNF1JEflVgXgfEzAMBgNVHRMEBTADAQH/MBIGCSqGSIb3DQEBCjAFogMC\n" |
| 183 | "AWoDgYEASUy2RZcgNbNQZA0/7F+V1YTLEXwD16bm+iSVnzGwtexmQVEYIZG74K/w\n" |
| 184 | "xbdZQdTbpNJkp1QPjPfh0zsatw6dmt5QoZ8K8No0DjR9dgf+Wvv5WJvJUIQBoAVN\n" |
| 185 | "Z0IL+OQFz6+LcTHxD27JJCebrATXZA0wThGTQDm7crL+a+SujBY=\n" |
| 186 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 187 | |
| 188 | // kBadPSSCertPEM is a self-signed RSA-PSS certificate with bad parameters. |
| 189 | static const char kBadPSSCertPEM[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 190 | "-----BEGIN CERTIFICATE-----\n" |
| 191 | "MIIDdjCCAjqgAwIBAgIJANcwZLyfEv7DMD4GCSqGSIb3DQEBCjAxoA0wCwYJYIZI\n" |
| 192 | "AWUDBAIBoRowGAYJKoZIhvcNAQEIMAsGCWCGSAFlAwQCAaIEAgIA3jAnMSUwIwYD\n" |
| 193 | "VQQDDBxUZXN0IEludmFsaWQgUFNTIGNlcnRpZmljYXRlMB4XDTE1MTEwNDE2MDIz\n" |
| 194 | "NVoXDTE1MTIwNDE2MDIzNVowJzElMCMGA1UEAwwcVGVzdCBJbnZhbGlkIFBTUyBj\n" |
| 195 | "ZXJ0aWZpY2F0ZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMTaM7WH\n" |
| 196 | "qVCAGAIA+zL1KWvvASTrhlq+1ePdO7wsrWX2KiYoTYrJYTnxhLnn0wrHqApt79nL\n" |
| 197 | "IBG7cfShyZqFHOY/IzlYPMVt+gPo293gw96Fds5JBsjhjkyGnOyr9OUntFqvxDbT\n" |
| 198 | "IIFU7o9IdxD4edaqjRv+fegVE+B79pDk4s0ujsk6dULtCg9Rst0ucGFo19mr+b7k\n" |
| 199 | "dbfn8pZ72ZNDJPueVdrUAWw9oll61UcYfk75XdrLk6JlL41GrYHc8KlfXf43gGQq\n" |
| 200 | "QfrpHkg4Ih2cI6Wt2nhFGAzrlcorzLliQIUJRIhM8h4IgDfpBpaPdVQLqS2pFbXa\n" |
| 201 | "5eQjqiyJwak2vJ8CAwEAAaNQME4wHQYDVR0OBBYEFCt180N4oGUt5LbzBwQ4Ia+2\n" |
| 202 | "4V97MB8GA1UdIwQYMBaAFCt180N4oGUt5LbzBwQ4Ia+24V97MAwGA1UdEwQFMAMB\n" |
| 203 | "Af8wMQYJKoZIhvcNAQEKMCSgDTALBglghkgBZQMEAgGhDTALBgkqhkiG9w0BAQii\n" |
| 204 | "BAICAN4DggEBAAjBtm90lGxgddjc4Xu/nbXXFHVs2zVcHv/mqOZoQkGB9r/BVgLb\n" |
| 205 | "xhHrFZ2pHGElbUYPfifdS9ztB73e1d4J+P29o0yBqfd4/wGAc/JA8qgn6AAEO/Xn\n" |
| 206 | "plhFeTRJQtLZVl75CkHXgUGUd3h+ADvKtcBuW9dSUncaUrgNKR8u/h/2sMG38RWY\n" |
| 207 | "DzBddC/66YTa3r7KkVUfW7yqRQfELiGKdcm+bjlTEMsvS+EhHup9CzbpoCx2Fx9p\n" |
| 208 | "NPtFY3yEObQhmL1JyoCRWqBE75GzFPbRaiux5UpEkns+i3trkGssZzsOuVqHNTNZ\n" |
| 209 | "lC9+9hPHIoc9UMmAQNo1vGIW3NWVoeGbaJ8=\n" |
| 210 | "-----END CERTIFICATE-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 211 | |
| 212 | static const char kRSAKey[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 213 | "-----BEGIN RSA PRIVATE KEY-----\n" |
| 214 | "MIICXgIBAAKBgQDYK8imMuRi/03z0K1Zi0WnvfFHvwlYeyK9Na6XJYaUoIDAtB92\n" |
| 215 | "kWdGMdAQhLciHnAjkXLI6W15OoV3gA/ElRZ1xUpxTMhjP6PyY5wqT5r6y8FxbiiF\n" |
| 216 | "KKAnHmUcrgfVW28tQ+0rkLGMryRtrukXOgXBv7gcrmU7G1jC2a7WqmeI8QIDAQAB\n" |
| 217 | "AoGBAIBy09Fd4DOq/Ijp8HeKuCMKTHqTW1xGHshLQ6jwVV2vWZIn9aIgmDsvkjCe\n" |
| 218 | "i6ssZvnbjVcwzSoByhjN8ZCf/i15HECWDFFh6gt0P5z0MnChwzZmvatV/FXCT0j+\n" |
| 219 | "WmGNB/gkehKjGXLLcjTb6dRYVJSCZhVuOLLcbWIV10gggJQBAkEA8S8sGe4ezyyZ\n" |
| 220 | "m4e9r95g6s43kPqtj5rewTsUxt+2n4eVodD+ZUlCULWVNAFLkYRTBCASlSrm9Xhj\n" |
| 221 | "QpmWAHJUkQJBAOVzQdFUaewLtdOJoPCtpYoY1zd22eae8TQEmpGOR11L6kbxLQsk\n" |
| 222 | "aMly/DOnOaa82tqAGTdqDEZgSNmCeKKknmECQAvpnY8GUOVAubGR6c+W90iBuQLj\n" |
| 223 | "LtFp/9ihd2w/PoDwrHZaoUYVcT4VSfJQog/k7kjE4MYXYWL8eEKg3WTWQNECQQDk\n" |
| 224 | "104Wi91Umd1PzF0ijd2jXOERJU1wEKe6XLkYYNHWQAe5l4J4MWj9OdxFXAxIuuR/\n" |
| 225 | "tfDwbqkta4xcux67//khAkEAvvRXLHTaa6VFzTaiiO8SaFsHV3lQyXOtMrBpB5jd\n" |
| 226 | "moZWgjHvB2W9Ckn7sDqsPB+U2tyX0joDdQEyuiMECDY8oQ==\n" |
| 227 | "-----END RSA PRIVATE KEY-----\n"; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 228 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 229 | // kCRLTestRoot is a test root certificate. It has private key: |
| 230 | // |
| 231 | // -----BEGIN RSA PRIVATE KEY----- |
| 232 | // MIIEpAIBAAKCAQEAo16WiLWZuaymsD8n5SKPmxV1y6jjgr3BS/dUBpbrzd1aeFzN |
| 233 | // lI8l2jfAnzUyp+I21RQ+nh/MhqjGElkTtK9xMn1Y+S9GMRh+5R/Du0iCb1tCZIPY |
| 234 | // 07Tgrb0KMNWe0v2QKVVruuYSgxIWodBfxlKO64Z8AJ5IbnWpuRqO6rctN9qUoMlT |
| 235 | // IAB6dL4G0tDJ/PGFWOJYwOMEIX54bly2wgyYJVBKiRRt4f7n8H922qmvPNA9idmX |
| 236 | // 9G1VAtgV6x97XXi7ULORIQvn9lVQF6nTYDBJhyuPB+mLThbLP2o9orxGx7aCtnnB |
| 237 | // ZUIxUvHNOI0FaSaZH7Fi0xsZ/GkG2HZe7ImPJwIDAQABAoIBAQCJF9MTHfHGkk+/ |
| 238 | // DwCXlA0Wg0e6hBuHl10iNobYkMWIl/xXjOknhYiqOqb181py76472SVC5ERprC+r |
| 239 | // Lf0PXzqKuA117mnkwT2bYLCL9Skf8WEhoFLQNbVlloF6wYjqXcYgKYKh8HgQbZl4 |
| 240 | // aLg2YQl2NADTNABsUWj/4H2WEelsODVviqfFs725lFg9KHDI8zxAZXLzDt/M9uVL |
| 241 | // GxJiX12tr0AwaeAFZ1oPM/y+LznM3N3+Ht3jHHw3jZ/u8Z1RdAmdpu3bZ6tbwGBr |
| 242 | // 9edsH5rKkm9aBvMrY7eX5VHqaqyRNFyG152ZOJh4XiiFG7EmgTPCpaHo50Y018Re |
| 243 | // grVtk+FBAoGBANY3lY+V8ZOwMxSHes+kTnoimHO5Ob7nxrOC71i27x+4HHsYUeAr |
| 244 | // /zOOghiDIn+oNkuiX5CIOWZKx159Bp65CPpCbTb/fh+HYnSgXFgCw7XptycO7LXM |
| 245 | // 5GwR5jSfpfzBFdYxjxoUzDMFBwTEYRTm0HkUHkH+s+ajjw5wqqbcGLcfAoGBAMM8 |
| 246 | // DKW6Tb66xsf708f0jonAjKYTLZ+WOcwsBEWSFHoY8dUjvW5gqx5acHTEsc5ZTeh4 |
| 247 | // BCFLa+Mn9cuJWVJNs09k7Xb2PNl92HQ4GN2vbdkJhExbkT6oLDHg1hVD0w8KLfz1 |
| 248 | // lTAW6pS+6CdOHMEJpvqx89EgU/1GgIQ1fXYczE75AoGAKeJoXdDFkUjsU+FBhAPu |
| 249 | // TDcjc80Nm2QaF9NMFR5/lsYa236f06MGnQAKM9zADBHJu/Qdl1brUjLg1HrBppsr |
| 250 | // RDNkw1IlSOjhuUf5hkPUHGd8Jijm440SRIcjabqla8wdBupdvo2+d2NOQgJbsQiI |
| 251 | // ToQ+fkzcxAXK3Nnuo/1436UCgYBjLH7UNOZHS8OsVM0I1r8NVKVdu4JCfeJQR8/H |
| 252 | // s2P5ffBir+wLRMnH+nMDreMQiibcPxMCArkERAlE4jlgaJ38Z62E76KLbLTmnJRt |
| 253 | // EC9Bv+bXjvAiHvWMRMUbOj/ddPNVez7Uld+FvdBaHwDWQlvzHzBWfBCOKSEhh7Z6 |
| 254 | // qDhUqQKBgQDPMDx2i5rfmQp3imV9xUcCkIRsyYQVf8Eo7NV07IdUy/otmksgn4Zt |
| 255 | // Lbf3v2dvxOpTNTONWjp2c+iUQo8QxJCZr5Sfb21oQ9Ktcrmc/CY7LeBVDibXwxdM |
| 256 | // vRG8kBzvslFWh7REzC3u06GSVhyKDfW93kN2cKVwGoahRlhj7oHuZQ== |
| 257 | // -----END RSA PRIVATE KEY----- |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 258 | static const char kCRLTestRoot[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 259 | "-----BEGIN CERTIFICATE-----\n" |
| 260 | "MIIDbzCCAlegAwIBAgIJAODri7v0dDUFMA0GCSqGSIb3DQEBCwUAME4xCzAJBgNV\n" |
| 261 | "BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRYwFAYDVQQHDA1Nb3VudGFpbiBW\n" |
| 262 | "aWV3MRIwEAYDVQQKDAlCb3JpbmdTU0wwHhcNMTYwOTI2MTUwNjI2WhcNMjYwOTI0\n" |
| 263 | "MTUwNjI2WjBOMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQG\n" |
| 264 | "A1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJQm9yaW5nU1NMMIIBIjANBgkq\n" |
| 265 | "hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo16WiLWZuaymsD8n5SKPmxV1y6jjgr3B\n" |
| 266 | "S/dUBpbrzd1aeFzNlI8l2jfAnzUyp+I21RQ+nh/MhqjGElkTtK9xMn1Y+S9GMRh+\n" |
| 267 | "5R/Du0iCb1tCZIPY07Tgrb0KMNWe0v2QKVVruuYSgxIWodBfxlKO64Z8AJ5IbnWp\n" |
| 268 | "uRqO6rctN9qUoMlTIAB6dL4G0tDJ/PGFWOJYwOMEIX54bly2wgyYJVBKiRRt4f7n\n" |
| 269 | "8H922qmvPNA9idmX9G1VAtgV6x97XXi7ULORIQvn9lVQF6nTYDBJhyuPB+mLThbL\n" |
| 270 | "P2o9orxGx7aCtnnBZUIxUvHNOI0FaSaZH7Fi0xsZ/GkG2HZe7ImPJwIDAQABo1Aw\n" |
| 271 | "TjAdBgNVHQ4EFgQUWPt3N5cZ/CRvubbrkqfBnAqhq94wHwYDVR0jBBgwFoAUWPt3\n" |
| 272 | "N5cZ/CRvubbrkqfBnAqhq94wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC\n" |
| 273 | "AQEAORu6M0MOwXy+3VEBwNilfTxyqDfruQsc1jA4PT8Oe8zora1WxE1JB4q2FJOz\n" |
| 274 | "EAuM3H/NXvEnBuN+ITvKZAJUfm4NKX97qmjMJwLKWe1gVv+VQTr63aR7mgWJReQN\n" |
| 275 | "XdMztlVeZs2dppV6uEg3ia1X0G7LARxGpA9ETbMyCpb39XxlYuTClcbA5ftDN99B\n" |
| 276 | "3Xg9KNdd++Ew22O3HWRDvdDpTO/JkzQfzi3sYwUtzMEonENhczJhGf7bQMmvL/w5\n" |
| 277 | "24Wxj4Z7KzzWIHsNqE/RIs6RV3fcW61j/mRgW2XyoWnMVeBzvcJr9NXp4VQYmFPw\n" |
| 278 | "amd8GKMZQvP0ufGnUn7D7uartA==\n" |
| 279 | "-----END CERTIFICATE-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 280 | |
| 281 | static const char kCRLTestLeaf[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 282 | "-----BEGIN CERTIFICATE-----\n" |
| 283 | "MIIDkDCCAnigAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwTjELMAkGA1UEBhMCVVMx\n" |
| 284 | "EzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDU1vdW50YWluIFZpZXcxEjAQ\n" |
| 285 | "BgNVBAoMCUJvcmluZ1NTTDAeFw0xNjA5MjYxNTA4MzFaFw0xNzA5MjYxNTA4MzFa\n" |
| 286 | "MEsxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMRIwEAYDVQQKDAlC\n" |
| 287 | "b3JpbmdTU0wxEzARBgNVBAMMCmJvcmluZy5zc2wwggEiMA0GCSqGSIb3DQEBAQUA\n" |
| 288 | "A4IBDwAwggEKAoIBAQDc5v1S1M0W+QWM+raWfO0LH8uvqEwuJQgODqMaGnSlWUx9\n" |
| 289 | "8iQcnWfjyPja3lWg9K62hSOFDuSyEkysKHDxijz5R93CfLcfnVXjWQDJe7EJTTDP\n" |
| 290 | "ozEvxN6RjAeYv7CF000euYr3QT5iyBjg76+bon1p0jHZBJeNPP1KqGYgyxp+hzpx\n" |
| 291 | "e0gZmTlGAXd8JQK4v8kpdYwD6PPifFL/jpmQpqOtQmH/6zcLjY4ojmqpEdBqIKIX\n" |
| 292 | "+saA29hMq0+NK3K+wgg31RU+cVWxu3tLOIiesETkeDgArjWRS1Vkzbi4v9SJxtNu\n" |
| 293 | "OZuAxWiynRJw3JwH/OFHYZIvQqz68ZBoj96cepjPAgMBAAGjezB5MAkGA1UdEwQC\n" |
| 294 | "MAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRl\n" |
| 295 | "MB0GA1UdDgQWBBTGn0OVVh/aoYt0bvEKG+PIERqnDzAfBgNVHSMEGDAWgBRY+3c3\n" |
| 296 | "lxn8JG+5tuuSp8GcCqGr3jANBgkqhkiG9w0BAQsFAAOCAQEAd2nM8gCQN2Dc8QJw\n" |
| 297 | "XSZXyuI3DBGGCHcay/3iXu0JvTC3EiQo8J6Djv7WLI0N5KH8mkm40u89fJAB2lLZ\n" |
| 298 | "ShuHVtcC182bOKnePgwp9CNwQ21p0rDEu/P3X46ZvFgdxx82E9xLa0tBB8PiPDWh\n" |
| 299 | "lV16jbaKTgX5AZqjnsyjR5o9/mbZVupZJXx5Syq+XA8qiJfstSYJs4KyKK9UOjql\n" |
| 300 | "ICkJVKpi2ahDBqX4MOH4SLfzVk8pqSpviS6yaA1RXqjpkxiN45WWaXDldVHMSkhC\n" |
| 301 | "5CNXsXi4b1nAntu89crwSLA3rEwzCWeYj+BX7e1T9rr3oJdwOU/2KQtW1js1yQUG\n" |
| 302 | "tjJMFw==\n" |
| 303 | "-----END CERTIFICATE-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 304 | |
| 305 | static const char kBasicCRL[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 306 | "-----BEGIN X509 CRL-----\n" |
| 307 | "MIIBpzCBkAIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 308 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 309 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoA4wDDAKBgNV\n" |
| 310 | "HRQEAwIBATANBgkqhkiG9w0BAQsFAAOCAQEAnrBKKgvd9x9zwK9rtUvVeFeJ7+LN\n" |
| 311 | "ZEAc+a5oxpPNEsJx6hXoApYEbzXMxuWBQoCs5iEBycSGudct21L+MVf27M38KrWo\n" |
| 312 | "eOkq0a2siqViQZO2Fb/SUFR0k9zb8xl86Zf65lgPplALun0bV/HT7MJcl04Tc4os\n" |
| 313 | "dsAReBs5nqTGNEd5AlC1iKHvQZkM//MD51DspKnDpsDiUVi54h9C1SpfZmX8H2Vv\n" |
| 314 | "diyu0fZ/bPAM3VAGawatf/SyWfBMyKpoPXEG39oAzmjjOj8en82psn7m474IGaho\n" |
| 315 | "/vBbhl1ms5qQiLYPjm4YELtnXQoFyC72tBjbdFd/ZE9k4CNKDbxFUXFbkw==\n" |
| 316 | "-----END X509 CRL-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 317 | |
| 318 | static const char kRevokedCRL[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 319 | "-----BEGIN X509 CRL-----\n" |
| 320 | "MIIBvjCBpwIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 321 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 322 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEyNDRaFw0xNjEwMjYxNTEyNDRaMBUwEwICEAAX\n" |
| 323 | "DTE2MDkyNjE1MTIyNlqgDjAMMAoGA1UdFAQDAgECMA0GCSqGSIb3DQEBCwUAA4IB\n" |
| 324 | "AQCUGaM4DcWzlQKrcZvI8TMeR8BpsvQeo5BoI/XZu2a8h//PyRyMwYeaOM+3zl0d\n" |
| 325 | "sjgCT8b3C1FPgT+P2Lkowv7rJ+FHJRNQkogr+RuqCSPTq65ha4WKlRGWkMFybzVH\n" |
| 326 | "NloxC+aU3lgp/NlX9yUtfqYmJek1CDrOOGPrAEAwj1l/BUeYKNGqfBWYJQtPJu+5\n" |
| 327 | "OaSvIYGpETCZJscUWODmLEb/O3DM438vLvxonwGqXqS0KX37+CHpUlyhnSovxXxp\n" |
| 328 | "Pz4aF+L7OtczxL0GYtD2fR9B7TDMqsNmHXgQrixvvOY7MUdLGbd4RfJL3yA53hyO\n" |
| 329 | "xzfKY2TzxLiOmctG0hXFkH5J\n" |
| 330 | "-----END X509 CRL-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 331 | |
| 332 | static const char kBadIssuerCRL[] = |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 333 | "-----BEGIN X509 CRL-----\n" |
| 334 | "MIIBwjCBqwIBATANBgkqhkiG9w0BAQsFADBSMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 335 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzEWMBQGA1UECgwN\n" |
| 336 | "Tm90IEJvcmluZ1NTTBcNMTYwOTI2MTUxMjQ0WhcNMTYxMDI2MTUxMjQ0WjAVMBMC\n" |
| 337 | "AhAAFw0xNjA5MjYxNTEyMjZaoA4wDDAKBgNVHRQEAwIBAjANBgkqhkiG9w0BAQsF\n" |
| 338 | "AAOCAQEAlBmjOA3Fs5UCq3GbyPEzHkfAabL0HqOQaCP12btmvIf/z8kcjMGHmjjP\n" |
| 339 | "t85dHbI4Ak/G9wtRT4E/j9i5KML+6yfhRyUTUJKIK/kbqgkj06uuYWuFipURlpDB\n" |
| 340 | "cm81RzZaMQvmlN5YKfzZV/clLX6mJiXpNQg6zjhj6wBAMI9ZfwVHmCjRqnwVmCUL\n" |
| 341 | "TybvuTmkryGBqREwmSbHFFjg5ixG/ztwzON/Ly78aJ8Bql6ktCl9+/gh6VJcoZ0q\n" |
| 342 | "L8V8aT8+Ghfi+zrXM8S9BmLQ9n0fQe0wzKrDZh14EK4sb7zmOzFHSxm3eEXyS98g\n" |
| 343 | "Od4cjsc3ymNk88S4jpnLRtIVxZB+SQ==\n" |
| 344 | "-----END X509 CRL-----\n"; |
| 345 | |
| 346 | // kKnownCriticalCRL is kBasicCRL but with a critical issuing distribution point |
| 347 | // extension. |
| 348 | static const char kKnownCriticalCRL[] = |
| 349 | "-----BEGIN X509 CRL-----\n" |
| 350 | "MIIBujCBowIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 351 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 352 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoCEwHzAKBgNV\n" |
| 353 | "HRQEAwIBATARBgNVHRwBAf8EBzAFoQMBAf8wDQYJKoZIhvcNAQELBQADggEBAA+3\n" |
| 354 | "i+5e5Ub8sccfgOBs6WVJFI9c8gvJjrJ8/dYfFIAuCyeocs7DFXn1n13CRZ+URR/Q\n" |
| 355 | "mVWgU28+xeusuSPYFpd9cyYTcVyNUGNTI3lwgcE/yVjPaOmzSZKdPakApRxtpKKQ\n" |
| 356 | "NN/56aQz3bnT/ZSHQNciRB8U6jiD9V30t0w+FDTpGaG+7bzzUH3UVF9xf9Ctp60A\n" |
| 357 | "3mfLe0scas7owSt4AEFuj2SPvcE7yvdOXbu+IEv21cEJUVExJAbhvIweHXh6yRW+\n" |
| 358 | "7VVeiNzdIjkZjyTmAzoXGha4+wbxXyBRbfH+XWcO/H+8nwyG8Gktdu2QB9S9nnIp\n" |
| 359 | "o/1TpfOMSGhMyMoyPrk=\n" |
| 360 | "-----END X509 CRL-----\n"; |
| 361 | |
| 362 | // kUnknownCriticalCRL is kBasicCRL but with an unknown critical extension. |
| 363 | static const char kUnknownCriticalCRL[] = |
| 364 | "-----BEGIN X509 CRL-----\n" |
| 365 | "MIIBvDCBpQIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 366 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 367 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoCMwITAKBgNV\n" |
| 368 | "HRQEAwIBATATBgwqhkiG9xIEAYS3CQABAf8EADANBgkqhkiG9w0BAQsFAAOCAQEA\n" |
| 369 | "GvBP0xqL509InMj/3493YVRV+ldTpBv5uTD6jewzf5XdaxEQ/VjTNe5zKnxbpAib\n" |
| 370 | "Kf7cwX0PMSkZjx7k7kKdDlEucwVvDoqC+O9aJcqVmM6GDyNb9xENxd0XCXja6MZC\n" |
| 371 | "yVgP4AwLauB2vSiEprYJyI1APph3iAEeDm60lTXX/wBM/tupQDDujKh2GPyvBRfJ\n" |
| 372 | "+wEDwGg3ICwvu4gO4zeC5qnFR+bpL9t5tOMAQnVZ0NWv+k7mkd2LbHdD44dxrfXC\n" |
| 373 | "nhtfERx99SDmC/jtUAJrGhtCO8acr7exCeYcduN7KKCm91OeCJKK6OzWst0Og1DB\n" |
| 374 | "kwzzU2rL3G65CrZ7H0SZsQ==\n" |
| 375 | "-----END X509 CRL-----\n"; |
| 376 | |
| 377 | // kUnknownCriticalCRL2 is kBasicCRL but with a critical issuing distribution |
| 378 | // point extension followed by an unknown critical extension |
| 379 | static const char kUnknownCriticalCRL2[] = |
| 380 | "-----BEGIN X509 CRL-----\n" |
| 381 | "MIIBzzCBuAIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzETMBEGA1UE\n" |
| 382 | "CAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNTW91bnRhaW4gVmlldzESMBAGA1UECgwJ\n" |
| 383 | "Qm9yaW5nU1NMFw0xNjA5MjYxNTEwNTVaFw0xNjEwMjYxNTEwNTVaoDYwNDAKBgNV\n" |
| 384 | "HRQEAwIBATARBgNVHRwBAf8EBzAFoQMBAf8wEwYMKoZIhvcSBAGEtwkAAQH/BAAw\n" |
| 385 | "DQYJKoZIhvcNAQELBQADggEBACTcpQC8jXL12JN5YzOcQ64ubQIe0XxRAd30p7qB\n" |
| 386 | "BTXGpgqBjrjxRfLms7EBYodEXB2oXMsDq3km0vT1MfYdsDD05S+SQ9CDsq/pUfaC\n" |
| 387 | "E2WNI5p8WircRnroYvbN2vkjlRbMd1+yNITohXYXCJwjEOAWOx3XIM10bwPYBv4R\n" |
| 388 | "rDobuLHoMgL3yHgMHmAkP7YpkBucNqeBV8cCdeAZLuhXFWi6yfr3r/X18yWbC/r2\n" |
| 389 | "2xXdkrSqXLFo7ToyP8YKTgiXpya4x6m53biEYwa2ULlas0igL6DK7wjYZX95Uy7H\n" |
| 390 | "GKljn9weIYiMPV/BzGymwfv2EW0preLwtyJNJPaxbdin6Jc=\n" |
| 391 | "-----END X509 CRL-----\n"; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 392 | |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 393 | // kEd25519Cert is a self-signed Ed25519 certificate. |
| 394 | static const char kEd25519Cert[] = |
| 395 | "-----BEGIN CERTIFICATE-----\n" |
| 396 | "MIIBkTCCAUOgAwIBAgIJAJwooam0UCDmMAUGAytlcDBFMQswCQYDVQQGEwJBVTET\n" |
| 397 | "MBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ\n" |
| 398 | "dHkgTHRkMB4XDTE0MDQyMzIzMjE1N1oXDTE0MDUyMzIzMjE1N1owRTELMAkGA1UE\n" |
| 399 | "BhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdp\n" |
| 400 | "ZGdpdHMgUHR5IEx0ZDAqMAUGAytlcAMhANdamAGCsQq31Uv+08lkBzoO4XLz2qYj\n" |
| 401 | "Ja8CGmj3B1Eao1AwTjAdBgNVHQ4EFgQUoux7eV+fJK2v3ah6QPU/lj1/+7UwHwYD\n" |
| 402 | "VR0jBBgwFoAUoux7eV+fJK2v3ah6QPU/lj1/+7UwDAYDVR0TBAUwAwEB/zAFBgMr\n" |
| 403 | "ZXADQQBuCzqji8VP9xU8mHEMjXGChX7YP5J664UyVKHKH9Z1u4wEbB8dJ3ScaWSL\n" |
| 404 | "r+VHVKUhsrvcdCelnXRrrSD7xWAL\n" |
| 405 | "-----END CERTIFICATE-----\n"; |
| 406 | |
| 407 | // kEd25519CertNull is an invalid self-signed Ed25519 with an explicit NULL in |
| 408 | // the signature algorithm. |
| 409 | static const char kEd25519CertNull[] = |
| 410 | "-----BEGIN CERTIFICATE-----\n" |
| 411 | "MIIBlTCCAUWgAwIBAgIJAJwooam0UCDmMAcGAytlcAUAMEUxCzAJBgNVBAYTAkFV\n" |
| 412 | "MRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRz\n" |
| 413 | "IFB0eSBMdGQwHhcNMTQwNDIzMjMyMTU3WhcNMTQwNTIzMjMyMTU3WjBFMQswCQYD\n" |
| 414 | "VQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQg\n" |
| 415 | "V2lkZ2l0cyBQdHkgTHRkMCowBQYDK2VwAyEA11qYAYKxCrfVS/7TyWQHOg7hcvPa\n" |
| 416 | "piMlrwIaaPcHURqjUDBOMB0GA1UdDgQWBBSi7Ht5X58kra/dqHpA9T+WPX/7tTAf\n" |
| 417 | "BgNVHSMEGDAWgBSi7Ht5X58kra/dqHpA9T+WPX/7tTAMBgNVHRMEBTADAQH/MAcG\n" |
| 418 | "AytlcAUAA0EA70uefNocdJohkKPNROKVyBuBD3LXMyvmdTklsaxSRY3PcZdOohlr\n" |
| 419 | "recgVPpVS7B+d9g4EwtZXIh4lodTBDHBBw==\n" |
| 420 | "-----END CERTIFICATE-----\n"; |
| 421 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 422 | // CertFromPEM parses the given, NUL-terminated pem block and returns an |
| 423 | // |X509*|. |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 424 | static bssl::UniquePtr<X509> CertFromPEM(const char *pem) { |
| 425 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(pem, strlen(pem))); |
| 426 | return bssl::UniquePtr<X509>( |
| 427 | PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 428 | } |
| 429 | |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 430 | // CRLFromPEM parses the given, NUL-terminated pem block and returns an |
| 431 | // |X509_CRL*|. |
| 432 | static bssl::UniquePtr<X509_CRL> CRLFromPEM(const char *pem) { |
| 433 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(pem, strlen(pem))); |
| 434 | return bssl::UniquePtr<X509_CRL>( |
| 435 | PEM_read_bio_X509_CRL(bio.get(), nullptr, nullptr, nullptr)); |
| 436 | } |
| 437 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 438 | // PrivateKeyFromPEM parses the given, NUL-terminated pem block and returns an |
| 439 | // |EVP_PKEY*|. |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 440 | static bssl::UniquePtr<EVP_PKEY> PrivateKeyFromPEM(const char *pem) { |
| 441 | bssl::UniquePtr<BIO> bio( |
| 442 | BIO_new_mem_buf(const_cast<char *>(pem), strlen(pem))); |
| 443 | return bssl::UniquePtr<EVP_PKEY>( |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 444 | PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr)); |
| 445 | } |
| 446 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 447 | // CertsToStack converts a vector of |X509*| to an OpenSSL STACK_OF(X509), |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 448 | // bumping the reference counts for each certificate in question. |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 449 | static bssl::UniquePtr<STACK_OF(X509)> CertsToStack( |
| 450 | const std::vector<X509 *> &certs) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 451 | bssl::UniquePtr<STACK_OF(X509)> stack(sk_X509_new_null()); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 452 | if (!stack) { |
| 453 | return nullptr; |
| 454 | } |
| 455 | for (auto cert : certs) { |
| 456 | if (!sk_X509_push(stack.get(), cert)) { |
| 457 | return nullptr; |
| 458 | } |
| 459 | X509_up_ref(cert); |
| 460 | } |
| 461 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 462 | return stack; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 463 | } |
| 464 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 465 | // CRLsToStack converts a vector of |X509_CRL*| to an OpenSSL |
| 466 | // STACK_OF(X509_CRL), bumping the reference counts for each CRL in question. |
| 467 | static bssl::UniquePtr<STACK_OF(X509_CRL)> CRLsToStack( |
| 468 | const std::vector<X509_CRL *> &crls) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 469 | bssl::UniquePtr<STACK_OF(X509_CRL)> stack(sk_X509_CRL_new_null()); |
| 470 | if (!stack) { |
| 471 | return nullptr; |
| 472 | } |
| 473 | for (auto crl : crls) { |
| 474 | if (!sk_X509_CRL_push(stack.get(), crl)) { |
| 475 | return nullptr; |
| 476 | } |
| 477 | X509_CRL_up_ref(crl); |
| 478 | } |
| 479 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 480 | return stack; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | static int Verify(X509 *leaf, const std::vector<X509 *> &roots, |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 484 | const std::vector<X509 *> &intermediates, |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 485 | const std::vector<X509_CRL *> &crls, |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 486 | unsigned long flags, |
| 487 | bool use_additional_untrusted) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 488 | bssl::UniquePtr<STACK_OF(X509)> roots_stack(CertsToStack(roots)); |
| 489 | bssl::UniquePtr<STACK_OF(X509)> intermediates_stack( |
| 490 | CertsToStack(intermediates)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 491 | bssl::UniquePtr<STACK_OF(X509_CRL)> crls_stack(CRLsToStack(crls)); |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 492 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 493 | if (!roots_stack || |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 494 | !intermediates_stack || |
| 495 | !crls_stack) { |
| 496 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 497 | } |
| 498 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 499 | bssl::UniquePtr<X509_STORE_CTX> ctx(X509_STORE_CTX_new()); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 500 | bssl::UniquePtr<X509_STORE> store(X509_STORE_new()); |
| 501 | if (!ctx || |
| 502 | !store) { |
| 503 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 504 | } |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 505 | |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 506 | if (use_additional_untrusted) { |
| 507 | X509_STORE_set0_additional_untrusted(store.get(), |
| 508 | intermediates_stack.get()); |
| 509 | } |
| 510 | |
| 511 | if (!X509_STORE_CTX_init( |
| 512 | ctx.get(), store.get(), leaf, |
| 513 | use_additional_untrusted ? nullptr : intermediates_stack.get())) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 514 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | X509_STORE_CTX_trusted_stack(ctx.get(), roots_stack.get()); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 518 | X509_STORE_CTX_set0_crls(ctx.get(), crls_stack.get()); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 519 | |
| 520 | X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new(); |
| 521 | if (param == nullptr) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 522 | return X509_V_ERR_UNSPECIFIED; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 523 | } |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 524 | X509_VERIFY_PARAM_set_time(param, 1474934400 /* Sep 27th, 2016 */); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 525 | X509_VERIFY_PARAM_set_depth(param, 16); |
| 526 | if (flags) { |
| 527 | X509_VERIFY_PARAM_set_flags(param, flags); |
| 528 | } |
| 529 | X509_STORE_CTX_set0_param(ctx.get(), param); |
| 530 | |
| 531 | ERR_clear_error(); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 532 | if (X509_verify_cert(ctx.get()) != 1) { |
| 533 | return X509_STORE_CTX_get_error(ctx.get()); |
| 534 | } |
| 535 | |
| 536 | return X509_V_OK; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 537 | } |
| 538 | |
Robert Sloan | 69939df | 2017-01-09 10:53:07 -0800 | [diff] [blame] | 539 | static int Verify(X509 *leaf, const std::vector<X509 *> &roots, |
| 540 | const std::vector<X509 *> &intermediates, |
| 541 | const std::vector<X509_CRL *> &crls, |
| 542 | unsigned long flags = 0) { |
| 543 | const int r1 = Verify(leaf, roots, intermediates, crls, flags, false); |
| 544 | const int r2 = Verify(leaf, roots, intermediates, crls, flags, true); |
| 545 | |
| 546 | if (r1 != r2) { |
| 547 | fprintf(stderr, |
| 548 | "Verify with, and without, use_additional_untrusted gave different " |
| 549 | "results: %d vs %d.\n", |
| 550 | r1, r2); |
| 551 | return false; |
| 552 | } |
| 553 | |
| 554 | return r1; |
| 555 | } |
| 556 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 557 | TEST(X509Test, TestVerify) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 558 | bssl::UniquePtr<X509> cross_signing_root(CertFromPEM(kCrossSigningRootPEM)); |
| 559 | bssl::UniquePtr<X509> root(CertFromPEM(kRootCAPEM)); |
| 560 | bssl::UniquePtr<X509> root_cross_signed(CertFromPEM(kRootCrossSignedPEM)); |
| 561 | bssl::UniquePtr<X509> intermediate(CertFromPEM(kIntermediatePEM)); |
| 562 | bssl::UniquePtr<X509> intermediate_self_signed( |
| 563 | CertFromPEM(kIntermediateSelfSignedPEM)); |
| 564 | bssl::UniquePtr<X509> leaf(CertFromPEM(kLeafPEM)); |
| 565 | bssl::UniquePtr<X509> leaf_no_key_usage(CertFromPEM(kLeafNoKeyUsagePEM)); |
| 566 | bssl::UniquePtr<X509> forgery(CertFromPEM(kForgeryPEM)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 567 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 568 | ASSERT_TRUE(cross_signing_root); |
| 569 | ASSERT_TRUE(root); |
| 570 | ASSERT_TRUE(root_cross_signed); |
| 571 | ASSERT_TRUE(intermediate); |
| 572 | ASSERT_TRUE(intermediate_self_signed); |
| 573 | ASSERT_TRUE(leaf); |
| 574 | ASSERT_TRUE(forgery); |
| 575 | ASSERT_TRUE(leaf_no_key_usage); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 576 | |
| 577 | std::vector<X509*> empty; |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 578 | std::vector<X509_CRL*> empty_crls; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 579 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, |
| 580 | Verify(leaf.get(), empty, empty, empty_crls)); |
| 581 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, |
| 582 | Verify(leaf.get(), empty, {intermediate.get()}, empty_crls)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 583 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 584 | ASSERT_EQ(X509_V_OK, |
| 585 | Verify(leaf.get(), {root.get()}, {intermediate.get()}, empty_crls)); |
| 586 | ASSERT_EQ(X509_V_OK, |
| 587 | Verify(leaf.get(), {cross_signing_root.get()}, |
| 588 | {intermediate.get(), root_cross_signed.get()}, empty_crls)); |
| 589 | ASSERT_EQ(X509_V_OK, |
| 590 | Verify(leaf.get(), {cross_signing_root.get(), root.get()}, |
| 591 | {intermediate.get(), root_cross_signed.get()}, empty_crls)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 592 | |
| 593 | /* This is the “altchains” test – we remove the cross-signing CA but include |
| 594 | * the cross-sign in the intermediates. */ |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 595 | ASSERT_EQ(X509_V_OK, |
| 596 | Verify(leaf.get(), {root.get()}, |
| 597 | {intermediate.get(), root_cross_signed.get()}, empty_crls)); |
| 598 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY, |
| 599 | Verify(leaf.get(), {root.get()}, |
| 600 | {intermediate.get(), root_cross_signed.get()}, empty_crls, |
| 601 | X509_V_FLAG_NO_ALT_CHAINS)); |
| 602 | ASSERT_EQ(X509_V_ERR_INVALID_CA, |
| 603 | Verify(forgery.get(), {intermediate_self_signed.get()}, |
| 604 | {leaf_no_key_usage.get()}, empty_crls)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 605 | |
| 606 | /* Test that one cannot skip Basic Constraints checking with a contorted set |
| 607 | * 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] | 608 | ASSERT_EQ(X509_V_ERR_INVALID_CA, |
| 609 | Verify(forgery.get(), |
| 610 | {intermediate_self_signed.get(), root_cross_signed.get()}, |
| 611 | {leaf_no_key_usage.get(), intermediate.get()}, empty_crls)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 612 | } |
| 613 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 614 | TEST(X509Test, TestCRL) { |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 615 | bssl::UniquePtr<X509> root(CertFromPEM(kCRLTestRoot)); |
| 616 | bssl::UniquePtr<X509> leaf(CertFromPEM(kCRLTestLeaf)); |
| 617 | bssl::UniquePtr<X509_CRL> basic_crl(CRLFromPEM(kBasicCRL)); |
| 618 | bssl::UniquePtr<X509_CRL> revoked_crl(CRLFromPEM(kRevokedCRL)); |
| 619 | bssl::UniquePtr<X509_CRL> bad_issuer_crl(CRLFromPEM(kBadIssuerCRL)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 620 | bssl::UniquePtr<X509_CRL> known_critical_crl(CRLFromPEM(kKnownCriticalCRL)); |
| 621 | bssl::UniquePtr<X509_CRL> unknown_critical_crl( |
| 622 | CRLFromPEM(kUnknownCriticalCRL)); |
| 623 | bssl::UniquePtr<X509_CRL> unknown_critical_crl2( |
| 624 | CRLFromPEM(kUnknownCriticalCRL2)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 625 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 626 | ASSERT_TRUE(root); |
| 627 | ASSERT_TRUE(leaf); |
| 628 | ASSERT_TRUE(basic_crl); |
| 629 | ASSERT_TRUE(revoked_crl); |
| 630 | ASSERT_TRUE(bad_issuer_crl); |
| 631 | ASSERT_TRUE(known_critical_crl); |
| 632 | ASSERT_TRUE(unknown_critical_crl); |
| 633 | ASSERT_TRUE(unknown_critical_crl2); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 634 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 635 | ASSERT_EQ(X509_V_OK, Verify(leaf.get(), {root.get()}, {root.get()}, |
| 636 | {basic_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 637 | ASSERT_EQ( |
| 638 | X509_V_ERR_CERT_REVOKED, |
| 639 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 640 | {basic_crl.get(), revoked_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 641 | |
| 642 | std::vector<X509_CRL *> empty_crls; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 643 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_CRL, |
| 644 | Verify(leaf.get(), {root.get()}, {root.get()}, empty_crls, |
| 645 | X509_V_FLAG_CRL_CHECK)); |
| 646 | ASSERT_EQ(X509_V_ERR_UNABLE_TO_GET_CRL, |
| 647 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 648 | {bad_issuer_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 649 | ASSERT_EQ(X509_V_OK, |
| 650 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 651 | {known_critical_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 652 | ASSERT_EQ(X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION, |
| 653 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 654 | {unknown_critical_crl.get()}, X509_V_FLAG_CRL_CHECK)); |
| 655 | ASSERT_EQ(X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION, |
| 656 | Verify(leaf.get(), {root.get()}, {root.get()}, |
| 657 | {unknown_critical_crl2.get()}, X509_V_FLAG_CRL_CHECK)); |
Steven Valdez | bb1ceac | 2016-10-07 10:34:51 -0400 | [diff] [blame] | 658 | } |
| 659 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 660 | TEST(X509Test, TestPSS) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 661 | bssl::UniquePtr<X509> cert(CertFromPEM(kExamplePSSCert)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 662 | ASSERT_TRUE(cert); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 663 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 664 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 665 | ASSERT_TRUE(pkey); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 666 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 667 | ASSERT_TRUE(X509_verify(cert.get(), pkey.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 668 | } |
| 669 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 670 | TEST(X509Test, TestPSSBadParameters) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 671 | bssl::UniquePtr<X509> cert(CertFromPEM(kBadPSSCertPEM)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 672 | ASSERT_TRUE(cert); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 673 | |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 674 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 675 | ASSERT_TRUE(pkey); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 676 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 677 | ASSERT_FALSE(X509_verify(cert.get(), pkey.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 678 | ERR_clear_error(); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 679 | } |
| 680 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 681 | TEST(X509Test, TestEd25519) { |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 682 | bssl::UniquePtr<X509> cert(CertFromPEM(kEd25519Cert)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 683 | ASSERT_TRUE(cert); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 684 | |
| 685 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 686 | ASSERT_TRUE(pkey); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 687 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 688 | ASSERT_TRUE(X509_verify(cert.get(), pkey.get())); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 691 | TEST(X509Test, TestEd25519BadParameters) { |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 692 | bssl::UniquePtr<X509> cert(CertFromPEM(kEd25519CertNull)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 693 | ASSERT_TRUE(cert); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 694 | |
| 695 | bssl::UniquePtr<EVP_PKEY> pkey(X509_get_pubkey(cert.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 696 | ASSERT_TRUE(pkey); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 697 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 698 | ASSERT_FALSE(X509_verify(cert.get(), pkey.get())); |
| 699 | |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 700 | uint32_t err = ERR_get_error(); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 701 | ASSERT_EQ(ERR_LIB_X509, ERR_GET_LIB(err)); |
| 702 | ASSERT_EQ(X509_R_INVALID_PARAMETER, ERR_GET_REASON(err)); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 703 | ERR_clear_error(); |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 704 | } |
| 705 | |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 706 | static bool SignatureRoundTrips(EVP_MD_CTX *md_ctx, EVP_PKEY *pkey) { |
| 707 | // Make a certificate like signed with |md_ctx|'s settings.' |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 708 | bssl::UniquePtr<X509> cert(CertFromPEM(kLeafPEM)); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 709 | if (!cert || !X509_sign_ctx(cert.get(), md_ctx)) { |
| 710 | return false; |
| 711 | } |
| 712 | |
| 713 | // Ensure that |pkey| may still be used to verify the resulting signature. All |
| 714 | // settings in |md_ctx| must have been serialized appropriately. |
| 715 | return !!X509_verify(cert.get(), pkey); |
| 716 | } |
| 717 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 718 | TEST(X509Test, RSASign) { |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 719 | bssl::UniquePtr<EVP_PKEY> pkey(PrivateKeyFromPEM(kRSAKey)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 720 | ASSERT_TRUE(pkey); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 721 | // Test PKCS#1 v1.5. |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 722 | bssl::ScopedEVP_MD_CTX md_ctx; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 723 | ASSERT_TRUE( |
| 724 | EVP_DigestSignInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get())); |
| 725 | ASSERT_TRUE(SignatureRoundTrips(md_ctx.get(), pkey.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 726 | |
| 727 | // Test RSA-PSS with custom parameters. |
| 728 | md_ctx.Reset(); |
| 729 | EVP_PKEY_CTX *pkey_ctx; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 730 | ASSERT_TRUE(EVP_DigestSignInit(md_ctx.get(), &pkey_ctx, EVP_sha256(), NULL, |
| 731 | pkey.get())); |
| 732 | ASSERT_TRUE(EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING)); |
| 733 | ASSERT_TRUE(EVP_PKEY_CTX_set_rsa_mgf1_md(pkey_ctx, EVP_sha512())); |
| 734 | ASSERT_TRUE(SignatureRoundTrips(md_ctx.get(), pkey.get())); |
| 735 | } |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 736 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 737 | TEST(X509Test, Ed25519Sign) { |
| 738 | uint8_t pub_bytes[32], priv_bytes[64]; |
| 739 | ED25519_keypair(pub_bytes, priv_bytes); |
| 740 | |
| 741 | bssl::UniquePtr<EVP_PKEY> pub(EVP_PKEY_new_ed25519_public(pub_bytes)); |
| 742 | ASSERT_TRUE(pub); |
| 743 | bssl::UniquePtr<EVP_PKEY> priv(EVP_PKEY_new_ed25519_private(priv_bytes)); |
| 744 | ASSERT_TRUE(priv); |
| 745 | |
| 746 | bssl::ScopedEVP_MD_CTX md_ctx; |
| 747 | ASSERT_TRUE( |
| 748 | EVP_DigestSignInit(md_ctx.get(), nullptr, nullptr, nullptr, priv.get())); |
| 749 | ASSERT_TRUE(SignatureRoundTrips(md_ctx.get(), pub.get())); |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 750 | } |
| 751 | |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 752 | static bool PEMToDER(bssl::UniquePtr<uint8_t> *out, size_t *out_len, |
| 753 | const char *pem) { |
| 754 | bssl::UniquePtr<BIO> bio(BIO_new_mem_buf(pem, strlen(pem))); |
| 755 | if (!bio) { |
| 756 | return false; |
| 757 | } |
| 758 | |
| 759 | char *name, *header; |
| 760 | uint8_t *data; |
| 761 | long data_len; |
| 762 | if (!PEM_read_bio(bio.get(), &name, &header, &data, &data_len)) { |
| 763 | fprintf(stderr, "failed to read PEM data.\n"); |
| 764 | return false; |
| 765 | } |
| 766 | OPENSSL_free(name); |
| 767 | OPENSSL_free(header); |
| 768 | |
| 769 | out->reset(data); |
| 770 | *out_len = data_len; |
| 771 | |
| 772 | return true; |
| 773 | } |
| 774 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 775 | TEST(X509Test, TestFromBuffer) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 776 | size_t data_len; |
| 777 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 778 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 779 | |
| 780 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 781 | CRYPTO_BUFFER_new(data.get(), data_len, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 782 | ASSERT_TRUE(buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 783 | bssl::UniquePtr<X509> root(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 784 | ASSERT_TRUE(root); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 785 | |
| 786 | const uint8_t *enc_pointer = root->cert_info->enc.enc; |
| 787 | const uint8_t *buf_pointer = CRYPTO_BUFFER_data(buf.get()); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 788 | ASSERT_GE(enc_pointer, buf_pointer); |
| 789 | ASSERT_LT(enc_pointer, buf_pointer + CRYPTO_BUFFER_len(buf.get())); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 790 | buf.reset(); |
| 791 | |
| 792 | /* This ensures the X509 took a reference to |buf|, otherwise this will be a |
| 793 | * reference to free memory and ASAN should notice. */ |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 794 | ASSERT_EQ(CBS_ASN1_SEQUENCE, enc_pointer[0]); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 795 | } |
| 796 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 797 | TEST(X509Test, TestFromBufferWithTrailingData) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 798 | size_t data_len; |
| 799 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 800 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 801 | |
| 802 | 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] | 803 | OPENSSL_memcpy(trailing_data.get(), data.get(), data_len); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 804 | |
| 805 | bssl::UniquePtr<CRYPTO_BUFFER> buf_trailing_data( |
| 806 | CRYPTO_BUFFER_new(trailing_data.get(), data_len + 1, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 807 | ASSERT_TRUE(buf_trailing_data); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 808 | |
| 809 | bssl::UniquePtr<X509> root_trailing_data( |
| 810 | X509_parse_from_buffer(buf_trailing_data.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 811 | ASSERT_FALSE(root_trailing_data); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 812 | } |
| 813 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 814 | TEST(X509Test, TestFromBufferModified) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 815 | size_t data_len; |
| 816 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 817 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 818 | |
| 819 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 820 | CRYPTO_BUFFER_new(data.get(), data_len, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 821 | ASSERT_TRUE(buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 822 | |
| 823 | bssl::UniquePtr<X509> root(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 824 | ASSERT_TRUE(root); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 825 | |
| 826 | bssl::UniquePtr<ASN1_INTEGER> fourty_two(ASN1_INTEGER_new()); |
| 827 | ASN1_INTEGER_set(fourty_two.get(), 42); |
| 828 | X509_set_serialNumber(root.get(), fourty_two.get()); |
| 829 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 830 | ASSERT_EQ(static_cast<long>(data_len), i2d_X509(root.get(), nullptr)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 831 | |
| 832 | X509_CINF_set_modified(root->cert_info); |
| 833 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 834 | ASSERT_NE(static_cast<long>(data_len), i2d_X509(root.get(), nullptr)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 835 | } |
| 836 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 837 | TEST(X509Test, TestFromBufferReused) { |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 838 | size_t data_len; |
| 839 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 840 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 841 | |
| 842 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 843 | CRYPTO_BUFFER_new(data.get(), data_len, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 844 | ASSERT_TRUE(buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 845 | |
| 846 | bssl::UniquePtr<X509> root(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 847 | ASSERT_TRUE(root); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 848 | |
| 849 | size_t data2_len; |
| 850 | bssl::UniquePtr<uint8_t> data2; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 851 | ASSERT_TRUE(PEMToDER(&data2, &data2_len, kLeafPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 852 | |
| 853 | X509 *x509p = root.get(); |
| 854 | const uint8_t *inp = data2.get(); |
| 855 | X509 *ret = d2i_X509(&x509p, &inp, data2_len); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 856 | ASSERT_EQ(root.get(), ret); |
| 857 | ASSERT_EQ(nullptr, root->buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 858 | |
| 859 | // Free |data2| and ensure that |root| took its own copy. Otherwise the |
| 860 | // following will trigger a use-after-free. |
| 861 | data2.reset(); |
| 862 | |
| 863 | uint8_t *i2d = nullptr; |
| 864 | int i2d_len = i2d_X509(root.get(), &i2d); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 865 | ASSERT_GE(i2d_len, 0); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 866 | bssl::UniquePtr<uint8_t> i2d_storage(i2d); |
| 867 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 868 | ASSERT_TRUE(PEMToDER(&data2, &data2_len, kLeafPEM)); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 869 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 870 | ASSERT_EQ(static_cast<long>(data2_len), i2d_len); |
| 871 | ASSERT_EQ(0, OPENSSL_memcmp(data2.get(), i2d, i2d_len)); |
| 872 | ASSERT_EQ(nullptr, root->buf); |
Steven Valdez | 909b19f | 2016-11-21 15:35:44 -0500 | [diff] [blame] | 873 | } |
| 874 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 875 | TEST(X509Test, TestFailedParseFromBuffer) { |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 876 | static const uint8_t kNonsense[] = {1, 2, 3, 4, 5}; |
| 877 | |
| 878 | bssl::UniquePtr<CRYPTO_BUFFER> buf( |
| 879 | CRYPTO_BUFFER_new(kNonsense, sizeof(kNonsense), nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 880 | ASSERT_TRUE(buf); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 881 | |
| 882 | bssl::UniquePtr<X509> cert(X509_parse_from_buffer(buf.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 883 | ASSERT_FALSE(cert); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 884 | ERR_clear_error(); |
| 885 | |
| 886 | // Test a buffer with trailing data. |
| 887 | size_t data_len; |
| 888 | bssl::UniquePtr<uint8_t> data; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 889 | ASSERT_TRUE(PEMToDER(&data, &data_len, kRootCAPEM)); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 890 | |
| 891 | 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] | 892 | OPENSSL_memcpy(data_with_trailing_byte.get(), data.get(), data_len); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 893 | data_with_trailing_byte[data_len] = 0; |
| 894 | |
| 895 | bssl::UniquePtr<CRYPTO_BUFFER> buf_with_trailing_byte( |
| 896 | CRYPTO_BUFFER_new(data_with_trailing_byte.get(), data_len + 1, nullptr)); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 897 | ASSERT_TRUE(buf_with_trailing_byte); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 898 | |
| 899 | bssl::UniquePtr<X509> root( |
| 900 | X509_parse_from_buffer(buf_with_trailing_byte.get())); |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 901 | ASSERT_FALSE(root); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 902 | ERR_clear_error(); |
David Benjamin | 1b24967 | 2016-12-06 18:25:50 -0500 | [diff] [blame] | 903 | } |
| 904 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 905 | TEST(X509Test, TestPrintUTCTIME) { |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 906 | static const struct { |
| 907 | const char *val, *want; |
| 908 | } asn1_utctime_tests[] = { |
| 909 | {"", "Bad time value"}, |
| 910 | |
| 911 | // Correct RFC 5280 form. Test years < 2000 and > 2000. |
| 912 | {"090303125425Z", "Mar 3 12:54:25 2009 GMT"}, |
| 913 | {"900303125425Z", "Mar 3 12:54:25 1990 GMT"}, |
| 914 | {"000303125425Z", "Mar 3 12:54:25 2000 GMT"}, |
| 915 | |
| 916 | // Correct form, bad values. |
| 917 | {"000000000000Z", "Bad time value"}, |
| 918 | {"999999999999Z", "Bad time value"}, |
| 919 | |
| 920 | // Missing components. Not legal RFC 5280, but permitted. |
| 921 | {"090303125425", "Mar 3 12:54:25 2009"}, |
| 922 | {"9003031254", "Mar 3 12:54:00 1990"}, |
| 923 | {"9003031254Z", "Mar 3 12:54:00 1990 GMT"}, |
| 924 | |
| 925 | // GENERALIZEDTIME confused for UTCTIME. |
| 926 | {"20090303125425Z", "Bad time value"}, |
| 927 | |
| 928 | // Legal ASN.1, but not legal RFC 5280. |
| 929 | {"9003031254+0800", "Bad time value"}, |
| 930 | {"9003031254-0800", "Bad time value"}, |
| 931 | |
| 932 | // Trailing garbage. |
| 933 | {"9003031254Z ", "Bad time value"}, |
| 934 | }; |
| 935 | |
| 936 | for (auto t : asn1_utctime_tests) { |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 937 | SCOPED_TRACE(t.val); |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 938 | bssl::UniquePtr<ASN1_UTCTIME> tm(ASN1_UTCTIME_new()); |
| 939 | bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem())); |
| 940 | |
| 941 | // Use this instead of ASN1_UTCTIME_set() because some callers get |
| 942 | // type-confused and pass ASN1_GENERALIZEDTIME to ASN1_UTCTIME_print(). |
| 943 | // ASN1_UTCTIME_set_string() is stricter, and would reject the inputs in |
| 944 | // question. |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 945 | ASSERT_TRUE(ASN1_STRING_set(tm.get(), t.val, strlen(t.val))); |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 946 | const int ok = ASN1_UTCTIME_print(bio.get(), tm.get()); |
| 947 | |
| 948 | const uint8_t *contents; |
| 949 | size_t len; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 950 | ASSERT_TRUE(BIO_mem_contents(bio.get(), &contents, &len)); |
| 951 | EXPECT_EQ(ok, (strcmp(t.want, "Bad time value") != 0) ? 1 : 0); |
| 952 | EXPECT_EQ(t.want, |
| 953 | std::string(reinterpret_cast<const char *>(contents), len)); |
Steven Valdez | b0b45c6 | 2017-01-17 16:23:54 -0500 | [diff] [blame] | 954 | } |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 955 | } |