Greenbone Vulnerability Management Libraries 22.35.9
sshutils_tests.c File Reference
#include "sshutils.c"
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
#include <glib.h>
#include <string.h>
Include dependency graph for sshutils_tests.c:

Go to the source code of this file.

Functions

 Describe (sshutils)
 BeforeEach (sshutils)
 AfterEach (sshutils)
 Ensure (sshutils, gvm_ssh_pkcs8_decrypt_returns_null_for_null_pkcs8_key)
 Ensure (sshutils, gvm_ssh_pkcs8_decrypt_handles_empty_passphrase)
 Ensure (sshutils, gvm_ssh_pkcs8_decrypt_handles_null_passphrase)
 Ensure (sshutils, gvm_ssh_pkcs8_decrypt_returns_null_for_invalid_key)
 Ensure (sshutils, gvm_ssh_pkcs8_decrypt_decrypts_rsa_key_correctly)
 Ensure (sshutils, gvm_ssh_pkcs8_decrypt_decrypts_ecdsa_key_correctly)
 Ensure (sshutils, gvm_ssh_pkcs8_decrypt_decrypts_ed25519_key_correctly)
 Ensure (sshutils, gvm_ssh_pkcs8_decrypt_handles_unencrypted_keys)
 Ensure (sshutils, gvm_ssh_public_from_private_returns_null_for_null_private_key)
 Ensure (sshutils, gvm_ssh_public_from_private_handles_invalid_private_key)
 Ensure (sshutils, gvm_ssh_public_from_private_handles_null_passphrase)
 Ensure (sshutils, gvm_ssh_public_from_private_handles_empty_passphrase)
 Ensure (sshutils, gvm_ssh_public_from_private_generates_rsa_public_key)
 Ensure (sshutils, gvm_ssh_public_from_private_generates_ecdsa_public_key)
 Ensure (sshutils, gvm_ssh_public_from_private_generates_ed25519_public_key)
 Ensure (sshutils, gvm_ssh_public_from_private_handles_encrypted_keys)
 Ensure (sshutils, gvm_ssh_public_from_private_handles_wrong_passphrase)
 Ensure (sshutils, gvm_ssh_private_key_info_returns_minus_one_for_null_private_key)
 Ensure (sshutils, gvm_ssh_private_key_info_handles_null_type_and_hash_pointers)
 Ensure (sshutils, gvm_ssh_private_key_info_handles_null_type_pointer)
 Ensure (sshutils, gvm_ssh_private_key_info_handles_null_hash_pointer)
 Ensure (sshutils, gvm_ssh_private_key_info_handles_invalid_private_key)
 Ensure (sshutils, gvm_ssh_private_key_info_handles_null_passphrase)
 Ensure (sshutils, gvm_ssh_private_key_info_handles_empty_passphrase)
 Ensure (sshutils, gvm_ssh_private_key_info_gets_rsa_key_type_and_hash)
 Ensure (sshutils, gvm_ssh_private_key_info_gets_ecdsa_key_type_and_hash)
 Ensure (sshutils, gvm_ssh_private_key_info_gets_ed25519_key_type_and_hash)
 Ensure (sshutils, gvm_ssh_private_key_info_handles_encrypted_keys)
 Ensure (sshutils, gvm_ssh_private_key_info_handles_wrong_passphrase)
 Ensure (sshutils, gvm_ssh_private_key_info_can_get_just_type)
 Ensure (sshutils, gvm_ssh_private_key_info_can_get_just_hash)
int main (int argc, char **argv)

Variables

static const char * test_rsa_pkcs8_encrypted
static const char * test_rsa_pkcs8_unencrypted
static const char * test_ecdsa_pkcs8_encrypted
static const char * test_ecdsa_openssh_private
static const char * test_ed25519_pkcs8_encrypted
static const char * test_ed25519_openssh_private
static const char * test_rsa_public_expected
static const char * test_ecdsa_public_expected
static const char * test_ed25519_public_expected
static const char * expected_rsa_sha256_hash
static const char * expected_ecdsa_sha256_hash
static const char * expected_ed25519_sha256_hash

Function Documentation

◆ AfterEach()

AfterEach ( sshutils )

Definition at line 120 of file sshutils_tests.c.

121{
122}

◆ BeforeEach()

BeforeEach ( sshutils )

Definition at line 116 of file sshutils_tests.c.

117{
118}

◆ Describe()

Describe ( sshutils )

◆ Ensure() [1/31]

Ensure ( sshutils ,
gvm_ssh_pkcs8_decrypt_decrypts_ecdsa_key_correctly  )

Definition at line 173 of file sshutils_tests.c.

174{
175 char *result =
177 assert_that (result, is_not_null);
178 assert_that (strstr (result, "-----BEGIN EC PRIVATE KEY-----"), is_not_null);
179 assert_that (strstr (result, "-----END EC PRIVATE KEY-----"), is_not_null);
180 g_free (result);
181}
char * gvm_ssh_pkcs8_decrypt(const char *pkcs8_key, const char *passphrase)
Decrypts a base64 encrypted ssh private key.
Definition sshutils.c:34
static const char * test_ecdsa_pkcs8_encrypted

References gvm_ssh_pkcs8_decrypt(), and test_ecdsa_pkcs8_encrypted.

Here is the call graph for this function:

◆ Ensure() [2/31]

Ensure ( sshutils ,
gvm_ssh_pkcs8_decrypt_decrypts_ed25519_key_correctly  )

Definition at line 183 of file sshutils_tests.c.

184{
185 char *result =
187 assert_that (result, is_not_null);
188 assert_that (strstr (result, "-----BEGIN PRIVATE KEY-----"), is_not_null);
189 assert_that (strstr (result, "-----END PRIVATE KEY-----"), is_not_null);
190 g_free (result);
191}
static const char * test_ed25519_pkcs8_encrypted

References gvm_ssh_pkcs8_decrypt(), and test_ed25519_pkcs8_encrypted.

Here is the call graph for this function:

◆ Ensure() [3/31]

Ensure ( sshutils ,
gvm_ssh_pkcs8_decrypt_decrypts_rsa_key_correctly  )

Definition at line 163 of file sshutils_tests.c.

164{
165 char *result =
167 assert_that (result, is_not_null);
168 assert_that (strstr (result, "-----BEGIN RSA PRIVATE KEY-----"), is_not_null);
169 assert_that (strstr (result, "-----END RSA PRIVATE KEY-----"), is_not_null);
170 g_free (result);
171}
static const char * test_rsa_pkcs8_encrypted

References gvm_ssh_pkcs8_decrypt(), and test_rsa_pkcs8_encrypted.

Here is the call graph for this function:

◆ Ensure() [4/31]

Ensure ( sshutils ,
gvm_ssh_pkcs8_decrypt_handles_empty_passphrase  )

Definition at line 132 of file sshutils_tests.c.

133{
134 // Test functional equivalence: decrypted key should produce expected public
135 // key
137 assert_that (result, is_not_null);
138
139 // Generate public key from decrypted private key
140 char *pub_from_decrypted = gvm_ssh_public_from_private (result, "");
141
142 assert_that (pub_from_decrypted, is_not_null);
143 assert_that (pub_from_decrypted,
144 is_equal_to_string (test_rsa_public_expected));
145
146 g_free (result);
147 g_free (pub_from_decrypted);
148}
char * gvm_ssh_public_from_private(const char *private_key, const char *passphrase)
Exports a base64 encoded public key from a private key and its passphrase.
Definition sshutils.c:75
static const char * test_rsa_pkcs8_unencrypted
static const char * test_rsa_public_expected

References gvm_ssh_pkcs8_decrypt(), gvm_ssh_public_from_private(), test_rsa_pkcs8_unencrypted, and test_rsa_public_expected.

Here is the call graph for this function:

◆ Ensure() [5/31]

Ensure ( sshutils ,
gvm_ssh_pkcs8_decrypt_handles_null_passphrase  )

Definition at line 150 of file sshutils_tests.c.

151{
152 char *result = gvm_ssh_pkcs8_decrypt ("invalid_key", NULL);
153 assert_that (result, is_null);
154}

References gvm_ssh_pkcs8_decrypt().

Here is the call graph for this function:

◆ Ensure() [6/31]

Ensure ( sshutils ,
gvm_ssh_pkcs8_decrypt_handles_unencrypted_keys  )

Definition at line 193 of file sshutils_tests.c.

194{
196 assert_that (result, is_not_null);
197 assert_that (strstr (result, "-----BEGIN RSA PRIVATE KEY-----"), is_not_null);
198 assert_that (strstr (result, "-----END RSA PRIVATE KEY-----"), is_not_null);
199 g_free (result);
200}

References gvm_ssh_pkcs8_decrypt(), and test_rsa_pkcs8_unencrypted.

Here is the call graph for this function:

◆ Ensure() [7/31]

Ensure ( sshutils ,
gvm_ssh_pkcs8_decrypt_returns_null_for_invalid_key  )

Definition at line 156 of file sshutils_tests.c.

157{
158 char *result =
159 gvm_ssh_pkcs8_decrypt ("invalid_pkcs8_key_content", "passphrase");
160 assert_that (result, is_null);
161}

References gvm_ssh_pkcs8_decrypt().

Here is the call graph for this function:

◆ Ensure() [8/31]

Ensure ( sshutils ,
gvm_ssh_pkcs8_decrypt_returns_null_for_null_pkcs8_key  )

Definition at line 126 of file sshutils_tests.c.

127{
128 char *result = gvm_ssh_pkcs8_decrypt (NULL, "passphrase");
129 assert_that (result, is_null);
130}

References gvm_ssh_pkcs8_decrypt().

Here is the call graph for this function:

◆ Ensure() [9/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_can_get_just_hash  )

Definition at line 441 of file sshutils_tests.c.

442{
443 char *sha256_hash = NULL;
445 &sha256_hash);
446 assert_that (result, is_equal_to (0));
447 assert_that (sha256_hash, is_not_null);
448 assert_that (strlen (sha256_hash),
449 is_equal_to (64)); // SHA-256 hex is 64 chars
450 g_free (sha256_hash);
451}
int gvm_ssh_private_key_info(const char *private_key, const char *passphrase, const char **type, char **sha256_hash)
Gets information from a SSH private key.
Definition sshutils.c:116

References gvm_ssh_private_key_info(), and test_rsa_pkcs8_unencrypted.

Here is the call graph for this function:

◆ Ensure() [10/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_can_get_just_type  )

Definition at line 432 of file sshutils_tests.c.

433{
434 const char *type = NULL;
435 int result =
437 assert_that (result, is_equal_to (0));
438 assert_that (type, is_equal_to_string ("ssh-rsa"));
439}

References gvm_ssh_private_key_info(), and test_rsa_pkcs8_unencrypted.

Here is the call graph for this function:

◆ Ensure() [11/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_gets_ecdsa_key_type_and_hash  )

Definition at line 377 of file sshutils_tests.c.

378{
379 const char *type = NULL;
380 char *sha256_hash = NULL;
382 &type, &sha256_hash);
383 assert_that (result, is_equal_to (0));
384 assert_that (type, is_equal_to_string ("ecdsa-sha2-nistp256"));
385 assert_that (sha256_hash, is_not_null);
386 assert_that (strlen (sha256_hash),
387 is_equal_to (64)); // SHA-256 hex is 64 chars
388 /* Verify that the hash matches the expected value */
389 assert_that (sha256_hash, is_equal_to_string (expected_ecdsa_sha256_hash));
390 g_free (sha256_hash);
391}
static const char * test_ecdsa_openssh_private
static const char * expected_ecdsa_sha256_hash

References expected_ecdsa_sha256_hash, gvm_ssh_private_key_info(), and test_ecdsa_openssh_private.

Here is the call graph for this function:

◆ Ensure() [12/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_gets_ed25519_key_type_and_hash  )

Definition at line 393 of file sshutils_tests.c.

394{
395 const char *type = NULL;
396 char *sha256_hash = NULL;
398 &type, &sha256_hash);
399 assert_that (result, is_equal_to (0));
400 assert_that (type, is_equal_to_string ("ssh-ed25519"));
401 assert_that (sha256_hash, is_not_null);
402 assert_that (strlen (sha256_hash),
403 is_equal_to (64)); // SHA-256 hex is 64 chars
404 /* Verify that the hash matches the expected value */
405 assert_that (sha256_hash, is_equal_to_string (expected_ed25519_sha256_hash));
406 g_free (sha256_hash);
407}
static const char * test_ed25519_openssh_private
static const char * expected_ed25519_sha256_hash

References expected_ed25519_sha256_hash, gvm_ssh_private_key_info(), and test_ed25519_openssh_private.

Here is the call graph for this function:

◆ Ensure() [13/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_gets_rsa_key_type_and_hash  )

Definition at line 361 of file sshutils_tests.c.

362{
363 const char *type = NULL;
364 char *sha256_hash = NULL;
366 &type, &sha256_hash);
367 assert_that (result, is_equal_to (0));
368 assert_that (type, is_equal_to_string ("ssh-rsa"));
369 assert_that (sha256_hash, is_not_null);
370 assert_that (strlen (sha256_hash),
371 is_equal_to (64)); // SHA-256 hex is 64 chars
372 /* Verify that the hash matches the expected value */
373 assert_that (sha256_hash, is_equal_to_string (expected_rsa_sha256_hash));
374 g_free (sha256_hash);
375}
static const char * expected_rsa_sha256_hash

References expected_rsa_sha256_hash, gvm_ssh_private_key_info(), and test_rsa_pkcs8_unencrypted.

Here is the call graph for this function:

◆ Ensure() [14/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_handles_empty_passphrase  )

Definition at line 345 of file sshutils_tests.c.

346{
347 const char *type = NULL;
348 char *sha256_hash = NULL;
349 // This should successfully extract the key information
351 &sha256_hash);
352 assert_that (result, is_equal_to (0));
353 assert_that (type, is_not_null);
354 assert_that (sha256_hash, is_not_null);
355 // Verify that the extracted type and hash match the expected values
356 assert_that (type, is_equal_to_string ("ssh-rsa"));
357 assert_that (sha256_hash, is_equal_to_string (expected_rsa_sha256_hash));
358 g_free (sha256_hash);
359}

References expected_rsa_sha256_hash, gvm_ssh_private_key_info(), and test_rsa_pkcs8_unencrypted.

Here is the call graph for this function:

◆ Ensure() [15/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_handles_encrypted_keys  )

Definition at line 409 of file sshutils_tests.c.

410{
411 const char *type = NULL;
412 char *sha256_hash = NULL;
414 "testpass123", &type, &sha256_hash);
415 assert_that (result, is_equal_to (0));
416 assert_that (type, is_equal_to_string ("ssh-rsa"));
417 assert_that (sha256_hash, is_not_null);
418 g_free (sha256_hash);
419}

References gvm_ssh_private_key_info(), and test_rsa_pkcs8_encrypted.

Here is the call graph for this function:

◆ Ensure() [16/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_handles_invalid_private_key  )

Definition at line 323 of file sshutils_tests.c.

324{
325 const char *type = NULL;
326 char *sha256_hash = NULL;
327 int result = gvm_ssh_private_key_info ("invalid_private_key", "passphrase",
328 &type, &sha256_hash);
329 assert_that (result, is_equal_to (-1));
330 assert_that (type, is_null);
331 assert_that (sha256_hash, is_null);
332}

References gvm_ssh_private_key_info().

Here is the call graph for this function:

◆ Ensure() [17/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_handles_null_hash_pointer  )

Definition at line 314 of file sshutils_tests.c.

315{
316 const char *type = NULL;
317 int result =
318 gvm_ssh_private_key_info ("invalid_key", "passphrase", &type, NULL);
319 assert_that (result, is_equal_to (-1));
320 assert_that (type, is_null);
321}

References gvm_ssh_private_key_info().

Here is the call graph for this function:

◆ Ensure() [18/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_handles_null_passphrase  )

Definition at line 334 of file sshutils_tests.c.

335{
336 const char *type = NULL;
337 char *sha256_hash = NULL;
338 int result =
339 gvm_ssh_private_key_info ("invalid_private_key", NULL, &type, &sha256_hash);
340 assert_that (result, is_equal_to (-1));
341 assert_that (type, is_null);
342 assert_that (sha256_hash, is_null);
343}

References gvm_ssh_private_key_info().

Here is the call graph for this function:

◆ Ensure() [19/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_handles_null_type_and_hash_pointers  )

Definition at line 298 of file sshutils_tests.c.

299{
300 int result =
301 gvm_ssh_private_key_info ("invalid_key", "passphrase", NULL, NULL);
302 assert_that (result, is_equal_to (-1));
303}

References gvm_ssh_private_key_info().

Here is the call graph for this function:

◆ Ensure() [20/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_handles_null_type_pointer  )

Definition at line 305 of file sshutils_tests.c.

306{
307 char *sha256_hash = NULL;
308 int result =
309 gvm_ssh_private_key_info ("invalid_key", "passphrase", NULL, &sha256_hash);
310 assert_that (result, is_equal_to (-1));
311 assert_that (sha256_hash, is_null);
312}

References gvm_ssh_private_key_info().

Here is the call graph for this function:

◆ Ensure() [21/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_handles_wrong_passphrase  )

Definition at line 421 of file sshutils_tests.c.

422{
423 const char *type = NULL;
424 char *sha256_hash = NULL;
425 int result = gvm_ssh_private_key_info (test_rsa_pkcs8_encrypted, "wrongpass",
426 &type, &sha256_hash);
427 assert_that (result, is_equal_to (-1));
428 assert_that (type, is_null);
429 assert_that (sha256_hash, is_null);
430}

References gvm_ssh_private_key_info(), and test_rsa_pkcs8_encrypted.

Here is the call graph for this function:

◆ Ensure() [22/31]

Ensure ( sshutils ,
gvm_ssh_private_key_info_returns_minus_one_for_null_private_key  )

Definition at line 286 of file sshutils_tests.c.

288{
289 const char *type = NULL;
290 char *sha256_hash = NULL;
291 int result =
292 gvm_ssh_private_key_info (NULL, "passphrase", &type, &sha256_hash);
293 assert_that (result, is_equal_to (-1));
294 assert_that (type, is_null);
295 assert_that (sha256_hash, is_null);
296}

References gvm_ssh_private_key_info().

Here is the call graph for this function:

◆ Ensure() [23/31]

Ensure ( sshutils ,
gvm_ssh_public_from_private_generates_ecdsa_public_key  )

Definition at line 245 of file sshutils_tests.c.

246{
248 assert_that (result, is_not_null);
249 assert_that (strstr (result, "ecdsa-sha2-nistp256"), is_not_null);
250 assert_that (strchr (result, ' '), is_not_null);
251 // Verify that the generated public key matches the expected value
252 assert_that (result, is_equal_to_string (test_ecdsa_public_expected));
253 g_free (result);
254}
static const char * test_ecdsa_public_expected

References gvm_ssh_public_from_private(), test_ecdsa_openssh_private, and test_ecdsa_public_expected.

Here is the call graph for this function:

◆ Ensure() [24/31]

Ensure ( sshutils ,
gvm_ssh_public_from_private_generates_ed25519_public_key  )

