sync
This commit is contained in:
parent
01bad5edf2
commit
f609457dcf
85 changed files with 1589 additions and 1491 deletions
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: bio_asn1.c,v 1.3 2023/04/25 19:48:24 tb Exp $ */
|
||||
/* $OpenBSD: bio_asn1.c,v 1.4 2023/05/02 09:30:37 tb Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2023 Theo Buehler <tb@openbsd.org>
|
||||
|
@ -125,8 +125,8 @@ test_prefix_leak(void)
|
|||
if ((bio_out = BIO_new(BIO_s_mem())) == NULL)
|
||||
goto err;
|
||||
|
||||
if (!i2d_ASN1_bio_stream(bio_out, (ASN1_VALUE *)pkcs7, bio_in,
|
||||
SMIME_STREAM | SMIME_BINARY, &PKCS7_it))
|
||||
if (!i2d_PKCS7_bio_stream(bio_out, pkcs7, bio_in,
|
||||
SMIME_STREAM | SMIME_BINARY))
|
||||
goto err;
|
||||
|
||||
if (set_me != 1) {
|
||||
|
|
|
@ -272,7 +272,7 @@ try_again:
|
|||
print "D- $line\n" if $verbose;
|
||||
next;
|
||||
}
|
||||
if ($id =~ /^(?:ASN1|BN|X509(?:V3)?)_[FR]_\w+$/) {
|
||||
if ($id =~ /^(?:ASN1|BIO|BN|X509(?:V3)?)_[FR]_\w+$/) {
|
||||
print "D- $line\n" if $verbose;
|
||||
next;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: x509_asn1.c,v 1.16 2023/05/01 11:02:23 job Exp $ */
|
||||
/* $OpenBSD: x509_asn1.c,v 1.17 2023/05/02 14:13:05 beck Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2023 Job Snijders <job@openbsd.org>
|
||||
*
|
||||
|
@ -512,13 +512,88 @@ test_x509_req_setters(void)
|
|||
return failed;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
static const struct testcase {
|
||||
char *data;
|
||||
int len;
|
||||
int len_to_pass;
|
||||
int encode_type;
|
||||
int expected_result;
|
||||
char *expected_string;
|
||||
} testCases[] = {
|
||||
/* should work */
|
||||
{"fozzie", 6, 80, MBSTRING_ASC, 6, "fozzie"},
|
||||
/* should work */
|
||||
{"fozzie", 6, -1, MBSTRING_ASC, 6, ""},
|
||||
/* should fail, truncation */
|
||||
{"muppet", 6, 5, MBSTRING_ASC, -1, ""},
|
||||
/* should fail, contains 0 byte */
|
||||
{"g\0nzo", 5, 80, MBSTRING_ASC, -1, ""},
|
||||
/* should fail, can't encode as utf-8 */
|
||||
{"\x30\x00", 2, 80, V_ASN1_SEQUENCE, -1, ""},
|
||||
};
|
||||
|
||||
#define NUM_TEST_CASES (sizeof(testCases) / sizeof(testCases[0]))
|
||||
|
||||
static int
|
||||
test_x509_name_get(void)
|
||||
{
|
||||
int failed = 0;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < NUM_TEST_CASES; i++) {
|
||||
const struct testcase *test = testCases + i;
|
||||
X509_NAME_ENTRY *entry = NULL;
|
||||
X509_NAME *name = NULL;
|
||||
char textbuf[80];
|
||||
int result;
|
||||
|
||||
textbuf[0] = '\0';
|
||||
if ((name = X509_NAME_new()) == NULL)
|
||||
err(1, "X509_NAME_new");
|
||||
if ((entry = X509_NAME_ENTRY_new()) == NULL)
|
||||
err(1, "X509_NAME_ENTRY_new");
|
||||
if (!X509_NAME_ENTRY_set_object(entry,
|
||||
OBJ_nid2obj(NID_commonName)))
|
||||
err(1, "X509_NAME_ENTRY_set_object");
|
||||
if (!X509_NAME_ENTRY_set_data(entry, test->encode_type,
|
||||
test->data, test->len))
|
||||
err(1, "X509_NAME_ENTRY_set_data");
|
||||
if (!X509_NAME_add_entry(name, entry, -1, 0))
|
||||
err(1, "X509_NAME_add_entry");
|
||||
if (test->len_to_pass == -1)
|
||||
result = X509_NAME_get_text_by_NID(name, NID_commonName,
|
||||
NULL, 0);
|
||||
else
|
||||
result = X509_NAME_get_text_by_NID(name, NID_commonName,
|
||||
textbuf, test->len_to_pass);
|
||||
if (result != test->expected_result) {
|
||||
fprintf(stderr,
|
||||
"Test %zu X509_GET_text_by_NID returned %d,"
|
||||
"expected %d\n", i, result, test->expected_result);
|
||||
failed++;
|
||||
}
|
||||
if (result != -1 &&
|
||||
strcmp(test->expected_string, textbuf) != 0) {
|
||||
fprintf(stderr,
|
||||
"Test %zu, X509_GET_text_by_NID returned bytes do"
|
||||
"not match \n", i);
|
||||
failed++;
|
||||
}
|
||||
X509_NAME_ENTRY_free(entry);
|
||||
X509_NAME_free(name);
|
||||
}
|
||||
return failed;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int failed = 0;
|
||||
|
||||
failed |= test_x509_setters();
|
||||
/* failed |= */ test_x509_crl_setters();
|
||||
/* failed |= */ test_x509_req_setters();
|
||||
failed |= test_x509_name_get();
|
||||
|
||||
OPENSSL_cleanup();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue