~ubuntu-branches/debian/squeeze/ntp/squeeze-201010051545

« back to all changes in this revision

Viewing changes to include/ntp_crypto.h

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2004-10-11 16:10:27 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041011161027-icyjbji8ujym633o
Tags: 1:4.2.0a-10ubuntu2
Use ntp.ubuntulinux.org instead of pool.ntp.org

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * ntp_crypto.h - definitions for cryptographic operations
3
3
 */
4
 
#ifdef AUTOKEY
5
 
#include "global.h"
6
 
#include "md5.h"
7
 
#ifdef RSAREF
8
 
#include "rsaref.h"
9
 
#include "rsa.h"
10
 
 
11
 
#define EVP_SignInit(a, b)      R_SignInit(a, b)
12
 
#define EVP_SignUpdate(a, b, c) R_SignUpdate(a, b, c);
13
 
#define EVP_SignFinal(a, b, c, d) R_SignFinal(a, b, c, d);
14
 
#define EVP_VerifyInit(a, b)    R_VerifyInit(a, b)
15
 
#define EVP_VerifyUpdate(a, b, c) R_VerifyUpdate(a, b, c);
16
 
#define EVP_VerifyFinal(a, b, c, d) R_VerifyFinal(a, b, c, d);
17
 
 
18
 
#endif /* RSAREF */
19
 
 
20
 
/*
21
 
 * Cryptostatus word
22
 
 */
23
 
#define CRYPTO_FLAG_ENAB  0x01  /* crypto enable */
24
 
#define CRYPTO_FLAG_RSA   0x02  /* public/private keys */
25
 
#define CRYPTO_FLAG_CERT  0x04  /* certificate */
26
 
#define CRYPTO_FLAG_DH    0x08  /* agreement parameters */
27
 
#define CRYPTO_FLAG_TAI   0x10  /* leapseconds table */
 
4
#ifdef OPENSSL
 
5
#include "openssl/evp.h"
 
6
/*
 
7
 * The following bits are set by the CRYPTO_ASSOC message from
 
8
 * the server and are not modified by the client.
 
9
 */
 
10
#define CRYPTO_FLAG_ENAB  0x0001 /* crypto enable */
 
11
#define CRYPTO_FLAG_TAI   0x0002 /* leapseconds table */
 
12
 
 
13
#define CRYPTO_FLAG_PRIV  0x0010 /* PC identity scheme */
 
14
#define CRYPTO_FLAG_IFF   0x0020 /* IFF identity scheme */
 
15
#define CRYPTO_FLAG_GQ    0x0040 /* GQ identity scheme */
 
16
#define CRYPTO_FLAG_MV    0x0080 /* MV identity scheme */
 
17
#define CRYPTO_FLAG_MASK  0x00f0 /* identity scheme mask */
 
18
        
 
19
/*
 
20
 * The following bits are used by the client during the protocol
 
21
 * exchange.
 
22
 */
 
23
#define CRYPTO_FLAG_VALID 0x0100 /* public key verified */
 
24
#define CRYPTO_FLAG_VRFY  0x0200 /* identity verified */
 
25
#define CRYPTO_FLAG_PROV  0x0400 /* signature verified */
 
26
#define CRYPTO_FLAG_AGREE 0x0800 /* cookie verifed */
 
27
#define CRYPTO_FLAG_AUTO  0x1000 /* autokey verified */
 
28
#define CRYPTO_FLAG_SIGN  0x2000 /* certificate signed */
 
29
#define CRYPTO_FLAG_LEAP  0x4000 /* leapseconds table verified */
 
30
 
 
31
/*
 
32
 * Flags used for certificate management
 
33
 */
 
34
#define CERT_SIGN       0x01    /* certificate is signed */
 
35
#define CERT_TRUST      0x02    /* certificate is trusted */
 
36
#define CERT_PRIV       0x04    /* certificate is private */
 
37
#define CERT_ERROR      0x80    /* certificate has errors */
28
38
 
29
39
/*
30
40
 * Extension field definitions
31
41
 */
32
 
#define CRYPTO_VN       1       /* current protocol version number */
33
 
 
34
 
#define CRYPTO_NULL     ((CRYPTO_VN << 8) | 0) /* no operation */
35
 
#define CRYPTO_STAT     ((CRYPTO_VN << 8) | 1) /* status */
36
 
#define CRYPTO_ASSOC    ((CRYPTO_VN << 8) | 2) /* association ID */
37
 
#define CRYPTO_AUTO     ((CRYPTO_VN << 8) | 3) /* autokey values */
38
 
#define CRYPTO_PRIV     ((CRYPTO_VN << 8) | 4) /* cookie value */
39
 
#define CRYPTO_DHPAR    ((CRYPTO_VN << 8) | 5) /* agreement params */
40
 
#define CRYPTO_DH       ((CRYPTO_VN << 8) | 6) /* public value */
41
 
#define CRYPTO_NAME     ((CRYPTO_VN << 8) | 7) /* host name/pub key */
42
 
#define CRYPTO_CERT     ((CRYPTO_VN << 8) | 8) /* PKI certificate */
43
 
#define CRYPTO_TAI      ((CRYPTO_VN << 8) | 9) /* leapseconds table */
44
 
#define CRYPTO_RESP     0x8000                  /* response */
45
 
#define CRYPTO_ERROR    0x4000                  /* error */
46
 
 
47
 
#ifdef PUBKEY
 
42
#define CRYPTO_MAXLEN   1024    /* max extension field length */
 
43
#define CRYPTO_VN       2       /* current protocol version number */
 
44
#define CRYPTO_CMD(x)   (((CRYPTO_VN << 8) | (x)) << 16)
 
45
#define CRYPTO_NULL     CRYPTO_CMD(0) /* no operation */
 
46
#define CRYPTO_ASSOC    CRYPTO_CMD(1) /* association */
 
47
#define CRYPTO_CERT     CRYPTO_CMD(2) /* certificate */
 
48
#define CRYPTO_COOK     CRYPTO_CMD(3) /* cookie value */
 
49
#define CRYPTO_AUTO     CRYPTO_CMD(4) /* autokey values */
 
50
#define CRYPTO_TAI      CRYPTO_CMD(5) /* leapseconds table */
 
51
#define CRYPTO_SIGN     CRYPTO_CMD(6) /* certificate sign */
 
52
#define CRYPTO_IFF      CRYPTO_CMD(7) /* IFF identity scheme */
 
53
#define CRYPTO_GQ       CRYPTO_CMD(8) /* GQ identity scheme */
 
54
#define CRYPTO_MV       CRYPTO_CMD(9) /* MV identity scheme */
 
55
#define CRYPTO_RESP     0x80000000 /* response */
 
56
#define CRYPTO_ERROR    0x40000000 /* error */
 
57
 
 
58
/*
 
59
 * Autokey event codes
 
60
 */
 
61
#define XEVNT_CMD(x)    (CRPT_EVENT | (x))
 
62
#define XEVNT_OK        XEVNT_CMD(0) /* success */
 
63
#define XEVNT_LEN       XEVNT_CMD(1) /* bad field format or length */
 
64
#define XEVNT_TSP       XEVNT_CMD(2) /* bad timestamp */
 
65
#define XEVNT_FSP       XEVNT_CMD(3) /* bad filestamp */
 
66
#define XEVNT_PUB       XEVNT_CMD(4) /* bad procedure or data */
 
67
#define XEVNT_MD        XEVNT_CMD(5) /* unsupported digest type */
 
68
#define XEVNT_KEY       XEVNT_CMD(6) /* unsupported identity type */
 
69
#define XEVNT_SGL       XEVNT_CMD(7) /* bad signature length */
 
70
#define XEVNT_SIG       XEVNT_CMD(8) /* signature not verified */
 
71
#define XEVNT_VFY       XEVNT_CMD(9) /* certificate not verified */
 
72
#define XEVNT_PER       XEVNT_CMD(10) /* certificate expired */
 
73
#define XEVNT_CKY       XEVNT_CMD(11) /* bad or missing cookie */
 
74
#define XEVNT_DAT       XEVNT_CMD(12) /* bad or missing leapseconds table */
 
75
#define XEVNT_CRT       XEVNT_CMD(13) /* bad or missing certificate */
 
76
#define XEVNT_ID        XEVNT_CMD(14) /* bad or missing identification */
 
77
 
48
78
/*
49
79
 * Configuration codes
50
80
 */
51
81
#define CRYPTO_CONF_NONE  0     /* nothing doing */
52
 
#define CRYPTO_CONF_FLAGS 1     /* initialize flags */
53
 
#define CRYPTO_CONF_PRIV  2     /* load private key from file */
54
 
#define CRYPTO_CONF_PUBL  3     /* load public key from file */
55
 
#define CRYPTO_CONF_DH    4     /* load Diffie_Hellman pars from file */
56
 
#define CRYPTO_CONF_LEAP  5     /* load leapsecond table */
57
 
#define CRYPTO_CONF_KEYS  6     /* set keys directory path */
58
 
#define CRYPTO_CONF_CERT  7     /* load PKI certificate from file */
59
 
#endif /* PUBKEY */
60
 
 
61
 
/*
62
 
 * Function prototypes
63
 
 */
64
 
extern  void    crypto_recv     P((struct peer *, struct recvbuf *));
65
 
extern  int     crypto_xmit     P((u_int32 *, int, u_int, keyid_t,
66
 
                                    u_int));
67
 
extern  keyid_t session_key     P((struct sockaddr_in *, struct
68
 
                                    sockaddr_in *, keyid_t, keyid_t,
69
 
                                    u_long));
70
 
extern  void    make_keylist    P((struct peer *, struct interface *));
71
 
extern  void    key_expire      P((struct peer *));
72
 
extern  void    crypto_agree    P((void));
73
 
#ifdef PUBKEY
74
 