Definition at line 256 of file sshutils_tests.c.

257{
258 char *result =
260 assert_that (result, is_not_null);
261 assert_that (strstr (result, "ssh-ed25519"), is_not_null);
262 assert_that (strchr (result, ' '), is_not_null);
263 // Verify that the generated public key matches the expected value
264 assert_that (result, is_equal_to_string (test_ed25519_public_expected));
265 g_free (result);
266}
static const char * test_ed25519_public_expected

References gvm_ssh_public_from_private(), test_ed25519_openssh_private, and test_ed25519_public_expected.

Here is the call graph for this function:

◆ Ensure() [25/31]

Ensure ( sshutils ,
gvm_ssh_public_from_private_generates_rsa_public_key  )

Definition at line 233 of file sshutils_tests.c.

234{
236 assert_that (result, is_not_null);
237 assert_that (strstr (result, "ssh-rsa"), is_not_null);
238 // Verify it matches expected format (type + space + base64_key)
239 assert_that (strchr (result, ' '), is_not_null);
240 // Verify that the generated public key matches the expected value
241 assert_that (result, is_equal_to_string (test_rsa_public_expected));
242 g_free (result);
243}

References gvm_ssh_public_from_private(), test_rsa_pkcs8_unencrypted, and test_rsa_public_expected.

Here is the call graph for this function:

◆ Ensure() [26/31]

Ensure ( sshutils ,
gvm_ssh_public_from_private_handles_empty_passphrase  )

Definition at line 223 of file sshutils_tests.c.

224{
225 // This should successfully generate the public key
227 assert_that (result, is_not_null);
228 assert_that (strstr (result, "ssh-rsa"), is_not_null);
229 assert_that (result, is_equal_to_string (test_rsa_public_expected));
230 g_free (result);
231}

References gvm_ssh_public_from_private(), test_rsa_pkcs8_unencrypted, and test_rsa_public_expected.

Here is the call graph for this function:

◆ Ensure() [27/31]

Ensure ( sshutils ,
gvm_ssh_public_from_private_handles_encrypted_keys  )

Definition at line 268 of file sshutils_tests.c.

269{
270 char *result =
272 assert_that (result, is_not_null);
273 assert_that (strstr (result, "ssh-rsa"), is_not_null);
274 g_free (result);
275}

References gvm_ssh_public_from_private(), and test_rsa_pkcs8_encrypted.

Here is the call graph for this function:

◆ Ensure() [28/31]

Ensure ( sshutils ,
gvm_ssh_public_from_private_handles_invalid_private_key  )

Definition at line 210 of file sshutils_tests.c.

211{
212 char *result =
213 gvm_ssh_public_from_private ("invalid_private_key", "passphrase");
214 assert_that (result, is_null);
215}

References gvm_ssh_public_from_private().

Here is the call graph for this function:

◆ Ensure() [29/31]

Ensure ( sshutils ,
gvm_ssh_public_from_private_handles_null_passphrase  )

Definition at line 217 of file sshutils_tests.c.

218{
219 char *result = gvm_ssh_public_from_private ("invalid_private_key", NULL);
220 assert_that (result, is_null);
221}

References gvm_ssh_public_from_private().

Here is the call graph for this function:

◆ Ensure() [30/31]

Ensure ( sshutils ,
gvm_ssh_public_from_private_handles_wrong_passphrase  )

Definition at line 277 of file sshutils_tests.c.

278{
279 char *result =
281 assert_that (result, is_null);
282}

References gvm_ssh_public_from_private(), and test_rsa_pkcs8_encrypted.

Here is the call graph for this function:

◆ Ensure() [31/31]

Ensure ( sshutils ,
gvm_ssh_public_from_private_returns_null_for_null_private_key  )

Definition at line 204 of file sshutils_tests.c.

205{
206 char *result = gvm_ssh_public_from_private (NULL, "passphrase");
207 assert_that (result, is_null);
208}

References gvm_ssh_public_from_private().

Here is the call graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 456 of file sshutils_tests.c.

