~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to lib/rfc2617.c

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The source in this file is derived from the reference implementation 
2
 
 * in RFC 2617. 
 
1
/* The source in this file is derived from the reference implementation
 
2
 * in RFC 2617.
3
3
 * RFC 2617 is Copyright (C) The Internet Society (1999).  All Rights Reserved.
4
4
 *
5
 
 * The following copyright and licence statement covers all changes made to the 
 
5
 * The following copyright and licence statement covers all changes made to the
6
6
 * reference implementation.
7
 
 * 
 
7
 *
8
8
 * Key changes were: alteration to a plain C layout.
9
9
 * Create CvtBin function
10
10
 * Allow CalcHA1 to make use of precaculated username:password:realm hash's
13
13
 
14
14
 
15
15
/*
16
 
 * $Id: rfc2617.c,v 1.12.2.1 2008/02/25 03:38:11 amosjeffries Exp $
 
16
 * $Id$
17
17
 *
18
18
 * DEBUG:
19
19
 * AUTHOR: RFC 2617 & Robert Collins
58
58
    unsigned char j;
59
59
 
60
60
    for (i = 0; i < HASHLEN; i++) {
61
 
        j = (Bin[i] >> 4) & 0xf;
62
 
        if (j <= 9)
63
 
            Hex[i * 2] = (j + '0');
64
 
        else
65
 
            Hex[i * 2] = (j + 'a' - 10);
66
 
        j = Bin[i] & 0xf;
67
 
        if (j <= 9)
68
 
            Hex[i * 2 + 1] = (j + '0');
69
 
        else
70
 
            Hex[i * 2 + 1] = (j + 'a' - 10);
 
61
        j = (Bin[i] >> 4) & 0xf;
 
62
        if (j <= 9)
 
63
            Hex[i * 2] = (j + '0');
 
64
        else
 
65
            Hex[i * 2] = (j + 'a' - 10);
 
66
        j = Bin[i] & 0xf;
 
67
        if (j <= 9)
 
68
            Hex[i * 2 + 1] = (j + '0');
 
69
        else
 
70
            Hex[i * 2 + 1] = (j + 'a' - 10);
71
71
    }
72
72
    Hex[HASHHEXLEN] = '\0';
73
73
}
79
79
    unsigned char j;
80
80
 
81
81
    for (i = 0; i < HASHHEXLEN; i++) {
82
 
        unsigned char n;
83
 
        j = Hex[i];
84
 
        if (('0' <= j) && (j <= '9'))
85
 
            n = j - '0';
86
 
        else if (('a' <= j) && (j <= 'f'))
87
 
            n = j - 'a' + 10;
88
 
        else if (('A' <= j) && (j <= 'F'))
89
 
            n = j - 'A' + 10;
90
 
        else
91
 
            continue;
92
 
        if (i % 2 == 0)
93
 
            Bin[i / 2] = n << 4;
94
 
        else
95
 
            Bin[i / 2] |= n;
 
82
        unsigned char n;
 
83
        j = Hex[i];
 
84
        if (('0' <= j) && (j <= '9'))
 
85
            n = j - '0';
 
86
        else if (('a' <= j) && (j <= 'f'))
 
87
            n = j - 'a' + 10;
 
88
        else if (('A' <= j) && (j <= 'F'))
 
89
            n = j - 'A' + 10;
 
90
        else
 
91
            continue;
 
92
        if (i % 2 == 0)
 
93
            Bin[i / 2] = n << 4;
 
94
        else
 
95
            Bin[i / 2] |= n;
96
96
    }
97
 
/* FIXME: Coverity detects the below as dead code.
98
 
  Why? :: right here i == 32 
99
 
    which means the first step of the for loop makes i==16
100
 
    and cannot be < HASHLEN (which is also 16)
101
 
*/
 
97
    /* FIXME: Coverity detects the below as dead code.
 
98
      Why? :: right here i == 32
 
99
        which means the first step of the for loop makes i==16
 
100
        and cannot be < HASHLEN (which is also 16)
 
101
    */
102
102
    for (i = i / 2; i < HASHLEN; i++) {
103
 
        Bin[i] = '\0';
 
103
        Bin[i] = '\0';
104
104
    }
105
105
}
106
106
 
121
121
    SquidMD5_CTX Md5Ctx;
122
122
 
123
123
    if (pszUserName) {
124
 
        SquidMD5Init(&Md5Ctx);
125
 
        SquidMD5Update(&Md5Ctx, pszUserName, strlen(pszUserName));
126
 
        SquidMD5Update(&Md5Ctx, ":", 1);
127
 
        SquidMD5Update(&Md5Ctx, pszRealm, strlen(pszRealm));
128
 
        SquidMD5Update(&Md5Ctx, ":", 1);
129
 
        SquidMD5Update(&Md5Ctx, pszPassword, strlen(pszPassword));
130
 
        SquidMD5Final((unsigned char *) HA1, &Md5Ctx);
 
124
        SquidMD5Init(&Md5Ctx);
 
125
        SquidMD5Update(&Md5Ctx, pszUserName, strlen(pszUserName));
 
126
        SquidMD5Update(&Md5Ctx, ":", 1);
 
127
        SquidMD5Update(&Md5Ctx, pszRealm, strlen(pszRealm));
 
128
        SquidMD5Update(&Md5Ctx, ":", 1);
 
129
        SquidMD5Update(&Md5Ctx, pszPassword, strlen(pszPassword));
 
130
        SquidMD5Final((unsigned char *) HA1, &Md5Ctx);
131
131
    }
132
132
    if (strcasecmp(pszAlg, "md5-sess") == 0) {
133
 
        HASHHEX HA1Hex;
134
 
        CvtHex(HA1, HA1Hex);    /* RFC2617 errata */
135
 
        SquidMD5Init(&Md5Ctx);
136
 
        SquidMD5Update(&Md5Ctx, HA1Hex, HASHHEXLEN);
137
 
        SquidMD5Update(&Md5Ctx, ":", 1);
138
 
        SquidMD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
139
 
        SquidMD5Update(&Md5Ctx, ":", 1);
140
 
        SquidMD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
141
 
        SquidMD5Final((unsigned char *) HA1, &Md5Ctx);
 
133
        HASHHEX HA1Hex;
 
134
        CvtHex(HA1, HA1Hex);    /* RFC2617 errata */
 
135
        SquidMD5Init(&Md5Ctx);
 
136
        SquidMD5Update(&Md5Ctx, HA1Hex, HASHHEXLEN);
 
137
        SquidMD5Update(&Md5Ctx, ":", 1);
 
138
        SquidMD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
 
139
        SquidMD5Update(&Md5Ctx, ":", 1);
 
140
        SquidMD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
 
141
        SquidMD5Final((unsigned char *) HA1, &Md5Ctx);
142
142
    }
143
143
    CvtHex(HA1, SessionKey);
144
144
}
168
168
    SquidMD5Update(&Md5Ctx, pszMethod, strlen(pszMethod));
169
169
    SquidMD5Update(&Md5Ctx, ":", 1);
170
170
    SquidMD5Update(&Md5Ctx, pszDigestUri, strlen(pszDigestUri));
171
 
    if (strcasecmp(pszQop, "auth-int") == 0) {
172
 
        SquidMD5Update(&Md5Ctx, ":", 1);
173
 
        SquidMD5Update(&Md5Ctx, HEntity, HASHHEXLEN);
 
171
    if (pszQop && strcasecmp(pszQop, "auth-int") == 0) {
 
172
        SquidMD5Update(&Md5Ctx, ":", 1);
 
173
        SquidMD5Update(&Md5Ctx, HEntity, HASHHEXLEN);
174
174
    }
175
175
    SquidMD5Final((unsigned char *) HA2, &Md5Ctx);
176
176
    CvtHex(HA2, HA2Hex);
182
182
    SquidMD5Update(&Md5Ctx, ":", 1);
183
183
    SquidMD5Update(&Md5Ctx, pszNonce, strlen(pszNonce));
184
184
    SquidMD5Update(&Md5Ctx, ":", 1);
185
 
    if (*pszQop) {
186
 
        SquidMD5Update(&Md5Ctx, pszNonceCount, strlen(pszNonceCount));
187
 
        SquidMD5Update(&Md5Ctx, ":", 1);
188
 
        SquidMD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
189
 
        SquidMD5Update(&Md5Ctx, ":", 1);
190
 
        SquidMD5Update(&Md5Ctx, pszQop, strlen(pszQop));
191
 
        SquidMD5Update(&Md5Ctx, ":", 1);
 
185
    if (pszQop) {
 
186
        SquidMD5Update(&Md5Ctx, pszNonceCount, strlen(pszNonceCount));
 
187
        SquidMD5Update(&Md5Ctx, ":", 1);
 
188
        SquidMD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
 
189
        SquidMD5Update(&Md5Ctx, ":", 1);
 
190
        SquidMD5Update(&Md5Ctx, pszQop, strlen(pszQop));
 
191
        SquidMD5Update(&Md5Ctx, ":", 1);
192
192
    }
193
193
    SquidMD5Update(&Md5Ctx, HA2Hex, HASHHEXLEN);
194
194
    SquidMD5Final((unsigned char *) RespHash, &Md5Ctx);