Annotation of embedaddon/bird2/proto/rpki/ssh_transport.c, revision 1.1
1.1 ! misho 1: /*
! 2: * BIRD -- An implementation of the SSH protocol for the RPKI transport
! 3: *
! 4: * (c) 2015 CZ.NIC
! 5: * (c) 2015 Pavel Tvrdik <pawel.tvrdik@gmail.com>
! 6: *
! 7: * This file was a part of RTRlib: http://rpki.realmv6.org/
! 8: * This transport implementation uses libssh (http://www.libssh.org/)
! 9: *
! 10: * Can be freely distributed and used under the terms of the GNU GPL.
! 11: */
! 12:
! 13: #include <stdio.h>
! 14: #include <stdlib.h>
! 15: #include <string.h>
! 16: #include <sys/time.h>
! 17:
! 18: #include "rpki.h"
! 19:
! 20: static int
! 21: rpki_tr_ssh_open(struct rpki_tr_sock *tr)
! 22: {
! 23: struct rpki_cache *cache = tr->cache;
! 24: struct rpki_config *cf = (void *) cache->p->p.cf;
! 25: struct rpki_tr_ssh_config *ssh_cf = (void *) cf->tr_config.spec;
! 26: sock *sk = tr->sk;
! 27:
! 28: sk->type = SK_SSH_ACTIVE;
! 29: sk->ssh = mb_allocz(sk->pool, sizeof(struct ssh_sock));
! 30: sk->ssh->username = ssh_cf->user;
! 31: sk->ssh->client_privkey_path = ssh_cf->bird_private_key;
! 32: sk->ssh->server_hostkey_path = ssh_cf->cache_public_key;
! 33: sk->ssh->subsystem = "rpki-rtr";
! 34: sk->ssh->state = SK_SSH_CONNECT;
! 35:
! 36: if (sk_open(sk) != 0)
! 37: return RPKI_TR_ERROR;
! 38:
! 39: return RPKI_TR_SUCCESS;
! 40: }
! 41:
! 42: static const char *
! 43: rpki_tr_ssh_ident(struct rpki_tr_sock *tr)
! 44: {
! 45: struct rpki_cache *cache = tr->cache;
! 46: struct rpki_config *cf = (void *) cache->p->p.cf;
! 47: struct rpki_tr_ssh_config *ssh_cf = (void *) cf->tr_config.spec;
! 48:
! 49: if (tr->ident != NULL)
! 50: return tr->ident;
! 51:
! 52: const char *username = ssh_cf->user;
! 53: const char *host = cf->hostname;
! 54: u16 port = cf->port;
! 55:
! 56: size_t len = strlen(username) + 1 + strlen(host) + 1 + 5 + 1; /* <user> + '@' + <host> + ':' + <port> + '\0' */
! 57: char *ident = mb_alloc(cache->pool, len);
! 58: bsnprintf(ident, len, "%s@%s:%u", username, host, port);
! 59: tr->ident = ident;
! 60:
! 61: return tr->ident;
! 62: }
! 63:
! 64: /**
! 65: * rpki_tr_ssh_init - initializes the RPKI transport structure for a SSH connection
! 66: * @tr: allocated RPKI transport structure
! 67: */
! 68: void
! 69: rpki_tr_ssh_init(struct rpki_tr_sock *tr)
! 70: {
! 71: tr->open_fp = &rpki_tr_ssh_open;
! 72: tr->ident_fp = &rpki_tr_ssh_ident;
! 73: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>