* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
-RCSID("$OpenBSD: ssh-keysign.c,v 1.3 2002/06/08 05:07:09 markus Exp $");
+RCSID("$OpenBSD: ssh-keysign.c,v 1.7 2002/07/03 14:21:05 markus Exp $");
#include <openssl/evp.h>
+#include <openssl/rand.h>
+#include <openssl/rsa.h>
#include "log.h"
#include "key.h"
+#include "ssh.h"
#include "ssh2.h"
#include "misc.h"
#include "xmalloc.h"
#include "msg.h"
#include "canohost.h"
#include "pathnames.h"
+#include "readconf.h"
+
+uid_t original_real_uid; /* XXX readconf.c needs this */
#ifdef HAVE___PROGNAME
extern char *__progname;
buffer_init(&b);
buffer_append(&b, data, datalen);
-
+
/* session id, currently limited to SHA1 (20 bytes) */
p = buffer_get_string(&b, &len);
if (len != 20)
if (strlen(host) != len - 1)
fail++;
else if (p[len - 1] != '.')
- fail++;
+ fail++;
else if (strncasecmp(host, p, len - 1) != 0)
- fail++;
+ fail++;
xfree(p);
/* local user */
main(int argc, char **argv)
{
Buffer b;
+ Options options;
Key *keys[2], *key;
struct passwd *pw;
int key_fd[2], i, found, version = 2, fd;
u_char *signature, *data;
char *host;
u_int slen, dlen;
+ u_int32_t rnd[256];
key_fd[0] = open(_PATH_HOST_RSA_KEY_FILE, O_RDONLY);
key_fd[1] = open(_PATH_HOST_DSA_KEY_FILE, O_RDONLY);
#ifdef DEBUG_SSH_KEYSIGN
log_init("ssh-keysign", SYSLOG_LEVEL_DEBUG3, SYSLOG_FACILITY_AUTH, 0);
-#endif
+#endif
+
+ /* verify that ssh-keysign is enabled by the admin */
+ original_real_uid = getuid(); /* XXX readconf.c needs this */
+ initialize_options(&options);
+ (void)read_config_file(_PATH_HOST_CONFIG_FILE, "", &options);
+ fill_default_options(&options);
+ if (options.hostbased_authentication != 1)
+ fatal("Hostbased authentication not enabled in %s",
+ _PATH_HOST_CONFIG_FILE);
if (key_fd[0] == -1 && key_fd[1] == -1)
fatal("could not open any host key");
if ((pw = getpwuid(getuid())) == NULL)
fatal("getpwuid failed");
- pw = pwcopy(pw);
+ pw = pwcopy(pw);
SSLeay_add_all_algorithms();
+ for (i = 0; i < 256; i++)
+ rnd[i] = arc4random();
+ RAND_seed(rnd, sizeof(rnd));
found = 0;
for (i = 0; i < 2; i++) {
keys[i] = key_load_private_pem(key_fd[i], KEY_UNSPEC,
NULL, NULL);
close(key_fd[i]);
+ if (keys[i] != NULL && keys[i]->type == KEY_RSA) {
+ if (RSA_blinding_on(keys[i]->rsa, NULL) != 1) {
+ error("RSA_blinding_on failed");
+ key_free(keys[i]);
+ keys[i] = NULL;
+ }
+ }
if (keys[i] != NULL)
found = 1;
}
fatal("bad fd");
if ((host = get_local_name(fd)) == NULL)
fatal("cannot get sockname for fd");
-
+
data = buffer_get_string(&b, &dlen);
if (valid_request(pw, host, &key, data, dlen) < 0)
fatal("not a valid request");
- xfree(data);
xfree(host);
found = 0;
if (key_sign(keys[i], &signature, &slen, data, dlen) != 0)
fatal("key_sign failed");
-
+ xfree(data);
+
/* send reply */
buffer_clear(&b);
buffer_put_string(&b, signature, slen);