summaryrefslogtreecommitdiff
path: root/daemon/digest.h
blob: de5dae3b8552018c897ddce2e6bbc3208ded44a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

#ifndef __DIGEST_H__
#define __DIGEST_H__

#include "md5.h"

#define DIGEST_NONCE_LEN sizeof(time_t) + sizeof(unsigned int) + MD5_LEN
#define DIGEST_SECRET_LEN 16

/* Parsed Digest response from the client */
typedef struct digest_header
{
  const char* scheme;
  const char* realm;
  const char* username;
  const char* nonce;
  const char* uri;
  const char* method;
  const char* digest;
  const char* algorithm;
  const char* cnonce;
  const char* opaque;
  const char* qop;
  const char* nc;
}
digest_header_t;

/* Kept by the server for validating the client */
typedef struct digest_record
{
  unsigned char nonce[DIGEST_NONCE_LEN];
  unsigned char userhash[MD5_LEN];
  unsigned char ha1[MD5_LEN];
  unsigned int nc;
}
digest_record_t;

digest_record_t* digest_makerec(unsigned char* nonce, const char* user);

int ha_digestparse(char* header, ha_buffer_t* buf, digest_header_t* rec,
                   unsigned char* nonce);

int ha_digestnonce(time_t* tm, unsigned char* nonce);

int digest_check(digest_header_t* dg, digest_record_t* rec, const ha_context_opts_t* opts,
                 ha_buffer_t* buf, const char* method, const char* uri);

const char* digest_respond(ha_buffer_t* buf, digest_header_t* dg,
                           digest_record_t* rec, unsigned char* next);

const char* digest_challenge(ha_buffer_t* buf, const char* nonce_str,
                             const char* realm, const char* domains, int stale);

void digest_makeha1(unsigned char* digest, const char* user,
                    const char* realm, const char* password);

#endif /* __DIGEST_H__ */