diff options
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-crypt.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/source/pdf/pdf-crypt.c b/source/pdf/pdf-crypt.c index 1499e39e..aad7324e 100644 --- a/source/pdf/pdf-crypt.c +++ b/source/pdf/pdf-crypt.c @@ -759,25 +759,34 @@ int pdf_authenticate_password(fz_context *ctx, pdf_document *doc, const char *pwd_utf8) { char password[2048]; + int auth; - if (doc->crypt) + if (!doc->crypt) + return 1; /* No password required */ + + password[0] = 0; + if (pwd_utf8) { - password[0] = 0; - if (pwd_utf8) - { - if (doc->crypt->r <= 4) - pdf_docenc_from_utf8(password, pwd_utf8, sizeof password); - else - pdf_saslprep_from_utf8(password, pwd_utf8, sizeof password); - } + if (doc->crypt->r <= 4) + pdf_docenc_from_utf8(password, pwd_utf8, sizeof password); + else + pdf_saslprep_from_utf8(password, pwd_utf8, sizeof password); + } - if (pdf_authenticate_user_password(ctx, doc->crypt, (unsigned char *)password, strlen(password))) - return 1; - if (pdf_authenticate_owner_password(ctx, doc->crypt, (unsigned char *)password, strlen(password))) - return 1; - return 0; + auth = 0; + if (pdf_authenticate_user_password(ctx, doc->crypt, (unsigned char *)password, strlen(password))) + auth = 2; + if (pdf_authenticate_owner_password(ctx, doc->crypt, (unsigned char *)password, strlen(password))) + auth |= 4; + else if (auth & 2) + { + /* We need to reauthenticate the user password, + * because the failed attempt to authenticate + * the owner password will have invalidated the + * stored keys. */ + (void)pdf_authenticate_user_password(ctx, doc->crypt, (unsigned char *)password, strlen(password)); } - return 1; + return auth; } int |