1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3
Copyright (C) 2008 Stefan Walter
5
The Gnome Keyring Library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public License as
7
published by the Free Software Foundation; either version 2 of the
8
License, or (at your option) any later version.
10
The Gnome Keyring Library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public
16
License along with the Gnome Library; see the file COPYING.LIB. If not,
17
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
Boston, MA 02111-1307, USA.
20
Author: Stef Walter <stef@memberwebs.com>
25
#include "egg/egg-secure-memory.h"
27
#include "ssh-store/gkm-ssh-openssh.h"
29
#include "gkm/gkm-sexp.h"
37
EGG_SECURE_GLIB_DEFINITIONS ();
39
static const gchar *PRIVATE_FILES[] = {
40
SRCDIR "/files/id_rsa_encrypted",
41
SRCDIR "/files/id_rsa_plain",
42
SRCDIR "/files/id_dsa_encrypted",
43
SRCDIR "/files/id_dsa_plain"
46
static const gchar *PUBLIC_FILES[] = {
47
SRCDIR "/files/id_rsa_test.pub",
48
SRCDIR "/files/id_dsa_test.pub"
51
#define COMMENT "A public key comment"
54
test_parse_public (void)
66
for (i = 0; i < G_N_ELEMENTS (PUBLIC_FILES); ++i) {
68
if (!g_file_get_contents (PUBLIC_FILES[i], &data, &n_data, NULL))
69
g_assert_not_reached ();
71
res = gkm_ssh_openssh_parse_public_key (data, n_data, &sexp, &comment);
72
if (res != GKM_DATA_SUCCESS) {
73
g_warning ("couldn't parse public key: %s", PUBLIC_FILES[i]);
74
g_assert_cmpint (res, ==, GKM_DATA_SUCCESS);
77
if (!gkm_sexp_parse_key (sexp, &algorithm, &is_private, NULL))
78
g_assert_not_reached ();
80
g_assert_cmpstr (comment, ==, COMMENT);
81
g_assert_cmpint (algorithm, !=, 0);
82
g_assert (!is_private);
86
gcry_sexp_release (sexp);
91
test_parse_private (void)
102
for (i = 0; i < G_N_ELEMENTS (PRIVATE_FILES); ++i) {
104
if (!g_file_get_contents (PRIVATE_FILES[i], &data, &n_data, NULL))
105
g_assert_not_reached ();
107
res = gkm_ssh_openssh_parse_private_key (data, n_data, "password", 8, &sexp);
108
if (res != GKM_DATA_SUCCESS) {
109
g_warning ("couldn't parse private key: %s", PRIVATE_FILES[i]);
110
g_assert_cmpint (res, ==, GKM_DATA_SUCCESS);
113
if (!gkm_sexp_parse_key (sexp, &algorithm, &is_private, NULL))
114
g_assert_not_reached ();
116
g_assert_cmpint (algorithm, !=, 0);
117
g_assert (is_private);
120
gcry_sexp_release (sexp);
125
main (int argc, char **argv)
128
g_test_init (&argc, &argv, NULL);
130
g_test_add_func ("/ssh-store/openssh/parse_private", test_parse_private);
131
g_test_add_func ("/ssh-store/openssh/parse_public", test_parse_public);
133
return g_test_run ();