rpa.c
上传用户:xxcykj
上传日期:2007-01-04
资源大小:727k
文件大小:26k
- /***********************************************************************
- module: rpa.c
- program: fetchmail
- programmer: Michael J. Palmer <106177.1156@compuserve.com>
- date: 29 August 1997
- compiler: GCC 2.7.2
- environment: RedHat 4.0 Linux 2.0.18
- description: RPA authorisation code for POP3 client
- The sole entry point is POP3_auth_rpa()
- ***********************************************************************/
- #include "config.h"
- #if defined(POP3_ENABLE) && defined(RPA_ENABLE)
- #include <stdio.h>
- #include <unistd.h>
- #include <ctype.h>
- #include <string.h>
- #include "socket.h"
- #include "fetchmail.h"
- #include "md5.h"
- #include "i18n.h"
- #ifdef TESTMODE
- extern unsigned char line1[];
- extern unsigned char line2[];
- extern unsigned char line3[];
- extern int linecount;
- #endif
- #ifndef NO_PROTO
- /* prototypes for internal functions */
- static int POP3_rpa_resp(unsigned char* argbuf, int socket );
- static void LenAppend(unsigned char** pptr, int len);
- static int LenSkip(unsigned char** pptr, int rxlen);
- static int DecBase64(unsigned char* bufp);
- static void EncBase64(unsigned char* bufp, int len);
- static void ToUnicode(unsigned char** pptr, unsigned char delim,
- unsigned char* buf, int* plen, int conv);
- static int SetRealmService(unsigned char* bufp);
- static void GenChallenge(unsigned char* buf, int len);
- static int DigestPassphrase(unsigned char* passphrase,
- unsigned char* rbuf, int unicodeit);
- static void CompUserResp();
- static int CheckUserAuth();
- static void md5(unsigned char* in, int len, unsigned char* out);
- #endif
- /* RPA protocol definitions */
- #define EARLYVER "x01x00" /* Earliest supp version */
- #define LATEVER "x03x00" /* Latest supp version */
- #define HDR 0x60 /* ASN.1 SEQUENCE */
- #define MECH "x06x09x60x86x48x01x86xF8x73x01x01"
- #define FLAGS "x00x01" /* Mutual authentication */
- #define STRMAX 128 /* Bytes in Unicode */
- #define Tsl 14 /* Timestamp bytelen */
- #define Pul 16 /* Passphrase digest len */
- #define Cul 16 /* Usr challenge bytelen */
- #define Rul 16 /* Usr response bytelen */
- #define Aul 16 /* User auth bytelen */
- #define Kusl 16 /* Session key bytelen */
- #define UNIPASS 1 /* 1=Unicode 0=iso8859 */
- #define PS_RPA 42 /* Return code */
- /* RPA authentication items */
- unsigned char Cs[256]; /* Service challenge */
- int Csl; /* Length of " " */
- unsigned char Ts[Tsl+1]; /* Timestamp incl