key.h revision 215116
1215116Sdes/* $OpenBSD: key.h,v 1.30 2010/04/16 01:47:26 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, 40215116Sdes KEY_RSA_CERT_V00, 41215116Sdes KEY_DSA_CERT_V00, 4276259Sgreen KEY_UNSPEC 4358582Skris}; 4476259Sgreenenum fp_type { 4576259Sgreen SSH_FP_SHA1, 4676259Sgreen SSH_FP_MD5 4776259Sgreen}; 4876259Sgreenenum fp_rep { 4976259Sgreen SSH_FP_HEX, 50181111Sdes SSH_FP_BUBBLEBABBLE, 51181111Sdes SSH_FP_RANDOMART 5276259Sgreen}; 5392555Sdes 5492555Sdes/* key is stored in external hardware */ 5592555Sdes#define KEY_FLAG_EXT 0x0001 5692555Sdes 57204917Sdes#define CERT_MAX_PRINCIPALS 256 58204917Sdesstruct KeyCert { 59204917Sdes Buffer certblob; /* Kept around for use on wire */ 60204917Sdes u_int type; /* SSH2_CERT_TYPE_USER or SSH2_CERT_TYPE_HOST */ 61215116Sdes u_int64_t serial; 62204917Sdes char *key_id; 63204917Sdes u_int nprincipals; 64204917Sdes char **principals; 65204917Sdes u_int64_t valid_after, valid_before; 66215116Sdes Buffer critical; 67215116Sdes Buffer extensions; 68204917Sdes Key *signature_key; 69204917Sdes}; 70204917Sdes 7158582Skrisstruct Key { 7292555Sdes int type; 7392555Sdes int flags; 7458582Skris RSA *rsa; 7558582Skris DSA *dsa; 76204917Sdes struct KeyCert *cert; 7758582Skris}; 7858582Skris 79126274SdesKey *key_new(int); 80204917Sdesvoid key_add_private(Key *); 81126274SdesKey *key_new_private(int); 82126274Sdesvoid key_free(Key *); 83126274SdesKey *key_demote(const Key *); 84204917Sdesint key_equal_public(const Key *, const Key *); 85126274Sdesint key_equal(const Key *, const Key *); 86204917Sdeschar *key_fingerprint(Key *, enum fp_type, enum fp_rep); 87204917Sdesu_char *key_fingerprint_raw(Key *, enum fp_type, u_int *); 88126274Sdesconst char *key_type(const Key *); 89207319Sdesconst char *key_cert_type(const Key *); 90126274Sdesint key_write(const Key *, FILE *); 91126274Sdesint key_read(Key *, char **); 92126274Sdesu_int key_size(const Key *); 9358582Skris 9492555SdesKey *key_generate(int, u_int); 95126274SdesKey *key_from_private(const Key *); 9692555Sdesint key_type_from_name(char *); 97204917Sdesint key_is_cert(const Key *); 98204917Sdesint key_type_plain(int); 99215116Sdesint key_to_certified(Key *, int); 100204917Sdesint key_drop_cert(Key *); 101204917Sdesint key_certify(Key *, Key *); 102204917Sdesvoid key_cert_copy(const Key *, struct Key *); 103204917Sdesint key_cert_check_authority(const Key *, int, int, const char *, 104204917Sdes const char **); 105215116Sdesint key_cert_is_legacy(Key *); 10676259Sgreen 107126274SdesKey *key_from_blob(const u_char *, u_int); 108126274Sdesint key_to_blob(const Key *, u_char **, u_int *); 109126274Sdesconst char *key_ssh_name(const Key *); 110126274Sdesint key_names_valid2(const char *); 11176259Sgreen 112126274Sdesint key_sign(const Key *, u_char **, u_int *, const u_char *, u_int); 113126274Sdesint key_verify(const Key *, const u_char *, u_int, const u_char *, u_int); 11476259Sgreen 115126274Sdesint ssh_dss_sign(const Key *, u_char **, u_int *, const u_char *, u_int); 116126274Sdesint ssh_dss_verify(const Key *, const u_char *, u_int, const u_char *, u_int); 117126274Sdesint ssh_rsa_sign(const Key *, u_char **, u_int *, const u_char *, u_int); 118126274Sdesint ssh_rsa_verify(const Key *, const u_char *, u_int, const u_char *, u_int); 119113908Sdes 12058582Skris#endif 121