1 /* Copyright (c) 1990,1993 Regents of The University of Michigan.
2 * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
3 * All Rights Reserved. See COPYRIGHT.
16 #include <atalk/afp.h>
17 #include <atalk/uam.h>
21 #define CRYPTBUFLEN (KEYSIZE*2)
22 #define CRYPT2BUFLEN (KEYSIZE + PASSWDLEN)
24 /* hash a number to a 16-bit quantity */
25 #define pgphash(a) ((((unsigned long) (a) >> 8) ^ \
26 (unsigned long) (a)) & 0xffff)
29 static struct passwd *pgppwd;
33 static int pgp_login(void *obj, struct passwd **uam_pwd,
34 char *ibuf, int ibuflen,
35 char *rbuf, int *rbuflen)
37 BIGNUM *bn, *gbn, *pbn;
44 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME, (void *) &name, &i) < 0)
47 len = (unsigned char) *ibuf++;
49 return( AFPERR_PARAM );
52 memcpy(name, ibuf, len );
55 if ((unsigned long) ibuf & 1) /* padding */
58 if (( pgppwd = uam_getname(name, i)) == NULL ) {
62 syslog( LOG_INFO, "pgp login: %s", name);
63 if (uam_checkuser(pgppwd) < 0)
64 return AFPERR_NOTAUTH;
66 /* get the challenge */
67 len = (unsigned char) *ibuf++;
70 /* get the signature. it's always 16 bytes. */
71 if (uam_afpserver_option(obj, UAM_OPTION_SIGNATURE,
72 (void *) &name, NULL) < 0) {
76 memcpy(rbuf + KEYSIZE, name, KEYSIZE);
82 static int pgp_logincont(void *obj, struct passwd **uam_pwd,
83 char *ibuf, int ibuflen,
84 char *rbuf, int *rbuflen)
86 BIGNUM *bn1, *bn2, *bn3;
92 /* check for session id */
93 memcpy(&sessid, ibuf, sizeof(sessid));
94 if (sessid != pgphash(obj))
96 ibuf += sizeof(sessid);
98 /* use rbuf as scratch space */
99 CAST_cbc_encrypt(ibuf, rbuf, CRYPT2BUFLEN, &castkey,
102 /* check to make sure that the random number is the same. we
103 * get sent back an incremented random number. */
104 if (!(bn1 = BN_bin2bn(rbuf, KEYSIZE, NULL)))
107 if (!(bn2 = BN_bin2bn(randbuf, sizeof(randbuf), NULL))) {
112 /* zero out the random number */
113 memset(rbuf, 0, sizeof(randbuf));
114 memset(randbuf, 0, sizeof(randbuf));
117 if (!(bn3 = BN_new())) {
123 BN_sub(bn3, bn1, bn2);
127 /* okay. is it one more? */
128 if (!BN_is_one(bn3)) {
135 if ( kcheckuser(*uam_pwd, rbuf) == 0) {
141 rbuf[PASSWDLEN] = '\0';
142 p = crypt( rbuf, pgppwd->pw_passwd );
143 memset(rbuf, 0, PASSWDLEN);
144 if ( strcmp( p, pgppwd->pw_passwd ) == 0 ) {
149 return AFPERR_NOTAUTH;
153 static int uam_setup(const char *path)
155 if (uam_register(UAM_SERVER_LOGIN, path, "PGPuam 1.0",
156 pgp_login, pgp_logincont, NULL) < 0)
162 static void uam_cleanup(void)
164 uam_unregister(UAM_SERVER_LOGIN, "PGPuam 1.0");
167 UAM_MODULE_EXPORT struct uam_export uams_pgp = {
170 uam_setup, uam_cleanup