ntp_crypto.h revision 285612
1/* 2 * ntp_crypto.h - definitions for cryptographic operations 3 */ 4#ifndef NTP_CRYPTO_H 5#define NTP_CRYPTO_H 6 7/* 8 * Configuration codes (also needed for parser without AUTOKEY) 9 */ 10#define CRYPTO_CONF_NONE 0 /* nothing doing */ 11#define CRYPTO_CONF_PRIV 1 /* host name */ 12#define CRYPTO_CONF_IDENT 2 /* group name */ 13#define CRYPTO_CONF_CERT 3 /* certificate file name */ 14#define CRYPTO_CONF_RAND 4 /* random seed file name */ 15#define CRYPTO_CONF_IFFPAR 5 /* IFF parameters file name */ 16#define CRYPTO_CONF_GQPAR 6 /* GQ parameters file name */ 17#define CRYPTO_CONF_MVPAR 7 /* MV parameters file name */ 18#define CRYPTO_CONF_PW 8 /* private key password */ 19#define CRYPTO_CONF_NID 9 /* specify digest name */ 20 21#ifdef AUTOKEY 22#ifndef OPENSSL 23#error AUTOKEY should be defined only if OPENSSL is. 24invalidsyntax: AUTOKEY should be defined only if OPENSSL is. 25#endif 26 27#include "openssl/evp.h" 28#include "ntp_calendar.h" /* for fields in the cert_info structure */ 29 30 31/* 32 * The following bits are set by the CRYPTO_ASSOC message from 33 * the server and are not modified by the client. 34 */ 35#define CRYPTO_FLAG_ENAB 0x0001 /* crypto enable */ 36#define CRYPTO_FLAG_TAI 0x0002 /* leapseconds table */ 37 38#define CRYPTO_FLAG_PRIV 0x0010 /* PC identity scheme */ 39#define CRYPTO_FLAG_IFF 0x0020 /* IFF identity scheme */ 40#define CRYPTO_FLAG_GQ 0x0040 /* GQ identity scheme */ 41#define CRYPTO_FLAG_MV 0x0080 /* MV identity scheme */ 42#define CRYPTO_FLAG_MASK 0x00f0 /* identity scheme mask */ 43 44/* 45 * The following bits are used by the client during the protocol 46 * exchange. 47 */ 48#define CRYPTO_FLAG_CERT 0x0100 /* public key verified */ 49#define CRYPTO_FLAG_VRFY 0x0200 /* identity verified */ 50#define CRYPTO_FLAG_PROV 0x0400 /* signature verified */ 51#define CRYPTO_FLAG_COOK 0x0800 /* cookie verifed */ 52#define CRYPTO_FLAG_AUTO 0x1000 /* autokey verified */ 53#define CRYPTO_FLAG_SIGN 0x2000 /* certificate signed */ 54#define CRYPTO_FLAG_LEAP 0x4000 /* leapsecond values verified */ 55#define CRYPTO_FLAG_ALL 0x7f00 /* all mask */ 56 57/* 58 * Flags used for certificate management 59 */ 60#define CERT_TRUST 0x01 /* certificate is trusted */ 61#define CERT_SIGN 0x02 /* certificate is signed */ 62#define CERT_VALID 0x04 /* certificate is valid */ 63#define CERT_PRIV 0x08 /* certificate is private */ 64#define CERT_ERROR 0x80 /* certificate has errors */ 65 66/* 67 * Extension field definitions 68 */ 69#define CRYPTO_MAXLEN 1024 /* max extension field length */ 70#define CRYPTO_VN 2 /* current protocol version number */ 71#define CRYPTO_CMD(x) (((CRYPTO_VN << 8) | (x)) << 16) 72#define CRYPTO_NULL CRYPTO_CMD(0) /* no operation */ 73#define CRYPTO_ASSOC CRYPTO_CMD(1) /* association */ 74#define CRYPTO_CERT CRYPTO_CMD(2) /* certificate */ 75#define CRYPTO_COOK CRYPTO_CMD(3) /* cookie value */ 76#define CRYPTO_AUTO CRYPTO_CMD(4) /* autokey values */ 77#define CRYPTO_LEAP CRYPTO_CMD(5) /* leapsecond values */ 78#define CRYPTO_SIGN CRYPTO_CMD(6) /* certificate sign */ 79#define CRYPTO_IFF CRYPTO_CMD(7) /* IFF identity scheme */ 80#define CRYPTO_GQ CRYPTO_CMD(8) /* GQ identity scheme */ 81#define CRYPTO_MV CRYPTO_CMD(9) /* MV identity scheme */ 82#define CRYPTO_RESP 0x80000000 /* response */ 83#define CRYPTO_ERROR 0x40000000 /* error */ 84 85/* 86 * Autokey event codes 87 */ 88#define XEVNT_CMD(x) (CRPT_EVENT | (x)) 89#define XEVNT_OK XEVNT_CMD(0) /* success */ 90#define XEVNT_LEN XEVNT_CMD(1) /* bad field format or length */ 91#define XEVNT_TSP XEVNT_CMD(2) /* bad timestamp */ 92#define XEVNT_FSP XEVNT_CMD(3) /* bad filestamp */ 93#define XEVNT_PUB XEVNT_CMD(4) /* bad or missing public key */ 94#define XEVNT_MD XEVNT_CMD(5) /* unsupported digest type */ 95#define XEVNT_KEY XEVNT_CMD(6) /* unsupported identity type */ 96#define XEVNT_SGL XEVNT_CMD(7) /* bad signature length */ 97#define XEVNT_SIG XEVNT_CMD(8) /* signature not verified */ 98#define XEVNT_VFY XEVNT_CMD(9) /* certificate not verified */ 99#define XEVNT_PER XEVNT_CMD(10) /* host certificate expired */ 100#define XEVNT_CKY XEVNT_CMD(11) /* bad or missing cookie */ 101#define XEVNT_DAT XEVNT_CMD(12) /* bad or missing leapseconds */ 102#define XEVNT_CRT XEVNT_CMD(13) /* bad or missing certificate */ 103#define XEVNT_ID XEVNT_CMD(14) /* bad or missing group key */ 104#define XEVNT_ERR XEVNT_CMD(15) /* protocol error */ 105 106/* 107 * Miscellaneous crypto stuff 108 */ 109#define NTP_MAXSESSION 100 /* maximum session key list entries */ 110#define NTP_MAXEXTEN 2048 /* maximum extension field size */ 111#define NTP_AUTOMAX 12 /* default key list timeout (log2 s) */ 112#define KEY_REVOKE 17 /* default key revoke timeout (log2 s) */ 113#define NTP_REFRESH 19 /* default restart timeout (log2 s) */ 114#define NTP_MAXKEY 65535 /* maximum symmetric key ID */ 115 116/* 117 * The autokey structure holds the values used to authenticate key IDs. 118 */ 119struct autokey { /* network byte order */ 120 keyid_t key; /* key ID */ 121 int32 seq; /* key number */ 122}; 123 124/* 125 * The value structure holds variable length data such as public 126 * key, agreement parameters, public valule and leapsecond table. 127 * They are in network byte order. 128 */ 129struct value { /* network byte order */ 130 tstamp_t tstamp; /* timestamp */ 131 tstamp_t fstamp; /* filestamp */ 132 u_int32 vallen; /* value length */ 133 void *ptr; /* data pointer (various) */ 134 u_int32 siglen; /* signature length */ 135 u_char *sig; /* signature */ 136}; 137 138/* 139 * The packet extension field structures are used to hold values 140 * and signatures in network byte order. 141 */ 142struct exten { 143 u_int32 opcode; /* opcode */ 144 u_int32 associd; /* association ID */ 145 u_int32 tstamp; /* timestamp */ 146 u_int32 fstamp; /* filestamp */ 147 u_int32 vallen; /* value length */ 148 u_int32 pkt[1]; /* start of value field */ 149}; 150 151 152/* 153 * The certificate info/value structure 154 */ 155struct cert_info { 156 struct cert_info *link; /* forward link */ 157 u_int flags; /* flags that wave */ 158 EVP_PKEY *pkey; /* generic key */ 159 long version; /* X509 version */ 160 int nid; /* signature/digest ID */ 161 const EVP_MD *digest; /* message digest algorithm */ 162 u_long serial; /* serial number */ 163 struct calendar first; /* not valid before */ 164 struct calendar last; /* not valid after */ 165 char *subject; /* subject common name */ 166 char *issuer; /* issuer common name */ 167 BIGNUM *grpkey; /* GQ group key */ 168 struct value cert; /* certificate/value */ 169}; 170 171/* 172 * The keys info/value structure 173 */ 174struct pkey_info { 175 struct pkey_info *link; /* forward link */ 176 EVP_PKEY *pkey; /* generic key */ 177 char *name; /* file name */ 178 tstamp_t fstamp; /* filestamp */ 179}; 180 181/* 182 * Cryptographic values 183 */ 184extern u_int crypto_flags; /* status word */ 185extern int crypto_nid; /* digest nid */ 186extern struct value hostval; /* host name/value */ 187extern struct cert_info *cinfo; /* host certificate information */ 188extern struct value tai_leap; /* leapseconds table */ 189#endif /* AUTOKEY */ 190#endif /* NTP_CRYPTO_H */ 191