chap-new.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * chap-new.c - New CHAP implementation.
  3. *
  4. * Copyright (c) 2003 Paul Mackerras. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * 2. The name(s) of the authors of this software must not be used to
  14. * endorse or promote products derived from this software without
  15. * prior written permission.
  16. *
  17. * 3. Redistributions of any form whatsoever must retain the following
  18. * acknowledgment:
  19. * "This product includes software developed by Paul Mackerras
  20. * <paulus@samba.org>".
  21. *
  22. * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  23. * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  24. * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
  25. * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  26. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  27. * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  28. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  29. */
  30. /*
  31. * CHAP packets begin with a standard header with code, id, len (2 bytes).
  32. */
  33. #define CHAP_HDRLEN 4
  34. /*
  35. * Values for the code field.
  36. */
  37. #define CHAP_CHALLENGE 1
  38. #define CHAP_RESPONSE 2
  39. #define CHAP_SUCCESS 3
  40. #define CHAP_FAILURE 4
  41. /*
  42. * CHAP digest codes.
  43. */
  44. #define CHAP_MD5 5
  45. #define CHAP_MICROSOFT 0x80
  46. #define CHAP_MICROSOFT_V2 0x81
  47. /*
  48. * Semi-arbitrary limits on challenge and response fields.
  49. */
  50. #define MAX_CHALLENGE_LEN 64
  51. #define MAX_RESPONSE_LEN 64
  52. /* bitmask of supported algorithms */
  53. #define MDTYPE_MICROSOFT_V2 0x1
  54. #define MDTYPE_MICROSOFT 0x2
  55. #define MDTYPE_MD5 0x4
  56. #define MDTYPE_NONE 0
  57. /* hashes supported by this instance of pppd */
  58. extern int chap_mdtype_all;
  59. /* Return the digest alg. ID for the most preferred digest type. */
  60. #define CHAP_DIGEST(mdtype) \
  61. ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \
  62. ((mdtype) & MDTYPE_MICROSOFT_V2)? CHAP_MICROSOFT_V2: \
  63. ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \
  64. 0
  65. /* Return the bit flag (lsb set) for our most preferred digest type. */
  66. #define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype)
  67. /* Return the bit flag for a given digest algorithm ID. */
  68. #define CHAP_MDTYPE_D(digest) \
  69. ((digest) == CHAP_MICROSOFT_V2)? MDTYPE_MICROSOFT_V2: \
  70. ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \
  71. ((digest) == CHAP_MD5)? MDTYPE_MD5: \
  72. 0
  73. /* Can we do the requested digest? */
  74. #define CHAP_CANDIGEST(mdtype, digest) \
  75. ((digest) == CHAP_MICROSOFT_V2)? (mdtype) & MDTYPE_MICROSOFT_V2: \
  76. ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \
  77. ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \
  78. 0
  79. /*
  80. * The code for each digest type has to supply one of these.
  81. */
  82. struct chap_digest_type {
  83. int code;
  84. /*
  85. * Note: challenge and response arguments below are formatted as
  86. * a length byte followed by the actual challenge/response data.
  87. */
  88. void (*generate_challenge)(unsigned char *challenge);
  89. int (*verify_response)(int id, char *name,
  90. unsigned char *secret, int secret_len,
  91. unsigned char *challenge, unsigned char *response,
  92. char *message, int message_space);
  93. void (*make_response)(unsigned char *response, int id, char *our_name,
  94. unsigned char *challenge, char *secret, int secret_len,
  95. unsigned char *priv);
  96. int (*check_success)(int id, unsigned char *pkt, int len);
  97. void (*handle_failure)(unsigned char *pkt, int len);
  98. struct chap_digest_type *next;
  99. };
  100. /* Hook for a plugin to validate CHAP challenge */
  101. extern int (*chap_verify_hook)(char *name, char *ourname, int id,
  102. struct chap_digest_type *digest,
  103. unsigned char *challenge, unsigned char *response,
  104. char *message, int message_space);
  105. /* Called by digest code to register a digest type */
  106. extern void chap_register_digest(struct chap_digest_type *);
  107. /* Called by authentication code to start authenticating the peer. */
  108. extern void chap_auth_peer(int unit, char *our_name, int digest_code);
  109. /* Called by auth. code to start authenticating us to the peer. */
  110. extern void chap_auth_with_peer(int unit, char *our_name, int digest_code);
  111. /* Represents the CHAP protocol to the main pppd code */
  112. extern struct protent chap_protent;