git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4 1/2] git-imap-send: Add CRAM-MD5 authenticate method support

From
HMHitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
Date
Feb 13, 2010, 06:49 UTC
Message-ID
<4B764B67.1020402@dcl.info.waseda.ac.jp>
In-Reply-To
<7vljeyp1rj.fsf@alter.siamese.dyndns.org>
On 2010年02月13日 06:44, Junio C Hamano wrote:
Show 44 quoted lines
> Hitoshi Mitake<mitake@dcl.info.waseda.ac.jp>  writes:
>
>> This patch makes git-imap-send CRAM-MD5 authenticate method ready.
>> In theory, CRAM-MD5 authenticate method doesn't depend on SSL.
>> But for easiness of maintainance, this patch uses base64 and md5 stuffs of OpenSSL.
>> So if you want to use CRAM-MD5 authenticate method,
>> you have to build git-imap-send with OpenSSL library.
>>
>> ---
>> v3: Erik noticed that there were some garbage lines in this patch.
>> I removed these. And 2/2 wasn't changed, I'm sending 1/2 only.
>>
>> v4: Based on Junio's indication, I cleaned up some points of imap-send.c .
>>
>> Cc: Erik Faye-Lund<kusmabite@googlemail.com>
>> Cc: Jakub Narebski<jnareb@gmail.com>
>> Cc: Linus Torvalds<torvalds@linux-foundation.org>
>> Cc: Jeff King<peff@peff.net>
>> Signed-off-by: Hitoshi Mitake<mitake@dcl.info.waseda.ac.jp>
>> ---
>
> I actually meant that the comment regarding the history of patch
> iterations should go after the three-dash.  Most notably, we want your
> S-o-b in the commit log.  That is:
>
> ----------------------------------------------------------------
> 	Subject: well thought out summary of what the patch is about
>
> 	Problem description, and rationale to justify the particular
>          solution you chose.
>
>          Signed-off-by: Your Name<your@address.example.com>
> 	---
>
> 	 Comments that may help the reviewers while the patch is
>           going through the review cycle, but would not be useful
>           after this particular version is applied and the commit
>           is shown in "git log" output
>
> 	 diffstat
>
>           diff --git ... patch text ...
> ----------------------------------------------------------------
>

I didn't know that Git has such a convenient feature. I'll move version specific comments to below of three-dash line.

Show 11 quoted lines
>> +
>> +	/* challenge must be shorter than challenge_64
>> +	 * because we are decoding base64*/
>
> Just a style thing but
>
> 	/*
>           * We prefer to write our multi-line
>           * comments like this.
>           */
>
OK, I'll modify this comment.
>> +	challenge = xcalloc(strlen(challenge_64) + 1, sizeof(char));
>
> Why not xmalloc()?  Does EVP_DecodeBlock() want a zero-filled buffer?
>

Because strlen(challenge_64) is the upper limit of length of challenge. So tail part of challenge may not be filled by EVP_DecodeBlock(), non-zero filled buffer produces not NULL terminated string. I've confused once by this problem before.

Show 6 quoted lines
>> +	EVP_DecodeBlock((unsigned char *)challenge, (unsigned char *)challenge_64, strlen(challenge_64));
>
> Does EVP_DecodeBlock diagnose an error in the input and return an error
> code?  How are you supposed to protect yourself from the server giving you
> a corrupt challenge that does not decode properly?
>

I've forgot processing return value from EVP_DecodeBlock(). I'll fix it.

Show 5 quoted lines
>> +	HMAC_Init(&hmac, (unsigned char *)pass, strlen(pass), EVP_md5());
>> +	HMAC_Update(&hmac, (unsigned char *)challenge, strlen(challenge));
>> +	HMAC_Final(&hmac, hash, NULL);
>
> Is there any clean-up necessary after you are done with hmac?
I've forgot calling HMAC_CTX_cleanup().
> EVP_md5()
> returns a pointer to EVP_MD but how and when is that resource released?
prototype of EVP_md5() is
     const EVP_MD *EVP_md5(void);
EVP_md5() only returns const value. There is no new resource allocation.
e.g. EVP_md() == EVP_md() is true.
Show 5 quoted lines
>
> By the way, HMAC_Init() seems to be deprecated and kept only for 0.9.6b
> compatibility.
>
>      http://www.openssl.org/docs/crypto/hmac.html

The document of OpenSSL doesn't describe HMAC_init_ex() well. I can't know that what the parameter ENGINE *impl means... So I'd like to use HMAC_Init(), if it is for compatibility.

