1
10
13
14
20
21
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
126
127
128
129
131
132
134
135
136
137
138
139
140
144
145
146
149
153
154
155
156
157
158
159
160
161
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
...
...
#define NX_SECURE_SOURCE_CODE
#include "nx_secure_x509.h"
...
...
UINT _nx_secure_x509_certificate_chain_verify(NX_SECURE_X509_CERTIFICATE_STORE *store,
NX_SECURE_X509_CERT *certificate)
{
UINT status;
NX_SECURE_X509_CERT *current_certificate;
NX_SECURE_X509_CERT *issuer_certificate;
UINT issuer_location = NX_SECURE_X509_CERT_LOCATION_NONE;
INT compare_result;
/* ... */
current_certificate = certificate;
if (current_certificate == NX_CRYPTO_NULL)
{
#ifdef NX_CRYPTO_STANDALONE_ENABLE
return(NX_CRYPTO_PTR_ERROR);
#else
return(NX_PTR_ERROR);
#endif
}if (current_certificate == NX_CRYPTO_NULL) { ... }
while (current_certificate != NX_CRYPTO_NULL)
{
compare_result = _nx_secure_x509_distinguished_name_compare(¤t_certificate -> nx_secure_x509_distinguished_name,
¤t_certificate -> nx_secure_x509_issuer, NX_SECURE_X509_NAME_ALL_FIELDS);
if (compare_result != 0)
{
status = _nx_secure_x509_store_certificate_find(store, ¤t_certificate -> nx_secure_x509_issuer, 0, &issuer_certificate, &issuer_location);
if (status != NX_SECURE_X509_SUCCESS)
{
return(NX_SECURE_X509_ISSUER_CERTIFICATE_NOT_FOUND);
}if (status != NX_SECURE_X509_SUCCESS) { ... }
}if (compare_result != 0) { ... }
else
{
#ifndef NX_SECURE_ALLOW_SELF_SIGNED_CERTIFICATES
return(NX_SECURE_X509_INVALID_SELF_SIGNED_CERT);/* ... */
#else
issuer_certificate = current_certificate;/* ... */
#endif
}else { ... }
status = _nx_secure_x509_certificate_verify(store, current_certificate, issuer_certificate);
if (status != 0)
{
return(status);
}if (status != 0) { ... }
else
{
/* ... */
if (issuer_location == NX_SECURE_X509_CERT_LOCATION_TRUSTED)
{
return(NX_SECURE_X509_SUCCESS);
}if (issuer_location == NX_SECURE_X509_CERT_LOCATION_TRUSTED) { ... }
#ifdef NX_SECURE_ALLOW_SELF_SIGNED_CERTIFICATES
if (issuer_certificate == current_certificate)
{
status = _nx_secure_x509_store_certificate_find(store, ¤t_certificate -> nx_secure_x509_distinguished_name, 0, &issuer_certificate, &issuer_location);
if(status == NX_SECURE_X509_SUCCESS && issuer_location == NX_SECURE_X509_CERT_LOCATION_TRUSTED)
{
return(NX_SECURE_X509_SUCCESS);
}if (status == NX_SECURE_X509_SUCCESS && issuer_location == NX_SECURE_X509_CERT_LOCATION_TRUSTED) { ... }
return(NX_SECURE_X509_CHAIN_VERIFY_FAILURE);
}if (issuer_certificate == current_certificate) { ... }
/* ... */#endif
}else { ... }
current_certificate = issuer_certificate;
}while (current_certificate != NX_CRYPTO_NULL) { ... }
return(NX_SECURE_X509_CHAIN_VERIFY_FAILURE);
}{ ... }