1*0bf56da3SHartmut Brandt /*
2*0bf56da3SHartmut Brandt * Copyright (c) 2020
3*0bf56da3SHartmut Brandt * Hartmut Brandt <harti@freebsd.org>
4*0bf56da3SHartmut Brandt * All rights reserved.
5*0bf56da3SHartmut Brandt *
6*0bf56da3SHartmut Brandt * Redistribution and use in source and binary forms, with or without
7*0bf56da3SHartmut Brandt * modification, are permitted provided that the following conditions
8*0bf56da3SHartmut Brandt * are met:
9*0bf56da3SHartmut Brandt * 1. Redistributions of source code must retain the above copyright
10*0bf56da3SHartmut Brandt * notice, this list of conditions and the following disclaimer.
11*0bf56da3SHartmut Brandt * 2. Redistributions in binary form must reproduce the above copyright
12*0bf56da3SHartmut Brandt * notice, this list of conditions and the following disclaimer in the
13*0bf56da3SHartmut Brandt * documentation and/or other materials provided with the distribution.
14*0bf56da3SHartmut Brandt *
15*0bf56da3SHartmut Brandt * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*0bf56da3SHartmut Brandt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*0bf56da3SHartmut Brandt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*0bf56da3SHartmut Brandt * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19*0bf56da3SHartmut Brandt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*0bf56da3SHartmut Brandt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*0bf56da3SHartmut Brandt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*0bf56da3SHartmut Brandt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*0bf56da3SHartmut Brandt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*0bf56da3SHartmut Brandt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*0bf56da3SHartmut Brandt * SUCH DAMAGE.
26*0bf56da3SHartmut Brandt *
27*0bf56da3SHartmut Brandt * :se ts=4
28*0bf56da3SHartmut Brandt */
29*0bf56da3SHartmut Brandt
30*0bf56da3SHartmut Brandt #include "constbuf.h"
31*0bf56da3SHartmut Brandt
32*0bf56da3SHartmut Brandt extern "C" {
33*0bf56da3SHartmut Brandt #include "asn1.h"
34*0bf56da3SHartmut Brandt }
35*0bf56da3SHartmut Brandt
36*0bf56da3SHartmut Brandt #include "catch.hpp"
37*0bf56da3SHartmut Brandt
38*0bf56da3SHartmut Brandt #include <algorithm>
39*0bf56da3SHartmut Brandt #include <cstdarg>
40*0bf56da3SHartmut Brandt #include <cstdint>
41*0bf56da3SHartmut Brandt #include <iostream>
42*0bf56da3SHartmut Brandt #include <string>
43*0bf56da3SHartmut Brandt #include <type_traits>
44*0bf56da3SHartmut Brandt
45*0bf56da3SHartmut Brandt using namespace test::literals;
46*0bf56da3SHartmut Brandt
47*0bf56da3SHartmut Brandt template<typename T>
48*0bf56da3SHartmut Brandt static std::enable_if_t<!std::is_integral_v<T>, asn_buf>
mk_asn_buf(const T & b)49*0bf56da3SHartmut Brandt mk_asn_buf(const T &b)
50*0bf56da3SHartmut Brandt {
51*0bf56da3SHartmut Brandt asn_buf abuf;
52*0bf56da3SHartmut Brandt
53*0bf56da3SHartmut Brandt abuf.asn_cptr = b.data();
54*0bf56da3SHartmut Brandt abuf.asn_len = b.size();
55*0bf56da3SHartmut Brandt
56*0bf56da3SHartmut Brandt return abuf;
57*0bf56da3SHartmut Brandt }
58*0bf56da3SHartmut Brandt
59*0bf56da3SHartmut Brandt static asn_buf
mk_asn_buf(asn_len_t len)60*0bf56da3SHartmut Brandt mk_asn_buf(asn_len_t len)
61*0bf56da3SHartmut Brandt {
62*0bf56da3SHartmut Brandt asn_buf abuf;
63*0bf56da3SHartmut Brandt
64*0bf56da3SHartmut Brandt abuf.asn_ptr = new u_char[len];
65*0bf56da3SHartmut Brandt abuf.asn_len = len;
66*0bf56da3SHartmut Brandt
67*0bf56da3SHartmut Brandt return abuf;
68*0bf56da3SHartmut Brandt }
69*0bf56da3SHartmut Brandt
70*0bf56da3SHartmut Brandt static std::string g_errstr;
71*0bf56da3SHartmut Brandt
72*0bf56da3SHartmut Brandt static void
save_g_errstr(const struct asn_buf * b,const char * fmt,...)73*0bf56da3SHartmut Brandt save_g_errstr(const struct asn_buf *b, const char *fmt, ...)
74*0bf56da3SHartmut Brandt {
75*0bf56da3SHartmut Brandt va_list ap;
76*0bf56da3SHartmut Brandt
77*0bf56da3SHartmut Brandt char sbuf[20000];
78*0bf56da3SHartmut Brandt va_start(ap, fmt);
79*0bf56da3SHartmut Brandt vsprintf(sbuf, fmt, ap);
80*0bf56da3SHartmut Brandt va_end(ap);
81*0bf56da3SHartmut Brandt
82*0bf56da3SHartmut Brandt if (b != NULL) {
83*0bf56da3SHartmut Brandt strcat(sbuf, " at");
84*0bf56da3SHartmut Brandt for (u_int i = 0; b->asn_len > i; i++)
85*0bf56da3SHartmut Brandt sprintf(sbuf + strlen(sbuf), " %02x", b->asn_cptr[i]);
86*0bf56da3SHartmut Brandt }
87*0bf56da3SHartmut Brandt strcat(sbuf, "\n");
88*0bf56da3SHartmut Brandt
89*0bf56da3SHartmut Brandt g_errstr = sbuf;
90*0bf56da3SHartmut Brandt }
91*0bf56da3SHartmut Brandt
92*0bf56da3SHartmut Brandt /**
93*0bf56da3SHartmut Brandt * Encapsulate an ASN.1 parse buffer and the parse header fields.
94*0bf56da3SHartmut Brandt * Constructing parses the header.
95*0bf56da3SHartmut Brandt */
96*0bf56da3SHartmut Brandt struct Asn_value
97*0bf56da3SHartmut Brandt {
98*0bf56da3SHartmut Brandt /** parse buffer */
99*0bf56da3SHartmut Brandt struct asn_buf buf;
100*0bf56da3SHartmut Brandt
101*0bf56da3SHartmut Brandt /** error from header parsing */
102*0bf56da3SHartmut Brandt asn_err err;
103*0bf56da3SHartmut Brandt
104*0bf56da3SHartmut Brandt /** ASN.1 tag byte */
105*0bf56da3SHartmut Brandt uint8_t type;
106*0bf56da3SHartmut Brandt
107*0bf56da3SHartmut Brandt /** value length */
108*0bf56da3SHartmut Brandt asn_len_t alen;
109*0bf56da3SHartmut Brandt
110*0bf56da3SHartmut Brandt /**
111*0bf56da3SHartmut Brandt * Construct a parse buffer and parse the header.
112*0bf56da3SHartmut Brandt *
113*0bf56da3SHartmut Brandt * \tparam Tbuf input buffer type
114*0bf56da3SHartmut Brandt *
115*0bf56da3SHartmut Brandt * \param ibuf input buffer
116*0bf56da3SHartmut Brandt */
117*0bf56da3SHartmut Brandt template<typename Tbuf>
118*0bf56da3SHartmut Brandt explicit
Asn_valueAsn_value119*0bf56da3SHartmut Brandt Asn_value(const Tbuf &ibuf)
120*0bf56da3SHartmut Brandt : buf {mk_asn_buf(ibuf)}, err {asn_get_header(&buf, &type, &alen)}
121*0bf56da3SHartmut Brandt {
122*0bf56da3SHartmut Brandt }
123*0bf56da3SHartmut Brandt };
124*0bf56da3SHartmut Brandt
125*0bf56da3SHartmut Brandt /**
126*0bf56da3SHartmut Brandt * Parse the ASN.1 header and check the error code. If the error is not
127*0bf56da3SHartmut Brandt * ASN_ERR_OK then check the error string.
128*0bf56da3SHartmut Brandt *
129*0bf56da3SHartmut Brandt * \tparam Tbuf input buffer type
130*0bf56da3SHartmut Brandt *
131*0bf56da3SHartmut Brandt * \param buf input buffer
132*0bf56da3SHartmut Brandt * \param err expected error code (default ASN_ERR_OK)
133*0bf56da3SHartmut Brandt * \param errstr expected error string (default empty)
134*0bf56da3SHartmut Brandt *
135*0bf56da3SHartmut Brandt * \return the parse buffer
136*0bf56da3SHartmut Brandt */
137*0bf56da3SHartmut Brandt template<typename Tbuf>
138*0bf56da3SHartmut Brandt static auto
check_header(const Tbuf & buf,asn_err err=ASN_ERR_OK,std::string_view errstr={})139*0bf56da3SHartmut Brandt check_header(const Tbuf &buf, asn_err err = ASN_ERR_OK,
140*0bf56da3SHartmut Brandt std::string_view errstr = {})
141*0bf56da3SHartmut Brandt {
142*0bf56da3SHartmut Brandt g_errstr.clear();
143*0bf56da3SHartmut Brandt auto r = Asn_value(buf);
144*0bf56da3SHartmut Brandt REQUIRE(r.err == err);
145*0bf56da3SHartmut Brandt if (r.err != ASN_ERR_OK)
146*0bf56da3SHartmut Brandt REQUIRE(g_errstr == errstr);
147*0bf56da3SHartmut Brandt else
148*0bf56da3SHartmut Brandt REQUIRE(g_errstr == "");
149*0bf56da3SHartmut Brandt return r;
150*0bf56da3SHartmut Brandt }
151*0bf56da3SHartmut Brandt
152*0bf56da3SHartmut Brandt /**
153*0bf56da3SHartmut Brandt * Parse the ASN.1 header and expect it not to fail. The check the tag.
154*0bf56da3SHartmut Brandt *
155*0bf56da3SHartmut Brandt * \tparam Tbuf input buffer type
156*0bf56da3SHartmut Brandt *
157*0bf56da3SHartmut Brandt * \param buf input buffer
158*0bf56da3SHartmut Brandt * \param tag expected type tag
159*0bf56da3SHartmut Brandt *
160*0bf56da3SHartmut Brandt * \return the parse buffer
161*0bf56da3SHartmut Brandt */
162*0bf56da3SHartmut Brandt template<typename Tbuf>
163*0bf56da3SHartmut Brandt static auto
check_header(const Tbuf & buf,uint8_t type)164*0bf56da3SHartmut Brandt check_header(const Tbuf &buf, uint8_t type)
165*0bf56da3SHartmut Brandt {
166*0bf56da3SHartmut Brandt auto r = check_header(buf);
167*0bf56da3SHartmut Brandt REQUIRE(r.type == type);
168*0bf56da3SHartmut Brandt return r;
169*0bf56da3SHartmut Brandt }
170*0bf56da3SHartmut Brandt
171*0bf56da3SHartmut Brandt /**
172*0bf56da3SHartmut Brandt * Parse the ASN.1 header and expect it not to fail. The check the tag and
173*0bf56da3SHartmut Brandt * the length.
174*0bf56da3SHartmut Brandt *
175*0bf56da3SHartmut Brandt * \tparam Tbuf input buffer type
176*0bf56da3SHartmut Brandt *
177*0bf56da3SHartmut Brandt * \param buf input buffer
178*0bf56da3SHartmut Brandt * \param tag expected type tag
179*0bf56da3SHartmut Brandt * \param alen expected value length
180*0bf56da3SHartmut Brandt *
181*0bf56da3SHartmut Brandt * \return the parse buffer
182*0bf56da3SHartmut Brandt */
183*0bf56da3SHartmut Brandt template<typename Tbuf>
184*0bf56da3SHartmut Brandt static auto
check_header(const Tbuf & buf,uint8_t type,asn_len_t alen)185*0bf56da3SHartmut Brandt check_header(const Tbuf &buf, uint8_t type, asn_len_t alen)
186*0bf56da3SHartmut Brandt {
187*0bf56da3SHartmut Brandt auto r = check_header(buf);
188*0bf56da3SHartmut Brandt REQUIRE(r.type == type);
189*0bf56da3SHartmut Brandt REQUIRE(r.alen == alen);
190*0bf56da3SHartmut Brandt return r;
191*0bf56da3SHartmut Brandt }
192*0bf56da3SHartmut Brandt
193*0bf56da3SHartmut Brandt template<typename Tbuf>
194*0bf56da3SHartmut Brandt static void
check_buf(const asn_buf & s,const Tbuf & exp,bool print=false)195*0bf56da3SHartmut Brandt check_buf(const asn_buf &s, const Tbuf &exp, bool print = false)
196*0bf56da3SHartmut Brandt {
197*0bf56da3SHartmut Brandt if (print) {
198*0bf56da3SHartmut Brandt for (auto c : exp)
199*0bf56da3SHartmut Brandt std::printf(":%02x", c);
200*0bf56da3SHartmut Brandt std::printf("\n");
201*0bf56da3SHartmut Brandt
202*0bf56da3SHartmut Brandt for (size_t i = 0; i < size(exp); i++)
203*0bf56da3SHartmut Brandt std::printf(":%02x", s.asn_ptr[i]);
204*0bf56da3SHartmut Brandt std::printf("\n");
205*0bf56da3SHartmut Brandt }
206*0bf56da3SHartmut Brandt REQUIRE(std::equal(begin(exp), end(exp), s.asn_ptr));
207*0bf56da3SHartmut Brandt }
208*0bf56da3SHartmut Brandt
209*0bf56da3SHartmut Brandt TEST_CASE("ASN.1 header parsing", "[asn1][parse]")
210*0bf56da3SHartmut Brandt {
211*0bf56da3SHartmut Brandt asn_error = save_g_errstr;
212*0bf56da3SHartmut Brandt
213*0bf56da3SHartmut Brandt SECTION("empty buffer") {
214*0bf56da3SHartmut Brandt check_header(std::vector<u_char>{}, ASN_ERR_EOBUF,
215*0bf56da3SHartmut Brandt "no identifier for header at\n");
216*0bf56da3SHartmut Brandt }
217*0bf56da3SHartmut Brandt SECTION("tag too large") {
218*0bf56da3SHartmut Brandt check_header("x1f:06:01:7f"_cbuf, ASN_ERR_FAILED,
219*0bf56da3SHartmut Brandt "tags > 0x1e not supported (0x1f) at 1f 06 01 7f\n");
220*0bf56da3SHartmut Brandt }
221*0bf56da3SHartmut Brandt SECTION("no length field") {
222*0bf56da3SHartmut Brandt check_header("x46"_cbuf, ASN_ERR_EOBUF, "no length field at\n");
223*0bf56da3SHartmut Brandt }
224*0bf56da3SHartmut Brandt SECTION("indefinite length") {
225*0bf56da3SHartmut Brandt check_header("x46:80:02:04:06"_cbuf, ASN_ERR_FAILED,
226*0bf56da3SHartmut Brandt "indefinite length not supported at 02 04 06\n");
227*0bf56da3SHartmut Brandt }
228*0bf56da3SHartmut Brandt SECTION("long length") {
229*0bf56da3SHartmut Brandt check_header("x46:83:00:00:02:7f:12"_cbuf, ASN_ERR_FAILED,
230*0bf56da3SHartmut Brandt "long length too long (3) at 00 00 02 7f 12\n");
231*0bf56da3SHartmut Brandt }
232*0bf56da3SHartmut Brandt SECTION("truncated length field") {
233*0bf56da3SHartmut Brandt check_header("x46:82:00"_cbuf, ASN_ERR_EOBUF,
234*0bf56da3SHartmut Brandt "long length truncated at 00\n");
235*0bf56da3SHartmut Brandt }
236*0bf56da3SHartmut Brandt SECTION("correct long length") {
237*0bf56da3SHartmut Brandt check_header("x04:81:00"_cbuf, ASN_TYPE_OCTETSTRING, 0);
238*0bf56da3SHartmut Brandt #ifndef BOGUS_CVE_2019_5610_FIX
239*0bf56da3SHartmut Brandt check_header("x04:81:04:00"_cbuf, ASN_TYPE_OCTETSTRING, 4);
240*0bf56da3SHartmut Brandt check_header("x04:81:ff:00"_cbuf, ASN_TYPE_OCTETSTRING, 255);
241*0bf56da3SHartmut Brandt #endif
242*0bf56da3SHartmut Brandt check_header("x04:82:00:00"_cbuf, ASN_TYPE_OCTETSTRING, 0);
243*0bf56da3SHartmut Brandt #ifndef BOGUS_CVE_2019_5610_FIX
244*0bf56da3SHartmut Brandt check_header("x04:82:00:80"_cbuf, ASN_TYPE_OCTETSTRING, 128);
245*0bf56da3SHartmut Brandt check_header("x04:82:01:80"_cbuf, ASN_TYPE_OCTETSTRING, 384);
246*0bf56da3SHartmut Brandt check_header("x04:82:ff:ff"_cbuf, ASN_TYPE_OCTETSTRING, 65535);
247*0bf56da3SHartmut Brandt #endif
248*0bf56da3SHartmut Brandt }
249*0bf56da3SHartmut Brandt SECTION("short length") {
250*0bf56da3SHartmut Brandt check_header("x04:00:00"_cbuf, ASN_TYPE_OCTETSTRING, 0);
251*0bf56da3SHartmut Brandt check_header("x04:01:00"_cbuf, ASN_TYPE_OCTETSTRING, 1);
252*0bf56da3SHartmut Brandt #ifndef BOGUS_CVE_2019_5610_FIX
253*0bf56da3SHartmut Brandt check_header("x04:40:00"_cbuf, ASN_TYPE_OCTETSTRING, 64);
254*0bf56da3SHartmut Brandt check_header("x04:7f:00"_cbuf, ASN_TYPE_OCTETSTRING, 127);
255*0bf56da3SHartmut Brandt #endif
256*0bf56da3SHartmut Brandt }
257*0bf56da3SHartmut Brandt }
258*0bf56da3SHartmut Brandt
259*0bf56da3SHartmut Brandt TEST_CASE("ASN.1 header building", "[asn1][build]")
260*0bf56da3SHartmut Brandt {
261*0bf56da3SHartmut Brandt asn_error = save_g_errstr;
262*0bf56da3SHartmut Brandt
263*0bf56da3SHartmut Brandt const auto conv_err = [] (asn_len_t alen, asn_len_t vlen, uint8_t type,
__anon4d4e46190102(asn_len_t alen, asn_len_t vlen, uint8_t type, asn_err err, std::string_view errstr) 264*0bf56da3SHartmut Brandt asn_err err, std::string_view errstr) {
265*0bf56da3SHartmut Brandt auto b = mk_asn_buf(alen);
266*0bf56da3SHartmut Brandt g_errstr.clear();
267*0bf56da3SHartmut Brandt REQUIRE(asn_put_header(&b, type, vlen) == err);
268*0bf56da3SHartmut Brandt REQUIRE(g_errstr == errstr);
269*0bf56da3SHartmut Brandt };
270*0bf56da3SHartmut Brandt
271*0bf56da3SHartmut Brandt const auto conv = [] (asn_len_t alen, asn_len_t vlen, uint8_t type,
__anon4d4e46190202(asn_len_t alen, asn_len_t vlen, uint8_t type, const auto &cbuf) 272*0bf56da3SHartmut Brandt const auto &cbuf) {
273*0bf56da3SHartmut Brandt auto b = mk_asn_buf(alen);
274*0bf56da3SHartmut Brandt auto t = b;
275*0bf56da3SHartmut Brandt REQUIRE(asn_put_header(&b, type, vlen) == ASN_ERR_OK);
276*0bf56da3SHartmut Brandt REQUIRE(b.asn_len == (size_t)0);
277*0bf56da3SHartmut Brandt check_buf(t, cbuf);
278*0bf56da3SHartmut Brandt };
279*0bf56da3SHartmut Brandt
280*0bf56da3SHartmut Brandt SECTION("no space for tag") {
281*0bf56da3SHartmut Brandt conv_err(0, 0, ASN_TYPE_OCTETSTRING, ASN_ERR_EOBUF, "");
282*0bf56da3SHartmut Brandt }
283*0bf56da3SHartmut Brandt SECTION("no space for length") {
284*0bf56da3SHartmut Brandt conv_err(1, 0, ASN_TYPE_OCTETSTRING, ASN_ERR_EOBUF, "");
285*0bf56da3SHartmut Brandt conv_err(2, 128, ASN_TYPE_OCTETSTRING, ASN_ERR_EOBUF, "");
286*0bf56da3SHartmut Brandt }
287*0bf56da3SHartmut Brandt SECTION("bad tag") {
288*0bf56da3SHartmut Brandt conv_err(2, 0, 0x1f, ASN_ERR_FAILED,
289*0bf56da3SHartmut Brandt "types > 0x1e not supported (0x1f)\n");
290*0bf56da3SHartmut Brandt conv_err(2, 0, 0xff, ASN_ERR_FAILED,
291*0bf56da3SHartmut Brandt "types > 0x1e not supported (0x1f)\n");
292*0bf56da3SHartmut Brandt }
293*0bf56da3SHartmut Brandt SECTION("ok") {
294*0bf56da3SHartmut Brandt conv(2, 0, ASN_TYPE_OCTETSTRING, "x04:00"_cbuf);
295*0bf56da3SHartmut Brandt }
296*0bf56da3SHartmut Brandt }
297*0bf56da3SHartmut Brandt
298*0bf56da3SHartmut Brandt TEST_CASE("Counter64 parsing", "[asn1][parse]")
299*0bf56da3SHartmut Brandt {
300*0bf56da3SHartmut Brandt asn_error = save_g_errstr;
301*0bf56da3SHartmut Brandt
302*0bf56da3SHartmut Brandt /**
303*0bf56da3SHartmut Brandt * Sucessfully parse a COUNTER64 value.
304*0bf56da3SHartmut Brandt *
305*0bf56da3SHartmut Brandt * \param buf buffer to parse
306*0bf56da3SHartmut Brandt * \param xval expected value
307*0bf56da3SHartmut Brandt */
__anon4d4e46190302(const auto &buf, uint64_t xval) 308*0bf56da3SHartmut Brandt const auto conv = [] (const auto &buf, uint64_t xval) {
309*0bf56da3SHartmut Brandt auto r = check_header(buf, ASN_APP_COUNTER64 | ASN_CLASS_APPLICATION);
310*0bf56da3SHartmut Brandt
311*0bf56da3SHartmut Brandt uint64_t val;
312*0bf56da3SHartmut Brandt REQUIRE(asn_get_counter64_raw(&r.buf, r.alen, &val) == ASN_ERR_OK);
313*0bf56da3SHartmut Brandt REQUIRE(val == xval);
314*0bf56da3SHartmut Brandt };
315*0bf56da3SHartmut Brandt
316*0bf56da3SHartmut Brandt /**
317*0bf56da3SHartmut Brandt * Parse COUNTER64 with error.
318*0bf56da3SHartmut Brandt *
319*0bf56da3SHartmut Brandt * \param buf buffer to parse
320*0bf56da3SHartmut Brandt * \param err expected error from value parser
321*0bf56da3SHartmut Brandt * \param errstr expected error string
322*0bf56da3SHartmut Brandt */
323*0bf56da3SHartmut Brandt const auto conv_err = [] (const auto &buf, asn_err err,
__anon4d4e46190402(const auto &buf, asn_err err, std::string_view errstr) 324*0bf56da3SHartmut Brandt std::string_view errstr) {
325*0bf56da3SHartmut Brandt auto r = check_header(buf, ASN_APP_COUNTER64 | ASN_CLASS_APPLICATION);
326*0bf56da3SHartmut Brandt
327*0bf56da3SHartmut Brandt g_errstr.clear();
328*0bf56da3SHartmut Brandt uint64_t val;
329*0bf56da3SHartmut Brandt REQUIRE(asn_get_counter64_raw(&r.buf, r.alen, &val) == err);
330*0bf56da3SHartmut Brandt REQUIRE(g_errstr == errstr);
331*0bf56da3SHartmut Brandt };
332*0bf56da3SHartmut Brandt
333*0bf56da3SHartmut Brandt SECTION("correct encoding") {
334*0bf56da3SHartmut Brandt
335*0bf56da3SHartmut Brandt conv("x46:01:00"_cbuf, 0x0ULL);
336*0bf56da3SHartmut Brandt conv("x46:01:01"_cbuf, 0x1ULL);
337*0bf56da3SHartmut Brandt conv("x46:01:7f"_cbuf, 0x7fULL);
338*0bf56da3SHartmut Brandt
339*0bf56da3SHartmut Brandt conv("x46:02:00:80"_cbuf, 0x80ULL);
340*0bf56da3SHartmut Brandt conv("x46:02:00:ff"_cbuf, 0xffULL);
341*0bf56da3SHartmut Brandt conv("x46:02:7f:ff"_cbuf, 0x7fffULL);
342*0bf56da3SHartmut Brandt
343*0bf56da3SHartmut Brandt conv("x46:03:00:80:00"_cbuf, 0x8000ULL);
344*0bf56da3SHartmut Brandt conv("x46:03:00:ff:ff"_cbuf, 0xffffULL);
345*0bf56da3SHartmut Brandt conv("x46:03:7f:ff:ff"_cbuf, 0x7fffffULL);
346*0bf56da3SHartmut Brandt
347*0bf56da3SHartmut Brandt conv("x46:04:00:80:00:00"_cbuf, 0x800000ULL);
348*0bf56da3SHartmut Brandt conv("x46:04:00:ff:ff:ff"_cbuf, 0xffffffULL);
349*0bf56da3SHartmut Brandt conv("x46:04:7f:ff:ff:ff"_cbuf, 0x7fffffffULL);
350*0bf56da3SHartmut Brandt
351*0bf56da3SHartmut Brandt conv("x46:05:00:80:00:00:00"_cbuf, 0x80000000ULL);
352*0bf56da3SHartmut Brandt conv("x46:05:00:ff:ff:ff:ff"_cbuf, 0xffffffffULL);
353*0bf56da3SHartmut Brandt conv("x46:05:7f:ff:ff:ff:ff"_cbuf, 0x7fffffffffULL);
354*0bf56da3SHartmut Brandt
355*0bf56da3SHartmut Brandt conv("x46:06:00:80:00:00:00:00"_cbuf, 0x8000000000ULL);
356*0bf56da3SHartmut Brandt conv("x46:06:00:ff:ff:ff:ff:ff"_cbuf, 0xffffffffffULL);
357*0bf56da3SHartmut Brandt conv("x46:06:7f:ff:ff:ff:ff:ff"_cbuf, 0x7fffffffffffULL);
358*0bf56da3SHartmut Brandt
359*0bf56da3SHartmut Brandt conv("x46:07:00:80:00:00:00:00:00"_cbuf, 0x800000000000ULL);
360*0bf56da3SHartmut Brandt conv("x46:07:00:ff:ff:ff:ff:ff:ff"_cbuf, 0xffffffffffffULL);
361*0bf56da3SHartmut Brandt conv("x46:07:7f:ff:ff:ff:ff:ff:ff"_cbuf, 0x7fffffffffffffULL);
362*0bf56da3SHartmut Brandt
363*0bf56da3SHartmut Brandt conv("x46:08:00:80:00:00:00:00:00:00"_cbuf, 0x80000000000000ULL);
364*0bf56da3SHartmut Brandt conv("x46:08:00:ff:ff:ff:ff:ff:ff:ff"_cbuf, 0xffffffffffffffULL);
365*0bf56da3SHartmut Brandt conv("x46:08:7f:ff:ff:ff:ff:ff:ff:ff"_cbuf, 0x7fffffffffffffffULL);
366*0bf56da3SHartmut Brandt
367*0bf56da3SHartmut Brandt conv("x46:09:00:80:00:00:00:00:00:00:00"_cbuf, 0x8000000000000000ULL);
368*0bf56da3SHartmut Brandt conv("x46:09:00:ff:ff:ff:ff:ff:ff:ff:ff"_cbuf, 0xffffffffffffffffULL);
369*0bf56da3SHartmut Brandt }
370*0bf56da3SHartmut Brandt
371*0bf56da3SHartmut Brandt SECTION("zero length") {
372*0bf56da3SHartmut Brandt conv_err("x46:00"_cbuf, ASN_ERR_BADLEN,
373*0bf56da3SHartmut Brandt "zero-length integer at\n");
374*0bf56da3SHartmut Brandt }
375*0bf56da3SHartmut Brandt
376*0bf56da3SHartmut Brandt SECTION("non minimal encoding") {
377*0bf56da3SHartmut Brandt conv_err("x46:02:00:00"_cbuf, ASN_ERR_BADLEN,
378*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 00\n");
379*0bf56da3SHartmut Brandt conv_err("x46:02:00:7f"_cbuf, ASN_ERR_BADLEN,
380*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 7f\n");
381*0bf56da3SHartmut Brandt conv_err("x46:03:00:00:80"_cbuf, ASN_ERR_BADLEN,
382*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 00 80\n");
383*0bf56da3SHartmut Brandt conv_err("x46:04:00:00:80:00"_cbuf, ASN_ERR_BADLEN,
384*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 00 80 00\n");
385*0bf56da3SHartmut Brandt conv_err("x46:0a:00:00:00:00:00:00:00:00:00:00"_cbuf, ASN_ERR_BADLEN,
386*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 00 00 00 00 00 00 00 00 00\n");
387*0bf56da3SHartmut Brandt conv_err("x46:0a:00:01:00:00:00:00:00:00:00:00"_cbuf, ASN_ERR_BADLEN,
388*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 01 00 00 00 00 00 00 00 00\n");
389*0bf56da3SHartmut Brandt }
390*0bf56da3SHartmut Brandt
391*0bf56da3SHartmut Brandt SECTION("out of range") {
392*0bf56da3SHartmut Brandt conv_err("x46:09:01:00:00:00:00:00:00:00:00"_cbuf, ASN_ERR_RANGE,
393*0bf56da3SHartmut Brandt "unsigned too large or negative at 01 00 00 00 00 00 00 00 00\n");
394*0bf56da3SHartmut Brandt conv_err("x46:0a:01:00:00:00:00:00:00:00:00:00"_cbuf, ASN_ERR_RANGE,
395*0bf56da3SHartmut Brandt "unsigned too large or negative at 01 00 00 00 00 00 00 00 00 00\n");
396*0bf56da3SHartmut Brandt conv_err("x46:01:80"_cbuf, ASN_ERR_RANGE,
397*0bf56da3SHartmut Brandt "unsigned too large or negative at 80\n");
398*0bf56da3SHartmut Brandt conv_err("x46:02:80:00"_cbuf, ASN_ERR_RANGE,
399*0bf56da3SHartmut Brandt "unsigned too large or negative at 80 00\n");
400*0bf56da3SHartmut Brandt conv_err("x46:03:80:00:00"_cbuf, ASN_ERR_RANGE,
401*0bf56da3SHartmut Brandt "unsigned too large or negative at 80 00 00\n");
402*0bf56da3SHartmut Brandt }
403*0bf56da3SHartmut Brandt
404*0bf56da3SHartmut Brandt #ifndef BOGUS_CVE_2019_5610_FIX
405*0bf56da3SHartmut Brandt SECTION("truncated value") {
406*0bf56da3SHartmut Brandt conv_err("x46:02:00"_cbuf, ASN_ERR_EOBUF,
407*0bf56da3SHartmut Brandt "truncated integer at 00\n");
408*0bf56da3SHartmut Brandt conv_err("x46:09:00:80:00:00:00"_cbuf, ASN_ERR_EOBUF,
409*0bf56da3SHartmut Brandt "truncated integer at 00 80 00 00 00\n");
410*0bf56da3SHartmut Brandt conv_err("x46:09:00:ff:ff:ff:ff:ff:ff:ff"_cbuf, ASN_ERR_EOBUF,
411*0bf56da3SHartmut Brandt "truncated integer at 00 ff ff ff ff ff ff ff\n");
412*0bf56da3SHartmut Brandt }
413*0bf56da3SHartmut Brandt #endif
414*0bf56da3SHartmut Brandt }
415*0bf56da3SHartmut Brandt
416*0bf56da3SHartmut Brandt TEST_CASE("Counter64 building", "[asn1][build]")
417*0bf56da3SHartmut Brandt {
418*0bf56da3SHartmut Brandt asn_error = save_g_errstr;
419*0bf56da3SHartmut Brandt
__anon4d4e46190502(asn_len_t alen, uint64_t val, const auto &buf) 420*0bf56da3SHartmut Brandt const auto conv = [] (asn_len_t alen, uint64_t val, const auto &buf) {
421*0bf56da3SHartmut Brandt auto b = mk_asn_buf(alen);
422*0bf56da3SHartmut Brandt auto s = b;
423*0bf56da3SHartmut Brandt REQUIRE(asn_put_counter64(&b, val) == ASN_ERR_OK);
424*0bf56da3SHartmut Brandt REQUIRE(b.asn_len == (size_t)0);
425*0bf56da3SHartmut Brandt check_buf(s, buf);
426*0bf56da3SHartmut Brandt };
427*0bf56da3SHartmut Brandt
428*0bf56da3SHartmut Brandt const auto conv_err = [] (asn_len_t alen, uint64_t val, asn_err err,
__anon4d4e46190602(asn_len_t alen, uint64_t val, asn_err err, std::string_view errstr) 429*0bf56da3SHartmut Brandt std::string_view errstr) {
430*0bf56da3SHartmut Brandt auto b = mk_asn_buf(alen);
431*0bf56da3SHartmut Brandt g_errstr.clear();
432*0bf56da3SHartmut Brandt REQUIRE(asn_put_counter64(&b, val) == err);
433*0bf56da3SHartmut Brandt REQUIRE(g_errstr == errstr);
434*0bf56da3SHartmut Brandt };
435*0bf56da3SHartmut Brandt
436*0bf56da3SHartmut Brandt conv(3, 0x0, "x46:01:00"_cbuf);
437*0bf56da3SHartmut Brandt conv(3, 0x1, "x46:01:01"_cbuf);
438*0bf56da3SHartmut Brandt conv(3, 0x7f, "x46:01:7f"_cbuf);
439*0bf56da3SHartmut Brandt
440*0bf56da3SHartmut Brandt conv(4, 0x80, "x46:02:00:80"_cbuf);
441*0bf56da3SHartmut Brandt conv(4, 0xff, "x46:02:00:ff"_cbuf);
442*0bf56da3SHartmut Brandt conv(4, 0x7fff, "x46:02:7f:ff"_cbuf);
443*0bf56da3SHartmut Brandt
444*0bf56da3SHartmut Brandt conv(5, 0x8000, "x46:03:00:80:00"_cbuf);
445*0bf56da3SHartmut Brandt conv(5, 0xffff, "x46:03:00:ff:ff"_cbuf);
446*0bf56da3SHartmut Brandt conv(5, 0x7fffff, "x46:03:7f:ff:ff"_cbuf);
447*0bf56da3SHartmut Brandt
448*0bf56da3SHartmut Brandt conv(6, 0x800000, "x46:04:00:80:00:00"_cbuf);
449*0bf56da3SHartmut Brandt conv(6, 0xffffff, "x46:04:00:ff:ff:ff"_cbuf);
450*0bf56da3SHartmut Brandt conv(6, 0x7fffffff, "x46:04:7f:ff:ff:ff"_cbuf);
451*0bf56da3SHartmut Brandt
452*0bf56da3SHartmut Brandt conv(7, 0x80000000, "x46:05:00:80:00:00:00"_cbuf);
453*0bf56da3SHartmut Brandt conv(7, 0xffffffff, "x46:05:00:ff:ff:ff:ff"_cbuf);
454*0bf56da3SHartmut Brandt conv(7, 0x7fffffffff, "x46:05:7f:ff:ff:ff:ff"_cbuf);
455*0bf56da3SHartmut Brandt
456*0bf56da3SHartmut Brandt conv(8, 0x8000000000, "x46:06:00:80:00:00:00:00"_cbuf);
457*0bf56da3SHartmut Brandt conv(8, 0xffffffffff, "x46:06:00:ff:ff:ff:ff:ff"_cbuf);
458*0bf56da3SHartmut Brandt conv(8, 0x7fffffffffff, "x46:06:7f:ff:ff:ff:ff:ff"_cbuf);
459*0bf56da3SHartmut Brandt
460*0bf56da3SHartmut Brandt conv(9, 0x800000000000, "x46:07:00:80:00:00:00:00:00"_cbuf);
461*0bf56da3SHartmut Brandt conv(9, 0xffffffffffff, "x46:07:00:ff:ff:ff:ff:ff:ff"_cbuf);
462*0bf56da3SHartmut Brandt conv(9, 0x7fffffffffffff, "x46:07:7f:ff:ff:ff:ff:ff:ff"_cbuf);
463*0bf56da3SHartmut Brandt
464*0bf56da3SHartmut Brandt conv(10, 0x80000000000000, "x46:08:00:80:00:00:00:00:00:00"_cbuf);
465*0bf56da3SHartmut Brandt conv(10, 0xffffffffffffff, "x46:08:00:ff:ff:ff:ff:ff:ff:ff"_cbuf);
466*0bf56da3SHartmut Brandt conv(10, 0x7fffffffffffffff, "x46:08:7f:ff:ff:ff:ff:ff:ff:ff"_cbuf);
467*0bf56da3SHartmut Brandt
468*0bf56da3SHartmut Brandt conv(11, 0x8000000000000000, "x46:09:00:80:00:00:00:00:00:00:00"_cbuf);
469*0bf56da3SHartmut Brandt conv(11, 0xffffffffffffffff, "x46:09:00:ff:ff:ff:ff:ff:ff:ff:ff"_cbuf);
470*0bf56da3SHartmut Brandt
471*0bf56da3SHartmut Brandt SECTION("empty buffer") {
472*0bf56da3SHartmut Brandt conv_err(0, 0, ASN_ERR_EOBUF, "");
473*0bf56da3SHartmut Brandt }
474*0bf56da3SHartmut Brandt SECTION("buffer too short for length field") {
475*0bf56da3SHartmut Brandt conv_err(1, 0, ASN_ERR_EOBUF, "");
476*0bf56da3SHartmut Brandt }
477*0bf56da3SHartmut Brandt SECTION("buffer too short") {
478*0bf56da3SHartmut Brandt conv_err(2, 0, ASN_ERR_EOBUF, "");
479*0bf56da3SHartmut Brandt conv_err(3, 0x80, ASN_ERR_EOBUF, "");
480*0bf56da3SHartmut Brandt conv_err(4, 0x8000, ASN_ERR_EOBUF, "");
481*0bf56da3SHartmut Brandt conv_err(5, 0x800000, ASN_ERR_EOBUF, "");
482*0bf56da3SHartmut Brandt conv_err(6, 0x80000000, ASN_ERR_EOBUF, "");
483*0bf56da3SHartmut Brandt conv_err(7, 0x8000000000, ASN_ERR_EOBUF, "");
484*0bf56da3SHartmut Brandt conv_err(8, 0x800000000000, ASN_ERR_EOBUF, "");
485*0bf56da3SHartmut Brandt conv_err(9, 0x80000000000000, ASN_ERR_EOBUF, "");
486*0bf56da3SHartmut Brandt conv_err(10, 0x8000000000000000, ASN_ERR_EOBUF, "");
487*0bf56da3SHartmut Brandt }
488*0bf56da3SHartmut Brandt }
489*0bf56da3SHartmut Brandt
490*0bf56da3SHartmut Brandt TEST_CASE("Unsigned32 parsing", "[asn1][parse]")
491*0bf56da3SHartmut Brandt {
492*0bf56da3SHartmut Brandt asn_error = save_g_errstr;
493*0bf56da3SHartmut Brandt
494*0bf56da3SHartmut Brandt /**
495*0bf56da3SHartmut Brandt * Sucessfully parse a COUNTER value.
496*0bf56da3SHartmut Brandt *
497*0bf56da3SHartmut Brandt * \param buf buffer to parse
498*0bf56da3SHartmut Brandt * \param xval expected value
499*0bf56da3SHartmut Brandt */
__anon4d4e46190702(const auto &buf, uint32_t xval) 500*0bf56da3SHartmut Brandt const auto conv = [] (const auto &buf, uint32_t xval) {
501*0bf56da3SHartmut Brandt auto r = check_header(buf, ASN_APP_COUNTER | ASN_CLASS_APPLICATION);
502*0bf56da3SHartmut Brandt
503*0bf56da3SHartmut Brandt uint32_t val;
504*0bf56da3SHartmut Brandt REQUIRE(asn_get_uint32_raw(&r.buf, r.alen, &val) == ASN_ERR_OK);
505*0bf56da3SHartmut Brandt REQUIRE(val == xval);
506*0bf56da3SHartmut Brandt };
507*0bf56da3SHartmut Brandt
508*0bf56da3SHartmut Brandt /**
509*0bf56da3SHartmut Brandt * Parse COUNTER with error.
510*0bf56da3SHartmut Brandt *
511*0bf56da3SHartmut Brandt * \param buf buffer to parse
512*0bf56da3SHartmut Brandt * \param err expected error from value parser
513*0bf56da3SHartmut Brandt * \param errstr expected error string
514*0bf56da3SHartmut Brandt */
515*0bf56da3SHartmut Brandt const auto conv_err = [] (const auto &buf, asn_err err,
__anon4d4e46190802(const auto &buf, asn_err err, std::string_view errstr) 516*0bf56da3SHartmut Brandt std::string_view errstr) {
517*0bf56da3SHartmut Brandt auto r = check_header(buf, ASN_APP_COUNTER | ASN_CLASS_APPLICATION);
518*0bf56da3SHartmut Brandt
519*0bf56da3SHartmut Brandt g_errstr.clear();
520*0bf56da3SHartmut Brandt uint32_t val;
521*0bf56da3SHartmut Brandt REQUIRE(asn_get_uint32_raw(&r.buf, r.alen, &val) == err);
522*0bf56da3SHartmut Brandt REQUIRE(g_errstr == errstr);
523*0bf56da3SHartmut Brandt };
524*0bf56da3SHartmut Brandt
525*0bf56da3SHartmut Brandt SECTION("correct encoding") {
526*0bf56da3SHartmut Brandt conv("x41:01:00"_cbuf, 0x0U);
527*0bf56da3SHartmut Brandt conv("x41:01:01"_cbuf, 0x1U);
528*0bf56da3SHartmut Brandt conv("x41:01:7f"_cbuf, 0x7fU);
529*0bf56da3SHartmut Brandt
530*0bf56da3SHartmut Brandt conv("x41:02:00:80"_cbuf, 0x80U);
531*0bf56da3SHartmut Brandt conv("x41:02:00:ff"_cbuf, 0xffU);
532*0bf56da3SHartmut Brandt conv("x41:02:7f:ff"_cbuf, 0x7fffU);
533*0bf56da3SHartmut Brandt
534*0bf56da3SHartmut Brandt conv("x41:03:00:80:00"_cbuf, 0x8000U);
535*0bf56da3SHartmut Brandt conv("x41:03:00:ff:ff"_cbuf, 0xffffU);
536*0bf56da3SHartmut Brandt conv("x41:03:7f:ff:ff"_cbuf, 0x7fffffU);
537*0bf56da3SHartmut Brandt
538*0bf56da3SHartmut Brandt conv("x41:04:00:80:00:00"_cbuf, 0x800000U);
539*0bf56da3SHartmut Brandt conv("x41:04:00:ff:ff:ff"_cbuf, 0xffffffU);
540*0bf56da3SHartmut Brandt conv("x41:04:7f:ff:ff:ff"_cbuf, 0x7fffffffU);
541*0bf56da3SHartmut Brandt
542*0bf56da3SHartmut Brandt conv("x41:05:00:80:00:00:00"_cbuf, 0x80000000U);
543*0bf56da3SHartmut Brandt conv("x41:05:00:ff:ff:ff:ff"_cbuf, 0xffffffffU);
544*0bf56da3SHartmut Brandt }
545*0bf56da3SHartmut Brandt SECTION("zero length") {
546*0bf56da3SHartmut Brandt
547*0bf56da3SHartmut Brandt conv_err("x41:00"_cbuf, ASN_ERR_BADLEN,
548*0bf56da3SHartmut Brandt "zero-length integer at\n");
549*0bf56da3SHartmut Brandt }
550*0bf56da3SHartmut Brandt
551*0bf56da3SHartmut Brandt SECTION("non minimal encoding") {
552*0bf56da3SHartmut Brandt conv_err("x41:02:00:00"_cbuf, ASN_ERR_BADLEN,
553*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 00\n");
554*0bf56da3SHartmut Brandt conv_err("x41:02:00:7f"_cbuf, ASN_ERR_BADLEN,
555*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 7f\n");
556*0bf56da3SHartmut Brandt conv_err("x41:03:00:00:80"_cbuf, ASN_ERR_BADLEN,
557*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 00 80\n");
558*0bf56da3SHartmut Brandt conv_err("x41:04:00:00:80:00"_cbuf, ASN_ERR_BADLEN,
559*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 00 80 00\n");
560*0bf56da3SHartmut Brandt conv_err("x41:06:00:00:00:00:00:00"_cbuf, ASN_ERR_BADLEN,
561*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 00 00 00 00 00\n");
562*0bf56da3SHartmut Brandt conv_err("x41:06:00:01:00:00:00:00"_cbuf, ASN_ERR_BADLEN,
563*0bf56da3SHartmut Brandt "non-minimal unsigned at 00 01 00 00 00 00\n");
564*0bf56da3SHartmut Brandt }
565*0bf56da3SHartmut Brandt
566*0bf56da3SHartmut Brandt SECTION("out of range") {
567*0bf56da3SHartmut Brandt conv_err("x41:05:01:00:00:00:00"_cbuf,
568*0bf56da3SHartmut Brandt ASN_ERR_RANGE, "uint32 too large 4294967296 at\n");
569*0bf56da3SHartmut Brandt conv_err("x41:06:01:00:00:00:00:00"_cbuf,
570*0bf56da3SHartmut Brandt ASN_ERR_RANGE, "uint32 too large 1099511627776 at\n");
571*0bf56da3SHartmut Brandt conv_err("x41:01:80"_cbuf,
572*0bf56da3SHartmut Brandt ASN_ERR_RANGE, "unsigned too large or negative at 80\n");
573*0bf56da3SHartmut Brandt conv_err("x41:02:80:00"_cbuf,
574*0bf56da3SHartmut Brandt ASN_ERR_RANGE, "unsigned too large or negative at 80 00\n");
575*0bf56da3SHartmut Brandt conv_err("x41:03:80:00:00"_cbuf,
576*0bf56da3SHartmut Brandt ASN_ERR_RANGE, "unsigned too large or negative at 80 00 00\n");
577*0bf56da3SHartmut Brandt }
578*0bf56da3SHartmut Brandt
579*0bf56da3SHartmut Brandt #ifndef BOGUS_CVE_2019_5610_FIX
580*0bf56da3SHartmut Brandt SECTION("truncated value") {
581*0bf56da3SHartmut Brandt conv_err("x41:01"_cbuf, ASN_ERR_EOBUF,
582*0bf56da3SHartmut Brandt "truncated integer at\n");
583*0bf56da3SHartmut Brandt conv_err("x41:02:01"_cbuf, ASN_ERR_EOBUF,
584*0bf56da3SHartmut Brandt "truncated integer at 01\n");
585*0bf56da3SHartmut Brandt conv_err("x41:05:00:80:"_cbuf, ASN_ERR_EOBUF,
586*0bf56da3SHartmut Brandt "truncated integer at 00 80\n");
587*0bf56da3SHartmut Brandt conv_err("x41:05:00:ff:ff:ff"_cbuf, ASN_ERR_EOBUF,
588*0bf56da3SHartmut Brandt "truncated integer at 00 ff ff ff\n");
589*0bf56da3SHartmut Brandt }
590*0bf56da3SHartmut Brandt #endif
591*0bf56da3SHartmut Brandt }
592*0bf56da3SHartmut Brandt
593*0bf56da3SHartmut Brandt TEST_CASE("Unsigned32 building", "[asn1][build]")
594*0bf56da3SHartmut Brandt {
595*0bf56da3SHartmut Brandt asn_error = save_g_errstr;
596*0bf56da3SHartmut Brandt
__anon4d4e46190902(asn_len_t alen, uint32_t val, const auto &buf) 597*0bf56da3SHartmut Brandt const auto conv = [] (asn_len_t alen, uint32_t val, const auto &buf) {
598*0bf56da3SHartmut Brandt auto b = mk_asn_buf(alen);
599*0bf56da3SHartmut Brandt auto s = b;
600*0bf56da3SHartmut Brandt REQUIRE(asn_put_uint32(&b, ASN_APP_COUNTER, val) == ASN_ERR_OK);
601*0bf56da3SHartmut Brandt REQUIRE(b.asn_len == (size_t)0);
602*0bf56da3SHartmut Brandt check_buf(s, buf);
603*0bf56da3SHartmut Brandt };
604*0bf56da3SHartmut Brandt
605*0bf56da3SHartmut Brandt const auto conv_err = [] (asn_len_t alen, uint32_t val, asn_err err,
__anon4d4e46190a02(asn_len_t alen, uint32_t val, asn_err err, std::string_view errstr) 606*0bf56da3SHartmut Brandt std::string_view errstr) {
607*0bf56da3SHartmut Brandt auto b = mk_asn_buf(alen);
608*0bf56da3SHartmut Brandt g_errstr.clear();
609*0bf56da3SHartmut Brandt REQUIRE(asn_put_uint32(&b, ASN_APP_COUNTER, val) == err);
610*0bf56da3SHartmut Brandt REQUIRE(g_errstr == errstr);
611*0bf56da3SHartmut Brandt };
612*0bf56da3SHartmut Brandt
613*0bf56da3SHartmut Brandt conv(3, 0x0, "x41:01:00"_cbuf);
614*0bf56da3SHartmut Brandt conv(3, 0x1, "x41:01:01"_cbuf);
615*0bf56da3SHartmut Brandt conv(3, 0x7f, "x41:01:7f"_cbuf);
616*0bf56da3SHartmut Brandt
617*0bf56da3SHartmut Brandt conv(4, 0x80, "x41:02:00:80"_cbuf);
618*0bf56da3SHartmut Brandt conv(4, 0xff, "x41:02:00:ff"_cbuf);
619*0bf56da3SHartmut Brandt conv(4, 0x7fff, "x41:02:7f:ff"_cbuf);
620*0bf56da3SHartmut Brandt
621*0bf56da3SHartmut Brandt conv(5, 0x8000, "x41:03:00:80:00"_cbuf);
622*0bf56da3SHartmut Brandt conv(5, 0xffff, "x41:03:00:ff:ff"_cbuf);
623*0bf56da3SHartmut Brandt conv(5, 0x7fffff, "x41:03:7f:ff:ff"_cbuf);
624*0bf56da3SHartmut Brandt
625*0bf56da3SHartmut Brandt conv(6, 0x800000, "x41:04:00:80:00:00"_cbuf);
626*0bf56da3SHartmut Brandt conv(6, 0xffffff, "x41:04:00:ff:ff:ff"_cbuf);
627*0bf56da3SHartmut Brandt conv(6, 0x7fffffff, "x41:04:7f:ff:ff:ff"_cbuf);
628*0bf56da3SHartmut Brandt
629*0bf56da3SHartmut Brandt conv(7, 0x80000000, "x41:05:00:80:00:00:00"_cbuf);
630*0bf56da3SHartmut Brandt conv(7, 0xffffffff, "x41:05:00:ff:ff:ff:ff"_cbuf);
631*0bf56da3SHartmut Brandt
632*0bf56da3SHartmut Brandt SECTION("empty buffer") {
633*0bf56da3SHartmut Brandt conv_err(0, 0, ASN_ERR_EOBUF, "");
634*0bf56da3SHartmut Brandt }
635*0bf56da3SHartmut Brandt SECTION("buffer too short for length field") {
636*0bf56da3SHartmut Brandt conv_err(1, 0, ASN_ERR_EOBUF, "");
637*0bf56da3SHartmut Brandt }
638*0bf56da3SHartmut Brandt SECTION("buffer too short") {
639*0bf56da3SHartmut Brandt conv_err(2, 0, ASN_ERR_EOBUF, "");
640*0bf56da3SHartmut Brandt conv_err(3, 0x80, ASN_ERR_EOBUF, "");
641*0bf56da3SHartmut Brandt conv_err(4, 0x8000, ASN_ERR_EOBUF, "");
642*0bf56da3SHartmut Brandt conv_err(5, 0x800000, ASN_ERR_EOBUF, "");
643*0bf56da3SHartmut Brandt conv_err(6, 0x80000000, ASN_ERR_EOBUF, "");
644*0bf56da3SHartmut Brandt }
645*0bf56da3SHartmut Brandt }
646*0bf56da3SHartmut Brandt
647*0bf56da3SHartmut Brandt TEST_CASE("Integer parsing", "[asn1][parse]")
648*0bf56da3SHartmut Brandt {
649*0bf56da3SHartmut Brandt asn_error = save_g_errstr;
650*0bf56da3SHartmut Brandt
651*0bf56da3SHartmut Brandt /**
652*0bf56da3SHartmut Brandt * Sucessfully parse a INTEGER value.
653*0bf56da3SHartmut Brandt *
654*0bf56da3SHartmut Brandt * \param buf buffer to parse
655*0bf56da3SHartmut Brandt * \param xval expected value
656*0bf56da3SHartmut Brandt */
__anon4d4e46190b02(const auto &buf, int32_t xval) 657*0bf56da3SHartmut Brandt const auto conv = [] (const auto &buf, int32_t xval) {
658*0bf56da3SHartmut Brandt auto r = check_header(buf, ASN_TYPE_INTEGER);
659*0bf56da3SHartmut Brandt
660*0bf56da3SHartmut Brandt int32_t val;
661*0bf56da3SHartmut Brandt REQUIRE(asn_get_integer_raw(&r.buf, r.alen, &val) == ASN_ERR_OK);
662*0bf56da3SHartmut Brandt REQUIRE(val == xval);
663*0bf56da3SHartmut Brandt };
664*0bf56da3SHartmut Brandt
665*0bf56da3SHartmut Brandt /**
666*0bf56da3SHartmut Brandt * Parse INTEGER with error.
667*0bf56da3SHartmut Brandt *
668*0bf56da3SHartmut Brandt * \param buf buffer to parse
669*0bf56da3SHartmut Brandt * \param err expected error from value parser
670*0bf56da3SHartmut Brandt * \param errstr expected error string
671*0bf56da3SHartmut Brandt */
672*0bf56da3SHartmut Brandt const auto conv_err = [] (const auto &buf, asn_err err,
__anon4d4e46190c02(const auto &buf, asn_err err, std::string_view errstr) 673*0bf56da3SHartmut Brandt std::string_view errstr) {
674*0bf56da3SHartmut Brandt auto r = check_header(buf, ASN_TYPE_INTEGER);
675*0bf56da3SHartmut Brandt
676*0bf56da3SHartmut Brandt g_errstr.clear();
677*0bf56da3SHartmut Brandt int32_t val;
678*0bf56da3SHartmut Brandt REQUIRE(asn_get_integer_raw(&r.buf, r.alen, &val) == err);
679*0bf56da3SHartmut Brandt REQUIRE(g_errstr == errstr);
680*0bf56da3SHartmut Brandt };
681*0bf56da3SHartmut Brandt
682*0bf56da3SHartmut Brandt SECTION("correct encoding") {
683*0bf56da3SHartmut Brandt conv("x02:01:00"_cbuf, 0x0);
684*0bf56da3SHartmut Brandt conv("x02:01:01"_cbuf, 0x1);
685*0bf56da3SHartmut Brandt conv("x02:01:7f"_cbuf, 0x7f);
686*0bf56da3SHartmut Brandt conv("x02:01:ff"_cbuf, -0x1);
687*0bf56da3SHartmut Brandt conv("x02:01:80"_cbuf, -0x80);
688*0bf56da3SHartmut Brandt
689*0bf56da3SHartmut Brandt conv("x02:02:00:80"_cbuf, 0x80);
690*0bf56da3SHartmut Brandt conv("x02:02:00:ff"_cbuf, 0xff);
691*0bf56da3SHartmut Brandt conv("x02:02:7f:ff"_cbuf, 0x7fff);
692*0bf56da3SHartmut Brandt conv("x02:02:ff:7f"_cbuf, -0x81);
693*0bf56da3SHartmut Brandt conv("x02:02:ff:01"_cbuf, -0xff);
694*0bf56da3SHartmut Brandt conv("x02:02:ff:00"_cbuf, -0x100);
695*0bf56da3SHartmut Brandt conv("x02:02:80:00"_cbuf, -0x8000);
696*0bf56da3SHartmut Brandt
697*0bf56da3SHartmut Brandt conv("x02:03:00:80:00"_cbuf, 0x8000);
698*0bf56da3SHartmut Brandt conv("x02:03:00:ff:ff"_cbuf, 0xffff);
699*0bf56da3SHartmut Brandt conv("x02:03:7f:ff:ff"_cbuf, 0x7fffff);
700*0bf56da3SHartmut Brandt conv("x02:03:ff:7f:ff"_cbuf, -0x8001);
701*0bf56da3SHartmut Brandt conv("x02:03:ff:00:01"_cbuf, -0xffff);
702*0bf56da3SHartmut Brandt conv("x02:03:ff:00:00"_cbuf, -0x10000);
703*0bf56da3SHartmut Brandt conv("x02:03:80:00:00"_cbuf, -0x800000);
704*0bf56da3SHartmut Brandt
705*0bf56da3SHartmut Brandt conv("x02:04:00:80:00:00"_cbuf, 0x800000);
706*0bf56da3SHartmut Brandt conv("x02:04:00:ff:ff:ff"_cbuf, 0xffffff);
707*0bf56da3SHartmut Brandt conv("x02:04:7f:ff:ff:ff"_cbuf, 0x7fffffff);
708*0bf56da3SHartmut Brandt conv("x02:04:ff:7f:ff:ff"_cbuf, -0x800001);
709*0bf56da3SHartmut Brandt conv("x02:04:ff:00:00:01"_cbuf, -0xffffff);
710*0bf56da3SHartmut Brandt conv("x02:04:ff:00:00:00"_cbuf, -0x1000000);
711*0bf56da3SHartmut Brandt conv("x02:04:80:00:00:00"_cbuf, -0x80000000);
712*0bf56da3SHartmut Brandt }
713*0bf56da3SHartmut Brandt
714*0bf56da3SHartmut Brandt SECTION("zero length") {
715*0bf56da3SHartmut Brandt conv_err("x02:00"_cbuf, ASN_ERR_BADLEN,
716*0bf56da3SHartmut Brandt "zero-length integer at\n");
717*0bf56da3SHartmut Brandt }
718*0bf56da3SHartmut Brandt SECTION("too long") {
719*0bf56da3SHartmut Brandt conv_err("x02:05:01:02:03:04:05"_cbuf, ASN_ERR_BADLEN,
720*0bf56da3SHartmut Brandt "integer too long at\n");
721*0bf56da3SHartmut Brandt }
722*0bf56da3SHartmut Brandt
723*0bf56da3SHartmut Brandt SECTION("non minimal encoding") {
724*0bf56da3SHartmut Brandt conv_err("x02:02:00:00"_cbuf, ASN_ERR_BADLEN,
725*0bf56da3SHartmut Brandt "non-minimal integer at 00 00\n");
726*0bf56da3SHartmut Brandt conv_err("x02:02:00:7f"_cbuf, ASN_ERR_BADLEN,
727*0bf56da3SHartmut Brandt "non-minimal integer at 00 7f\n");
728*0bf56da3SHartmut Brandt conv_err("x02:03:00:00:80"_cbuf, ASN_ERR_BADLEN,
729*0bf56da3SHartmut Brandt "non-minimal integer at 00 00 80\n");
730*0bf56da3SHartmut Brandt conv_err("x02:04:00:00:80:00"_cbuf, ASN_ERR_BADLEN,
731*0bf56da3SHartmut Brandt "non-minimal integer at 00 00 80 00\n");
732*0bf56da3SHartmut Brandt conv_err("x02:06:00:00:00:00:00:00"_cbuf, ASN_ERR_BADLEN,
733*0bf56da3SHartmut Brandt "non-minimal integer at 00 00 00 00 00 00\n");
734*0bf56da3SHartmut Brandt conv_err("x02:06:00:01:00:00:00:00"_cbuf, ASN_ERR_BADLEN,
735*0bf56da3SHartmut Brandt "non-minimal integer at 00 01 00 00 00 00\n");
736*0bf56da3SHartmut Brandt conv_err("x02:02:ff:80"_cbuf, ASN_ERR_BADLEN,
737*0bf56da3SHartmut Brandt "non-minimal integer at ff 80\n");
738*0bf56da3SHartmut Brandt conv_err("x02:02:ff:ff"_cbuf, ASN_ERR_BADLEN,
739*0bf56da3SHartmut Brandt "non-minimal integer at ff ff\n");
740*0bf56da3SHartmut Brandt conv_err("x02:03:ff:80:00"_cbuf, ASN_ERR_BADLEN,
741*0bf56da3SHartmut Brandt "non-minimal integer at ff 80 00\n");
742*0bf56da3SHartmut Brandt conv_err("x02:03:ff:ff:ff"_cbuf, ASN_ERR_BADLEN,
743*0bf56da3SHartmut Brandt "non-minimal integer at ff ff ff\n");
744*0bf56da3SHartmut Brandt conv_err("x02:04:ff:80:00:00"_cbuf, ASN_ERR_BADLEN,
745*0bf56da3SHartmut Brandt "non-minimal integer at ff 80 00 00\n");
746*0bf56da3SHartmut Brandt conv_err("x02:04:ff:ff:ff:ff"_cbuf, ASN_ERR_BADLEN,
747*0bf56da3SHartmut Brandt "non-minimal integer at ff ff ff ff\n");
748*0bf56da3SHartmut Brandt conv_err("x02:06:ff:80:00:00:00:00"_cbuf, ASN_ERR_BADLEN,
749*0bf56da3SHartmut Brandt "non-minimal integer at ff 80 00 00 00 00\n");
750*0bf56da3SHartmut Brandt conv_err("x02:06:ff:ff:ff:ff:ff:ff"_cbuf, ASN_ERR_BADLEN,
751*0bf56da3SHartmut Brandt "non-minimal integer at ff ff ff ff ff ff\n");
752*0bf56da3SHartmut Brandt }
753*0bf56da3SHartmut Brandt
754*0bf56da3SHartmut Brandt #ifndef BOGUS_CVE_2019_5610_FIX
755*0bf56da3SHartmut Brandt SECTION("truncated value") {
756*0bf56da3SHartmut Brandt conv_err("x02:01"_cbuf, ASN_ERR_EOBUF,
757*0bf56da3SHartmut Brandt "truncated integer at\n");
758*0bf56da3SHartmut Brandt conv_err("x02:02:ff"_cbuf, ASN_ERR_EOBUF,
759*0bf56da3SHartmut Brandt "truncated integer at ff\n");
760*0bf56da3SHartmut Brandt conv_err("x02:05:ff:00:03:01"_cbuf, ASN_ERR_EOBUF,
761*0bf56da3SHartmut Brandt "truncated integer at ff 00 03 01\n");
762*0bf56da3SHartmut Brandt conv_err("x02:04:7f:ff:"_cbuf, ASN_ERR_EOBUF,
763*0bf56da3SHartmut Brandt "truncated integer at 7f ff\n");
764*0bf56da3SHartmut Brandt conv_err("x02:04:80:00:00"_cbuf, ASN_ERR_EOBUF,
765*0bf56da3SHartmut Brandt "truncated integer at 80 00 00\n");
766*0bf56da3SHartmut Brandt }
767*0bf56da3SHartmut Brandt #endif
768*0bf56da3SHartmut Brandt }
769*0bf56da3SHartmut Brandt
770*0bf56da3SHartmut Brandt TEST_CASE("Integer32 building", "[asn1][build]")
771*0bf56da3SHartmut Brandt {
772*0bf56da3SHartmut Brandt asn_error = save_g_errstr;
773*0bf56da3SHartmut Brandt
__anon4d4e46190d02(asn_len_t alen, int32_t val, const auto &buf) 774*0bf56da3SHartmut Brandt const auto conv = [] (asn_len_t alen, int32_t val, const auto &buf) {
775*0bf56da3SHartmut Brandt auto b = mk_asn_buf(alen);
776*0bf56da3SHartmut Brandt auto s = b;
777*0bf56da3SHartmut Brandt REQUIRE(asn_put_integer(&b, val) == ASN_ERR_OK);
778*0bf56da3SHartmut Brandt REQUIRE(b.asn_len == (size_t)0);
779*0bf56da3SHartmut Brandt check_buf(s, buf);
780*0bf56da3SHartmut Brandt };
781*0bf56da3SHartmut Brandt
782*0bf56da3SHartmut Brandt const auto conv_err = [] (asn_len_t alen, int32_t val, asn_err err,
__anon4d4e46190e02(asn_len_t alen, int32_t val, asn_err err, std::string_view errstr) 783*0bf56da3SHartmut Brandt std::string_view errstr) {
784*0bf56da3SHartmut Brandt auto b = mk_asn_buf(alen);
785*0bf56da3SHartmut Brandt g_errstr.clear();
786*0bf56da3SHartmut Brandt REQUIRE(asn_put_integer(&b, val) == err);
787*0bf56da3SHartmut Brandt REQUIRE(g_errstr == errstr);
788*0bf56da3SHartmut Brandt };
789*0bf56da3SHartmut Brandt
790*0bf56da3SHartmut Brandt conv(3, 0x0, "x02:01:00"_cbuf);
791*0bf56da3SHartmut Brandt conv(3, 0x1, "x02:01:01"_cbuf);
792*0bf56da3SHartmut Brandt conv(3, 0x7f, "x02:01:7f"_cbuf);
793*0bf56da3SHartmut Brandt conv(3, -0x1, "x02:01:ff"_cbuf);
794*0bf56da3SHartmut Brandt conv(3, -0x80, "x02:01:80"_cbuf);
795*0bf56da3SHartmut Brandt
796*0bf56da3SHartmut Brandt conv(4, 0x80, "x02:02:00:80"_cbuf);
797*0bf56da3SHartmut Brandt conv(4, 0xff, "x02:02:00:ff"_cbuf);
798*0bf56da3SHartmut Brandt conv(4, 0x7fff, "x02:02:7f:ff"_cbuf);
799*0bf56da3SHartmut Brandt conv(4, -0x81, "x02:02:ff:7f"_cbuf);
800*0bf56da3SHartmut Brandt conv(4, -0xff, "x02:02:ff:01"_cbuf);
801*0bf56da3SHartmut Brandt conv(4, -0x100, "x02:02:ff:00"_cbuf);
802*0bf56da3SHartmut Brandt conv(4, -0x8000, "x02:02:80:00"_cbuf);
803*0bf56da3SHartmut Brandt
804*0bf56da3SHartmut Brandt conv(5, 0x8000, "x02:03:00:80:00"_cbuf);
805*0bf56da3SHartmut Brandt conv(5, 0xffff, "x02:03:00:ff:ff"_cbuf);
806*0bf56da3SHartmut Brandt conv(5, 0x7fffff, "x02:03:7f:ff:ff"_cbuf);
807*0bf56da3SHartmut Brandt conv(5, -0x8001, "x02:03:ff:7f:ff"_cbuf);
808*0bf56da3SHartmut Brandt conv(5, -0xffff, "x02:03:ff:00:01"_cbuf);
809*0bf56da3SHartmut Brandt conv(5, -0x10000, "x02:03:ff:00:00"_cbuf);
810*0bf56da3SHartmut Brandt conv(5, -0x800000, "x02:03:80:00:00"_cbuf);
811*0bf56da3SHartmut Brandt
812*0bf56da3SHartmut Brandt conv(6, 0x800000, "x02:04:00:80:00:00"_cbuf);
813*0bf56da3SHartmut Brandt conv(6, 0xffffff, "x02:04:00:ff:ff:ff"_cbuf);
814*0bf56da3SHartmut Brandt conv(6, 0x7fffffff, "x02:04:7f:ff:ff:ff"_cbuf);
815*0bf56da3SHartmut Brandt conv(6, -0x800001, "x02:04:ff:7f:ff:ff"_cbuf);
816*0bf56da3SHartmut Brandt conv(6, -0xffffff, "x02:04:ff:00:00:01"_cbuf);
817*0bf56da3SHartmut Brandt conv(6, -0x1000000, "x02:04:ff:00:00:00"_cbuf);
818*0bf56da3SHartmut Brandt conv(6, -0x80000000, "x02:04:80:00:00:00"_cbuf);
819*0bf56da3SHartmut Brandt
820*0bf56da3SHartmut Brandt SECTION("empty buffer") {
821*0bf56da3SHartmut Brandt conv_err(0, 0, ASN_ERR_EOBUF, "");
822*0bf56da3SHartmut Brandt }
823*0bf56da3SHartmut Brandt SECTION("buffer too short for length field") {
824*0bf56da3SHartmut Brandt conv_err(1, 0, ASN_ERR_EOBUF, "");
825*0bf56da3SHartmut Brandt }
826*0bf56da3SHartmut Brandt SECTION("buffer too short") {
827*0bf56da3SHartmut Brandt conv_err(2, 0, ASN_ERR_EOBUF, "");
828*0bf56da3SHartmut Brandt conv_err(3, 0xff, ASN_ERR_EOBUF, "");
829*0bf56da3SHartmut Brandt conv_err(4, 0xffff, ASN_ERR_EOBUF, "");
830*0bf56da3SHartmut Brandt conv_err(5, 0xffffff, ASN_ERR_EOBUF, "");
831*0bf56da3SHartmut Brandt conv_err(5, 0x7fffffff, ASN_ERR_EOBUF, "");
832*0bf56da3SHartmut Brandt conv_err(2, -0x80, ASN_ERR_EOBUF, "");
833*0bf56da3SHartmut Brandt conv_err(3, -0x8000, ASN_ERR_EOBUF, "");
834*0bf56da3SHartmut Brandt conv_err(4, -0x800000, ASN_ERR_EOBUF, "");
835*0bf56da3SHartmut Brandt conv_err(5, -0x80000000, ASN_ERR_EOBUF, "");
836*0bf56da3SHartmut Brandt }
837*0bf56da3SHartmut Brandt }
838*0bf56da3SHartmut Brandt
839*0bf56da3SHartmut Brandt TEST_CASE("Oid parsing", "[asn1][parse]")
840*0bf56da3SHartmut Brandt {
841*0bf56da3SHartmut Brandt asn_error = save_g_errstr;
842*0bf56da3SHartmut Brandt
843*0bf56da3SHartmut Brandt /**
844*0bf56da3SHartmut Brandt * Sucessfully parse a INTEGER value.
845*0bf56da3SHartmut Brandt *
846*0bf56da3SHartmut Brandt * \param buf buffer to parse
847*0bf56da3SHartmut Brandt * \param xval expected value
848*0bf56da3SHartmut Brandt */
__anon4d4e46190f02(const auto &buf, const asn_oid &xval) 849*0bf56da3SHartmut Brandt const auto conv = [] (const auto &buf, const asn_oid &xval) {
850*0bf56da3SHartmut Brandt auto r = check_header(buf, ASN_TYPE_OBJID);
851*0bf56da3SHartmut Brandt
852*0bf56da3SHartmut Brandt struct asn_oid val;
853*0bf56da3SHartmut Brandt REQUIRE(asn_get_objid_raw(&r.buf, r.alen, &val) == ASN_ERR_OK);
854*0bf56da3SHartmut Brandt REQUIRE(asn_compare_oid(&val, &xval) == 0);
855*0bf56da3SHartmut Brandt };
856*0bf56da3SHartmut Brandt
857*0bf56da3SHartmut Brandt /**
858*0bf56da3SHartmut Brandt * Parse INTEGER with error.
859*0bf56da3SHartmut Brandt *
860*0bf56da3SHartmut Brandt * \param buf buffer to parse
861*0bf56da3SHartmut Brandt * \param err expected error from value parser
862*0bf56da3SHartmut Brandt * \param errstr expected error string
863*0bf56da3SHartmut Brandt */
864*0bf56da3SHartmut Brandt const auto conv_err = [] (const auto &buf, asn_err err,
__anon4d4e46191002(const auto &buf, asn_err err, std::string_view errstr) 865*0bf56da3SHartmut Brandt std::string_view errstr) {
866*0bf56da3SHartmut Brandt auto r = check_header(buf, ASN_TYPE_OBJID);
867*0bf56da3SHartmut Brandt
868*0bf56da3SHartmut Brandt g_errstr.clear();
869*0bf56da3SHartmut Brandt struct asn_oid val;
870*0bf56da3SHartmut Brandt REQUIRE(asn_get_objid_raw(&r.buf, r.alen, &val) == err);
871*0bf56da3SHartmut Brandt REQUIRE(g_errstr == errstr);
872*0bf56da3SHartmut Brandt };
873*0bf56da3SHartmut Brandt
874*0bf56da3SHartmut Brandt conv("x06:01:00"_cbuf, asn_oid {2, {0, 0}});
875*0bf56da3SHartmut Brandt conv("x06:01:28"_cbuf, asn_oid {2, {1, 0}});
876*0bf56da3SHartmut Brandt conv("x06:01:50"_cbuf, asn_oid {2, {2, 0}});
877*0bf56da3SHartmut Brandt
878*0bf56da3SHartmut Brandt conv("x06:01:27"_cbuf, asn_oid {2, {0, 39}});
879*0bf56da3SHartmut Brandt conv("x06:01:4f"_cbuf, asn_oid {2, {1, 39}});
880*0bf56da3SHartmut Brandt conv("x06:01:7f"_cbuf, asn_oid {2, {2, 47}});
881*0bf56da3SHartmut Brandt
882*0bf56da3SHartmut Brandt conv("x06:02:81:00"_cbuf, asn_oid {2, {2, 48}});
883*0bf56da3SHartmut Brandt conv("x06:02:ff:7f"_cbuf, asn_oid {2, {2, 16303}});
884*0bf56da3SHartmut Brandt conv("x06:03:ff:ff:7f"_cbuf, asn_oid {2, {2, 2097071}});
885*0bf56da3SHartmut Brandt conv("x06:04:ff:ff:ff:7f"_cbuf, asn_oid {2, {2, 268435375}});
886*0bf56da3SHartmut Brandt conv("x06:05:8f:ff:ff:ff:7f"_cbuf, asn_oid {2, {2, 4294967215}});
887*0bf56da3SHartmut Brandt
888*0bf56da3SHartmut Brandt /* maximum OID */
889*0bf56da3SHartmut Brandt conv("x06:82:02:7b:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f"_cbuf, asn_oid {128, {
890*0bf56da3SHartmut Brandt 2, 4294967215, 4294967295, 4294967295,
891*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
892*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
893*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
894*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
895*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
896*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
897*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
898*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
899*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
900*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
901*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
902*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
903*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
904*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
905*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
906*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
907*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
908*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
909*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
910*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
911*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
912*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
913*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
914*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
915*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
916*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
917*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
918*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
919*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
920*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
921*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
922*0bf56da3SHartmut Brandt }});
923*0bf56da3SHartmut Brandt
924*0bf56da3SHartmut Brandt SECTION("truncated OID") {
925*0bf56da3SHartmut Brandt #ifndef BOGUS_CVE_2019_5610_FIX
926*0bf56da3SHartmut Brandt conv_err("x06:02:01"_cbuf, ASN_ERR_EOBUF,
927*0bf56da3SHartmut Brandt "truncated OBJID at 01\n");
928*0bf56da3SHartmut Brandt #endif
929*0bf56da3SHartmut Brandt conv_err("x06:01:8f"_cbuf, ASN_ERR_EOBUF,
930*0bf56da3SHartmut Brandt "unterminated subid at\n");
931*0bf56da3SHartmut Brandt conv_err("x06:04:07:7f:82:8e"_cbuf, ASN_ERR_EOBUF,
932*0bf56da3SHartmut Brandt "unterminated subid at\n");
933*0bf56da3SHartmut Brandt }
934*0bf56da3SHartmut Brandt SECTION("short OID") {
935*0bf56da3SHartmut Brandt conv_err("x06:00"_cbuf, ASN_ERR_BADLEN,
936*0bf56da3SHartmut Brandt "short OBJID at\n");
937*0bf56da3SHartmut Brandt }
938*0bf56da3SHartmut Brandt SECTION("too long") {
939*0bf56da3SHartmut Brandt conv_err("x06:81:80:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c:7c"_cbuf, ASN_ERR_BADLEN, "OID too long (128) at 7c\n");
940*0bf56da3SHartmut Brandt }
941*0bf56da3SHartmut Brandt SECTION("subid too large") {
942*0bf56da3SHartmut Brandt conv_err("x06:06:20:90:82:83:84:75"_cbuf, ASN_ERR_RANGE,
943*0bf56da3SHartmut Brandt "OID subid too larger at 75\n");
944*0bf56da3SHartmut Brandt }
945*0bf56da3SHartmut Brandt }
946*0bf56da3SHartmut Brandt
947*0bf56da3SHartmut Brandt TEST_CASE("Objid building", "[asn1][build]")
948*0bf56da3SHartmut Brandt {
949*0bf56da3SHartmut Brandt asn_error = save_g_errstr;
950*0bf56da3SHartmut Brandt
__anon4d4e46191102(asn_len_t alen, const asn_oid &val, const auto &buf) 951*0bf56da3SHartmut Brandt const auto conv = [] (asn_len_t alen, const asn_oid &val, const auto &buf) {
952*0bf56da3SHartmut Brandt auto b = mk_asn_buf(alen);
953*0bf56da3SHartmut Brandt auto s = b;
954*0bf56da3SHartmut Brandt REQUIRE(asn_put_objid(&b, &val) == ASN_ERR_OK);
955*0bf56da3SHartmut Brandt REQUIRE(b.asn_len == (size_t)0);
956*0bf56da3SHartmut Brandt check_buf(s, buf);
957*0bf56da3SHartmut Brandt };
958*0bf56da3SHartmut Brandt
959*0bf56da3SHartmut Brandt const auto conv_err = [] (asn_len_t alen, const asn_oid &val, asn_err err,
__anon4d4e46191202(asn_len_t alen, const asn_oid &val, asn_err err, std::string_view errstr) 960*0bf56da3SHartmut Brandt std::string_view errstr) {
961*0bf56da3SHartmut Brandt auto b = mk_asn_buf(alen);
962*0bf56da3SHartmut Brandt g_errstr.clear();
963*0bf56da3SHartmut Brandt REQUIRE(asn_put_objid(&b, &val) == err);
964*0bf56da3SHartmut Brandt REQUIRE(g_errstr == errstr);
965*0bf56da3SHartmut Brandt };
966*0bf56da3SHartmut Brandt
967*0bf56da3SHartmut Brandt conv(3, asn_oid {2, {0, 0}}, "x06:01:00"_cbuf);
968*0bf56da3SHartmut Brandt conv(3, asn_oid {2, {1, 0}}, "x06:01:28"_cbuf);
969*0bf56da3SHartmut Brandt conv(3, asn_oid {2, {2, 0}}, "x06:01:50"_cbuf);
970*0bf56da3SHartmut Brandt
971*0bf56da3SHartmut Brandt conv(3, asn_oid {2, {0, 39}}, "x06:01:27"_cbuf);
972*0bf56da3SHartmut Brandt conv(3, asn_oid {2, {1, 39}}, "x06:01:4f"_cbuf);
973*0bf56da3SHartmut Brandt conv(3, asn_oid {2, {2, 47}}, "x06:01:7f"_cbuf);
974*0bf56da3SHartmut Brandt
975*0bf56da3SHartmut Brandt conv(4, asn_oid {2, {2, 48}}, "x06:02:81:00"_cbuf);
976*0bf56da3SHartmut Brandt conv(4, asn_oid {2, {2, 16303}}, "x06:02:ff:7f"_cbuf);
977*0bf56da3SHartmut Brandt conv(5, asn_oid {2, {2, 2097071}}, "x06:03:ff:ff:7f"_cbuf);
978*0bf56da3SHartmut Brandt conv(6, asn_oid {2, {2, 268435375}}, "x06:04:ff:ff:ff:7f"_cbuf);
979*0bf56da3SHartmut Brandt conv(7, asn_oid {2, {2, 4294967215}}, "x06:05:8f:ff:ff:ff:7f"_cbuf);
980*0bf56da3SHartmut Brandt
981*0bf56da3SHartmut Brandt SECTION("sub-id too large") {
982*0bf56da3SHartmut Brandt conv_err(3, asn_oid {2, {3, 0}}, ASN_ERR_RANGE,
983*0bf56da3SHartmut Brandt "oid out of range (3,0)\n");
984*0bf56da3SHartmut Brandt conv_err(3, asn_oid {2, {0, 40}}, ASN_ERR_RANGE,
985*0bf56da3SHartmut Brandt "oid out of range (0,40)\n");
986*0bf56da3SHartmut Brandt conv_err(3, asn_oid {2, {1, 40}}, ASN_ERR_RANGE,
987*0bf56da3SHartmut Brandt "oid out of range (1,40)\n");
988*0bf56da3SHartmut Brandt conv_err(3, asn_oid {2, {2, 4294967216}}, ASN_ERR_RANGE,
989*0bf56da3SHartmut Brandt "oid out of range (2,4294967216)\n");
990*0bf56da3SHartmut Brandt }
991*0bf56da3SHartmut Brandt SECTION("oid too long") {
992*0bf56da3SHartmut Brandt conv_err(200, asn_oid {129, {}}, ASN_ERR_RANGE,
993*0bf56da3SHartmut Brandt "oid too long 129\n");
994*0bf56da3SHartmut Brandt }
995*0bf56da3SHartmut Brandt SECTION("oid too short") {
996*0bf56da3SHartmut Brandt conv_err(3, asn_oid {0, {}}, ASN_ERR_RANGE,
997*0bf56da3SHartmut Brandt "short oid\n");
998*0bf56da3SHartmut Brandt conv_err(3, asn_oid {1, {0}}, ASN_ERR_RANGE,
999*0bf56da3SHartmut Brandt "short oid\n");
1000*0bf56da3SHartmut Brandt conv_err(3, asn_oid {1, {3}}, ASN_ERR_RANGE,
1001*0bf56da3SHartmut Brandt "oid[0] too large (3)\n");
1002*0bf56da3SHartmut Brandt }
1003*0bf56da3SHartmut Brandt
1004*0bf56da3SHartmut Brandt /* maximum OID */
1005*0bf56da3SHartmut Brandt conv(5 * (128 - 1) + 4, asn_oid {128, {
1006*0bf56da3SHartmut Brandt 2, 4294967215, 4294967295, 4294967295,
1007*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1008*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1009*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1010*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1011*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1012*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1013*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1014*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1015*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1016*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1017*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1018*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1019*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1020*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1021*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1022*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1023*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1024*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1025*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1026*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1027*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1028*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1029*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1030*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1031*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1032*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1033*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1034*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1035*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1036*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1037*0bf56da3SHartmut Brandt 4294967295, 4294967295, 4294967295, 4294967295,
1038*0bf56da3SHartmut Brandt }}, "x06:82:02:7b:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f:8f:ff:ff:ff:7f"_cbuf);
1039*0bf56da3SHartmut Brandt }
1040*0bf56da3SHartmut Brandt
1041*0bf56da3SHartmut Brandt /* loop tests */
1042