dst.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2000-2002  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 #ifndef DST_DST_H
00019 #define DST_DST_H 1
00020 
00021 /*! \file dst/dst.h */
00022 
00023 #include <isc/lang.h>
00024 #include <isc/stdtime.h>
00025 
00026 #include <dns/types.h>
00027 #include <dns/log.h>
00028 #include <dns/name.h>
00029 #include <dns/secalg.h>
00030 #include <dns/ds.h>
00031 #include <dns/dsdigest.h>
00032 
00033 #include <dst/gssapi.h>
00034 
00035 ISC_LANG_BEGINDECLS
00036 
00037 /***
00038  *** Types
00039  ***/
00040 
00041 /*%
00042  * The dst_key structure is opaque.  Applications should use the accessor
00043  * functions provided to retrieve key attributes.  If an application needs
00044  * to set attributes, new accessor functions will be written.
00045  */
00046 
00047 typedef struct dst_key          dst_key_t;
00048 typedef struct dst_context      dst_context_t;
00049 
00050 /* DST algorithm codes */
00051 #define DST_ALG_UNKNOWN         0
00052 #define DST_ALG_RSAMD5          1
00053 #define DST_ALG_RSA             DST_ALG_RSAMD5  /*%< backwards compatibility */
00054 #define DST_ALG_DH              2
00055 #define DST_ALG_DSA             3
00056 #define DST_ALG_ECC             4
00057 #define DST_ALG_RSASHA1         5
00058 #define DST_ALG_NSEC3DSA        6
00059 #define DST_ALG_NSEC3RSASHA1    7
00060 #define DST_ALG_RSASHA256       8
00061 #define DST_ALG_RSASHA512       10
00062 #define DST_ALG_ECCGOST         12
00063 #define DST_ALG_ECDSA256        13
00064 #define DST_ALG_ECDSA384        14
00065 #define DST_ALG_HMACMD5         157
00066 #define DST_ALG_GSSAPI          160
00067 #define DST_ALG_HMACSHA1        161     /* XXXMPA */
00068 #define DST_ALG_HMACSHA224      162     /* XXXMPA */
00069 #define DST_ALG_HMACSHA256      163     /* XXXMPA */
00070 #define DST_ALG_HMACSHA384      164     /* XXXMPA */
00071 #define DST_ALG_HMACSHA512      165     /* XXXMPA */
00072 #define DST_ALG_PRIVATE         254
00073 #define DST_ALG_EXPAND          255
00074 #define DST_MAX_ALGS            255
00075 
00076 /*% A buffer of this size is large enough to hold any key */
00077 #define DST_KEY_MAXSIZE         1280
00078 
00079 /*%
00080  * A buffer of this size is large enough to hold the textual representation
00081  * of any key
00082  */
00083 #define DST_KEY_MAXTEXTSIZE     2048
00084 
00085 /*% 'Type' for dst_read_key() */
00086 #define DST_TYPE_KEY            0x1000000       /* KEY key */
00087 #define DST_TYPE_PRIVATE        0x2000000
00088 #define DST_TYPE_PUBLIC         0x4000000
00089 
00090 /* Key timing metadata definitions */
00091 #define DST_TIME_CREATED        0
00092 #define DST_TIME_PUBLISH        1
00093 #define DST_TIME_ACTIVATE       2
00094 #define DST_TIME_REVOKE         3
00095 #define DST_TIME_INACTIVE       4
00096 #define DST_TIME_DELETE         5
00097 #define DST_TIME_DSPUBLISH      6
00098 #define DST_MAX_TIMES           6
00099 
00100 /* Numeric metadata definitions */
00101 #define DST_NUM_PREDECESSOR     0
00102 #define DST_NUM_SUCCESSOR       1
00103 #define DST_NUM_MAXTTL          2
00104 #define DST_NUM_ROLLPERIOD      3
00105 #define DST_MAX_NUMERIC         3
00106 
00107 /*
00108  * Current format version number of the private key parser.
00109  *
00110  * When parsing a key file with the same major number but a higher minor
00111  * number, the key parser will ignore any fields it does not recognize.
00112  * Thus, DST_MINOR_VERSION should be incremented whenever new
00113  * fields are added to the private key file (such as new metadata).
00114  *
00115  * When rewriting these keys, those fields will be dropped, and the
00116  * format version set back to the current one..
00117  *
00118  * When a key is seen with a higher major number, the key parser will
00119  * reject it as invalid.  Thus, DST_MAJOR_VERSION should be incremented
00120  * and DST_MINOR_VERSION set to zero whenever there is a format change
00121  * which is not backward compatible to previous versions of the dst_key
00122  * parser, such as change in the syntax of an existing field, the removal
00123  * of a currently mandatory field, or a new field added which would
00124  * alter the functioning of the key if it were absent.
00125  */
00126 #define DST_MAJOR_VERSION       1
00127 #define DST_MINOR_VERSION       3
00128 
00129 /***
00130  *** Functions
00131  ***/
00132 
00133 isc_result_t
00134 dst_lib_init(isc_mem_t *mctx, isc_entropy_t *ectx, unsigned int eflags);
00135 
00136 isc_result_t
00137 dst_lib_init2(isc_mem_t *mctx, isc_entropy_t *ectx,
00138               const char *engine, unsigned int eflags);
00139 /*%<
00140  * Initializes the DST subsystem.
00141  *
00142  * Requires:
00143  * \li  "mctx" is a valid memory context
00144  * \li  "ectx" is a valid entropy context
00145  *
00146  * Returns:
00147  * \li  ISC_R_SUCCESS
00148  * \li  ISC_R_NOMEMORY
00149  * \li  DST_R_NOENGINE
00150  *
00151  * Ensures:
00152  * \li  DST is properly initialized.
00153  */
00154 
00155 void
00156 dst_lib_destroy(void);
00157 /*%<
00158  * Releases all resources allocated by DST.
00159  */
00160 
00161 isc_boolean_t
00162 dst_algorithm_supported(unsigned int alg);
00163 /*%<
00164  * Checks that a given algorithm is supported by DST.
00165  *
00166  * Returns:
00167  * \li  ISC_TRUE
00168  * \li  ISC_FALSE
00169  */
00170 
00171 isc_boolean_t
00172 dst_ds_digest_supported(unsigned int digest_type);
00173 /*%<
00174  * Checks that a given digest algorithm is supported by DST.
00175  *
00176  * Returns:
00177  * \li  ISC_TRUE
00178  * \li  ISC_FALSE
00179  */
00180 
00181 isc_result_t
00182 dst_context_create(dst_key_t *key, isc_mem_t *mctx, dst_context_t **dctxp);
00183 
00184 isc_result_t
00185 dst_context_create2(dst_key_t *key, isc_mem_t *mctx,
00186                     isc_logcategory_t *category, dst_context_t **dctxp);
00187 
00188 isc_result_t
00189 dst_context_create3(dst_key_t *key, isc_mem_t *mctx,
00190                     isc_logcategory_t *category, isc_boolean_t useforsigning,
00191                     dst_context_t **dctxp);
00192 
00193 isc_result_t
00194 dst_context_create4(dst_key_t *key, isc_mem_t *mctx,
00195                     isc_logcategory_t *category, isc_boolean_t useforsigning,
00196                     int maxbits, dst_context_t **dctxp);
00197 /*%<
00198  * Creates a context to be used for a sign or verify operation.
00199  *
00200  * Requires:
00201  * \li  "key" is a valid key.
00202  * \li  "mctx" is a valid memory context.
00203  * \li  dctxp != NULL && *dctxp == NULL
00204  *
00205  * Returns:
00206  * \li  ISC_R_SUCCESS
00207  * \li  ISC_R_NOMEMORY
00208  *
00209  * Ensures:
00210  * \li  *dctxp will contain a usable context.
00211  */
00212 
00213 void
00214 dst_context_destroy(dst_context_t **dctxp);
00215 /*%<
00216  * Destroys all memory associated with a context.
00217  *
00218  * Requires:
00219  * \li  *dctxp != NULL && *dctxp == NULL
00220  *
00221  * Ensures:
00222  * \li  *dctxp == NULL
00223  */
00224 
00225 isc_result_t
00226 dst_context_adddata(dst_context_t *dctx, const isc_region_t *data);
00227 /*%<
00228  * Incrementally adds data to the context to be used in a sign or verify
00229  * operation.
00230  *
00231  * Requires:
00232  * \li  "dctx" is a valid context
00233  * \li  "data" is a valid region
00234  *
00235  * Returns:
00236  * \li  ISC_R_SUCCESS
00237  * \li  DST_R_SIGNFAILURE
00238  * \li  all other errors indicate failure
00239  */
00240 
00241 isc_result_t
00242 dst_context_sign(dst_context_t *dctx, isc_buffer_t *sig);
00243 /*%<
00244  * Computes a signature using the data and key stored in the context.
00245  *
00246  * Requires:
00247  * \li  "dctx" is a valid context.
00248  * \li  "sig" is a valid buffer.
00249  *
00250  * Returns:
00251  * \li  ISC_R_SUCCESS
00252  * \li  DST_R_VERIFYFAILURE
00253  * \li  all other errors indicate failure
00254  *
00255  * Ensures:
00256  * \li  "sig" will contain the signature
00257  */
00258 
00259 isc_result_t
00260 dst_context_verify(dst_context_t *dctx, isc_region_t *sig);
00261 
00262 isc_result_t
00263 dst_context_verify2(dst_context_t *dctx, unsigned int maxbits,
00264                     isc_region_t *sig);
00265 /*%<
00266  * Verifies the signature using the data and key stored in the context.
00267  *
00268  * 'maxbits' specifies the maximum number of bits permitted in the RSA
00269  * exponent.
00270  *
00271  * Requires:
00272  * \li  "dctx" is a valid context.
00273  * \li  "sig" is a valid region.
00274  *
00275  * Returns:
00276  * \li  ISC_R_SUCCESS
00277  * \li  all other errors indicate failure
00278  *
00279  * Ensures:
00280  * \li  "sig" will contain the signature
00281  */
00282 
00283 isc_result_t
00284 dst_key_computesecret(const dst_key_t *pub, const dst_key_t *priv,
00285                       isc_buffer_t *secret);
00286 /*%<
00287  * Computes a shared secret from two (Diffie-Hellman) keys.
00288  *
00289  * Requires:
00290  * \li  "pub" is a valid key that can be used to derive a shared secret
00291  * \li  "priv" is a valid private key that can be used to derive a shared secret
00292  * \li  "secret" is a valid buffer
00293  *
00294  * Returns:
00295  * \li  ISC_R_SUCCESS
00296  * \li  any other result indicates failure
00297  *
00298  * Ensures:
00299  * \li  If successful, secret will contain the derived shared secret.
00300  */
00301 
00302 isc_result_t
00303 dst_key_getfilename(dns_name_t *name, dns_keytag_t id, unsigned int alg,
00304                     int type, const char *directory,
00305                     isc_mem_t *mctx, isc_buffer_t *buf);
00306 /*%<
00307  * Generates a key filename for the name, algorithm, and
00308  * id, and places it in the buffer 'buf'. If directory is NULL, the
00309  * current directory is assumed.
00310  *
00311  * Requires:
00312  * \li  "name" is a valid absolute dns name.
00313  * \li  "id" is a valid key tag identifier.
00314  * \li  "alg" is a supported key algorithm.
00315  * \li  "type" is DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or the bitwise union.
00316  *                DST_TYPE_KEY look for a KEY record otherwise DNSKEY
00317  * \li  "mctx" is a valid memory context.
00318  * \li  "buf" is not NULL.
00319  *
00320  * Returns:
00321  * \li  ISC_R_SUCCESS
00322  * \li  any other result indicates failure
00323  */
00324 
00325 isc_result_t
00326 dst_key_fromfile(dns_name_t *name, dns_keytag_t id, unsigned int alg, int type,
00327                  const char *directory, isc_mem_t *mctx, dst_key_t **keyp);
00328 /*%<
00329  * Reads a key from permanent storage.  The key can either be a public or
00330  * private key, and is specified by name, algorithm, and id.  If a private key
00331  * is specified, the public key must also be present.  If directory is NULL,
00332  * the current directory is assumed.
00333  *
00334  * Requires:
00335  * \li  "name" is a valid absolute dns name.
00336  * \li  "id" is a valid key tag identifier.
00337  * \li  "alg" is a supported key algorithm.
00338  * \li  "type" is DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or the bitwise union.
00339  *                DST_TYPE_KEY look for a KEY record otherwise DNSKEY
00340  * \li  "mctx" is a valid memory context.
00341  * \li  "keyp" is not NULL and "*keyp" is NULL.
00342  *
00343  * Returns:
00344  * \li  ISC_R_SUCCESS
00345  * \li  any other result indicates failure
00346  *
00347  * Ensures:
00348  * \li  If successful, *keyp will contain a valid key.
00349  */
00350 
00351 isc_result_t
00352 dst_key_fromnamedfile(const char *filename, const char *dirname,
00353                       int type, isc_mem_t *mctx, dst_key_t **keyp);
00354 /*%<
00355  * Reads a key from permanent storage.  The key can either be a public or
00356  * key, and is specified by filename.  If a private key is specified, the
00357  * public key must also be present.
00358  *
00359  * If 'dirname' is not NULL, and 'filename' is a relative path,
00360  * then the file is looked up relative to the given directory.
00361  * If 'filename' is an absolute path, 'dirname' is ignored.
00362  *
00363  * Requires:
00364  * \li  "filename" is not NULL
00365  * \li  "type" is DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or the bitwise union
00366  *                DST_TYPE_KEY look for a KEY record otherwise DNSKEY
00367  * \li  "mctx" is a valid memory context
00368  * \li  "keyp" is not NULL and "*keyp" is NULL.
00369  *
00370  * Returns:
00371  * \li  ISC_R_SUCCESS
00372  * \li  any other result indicates failure
00373  *
00374  * Ensures:
00375  * \li  If successful, *keyp will contain a valid key.
00376  */
00377 
00378 
00379 isc_result_t
00380 dst_key_read_public(const char *filename, int type,
00381                     isc_mem_t *mctx, dst_key_t **keyp);
00382 /*%<
00383  * Reads a public key from permanent storage.  The key must be a public key.
00384  *
00385  * Requires:
00386  * \li  "filename" is not NULL
00387  * \li  "type" is DST_TYPE_KEY look for a KEY record otherwise DNSKEY
00388  * \li  "mctx" is a valid memory context
00389  * \li  "keyp" is not NULL and "*keyp" is NULL.
00390  *
00391  * Returns:
00392  * \li  ISC_R_SUCCESS
00393  * \li  DST_R_BADKEYTYPE if the key type is not the expected one
00394  * \li  ISC_R_UNEXPECTEDTOKEN if the file can not be parsed as a public key
00395  * \li  any other result indicates failure
00396  *
00397  * Ensures:
00398  * \li  If successful, *keyp will contain a valid key.
00399  */
00400 
00401 isc_result_t
00402 dst_key_tofile(const dst_key_t *key, int type, const char *directory);
00403 /*%<
00404  * Writes a key to permanent storage.  The key can either be a public or
00405  * private key.  Public keys are written in DNS format and private keys
00406  * are written as a set of base64 encoded values.  If directory is NULL,
00407  * the current directory is assumed.
00408  *
00409  * Requires:
00410  * \li  "key" is a valid key.
00411  * \li  "type" is DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or the bitwise union
00412  *
00413  * Returns:
00414  * \li  ISC_R_SUCCESS
00415  * \li  any other result indicates failure
00416  */
00417 
00418 isc_result_t
00419 dst_key_fromdns(dns_name_t *name, dns_rdataclass_t rdclass,
00420                 isc_buffer_t *source, isc_mem_t *mctx, dst_key_t **keyp);
00421 /*%<
00422  * Converts a DNS KEY record into a DST key.
00423  *
00424  * Requires:
00425  * \li  "name" is a valid absolute dns name.
00426  * \li  "source" is a valid buffer.  There must be at least 4 bytes available.
00427  * \li  "mctx" is a valid memory context.
00428  * \li  "keyp" is not NULL and "*keyp" is NULL.
00429  *
00430  * Returns:
00431  * \li  ISC_R_SUCCESS
00432  * \li  any other result indicates failure
00433  *
00434  * Ensures:
00435  * \li  If successful, *keyp will contain a valid key, and the consumed
00436  *      pointer in data will be advanced.
00437  */
00438 
00439 isc_result_t
00440 dst_key_todns(const dst_key_t *key, isc_buffer_t *target);
00441 /*%<
00442  * Converts a DST key into a DNS KEY record.
00443  *
00444  * Requires:
00445  * \li  "key" is a valid key.
00446  * \li  "target" is a valid buffer.  There must be at least 4 bytes unused.
00447  *
00448  * Returns:
00449  * \li  ISC_R_SUCCESS
00450  * \li  any other result indicates failure
00451  *
00452  * Ensures:
00453  * \li  If successful, the used pointer in 'target' is advanced by at least 4.
00454  */
00455 
00456 isc_result_t
00457 dst_key_frombuffer(dns_name_t *name, unsigned int alg,
00458                    unsigned int flags, unsigned int protocol,
00459                    dns_rdataclass_t rdclass,
00460                    isc_buffer_t *source, isc_mem_t *mctx, dst_key_t **keyp);
00461 /*%<
00462  * Converts a buffer containing DNS KEY RDATA into a DST key.
00463  *
00464  * Requires:
00465  *\li   "name" is a valid absolute dns name.
00466  *\li   "alg" is a supported key algorithm.
00467  *\li   "source" is a valid buffer.
00468  *\li   "mctx" is a valid memory context.
00469  *\li   "keyp" is not NULL and "*keyp" is NULL.
00470  *
00471  * Returns:
00472  *\li   ISC_R_SUCCESS
00473  * \li  any other result indicates failure
00474  *
00475  * Ensures:
00476  *\li   If successful, *keyp will contain a valid key, and the consumed
00477  *      pointer in source will be advanced.
00478  */
00479 
00480 isc_result_t
00481 dst_key_tobuffer(const dst_key_t *key, isc_buffer_t *target);
00482 /*%<
00483  * Converts a DST key into DNS KEY RDATA format.
00484  *
00485  * Requires:
00486  *\li   "key" is a valid key.
00487  *\li   "target" is a valid buffer.
00488  *
00489  * Returns:
00490  *\li   ISC_R_SUCCESS
00491  * \li  any other result indicates failure
00492  *
00493  * Ensures:
00494  *\li   If successful, the used pointer in 'target' is advanced.
00495  */
00496 
00497 isc_result_t
00498 dst_key_privatefrombuffer(dst_key_t *key, isc_buffer_t *buffer);
00499 /*%<
00500  * Converts a public key into a private key, reading the private key
00501  * information from the buffer.  The buffer should contain the same data
00502  * as the .private key file would.
00503  *
00504  * Requires:
00505  *\li   "key" is a valid public key.
00506  *\li   "buffer" is not NULL.
00507  *
00508  * Returns:
00509  *\li   ISC_R_SUCCESS
00510  * \li  any other result indicates failure
00511  *
00512  * Ensures:
00513  *\li   If successful, key will contain a valid private key.
00514  */
00515 
00516 gss_ctx_id_t
00517 dst_key_getgssctx(const dst_key_t *key);
00518 /*%<
00519  * Returns the opaque key data.
00520  * Be cautions when using this value unless you know what you are doing.
00521  *
00522  * Requires:
00523  *\li   "key" is not NULL.
00524  *
00525  * Returns:
00526  *\li   gssctx key data, possibly NULL.
00527  */
00528 
00529 isc_result_t
00530 dst_key_fromgssapi(dns_name_t *name, gss_ctx_id_t gssctx, isc_mem_t *mctx,
00531                    dst_key_t **keyp, isc_region_t *intoken);
00532 /*%<
00533  * Converts a GSSAPI opaque context id into a DST key.
00534  *
00535  * Requires:
00536  *\li   "name" is a valid absolute dns name.
00537  *\li   "gssctx" is a GSSAPI context id.
00538  *\li   "mctx" is a valid memory context.
00539  *\li   "keyp" is not NULL and "*keyp" is NULL.
00540  *
00541  * Returns:
00542  *\li   ISC_R_SUCCESS
00543  * \li  any other result indicates failure
00544  *
00545  * Ensures:
00546  *\li   If successful, *keyp will contain a valid key and be responsible for
00547  *      the context id.
00548  */
00549 
00550 #ifdef DST_KEY_INTERNAL
00551 isc_result_t
00552 dst_key_buildinternal(dns_name_t *name, unsigned int alg,
00553                       unsigned int bits, unsigned int flags,
00554                       unsigned int protocol, dns_rdataclass_t rdclass,
00555                       void *data, isc_mem_t *mctx, dst_key_t **keyp);
00556 #endif
00557 
00558 isc_result_t
00559 dst_key_fromlabel(dns_name_t *name, int alg, unsigned int flags,
00560                   unsigned int protocol, dns_rdataclass_t rdclass,
00561                   const char *engine, const char *label, const char *pin,
00562                   isc_mem_t *mctx, dst_key_t **keyp);
00563 
00564 isc_result_t
00565 dst_key_generate(dns_name_t *name, unsigned int alg,
00566                  unsigned int bits, unsigned int param,
00567                  unsigned int flags, unsigned int protocol,
00568                  dns_rdataclass_t rdclass,
00569                  isc_mem_t *mctx, dst_key_t **keyp);
00570 
00571 isc_result_t
00572 dst_key_generate2(dns_name_t *name, unsigned int alg,
00573                   unsigned int bits, unsigned int param,
00574                   unsigned int flags, unsigned int protocol,
00575                   dns_rdataclass_t rdclass,
00576                   isc_mem_t *mctx, dst_key_t **keyp,
00577                   void (*callback)(int));
00578 
00579 /*%<
00580  * Generate a DST key (or keypair) with the supplied parameters.  The
00581  * interpretation of the "param" field depends on the algorithm:
00582  * \code
00583  *      RSA:    exponent
00584  *              0       use exponent 3
00585  *              !0      use Fermat4 (2^16 + 1)
00586  *      DH:     generator
00587  *              0       default - use well known prime if bits == 768 or 1024,
00588  *                      otherwise use 2 as the generator.
00589  *              !0      use this value as the generator.
00590  *      DSA:    unused
00591  *      HMACMD5: entropy
00592  *              0       default - require good entropy
00593  *              !0      lack of good entropy is ok
00594  *\endcode
00595  *
00596  * Requires:
00597  *\li   "name" is a valid absolute dns name.
00598  *\li   "keyp" is not NULL and "*keyp" is NULL.
00599  *
00600  * Returns:
00601  *\li   ISC_R_SUCCESS
00602  * \li  any other result indicates failure
00603  *
00604  * Ensures:
00605  *\li   If successful, *keyp will contain a valid key.
00606  */
00607 
00608 isc_boolean_t
00609 dst_key_compare(const dst_key_t *key1, const dst_key_t *key2);
00610 /*%<
00611  * Compares two DST keys.  Returns true if they match, false otherwise.
00612  *
00613  * Keys ARE NOT considered to match if one of them is the revoked version
00614  * of the other.
00615  *
00616  * Requires:
00617  *\li   "key1" is a valid key.
00618  *\li   "key2" is a valid key.
00619  *
00620  * Returns:
00621  *\li   ISC_TRUE
00622  * \li  ISC_FALSE
00623  */
00624 
00625 isc_boolean_t
00626 dst_key_pubcompare(const dst_key_t *key1, const dst_key_t *key2,
00627                    isc_boolean_t match_revoked_key);
00628 /*%<
00629  * Compares only the public portions of two DST keys.  Returns true
00630  * if they match, false otherwise.  This allows us, for example, to
00631  * determine whether a public key found in a zone matches up with a
00632  * key pair found on disk.
00633  *
00634  * If match_revoked_key is TRUE, then keys ARE considered to match if one
00635  * of them is the revoked version of the other. Otherwise, they are not.
00636  *
00637  * Requires:
00638  *\li   "key1" is a valid key.
00639  *\li   "key2" is a valid key.
00640  *
00641  * Returns:
00642  *\li   ISC_TRUE
00643  * \li  ISC_FALSE
00644  */
00645 
00646 isc_boolean_t
00647 dst_key_paramcompare(const dst_key_t *key1, const dst_key_t *key2);
00648 /*%<
00649  * Compares the parameters of two DST keys.  This is used to determine if
00650  * two (Diffie-Hellman) keys can be used to derive a shared secret.
00651  *
00652  * Requires:
00653  *\li   "key1" is a valid key.
00654  *\li   "key2" is a valid key.
00655  *
00656  * Returns:
00657  *\li   ISC_TRUE
00658  * \li  ISC_FALSE
00659  */
00660 
00661 void
00662 dst_key_attach(dst_key_t *source, dst_key_t **target);
00663 /*
00664  * Attach to a existing key increasing the reference count.
00665  *
00666  * Requires:
00667  *\li 'source' to be a valid key.
00668  *\li 'target' to be non-NULL and '*target' to be NULL.
00669  */
00670 
00671 void
00672 dst_key_free(dst_key_t **keyp);
00673 /*%<
00674  * Decrement the key's reference counter and, when it reaches zero,
00675  * release all memory associated with the key.
00676  *
00677  * Requires:
00678  *\li   "keyp" is not NULL and "*keyp" is a valid key.
00679  *\li   reference counter greater than zero.
00680  *
00681  * Ensures:
00682  *\li   All memory associated with "*keyp" will be freed.
00683  *\li   *keyp == NULL
00684  */
00685 
00686 /*%<
00687  * Accessor functions to obtain key fields.
00688  *
00689  * Require:
00690  *\li   "key" is a valid key.
00691  */
00692 dns_name_t *
00693 dst_key_name(const dst_key_t *key);
00694 
00695 unsigned int
00696 dst_key_size(const dst_key_t *key);
00697 
00698 unsigned int
00699 dst_key_proto(const dst_key_t *key);
00700 
00701 unsigned int
00702 dst_key_alg(const dst_key_t *key);
00703 
00704 isc_uint32_t
00705 dst_key_flags(const dst_key_t *key);
00706 
00707 dns_keytag_t
00708 dst_key_id(const dst_key_t *key);
00709 
00710 dns_keytag_t
00711 dst_key_rid(const dst_key_t *key);
00712 
00713 dns_rdataclass_t
00714 dst_key_class(const dst_key_t *key);
00715 
00716 isc_boolean_t
00717 dst_key_isprivate(const dst_key_t *key);
00718 
00719 isc_boolean_t
00720 dst_key_iszonekey(const dst_key_t *key);
00721 
00722 isc_boolean_t
00723 dst_key_isnullkey(const dst_key_t *key);
00724 
00725 isc_result_t
00726 dst_key_buildfilename(const dst_key_t *key, int type,
00727                       const char *directory, isc_buffer_t *out);
00728 /*%<
00729  * Generates the filename used by dst to store the specified key.
00730  * If directory is NULL, the current directory is assumed.
00731  *
00732  * Requires:
00733  *\li   "key" is a valid key
00734  *\li   "type" is either DST_TYPE_PUBLIC, DST_TYPE_PRIVATE, or 0 for no suffix.
00735  *\li   "out" is a valid buffer
00736  *
00737  * Ensures:
00738  *\li   the file name will be written to "out", and the used pointer will
00739  *              be advanced.
00740  */
00741 
00742 isc_result_t
00743 dst_key_sigsize(const dst_key_t *key, unsigned int *n);
00744 /*%<
00745  * Computes the size of a signature generated by the given key.
00746  *
00747  * Requires:
00748  *\li   "key" is a valid key.
00749  *\li   "n" is not NULL
00750  *
00751  * Returns:
00752  *\li   #ISC_R_SUCCESS
00753  *\li   DST_R_UNSUPPORTEDALG
00754  *
00755  * Ensures:
00756  *\li   "n" stores the size of a generated signature
00757  */
00758 
00759 isc_result_t
00760 dst_key_secretsize(const dst_key_t *key, unsigned int *n);
00761 /*%<
00762  * Computes the size of a shared secret generated by the given key.
00763  *
00764  * Requires:
00765  *\li   "key" is a valid key.
00766  *\li   "n" is not NULL
00767  *
00768  * Returns:
00769  *\li   #ISC_R_SUCCESS
00770  *\li   DST_R_UNSUPPORTEDALG
00771  *
00772  * Ensures:
00773  *\li   "n" stores the size of a generated shared secret
00774  */
00775 
00776 isc_uint16_t
00777 dst_region_computeid(const isc_region_t *source, unsigned int alg);
00778 isc_uint16_t
00779 dst_region_computerid(const isc_region_t *source, unsigned int alg);
00780 /*%<
00781  * Computes the (revoked) key id of the key stored in the provided
00782  * region with the given algorithm.
00783  *
00784  * Requires:
00785  *\li   "source" contains a valid, non-NULL region.
00786  *
00787  * Returns:
00788  *\li   the key id
00789  */
00790 
00791 isc_uint16_t
00792 dst_key_getbits(const dst_key_t *key);
00793 /*%<
00794  * Get the number of digest bits required (0 == MAX).
00795  *
00796  * Requires:
00797  *      "key" is a valid key.
00798  */
00799 
00800 void
00801 dst_key_setbits(dst_key_t *key, isc_uint16_t bits);
00802 /*%<
00803  * Set the number of digest bits required (0 == MAX).
00804  *
00805  * Requires:
00806  *      "key" is a valid key.
00807  */
00808 
00809 void
00810 dst_key_setttl(dst_key_t *key, dns_ttl_t ttl);
00811 /*%<
00812  * Set the default TTL to use when converting the key
00813  * to a KEY or DNSKEY RR.
00814  *
00815  * Requires:
00816  *      "key" is a valid key.
00817  */
00818 
00819 dns_ttl_t
00820 dst_key_getttl(const dst_key_t *key);
00821 /*%<
00822  * Get the default TTL to use when converting the key
00823  * to a KEY or DNSKEY RR.
00824  *
00825  * Requires:
00826  *      "key" is a valid key.
00827  */
00828 
00829 isc_result_t
00830 dst_key_setflags(dst_key_t *key, isc_uint32_t flags);
00831 /*
00832  * Set the key flags, and recompute the key ID.
00833  *
00834  * Requires:
00835  *      "key" is a valid key.
00836  */
00837 
00838 isc_result_t
00839 dst_key_getnum(const dst_key_t *key, int type, isc_uint32_t *valuep);
00840 /*%<
00841  * Get a member of the numeric metadata array and place it in '*valuep'.
00842  *
00843  * Requires:
00844  *      "key" is a valid key.
00845  *      "type" is no larger than DST_MAX_NUMERIC
00846  *      "timep" is not null.
00847  */
00848 
00849 void
00850 dst_key_setnum(dst_key_t *key, int type, isc_uint32_t value);
00851 /*%<
00852  * Set a member of the numeric metadata array.
00853  *
00854  * Requires:
00855  *      "key" is a valid key.
00856  *      "type" is no larger than DST_MAX_NUMERIC
00857  */
00858 
00859 void
00860 dst_key_unsetnum(dst_key_t *key, int type);
00861 /*%<
00862  * Flag a member of the numeric metadata array as "not set".
00863  *
00864  * Requires:
00865  *      "key" is a valid key.
00866  *      "type" is no larger than DST_MAX_NUMERIC
00867  */
00868 
00869 isc_result_t
00870 dst_key_gettime(const dst_key_t *key, int type, isc_stdtime_t *timep);
00871 /*%<
00872  * Get a member of the timing metadata array and place it in '*timep'.
00873  *
00874  * Requires:
00875  *      "key" is a valid key.
00876  *      "type" is no larger than DST_MAX_TIMES
00877  *      "timep" is not null.
00878  */
00879 
00880 void
00881 dst_key_settime(dst_key_t *key, int type, isc_stdtime_t when);
00882 /*%<
00883  * Set a member of the timing metadata array.
00884  *
00885  * Requires:
00886  *      "key" is a valid key.
00887  *      "type" is no larger than DST_MAX_TIMES
00888  */
00889 
00890 void
00891 dst_key_unsettime(dst_key_t *key, int type);
00892 /*%<
00893  * Flag a member of the timing metadata array as "not set".
00894  *
00895  * Requires:
00896  *      "key" is a valid key.
00897  *      "type" is no larger than DST_MAX_TIMES
00898  */
00899 
00900 isc_result_t
00901 dst_key_getprivateformat(const dst_key_t *key, int *majorp, int *minorp);
00902 /*%<
00903  * Get the private key format version number.  (If the key does not have
00904  * a private key associated with it, the version will be 0.0.)  The major
00905  * version number is placed in '*majorp', and the minor version number in
00906  * '*minorp'.
00907  *
00908  * Requires:
00909  *      "key" is a valid key.
00910  *      "majorp" is not NULL.
00911  *      "minorp" is not NULL.
00912  */
00913 
00914 void
00915 dst_key_setprivateformat(dst_key_t *key, int major, int minor);
00916 /*%<
00917  * Set the private key format version number.
00918  *
00919  * Requires:
00920  *      "key" is a valid key.
00921  */
00922 
00923 #define DST_KEY_FORMATSIZE (DNS_NAME_FORMATSIZE + DNS_SECALG_FORMATSIZE + 7)
00924 
00925 void
00926 dst_key_format(const dst_key_t *key, char *cp, unsigned int size);
00927 /*%<
00928  * Write the uniquely identifying information about the key (name,
00929  * algorithm, key ID) into a string 'cp' of size 'size'.
00930  */
00931 
00932 
00933 isc_buffer_t *
00934 dst_key_tkeytoken(const dst_key_t *key);
00935 /*%<
00936  * Return the token from the TKEY request, if any.  If this key was
00937  * not negotiated via TKEY, return NULL.
00938  *
00939  * Requires:
00940  *      "key" is a valid key.
00941  */
00942 
00943 
00944 isc_result_t
00945 dst_key_dump(dst_key_t *key, isc_mem_t *mctx, char **buffer, int *length);
00946 /*%<
00947  * Allocate 'buffer' and dump the key into it in base64 format. The buffer
00948  * is not NUL terminated. The length of the buffer is returned in *length.
00949  *
00950  * 'buffer' needs to be freed using isc_mem_put(mctx, buffer, length);
00951  *
00952  * Requires:
00953  *      'buffer' to be non NULL and *buffer to be NULL.
00954  *      'length' to be non NULL and *length to be zero.
00955  *
00956  * Returns:
00957  *      ISC_R_SUCCESS
00958  *      ISC_R_NOMEMORY
00959  *      ISC_R_NOTIMPLEMENTED
00960  *      others.
00961  */
00962 
00963 isc_result_t
00964 dst_key_restore(dns_name_t *name, unsigned int alg, unsigned int flags,
00965                 unsigned int protocol, dns_rdataclass_t rdclass,
00966                 isc_mem_t *mctx, const char *keystr, dst_key_t **keyp);
00967 
00968 isc_boolean_t
00969 dst_key_inactive(const dst_key_t *key);
00970 /*%<
00971  * Determines if the private key is missing due the key being deemed inactive.
00972  *
00973  * Requires:
00974  *      'key' to be valid.
00975  */
00976 
00977 void
00978 dst_key_setinactive(dst_key_t *key, isc_boolean_t inactive);
00979 /*%<
00980  * Set key inactive state.
00981  *
00982  * Requires:
00983  *      'key' to be valid.
00984  */
00985 
00986 void
00987 dst_key_setexternal(dst_key_t *key, isc_boolean_t value);
00988 
00989 isc_boolean_t
00990 dst_key_isexternal(dst_key_t *key);
00991 
00992 ISC_LANG_ENDDECLS
00993 
00994 #endif /* DST_DST_H */

Generated on Tue Apr 28 17:40:57 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha