Commit d52f6b5c authored by Niels Möller's avatar Niels Möller
Browse files

* src/sexp_commands.c, src/sexp_commands.h, src/spki_commands.c,

src/spki_commands.h: Deleted obsolete files.

Rev: src/sexp_commands.c:1.26(DEAD)
Rev: src/sexp_commands.h:1.12(DEAD)
Rev: src/spki_commands.c:1.32(DEAD)
Rev: src/spki_commands.h:1.15(DEAD)
parent 635f576c
/* sexp_commands.c
*
* Reading and writing of s-expressions.
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999 Balzs Scheidler, Niels Mller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sexp_commands.h"
#warning sexp_commands.c is obsolete
#include "format.h"
#include "io.h"
#include "read_file.h"
#include "werror.h"
#include "xalloc.h"
#include <assert.h>
/* Forward declarations */
static struct catch_command catch_sexp_exceptions;
#define CATCH_SEXP (&catch_sexp_exceptions.super.super)
static struct read_sexp_command read_sexp;
#define READ_SEXP (&read_sexp.super.super)
#if 0
#define GABA_DEFINE
#include "sexp_commands.h.x"
#undef GABA_DEFINE
#include "sexp_commands.c.x"
/* FIXME: Should be obsoleted; used by spki_commands.c */
/* GABA:
(class
(name sexp_parser)
(super abstract_write)
(vars
(style . int)
(c object command_continuation)
(e object exception_handler)))
*/
static const struct exception
sexp_syntax_exception = STATIC_EXCEPTION(EXC_SEXP_SYNTAX,
"Sexp syntax error");
static const struct exception
sexp_eof_exception = STATIC_EXCEPTION(EXC_SEXP_EOF, "All sexps read");
static void
do_sexp_parse_once(struct abstract_write *s, struct lsh_string *input)
{
CAST(sexp_parser, self, s);
struct simple_buffer buffer;
struct sexp *expr;
assert(input);
simple_buffer_init(&buffer, input->length, input->data);
expr = sexp_parse(self->style, &buffer);
if (!expr)
EXCEPTION_RAISE(self->e, &sexp_syntax_exception);
else
COMMAND_RETURN(self->c, expr);
lsh_string_free(input);
}
static void
do_sexp_parse_many(struct abstract_write *s, struct lsh_string *input)
{
CAST(sexp_parser, self, s);
struct simple_buffer buffer;
const struct exception *e = &sexp_eof_exception;
assert(input);
simple_buffer_init(&buffer, input->length, input->data);
while (!parse_eod(&buffer))
{
struct sexp *expr = sexp_parse(self->style, &buffer);
if (!expr)
{
e = &sexp_syntax_exception;
break;
}
else
COMMAND_RETURN(self->c, expr);
}
EXCEPTION_RAISE(self->e, e);
lsh_string_free(input);
}
static struct abstract_write *
make_sexp_parser(int style, int goon,
struct command_continuation *c,
struct exception_handler *e)
{
NEW(sexp_parser, self);
self->super.write = goon ? do_sexp_parse_many : do_sexp_parse_once;
self->style = style;
self->c = c;
self->e = e;
return &self->super;
}
#define SEXP_BUFFER_SIZE 1024
void
do_read_sexp(struct command *s,
struct lsh_object *a,
struct command_continuation *c,
struct exception_handler *e)
{
CAST(read_sexp_command, self, s);
CAST(lsh_fd, fd, a);
trace("do_read_sexp\n");
assert(fd);
io_read(fd,
make_buffered_read
(SEXP_BUFFER_SIZE,
make_read_file
(make_sexp_parser(self->format,
self->goon,
c, e),
self->max_size)),
NULL);
}
struct command *
make_read_sexp_command(int format, int goon, UINT32 max_size)
{
NEW(read_sexp_command, self);
trace("make_read_sexp_command\n");
self->super.call = do_read_sexp;
self->format = format;
self->goon = goon;
self->max_size = max_size;
return &self->super;
}
static struct catch_command catch_sexp_exceptions
= STATIC_CATCH_COMMAND(EXC_ALL, EXC_SEXP_EOF, 1);
/* FIXME: Delete this limit, and all the complex read_handler stuff
* involved in readin sexps. */
/* Arbitrary limit on file size. */
#define MAX_SEXP_SIZE 10000
static struct read_sexp_command read_sexp
= STATIC_READ_SEXP(SEXP_TRANSPORT, 1, MAX_SEXP_SIZE);
/* GABA:
(expr
(name for_sexp)
(params
(handler object command))
(expr
(lambda (proc)
(catch_sexp handler
(lambda (file)
(proc (read_sexp file)))))))
*/
DEFINE_COMMAND(for_sexp_command)
(struct command *s UNUSED,
struct lsh_object *a,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST_SUBTYPE(command, handler, a);
COMMAND_RETURN(c, for_sexp(handler));
}
#endif
/* sexp_commands.h
*
* Reading and writing of s-expressions.
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999 Niels Möller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SEXP_COMMANDS_H_INCLUDED
#define SEXP_COMMANDS_H_INCLUDED
#warning sexp_commands.h is obsolete
#include "abstract_crypto.h"
#include "abstract_io.h"
#include "command.h"
#include "sexp.h"
#define GABA_DECLARE
#include "sexp_commands.h.x"
#undef GABA_DECLARE
/* GABA:
(class
(name read_sexp_command)
(super command)
(vars
(format . int)
(goon . int)
(max_size . UINT32)))
*/
void
do_read_sexp(struct command *s,
struct lsh_object *a,
struct command_continuation *c,
struct exception_handler *e);
#define STATIC_READ_SEXP(format, goon, max_size) \
{ STATIC_COMMAND(do_read_sexp), format, goon, max_size }
struct command *
make_read_sexp_command(int format, int goon, UINT32 max_size);
extern struct command for_sexp_command;
#define FOR_SEXP (&for_sexp_command.super)
#endif /* SEXP_COMMANDS_H_INCLUDED */
/* spki_commands.c
*
* SPKI interface
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999 Niels Mller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "spki_commands.h"
#warning spki_commands.h is obsolete
#include "atoms.h"
#include "crypto.h"
#include "format.h"
#include "queue.h"
#include "randomness.h"
#include "sexp_commands.h"
#include "werror.h"
#include "xalloc.h"
#include <assert.h>
/* Forward declarations */
struct command spki_add_acl_command;
#define SPKI_ADD_ACL (&spki_add_acl_command.super)
struct command spki_return_hostkeys;
#define RETURN_HOSTKEYS (&spki_return_hostkeys.super)
struct command spki_add_hostkey_command;
#define SPKI_ADD_HOSTKEY (&spki_add_hostkey_command.super)
struct command spki_return_userkeys;
#define RETURN_USERKEYS (&spki_return_userkeys.super)
struct command spki_add_userkey_command;
#define SPKI_ADD_USERKEY (&spki_add_userkey_command.super)
#define SA(x) sexp_a(ATOM_##x)
#define SPKI_ERROR(e, msg, expr) \
EXCEPTION_RAISE((e), make_spki_exception(EXC_SPKI_TYPE, (msg), (expr)))
#if 0
/* Reading keys */
/* FIXME: Used only by sexp2keypair, move code there? */
static void
parse_private_key(struct alist *algorithms,
struct sexp_iterator *i,
struct command_continuation *c,
struct exception_handler *e)
{
struct sexp *expr = SEXP_GET(i);
int algorithm_name;
struct signer *s;
struct verifier *v;
struct lsh_string *spki_public;
if (!expr)
{
werror("parse_private_key: Invalid key.\n");
SPKI_ERROR(e, "spki.c: Invalid key.", expr);
return;
}
s = spki_make_signer(algorithms, expr, &algorithm_name);
if (!s)
{
SPKI_ERROR(e, "spki.c: Invalid key.", expr);
return;
}
v = SIGNER_GET_VERIFIER(s);
spki_public = sexp_format(spki_make_public_key(SIGNER_GET_VERIFIER(s)),
SEXP_CANONICAL, 0);
/* Test key here? */
switch (algorithm_name)
{
case ATOM_DSA:
COMMAND_RETURN(c, make_keypair(ATOM_SSH_DSS,
PUBLIC_KEY(v),
s));
COMMAND_RETURN(c, make_keypair(ATOM_SPKI_SIGN_DSS,
spki_public, s));
break;
case ATOM_RSA_PKCS1_SHA1:
COMMAND_RETURN(c, make_keypair(ATOM_SSH_RSA,
PUBLIC_KEY(v),
s));
/* Fall through */
case ATOM_RSA_PKCS1_MD5:
COMMAND_RETURN(c, make_keypair(ATOM_SPKI_SIGN_RSA,
spki_public, s));
break;
default:
fatal("Internal error!\n");
#if 0
/* Get a corresponding public key. */
COMMAND_RETURN(c, make_keypair
(ATOM_SPKI,
sexp_format(spki_make_public_key(SIGNER_GET_VERIFIER(s)),
SEXP_CANONICAL, 0),
s));
#endif
break;
}
}
/* (sexp2keypair algorithms sexp) -> one or more keypairs */
DEFINE_COMMAND2(spki_sexp2keypair_command)
(struct command_2 *s UNUSED,
struct lsh_object *a1,
struct lsh_object *a2,
struct command_continuation *c,
struct exception_handler *e)
{
CAST_SUBTYPE(alist, algorithms, a1);
CAST_SUBTYPE(sexp, key, a2);
struct sexp_iterator *i;
switch (spki_get_type(key, &i))
{
default:
SPKI_ERROR(e, "spki.c: Expected private-key expression.", key);
return;
case ATOM_PRIVATE_KEY:
parse_private_key(algorithms, i, c, e);
break;
}
}
/* Reading of ACL:s
* ****************/
#endif
DEFINE_COMMAND(spki_make_context_command)
(struct command *s UNUSED,
struct lsh_object *a,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST_SUBTYPE(alist, algorithms, a);
trace("spki_make_context_command\n");
COMMAND_RETURN(c, make_spki_context(algorithms));
}
/* Reading of host-keys
* ********************/
/* GABA:
(class
(name spki_read_hostkey_context)
(super command)
(vars
(keys object alist)))
*/
#if 0
static void
do_spki_add_hostkey(struct command *s,
struct lsh_object *a,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST(spki_read_hostkey_context, self, s);
CAST(keypair, key, a);
trace("do_spki_add_hostkey\n");
if (ALIST_GET(self->keys, key->type))
werror("Multiple host keys of type %a.\n", key->type);
else
ALIST_SET(self->keys, key->type, &key->super);
COMMAND_RETURN(c, self->keys);
}
/* Ignores its argument */
DEFINE_COMMAND(spki_add_hostkey_command)
(struct command *s UNUSED,
struct lsh_object *a UNUSED,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
NEW(spki_read_hostkey_context, self);
trace("spki_add_hostkey_command\n");
self->super.call = do_spki_add_hostkey;
self->keys = make_alist(0, -1);
COMMAND_RETURN(c, self);
}
DEFINE_COMMAND(spki_return_hostkeys)
(struct command *s UNUSED,
struct lsh_object *a,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST(spki_read_hostkey_context, self, a);
trace("spki_return_hostkeys\n");
COMMAND_RETURN(c, self->keys);
}
/* ;;GABA:
(expr
(name spki_read_hostkeys)
(params
(algorithms object alist))
(expr
(lambda (file)
(let ((add (spki_add_hostkey file)))
(for_sexp (lambda (e)
;; Delay return until we actually get an exception
(return_hostkeys (prog1 add e)))
(lambda (key)
(add (sexp2keypair
algorithms key)))
file)))))
*/
DEFINE_COMMAND(spki_read_hostkeys_command)
(struct command *s UNUSED,
struct lsh_object *a,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST_SUBTYPE(alist, algorithms, a);
CAST_SUBTYPE(command, res, spki_read_hostkeys(algorithms));
trace("spki_read_hostkeys_command\n");
COMMAND_RETURN(c, res);
}
#endif
/* spki_commands.h
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1999 Niels Möller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef LSH_SPKI_COMMANDS_H_INCLUDED
#define LSH_SPKI_COMMANDS_H_INCLUDED
#warning spki_commands.h is obsolete
#include "command.h"
#include "interact.h"
#include "spki.h"
extern struct command_2 spki_sexp2keypair_command;
#define SEXP2KEYPAIR (&spki_sexp2keypair_command.super.super)
extern struct command spki_make_context_command;
#define SPKI_MAKE_CONTEXT (&spki_make_context_command.super)
extern struct command spki_read_hostkeys_command;
#define SPKI_READ_HOSTKEYS (&spki_read_hostkeys_command.super)
struct command *
make_spki_read_userkeys(struct alist *algorithms,
struct alist *signature_algorithms,
struct interact *tty);
/* Encryption of private data. */
struct command *
make_pkcs5_decrypt(struct alist *mac_algorithms,
struct alist *crypto_algorithms,
struct interact *tty);
#endif /* LSH_SPKI_COMMANDS_H_INCLUDED */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment