key.h revision 204917
1204917Sdes/* $OpenBSD: key.h,v 1.28 2010/02/26 20:29:54 djm Exp $ */ 276259Sgreen 365668Skris/* 492555Sdes * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 565668Skris * 665668Skris * Redistribution and use in source and binary forms, with or without 765668Skris * modification, are permitted provided that the following conditions 865668Skris * are met: 965668Skris * 1. Redistributions of source code must retain the above copyright 1065668Skris * notice, this list of conditions and the following disclaimer. 1165668Skris * 2. Redistributions in binary form must reproduce the above copyright 1265668Skris * notice, this list of conditions and the following disclaimer in the 1365668Skris * documentation and/or other materials provided with the distribution. 1465668Skris * 1565668Skris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1665668Skris * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1765668Skris * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1865668Skris * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1965668Skris * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2065668Skris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2165668Skris * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2265668Skris * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2365668Skris * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2465668Skris * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2565668Skris */ 2658582Skris#ifndef KEY_H 2758582Skris#define KEY_H 2858582Skris 29204917Sdes#include "buffer.h" 3076259Sgreen#include <openssl/rsa.h> 3176259Sgreen#include <openssl/dsa.h> 3276259Sgreen 3358582Skristypedef struct Key Key; 3458582Skrisenum types { 3576259Sgreen KEY_RSA1, 3658582Skris KEY_RSA, 3758582Skris KEY_DSA, 38204917Sdes KEY_RSA_CERT, 39204917Sdes KEY_DSA_CERT, 4076259Sgreen KEY_UNSPEC 4158582Skris}; 4276259Sgreenenum fp_type { 4376259Sgreen SSH_FP_SHA1, 4476259Sgreen SSH_FP_MD5 4576259Sgreen}; 4676259Sgreenenum fp_rep { 4776259Sgreen SSH_FP_HEX, 48181111Sdes SSH_FP_BUBBLEBABBLE, 49181111Sdes SSH_FP_RANDOMART 5076259Sgreen}; 5192555Sdes 5292555Sdes/* key is stored in external hardware */ 5392555Sdes#define KEY_FLAG_EXT 0x0001 5492555Sdes 55204917Sdes#define CERT_MAX_PRINCIPALS 256 56204917Sdesstruct KeyCert { 57204917Sdes Buffer certblob; /* Kept around for use on wire */ 58204917Sdes u_int type; /* SSH2_CERT_TYPE_USER or SSH2_CERT_TYPE_HOST */ 59204917Sdes char *key_id; 60204917Sdes u_int nprincipals; 61204917Sdes char **principals; 62204917Sdes u_int64_t valid_after, valid_before; 63204917Sdes Buffer constraints; 64204917Sdes Key *signature_key; 65204917Sdes}; 66204917Sdes 6758582Skrisstruct Key { 6892555Sdes int type; 6992555Sdes int flags; 7058582Skris RSA *rsa; 7158582Skris DSA *dsa; 72204917Sdes struct KeyCert *cert; 7358582Skris}; 7458582Skris 75126274SdesKey *key_new(int); 76204917Sdesvoid key_add_private(Key *); 77126274SdesKey *key_new_private(int); 78126274Sdesvoid key_free(Key *); 79126274SdesKey *key_demote(const Key *); 80204917Sdesint key_equal_public(const Key *, const Key *); 81126274Sdesint key_equal(const Key *, const Key *); 82204917Sdeschar *key_fingerprint(Key *, enum fp_type, enum fp_rep); 83204917Sdesu_char *key_fingerprint_raw(Key *, enum fp_type, u_int *); 84126274Sdesconst char *key_type(const Key *); 85126274Sdesint key_write(const Key *, FILE *); 86126274Sdesint key_read(Key *, char **); 87126274Sdesu_int key_size(const Key *); 8858582Skris 8992555SdesKey *key_generate(int, u_int); 90126274SdesKey *key_from_private(const Key *); 9192555Sdesint key_type_from_name(char *); 92204917Sdesint key_is_cert(const Key *); 93204917Sdesint key_type_plain(int); 94204917Sdesint key_to_certified(Key *); 95204917Sdesint key_drop_cert(Key *); 96204917Sdesint key_certify(Key *, Key *); 97204917Sdesvoid key_cert_copy(const Key *, struct Key *); 98204917Sdesint key_cert_check_authority(const Key *, int, int, const char *, 99204917Sdes const char **); 10076259Sgreen 101126274SdesKey *key_from_blob(const u_char *, u_int); 102126274Sdesint key_to_blob(const Key *, u_char **, u_int *); 103126274Sdesconst char *key_ssh_name(const Key *); 104126274Sdesint key_names_valid2(const char *); 10576259Sgreen 106126274Sdesint key_sign(const Key *, u_char **, u_int *, const u_char *, u_int); 107126274Sdesint key_verify(const Key *, const u_char *, u_int, const u_char *, u_int); 10876259Sgreen 109126274Sdesint ssh_dss_sign(const Key *, u_char **, u_int *, const u_char *, u_int); 110126274Sdesint ssh_dss_verify(const Key *, const u_char *, u_int, const u_char *, u_int); 111126274Sdesint ssh_rsa_sign(const Key *, u_char **, u_int *, const u_char *, u_int); 112126274Sdesint ssh_rsa_verify(const Key *, const u_char *, u_int, const u_char *, u_int); 113113908Sdes 11458582Skris#endif 115