Show 16 quoted lines
>
>> +	hex[32] = 0;
>> +	for (i = 0; i<  16; i++) {
>> +		hex[2 * i] = hexchar((hash[i]>>  4)&  0xf);
>> +		hex[2 * i + 1] = hexchar(hash[i]&  0xf);
>> +	}
>> +
>> +	/* length: "<user>  <digest in hex>" */
>> +	resp_len = strlen(user) + 1 + strlen(hex) + 1;
>> +	response = xcalloc(resp_len, sizeof(char));
>> +	snprintf(response, resp_len, "%s %s", user, hex);
>> +
>> +	response_64 = xcalloc(ENCODED_SIZE(resp_len), sizeof(char));
>
> Why not xmalloc()?  Does EVP_EncodeBlock() want a zero-filled buffer?
>

The reason using xcalloc() here is like one of above. ENCODED_SIZE() calculates upper limit of encoded size.

>> +	EVP_EncodeBlock((unsigned char *)response_64, (unsigned char *)response, strlen(response));
>
> I wouldn't worry too much about error response from this function as I
> would for EVP_DecodeBlock() I mentioned earlier.
I'll modify it, too.
>
> By the way, I made a couple of small fix-ups to your [2/2] (I think they
> were just style and unnecessary use of xcalloc()) and queued.

Thanks. Where can I find them? # But as I mentioned above, use of xcalloc() is necessary.

And again, thanks for your very detailed review!
Previous: Junio C HamanoNext: Hitoshi Mitake
Message 25 of 49 in “imap.preformattedHTML and imap.sslverify”
  1. Junio C HamanoFeb 6, 2010
  2. Jeremy WhiteFeb 8, 2010
  3. Junio C HamanoFeb 8, 2010
  4. 0/4 Some improvements for git-imap-sendHitoshi Mitake, Feb 9, 2010
  5. Jeff KingFeb 9, 2010
  6. Erik Faye-LundFeb 9, 2010
  7. Jeff KingFeb 9, 2010
  8. Erik Faye-LundFeb 9, 2010
  9. Jeff KingFeb 9, 2010
  10. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 11, 2010
  11. Erik Faye-LundFeb 11, 2010
  12. Hitoshi MitakeFeb 11, 2010
  13. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 11, 2010
  14. Junio C HamanoFeb 11, 2010
  15. Hitoshi MitakeFeb 12, 2010
  16. 2/2 git-imap-send: Convert LF to CRLF before storing patch to draft boxHitoshi Mitake, Feb 11, 2010
  17. Junio C HamanoFeb 11, 2010
  18. Hitoshi MitakeFeb 12, 2010
  19. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 11, 2010
  20. 2/2 git-imap-send: Convert LF to CRLF before storing patch to draft boxHitoshi Mitake, Feb 11, 2010
  21. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 12, 2010
  22. Erik Faye-LundFeb 12, 2010
  23. Hitoshi MitakeFeb 13, 2010
  24. Junio C HamanoFeb 12, 2010
  25. Hitoshi MitakeFeb 13, 2010
  26. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 13, 2010
  27. Junio C HamanoFeb 13, 2010
  28. Junio C HamanoFeb 16, 2010
  29. Hitoshi MitakeFeb 17, 2010
  30. 1/2 git-imap-send: Add CRAM-MD5 authenticate method supportHitoshi Mitake, Feb 17, 2010
  31. Junio C HamanoFeb 17, 2010
  32. Hitoshi MitakeFeb 18, 2010
  33. Hitoshi MitakeFeb 17, 2010
  34. 2/2 git-imap-send: Convert LF to CRLF before storing patch to draft boxHitoshi Mitake, Feb 12, 2010
  35. 1/4 Add base64 encoder and decoderHitoshi Mitake, Feb 9, 2010
  36. Erik Faye-LundFeb 9, 2010
  37. Hitoshi MitakeFeb 11, 2010
  38. 2/4 Add stuffs for MD5 hash algorithmHitoshi Mitake, Feb 9, 2010
  39. 3/4 git-imap-send: Implement CRAM-MD5 auth methodHitoshi Mitake, Feb 9, 2010
  40. Erik Faye-LundFeb 9, 2010
  41. Hitoshi MitakeFeb 11, 2010
  42. Erik Faye-LundFeb 11, 2010
  43. Hitoshi MitakeFeb 11, 2010
  44. 4/4 git-imap-send: Add method to convert from LF to CRLFHitoshi Mitake, Feb 9, 2010
  45. Jakub NarebskiFeb 9, 2010
  46. Hitoshi MitakeFeb 11, 2010
  47. Linus TorvaldsFeb 9, 2010
  48. Junio C HamanoFeb 9, 2010
  49. Hitoshi MitakeFeb 11, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.