NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
auth_cram.c File Reference

IMAP CRAM-MD5 authentication method. More...

#include "config.h"
#include <stdio.h>
#include <string.h>
#include "private.h"
#include "mutt/lib.h"
#include "conn/lib.h"
#include "adata.h"
#include "auth.h"
+ Include dependency graph for auth_cram.c:

Go to the source code of this file.

Macros

#define MD5_BLOCK_LEN   64
 
#define MD5_DIGEST_LEN   16
 

Functions

static void hmac_md5 (const char *password, const char *challenge, unsigned char *response)
 Produce CRAM-MD5 challenge response.
 
enum ImapAuthRes imap_auth_cram_md5 (struct ImapAccountData *adata, const char *method)
 Authenticate using CRAM-MD5 - Implements ImapAuth::authenticate() -.
 

Detailed Description

IMAP CRAM-MD5 authentication method.

Authors
  • Brendan Cully
  • Richard Russon
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file auth_cram.c.

Macro Definition Documentation

◆ MD5_BLOCK_LEN

#define MD5_BLOCK_LEN   64

Definition at line 40 of file auth_cram.c.

◆ MD5_DIGEST_LEN

#define MD5_DIGEST_LEN   16

Definition at line 41 of file auth_cram.c.

Function Documentation

◆ hmac_md5()

static void hmac_md5 ( const char *  password,
const char *  challenge,
unsigned char *  response 
)
static

Produce CRAM-MD5 challenge response.

Parameters
[in]passwordPassword to encrypt
[in]challengeChallenge from server
[out]responseBuffer for the response

Definition at line 49 of file auth_cram.c.

50{
51 struct Md5Ctx md5ctx = { 0 };
52 unsigned char ipad[MD5_BLOCK_LEN] = { 0 };
53 unsigned char opad[MD5_BLOCK_LEN] = { 0 };
54 unsigned char secret[MD5_BLOCK_LEN + 1] = { 0 };
55
56 size_t secret_len = strlen(password);
57
58 /* passwords longer than MD5_BLOCK_LEN bytes are substituted with their MD5
59 * digests */
60 if (secret_len > MD5_BLOCK_LEN)
61 {
62 unsigned char hash_passwd[MD5_DIGEST_LEN];
63 mutt_md5_bytes(password, secret_len, hash_passwd);
64 mutt_str_copy((char *) secret, (char *) hash_passwd, MD5_DIGEST_LEN);
65 secret_len = MD5_DIGEST_LEN;
66 }
67 else
68 {
69 mutt_str_copy((char *) secret, password, sizeof(secret));
70 }
71
72 memcpy(ipad, secret, secret_len);
73 memcpy(opad, secret, secret_len);
74
75 for (int i = 0; i < MD5_BLOCK_LEN; i++)
76 {
77 ipad[i] ^= 0x36;
78 opad[i] ^= 0x5c;
79 }
80
81 /* inner hash: challenge and ipadded secret */
82 mutt_md5_init_ctx(&md5ctx);
84 mutt_md5_process(challenge, &md5ctx);
85 mutt_md5_finish_ctx(&md5ctx, response);
86
87 /* outer hash: inner hash and opadded secret */
88 mutt_md5_init_ctx(&md5ctx);
90 mutt_md5_process_bytes(response, MD5_DIGEST_LEN, &md5ctx);
91 mutt_md5_finish_ctx(&md5ctx, response);
92}
#define MD5_BLOCK_LEN
Definition: auth_cram.c:40
#define MD5_DIGEST_LEN
Definition: auth_cram.c:41
void mutt_md5_process_bytes(const void *buf, size_t buflen, struct Md5Ctx *md5ctx)
Process a block of data.
Definition: md5.c:373
void * mutt_md5_bytes(const void *buffer, size_t len, void *resbuf)
Calculate the MD5 hash of a buffer.
Definition: md5.c:336
void mutt_md5_process(const char *str, struct Md5Ctx *md5ctx)
Process a NULL-terminated string.
Definition: md5.c:355
void mutt_md5_init_ctx(struct Md5Ctx *md5ctx)
Initialise the MD5 computation.
Definition: md5.c:261
void * mutt_md5_finish_ctx(struct Md5Ctx *md5ctx, void *resbuf)
Process the remaining bytes in the buffer.
Definition: md5.c:285
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:581
Cursor for the MD5 hashing.
Definition: md5.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function: