1 | /* $Id: tstRTCrPkix-1.cpp 100530 2023-07-11 23:09:45Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT testcase - Crypto - Public-Key Infrastructure \#1.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2018-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include <iprt/crypto/pkix.h>
|
---|
42 |
|
---|
43 | #include <iprt/err.h>
|
---|
44 | #include <iprt/string.h>
|
---|
45 | #include <iprt/test.h>
|
---|
46 | #include <iprt/crypto/key.h>
|
---|
47 | #include <iprt/crypto/digest.h>
|
---|
48 |
|
---|
49 |
|
---|
50 | /*********************************************************************************************************************************
|
---|
51 | * Global Variables *
|
---|
52 | *********************************************************************************************************************************/
|
---|
53 | static RTTEST g_hTest;
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Key pairs to use when testing.
|
---|
57 | */
|
---|
58 | static const struct { unsigned cBits; const char *pszPrivateKey, *pszPublicKey, *pszPassword; } g_aKeyPairs[] =
|
---|
59 | {
|
---|
60 | {
|
---|
61 | 4096,
|
---|
62 | "-----BEGIN RSA PRIVATE KEY-----\n"
|
---|
63 | "MIIJKQIBAAKCAgEA1SOurMTVz033GGi+5VrMb0SnU7Dj49ZQCKSuxaSFK4tvbZXQ\n"
|
---|
64 | "BRSgwC1PcQVyt3GdoC71i3O4f9TxaA870icCIY7cqf4LKL9uB5Vga2SNMfx3+Kqc\n"
|
---|
65 | "JVt9LFsghXfLocdfV1k+xeDVGcSP7uUvnXoIZyeS8puqoRYNiua1UT+ddXwihTId\n"
|
---|
66 | "+6O9Q8IxcCPWkqW89LYBQVFqqMYoWzNcbEctY6WpPzZk3er+AvMekBD409LbtT7j\n"
|
---|
67 | "TrzIGd6eQ0aF2MyVA6lOwe3u99Ubo/FTpule/FQ5LXaEmlHPfDbIw+LRArdYgjoQ\n"
|
---|
68 | "U9l4SFajm0VbIKd2LFn5SRXHTbtAoKX2zpaoi8GF3u8VR/EmmTPYFHr2gUoLuyeT\n"
|
---|
69 | "aY56OG/5ns7N/NRzOX1d1lNRFcQYNCXPEtqaUfUfMJU4Jqp1LOEcd1xMkOUh8lc7\n"
|
---|
70 | "DyvUfhry+SAcxB5SxcyjdWEXpj4G12/N3f6vsRoZNTFt5j0hsbiOAOFykgN0a2OF\n"
|
---|
71 | "77bsd975e1mxkqXJ9A0sbB8EXsD2PSrUZ7Pt+T9CiQGOjqVUg2Vr1jevcQRHe5ed\n"
|
---|
72 | "/R+B2jp6MjYjbr7cKqcXaRxEprGl+U5kIygql93DTgQaXwX/ZjXmwjXvQ0W4Oxxe\n"
|
---|
73 | "xqyW6YvDBYeNKxstuM5qfgzYf7FD/8lZYkyMAXELgpCqC92xlTbWpRVNpXcCAwEA\n"
|
---|
74 | "AQKCAgAlkBpSvIXp+RWZKayrAyuQWIscxsoC91w3ib57epk1qWdD6uk0XARQmius\n"
|
---|
75 | "AYfMKKvc9Sm1H/neHYtGCZlDWjiX7XOaSflxfvtHPt41Tw1LR/Fk07ydINiYnp7G\n"
|
---|
76 | "puwuYNK+tC3J9evYlLnBIocXu9ALTgAp3aFermJInoxJ+2omsG/tBX4fQSYz8N+B\n"
|
---|
77 | "oe9I/QimIAVsm4qun+2w1QZu1sR7EVEYoN959NY7ctlqDnOr8TdjY+fvknm5hXBi\n"
|
---|
78 | "7uTb5oJEmOwWZXZ+GwK6C+fwPKTO15EUIBUSlWR5wbX0P98SGXnxyYXjISp/pTVE\n"
|
---|
79 | "Qh7jTGAZROoYJUxwuJWVOmqa0hZ16GAOI/6RDlBsI1BMkdBpJCwGLFHrTfVy+iLe\n"
|
---|
80 | "LaMK2eORCpwmAgZL09k4GO7bILZmTBshLVxsKRlJZOEabaPgSdcV2LSagQqNIfcd\n"
|
---|
81 | "kRpKqKCq4zEs5PEumVFpDb8zlSOzRMqpTiQva2DHIe1Tz2JTCBjAAxZSokDjRM17\n"
|
---|
82 | "DQFjNTdQglhAWmFEGKge/gX/4FhmW9z8TgspTLQKuItBRaUpNaYPGKRjjpmCVOEi\n"
|
---|
83 | "41IBZiGYxaqhqSsMVYZlIgI6Iy5gA7Aex06ijYW7ejO5vrnRls5UWg6NIFI0CVcx\n"
|
---|
84 | "4S6YAjH/MsMqrS8KuI4Q98vKPyTpU2D3qPQRFc/YLq2OfSUSUQKCAQEA+36Pfe5b\n"
|
---|
85 | "xL49jttIdktVOLOWum+0g5ddANfMaTmDAR1QadDx97ieu7K1YDeHKhFsU5AClUZO\n"
|
---|
86 | "BKkmagk+ZdMcMg3l05bCXYnBfio4jN5aMA8bGNewPm2y4XTacWGcA9Vk76RWIDsS\n"
|
---|
87 | "mYM56iZFwwYlDckUIIx+fQ+H7u61CzVXvDBB9owo+2SJwduRuNac+pMktp6qfNod\n"
|
---|
88 | "vDASsusmO7JwHLn8HHItRa/GAjKrXkQNPQjSbJH1Y/e4F/3Z99M9rc6XzdzllbTg\n"
|
---|
89 | "M7+3mF28BPQiJ+9Wz2CJ7BZRGMnuYQx/wRLvJqLBuUuxc+DGmjJhDH8sO5nHxbyh\n"
|
---|
90 | "/q8vaMAoYo7nTQKCAQEA2PU2cHivsG5VFvKalsFcG4OfE7nQQ2ORXpnQQgBF8KC3\n"
|
---|
91 | "me31dwdKb0LJayPBx9FlmQQ5YaebFdQgZNhHwJBJcNIBb8W92kgeFJmYt/OMIeDS\n"
|
---|
92 | "6W7EEaPMkAk5nDp9ulNZ2kRUNgC+ownST3snIgLeehW6Yod6hbh3DzBTFbCqpw0L\n"
|
---|
93 | "uqu6XsSGn+Fy4NYTSHFVb8k8HlER6qoEKrk2A+ng+DyUvldLVF3fPPIcIhqWp5Jh\n"
|
---|
94 | "8/Z2KZb49eOkRZoobYl0jq2RXA6ocVbYEH9+n4wUBoOJG4B+ePhdUwdhtBQ21n3g\n"
|
---|
95 | "YRyYA1124FLVDEr/xEIEaahGkFScUfprKEJCH8KF0wKCAQEAyJVCgOARFTPeCQhg\n"
|
---|
96 | "HOksiVLDDuN1B9c7eCalg+84yzTEJAFgW4FGKNH500m2ZhkLWwJq7P/rzc/TMZM5\n"
|
---|
97 | "zyC3RjzLZxzA3LW4O5YVEFVvfREvPXsZuFDp8OOwLen58xzJqlBZ2M8EoKeHE3d/\n"
|
---|
98 | "AHLwLrSHdwZXBAvVEP4WK2BaH2Al3Cwhq4+eR52F9fRFs5yUFYsq0vVr7eIxp73g\n"
|
---|
99 | "+o/w1xiHOXDfJstwk+QxxbdlD57vpWQsYZT7oTb4F67FbNBvRuO9wM9IWj24gq+P\n"
|
---|
100 | "/Cty6oL7q96FYmTSPYEgvQqpAibF0vzQoab7Wz6VZ/pyaPMtJkQaj11JnsW+fD92\n"
|
---|
101 | "dlUfqQKCAQAXE8Ytoni1oJbGcRnGbVzZxF9YXsxrTpz43g2L57GIzd+ZrPkOJyVg\n"
|
---|
102 | "vk7kaZJEKd7PruZXn9dcNAsaDvNa5T4alQv4EqWGIWOpt0jKUEqYk+x7Tf/nDHBG\n"
|
---|
103 | "5eRN3N7gwdrt35TBhcTBXNsU/zmDYaC+ha8kqdp7fMqVQAOma/tK95VGztttFyRm\n"
|
---|
104 | "vzlT9xFoBD4dPN97Lg5k0p7M2JSJSAhY/0CnGmv11mJXfj1F12QtAOIQbCfXdqqW\n"
|
---|
105 | "pRclHCeutw9B2e57R0fdfmpPHvCeEe1TYAxmc32AapKqsT9QQ1It8Ie8bKkyum9Z\n"
|
---|
106 | "nxXwT83y1z7W6kJPOeDCy4s4ZgvYiv1nAoIBAQCgNGsn+CurnTxE8dFZwDbUy9Ie\n"
|
---|
107 | "Moh/Ndy6TaSwmQghcB/wLLppSixr2SndOW8ZOuAG5oF6DWl+py4fQ78OIfIHF5sf\n"
|
---|
108 | "9o607BKQza0gNVU6vrYNneqI5HeBtBQ4YbNtWwCAKH84GEqjRb8fSgDw8Ye+Ner/\n"
|
---|
109 | "SnfR/tW0EyegtpBSlsulY+8xY570H2i4sfuPkZLaoNAz3FvRiknfwylxhJaMiYSK\n"
|
---|
110 | "0EO8W1qsBYHEJerxUF5aV+xjj+bSt4CCLEdlcqSGHKxo64BrWC2ySPKmMBXTJsjS\n"
|
---|
111 | "bbHLyFzI7yjdUnzhcCK2uS4Yosi5F02VUiNkW8ifTa+D/Wv3lnncAT1hbWJB\n"
|
---|
112 | "-----END RSA PRIVATE KEY-----\n",
|
---|
113 | "-----BEGIN PUBLIC KEY-----\n"
|
---|
114 | "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA1SOurMTVz033GGi+5VrM\n"
|
---|
115 | "b0SnU7Dj49ZQCKSuxaSFK4tvbZXQBRSgwC1PcQVyt3GdoC71i3O4f9TxaA870icC\n"
|
---|
116 | "IY7cqf4LKL9uB5Vga2SNMfx3+KqcJVt9LFsghXfLocdfV1k+xeDVGcSP7uUvnXoI\n"
|
---|
117 | "ZyeS8puqoRYNiua1UT+ddXwihTId+6O9Q8IxcCPWkqW89LYBQVFqqMYoWzNcbEct\n"
|
---|
118 | "Y6WpPzZk3er+AvMekBD409LbtT7jTrzIGd6eQ0aF2MyVA6lOwe3u99Ubo/FTpule\n"
|
---|
119 | "/FQ5LXaEmlHPfDbIw+LRArdYgjoQU9l4SFajm0VbIKd2LFn5SRXHTbtAoKX2zpao\n"
|
---|
120 | "i8GF3u8VR/EmmTPYFHr2gUoLuyeTaY56OG/5ns7N/NRzOX1d1lNRFcQYNCXPEtqa\n"
|
---|
121 | "UfUfMJU4Jqp1LOEcd1xMkOUh8lc7DyvUfhry+SAcxB5SxcyjdWEXpj4G12/N3f6v\n"
|
---|
122 | "sRoZNTFt5j0hsbiOAOFykgN0a2OF77bsd975e1mxkqXJ9A0sbB8EXsD2PSrUZ7Pt\n"
|
---|
123 | "+T9CiQGOjqVUg2Vr1jevcQRHe5ed/R+B2jp6MjYjbr7cKqcXaRxEprGl+U5kIygq\n"
|
---|
124 | "l93DTgQaXwX/ZjXmwjXvQ0W4OxxexqyW6YvDBYeNKxstuM5qfgzYf7FD/8lZYkyM\n"
|
---|
125 | "AXELgpCqC92xlTbWpRVNpXcCAwEAAQ==\n"
|
---|
126 | "-----END PUBLIC KEY-----\n",
|
---|
127 | NULL
|
---|
128 | },
|
---|
129 | {
|
---|
130 | 2048,
|
---|
131 | "-----BEGIN RSA PRIVATE KEY-----\n"
|
---|
132 | "MIIEogIBAAKCAQEA06LAmfLBnRldEQF6E9CcMisCiaaDco0fYJvu60jkSBiA29k2\n"
|
---|
133 | "Ru7LzTF6ctNXkC25P4RC25RjOYJbC0iS5YIR7VYFP6R505zDWs8vONeFchdQpfau\n"
|
---|
134 | "TVjpgipIFovNGEUOGgXKD60n8txceuSygA3fg80movXmI7O+QLyrUkvFx2onDdVM\n"
|
---|
135 | "Vlt8uhBwv8h62mJArienFDbNyQcmj47Y5pxkBRrcA8qnti+I3I3yA3kslq2O0QtN\n"
|
---|
136 | "LHA7ttFYjieCcVv7pm/5g4kI2XyPv56RSem/RNsEv/qoK+g/h+b2C0sVO7eUyM6n\n"
|
---|
137 | "x9VT8w+ODunnYWs1HiAGAhzj7NhsnJp0gm88KwIDAQABAoIBAEvePnlx4yK0Yv6j\n"
|
---|
138 | "ruXHlRcPABvki57XJHZ3sBC80sldr2Qg3CpVlM38fM8JIIzZN12jxmv9KA0HxCep\n"
|
---|
139 | "Xq/UDyUr/zmvdtT7j7TQLTeNW5No9EpqwlWMGDnHeoxKlb2rk8CUbrlr87RGdwi/\n"
|
---|
140 | "T5ZEYupW8xDcYiJOX1fJywj3jPFNX70Iofirz+twKJuq/pT/It1b3VKVBZb5qSW/\n"
|
---|
141 | "kfMMnJ1kELEAk7ue1sXm5QzF0/CizHNalEGJjuKauH21iCy1BGuJ00F31iploB4f\n"
|
---|
142 | "lqzXpNbDGyFWfQo6bZwduyrdgBe2dFt4mg5htknJPo4oSl+oLi4HewhwO3jpt06z\n"
|
---|
143 | "KRoT8XECgYEA7vVX6QwGbfnK/+CePiTBrD3FOgzfDagn5jSrvH0Km/YDVIa/6T7k\n"
|
---|
144 | "9M2qw5MP7D9gWPDkS7L8hL/YxCSP0mYf4ABp89/n++V6ON7tEjyA3SixXpCqLYUd\n"
|
---|
145 | "nSYl/ygJblEujFvhVtZaKyGpTMQXyJpCbV3ZdAar8Mg2p36MusitsscCgYEA4rqU\n"
|
---|
146 | "oTurBhXwGYzFT92OA44aFpJgh/fo532NOpayPA/eeY0cea+N2TLZYtUmUWDAaslu\n"
|
---|
147 | "3GG+VCHzYZCwRW5QTDJjZUB7VM0tONQDXPa4TLdI0GSDxnX7QXwyE6tk7JMTJ6fH\n"
|
---|
148 | "ZuC/Kt84ngFerZCgr5/JSy2jVfBs2sv0fdjoh30CgYBKvwvkphJMzFoneAeHwM+k\n"
|
---|
149 | "JR5Qbj5Hc1YnuEoQB70N1AJuqkfVmgrcWIkV7CaK67gjmhaPZ0l97NTNZfJnCfLm\n"
|
---|
150 | "irqZwmw6aym0KGdX0P0uMNBqmC3jV0RQJ+Ky0b9BdrtsxEDUfPBvlXPzw1L9OOOW\n"
|
---|
151 | "ekjO9ldKVhZihj9XHfbXeQKBgCh/XzD1cXTi0kIeDNhZIJat+Sby+l8O/wDqQiGm\n"
|
---|
152 | "7SshQoG/nMh3fQTAumeW3wNGHth0JmMi6lYowko5B+M+8wTJM0vQmrbo9xzhccBX\n"
|
---|
153 | "KVA6pLzkV01JoZluz5sH0D0ZgCBjLZDIsBy+RmSipgCmhq0YA2J0QmqFSUxDheY8\n"
|
---|
154 | "qjwZAoGANbzLzEI9wjg7ZgRPqaIfoYjTimJMAeyesXKZMJG5BxoZRyPLa3ytbzRD\n"
|
---|
155 | "B3Gf0oOYYI0QEEa1kLv7h1OUCjVRJnKcwsSIU9D1PDZI5WSP4dyoTUqZ/x7KbOZ5\n"
|
---|
156 | "9Ze5jxhl4B1Kr+WvZ3VBWbBBCuX8bJzOvh+C8216TWhESaz85+0=\n"
|
---|
157 | "-----END RSA PRIVATE KEY-----\n",
|
---|
158 | "-----BEGIN PUBLIC KEY-----\n"
|
---|
159 | "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA06LAmfLBnRldEQF6E9Cc\n"
|
---|
160 | "MisCiaaDco0fYJvu60jkSBiA29k2Ru7LzTF6ctNXkC25P4RC25RjOYJbC0iS5YIR\n"
|
---|
161 | "7VYFP6R505zDWs8vONeFchdQpfauTVjpgipIFovNGEUOGgXKD60n8txceuSygA3f\n"
|
---|
162 | "g80movXmI7O+QLyrUkvFx2onDdVMVlt8uhBwv8h62mJArienFDbNyQcmj47Y5pxk\n"
|
---|
163 | "BRrcA8qnti+I3I3yA3kslq2O0QtNLHA7ttFYjieCcVv7pm/5g4kI2XyPv56RSem/\n"
|
---|
164 | "RNsEv/qoK+g/h+b2C0sVO7eUyM6nx9VT8w+ODunnYWs1HiAGAhzj7NhsnJp0gm88\n"
|
---|
165 | "KwIDAQAB\n"
|
---|
166 | "-----END PUBLIC KEY-----\n",
|
---|
167 | NULL
|
---|
168 | },
|
---|
169 | {
|
---|
170 | 1024,
|
---|
171 | "-----BEGIN RSA PRIVATE KEY-----\n"
|
---|
172 | "MIICXAIBAAKBgQC2wFEkDX17SxuhH4jrSl/+lSEEXI2YGzXbDnsroXMjAa6pGj9f\n"
|
---|
173 | "7+VOGvnBTJnT2FubDSvpaXMIEO0PTjMpS2fKKdn1jljAj3vfF9HpyyKOBgLwY1Pl\n"
|
---|
174 | "fwj3bNPUomGZ+sgigNYWJ4+lXlSxJ7UlTQuQd7PiRsgCEIRny+5thH/rSwIDAQAB\n"
|
---|
175 | "AoGAEzUTUh642YSDWuPdmB0xCajS14qCt0Hk3ykeeO93Em7S1KMVlhe4mgTryw0p\n"
|
---|
176 | "/cH3nsw7mUSj+m0M/VbSubxbJA7VMVoaM3gnnHAttQVrGHxKMfA2Yupp0gLB9SFa\n"
|
---|
177 | "W0oLO2NNz9IElQfPYWsir2VSqMbgil9srHxNMRMjcTv0O4ECQQDe8vstmZ3b2q5u\n"
|
---|
178 | "L+Fd5pGF+rK919Bh59Nuvv3xPsJVoVjcfRJKGLKVMe+AK9YicM2jqqgV9UQ7gSZK\n"
|
---|
179 | "z5jxS1YDAkEA0dfOsmFFGrAu4vAJf/YxJm/G7DyinM4Ffq1fVxCIZGOJxU5+EtH3\n"
|
---|
180 | "YTRA0U6kM77O9i4Ms2LM9agSz76hdPjXGQJARVxowo4JK44EOGmS/qit23XcR+2t\n"
|
---|
181 | "edgq0kh/Lp+szAEvaSFMIFtAq+PmNATvULWxdFqygmpUuQJ8DEg7t84NSwJAfMS7\n"
|
---|
182 | "UpbBVvAAwNCGZX5FlRwLA/W9nkxlOf/t2z+qST5h8V4NWjVbyIEgNRN0UIwYVInm\n"
|
---|
183 | "5VZOlZX8sWcgawN2KQJBAMvkCsY6sVjlK2FXA9f3FVHs6DT4g2TRLvCkwZAjbibY\n"
|
---|
184 | "qy2W1RrPdtPOKXfr251hAlimxwcGXwTsRm07qirlQjE=\n"
|
---|
185 | "-----END RSA PRIVATE KEY-----\n",
|
---|
186 | "-----BEGIN PUBLIC KEY-----\n"
|
---|
187 | "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2wFEkDX17SxuhH4jrSl/+lSEE\n"
|
---|
188 | "XI2YGzXbDnsroXMjAa6pGj9f7+VOGvnBTJnT2FubDSvpaXMIEO0PTjMpS2fKKdn1\n"
|
---|
189 | "jljAj3vfF9HpyyKOBgLwY1Plfwj3bNPUomGZ+sgigNYWJ4+lXlSxJ7UlTQuQd7Pi\n"
|
---|
190 | "RsgCEIRny+5thH/rSwIDAQAB\n"
|
---|
191 | "-----END PUBLIC KEY-----\n",
|
---|
192 | NULL
|
---|
193 | },
|
---|
194 | {
|
---|
195 | 512,
|
---|
196 | "-----BEGIN RSA PRIVATE KEY-----\n"
|
---|
197 | "MIIBOwIBAAJBAMgbhgcN8LxMNpEZgOC3hgI61pAwSxn4X8rSBHyTt7pfqbU0g2Tk\n"
|
---|
198 | "PsNT7J6YS2xN+MwKiYNDeCTjRRbt67o1ZscCAwEAAQJBAKyXOKEq/+CYZ1P8yDCJ\n"
|
---|
199 | "eZbAwsD4Nj4+//gB7ga4rXWbeDbkEFtLsN7wHIl1RQobfddStC5edTTbVJMk/NmX\n"
|
---|
200 | "ESkCIQDpouOkB/cJvxfqeHqXuk4IS2s/hESEjX8dxFPsa3iNVQIhANtDCGPHhSvf\n"
|
---|
201 | "za9hH/Wqxzbf2IrAPn/aJVNmphSi6wOrAiBj77IR2vpXp+7R86D0v9NbBu+kJq6s\n"
|
---|
202 | "SF4kXHNNgJb7VQIhAKfuFTTmkRZjWNNj3eh4Hg/nLaBHURb26vOPgM/5X2n1AiAo\n"
|
---|
203 | "b9m3zOpoO/0MAGCQ6qDHeebjvd65LSKgsmuDOSiOLw==\n"
|
---|
204 | "-----END RSA PRIVATE KEY-----\n",
|
---|
205 | "-----BEGIN PUBLIC KEY-----\n"
|
---|
206 | "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMgbhgcN8LxMNpEZgOC3hgI61pAwSxn4\n"
|
---|
207 | "X8rSBHyTt7pfqbU0g2TkPsNT7J6YS2xN+MwKiYNDeCTjRRbt67o1ZscCAwEAAQ==\n"
|
---|
208 | "-----END PUBLIC KEY-----\n",
|
---|
209 | NULL
|
---|
210 | },
|
---|
211 |
|
---|
212 | /*
|
---|
213 | * Keys with passwords.
|
---|
214 | */
|
---|
215 | {
|
---|
216 | 2048,
|
---|
217 | "-----BEGIN RSA PRIVATE KEY-----\n"
|
---|
218 | "Proc-Type: 4,ENCRYPTED\n"
|
---|
219 | "DEK-Info: AES-128-CBC,86B32E02F476832DE26291AEF884BFB2\n"
|
---|
220 | "\n"
|
---|
221 | "3vqVAOubNaajTSUj/t0ueXRG11kVOCbQkj6AoB4bO+xYUabtcisM4I34It6GN1ZJ\n"
|
---|
222 | "yXv2DcCE3At31LvvqS8bYGvRhY+oPpCUkC4DX+RX9Tkw5ivl1F9pv/rL3nv2F3LX\n"
|
---|
223 | "KxMUcygwJOG2ItPu+vLI0HDYGn9reR+6boriwQfU6S8An4C6LrIZK0hUN0Bpr6W+\n"
|
---|
224 | "JyTX9B3Tgy/BldW6yziRzYUZHnnKEKKacvHP5l0n/6nn6iFSJSFmnzvsedwOvUI0\n"
|
---|
225 | "eHQ1LvbfQnd5yIalQ5S8UkgpKb5S4s2U0AthAC67m+Nc0E8NcbCMY1JT4FlsWVLD\n"
|
---|
226 | "GqWmjKhwEBgoPRROEiq39KgPnoxnCEIOiQ6l8kZ0uvqlCHhWM4b1UVqb6hyrmY32\n"
|
---|
227 | "SEBiwRqFewVYzPFI1+vT3CH/BJcXCBISNj2c4OZDqhmgncGWpLwqU1GIlLp82o3l\n"
|
---|
228 | "t58WfNuqUM7bc/T6cIKAI2JoR2R96Zo0cgL+419msVUdZXhM/10K3W+wbHUVuSqh\n"
|
---|
229 | "iDOCJhXWIhu47kjbCOh7OvpOtOPayWBLQiGh1Q4+WQU6t6Vdr/i71dKP0/P/QHwk\n"
|
---|
230 | "ELNaWv/RLbE6PqKuXcjtoIqzynTvS/6C7PLEKEX3PB6kZNV+m7C0Dxu4BFj04vtx\n"
|
---|
231 | "5CL71sGaB1ETYUdMRSvCa+f/1zwUXngmozUL+D4PkCz/vT5FYKElWt7RBMt8N+rC\n"
|
---|
232 | "Iga+YqqvnuSPrxGXLCGZBuI2V+0BwG1pUHwk/C3uo/ggacj9+E/Oiei725cEI7H5\n"
|
---|
233 | "FnJdFrubYsoGtyII4H1MJzp768s+bD5Bs9m/6a1m+HtzwjxNt329MyAW4DixNGEp\n"
|
---|
234 | "T1e1e6DMnYU8XlxHkRu3IkgWjY3GPw+mfnxT5ThM16w3XC5bvRPMbIukJxFE3yDL\n"
|
---|
235 | "jsUeVhA9NHBZbrFIjLwBWoxqlmgZjJrMFE8pcdFbNl2nKvOK0DHw6Tc93Qz0pg4q\n"
|
---|
236 | "tvt51k9FR4WNmUY8uElmkhepAAAyzcGAHqxvrzkBmXOh76i5+j32swmmaTdx35I2\n"
|
---|
237 | "GdRPAl75JEKZVKgHZOW6f/eCWdY7z0GAOnn+fkEzxAufU+DQAOuNkgVKySTyov5J\n"
|
---|
238 | "v3aaMBuyrxyhgqt+k7PahlRE00S84+QvEgeiTmP/Beyd2GHwKiQ0G/9mwkVjSB1Y\n"
|
---|
239 | "rFw0pzzud1JcYy3uFKZB+YHrV4YbfUHmJR0CKCqHUD2R95rNBIcS5ZpMm1Ak0d5E\n"
|
---|
240 | "jAQsYlGIbWGx6aNmmf7NWacRpwVPnViU30cumeQxbCLQ2Mfb9N2zuwgplOSNp/2m\n"
|
---|
241 | "KRU7jRs3ZLD21iplVBbmmvpC8HyJ7605bDWBw+eVaS92sEmA5lnD3uRil+7/tM8C\n"
|
---|
242 | "rXrnU8h7vFBSWxcVM1kEiocE8eetSMczI7uA36KWbAWcMlG6hCyQSLuGkxGSZpaM\n"
|
---|
243 | "Ro+IJx/vHNvnVj2ObqHCmSIE0+VkeyV3SlF2MqrdHNss/iOUBYFsE9zVN/oQcibt\n"
|
---|
244 | "dXMXRN81KyHg8keNiwdd18ZWVW2+lix1mbPPgwd5iptnT4Qyder5HJroV52LdRZc\n"
|
---|
245 | "nf3XjVzVp7tTGjGi9T/FvkpQR4tkU+Sl17qDrw9H/Y7k1j90zWFn8kykpwSRt0bV\n"
|
---|
246 | "-----END RSA PRIVATE KEY-----\n",
|
---|
247 | "-----BEGIN PUBLIC KEY-----\n"
|
---|
248 | "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvvqfSDO1HN3Els04TSGE\n"
|
---|
249 | "sJ0Himl934+ryfNXYIRWkq91i5+rENyZ475XBMjg8fblhvHy7vy4GfUo0PKVXxWS\n"
|
---|
250 | "nPqOPSLEP3r2vsCX5l+KRBnGi4TeGWDTB8R6oA6HKY5ybtzUr1MHKwa7K7YJu7M9\n"
|
---|
251 | "DW7n2JPLRajUMioO9wbYK70qlbxjeOu0V62D68fWoa3alSWMlMBv9KZW9g2oJHQy\n"
|
---|
252 | "mUO2OdJFdyaah3z6vTKtzxmZ+NB4iwIjD6Go1CMj+FOjjjJb3EgUOIZAsRz/+9MF\n"
|
---|
253 | "S3cRfh/8u9cZQ20Woh5vmw1anXxbwk6Z8uIFYrdgcY5G7ak0/3VukbP7VzvG+voY\n"
|
---|
254 | "AwIDAQAB\n"
|
---|
255 | "-----END PUBLIC KEY-----\n",
|
---|
256 | "password"
|
---|
257 | },
|
---|
258 |
|
---|
259 | /*
|
---|
260 | * PKCS8 Test Keys with and without passwords.
|
---|
261 | */
|
---|
262 | {
|
---|
263 | 1024,
|
---|
264 | "-----BEGIN PRIVATE KEY-----\n"
|
---|
265 | "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAK4uHX+XRbLQ7dGm\n"
|
---|
266 | "sE1IqNDi4Obf7WS2TwfklmterJvCMrN3DxDAFq9et5j8kFRtI0Lgbc6sVAxlSkaw\n"
|
---|
267 | "+0LltbkC8JX0cjPSIlozzcZn+9dQ+m5rVLDl3AaV3kBLrYpnNggdTRiHuVbNPqZq\n"
|
---|
268 | "0CNDMxCqHpqRjtIOuoKukcOZasD5AgMBAAECgYA4IlKNaTIkM+NBGshcz9rgHw4+\n"
|
---|
269 | "OdKnD34e3BOCHOvh8s8mOWuYiV+GOy9OVa8qFlYz2mJpJe6cZBRw/d6sK53Jrzc1\n"
|
---|
270 | "ULULW9YNqgkhdhTm0z8QolYjBU+qp9pAXhh29tCdMxgCWAsiVR9jsnFtPQX4QEmM\n"
|
---|
271 | "9t+65ghTFQWtQXMqpQJBANly600i4GYoxvzvp67RvUkmnG47LvwuVRMwUAmAX6QP\n"
|
---|
272 | "Ww5q6aJd9HnHttLsNHxgX49aVxgpFu2uJI2SwSV3qwMCQQDND2kty83UXW5RahIt\n"
|
---|
273 | "BXAY8W60Itw6+bPLg3P4IixDCoHphnLqkz5ZT2NxxPsAPGeaFZDVyNs3Hgasnd8V\n"
|
---|
274 | "V8VTAkEAi4KWgrvQmtqoqFkeDSRVvBwAmxxvja4wOQpzH1V0hy6u7fYcBWcgVg2T\n"
|
---|
275 | "N4oCNpYiWTfNzxt1sXJb01UHhIFdfwJAO8ZiQpdGSMFzhwgEhFsxchPu0VPYHtjr\n"
|
---|
276 | "MEgBZjOP83r8o7YtiXOimSYrNt7UzBzPlnry3V7PiCGYkHj0rqQHQQJBANi5N5X4\n"
|
---|
277 | "g7dNDsE5i1B0JsQ4ru8qE60ZtoOOCwNjwiI/IIsMVW2KqhTBynEYLnWolkRRogEF\n"
|
---|
278 | "ACoRRxUBhj9EefI=\n"
|
---|
279 | "-----END PRIVATE KEY-----\n",
|
---|
280 | "-----BEGIN PUBLIC KEY-----\n"
|
---|
281 | "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCuLh1/l0Wy0O3RprBNSKjQ4uDm\n"
|
---|
282 | "3+1ktk8H5JZrXqybwjKzdw8QwBavXreY/JBUbSNC4G3OrFQMZUpGsPtC5bW5AvCV\n"
|
---|
283 | "9HIz0iJaM83GZ/vXUPpua1Sw5dwGld5AS62KZzYIHU0Yh7lWzT6matAjQzMQqh6a\n"
|
---|
284 | "kY7SDrqCrpHDmWrA+QIDAQAB\n"
|
---|
285 | "-----END PUBLIC KEY-----\n",
|
---|
286 | NULL
|
---|
287 | },
|
---|
288 | {
|
---|
289 | 2048,
|
---|
290 | "-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
|
---|
291 | "MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQIRFetWFFFIb4CAggA\n"
|
---|
292 | "MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBAZMr0Lq1s+olU2jUY8MuQJBIIE\n"
|
---|
293 | "0ICOZE6GhPCQbUSudbBYTG4zBRGhJOTeGF43c3pqi6UNS4qWK9IQ3B5hm618Iof0\n"
|
---|
294 | "YUnCDKy9G7TPMwP+8pcybFXuvWo1yeJcVGNalBq/LmUG2RBJ3hh/IikDnzj2jq1u\n"
|
---|
295 | "QKFTgl5yZ41bC75d81fdg0CpYqIGOjLdQcUJmVk+lKggWcN7KuqPj+9FhCoRyjIp\n"
|
---|
296 | "UyLYQQ8E0sb7tk0gJoi6VHddTYpLEDiFzGqXP/XWykCFHx977sbRuOymrTF3C3OZ\n"
|
---|
297 | "X5PSkszydSBzomPl1MnmiMjAmgc3j6EABUpzjaUZ2l2xxeM9r/c076zSpHdcBFus\n"
|
---|
298 | "Y3pA9Hm9HvV2q+1FHHNk90vZlXWtyTh8tSJvT3WF63kYMyIXXztovldjxX76fxB0\n"
|
---|
299 | "c5K0E9FH5sjv0R4AfMf4CMsP5InGfy2zICRwi+xvp97lq6nEXjIqiePyNTUA3QAy\n"
|
---|
300 | "brZtzM67KxFL/TuV6Y20DILAPlWZe3C8KFpFeHEi5yddi0VikzQVl1X/hieCt4SP\n"
|
---|
301 | "aTdd+MCn3XIu+58RK6UYCVCxbH9j9iZCznOfWLRMpthvoa9SO8M8DTFlx/bptClt\n"
|
---|
302 | "IKUnsQgBpvT3+xzpJk4sQyD4aZDcDMQeNfDr/1KyYMEjaqvGMqKfLed2HLDHdD9f\n"
|
---|
303 | "rsg41wTCqp/draUh2qxa7pXkK0KcNbH4hLH//pduaLubHmOPofLvprVIISyOtspN\n"
|
---|
304 | "tsPtXs43Ta4dOQWLg2Q/lwlo0psi1im/fHKyr7rpMdUa+dRGX8H4tYsFJufHzVjr\n"
|
---|
305 | "rQrKDHPsNfhy+JuCfQu/8SdZCXwcBxxeSlam5EgtlfsTDC+zIP8dDHaOWsDRm+k3\n"
|
---|
306 | "ryKTSn84LBQLWzc3RhZteAlzDHcmrS/MmF4yfpgSkFI+aUF5+XPLqoYVsoVKQ5bL\n"
|
---|
307 | "NnA6xJBkXVtzNZUYH3cHoiAOATlhHRFtoWrKoEQXlCNvvTCiBGoMPfjpnTy3u/kS\n"
|
---|
308 | "8JaUsJLvDFQBFPSxdYA+w/zb3zy0Nh5s3R9D6IkrH0X2mk8JhABYNzDIDYlS2Ioz\n"
|
---|
309 | "ARpmwuZwPUG1iSzamYZCt2OVd1acPexiwTATihfPVT2RFbHET9+e7NX/5TFnGP++\n"
|
---|
310 | "4o6mckiD5c9QmwE29FLTeiqwKvLweLrrF6/1/S45/okibqXHgh7O567y+PSMmjk5\n"
|
---|
311 | "L0azEmv6UIs5z4FNvDxS5++b3oqUMu+oazQP1aDk0H/8xJaDFrnOKWL9h8waeBn7\n"
|
---|
312 | "JBuuIFKqRb6S9H0ZPb1R7Z9BVuUil76nc4zr0kLNdJ8dq2l/kcqIIFrtVJX/INaf\n"
|
---|
313 | "gYvlsIYXpb/IhBZit1GJxwi8kk29b2QSyDW6CNNi3dC8Y1p9jiLejqFM4LQL/HNr\n"
|
---|
314 | "atc1pUBPePK1ZHJ0OLyVthJYXmn8v+M9eHfptQzBZpILTZZK719uOtHloPrI64LY\n"
|
---|
315 | "iO00glzBju2W1yDF6cTgmWQEigWno65Is5pjN5ByMf3ouHM8qJFIhTEqCpAY7cQQ\n"
|
---|
316 | "2k6o7dqAcQm7Q+BvhfsWcPWq/GH/OOkuUDqQaK1YDA+lUj9uyrxm9AlrDtUjezLE\n"
|
---|
317 | "k3IT6ZiBVrPlKWCMbT6ajm9ti0RuCRnZfrrLn2gu16weRtaNeVyza6D5wn+eKXmE\n"
|
---|
318 | "5dnugDd6T+QBX/3+WLaXTL3l/tj7i9WwNJU4uqW7y6+P\n"
|
---|
319 | "-----END ENCRYPTED PRIVATE KEY-----\n",
|
---|
320 | "-----BEGIN PUBLIC KEY-----\n"
|
---|
321 | "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp6CMrt0Z/k5+c/7C3oWz\n"
|
---|
322 | "bLBmE4fttE84EZsrwB/ZDhMBQDsVF/GMePj1e5zrxnVq6GZhcNbcJTqHp0mWb+K5\n"
|
---|
323 | "HMlAihPKYlswJQtkVgp/czbdXwt3MI+D4ifUiq4v8AMrJHW+AYd0GYKzYma6LGVj\n"
|
---|
324 | "75Bue450bsLocMKwB03iyFE8SBwzGSj9jwJ9UYBvVUnNsutq6nCPTj1bM6naFIHO\n"
|
---|
325 | "Y+cozHIrKyvHGHoWBVUqKARlNT3TtbTyGxaT4QyZj8Pm9jB5Np6CrF7nmV936Q3A\n"
|
---|
326 | "3CHji8BbhfcdZ/9s53wkSwztfpe8NYh1/RiLZtZdky9E6Q67dt3h4bKHsKRFi0xW\n"
|
---|
327 | "jQIDAQAB\n"
|
---|
328 | "-----END PUBLIC KEY-----\n",
|
---|
329 | "password"
|
---|
330 | },
|
---|
331 | };
|
---|
332 |
|
---|
333 |
|
---|
334 |
|
---|
335 |
|
---|
336 | static void test1()
|
---|
337 | {
|
---|
338 | RTTestSub(g_hTest, "Basics");
|
---|
339 | int rc;
|
---|
340 | RTCRKEY hPublicKey = NIL_RTCRKEY;
|
---|
341 | RTCRKEY hPrivateKey = NIL_RTCRKEY;
|
---|
342 |
|
---|
343 | for (unsigned i = 0; i < RT_ELEMENTS(g_aKeyPairs); i++)
|
---|
344 | {
|
---|
345 | RTCrKeyRelease(hPublicKey);
|
---|
346 | hPublicKey = NIL_RTCRKEY;
|
---|
347 | RTCrKeyRelease(hPrivateKey);
|
---|
348 | hPrivateKey = NIL_RTCRKEY;
|
---|
349 |
|
---|
350 | /*
|
---|
351 | * Load the key pair.
|
---|
352 | */
|
---|
353 | rc = RTCrKeyCreateFromBuffer(&hPublicKey, 0, g_aKeyPairs[i].pszPublicKey, strlen(g_aKeyPairs[i].pszPublicKey),
|
---|
354 | NULL /*pszPassword*/, NULL /*pErrInfo*/, NULL /*pszErrorTag*/);
|
---|
355 | if (RT_FAILURE(rc))
|
---|
356 | RTTestIFailed("Error %Rrc decoding public key #%u (%u bits)", rc, i, g_aKeyPairs[i].cBits);
|
---|
357 |
|
---|
358 | rc = RTCrKeyCreateFromBuffer(&hPrivateKey, 0, g_aKeyPairs[i].pszPrivateKey, strlen(g_aKeyPairs[i].pszPrivateKey),
|
---|
359 | g_aKeyPairs[i].pszPassword, NULL /*pErrInfo*/, NULL /*pszErrorTag*/);
|
---|
360 | if (RT_FAILURE(rc))
|
---|
361 | RTTestIFailed("Error %Rrc decoding private key #%u (%u bits)", rc, i, g_aKeyPairs[i].cBits);
|
---|
362 |
|
---|
363 | if (hPrivateKey == NIL_RTCRKEY || hPublicKey == NIL_RTCRKEY)
|
---|
364 | continue;
|
---|
365 |
|
---|
366 | /*
|
---|
367 | * If we've got a password encrypted key, try some incorrect password.
|
---|
368 | */
|
---|
369 | if (g_aKeyPairs[i].pszPassword)
|
---|
370 | {
|
---|
371 | static const char * const s_apszBadPassword[] =
|
---|
372 | {
|
---|
373 | "bad-password", "", "<>", "really really long long long bad bad bad bad bad password password password password",
|
---|
374 | "a", "ab", "abc", "abcd", "abcde", "fdcba"
|
---|
375 | };
|
---|
376 | for (unsigned iPasswd = 0; iPasswd < RT_ELEMENTS(s_apszBadPassword); iPasswd++)
|
---|
377 | {
|
---|
378 | RTCRKEY hKey = NIL_RTCRKEY;
|
---|
379 | rc = RTCrKeyCreateFromBuffer(&hKey, 0, g_aKeyPairs[i].pszPrivateKey, strlen(g_aKeyPairs[i].pszPrivateKey),
|
---|
380 | s_apszBadPassword[iPasswd], NULL /*pErrInfo*/, NULL /*pszErrorTag*/);
|
---|
381 | if (rc != VERR_CR_KEY_DECRYPTION_FAILED)
|
---|
382 | RTTestIFailed("Unexpected bad password response %Rrc decoding private key #%u (%u bits) using '%s' as password",
|
---|
383 | rc, i, g_aKeyPairs[i].cBits, s_apszBadPassword[iPasswd]);
|
---|
384 | }
|
---|
385 | }
|
---|
386 |
|
---|
387 | /*
|
---|
388 | * Create corresponding signing and verifying decoder instances.
|
---|
389 | */
|
---|
390 | static struct { uint32_t cBits; const char *pszObjId; } const s_aSignatures[] =
|
---|
391 | {
|
---|
392 | { 128, RTCR_PKCS1_MD2_WITH_RSA_OID },
|
---|
393 | //{ 128, RTCR_PKCS1_MD4_WITH_RSA_OID },
|
---|
394 | { 128, RTCR_PKCS1_MD5_WITH_RSA_OID },
|
---|
395 | { 160, RTCR_PKCS1_SHA1_WITH_RSA_OID },
|
---|
396 | { 256, RTCR_PKCS1_SHA256_WITH_RSA_OID },
|
---|
397 | { 224, RTCR_PKCS1_SHA224_WITH_RSA_OID },
|
---|
398 | { 384, RTCR_PKCS1_SHA384_WITH_RSA_OID },
|
---|
399 | { 512, RTCR_PKCS1_SHA512_WITH_RSA_OID },
|
---|
400 | };
|
---|
401 | RTCRPKIXSIGNATURE hSign = NIL_RTCRPKIXSIGNATURE;
|
---|
402 | RTCRPKIXSIGNATURE hVerify = NIL_RTCRPKIXSIGNATURE;
|
---|
403 | for (unsigned iSig = 0; iSig < RT_ELEMENTS(s_aSignatures); iSig++)
|
---|
404 | {
|
---|
405 | RTCrPkixSignatureRelease(hSign);
|
---|
406 | hSign = NIL_RTCRPKIXSIGNATURE;
|
---|
407 | RTCrPkixSignatureRelease(hVerify);
|
---|
408 | hVerify = NIL_RTCRPKIXSIGNATURE;
|
---|
409 |
|
---|
410 | rc = RTCrPkixSignatureCreateByObjIdString(&hSign, s_aSignatures[iSig].pszObjId, hPrivateKey, NULL, true /*fSigning*/);
|
---|
411 | if (RT_FAILURE(rc))
|
---|
412 | RTTestIFailed("RTCrPkixSignatureCreateByObjIdString failed with %Rrc on %u bits private key and %u bits MD (%s)",
|
---|
413 | rc, g_aKeyPairs[i].cBits, s_aSignatures[iSig].cBits, s_aSignatures[iSig].pszObjId);
|
---|
414 |
|
---|
415 | rc = RTCrPkixSignatureCreateByObjIdString(&hVerify, s_aSignatures[iSig].pszObjId, hPublicKey, NULL, false /*fSigning*/);
|
---|
416 | if (RT_FAILURE(rc))
|
---|
417 | RTTestIFailed("RTCrPkixSignatureCreateByObjIdString failed with %Rrc on %u bits public key and %u bits MD (%s)",
|
---|
418 | rc, g_aKeyPairs[i].cBits, s_aSignatures[iSig].cBits, s_aSignatures[iSig].pszObjId);
|
---|
419 |
|
---|
420 | if (RT_FAILURE(rc) || hSign == NIL_RTCRPKIXSIGNATURE || hVerify == NIL_RTCRPKIXSIGNATURE)
|
---|
421 | continue;
|
---|
422 |
|
---|
423 | /*
|
---|
424 | * Try a few different boilplate things.
|
---|
425 | */
|
---|
426 | static struct { void const *pv; size_t cb; } const s_aTexts[] =
|
---|
427 | {
|
---|
428 | { RT_STR_TUPLE("") },
|
---|
429 | { RT_STR_TUPLE("IPRT") },
|
---|
430 | { RT_STR_TUPLE("abcdef") },
|
---|
431 | };
|
---|
432 |
|
---|
433 | for (unsigned iText = 0; iText < RT_ELEMENTS(s_aTexts); iText++)
|
---|
434 | {
|
---|
435 | uint8_t abSignature[4096];
|
---|
436 | size_t cbSignature = sizeof(abSignature);
|
---|
437 |
|
---|
438 | RTCRDIGEST hDigest = NIL_RTCRDIGEST;
|
---|
439 | rc = RTCrDigestCreateByObjIdString(&hDigest, s_aSignatures[iSig].pszObjId);
|
---|
440 | if (RT_SUCCESS(rc))
|
---|
441 | {
|
---|
442 | RTTESTI_CHECK_RC(RTCrDigestUpdate(hDigest, s_aTexts[iText].pv, s_aTexts[iText].cb), VINF_SUCCESS);
|
---|
443 |
|
---|
444 | rc = RTCrPkixSignatureSign(hSign, hDigest, abSignature, &cbSignature);
|
---|
445 | if (RT_SUCCESS(rc))
|
---|
446 | {
|
---|
447 | rc = RTCrPkixSignatureVerify(hVerify, hDigest, abSignature, cbSignature);
|
---|
448 | if (RT_FAILURE(rc))
|
---|
449 | RTTestIFailed("RTCrPkixSignatureVerify failed with %Rrc for %u bits MD with %u bits key (%s); signature length %u",
|
---|
450 | rc, s_aSignatures[iSig].cBits, g_aKeyPairs[i].cBits, s_aSignatures[iSig].pszObjId, cbSignature);
|
---|
451 |
|
---|
452 | }
|
---|
453 | else if (rc != VERR_CR_PKIX_HASH_TOO_LONG_FOR_KEY)
|
---|
454 | RTTestIFailed("RTCrPkixSignatureSign failed with %Rrc for %u bits MD with %u bits key (%s)",
|
---|
455 | rc, s_aSignatures[iSig].cBits, g_aKeyPairs[i].cBits, s_aSignatures[iSig].pszObjId);
|
---|
456 | RTCrDigestRelease(hDigest);
|
---|
457 | }
|
---|
458 | else
|
---|
459 | RTTestIFailed("RTCrDigestCreateByObjIdString failed with %Rrc for %s (%u bits)",
|
---|
460 | rc, s_aSignatures[iSig].pszObjId, s_aSignatures[iSig].cBits);
|
---|
461 | }
|
---|
462 | }
|
---|
463 |
|
---|
464 | RTCrPkixSignatureRelease(hSign);
|
---|
465 | hSign = NIL_RTCRPKIXSIGNATURE;
|
---|
466 | RTCrPkixSignatureRelease(hVerify);
|
---|
467 | hVerify = NIL_RTCRPKIXSIGNATURE;
|
---|
468 | }
|
---|
469 |
|
---|
470 | RTCrKeyRelease(hPublicKey);
|
---|
471 | hPublicKey = NIL_RTCRKEY;
|
---|
472 | RTCrKeyRelease(hPrivateKey);
|
---|
473 | hPrivateKey = NIL_RTCRKEY;
|
---|
474 | }
|
---|
475 |
|
---|
476 |
|
---|
477 |
|
---|
478 |
|
---|
479 | int main()
|
---|
480 | {
|
---|
481 | RTEXITCODE rcExit = RTTestInitAndCreate("tstRTCrPkix-1", &g_hTest);
|
---|
482 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
483 | return rcExit;
|
---|
484 | RTTestBanner(g_hTest);
|
---|
485 |
|
---|
486 | test1();
|
---|
487 |
|
---|
488 | return RTTestSummaryAndDestroy(g_hTest);
|
---|
489 | }
|
---|
490 |
|
---|