2016-10-27 05:12:48 +08:00
|
|
|
/*
|
2018-09-11 20:22:14 +08:00
|
|
|
* Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2016-10-27 05:12:48 +08:00
|
|
|
*
|
2018-12-06 20:05:25 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-10-27 05:12:48 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Internal tests for the asn1 module */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <openssl/asn1.h>
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/objects.h>
|
|
|
|
#include "testutil.h"
|
2017-08-22 20:35:43 +08:00
|
|
|
#include "internal/nelem.h"
|
2016-10-27 05:12:48 +08:00
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* Test of a_strnid's tbl_standard
|
|
|
|
*
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include "../crypto/asn1/tbl_standard.h"
|
|
|
|
|
2017-11-16 04:04:12 +08:00
|
|
|
static int test_tbl_standard(void)
|
2016-10-27 05:12:48 +08:00
|
|
|
{
|
|
|
|
const ASN1_STRING_TABLE *tmp;
|
|
|
|
int last_nid = -1;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) {
|
|
|
|
if (tmp->nid < last_nid) {
|
|
|
|
last_nid = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_nid = tmp->nid;
|
|
|
|
}
|
|
|
|
|
2017-06-19 09:21:22 +08:00
|
|
|
if (TEST_int_ne(last_nid, 0)) {
|
|
|
|
TEST_info("asn1 tbl_standard: Table order OK");
|
2016-10-27 05:12:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-06-20 05:58:14 +08:00
|
|
|
TEST_info("asn1 tbl_standard: out of order");
|
2016-10-27 05:12:48 +08:00
|
|
|
for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++)
|
2017-06-20 05:58:14 +08:00
|
|
|
TEST_note("asn1 tbl_standard: Index %zu, NID %d, Name=%s",
|
2017-06-19 09:21:22 +08:00
|
|
|
i, tmp->nid, OBJ_nid2ln(tmp->nid));
|
2016-10-27 05:12:48 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
*
|
|
|
|
* Test of ameth_lib's standard_methods
|
|
|
|
*
|
|
|
|
***/
|
|
|
|
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/asn1.h"
|
2016-10-27 05:12:48 +08:00
|
|
|
#include "../crypto/asn1/standard_methods.h"
|
|
|
|
|
2017-11-16 04:04:12 +08:00
|
|
|
static int test_standard_methods(void)
|
2016-10-27 05:12:48 +08:00
|
|
|
{
|
|
|
|
const EVP_PKEY_ASN1_METHOD **tmp;
|
|
|
|
int last_pkey_id = -1;
|
|
|
|
size_t i;
|
2018-08-07 10:55:47 +08:00
|
|
|
int ok = 1;
|
2016-10-27 05:12:48 +08:00
|
|
|
|
|
|
|
for (tmp = standard_methods, i = 0; i < OSSL_NELEM(standard_methods);
|
|
|
|
i++, tmp++) {
|
|
|
|
if ((*tmp)->pkey_id < last_pkey_id) {
|
|
|
|
last_pkey_id = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_pkey_id = (*tmp)->pkey_id;
|
2018-08-07 10:55:47 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* One of the following must be true:
|
|
|
|
*
|
|
|
|
* pem_str == NULL AND ASN1_PKEY_ALIAS is set
|
|
|
|
* pem_str != NULL AND ASN1_PKEY_ALIAS is clear
|
|
|
|
*
|
|
|
|
* Anything else is an error and may lead to a corrupt ASN1 method table
|
|
|
|
*/
|
2018-08-07 23:49:28 +08:00
|
|
|
if (!TEST_true(((*tmp)->pem_str == NULL && ((*tmp)->pkey_flags & ASN1_PKEY_ALIAS) != 0)
|
|
|
|
|| ((*tmp)->pem_str != NULL && ((*tmp)->pkey_flags & ASN1_PKEY_ALIAS) == 0))) {
|
2018-08-07 10:55:47 +08:00
|
|
|
TEST_note("asn1 standard methods: Index %zu, pkey ID %d, Name=%s",
|
|
|
|
i, (*tmp)->pkey_id, OBJ_nid2sn((*tmp)->pkey_id));
|
|
|
|
ok = 0;
|
|
|
|
}
|
2016-10-27 05:12:48 +08:00
|
|
|
}
|
|
|
|
|
2017-06-19 09:21:22 +08:00
|
|
|
if (TEST_int_ne(last_pkey_id, 0)) {
|
|
|
|
TEST_info("asn1 standard methods: Table order OK");
|
2018-08-07 10:55:47 +08:00
|
|
|
return ok;
|
2016-10-27 05:12:48 +08:00
|
|
|
}
|
|
|
|
|
2017-06-20 05:58:14 +08:00
|
|
|
TEST_note("asn1 standard methods: out of order");
|
2016-10-27 05:12:48 +08:00
|
|
|
for (tmp = standard_methods, i = 0; i < OSSL_NELEM(standard_methods);
|
|
|
|
i++, tmp++)
|
2017-06-20 05:58:14 +08:00
|
|
|
TEST_note("asn1 standard methods: Index %zu, pkey ID %d, Name=%s",
|
|
|
|
i, (*tmp)->pkey_id, OBJ_nid2sn((*tmp)->pkey_id));
|
2016-10-27 05:12:48 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-18 09:48:27 +08:00
|
|
|
int setup_tests(void)
|
2016-10-27 05:12:48 +08:00
|
|
|
{
|
2016-11-04 00:15:41 +08:00
|
|
|
ADD_TEST(test_tbl_standard);
|
|
|
|
ADD_TEST(test_standard_methods);
|
2017-07-18 09:48:27 +08:00
|
|
|
return 1;
|
2016-10-27 05:12:48 +08:00
|
|
|
}
|