summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2009-08-19 02:39:58 +0200
committerTor Andersson <tor@ghostscript.com>2009-08-19 02:39:58 +0200
commitac4f72884effe8c177f09d27bf4977c84eb3ec58 (patch)
tree5f0eafafab91d1dc07434f0a23b19399c6682818 /apps
parent1d2eb9d542b11e488dbd206c6ef9936b4f60fc13 (diff)
downloadmupdf-ac4f72884effe8c177f09d27bf4977c84eb3ec58.tar.xz
Implement support for AES encryption.
Diffstat (limited to 'apps')
-rw-r--r--apps/common/pdfapp.c14
-rw-r--r--apps/common/pdftool.c4
-rw-r--r--apps/mozilla/moz_main.c21
-rw-r--r--apps/pdfclean.c1
-rw-r--r--apps/pdfinfo.c2
-rw-r--r--apps/windows/winmain.c11
6 files changed, 27 insertions, 26 deletions
diff --git a/apps/common/pdfapp.c b/apps/common/pdfapp.c
index b24cec3d..bfe09546 100644
--- a/apps/common/pdfapp.c
+++ b/apps/common/pdfapp.c
@@ -91,23 +91,23 @@ void pdfapp_open(pdfapp_t *app, char *filename)
pdfapp_error(app, error);
}
- /*
- * Handle encrypted PDF files
- */
-
error = pdf_decryptxref(app->xref);
if (error)
pdfapp_error(app, error);
- if (app->xref->crypt)
+ /*
+ * Handle encrypted PDF files
+ */
+
+ if (pdf_needspassword(app->xref))
{
- int okay = pdf_setpassword(app->xref->crypt, password);
+ int okay = pdf_authenticatepassword(app->xref, password);
while (!okay)
{
password = winpassword(app, filename);
if (!password)
exit(1);
- okay = pdf_setpassword(app->xref->crypt, password);
+ okay = pdf_authenticatepassword(app->xref, password);
if (!okay)
pdfapp_warn(app, "Invalid password.");
}
diff --git a/apps/common/pdftool.c b/apps/common/pdftool.c
index 5de9e1b6..025dcd9b 100644
--- a/apps/common/pdftool.c
+++ b/apps/common/pdftool.c
@@ -50,9 +50,9 @@ void openxref(char *filename, char *password, int dieonbadpass)
if (error)
die(error);
- if (xref->crypt)
+ if (pdf_needspassword(xref))
{
- okay = pdf_setpassword(xref->crypt, password);
+ okay = pdf_authenticatepassword(xref, password);
if (!okay && !dieonbadpass)
fz_warn("invalid password, attempting to continue.");
else if (!okay && dieonbadpass)
diff --git a/apps/mozilla/moz_main.c b/apps/mozilla/moz_main.c
index 569d48a4..ba55ba90 100644
--- a/apps/mozilla/moz_main.c
+++ b/apps/mozilla/moz_main.c
@@ -72,8 +72,6 @@ void pdfmoz_open(pdfmoz_t *moz, char *filename)
SCROLLINFO si;
fz_error error;
fz_obj *obj;
- char *password = "";
- pdf_pagetree *pages;
fz_irect bbox;
int rot;
int i;
@@ -110,19 +108,24 @@ void pdfmoz_open(pdfmoz_t *moz, char *filename)
if (error)
pdfmoz_error(moz, error);
- if (moz->xref->crypt)
+ if (pdf_needspassword(moz->xref))
{
- int okay = pdf_setpassword(moz->xref->crypt, password);
- if (!okay)
- pdfmoz_warn(moz, "Invalid password.");
+ pdfmoz_warn(moz, "PDF file is encrypted and needs a password.");
}
- moz->pagecount = moz->xrex->pagecount;
+ error = pdf_getpagecount(moz->xref, &moz->pagecount);
+ if (error)
+ pdfmoz_error(moz, fz_throw("Cannot get page count."));
+
moz->pages = fz_malloc(sizeof(page_t) * moz->pagecount);
for (i = 0; i < moz->pagecount; i++)
{
- moz->pages[i].obj = fz_keepobj(pdf_getpageobject(pages, i));
+ fz_obj *pageobj;
+ error = pdf_getpageobject(moz->xref, i, &pageobj);
+ if (error)
+ pdfmoz_error(moz, fz_throw("cannot load page object"));
+ moz->pages[i].obj = fz_keepobj(pageobj);
moz->pages[i].page = nil;
moz->pages[i].image = nil;
@@ -144,8 +147,6 @@ void pdfmoz_open(pdfmoz_t *moz, char *filename)
moz->pages[i].px = 1 + PAD;
}
- pdf_droppagetree(pages);
-
/*
* Load meta information
* TODO: move this into mupdf library
diff --git a/apps/pdfclean.c b/apps/pdfclean.c
index 77da8f9b..7db29e0c 100644
--- a/apps/pdfclean.c
+++ b/apps/pdfclean.c
@@ -9,7 +9,6 @@
#include "pdftool.h"
-static pdf_crypt *outcrypt = NULL;
static FILE *out = NULL;
static char *uselist = NULL;
diff --git a/apps/pdfinfo.c b/apps/pdfinfo.c
index dcd65dc9..ab244ec3 100644
--- a/apps/pdfinfo.c
+++ b/apps/pdfinfo.c
@@ -199,7 +199,7 @@ gatherglobalinfo(void)
if (!fz_isdict(cryptinfo->ref) && !fz_isindirect(cryptinfo->ref))
die(fz_throw("not an indirect crypt object"));
- cryptinfo->u.crypt.obj = xref->crypt->encrypt;
+ // XXX cryptinfo->u.crypt.obj = xref->crypt->encrypt;
}
}
diff --git a/apps/windows/winmain.c b/apps/windows/winmain.c
index 657be9d4..f278b199 100644
--- a/apps/windows/winmain.c
+++ b/apps/windows/winmain.c
@@ -21,7 +21,7 @@ static LRESULT CALLBACK frameproc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK viewproc(HWND, UINT, WPARAM, LPARAM);
static int bmpstride = 0;
-static char *bmpdata = NULL;
+static unsigned char *bmpdata = NULL;
static int justcopied = 0;
static pdfapp_t gapp;
@@ -199,12 +199,13 @@ dloginfoproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
SetDlgItemTextA(hwnd, 0x10, gapp.filename);
- sprintf(buf, "PDF %g", xref->version);
+ sprintf(buf, "PDF %d.%d", xref->version / 10, xref->version % 10);
SetDlgItemTextA(hwnd, 0x11, buf);
if (xref->crypt)
{
- sprintf(buf, "Standard %d bit RC4", xref->crypt->len * 8);
+ sprintf(buf, "Standard %d bit %s", xref->crypt->length,
+ xref->crypt->strf.method == PDF_CRYPT_AESV2 ? "AES" : "RC4");
SetDlgItemTextA(hwnd, 0x12, buf);
strcpy(buf, "");
if (xref->crypt->p & (1 << 2))
@@ -423,8 +424,8 @@ void winconvert(pdfapp_t *app, fz_pixmap *image)
for (y = 0; y < image->h; y++)
{
- char *p = bmpdata + y * bmpstride;
- char *s = image->samples + y * image->w * 4;
+ unsigned char *p = bmpdata + y * bmpstride;
+ unsigned char *s = image->samples + y * image->w * 4;
for (x = 0; x < image->w; x++)
{
p[x * 3 + 0] = s[x * 4 + 3];