extern  void    crypto_config   P((int, char *));
75
 
extern  void    crypto_setup    P((void));
76
 
extern  int     crypto_public   P((struct peer *, u_char *, u_int));
77
 
#endif /* PUBKEY */
 
82
#define CRYPTO_CONF_PRIV  1     /* host keys file name */
 
83
#define CRYPTO_CONF_SIGN  2     /* signature keys file name */
 
84
#define CRYPTO_CONF_LEAP  3     /* leapseconds table file name */
 
85
#define CRYPTO_CONF_KEYS  4     /* keys directory path */
 
86
#define CRYPTO_CONF_CERT  5     /* certificate file name */
 
87
#define CRYPTO_CONF_RAND  6     /* random seed file name */
 
88
#define CRYPTO_CONF_TRST  7     /* specify trust */
 
89
#define CRYPTO_CONF_IFFPAR 8    /* IFF parameters file name */
 
90
#define CRYPTO_CONF_GQPAR 9     /* GQ parameters file name */
 
91
#define CRYPTO_CONF_MVPAR 10    /* GQ parameters file name */
 
92
#define CRYPTO_CONF_PW    11    /* private key password */
 
93
 
 
94
/*
 
95
 * Miscellaneous crypto stuff
 
96
 */
 
97
#define NTP_MAXSESSION  100     /* maximum session key list entries */
 
98
#define NTP_AUTOMAX     13      /* log2 default max session key life */
 
99
#define KEY_REVOKE      16      /* log2 default key revoke timeout */
 
100
#define NTP_MAXEXTEN    1024    /* maximum extension field size */
 
101
 
 
102
/*
 
103
 * The autokey structure holds the values used to authenticate key IDs.
 
104
 */
 
105
struct autokey {                /* network byte order */
 
106
        keyid_t key;            /* key ID */
 
107
        int32   seq;            /* key number */
 
108
};
 
109
 
 
110
/*
 
111
 * The value structure holds variable length data such as public
 
112
 * key, agreement parameters, public valule and leapsecond table.
 
113
 * They are in network byte order.
 
114
 */
 
115
struct value {                  /* network byte order */
 
116
        tstamp_t tstamp;        /* timestamp */
 
117
        tstamp_t fstamp;        /* filestamp */
 
118
        u_int32 vallen;         /* value length */
 
119
        u_char  *ptr;           /* data pointer (various) */
 
120
        u_int32 siglen;         /* signature length */
 
121
        u_char  *sig;           /* signature */
 
122
};
 
123
 
 
124
/*
 
125
 * The packet extension field structures are used to hold values
 
126
 * and signatures in network byte order.
 
127
 */
 
128
struct exten {
 
129
        u_int32 opcode;         /* opcode */
 
130
        u_int32 associd;        /* association ID */
 
131
        u_int32 tstamp;         /* timestamp */
 
132
        u_int32 fstamp;         /* filestamp */
 
133
        u_int32 vallen;         /* value length */
 
134
        u_int32 pkt[1];         /* start of value field */
 
135
};
 
136
 
 
137
/*
 
138
 * The certificate info/value structure
 
139
 */
 
140
struct cert_info {
 
141
        struct cert_info *link; /* forward link */
 
142
        u_int   flags;          /* flags that wave */
 
143
        EVP_PKEY *pkey;         /* generic key */
 
144
        long    version;        /* X509 version */
 
145
        int     nid;            /* signature/digest ID */
 
146
        const EVP_MD *digest;   /* message digest algorithm */
 
147
        u_long  serial;         /* serial number */
 
148
        tstamp_t first;         /* valid not before */
 
149
        tstamp_t last;          /* valid not after */
 
150
        char    *subject;       /* subject common name */
 
151
        char    *issuer;        /* issuer common name */
 
152
        u_char  *grpkey;        /* GQ group key */
 
153
        u_int   grplen;         /* GQ group key length */
 
154
        struct value cert;      /* certificate/value */
 
155
};
78
156
 
79
157
/*
80
158
 * Cryptographic values
81
159
 */
 
160
extern  char    *keysdir;       /* crypto keys directory */
82
161
extern  u_int   crypto_flags;   /* status word */
83
 
#ifdef PUBKEY
84
 
extern  R_DH_PARAMS dh_params;
85
 
extern  struct value host;      /* host name/public key */
86
 
extern  struct value certif;    /* certificate */
87
 
extern  struct value dhparam;   /* agreement parameters */
88
 
extern  struct value dhpub;     /* public value */
 
162
extern  struct value hostval;   /* host name/value */
 
163
extern  struct cert_info *cinfo; /* host certificate information */
89
164
extern  struct value tai_leap;  /* leapseconds table */
90
 
extern  u_int   crypto_flags;   /* status word */       
91
165
extern  u_int   sys_tai;        /* current UTC offset from TAI */
92
 
#endif /* PUBKEY */
93
 
#endif /* AUTOKEY */
 
166
#endif /* OPENSSL */