457{
458 int ret;
459 TestSuite *suite;
460
461 suite = create_test_suite ();
462
463 add_test_with_context (suite, sshutils,
464 gvm_ssh_pkcs8_decrypt_returns_null_for_null_pkcs8_key);
465 add_test_with_context (suite, sshutils,
466 gvm_ssh_pkcs8_decrypt_handles_empty_passphrase);
467 add_test_with_context (suite, sshutils,
468 gvm_ssh_pkcs8_decrypt_handles_null_passphrase);
469 add_test_with_context (suite, sshutils,
470 gvm_ssh_pkcs8_decrypt_returns_null_for_invalid_key);
471 add_test_with_context (suite, sshutils,
472 gvm_ssh_pkcs8_decrypt_decrypts_rsa_key_correctly);
473 add_test_with_context (suite, sshutils,
474 gvm_ssh_pkcs8_decrypt_decrypts_ecdsa_key_correctly);
475 add_test_with_context (suite, sshutils,
476 gvm_ssh_pkcs8_decrypt_decrypts_ed25519_key_correctly);
477 add_test_with_context (suite, sshutils,
478 gvm_ssh_pkcs8_decrypt_handles_unencrypted_keys);
479
480 add_test_with_context (
481 suite, sshutils,
482 gvm_ssh_public_from_private_returns_null_for_null_private_key);
483 add_test_with_context (
484 suite, sshutils, gvm_ssh_public_from_private_handles_invalid_private_key);
485 add_test_with_context (suite, sshutils,
486 gvm_ssh_public_from_private_handles_null_passphrase);
487 add_test_with_context (suite, sshutils,
488 gvm_ssh_public_from_private_handles_empty_passphrase);
489 add_test_with_context (suite, sshutils,
490 gvm_ssh_public_from_private_generates_rsa_public_key);
491 add_test_with_context (
492 suite, sshutils, gvm_ssh_public_from_private_generates_ecdsa_public_key);
493 add_test_with_context (
494 suite, sshutils, gvm_ssh_public_from_private_generates_ed25519_public_key);
495 add_test_with_context (suite, sshutils,
496 gvm_ssh_public_from_private_handles_encrypted_keys);
497 add_test_with_context (suite, sshutils,
498 gvm_ssh_public_from_private_handles_wrong_passphrase);
499
500 add_test_with_context (
501 suite, sshutils,
502 gvm_ssh_private_key_info_returns_minus_one_for_null_private_key);
503 add_test_with_context (
504 suite, sshutils,
505 gvm_ssh_private_key_info_handles_null_type_and_hash_pointers);
506 add_test_with_context (suite, sshutils,
507 gvm_ssh_private_key_info_handles_null_type_pointer);
508 add_test_with_context (suite, sshutils,
509 gvm_ssh_private_key_info_handles_null_hash_pointer);
510 add_test_with_context (suite, sshutils,
511 gvm_ssh_private_key_info_handles_invalid_private_key);
512 add_test_with_context (suite, sshutils,
513 gvm_ssh_private_key_info_handles_null_passphrase);
514 add_test_with_context (suite, sshutils,
515 gvm_ssh_private_key_info_handles_empty_passphrase);
516 add_test_with_context (suite, sshutils,
517 gvm_ssh_private_key_info_gets_rsa_key_type_and_hash);
518 add_test_with_context (suite, sshutils,
519 gvm_ssh_private_key_info_gets_ecdsa_key_type_and_hash);
520 add_test_with_context (
521 suite, sshutils, gvm_ssh_private_key_info_gets_ed25519_key_type_and_hash);
522 add_test_with_context (suite, sshutils,
523 gvm_ssh_private_key_info_handles_encrypted_keys);
524 add_test_with_context (suite, sshutils,
525 gvm_ssh_private_key_info_handles_wrong_passphrase);
526 add_test_with_context (suite, sshutils,
527 gvm_ssh_private_key_info_can_get_just_type);
528 add_test_with_context (suite, sshutils,
529 gvm_ssh_private_key_info_can_get_just_hash);
530
531 if (argc > 1)
532 ret = run_single_test (suite, argv[1], create_text_reporter ());
533 else
534 ret = run_test_suite (suite, create_text_reporter ());
535
536 destroy_test_suite (suite);
537
538 return ret;
539}

Variable Documentation

◆ expected_ecdsa_sha256_hash

const char* expected_ecdsa_sha256_hash
static
Initial value:
=
"e176454f3e3de11a826e3b72a7a3971fbf823dbd464512f14340378b647c209a"

Definition at line 109 of file sshutils_tests.c.

Referenced by Ensure().

◆ expected_ed25519_sha256_hash

const char* expected_ed25519_sha256_hash
static
Initial value:
=
"62ff0717d25f334662fc5d0ca4ecac4db7b5c1cf57f599aa59f664014a2898ec"

Definition at line 112 of file sshutils_tests.c.

Referenced by Ensure().

◆ expected_rsa_sha256_hash

const char* expected_rsa_sha256_hash
static
Initial value:
=
"a581ce248a4a7e7a49603712d9ac4c83fdc491cc908eb430af566cb1975d7f3c"

Definition at line 106 of file sshutils_tests.c.

Referenced by Ensure(), and Ensure().

◆ test_ecdsa_openssh_private

const char* test_ecdsa_openssh_private
static
Initial value:
=
"-----BEGIN OPENSSH PRIVATE KEY-----\n"
"b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAaAAAABNlY2RzYS\n"
"1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQTBttsbosZ3Owlvc5aumQJd1W0LMd3X\n"
"gi3XxeQmwiGhFd0R1SahBmxMQdp6VXCyOnuUvrTGstFrQi0t3UsAII45AAAAoHkGdWV5Bn\n"
"VlAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMG22xuixnc7CW9z\n"
"lq6ZAl3VbQsx3deCLdfF5CbCIaEV3RHVJqEGbExB2npVcLI6e5S+tMay0WtCLS3dSwAgjj\n"
"kAAAAhAOuN88lVWbYX99J/AgA+VPGoBkO2oN2v1kq7wRBSNI2HAAAAAAECAwQFBgc=\n"
"-----END OPENSSH PRIVATE KEY-----"

Definition at line 62 of file sshutils_tests.c.

Referenced by Ensure(), and Ensure().

◆ test_ecdsa_pkcs8_encrypted

const char* test_ecdsa_pkcs8_encrypted
static
Initial value:
=
"-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
"MIHsMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjlyxUA9O2PHAICCAAw\n"
"DAYIKoZIhvcNAgkFADAdBglghkgBZQMEAQIEEO719labTRMgZ32j+ZnBT4YEgZBm\n"
"xdt/8ovIPzp07r4rrOJC1tZmoZXeRW8uDMm3OxHx7lV+obwqVh+ZfJHRvFe7ggvT\n"
"riL2tGh/eyTV5F/7mtGGhOFyjMAEgE2vT9TCwYwheQ0R690G5K+Mw3vt4xvVVtgD\n"
"6XoSuak8bnkXri/KmSFaWD650TMmLYGqGTlAzanoNuU7+8IERwYwvOg7QXaGSbA=\n"
"-----END ENCRYPTED PRIVATE KEY-----"

Definition at line 53 of file sshutils_tests.c.

Referenced by Ensure().

◆ test_ecdsa_public_expected

const char* test_ecdsa_public_expected
static
Initial value:
=
"ecdsa-sha2-nistp256 "
"AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBMG22xuixnc7CW9zlq6ZAl3V"
"bQsx3deCLdfF5CbCIaEV3RHVJqEGbExB2npVcLI6e5S+tMay0WtCLS3dSwAgjjk="

Definition at line 97 of file sshutils_tests.c.

Referenced by Ensure().

◆ test_ed25519_openssh_private

const char* test_ed25519_openssh_private
static
Initial value:
=
"-----BEGIN OPENSSH PRIVATE KEY-----\n"
"b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\n"
"QyNTUxOQAAACDc//VteiCk/grV3VBgQZpTZcClYUSe/Jah00ZaETd8BAAAAIgYiPkgGIj5\n"
"IAAAAAtzc2gtZWQyNTUxOQAAACDc//VteiCk/grV3VBgQZpTZcClYUSe/Jah00ZaETd8BA\n"
"AAAEBFmyjnCahpsDze3hjhZTQlH3o+r3/x1b+UX/Pzbx+C2tz/9W16IKT+CtXdUGBBmlNl\n"
"wKVhRJ78lqHTRloRN3wEAAAAAAECAwQF\n"
"-----END OPENSSH PRIVATE KEY-----"

Definition at line 80 of file sshutils_tests.c.

Referenced by Ensure(), and Ensure().

◆ test_ed25519_pkcs8_encrypted

const char* test_ed25519_pkcs8_encrypted
static
Initial value:
=
"-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
"MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjJzcFV4nR8QgICCAAw\n"
"DAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEELktrSEPHfD5f7p/W2OAyusEQC8R\n"
"d20mo9N7ywH+619oLIA52Xn7jXefbT/GXBmBPo0GaQV0f0ueg9R0g9rXXu2EgIIG\n"
"LQXgDsbD4kdN6Op41FY=\n"
"-----END ENCRYPTED PRIVATE KEY-----"

Definition at line 72 of file sshutils_tests.c.

Referenced by Ensure().

◆ test_ed25519_public_expected

const char* test_ed25519_public_expected
static
Initial value:
=
"ssh-ed25519 "
"AAAAC3NzaC1lZDI1NTE5AAAAINz/9W16IKT+CtXdUGBBmlNlwKVhRJ78lqHTRloRN3wE"

Definition at line 102 of file sshutils_tests.c.

Referenced by Ensure().

◆ test_rsa_pkcs8_encrypted

