mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2025-12-30 19:25:59 +01:00
Fixed const correctness issues in programs and tests
(cherry picked from commit e0225e4d7f18f4565224f4997af537533d06a80d) Conflicts: programs/ssl/ssl_client2.c programs/ssl/ssl_server2.c programs/test/ssl_test.c programs/x509/cert_app.c
This commit is contained in:
parent
3c2122ff9d
commit
ef3f8c747e
21 changed files with 112 additions and 93 deletions
|
|
@ -75,7 +75,7 @@ int main( int argc, char *argv[] )
|
|||
{
|
||||
int ret, len, server_fd;
|
||||
unsigned char buf[1024];
|
||||
char *pers = "ssl_client1";
|
||||
const char *pers = "ssl_client1";
|
||||
|
||||
entropy_context entropy;
|
||||
ctr_drbg_context ctr_drbg;
|
||||
|
|
@ -96,7 +96,8 @@ int main( int argc, char *argv[] )
|
|||
|
||||
entropy_init( &entropy );
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
|
|
@ -111,7 +112,7 @@ int main( int argc, char *argv[] )
|
|||
fflush( stdout );
|
||||
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_crt( &cacert, (unsigned char *) test_ca_crt,
|
||||
ret = x509parse_crt( &cacert, (const unsigned char *) test_ca_crt,
|
||||
strlen( test_ca_crt ) );
|
||||
#else
|
||||
ret = 1;
|
||||
|
|
|
|||
|
|
@ -65,16 +65,16 @@
|
|||
*/
|
||||
struct options
|
||||
{
|
||||
char *server_name; /* hostname of the server (client only) */
|
||||
const char *server_name; /* hostname of the server (client only) */
|
||||
int server_port; /* port on which the ssl service runs */
|
||||
int debug_level; /* level of debugging */
|
||||
char *request_page; /* page on server to request */
|
||||
char *ca_file; /* the file with the CA certificate(s) */
|
||||
char *ca_path; /* the path with the CA certificate(s) reside */
|
||||
char *crt_file; /* the file with the client certificate */
|
||||
char *key_file; /* the file with the client key */
|
||||
char *psk; /* the pre-shared key */
|
||||
char *psk_identity; /* the pre-shared key identity */
|
||||
const char *request_page; /* page on server to request */
|
||||
const char *ca_file; /* the file with the CA certificate(s) */
|
||||
const char *ca_path; /* the path with the CA certificate(s) reside */
|
||||
const char *crt_file; /* the file with the client certificate */
|
||||
const char *key_file; /* the file with the client key */
|
||||
const char *psk; /* the pre-shared key */
|
||||
const char *psk_identity; /* the pre-shared key identity */
|
||||
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
|
||||
int renegotiation; /* enable / disable renegotiation */
|
||||
int allow_legacy; /* allow legacy renegotiation */
|
||||
|
|
@ -203,7 +203,7 @@ int main( int argc, char *argv[] )
|
|||
unsigned char psk[256];
|
||||
size_t psk_len = 0;
|
||||
#endif
|
||||
char *pers = "ssl_client2";
|
||||
const char *pers = "ssl_client2";
|
||||
|
||||
entropy_context entropy;
|
||||
ctr_drbg_context ctr_drbg;
|
||||
|
|
@ -449,7 +449,8 @@ int main( int argc, char *argv[] )
|
|||
|
||||
entropy_init( &entropy );
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned -0x%x\n", -ret );
|
||||
goto exit;
|
||||
|
|
@ -472,7 +473,7 @@ int main( int argc, char *argv[] )
|
|||
else
|
||||
#endif
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_crt( &cacert, (unsigned char *) test_ca_crt,
|
||||
ret = x509parse_crt( &cacert, (const unsigned char *) test_ca_crt,
|
||||
strlen( test_ca_crt ) );
|
||||
#else
|
||||
{
|
||||
|
|
@ -502,7 +503,7 @@ int main( int argc, char *argv[] )
|
|||
else
|
||||
#endif
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_crt( &clicert, (unsigned char *) test_cli_crt,
|
||||
ret = x509parse_crt( &clicert, (const unsigned char *) test_cli_crt,
|
||||
strlen( test_cli_crt ) );
|
||||
#else
|
||||
{
|
||||
|
|
@ -522,7 +523,7 @@ int main( int argc, char *argv[] )
|
|||
else
|
||||
#endif
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_key( &rsa, (unsigned char *) test_cli_key,
|
||||
ret = x509parse_key( &rsa, (const unsigned char *) test_cli_key,
|
||||
strlen( test_cli_key ), NULL, 0 );
|
||||
#else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ int main( int argc, char *argv[] )
|
|||
int listen_fd;
|
||||
int client_fd;
|
||||
unsigned char buf[1024];
|
||||
char *pers = "ssl_fork_server";
|
||||
const char *pers = "ssl_fork_server";
|
||||
|
||||
entropy_context entropy;
|
||||
ctr_drbg_context ctr_drbg;
|
||||
|
|
@ -118,7 +118,8 @@ int main( int argc, char *argv[] )
|
|||
|
||||
entropy_init( &entropy );
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
|
|
@ -139,7 +140,7 @@ int main( int argc, char *argv[] )
|
|||
* Instead, you may want to use x509parse_crtfile() to read the
|
||||
* server and CA certificates, as well as x509parse_keyfile().
|
||||
*/
|
||||
ret = x509parse_crt( &srvcert, (unsigned char *) test_srv_crt,
|
||||
ret = x509parse_crt( &srvcert, (const unsigned char *) test_srv_crt,
|
||||
strlen( test_srv_crt ) );
|
||||
if( ret != 0 )
|
||||
{
|
||||
|
|
@ -147,7 +148,7 @@ int main( int argc, char *argv[] )
|
|||
goto exit;
|
||||
}
|
||||
|
||||
ret = x509parse_crt( &srvcert, (unsigned char *) test_ca_crt,
|
||||
ret = x509parse_crt( &srvcert, (const unsigned char *) test_ca_crt,
|
||||
strlen( test_ca_crt ) );
|
||||
if( ret != 0 )
|
||||
{
|
||||
|
|
@ -156,7 +157,7 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
|
||||
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
||||
ret = x509parse_key( &rsa, (unsigned char *) test_srv_key,
|
||||
ret = x509parse_key( &rsa, (const unsigned char *) test_srv_key,
|
||||
strlen( test_srv_key ), NULL, 0 );
|
||||
if( ret != 0 )
|
||||
{
|
||||
|
|
@ -219,7 +220,8 @@ int main( int argc, char *argv[] )
|
|||
if( pid != 0 )
|
||||
{
|
||||
if( ( ret = ctr_drbg_reseed( &ctr_drbg,
|
||||
(unsigned char* ) "parent", 6 ) ) != 0 )
|
||||
(const unsigned char *) "parent",
|
||||
6 ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_reseed returned %d\n", ret );
|
||||
goto exit;
|
||||
|
|
@ -238,7 +240,8 @@ int main( int argc, char *argv[] )
|
|||
fflush( stdout );
|
||||
|
||||
if( ( ret = ctr_drbg_reseed( &ctr_drbg,
|
||||
(unsigned char *) "child", 5 ) ) != 0 )
|
||||
(const unsigned char *) "child",
|
||||
5 ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_reseed returned %d\n", ret );
|
||||
goto exit;
|
||||
|
|
|
|||
|
|
@ -77,18 +77,18 @@
|
|||
*/
|
||||
struct options
|
||||
{
|
||||
char *server_name; /* hostname of the server (client only) */
|
||||
const char *server_name; /* hostname of the server (client only) */
|
||||
int server_port; /* port on which the ssl service runs */
|
||||
int debug_level; /* level of debugging */
|
||||
int authentication; /* if authentication is required */
|
||||
int mode; /* SSL/TLS (0) or STARTTLS (1) */
|
||||
char *user_name; /* username to use for authentication */
|
||||
char *user_pwd; /* password to use for authentication */
|
||||
char *mail_from; /* E-Mail address to use as sender */
|
||||
char *mail_to; /* E-Mail address to use as recipient */
|
||||
char *ca_file; /* the file with the CA certificate(s) */
|
||||
char *crt_file; /* the file with the client certificate */
|
||||
char *key_file; /* the file with the client key */
|
||||
const char *user_name; /* username to use for authentication */
|
||||
const char *user_pwd; /* password to use for authentication */
|
||||
const char *mail_from; /* E-Mail address to use as sender */
|
||||
const char *mail_to; /* E-Mail address to use as recipient */
|
||||
const char *ca_file; /* the file with the CA certificate(s) */
|
||||
const char *crt_file; /* the file with the client certificate */
|
||||
const char *key_file; /* the file with the client key */
|
||||
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
|
||||
} opt;
|
||||
|
||||
|
|
@ -345,7 +345,7 @@ int main( int argc, char *argv[] )
|
|||
unsigned char base[1024];
|
||||
#endif
|
||||
char hostname[32];
|
||||
char *pers = "ssl_mail_client";
|
||||
const char *pers = "ssl_mail_client";
|
||||
|
||||
entropy_context entropy;
|
||||
ctr_drbg_context ctr_drbg;
|
||||
|
|
@ -465,7 +465,8 @@ int main( int argc, char *argv[] )
|
|||
|
||||
entropy_init( &entropy );
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
|
|
@ -485,7 +486,7 @@ int main( int argc, char *argv[] )
|
|||
else
|
||||
#endif
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_crt( &cacert, (unsigned char *) test_ca_crt,
|
||||
ret = x509parse_crt( &cacert, (const unsigned char *) test_ca_crt,
|
||||
strlen( test_ca_crt ) );
|
||||
#else
|
||||
{
|
||||
|
|
@ -515,7 +516,7 @@ int main( int argc, char *argv[] )
|
|||
else
|
||||
#endif
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_crt( &clicert, (unsigned char *) test_cli_crt,
|
||||
ret = x509parse_crt( &clicert, (const unsigned char *) test_cli_crt,
|
||||
strlen( test_cli_crt ) );
|
||||
#else
|
||||
{
|
||||
|
|
@ -535,7 +536,7 @@ int main( int argc, char *argv[] )
|
|||
else
|
||||
#endif
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_key( &rsa, (unsigned char *) test_cli_key,
|
||||
ret = x509parse_key( &rsa, (const unsigned char *) test_cli_key,
|
||||
strlen( test_cli_key ), NULL, 0 );
|
||||
#else
|
||||
{
|
||||
|
|
@ -692,7 +693,8 @@ int main( int argc, char *argv[] )
|
|||
fflush( stdout );
|
||||
|
||||
n = sizeof( buf );
|
||||
len = base64_encode( base, &n, (unsigned char *) opt.user_name, strlen( opt.user_name ) );
|
||||
len = base64_encode( base, &n, (const unsigned char *) opt.user_name,
|
||||
strlen( opt.user_name ) );
|
||||
len = sprintf( (char *) buf, "%s\n", base );
|
||||
ret = write_ssl_and_get_response( &ssl, buf, len );
|
||||
if( ret < 300 || ret > 399 )
|
||||
|
|
@ -706,7 +708,8 @@ int main( int argc, char *argv[] )
|
|||
printf( " > Write password to server: %s", opt.user_pwd );
|
||||
fflush( stdout );
|
||||
|
||||
len = base64_encode( base, &n, (unsigned char *) opt.user_pwd, strlen( opt.user_pwd ) );
|
||||
len = base64_encode( base, &n, (const unsigned char *) opt.user_pwd,
|
||||
strlen( opt.user_pwd ) );
|
||||
len = sprintf( (char *) buf, "%s\n", base );
|
||||
ret = write_ssl_and_get_response( &ssl, buf, len );
|
||||
if( ret < 200 || ret > 399 )
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ int main( int argc, char *argv[] )
|
|||
int listen_fd;
|
||||
int client_fd = -1;
|
||||
unsigned char buf[1024];
|
||||
char *pers = "ssl_server";
|
||||
const char *pers = "ssl_server";
|
||||
|
||||
entropy_context entropy;
|
||||
ctr_drbg_context ctr_drbg;
|
||||
|
|
@ -119,7 +119,7 @@ int main( int argc, char *argv[] )
|
|||
* Instead, you may want to use x509parse_crtfile() to read the
|
||||
* server and CA certificates, as well as x509parse_keyfile().
|
||||
*/
|
||||
ret = x509parse_crt( &srvcert, (unsigned char *) test_srv_crt,
|
||||
ret = x509parse_crt( &srvcert, (const unsigned char *) test_srv_crt,
|
||||
strlen( test_srv_crt ) );
|
||||
if( ret != 0 )
|
||||
{
|
||||
|
|
@ -127,7 +127,7 @@ int main( int argc, char *argv[] )
|
|||
goto exit;
|
||||
}
|
||||
|
||||
ret = x509parse_crt( &srvcert, (unsigned char *) test_ca_crt,
|
||||
ret = x509parse_crt( &srvcert, (const unsigned char *) test_ca_crt,
|
||||
strlen( test_ca_crt ) );
|
||||
if( ret != 0 )
|
||||
{
|
||||
|
|
@ -136,7 +136,7 @@ int main( int argc, char *argv[] )
|
|||
}
|
||||
|
||||
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
||||
ret = x509parse_key( &rsa, (unsigned char *) test_srv_key,
|
||||
ret = x509parse_key( &rsa, (const unsigned char *) test_srv_key,
|
||||
strlen( test_srv_key ), NULL, 0 );
|
||||
if( ret != 0 )
|
||||
{
|
||||
|
|
@ -168,7 +168,8 @@ int main( int argc, char *argv[] )
|
|||
|
||||
entropy_init( &entropy );
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned %d\n", ret );
|
||||
goto exit;
|
||||
|
|
|
|||
|
|
@ -76,12 +76,12 @@ struct options
|
|||
{
|
||||
int server_port; /* port on which the ssl service runs */
|
||||
int debug_level; /* level of debugging */
|
||||
char *ca_file; /* the file with the CA certificate(s) */
|
||||
char *ca_path; /* the path with the CA certificate(s) reside */
|
||||
char *crt_file; /* the file with the client certificate */
|
||||
char *key_file; /* the file with the client key */
|
||||
char *psk; /* the pre-shared key */
|
||||
char *psk_identity; /* the pre-shared key identity */
|
||||
const char *ca_file; /* the file with the CA certificate(s) */
|
||||
const char *ca_path; /* the path with the CA certificate(s) reside */
|
||||
const char *crt_file; /* the file with the client certificate */
|
||||
const char *key_file; /* the file with the client key */
|
||||
const char *psk; /* the pre-shared key */
|
||||
const char *psk_identity; /* the pre-shared key identity */
|
||||
int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
|
||||
int renegotiation; /* enable / disable renegotiation */
|
||||
int allow_legacy; /* allow legacy renegotiation */
|
||||
|
|
@ -168,7 +168,7 @@ int main( int argc, char *argv[] )
|
|||
unsigned char psk[256];
|
||||
size_t psk_len = 0;
|
||||
#endif
|
||||
char *pers = "ssl_server2";
|
||||
const char *pers = "ssl_server2";
|
||||
|
||||
entropy_context entropy;
|
||||
ctr_drbg_context ctr_drbg;
|
||||
|
|
@ -376,7 +376,8 @@ int main( int argc, char *argv[] )
|
|||
|
||||
entropy_init( &entropy );
|
||||
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
|
||||
(unsigned char *) pers, strlen( pers ) ) ) != 0 )
|
||||
(const unsigned char *) pers,
|
||||
strlen( pers ) ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! ctr_drbg_init returned -0x%x\n", -ret );
|
||||
goto exit;
|
||||
|
|
@ -399,7 +400,7 @@ int main( int argc, char *argv[] )
|
|||
else
|
||||
#endif
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_crt( &cacert, (unsigned char *) test_ca_crt,
|
||||
ret = x509parse_crt( &cacert, (const unsigned char *) test_ca_crt,
|
||||
strlen( test_ca_crt ) );
|
||||
#else
|
||||
{
|
||||
|
|
@ -427,7 +428,7 @@ int main( int argc, char *argv[] )
|
|||
else
|
||||
#endif
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_crt( &srvcert, (unsigned char *) test_srv_crt,
|
||||
ret = x509parse_crt( &srvcert, (const unsigned char *) test_srv_crt,
|
||||
strlen( test_srv_crt ) );
|
||||
#else
|
||||
{
|
||||
|
|
@ -447,7 +448,7 @@ int main( int argc, char *argv[] )
|
|||
else
|
||||
#endif
|
||||
#if defined(POLARSSL_CERTS_C)
|
||||
ret = x509parse_key( &rsa, (unsigned char *) test_srv_key,
|
||||
ret = x509parse_key( &rsa, (const unsigned char *) test_srv_key,
|
||||
strlen( test_srv_key ), NULL, 0 );
|
||||
#else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue