Ticket #538: bug538-workaround.patch

File bug538-workaround.patch, 7.8 KB (added by n, 7 years ago)

Working workaround

  • src/openvpn/console.h

    old new query_user_SINGLE(char *prompt, size_t p 
    117117    return query_user_exec();
    118118}
    119119
     120/**
     121 * A plain "make Gert happy" wrapper over built-in user querying method.
     122 * Same arguments as @query_user_add
     123 *
     124 * Allows to use built-in method for PKCS11 PIN prompt regardless of
     125 * the systemd support status and presence,
     126 * see https://community.openvpn.net/openvpn/ticket/538 for details.
     127*/
     128static inline bool
     129query_user_builtin_SINGLE(char *prompt, size_t prompt_len,
     130                  char *resp, size_t resp_len,
     131                  bool echo)
     132{
     133    query_user_clear();
     134    query_user_add(prompt, prompt_len, resp, resp_len, echo);
     135    return query_user_exec_builtin();
     136}
     137
    120138#endif /* ifndef CONSOLE_H */
  • src/openvpn/pkcs11.c

    old new _pkcs11_openvpn_pin_prompt( 
    249249            &token_pass,
    250250            NULL,
    251251            prompt,
    252             GET_USER_PASS_MANAGEMENT|GET_USER_PASS_PASSWORD_ONLY|GET_USER_PASS_NOFATAL
     252            GET_USER_PASS_MANAGEMENT|GET_USER_PASS_PASSWORD_ONLY|GET_USER_PASS_NOFATAL|GET_USER_PASS_FORCE_BUILTIN
    253253            )
    254254        )
    255255    {
    _pkcs11_openvpn_show_pkcs11_ids_pin_prom 
    795795    ASSERT(token!=NULL);
    796796
    797797    buf_printf(&pass_prompt, "Please enter '%s' token PIN or 'cancel': ", token->display);
    798     if (!query_user_SINGLE(BSTR(&pass_prompt), BLEN(&pass_prompt),
     798    if (!query_user_builtin_SINGLE(BSTR(&pass_prompt), BLEN(&pass_prompt),
    799799                           pin, pin_max, false))
    800800    {
    801801        msg(M_FATAL, "Could not retrieve the PIN");
  • src/openvpn/misc.c

    old new get_user_pass_cr(struct user_pass *up, 
    11541154            struct buffer user_prompt = alloc_buf_gc(128, &gc);
    11551155
    11561156            buf_printf(&user_prompt, "NEED-OK|%s|%s:", prefix, up->username);
    1157             if (!query_user_SINGLE(BSTR(&user_prompt), BLEN(&user_prompt),
    1158                                    up->password, USER_PASS_LEN, false))
    1159             {
    1160                 msg(M_FATAL, "ERROR: could not read %s ok-confirmation from stdin", prefix);
     1157            if (flags & GET_USER_PASS_FORCE_BUILTIN) {
     1158                if (!query_user_builtin_SINGLE(BSTR(&user_prompt), BLEN(&user_prompt),
     1159                                       up->password, USER_PASS_LEN, false))
     1160                {
     1161                    msg(M_FATAL, "ERROR: could not read %s ok-confirmation from stdin", prefix);
     1162                }
     1163            }
     1164            else {
     1165                if (!query_user_SINGLE(BSTR(&user_prompt), BLEN(&user_prompt),
     1166                                       up->password, USER_PASS_LEN, false))
     1167                {
     1168                    msg(M_FATAL, "ERROR: could not read %s ok-confirmation from stdin", prefix);
     1169                }
    11611170            }
    11621171
    11631172            if (!strlen(up->password))
    get_user_pass_cr(struct user_pass *up, 
    12541263                    buf_printf(&challenge, "CHALLENGE: %s", ac->challenge_text);
    12551264                    buf_set_write(&packed_resp, (uint8_t *)up->password, USER_PASS_LEN);
    12561265
    1257                     if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challenge),
    1258                                            response, USER_PASS_LEN, BOOL_CAST(ac->flags&CR_ECHO)))
    1259                     {
    1260                         msg(M_FATAL, "ERROR: could not read challenge response from stdin");
     1266                    if (flags & GET_USER_PASS_FORCE_BUILTIN) {
     1267                        if (!query_user_builtin_SINGLE(BSTR(&challenge), BLEN(&challenge),
     1268                                               response, USER_PASS_LEN, BOOL_CAST(ac->flags&CR_ECHO)))
     1269                        {
     1270                            msg(M_FATAL, "ERROR: could not read challenge response from stdin");
     1271                        }
     1272                    }
     1273                    else {
     1274                        if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challenge),
     1275                                               response, USER_PASS_LEN, BOOL_CAST(ac->flags&CR_ECHO)))
     1276                        {
     1277                            msg(M_FATAL, "ERROR: could not read challenge response from stdin");
     1278                        }
    12611279                    }
    12621280                    strncpynt(up->username, ac->user, USER_PASS_LEN);
    12631281                    buf_printf(&packed_resp, "CRV1::%s::%s", ac->state_id, response);
    get_user_pass_cr(struct user_pass *up, 
    12891307                                   up->password, USER_PASS_LEN, false);
    12901308                }
    12911309
    1292                 if (!query_user_exec() )
    1293                 {
    1294                     msg(M_FATAL, "ERROR: Failed retrieving username or password");
     1310                if (flags & GET_USER_PASS_FORCE_BUILTIN) {
     1311                    if (!query_user_exec_builtin() )
     1312                    {
     1313                        msg(M_FATAL, "ERROR: Failed retrieving username or password");
     1314                    }
     1315                }
     1316                else {
     1317                    if (!query_user_exec() )
     1318                    {
     1319                        msg(M_FATAL, "ERROR: Failed retrieving username or password");
     1320                    }
    12951321                }
    12961322
    12971323                if (!(flags & GET_USER_PASS_PASSWORD_ONLY))
    get_user_pass_cr(struct user_pass *up, 
    13121338                    challenge = alloc_buf_gc(14+strlen(auth_challenge), &gc);
    13131339                    buf_printf(&challenge, "CHALLENGE: %s", auth_challenge);
    13141340
    1315                     if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challenge),
    1316                                            response, USER_PASS_LEN,
    1317                                            BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALLENGE_ECHO)))
    1318                     {
    1319                         msg(M_FATAL, "ERROR: could not retrieve static challenge response");
     1341                    if (flags & GET_USER_PASS_FORCE_BUILTIN) {
     1342                        if (!query_user_builtin_SINGLE(BSTR(&challenge), BLEN(&challenge),
     1343                                               response, USER_PASS_LEN,
     1344                                               BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALLENGE_ECHO)))
     1345                        {
     1346                            msg(M_FATAL, "ERROR: could not retrieve static challenge response");
     1347                        }
     1348                    }
     1349                    else {
     1350                        if (!query_user_SINGLE(BSTR(&challenge), BLEN(&challenge),
     1351                                               response, USER_PASS_LEN,
     1352                                               BOOL_CAST(flags & GET_USER_PASS_STATIC_CHALLENGE_ECHO)))
     1353                        {
     1354                            msg(M_FATAL, "ERROR: could not retrieve static challenge response");
     1355                        }
    13201356                    }
    13211357                    if (openvpn_base64_encode(up->password, strlen(up->password), &pw64) == -1
    13221358                        || openvpn_base64_encode(response, strlen(response), &resp64) == -1)
  • src/openvpn/misc.h

    old new struct static_challenge_info {}; 
    265265
    266266#define GET_USER_PASS_INLINE_CREDS (1<<10)  /* indicates that auth_file is actually inline creds */
    267267
     268#define GET_USER_PASS_FORCE_BUILTIN (1<<11) /* force builtin prompt to work around 538 */
     269
    268270bool get_user_pass_cr(struct user_pass *up,
    269271                      const char *auth_file,
    270272                      const char *prefix,