const char* test_rsa_pkcs8_encrypted
static
Initial value:
=
"-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
"MIIC3TBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQIzfBGcP5wd8MCAggA\n"
"MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAECBBBFzFqkORQCGsovV40fuoGFBIIC\n"
"gOWIjapbrp9CSFdlzvttFDyJWuv7jqW9Go7aCXnvqXWGDbxOlJSM8fAy4mmr0+71\n"
"CoIywoqg/3k6tmM3xMRSzql4RaZuDosoD0bAi7CPS2FKb+rMkCzOn8/v14U0QoX6\n"
"5lzB6a9PaTc+T5d29hPy/OxJutVOq/VvmoOng9mLcGesdEZXrXbunbJNsI0MHmzi\n"
"lwHNAdPkdGGHyMRb3DgRYVrn5XIkVINNTLk/3iKjqAAlP/uSN3cpU0L3+FW4bF3s\n"
"xKFktcbD/AbwRd5/W8PGHrMOaSqCiWmOCSdSa1xKNecjFN8SNAiZusp7V/H+ylyL\n"
"GPXE1sUL7FX1InwOR9NlVXRizf0696ZvH8aRrORO+j4yGT0XUxrLpS/OQ7Ea2jHs\n"
"EitXcC+cKTb0GRMjzp/BtK/yeiOTfo4N1ilTF9wjC+AZbZoS+qWxDxyeJ2x7TDQj\n"
"OiTiK3XWUDGzGt/9O1qn8Bguqbidc09oZ0WdRGpYGVZiRIB2Cd6adIEdU+MK58aJ\n"
"3qg4E5wQv9uQHoC4KRdsz2wXojXvjg55XUYjerDBAsZKXBXubguGSVDH6w2Xtqf5\n"
"DouWZwrHI4YEaF/ObzGfniUI1DXU8l7Zxmsb+BlvwG2JUoec7gVCD45ciL0JMElf\n"
"ZdZq+pm+LZ888GEM+4HLu9M5jS+rrj2UqKIR5IpmTa/wYdvBqJi9k4TKfa6DWPjj\n"
"ePwQ4I35Ke6rp4mKN/oqfKoH5ArLD5JIvRtqxTcpacw2dcxudf2TMVO92EZB6IgV\n"
"dlEZR+MS94rDuR5JwlyCd4wScg8uVL0SwOe7WFXhYDPVf3NeiHQc7ae7fE+IpJGy\n"
"RKqIeOPYWQcUa4NgMAv3qMA=\n"
"-----END ENCRYPTED PRIVATE KEY-----"

Definition at line 15 of file sshutils_tests.c.

Referenced by Ensure(), Ensure(), Ensure(), Ensure(), and Ensure().

◆ test_rsa_pkcs8_unencrypted

const char* test_rsa_pkcs8_unencrypted
static
Initial value:
=
"-----BEGIN PRIVATE KEY-----\n"
"MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAM1akpXjXsXSgeKC\n"
"FTc+k9x97hGN5bECPYTvP07rod0/UeDI5GQpcA8bpyB8v1QQatYRKRIIcLt+qW3r\n"
"qBiXDVG5WN9+ei8m3hvKzjGenbPfP9a50t86df5te1RAWbncZJPHPr4TjgFVh64+\n"
"7QVv5HrqXLVSKczVKwLtXJaHzi/fAgMBAAECgYBrTNwzPa8Tpr7/YAE98JDKMXLn\n"
"8UEHkKgcgfaOgkj9lkxuLApK2+wVuNlG/GfswPdSC31uUsK09aYKLYyT7Lmj/Zcb\n"
"NnrDDcVxK3AtQIlvIgEwO766riv91vPXRiig2xHkyzFJnyDjev9F5gB36LbMU5ZN\n"
"3lJswD6lgw30BlDMYQJBAPt2W6ws1AbfoJQJTob2hLRSAmCf/x+Fvv2lb5YINogj\n"
"2P+vq51i4YQhYOiIO1vdl0qhfhj+TdyIQ/A7jsb5+B0CQQDRDzbHhbY0p0MUT4rX\n"
"2Ysfrt3pEe8cHVdtT6RMiw3IUODWhlWXQJrmV1BgyEM05mgbRWMGz5xgOXG8it0y\n"
"/h8rAkBgm1YYzZgfk+aDORgcLbVJ+X/EU3OWTrHTjK1T/I/Guc7yXDEYZBazxocO\n"
"jtgPMRCgsW5ad8i+AvPm5VqzAvHZAkEAsWLvYCycheDGkh1L+gqkeaWutWx6LqjW\n"
"3fGNv0Td1PKLVHt3dHdk971ufjBulhxKiZk+hTDzxtH3J7vMJNBrMQJBAL/r0j0+\n"
"DgBywIZkjLzJwn3w4/wRl6YSr8DRgu8CtTFVozjkA177NpVzznlvfQU8RdNG3bbt\n"
"nw3vL7hUSbuvhmY=\n"
"-----END PRIVATE KEY-----"

Definition at line 35 of file sshutils_tests.c.

Referenced by Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), and Ensure().

◆ test_rsa_public_expected

const char* test_rsa_public_expected
static
Initial value:
=
"ssh-rsa "
"AAAAB3NzaC1yc2EAAAADAQABAAAAgQDNWpKV417F0oHighU3PpPcfe4RjeWxAj2E7z9O66HdP1Hg"
"yORkKXAPG6cgfL9UEGrWESkSCHC7fqlt66gYlw1RuVjffnovJt4bys4xnp2z3z/"
"WudLfOnX+bXtUQFm53GSTxz6+E44BVYeuPu0Fb+R66ly1UinM1SsC7VyWh84v3w=="

Definition at line 91 of file sshutils_tests.c.

Referenced by Ensure(), Ensure(), and Ensure().