summaryrefslogtreecommitdiff
path: root/test/regression/nx_secure_test/nx_secure_x509_pkcs7_decode_coverage_test.c
blob: c4c33f7c10b05ac5b4eaf6d91028e1050b63771a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation                                */
/* Copyright (c) 2026 Eclipse ThreadX contributors                         */
/*                                                                         */
/* This program and the accompanying materials are made available under    */
/* the terms of the MIT License which is available at                      */
/* https://opensource.org/licenses/MIT.                                    */
/*                                                                         */
/* SPDX-License-Identifier: MIT                                            */
/***************************************************************************/

/* This test is to cover nx_secure_x509_pkcs7_decode.c.  */

#include   "tx_api.h"
#include   "nx_api.h"
#include   "nx_tcp.h"
#include   "nx_secure_tls_api.h"
#include   "tls_test_utility.h"

extern void    test_control_return(UINT status);

#define     DEMO_STACK_SIZE         2048

/* Define the ThreadX and NetX object control blocks...  */
static TX_THREAD               thread_0;

/* Define thread prototypes.  */
static void    thread_0_entry(ULONG thread_input);
extern void    _nx_ram_network_driver_1500(struct NX_IP_DRIVER_STRUCT *driver_req);

/* Define what the initial system looks like.  */
#ifdef CTEST
void test_application_define(void *first_unused_memory);
void test_application_define(void *first_unused_memory)
#else
void nx_secure_x509_pkcs7_decode_coverage_test_application_define(void *first_unused_memory)
#endif
{
    /* Create the main thread.  */
    tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
                     first_unused_memory, DEMO_STACK_SIZE,
                     4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
}

static UCHAR signature_data[] = 
{
0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x30, 0x31, 0x30,
0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20,
0x80, 0xda, 0x3c, 0x9c, 0x9b, 0xf6, 0xe0, 0x4d, 0x4d, 0x2f, 0x92, 0xd5, 0x85, 0x99, 0xb2, 0xfb,
0x53, 0x0c, 0xc7, 0x44, 0xa8, 0xdb, 0x94, 0x89, 0x48, 0x03, 0x66, 0xc2, 0x5f, 0x60, 0xbe, 0xbd,
};


static void    thread_0_entry(ULONG thread_input)
{
UINT status;
UINT signature_length;
const UCHAR *oid;
UINT oid_length;
const UCHAR *decrypted_hash;
UINT decrypted_hash_length;
UCHAR *decrypted_signature;
UCHAR temp;

    /* Print out test information banner.  */
    printf("NetX Secure Test:   X509 PKCS7 Decode Coverage Test....................");

    /* Cover line 151. */
    decrypted_signature = signature_data;
    signature_length = sizeof(signature_data);
    temp = decrypted_signature[0xcd];
    decrypted_signature[0xcd] = 0x31;
    status = _nx_secure_x509_pkcs7_decode(decrypted_signature, signature_length, &oid, &oid_length,
                                          &decrypted_hash, &decrypted_hash_length);
    EXPECT_EQ(NX_SECURE_X509_PKCS7_PARSING_FAILED, status);
    decrypted_signature[0xcd] = 0xb0;
    status = _nx_secure_x509_pkcs7_decode(decrypted_signature, signature_length, &oid, &oid_length,
                                          &decrypted_hash, &decrypted_hash_length);
    EXPECT_EQ(NX_SECURE_X509_PKCS7_PARSING_FAILED, status);
    decrypted_signature[0xcd] = temp;

    /* Cover line 161. */
    temp = decrypted_signature[0xcf];
    decrypted_signature[0xcf] = 0x31;
    status = _nx_secure_x509_pkcs7_decode(decrypted_signature, signature_length, &oid, &oid_length,
                                          &decrypted_hash, &decrypted_hash_length);
    EXPECT_EQ(NX_SECURE_X509_PKCS7_PARSING_FAILED, status);
    decrypted_signature[0xcf] = 0xb0;
    status = _nx_secure_x509_pkcs7_decode(decrypted_signature, signature_length, &oid, &oid_length,
                                          &decrypted_hash, &decrypted_hash_length);
    EXPECT_EQ(NX_SECURE_X509_PKCS7_PARSING_FAILED, status);
    decrypted_signature[0xcf] = temp;

    /* Cover line 178.  */
    temp = decrypted_signature[0xd1];
    decrypted_signature[0xd1] = 0x86;
    status = _nx_secure_x509_pkcs7_decode(decrypted_signature, signature_length, &oid, &oid_length,
                                          &decrypted_hash, &decrypted_hash_length);
    EXPECT_EQ(NX_SECURE_X509_PKCS7_PARSING_FAILED, status);
    decrypted_signature[0xd1] = 0x07;
    status = _nx_secure_x509_pkcs7_decode(decrypted_signature, signature_length, &oid, &oid_length,
                                          &decrypted_hash, &decrypted_hash_length);
    EXPECT_EQ(NX_SECURE_X509_PKCS7_PARSING_FAILED, status);
    decrypted_signature[0xd1] = temp;

    /* Cover line 201.  */
    temp = decrypted_signature[0xde];
    decrypted_signature[0xde] = 0x84;
    status = _nx_secure_x509_pkcs7_decode(decrypted_signature, signature_length, &oid, &oid_length,
                                          &decrypted_hash, &decrypted_hash_length);
    EXPECT_EQ(NX_SECURE_X509_PKCS7_PARSING_FAILED, status);
    decrypted_signature[0xde] = temp;

    printf("SUCCESS!\n");
    test_control_return(0);
}