summaryrefslogtreecommitdiff
path: root/authfile.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-04-17 07:15:11 +0000
committerDamien Miller <djm@mindrot.org>2020-04-17 17:17:47 +1000
commit094dd513f4b42e6a3cebefd18d1837eb709b4d99 (patch)
treef0a9d784f6ca6e7cd70200ee984293b94a074a6e /authfile.c
parent4e04f46f248f1708e39b900b76c9693c820eff68 (diff)
upstream: refactor out some duplicate private key loading code;
based on patch from loic AT venez.fr, ok dtucker@ OpenBSD-Commit-ID: 5eff2476b0d8d0614924c55e350fb7bb9c84f45e
Diffstat (limited to 'authfile.c')
-rw-r--r--authfile.c43
1 files changed, 9 insertions, 34 deletions
diff --git a/authfile.c b/authfile.c
index 50fa48e4a..35ccf576c 100644
--- a/authfile.c
+++ b/authfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: authfile.c,v 1.139 2020/04/08 00:10:37 djm Exp $ */ 1/* $OpenBSD: authfile.c,v 1.140 2020/04/17 07:15:11 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved.
4 * 4 *
@@ -141,6 +141,14 @@ sshkey_load_private_type(int type, const char *filename, const char *passphrase,
141} 141}
142 142
143int 143int
144sshkey_load_private(const char *filename, const char *passphrase,
145 struct sshkey **keyp, char **commentp)
146{
147 return sshkey_load_private_type(KEY_UNSPEC, filename, passphrase,
148 keyp, commentp);
149}
150
151int
144sshkey_load_private_type_fd(int fd, int type, const char *passphrase, 152sshkey_load_private_type_fd(int fd, int type, const char *passphrase,
145 struct sshkey **keyp, char **commentp) 153 struct sshkey **keyp, char **commentp)
146{ 154{
@@ -161,39 +169,6 @@ sshkey_load_private_type_fd(int fd, int type, const char *passphrase,
161 return r; 169 return r;
162} 170}
163 171
164/* XXX this is almost identical to sshkey_load_private_type() */
165int
166sshkey_load_private(const char *filename, const char *passphrase,
167 struct sshkey **keyp, char **commentp)
168{
169 struct sshbuf *buffer = NULL;
170 int r, fd;
171
172 if (keyp != NULL)
173 *keyp = NULL;
174 if (commentp != NULL)
175 *commentp = NULL;
176
177 if ((fd = open(filename, O_RDONLY)) == -1)
178 return SSH_ERR_SYSTEM_ERROR;
179 if (sshkey_perm_ok(fd, filename) != 0) {
180 r = SSH_ERR_KEY_BAD_PERMISSIONS;
181 goto out;
182 }
183 if ((r = sshbuf_load_fd(fd, &buffer)) != 0 ||
184 (r = sshkey_parse_private_fileblob(buffer, passphrase, keyp,
185 commentp)) != 0)
186 goto out;
187 if (keyp && *keyp &&
188 (r = sshkey_set_filename(*keyp, filename)) != 0)
189 goto out;
190 r = 0;
191 out:
192 close(fd);
193 sshbuf_free(buffer);
194 return r;
195}
196
197/* Load a pubkey from the unencrypted envelope of a new-format private key */ 172/* Load a pubkey from the unencrypted envelope of a new-format private key */
198static int 173static int
199sshkey_load_pubkey_from_private(const char *filename, struct sshkey **pubkeyp) 174sshkey_load_pubkey_from_private(const char *filename, struct sshkey **pubkeyp)