| 877 | |
| 878 | #define ENCODED_SIZE(n) (4 * DIV_ROUND_UP((n), 3)) |
| 879 | static char *plain_base64(const char *user, const char *pass) |
| 880 | { |
| 881 | struct strbuf raw = STRBUF_INIT; |
| 882 | int b64_len; |
| 883 | char *b64; |
| 884 | |
| 885 | /* |
| 886 | * Compose the PLAIN string |
| 887 | * |
| 888 | * The username and password are combined to one string and base64 encoded. |
| 889 | * "\0user\0pass" |
| 890 | * |
| 891 | * The method has been described in RFC4616. |
| 892 | * |
| 893 | * https://datatracker.ietf.org/doc/html/rfc4616 |
| 894 | */ |
| 895 | strbuf_addch(&raw, '\0'); |
| 896 | strbuf_addstr(&raw, user); |
| 897 | strbuf_addch(&raw, '\0'); |
| 898 | strbuf_addstr(&raw, pass); |
| 899 | |
| 900 | b64 = xmallocz(ENCODED_SIZE(raw.len)); |
| 901 | b64_len = EVP_EncodeBlock((unsigned char *)b64, (unsigned char *)raw.buf, raw.len); |
| 902 | strbuf_release(&raw); |
| 903 | |
| 904 | if (b64_len < 0) { |
| 905 | free(b64); |
| 906 | return NULL; |
| 907 | } |
| 908 | return b64; |
| 909 | } |
| 910 | |
| 911 | static char *cram(const char *challenge_64, const char *user, const char *pass) |
| 912 | { |
no test coverage detected