mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-03-24 20:40:09 +09:00
Compare commits
15 Commits
4dfcdd96b8
...
e927820082
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e927820082 | ||
|
|
67950c620d | ||
|
|
31ea4d1213 | ||
|
|
29c503ed7c | ||
|
|
b1a28f7987 | ||
|
|
616d165f14 | ||
|
|
b9ecb9283e | ||
|
|
c38edb59f2 | ||
|
|
def7a679f8 | ||
|
|
6f671919ad | ||
|
|
45b1d85fb0 | ||
|
|
e7f4cc9580 | ||
|
|
5479b276b2 | ||
|
|
5d7fbcf22a | ||
|
|
123c442a56 |
@@ -24,7 +24,7 @@ int main(void)
|
||||
int rv;
|
||||
|
||||
/* Generate a new ED25519 private key file */
|
||||
rv = ssh_pki_generate(SSH_KEYTYPE_ED25519, 0, &key);
|
||||
rv = ssh_pki_generate_key(SSH_KEYTYPE_ED25519, NULL, &key);
|
||||
if (rv != SSH_OK) {
|
||||
fprintf(stderr, "Failed to generate private key");
|
||||
return -1;
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
struct arguments_st {
|
||||
enum ssh_keytypes_e type;
|
||||
unsigned long bits;
|
||||
int bits;
|
||||
char *file;
|
||||
char *passphrase;
|
||||
char *format;
|
||||
@@ -321,8 +321,9 @@ list_fingerprint(char *file)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
ssh_pki_ctx ctx = NULL;
|
||||
ssh_key key = NULL;
|
||||
int rc = 0;
|
||||
int ret = EXIT_FAILURE, rc, fd;
|
||||
char overwrite[1024] = "";
|
||||
|
||||
char *pubkey_file = NULL;
|
||||
@@ -361,15 +362,15 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
rc = open(arguments.file, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR);
|
||||
if (rc < 0) {
|
||||
fd = open(arguments.file, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR);
|
||||
if (fd < 0) {
|
||||
if (errno == EEXIST) {
|
||||
printf("File \"%s\" exists. Overwrite it? (y|n) ", arguments.file);
|
||||
rc = scanf("%1023s", overwrite);
|
||||
if (rc > 0 && tolower(overwrite[0]) == 'y') {
|
||||
rc = open(arguments.file, O_WRONLY);
|
||||
if (rc > 0) {
|
||||
close(rc);
|
||||
fd = open(arguments.file, O_WRONLY);
|
||||
if (fd > 0) {
|
||||
close(fd);
|
||||
errno = 0;
|
||||
rc = chmod(arguments.file, S_IRUSR | S_IWUSR);
|
||||
if (rc != 0) {
|
||||
@@ -391,13 +392,30 @@ int main(int argc, char *argv[])
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
close(rc);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* Create a new PKI Context if needed -- for other types using NULL is ok */
|
||||
if (arguments.type == SSH_KEYTYPE_RSA && arguments.bits != 0) {
|
||||
ctx = ssh_pki_ctx_new();
|
||||
if (ctx == NULL) {
|
||||
fprintf(stderr, "Error: Failed to allocate PKI context\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
rc = ssh_pki_ctx_options_set(ctx,
|
||||
SSH_PKI_OPTION_RSA_KEY_SIZE,
|
||||
&arguments.bits);
|
||||
if (rc != SSH_OK) {
|
||||
fprintf(stderr, "Error: Failed to set RSA bit size\n");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
/* Generate a new private key */
|
||||
rc = ssh_pki_generate(arguments.type, arguments.bits, &key);
|
||||
rc = ssh_pki_generate_key(arguments.type, ctx, &key);
|
||||
if (rc != SSH_OK) {
|
||||
fprintf(stderr, "Error: Failed to generate keys");
|
||||
fprintf(stderr, "Error: Failed to generate keys\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -451,24 +469,23 @@ int main(int argc, char *argv[])
|
||||
|
||||
pubkey_file = (char *)malloc(strlen(arguments.file) + 5);
|
||||
if (pubkey_file == NULL) {
|
||||
rc = ENOMEM;
|
||||
goto end;
|
||||
}
|
||||
|
||||
sprintf(pubkey_file, "%s.pub", arguments.file);
|
||||
|
||||
errno = 0;
|
||||
rc = open(pubkey_file,
|
||||
fd = open(pubkey_file,
|
||||
O_CREAT | O_EXCL | O_WRONLY,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
if (rc < 0) {
|
||||
if (fd < 0) {
|
||||
if (errno == EEXIST) {
|
||||
printf("File \"%s\" exists. Overwrite it? (y|n) ", pubkey_file);
|
||||
rc = scanf("%1023s", overwrite);
|
||||
if (rc > 0 && tolower(overwrite[0]) == 'y') {
|
||||
rc = open(pubkey_file, O_WRONLY);
|
||||
if (rc > 0) {
|
||||
close(rc);
|
||||
fd = open(pubkey_file, O_WRONLY);
|
||||
if (fd > 0) {
|
||||
close(fd);
|
||||
errno = 0;
|
||||
rc = chmod(pubkey_file,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
@@ -491,7 +508,7 @@ int main(int argc, char *argv[])
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
close(rc);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* Write the public key */
|
||||
@@ -501,14 +518,12 @@ int main(int argc, char *argv[])
|
||||
goto end;
|
||||
}
|
||||
|
||||
end:
|
||||
if (key != NULL) {
|
||||
ssh_key_free(key);
|
||||
}
|
||||
ret = EXIT_SUCCESS;
|
||||
|
||||
if (arguments.file != NULL) {
|
||||
end:
|
||||
ssh_pki_ctx_free(ctx);
|
||||
ssh_key_free(key);
|
||||
free(arguments.file);
|
||||
}
|
||||
|
||||
if (arguments.passphrase != NULL) {
|
||||
#ifdef HAVE_EXPLICIT_BZERO
|
||||
@@ -519,8 +534,6 @@ end:
|
||||
free(arguments.passphrase);
|
||||
}
|
||||
|
||||
if (pubkey_file != NULL) {
|
||||
free(pubkey_file);
|
||||
}
|
||||
return rc;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
#ifndef _BYTEARRAY_H
|
||||
#define _BYTEARRAY_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define _DATA_BYTE_CONST(data, pos) \
|
||||
((uint8_t)(((const uint8_t *)(data))[(pos)]))
|
||||
|
||||
|
||||
@@ -25,14 +25,19 @@
|
||||
#ifndef _CRYPTO_H_
|
||||
#define _CRYPTO_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
#include <gcrypt.h>
|
||||
#elif defined(HAVE_LIBMBEDCRYPTO)
|
||||
#include <mbedtls/gcm.h>
|
||||
#endif
|
||||
#ifdef HAVE_OPENSSL_ECDH_H
|
||||
#include <openssl/ecdh.h>
|
||||
#endif
|
||||
|
||||
#include "libssh/wrapper.h"
|
||||
|
||||
#ifdef cbc_encrypt
|
||||
@@ -42,9 +47,6 @@
|
||||
#undef cbc_decrypt
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENSSL_ECDH_H
|
||||
#include <openssl/ecdh.h>
|
||||
#endif
|
||||
#include "libssh/curve25519.h"
|
||||
#include "libssh/dh.h"
|
||||
#include "libssh/ecdh.h"
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
#ifndef SRC_DH_GEX_H_
|
||||
#define SRC_DH_GEX_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
#ifndef SSH_KNOWNHOSTS_H_
|
||||
#define SSH_KNOWNHOSTS_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -24,8 +24,9 @@
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
|
||||
#include <gcrypt.h>
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
typedef gcry_md_hd_t SHACTX;
|
||||
typedef gcry_md_hd_t SHA256CTX;
|
||||
typedef gcry_md_hd_t SHA384CTX;
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_LIBMBEDCRYPTO
|
||||
|
||||
#include <mbedtls/md.h>
|
||||
#include <mbedtls/bignum.h>
|
||||
#include <mbedtls/pk.h>
|
||||
@@ -36,6 +35,8 @@
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
#include <mbedtls/platform.h>
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
typedef mbedtls_md_context_t *SHACTX;
|
||||
typedef mbedtls_md_context_t *SHA256CTX;
|
||||
typedef mbedtls_md_context_t *SHA384CTX;
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libssh/callbacks.h"
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
struct ssh_auth_request {
|
||||
char *username;
|
||||
int method;
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
#ifndef MISC_H_
|
||||
#define MISC_H_
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "config.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifdef _MSC_VER
|
||||
# ifndef _SSIZE_T_DEFINED
|
||||
# undef ssize_t
|
||||
@@ -31,13 +32,14 @@
|
||||
# define _SSIZE_T_DEFINED
|
||||
# endif /* _SSIZE_T_DEFINED */
|
||||
# endif /* _MSC_VER */
|
||||
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
#endif /* _WIN32 */
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,13 @@
|
||||
#ifndef _OPTIONS_H
|
||||
#define _OPTIONS_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
#ifndef PACKET_H_
|
||||
#define PACKET_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "libssh/callbacks.h"
|
||||
#include "libssh/wrapper.h"
|
||||
|
||||
struct ssh_socket_struct;
|
||||
|
||||
@@ -24,8 +24,12 @@
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_POLL
|
||||
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
#ifdef HAVE_POLL
|
||||
typedef struct pollfd ssh_pollfd_t;
|
||||
|
||||
#else /* HAVE_POLL */
|
||||
|
||||
@@ -21,9 +21,13 @@
|
||||
#ifndef _SCP_H
|
||||
#define _SCP_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
enum ssh_scp_states {
|
||||
SSH_SCP_NEW, //Data structure just created
|
||||
SSH_SCP_WRITE_INITED, //Gave our intention to write
|
||||
|
||||
@@ -21,7 +21,12 @@
|
||||
#ifndef SFTP_PRIV_H
|
||||
#define SFTP_PRIV_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libssh/sftp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -21,13 +21,14 @@
|
||||
#ifndef WRAPPER_H_
|
||||
#define WRAPPER_H_
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "libssh/libssh.h"
|
||||
#include "libssh/libcrypto.h"
|
||||
#include "libssh/libgcrypt.h"
|
||||
#include "libssh/libmbedcrypto.h"
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -310,7 +310,11 @@ static int ssh_known_hosts_read_entries(const char *match,
|
||||
}
|
||||
}
|
||||
if (entry != NULL) {
|
||||
ssh_list_append(*entries, entry);
|
||||
rc = ssh_list_append(*entries, entry);
|
||||
if (rc != SSH_OK) {
|
||||
ssh_knownhosts_entry_free(entry);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ void ssh_pki_ctx_free(ssh_pki_ctx context)
|
||||
* Set the RSA key size in bits for key generation.
|
||||
* Typically 2048, 3072, or 4096 bits. Must be greater
|
||||
* than or equal to 1024, as anything below is considered
|
||||
* insecure.
|
||||
* insecure. Use 0 (default) to use default key size (3072).
|
||||
*
|
||||
* - SSH_PKI_OPTION_SK_APPLICATION (const char *):
|
||||
* The Relying Party identifier (application string) that
|
||||
@@ -191,7 +191,7 @@ int ssh_pki_ctx_options_set(ssh_pki_ctx context,
|
||||
if (value == NULL) {
|
||||
SSH_LOG(SSH_LOG_WARN, "RSA key size pointer must not be NULL");
|
||||
return SSH_ERROR;
|
||||
} else if (*(int *)value != 0 && *(int *)value <= RSA_MIN_KEY_SIZE) {
|
||||
} else if (*(int *)value != 0 && *(int *)value < RSA_MIN_KEY_SIZE) {
|
||||
SSH_LOG(
|
||||
SSH_LOG_WARN,
|
||||
"RSA key size must be greater than %d bits or 0 for default",
|
||||
|
||||
@@ -167,7 +167,7 @@ static void torture_connect_addrfamily(void **state)
|
||||
{SSH_ADDRESS_FAMILY_INET6, "afinet6", SSH_OK},
|
||||
};
|
||||
|
||||
int aftest_count = sizeof(aftests) / sizeof(aftests[0]);
|
||||
int aftest_count = ARRAY_SIZE(aftests);
|
||||
for (int i = 0; i < aftest_count; ++i) {
|
||||
struct aftest const *t = &aftests[i];
|
||||
|
||||
|
||||
@@ -94,8 +94,7 @@ static void torture_kex_basic_functionality(void **state)
|
||||
assert_non_null(kex_algo);
|
||||
|
||||
is_valid_algo = false;
|
||||
valid_algorithms_count =
|
||||
sizeof(valid_algorithms) / sizeof(valid_algorithms[0]);
|
||||
valid_algorithms_count = ARRAY_SIZE(valid_algorithms);
|
||||
for (i = 0; i < valid_algorithms_count; i++) {
|
||||
if (strcmp(kex_algo, valid_algorithms[i]) == 0) {
|
||||
is_valid_algo = true;
|
||||
|
||||
@@ -129,6 +129,11 @@ pass environment variables to the container:
|
||||
|
||||
python infra/helper.py reproduce -eLIBSSH_VERBOSITY=9 libssh ssh_client_fuzzer ~/Downloads/clusterfuzz-testcase-ssh_client_fuzzer-4637376441483264
|
||||
|
||||
In case the nalloc fuzzer fails, running the test with `NALLOC_VERBOSE=1`
|
||||
environment variable will help to pinpoint the failed malloc:
|
||||
|
||||
python infra/helper.py reproduce -eNALLOC_VERBOSE=1 libssh ssh_known_hosts_fuzzer_nalloc ~/Downloads/clusterfuzz-testcase-minimized-ssh_known_hosts_fuzzer_nalloc-5555469543604224
|
||||
|
||||
### Fix the issue and verify the fix
|
||||
|
||||
Now, we can properly investigate the issue and once we have a fix, we can
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
@@ -22,6 +23,7 @@
|
||||
|
||||
#define LIBSSH_STATIC 1
|
||||
#include "libssh/libssh.h"
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/sftp.h"
|
||||
#include "libssh/sftp_priv.h"
|
||||
|
||||
@@ -109,7 +111,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
/* Main fuzzing target: sftp_parse_attr */
|
||||
/* Parses untrusted SFTP messages from client */
|
||||
/* Test all combinations (v3/v4, with/without name) */
|
||||
for (i = 0; i < (sizeof(versions) / sizeof(versions[0])); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(versions); i++) {
|
||||
sftp->version = versions[i];
|
||||
|
||||
/* Reset and repopulate buffer for each iteration */
|
||||
|
||||
@@ -849,10 +849,10 @@ static int pkd_run_tests(void) {
|
||||
};
|
||||
|
||||
/* Test list is populated depending on which clients are enabled. */
|
||||
struct CMUnitTest all_tests[(sizeof(openssh_tests) / sizeof(openssh_tests[0])) +
|
||||
(sizeof(dropbear_tests) / sizeof(dropbear_tests[0])) +
|
||||
(sizeof(putty_tests) / sizeof(putty_tests[0])) +
|
||||
(sizeof(noop_tests) / sizeof(noop_tests[0]))];
|
||||
struct CMUnitTest all_tests[ARRAY_SIZE(openssh_tests) +
|
||||
ARRAY_SIZE(dropbear_tests) +
|
||||
ARRAY_SIZE(putty_tests) +
|
||||
ARRAY_SIZE(noop_tests)];
|
||||
memset(&all_tests[0], 0x0, sizeof(all_tests));
|
||||
|
||||
/* Generate client keys and populate test list for each enabled client. */
|
||||
@@ -860,10 +860,10 @@ static int pkd_run_tests(void) {
|
||||
setup_openssh_client_keys();
|
||||
if (ssh_fips_mode()) {
|
||||
memcpy(&all_tests[tindex], &openssh_fips_tests[0], sizeof(openssh_fips_tests));
|
||||
tindex += (sizeof(openssh_fips_tests) / sizeof(openssh_fips_tests[0]));
|
||||
tindex += ARRAY_SIZE(openssh_fips_tests);
|
||||
} else {
|
||||
memcpy(&all_tests[tindex], &openssh_tests[0], sizeof(openssh_tests));
|
||||
tindex += (sizeof(openssh_tests) / sizeof(openssh_tests[0]));
|
||||
tindex += ARRAY_SIZE(openssh_tests);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -871,7 +871,7 @@ static int pkd_run_tests(void) {
|
||||
setup_dropbear_client_keys();
|
||||
if (!ssh_fips_mode()) {
|
||||
memcpy(&all_tests[tindex], &dropbear_tests[0], sizeof(dropbear_tests));
|
||||
tindex += (sizeof(dropbear_tests) / sizeof(dropbear_tests[0]));
|
||||
tindex += ARRAY_SIZE(dropbear_tests);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -879,12 +879,12 @@ static int pkd_run_tests(void) {
|
||||
setup_putty_client_keys();
|
||||
if (!ssh_fips_mode()) {
|
||||
memcpy(&all_tests[tindex], &putty_tests[0], sizeof(putty_tests));
|
||||
tindex += (sizeof(putty_tests) / sizeof(putty_tests[0]));
|
||||
tindex += ARRAY_SIZE(putty_tests);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(&all_tests[tindex], &noop_tests[0], sizeof(noop_tests));
|
||||
tindex += (sizeof(noop_tests) / sizeof(noop_tests[0]));
|
||||
tindex += ARRAY_SIZE(noop_tests);
|
||||
|
||||
if ((pkd_dargs.opts.testname == NULL) &&
|
||||
(pkd_dargs.opts.testmatch == NULL)) {
|
||||
|
||||
@@ -131,7 +131,7 @@ void torture_sftp_close(struct torture_sftp *t);
|
||||
void torture_write_file(const char *filename, const char *data);
|
||||
|
||||
#define torture_filter_tests(tests) \
|
||||
_torture_filter_tests(tests, sizeof(tests) / sizeof(tests)[0])
|
||||
_torture_filter_tests(tests, ARRAY_SIZE(tests))
|
||||
void _torture_filter_tests(struct CMUnitTest *tests, size_t ntests);
|
||||
|
||||
const char *torture_server_address(int domain);
|
||||
|
||||
@@ -24,8 +24,12 @@
|
||||
#ifndef _TORTURE_KEY_H
|
||||
#define _TORTURE_KEY_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "libssh/libssh.h"
|
||||
|
||||
#define TORTURE_TESTKEY_PASSWORD "libssh-rocks"
|
||||
|
||||
/* Return the encrypted private key in a new OpenSSH format */
|
||||
|
||||
@@ -10,20 +10,22 @@
|
||||
|
||||
#define LIMIT (8*1024*1024)
|
||||
|
||||
static int setup(void **state) {
|
||||
ssh_buffer buffer;
|
||||
static int setup(void **state)
|
||||
{
|
||||
ssh_buffer buffer = NULL;
|
||||
|
||||
buffer = ssh_buffer_new();
|
||||
if (buffer == NULL) {
|
||||
return -1;
|
||||
}
|
||||
ssh_buffer_set_secure(buffer);
|
||||
*state = (void *) buffer;
|
||||
*state = (void *)buffer;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int teardown(void **state) {
|
||||
static int teardown(void **state)
|
||||
{
|
||||
SSH_BUFFER_FREE(*state);
|
||||
|
||||
return 0;
|
||||
@@ -33,14 +35,15 @@ static int teardown(void **state) {
|
||||
* Test if the continuously growing buffer size never exceeds 2 time its
|
||||
* real capacity
|
||||
*/
|
||||
static void torture_growing_buffer(void **state) {
|
||||
static void torture_growing_buffer(void **state)
|
||||
{
|
||||
ssh_buffer buffer = *state;
|
||||
int i;
|
||||
|
||||
for(i=0;i<LIMIT;++i){
|
||||
ssh_buffer_add_data(buffer,"A",1);
|
||||
if(buffer->used >= 128){
|
||||
if(ssh_buffer_get_len(buffer) * 2 < buffer->allocated){
|
||||
for (i = 0; i < LIMIT; ++i) {
|
||||
ssh_buffer_add_data(buffer, "A", 1);
|
||||
if (buffer->used >= 128) {
|
||||
if (ssh_buffer_get_len(buffer) * 2 < buffer->allocated) {
|
||||
assert_true(ssh_buffer_get_len(buffer) * 2 >= buffer->allocated);
|
||||
}
|
||||
}
|
||||
@@ -51,18 +54,20 @@ static void torture_growing_buffer(void **state) {
|
||||
* Test if the continuously growing buffer size never exceeds 2 time its
|
||||
* real capacity, when we remove 1 byte after each call (sliding window)
|
||||
*/
|
||||
static void torture_growing_buffer_shifting(void **state) {
|
||||
static void torture_growing_buffer_shifting(void **state)
|
||||
{
|
||||
ssh_buffer buffer = *state;
|
||||
int i;
|
||||
unsigned char c;
|
||||
for(i=0; i<1024;++i){
|
||||
ssh_buffer_add_data(buffer,"S",1);
|
||||
|
||||
for (i = 0; i < 1024; ++i) {
|
||||
ssh_buffer_add_data(buffer, "S", 1);
|
||||
}
|
||||
for(i=0;i<LIMIT;++i){
|
||||
ssh_buffer_get_u8(buffer,&c);
|
||||
ssh_buffer_add_data(buffer,"A",1);
|
||||
if(buffer->used >= 128){
|
||||
if(ssh_buffer_get_len(buffer) * 4 < buffer->allocated){
|
||||
for (i = 0; i < LIMIT; ++i) {
|
||||
ssh_buffer_get_u8(buffer, &c);
|
||||
ssh_buffer_add_data(buffer, "A", 1);
|
||||
if (buffer->used >= 128) {
|
||||
if (ssh_buffer_get_len(buffer) * 4 < buffer->allocated) {
|
||||
assert_true(ssh_buffer_get_len(buffer) * 4 >= buffer->allocated);
|
||||
return;
|
||||
}
|
||||
@@ -73,58 +78,68 @@ static void torture_growing_buffer_shifting(void **state) {
|
||||
/*
|
||||
* Test the behavior of ssh_buffer_prepend_data
|
||||
*/
|
||||
static void torture_buffer_prepend(void **state) {
|
||||
static void torture_buffer_prepend(void **state)
|
||||
{
|
||||
ssh_buffer buffer = *state;
|
||||
uint32_t v;
|
||||
ssh_buffer_add_data(buffer,"abcdef",6);
|
||||
ssh_buffer_prepend_data(buffer,"xyz",3);
|
||||
assert_int_equal(ssh_buffer_get_len(buffer),9);
|
||||
|
||||
ssh_buffer_add_data(buffer, "abcdef", 6);
|
||||
ssh_buffer_prepend_data(buffer, "xyz", 3);
|
||||
assert_int_equal(ssh_buffer_get_len(buffer), 9);
|
||||
assert_memory_equal(ssh_buffer_get(buffer), "xyzabcdef", 9);
|
||||
|
||||
/* Now remove 4 bytes and see if we can replace them */
|
||||
ssh_buffer_get_u32(buffer,&v);
|
||||
assert_int_equal(ssh_buffer_get_len(buffer),5);
|
||||
ssh_buffer_get_u32(buffer, &v);
|
||||
assert_int_equal(ssh_buffer_get_len(buffer), 5);
|
||||
assert_memory_equal(ssh_buffer_get(buffer), "bcdef", 5);
|
||||
|
||||
ssh_buffer_prepend_data(buffer,"aris",4);
|
||||
assert_int_equal(ssh_buffer_get_len(buffer),9);
|
||||
ssh_buffer_prepend_data(buffer, "aris", 4);
|
||||
assert_int_equal(ssh_buffer_get_len(buffer), 9);
|
||||
assert_memory_equal(ssh_buffer_get(buffer), "arisbcdef", 9);
|
||||
|
||||
/* same thing but we add 5 bytes now */
|
||||
ssh_buffer_get_u32(buffer,&v);
|
||||
assert_int_equal(ssh_buffer_get_len(buffer),5);
|
||||
ssh_buffer_get_u32(buffer, &v);
|
||||
assert_int_equal(ssh_buffer_get_len(buffer), 5);
|
||||
assert_memory_equal(ssh_buffer_get(buffer), "bcdef", 5);
|
||||
|
||||
ssh_buffer_prepend_data(buffer,"12345",5);
|
||||
assert_int_equal(ssh_buffer_get_len(buffer),10);
|
||||
ssh_buffer_prepend_data(buffer, "12345", 5);
|
||||
assert_int_equal(ssh_buffer_get_len(buffer), 10);
|
||||
assert_memory_equal(ssh_buffer_get(buffer), "12345bcdef", 10);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test the behavior of ssh_buffer_get_ssh_string with invalid data
|
||||
*/
|
||||
static void torture_ssh_buffer_get_ssh_string(void **state) {
|
||||
ssh_buffer buffer;
|
||||
int i,j,k,l, rc;
|
||||
static void torture_ssh_buffer_get_ssh_string(void **state)
|
||||
{
|
||||
ssh_buffer buffer = NULL;
|
||||
int i, j, k, l, rc;
|
||||
/* some values that can go wrong */
|
||||
uint32_t values[] = {0xffffffff, 0xfffffffe, 0xfffffffc, 0xffffff00,
|
||||
0x80000000, 0x80000004, 0x7fffffff};
|
||||
uint32_t values[] = {0xffffffff,
|
||||
0xfffffffe,
|
||||
0xfffffffc,
|
||||
0xffffff00,
|
||||
0x80000000,
|
||||
0x80000004,
|
||||
0x7fffffff};
|
||||
char data[128];
|
||||
|
||||
(void)state;
|
||||
memset(data,'X',sizeof(data));
|
||||
for(i=0; i < (int)(sizeof(values)/sizeof(values[0]));++i){
|
||||
for(j=0; j< (int)sizeof(data);++j){
|
||||
for(k=1;k<5;++k){
|
||||
|
||||
memset(data, 'X', sizeof(data));
|
||||
for (i = 0; i < (int)ARRAY_SIZE(values); ++i) {
|
||||
for (j = 0; j < (int)sizeof(data); ++j) {
|
||||
for (k = 1; k < 5; ++k) {
|
||||
buffer = ssh_buffer_new();
|
||||
assert_non_null(buffer);
|
||||
|
||||
for(l=0;l<k;++l){
|
||||
rc = ssh_buffer_add_u32(buffer,htonl(values[i]));
|
||||
for (l = 0; l < k; ++l) {
|
||||
rc = ssh_buffer_add_u32(buffer, htonl(values[i]));
|
||||
assert_int_equal(rc, 0);
|
||||
}
|
||||
rc = ssh_buffer_add_data(buffer,data,j);
|
||||
rc = ssh_buffer_add_data(buffer, data, j);
|
||||
assert_int_equal(rc, 0);
|
||||
for(l=0;l<k;++l){
|
||||
for (l = 0; l < k; ++l) {
|
||||
ssh_string str = ssh_buffer_get_ssh_string(buffer);
|
||||
assert_null(str);
|
||||
SSH_STRING_FREE(str);
|
||||
@@ -135,56 +150,81 @@ static void torture_ssh_buffer_get_ssh_string(void **state) {
|
||||
}
|
||||
}
|
||||
|
||||
static void torture_ssh_buffer_add_format(void **state) {
|
||||
ssh_buffer buffer=*state;
|
||||
static void torture_ssh_buffer_add_format(void **state)
|
||||
{
|
||||
ssh_buffer buffer = *state;
|
||||
uint8_t b;
|
||||
uint16_t w;
|
||||
uint32_t d;
|
||||
uint64_t q;
|
||||
ssh_string s;
|
||||
ssh_string s = NULL;
|
||||
int rc;
|
||||
size_t len;
|
||||
uint8_t verif[]="\x42\x13\x37\x0b\xad\xc0\xde\x13\x24\x35\x46"
|
||||
uint8_t verif[] = "\x42\x13\x37\x0b\xad\xc0\xde\x13\x24\x35\x46"
|
||||
"\xac\xbd\xce\xdf"
|
||||
"\x00\x00\x00\x06" "libssh"
|
||||
"\x00\x00\x00\x05" "rocks"
|
||||
"\x00\x00\x00\x06"
|
||||
"libssh"
|
||||
"\x00\x00\x00\x05"
|
||||
"rocks"
|
||||
"So much"
|
||||
"Fun!";
|
||||
|
||||
b=0x42;
|
||||
w=0x1337;
|
||||
d=0xbadc0de;
|
||||
q=0x13243546acbdcedf;
|
||||
s=ssh_string_from_char("libssh");
|
||||
rc=ssh_buffer_pack(buffer, "bwdqSsPt",b,w,d,q,s,"rocks",(size_t)7,"So much","Fun!");
|
||||
b = 0x42;
|
||||
w = 0x1337;
|
||||
d = 0xbadc0de;
|
||||
q = 0x13243546acbdcedf;
|
||||
s = ssh_string_from_char("libssh");
|
||||
rc = ssh_buffer_pack(buffer,
|
||||
"bwdqSsPt",
|
||||
b,
|
||||
w,
|
||||
d,
|
||||
q,
|
||||
s,
|
||||
"rocks",
|
||||
(size_t)7,
|
||||
"So much",
|
||||
"Fun!");
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
|
||||
len = ssh_buffer_get_len(buffer);
|
||||
assert_int_equal(len, sizeof(verif) - 1);
|
||||
assert_memory_equal(ssh_buffer_get(buffer), verif, sizeof(verif) -1);
|
||||
assert_memory_equal(ssh_buffer_get(buffer), verif, sizeof(verif) - 1);
|
||||
|
||||
SSH_STRING_FREE(s);
|
||||
}
|
||||
|
||||
static void torture_ssh_buffer_get_format(void **state) {
|
||||
ssh_buffer buffer=*state;
|
||||
uint8_t b=0;
|
||||
uint16_t w=0;
|
||||
uint32_t d=0;
|
||||
uint64_t q=0;
|
||||
ssh_string s=NULL;
|
||||
char *s1=NULL, *s2=NULL;
|
||||
static void torture_ssh_buffer_get_format(void **state)
|
||||
{
|
||||
ssh_buffer buffer = *state;
|
||||
uint8_t b = 0;
|
||||
uint16_t w = 0;
|
||||
uint32_t d = 0;
|
||||
uint64_t q = 0;
|
||||
ssh_string s = NULL;
|
||||
char *s1 = NULL, *s2 = NULL;
|
||||
int rc;
|
||||
size_t len;
|
||||
uint8_t verif[]="\x42\x13\x37\x0b\xad\xc0\xde\x13\x24\x35\x46"
|
||||
uint8_t verif[] = "\x42\x13\x37\x0b\xad\xc0\xde\x13\x24\x35\x46"
|
||||
"\xac\xbd\xce\xdf"
|
||||
"\x00\x00\x00\x06" "libssh"
|
||||
"\x00\x00\x00\x05" "rocks"
|
||||
"\x00\x00\x00\x06"
|
||||
"libssh"
|
||||
"\x00\x00\x00\x05"
|
||||
"rocks"
|
||||
"So much";
|
||||
|
||||
rc = ssh_buffer_add_data(buffer, verif, sizeof(verif) - 1);
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
rc = ssh_buffer_unpack(buffer, "bwdqSsP",&b,&w,&d,&q,&s,&s1,(size_t)7,&s2);
|
||||
rc = ssh_buffer_unpack(buffer,
|
||||
"bwdqSsP",
|
||||
&b,
|
||||
&w,
|
||||
&d,
|
||||
&q,
|
||||
&s,
|
||||
&s1,
|
||||
(size_t)7,
|
||||
&s2);
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
|
||||
assert_int_equal(b, 0x42);
|
||||
@@ -210,24 +250,37 @@ static void torture_ssh_buffer_get_format(void **state) {
|
||||
SAFE_FREE(s2);
|
||||
}
|
||||
|
||||
static void torture_ssh_buffer_get_format_error(void **state) {
|
||||
ssh_buffer buffer=*state;
|
||||
uint8_t b=0;
|
||||
uint16_t w=0;
|
||||
uint32_t d=0;
|
||||
uint64_t q=0;
|
||||
ssh_string s=NULL;
|
||||
char *s1=NULL, *s2=NULL;
|
||||
static void torture_ssh_buffer_get_format_error(void **state)
|
||||
{
|
||||
ssh_buffer buffer = *state;
|
||||
uint8_t b = 0;
|
||||
uint16_t w = 0;
|
||||
uint32_t d = 0;
|
||||
uint64_t q = 0;
|
||||
ssh_string s = NULL;
|
||||
char *s1 = NULL, *s2 = NULL;
|
||||
int rc;
|
||||
uint8_t verif[]="\x42\x13\x37\x0b\xad\xc0\xde\x13\x24\x35\x46"
|
||||
uint8_t verif[] = "\x42\x13\x37\x0b\xad\xc0\xde\x13\x24\x35\x46"
|
||||
"\xac\xbd\xce\xdf"
|
||||
"\x00\x00\x00\x06" "libssh"
|
||||
"\x00\x00\x00\x05" "rocks"
|
||||
"\x00\x00\x00\x06"
|
||||
"libssh"
|
||||
"\x00\x00\x00\x05"
|
||||
"rocks"
|
||||
"So much";
|
||||
|
||||
rc = ssh_buffer_add_data(buffer, verif, sizeof(verif) - 1);
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
rc = ssh_buffer_unpack(buffer, "bwdqSsPb",&b,&w,&d,&q,&s,&s1,(size_t)7,&s2,&b);
|
||||
rc = ssh_buffer_unpack(buffer,
|
||||
"bwdqSsPb",
|
||||
&b,
|
||||
&w,
|
||||
&d,
|
||||
&q,
|
||||
&s,
|
||||
&s1,
|
||||
(size_t)7,
|
||||
&s2,
|
||||
&b);
|
||||
assert_int_equal(rc, SSH_ERROR);
|
||||
|
||||
assert_null(s);
|
||||
@@ -235,7 +288,8 @@ static void torture_ssh_buffer_get_format_error(void **state) {
|
||||
assert_null(s2);
|
||||
}
|
||||
|
||||
static void torture_buffer_pack_badformat(void **state){
|
||||
static void torture_buffer_pack_badformat(void **state)
|
||||
{
|
||||
ssh_buffer buffer = *state;
|
||||
uint8_t b = 42;
|
||||
int rc;
|
||||
|
||||
@@ -584,7 +584,7 @@ torture_match_cidr_address_list_ipv6(void **state)
|
||||
(void)state;
|
||||
|
||||
/* Test valid link-local addresses */
|
||||
valid_addr_len = sizeof(valid_addr) / sizeof(valid_addr[0]);
|
||||
valid_addr_len = ARRAY_SIZE(valid_addr);
|
||||
for (i = 0; i < valid_addr_len; i++) {
|
||||
rc = match_cidr_address_list(valid_addr[i], IPV6_LIST, AF_INET6);
|
||||
assert_int_equal(rc, 1);
|
||||
@@ -601,7 +601,7 @@ torture_match_cidr_address_list_ipv6(void **state)
|
||||
assert_int_equal(rc, 1);
|
||||
|
||||
/* Test some invalid input */
|
||||
invalid_addr_len = sizeof(invalid_addr) / sizeof(invalid_addr[0]);
|
||||
invalid_addr_len = ARRAY_SIZE(invalid_addr);
|
||||
for (i = 0; i < invalid_addr_len; i++) {
|
||||
rc = match_cidr_address_list(invalid_addr[i], IPV6_LIST, AF_INET6);
|
||||
assert_int_equal(rc, 0);
|
||||
|
||||
@@ -647,7 +647,7 @@ static void torture_pki_generate_key_ecdsa(void **state)
|
||||
ssh_session session=ssh_new();
|
||||
(void) state;
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_ECDSA_P256, 0, &key);
|
||||
rc = ssh_pki_generate_key(SSH_KEYTYPE_ECDSA_P256, NULL, &key);
|
||||
assert_return_code(rc, errno);
|
||||
assert_non_null(key);
|
||||
rc = ssh_pki_export_privkey_to_pubkey(key, &pubkey);
|
||||
@@ -690,7 +690,7 @@ static void torture_pki_generate_key_ecdsa(void **state)
|
||||
SSH_KEY_FREE(key);
|
||||
SSH_KEY_FREE(pubkey);
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_ECDSA_P384, 0, &key);
|
||||
rc = ssh_pki_generate_key(SSH_KEYTYPE_ECDSA_P384, NULL, &key);
|
||||
assert_return_code(rc, errno);
|
||||
assert_non_null(key);
|
||||
rc = ssh_pki_export_privkey_to_pubkey(key, &pubkey);
|
||||
@@ -733,7 +733,7 @@ static void torture_pki_generate_key_ecdsa(void **state)
|
||||
SSH_KEY_FREE(key);
|
||||
SSH_KEY_FREE(pubkey);
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_ECDSA_P521, 0, &key);
|
||||
rc = ssh_pki_generate_key(SSH_KEYTYPE_ECDSA_P521, NULL, &key);
|
||||
assert_return_code(rc, errno);
|
||||
assert_non_null(key);
|
||||
rc = ssh_pki_export_privkey_to_pubkey(key, &pubkey);
|
||||
|
||||
@@ -546,7 +546,7 @@ static void torture_pki_ed25519_generate_key(void **state)
|
||||
|
||||
assert_non_null(session);
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_ED25519, 256, &key);
|
||||
rc = ssh_pki_generate_key(SSH_KEYTYPE_ED25519, NULL, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
assert_non_null(key);
|
||||
rc = ssh_pki_export_privkey_to_pubkey(key, &pubkey);
|
||||
|
||||
@@ -440,7 +440,7 @@ static void torture_pki_rsa_copy_cert_to_privkey(void **state)
|
||||
SSH_KEY_FREE(pubkey);
|
||||
|
||||
/* Generate different key and try to assign it this certificate */
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 2048, &privkey);
|
||||
rc = ssh_pki_generate_key(SSH_KEYTYPE_RSA, NULL, &privkey);
|
||||
assert_return_code(rc, errno);
|
||||
assert_non_null(privkey);
|
||||
rc = ssh_pki_export_privkey_to_pubkey(privkey, &pubkey);
|
||||
@@ -651,8 +651,6 @@ static void torture_pki_generate_rsa_deprecated(void **state)
|
||||
ssh_signature_free(sign);
|
||||
SSH_KEY_FREE(key);
|
||||
SSH_KEY_FREE(pubkey);
|
||||
key = NULL;
|
||||
pubkey = NULL;
|
||||
}
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 2048, &key);
|
||||
@@ -668,8 +666,6 @@ static void torture_pki_generate_rsa_deprecated(void **state)
|
||||
ssh_signature_free(sign);
|
||||
SSH_KEY_FREE(key);
|
||||
SSH_KEY_FREE(pubkey);
|
||||
key = NULL;
|
||||
pubkey = NULL;
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 4096, &key);
|
||||
assert_return_code(rc, errno);
|
||||
@@ -684,8 +680,6 @@ static void torture_pki_generate_rsa_deprecated(void **state)
|
||||
ssh_signature_free(sign);
|
||||
SSH_KEY_FREE(key);
|
||||
SSH_KEY_FREE(pubkey);
|
||||
key = NULL;
|
||||
pubkey = NULL;
|
||||
|
||||
ssh_free(session);
|
||||
}
|
||||
@@ -760,15 +754,33 @@ static void torture_pki_rsa_sha2(void **state)
|
||||
|
||||
static void torture_pki_rsa_key_size(void **state)
|
||||
{
|
||||
int rc;
|
||||
int rc, bit_size;
|
||||
ssh_key key = NULL, pubkey = NULL;
|
||||
ssh_signature sign = NULL;
|
||||
ssh_session session=ssh_new();
|
||||
unsigned int length = 4096;
|
||||
ssh_pki_ctx ctx = NULL;
|
||||
|
||||
(void) state;
|
||||
(void)state;
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 2048, &key);
|
||||
ctx = ssh_pki_ctx_new();
|
||||
assert_non_null(ctx);
|
||||
|
||||
/* Invalid argument NULL */
|
||||
rc = ssh_pki_ctx_options_set(ctx, SSH_PKI_OPTION_RSA_KEY_SIZE, NULL);
|
||||
assert_ssh_return_code_equal(session, rc, SSH_ERROR);
|
||||
|
||||
/* Too small size */
|
||||
bit_size = 768;
|
||||
rc = ssh_pki_ctx_options_set(ctx, SSH_PKI_OPTION_RSA_KEY_SIZE, &bit_size);
|
||||
assert_ssh_return_code_equal(session, rc, SSH_ERROR);
|
||||
|
||||
/* Ok value */
|
||||
bit_size = 2048;
|
||||
rc = ssh_pki_ctx_options_set(ctx, SSH_PKI_OPTION_RSA_KEY_SIZE, &bit_size);
|
||||
assert_return_code(rc, errno);
|
||||
|
||||
rc = ssh_pki_generate_key(SSH_KEYTYPE_RSA, ctx, &key);
|
||||
assert_return_code(rc, errno);
|
||||
assert_non_null(key);
|
||||
rc = ssh_pki_export_privkey_to_pubkey(key, &pubkey);
|
||||
@@ -790,9 +802,7 @@ static void torture_pki_rsa_key_size(void **state)
|
||||
ssh_signature_free(sign);
|
||||
SSH_KEY_FREE(key);
|
||||
SSH_KEY_FREE(pubkey);
|
||||
key = NULL;
|
||||
pubkey = NULL;
|
||||
|
||||
SSH_PKI_CTX_FREE(ctx);
|
||||
ssh_free(session);
|
||||
}
|
||||
|
||||
@@ -890,11 +900,19 @@ static void torture_pki_sign_data_rsa(void **state)
|
||||
{
|
||||
int rc;
|
||||
ssh_key key = NULL;
|
||||
ssh_pki_ctx ctx = NULL;
|
||||
int bit_size = 2048;
|
||||
|
||||
(void) state;
|
||||
|
||||
/* Setup */
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 2048, &key);
|
||||
ctx = ssh_pki_ctx_new();
|
||||
assert_non_null(ctx);
|
||||
|
||||
rc = ssh_pki_ctx_options_set(ctx, SSH_PKI_OPTION_RSA_KEY_SIZE, &bit_size);
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
|
||||
rc = ssh_pki_generate_key(SSH_KEYTYPE_RSA, ctx, &key);
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
assert_non_null(key);
|
||||
|
||||
@@ -914,6 +932,7 @@ static void torture_pki_sign_data_rsa(void **state)
|
||||
|
||||
/* Cleanup */
|
||||
SSH_KEY_FREE(key);
|
||||
SSH_PKI_CTX_FREE(ctx);
|
||||
}
|
||||
|
||||
static void torture_pki_fail_sign_with_incompatible_hash(void **state)
|
||||
@@ -921,12 +940,20 @@ static void torture_pki_fail_sign_with_incompatible_hash(void **state)
|
||||
int rc;
|
||||
ssh_key key = NULL;
|
||||
ssh_key pubkey = NULL;
|
||||
ssh_pki_ctx ctx = NULL;
|
||||
int bit_size = 2048;
|
||||
ssh_signature sig, bad_sig;
|
||||
|
||||
(void) state;
|
||||
|
||||
/* Setup */
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 2048, &key);
|
||||
ctx = ssh_pki_ctx_new();
|
||||
assert_non_null(ctx);
|
||||
|
||||
rc = ssh_pki_ctx_options_set(ctx, SSH_PKI_OPTION_RSA_KEY_SIZE, &bit_size);
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
|
||||
rc = ssh_pki_generate_key(SSH_KEYTYPE_RSA, ctx, &key);
|
||||
assert_int_equal(rc, SSH_OK);
|
||||
assert_non_null(key);
|
||||
|
||||
@@ -956,6 +983,7 @@ static void torture_pki_fail_sign_with_incompatible_hash(void **state)
|
||||
ssh_signature_free(sig);
|
||||
SSH_KEY_FREE(pubkey);
|
||||
SSH_KEY_FREE(key);
|
||||
SSH_PKI_CTX_FREE(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -142,8 +142,7 @@ static int setup_sshsig_compat(void **state)
|
||||
test_state->original_cwd = original_cwd;
|
||||
test_state->temp_dir = temp_dir;
|
||||
test_state->test_combinations = test_combinations;
|
||||
test_state->num_combinations =
|
||||
sizeof(test_combinations) / sizeof(test_combinations[0]);
|
||||
test_state->num_combinations = ARRAY_SIZE(test_combinations);
|
||||
|
||||
*state = test_state;
|
||||
|
||||
|
||||
@@ -550,14 +550,23 @@ static void *thread_pki_rsa_generate_key(void *threadid)
|
||||
ssh_key key = NULL, pubkey = NULL;
|
||||
ssh_signature sign = NULL;
|
||||
ssh_session session = NULL;
|
||||
ssh_pki_ctx ctx = NULL;
|
||||
int size = 0;
|
||||
|
||||
(void) threadid;
|
||||
|
||||
session = ssh_new();
|
||||
assert_non_null(session);
|
||||
|
||||
ctx = ssh_pki_ctx_new();
|
||||
assert_non_null(ctx);
|
||||
|
||||
if (!ssh_fips_mode()) {
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 1024, &key);
|
||||
size = 1024;
|
||||
rc = ssh_pki_ctx_options_set(ctx, SSH_PKI_OPTION_RSA_KEY_SIZE, &size);
|
||||
assert_return_code(rc, errno);
|
||||
|
||||
rc = ssh_pki_generate_key(SSH_KEYTYPE_RSA, ctx, &key);
|
||||
assert_ssh_return_code(session, rc);
|
||||
assert_non_null(key);
|
||||
|
||||
@@ -576,7 +585,11 @@ static void *thread_pki_rsa_generate_key(void *threadid)
|
||||
SSH_KEY_FREE(pubkey);
|
||||
}
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 2048, &key);
|
||||
size = 2048;
|
||||
rc = ssh_pki_ctx_options_set(ctx, SSH_PKI_OPTION_RSA_KEY_SIZE, &size);
|
||||
assert_return_code(rc, errno);
|
||||
|
||||
rc = ssh_pki_generate_key(SSH_KEYTYPE_RSA, ctx, &key);
|
||||
assert_ssh_return_code(session, rc);
|
||||
assert_non_null(key);
|
||||
|
||||
@@ -594,8 +607,12 @@ static void *thread_pki_rsa_generate_key(void *threadid)
|
||||
SSH_KEY_FREE(key);
|
||||
SSH_KEY_FREE(pubkey);
|
||||
|
||||
rc = ssh_pki_generate(SSH_KEYTYPE_RSA, 4096, &key);
|
||||
assert_true(rc == SSH_OK);
|
||||
size = 4096;
|
||||
rc = ssh_pki_ctx_options_set(ctx, SSH_PKI_OPTION_RSA_KEY_SIZE, &size);
|
||||
assert_return_code(rc, errno);
|
||||
|
||||
rc = ssh_pki_generate_key(SSH_KEYTYPE_RSA, ctx, &key);
|
||||
assert_ssh_return_code(session, rc);
|
||||
assert_non_null(key);
|
||||
|
||||
rc = ssh_pki_export_privkey_to_pubkey(key, &pubkey);
|
||||
@@ -612,6 +629,7 @@ static void *thread_pki_rsa_generate_key(void *threadid)
|
||||
SSH_KEY_FREE(key);
|
||||
SSH_KEY_FREE(pubkey);
|
||||
|
||||
SSH_PKI_CTX_FREE(ctx);
|
||||
ssh_free(session);
|
||||
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user