* external/libhpdf/Makefile
+ Enabled for all dos platforms (dos/watcom currently and
probably all dos builds done on MS-DOS hosts).
+ external/libhpdf/ori_dst
+ external/libhpdf/ori_src
+ external/libhpdf/cnv_hb2o.bat
+ external/libhpdf/cnv_o2hb.bat
- external/libhpdf/hpdf_annotation.c
- external/libhpdf/hpdf_annotation.h
- external/libhpdf/hpdf_array.c
- external/libhpdf/hpdf_binary.c
- external/libhpdf/hpdf_boolean.c
- external/libhpdf/hpdf_catalog.c
- external/libhpdf/hpdf_catalog.h
- external/libhpdf/hpdf_conf.h
- external/libhpdf/hpdf_config.h
- external/libhpdf/hpdf_consts.h
- external/libhpdf/hpdf_destination.c
- external/libhpdf/hpdf_destination.h
- external/libhpdf/hpdf_dict.c
- external/libhpdf/hpdf_doc.c
- external/libhpdf/hpdf_doc.h
- external/libhpdf/hpdf_doc_png.c
- external/libhpdf/hpdf_encoder.c
- external/libhpdf/hpdf_encoder.h
- external/libhpdf/hpdf_encoder_cns.c
- external/libhpdf/hpdf_encoder_cnt.c
- external/libhpdf/hpdf_encoder_jp.c
- external/libhpdf/hpdf_encoder_kr.c
- external/libhpdf/hpdf_encrypt.c
- external/libhpdf/hpdf_encrypt.h
- external/libhpdf/hpdf_encryptdict.c
- external/libhpdf/hpdf_encryptdict.h
- external/libhpdf/hpdf_error.c
- external/libhpdf/hpdf_error.h
- external/libhpdf/hpdf_ext_gstate.c
- external/libhpdf/hpdf_ext_gstate.h
- external/libhpdf/hpdf_font.c
- external/libhpdf/hpdf_font.h
- external/libhpdf/hpdf_font_cid.c
- external/libhpdf/hpdf_font_tt.c
- external/libhpdf/hpdf_font_type1.c
- external/libhpdf/hpdf_fontdef.c
- external/libhpdf/hpdf_fontdef.h
- external/libhpdf/hpdf_fontdef_base14.c
- external/libhpdf/hpdf_fontdef_cid.c
- external/libhpdf/hpdf_fontdef_cns.c
- external/libhpdf/hpdf_fontdef_cnt.c
- external/libhpdf/hpdf_fontdef_jp.c
- external/libhpdf/hpdf_fontdef_kr.c
- external/libhpdf/hpdf_fontdef_tt.c
- external/libhpdf/hpdf_fontdef_type1.c
- external/libhpdf/hpdf_gstate.c
- external/libhpdf/hpdf_gstate.h
- external/libhpdf/hpdf_image.c
- external/libhpdf/hpdf_image.h
- external/libhpdf/hpdf_image_png.c
- external/libhpdf/hpdf_info.c
- external/libhpdf/hpdf_info.h
- external/libhpdf/hpdf_list.c
- external/libhpdf/hpdf_list.h
- external/libhpdf/hpdf_mmgr.c
- external/libhpdf/hpdf_mmgr.h
- external/libhpdf/hpdf_name.c
- external/libhpdf/hpdf_null.c
- external/libhpdf/hpdf_number.c
- external/libhpdf/hpdf_objects.c
- external/libhpdf/hpdf_objects.h
- external/libhpdf/hpdf_outline.c
- external/libhpdf/hpdf_outline.h
- external/libhpdf/hpdf_page_label.c
- external/libhpdf/hpdf_page_label.h
- external/libhpdf/hpdf_page_operator.c
- external/libhpdf/hpdf_pages.c
- external/libhpdf/hpdf_pages.h
- external/libhpdf/hpdf_real.c
- external/libhpdf/hpdf_streams.c
- external/libhpdf/hpdf_streams.h
- external/libhpdf/hpdf_string.c
- external/libhpdf/hpdf_types.h
- external/libhpdf/hpdf_u3d.c
- external/libhpdf/hpdf_u3d.h
- external/libhpdf/hpdf_utils.c
- external/libhpdf/hpdf_utils.h
- external/libhpdf/hpdf_version.h
- external/libhpdf/hpdf_xref.c
+ external/libhpdf/hpdfanno.c
+ external/libhpdf/hpdfanno.h
+ external/libhpdf/hpdfarra.c
+ external/libhpdf/hpdfbina.c
+ external/libhpdf/hpdfbool.c
+ external/libhpdf/hpdfcata.c
+ external/libhpdf/hpdfcata.h
+ external/libhpdf/hpdfcfg.h
+ external/libhpdf/hpdfconf.h
+ external/libhpdf/hpdfcons.h
+ external/libhpdf/hpdfdest.c
+ external/libhpdf/hpdfdest.h
+ external/libhpdf/hpdfdict.c
+ external/libhpdf/hpdfdoc.c
+ external/libhpdf/hpdfdoc.h
+ external/libhpdf/hpdfdocp.c
+ external/libhpdf/hpdfecy.c
+ external/libhpdf/hpdfecyd.c
+ external/libhpdf/hpdfencc.c
+ external/libhpdf/hpdfencj.c
+ external/libhpdf/hpdfenck.c
+ external/libhpdf/hpdfencn.c
+ external/libhpdf/hpdfenco.c
+ external/libhpdf/hpdfenco.h
+ external/libhpdf/hpdfencr.h
+ external/libhpdf/hpdfency.h
+ external/libhpdf/hpdferro.c
+ external/libhpdf/hpdferro.h
+ external/libhpdf/hpdfextg.c
+ external/libhpdf/hpdfextg.h
+ external/libhpdf/hpdffdf.c
+ external/libhpdf/hpdffdf1.c
+ external/libhpdf/hpdffdfb.c
+ external/libhpdf/hpdffdfc.c
+ external/libhpdf/hpdffdfi.c
+ external/libhpdf/hpdffdfj.c
+ external/libhpdf/hpdffdfk.c
+ external/libhpdf/hpdffdfn.c
+ external/libhpdf/hpdffdft.c
+ external/libhpdf/hpdffon1.c
+ external/libhpdf/hpdffonc.c
+ external/libhpdf/hpdffond.h
+ external/libhpdf/hpdffont.c
+ external/libhpdf/hpdffont.h
+ external/libhpdf/hpdffott.c
+ external/libhpdf/hpdfgsta.c
+ external/libhpdf/hpdfgsta.h
+ external/libhpdf/hpdfimag.c
+ external/libhpdf/hpdfimag.h
+ external/libhpdf/hpdfimap.c
+ external/libhpdf/hpdfinfo.c
+ external/libhpdf/hpdfinfo.h
+ external/libhpdf/hpdflist.c
+ external/libhpdf/hpdflist.h
+ external/libhpdf/hpdfmmgr.c
+ external/libhpdf/hpdfmmgr.h
+ external/libhpdf/hpdfname.c
+ external/libhpdf/hpdfnull.c
+ external/libhpdf/hpdfnumb.c
+ external/libhpdf/hpdfobje.c
+ external/libhpdf/hpdfobje.h
+ external/libhpdf/hpdfoutl.c
+ external/libhpdf/hpdfoutl.h
+ external/libhpdf/hpdfpage.c
+ external/libhpdf/hpdfpage.h
+ external/libhpdf/hpdfpago.c
+ external/libhpdf/hpdfpags.c
+ external/libhpdf/hpdfpags.h
+ external/libhpdf/hpdfreal.c
+ external/libhpdf/hpdfstre.c
+ external/libhpdf/hpdfstre.h
+ external/libhpdf/hpdfstri.c
+ external/libhpdf/hpdftype.h
+ external/libhpdf/hpdfu3d.c
+ external/libhpdf/hpdfu3d.h
+ external/libhpdf/hpdfutil.c
+ external/libhpdf/hpdfutil.h
+ external/libhpdf/hpdfvers.h
+ external/libhpdf/hpdfxref.c
* external/libhpdf/hpdf.h
* external/libhpdf/Makefile
* Converted to short filenames. Added converted scripts.
* source/hbpcre/cnv_hb2o.bat
* source/hbpcre/cnv_o2hb.bat
! Fixed typo in prev.
* Removed PCRE references from comment texts.
239 lines
6.4 KiB
C
239 lines
6.4 KiB
C
/*
|
|
* << Haru Free PDF Library >> -- hpdf_encryptdict.c
|
|
*
|
|
* URL: http://libharu.org
|
|
*
|
|
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
|
|
* Copyright (c) 2007-2008 Antony Dovgal <tony@daylessday.org>
|
|
*
|
|
* Permission to use, copy, modify, distribute and sell this software
|
|
* and its documentation for any purpose is hereby granted without fee,
|
|
* provided that the above copyright notice appear in all copies and
|
|
* that both that copyright notice and this permission notice appear
|
|
* in supporting documentation.
|
|
* It is provided "as is" without express or implied warranty.
|
|
*
|
|
*/
|
|
|
|
#include <time.h>
|
|
#include "hpdfconf.h"
|
|
#include "hpdfutil.h"
|
|
#include "hpdfobje.h"
|
|
#include "hpdfency.h"
|
|
#include "hpdfinfo.h"
|
|
|
|
HPDF_EncryptDict
|
|
HPDF_EncryptDict_New (HPDF_MMgr mmgr,
|
|
HPDF_Xref xref)
|
|
{
|
|
HPDF_Encrypt attr;
|
|
HPDF_EncryptDict dict;
|
|
|
|
HPDF_PTRACE((" HPDF_EncryptDict_New\n"));
|
|
|
|
dict = HPDF_Dict_New (mmgr);
|
|
if (!dict)
|
|
return NULL;
|
|
|
|
dict->header.obj_class |= HPDF_OSUBCLASS_ENCRYPT;
|
|
dict->free_fn = HPDF_EncryptDict_OnFree;
|
|
|
|
attr = HPDF_GetMem (dict->mmgr, sizeof(HPDF_Encrypt_Rec));
|
|
if (!attr) {
|
|
HPDF_Dict_Free (dict);
|
|
return NULL;
|
|
}
|
|
|
|
dict->attr = attr;
|
|
HPDF_Encrypt_Init (attr);
|
|
|
|
if (HPDF_Xref_Add (xref, dict) != HPDF_OK)
|
|
return NULL;
|
|
|
|
return dict;
|
|
}
|
|
|
|
|
|
void
|
|
HPDF_EncryptDict_CreateID (HPDF_EncryptDict dict,
|
|
HPDF_Dict info,
|
|
HPDF_Xref xref)
|
|
{
|
|
HPDF_MD5_CTX ctx;
|
|
HPDF_Encrypt attr = (HPDF_Encrypt)dict->attr;
|
|
|
|
/* use the result of 'time' function to get random value.
|
|
* when debugging, 'time' value is ignored.
|
|
*/
|
|
#ifndef HPDF_DEBUG
|
|
time_t t = HPDF_TIME (NULL);
|
|
#endif /* HPDF_DEBUG */
|
|
|
|
HPDF_MD5Init (&ctx);
|
|
|
|
#ifndef HPDF_DEBUG
|
|
HPDF_MD5Update(&ctx, (HPDF_BYTE *)&t, sizeof(t));
|
|
|
|
/* create File Identifier from elements of Into dictionary. */
|
|
if (info) {
|
|
const char *s;
|
|
HPDF_UINT len;
|
|
|
|
/* Author */
|
|
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_AUTHOR);
|
|
if ((len = HPDF_StrLen (s, -1)) > 0)
|
|
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
|
|
|
/* Creator */
|
|
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_CREATOR);
|
|
if ((len = HPDF_StrLen (s, -1)) > 0)
|
|
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
|
|
|
/* Producer */
|
|
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_PRODUCER);
|
|
if ((len = HPDF_StrLen (s, -1)) > 0)
|
|
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
|
|
|
/* Title */
|
|
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_TITLE);
|
|
if ((len = HPDF_StrLen (s, -1)) > 0)
|
|
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
|
|
|
/* Subject */
|
|
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_SUBJECT);
|
|
if ((len = HPDF_StrLen (s, -1)) > 0)
|
|
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
|
|
|
/* Keywords */
|
|
s = HPDF_Info_GetInfoAttr (info, HPDF_INFO_KEYWORDS);
|
|
if ((len = HPDF_StrLen (s, -1)) > 0)
|
|
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)s, len);
|
|
|
|
HPDF_MD5Update(&ctx, (const HPDF_BYTE *)&(xref->entries->count),
|
|
sizeof(HPDF_UINT32));
|
|
|
|
}
|
|
#endif
|
|
HPDF_MD5Final(attr->encrypt_id, &ctx);
|
|
}
|
|
|
|
|
|
HPDF_STATUS
|
|
HPDF_EncryptDict_Prepare (HPDF_EncryptDict dict,
|
|
HPDF_Dict info,
|
|
HPDF_Xref xref)
|
|
{
|
|
HPDF_STATUS ret;
|
|
HPDF_Encrypt attr = (HPDF_Encrypt)dict->attr;
|
|
HPDF_Binary user_key;
|
|
HPDF_Binary owner_key;
|
|
|
|
HPDF_PTRACE((" HPDF_EncryptDict_Prepare\n"));
|
|
|
|
HPDF_EncryptDict_CreateID (dict, info, xref);
|
|
HPDF_Encrypt_CreateOwnerKey (attr);
|
|
HPDF_Encrypt_CreateEncryptionKey (attr);
|
|
HPDF_Encrypt_CreateUserKey (attr);
|
|
|
|
owner_key = HPDF_Binary_New (dict->mmgr, attr->owner_key, HPDF_PASSWD_LEN);
|
|
if (!owner_key)
|
|
return HPDF_Error_GetCode (dict->error);
|
|
|
|
if ((ret = HPDF_Dict_Add (dict, "O", owner_key)) != HPDF_OK)
|
|
return ret;
|
|
|
|
user_key = HPDF_Binary_New (dict->mmgr, attr->user_key, HPDF_PASSWD_LEN);
|
|
if (!user_key)
|
|
return HPDF_Error_GetCode (dict->error);
|
|
|
|
if ((ret = HPDF_Dict_Add (dict, "U", user_key)) != HPDF_OK)
|
|
return ret;
|
|
|
|
ret += HPDF_Dict_AddName (dict, "Filter", "Standard");
|
|
|
|
if (attr->mode == HPDF_ENCRYPT_R2) {
|
|
ret += HPDF_Dict_AddNumber (dict, "V", 1);
|
|
ret += HPDF_Dict_AddNumber (dict, "R", 2);
|
|
} else if (attr->mode == HPDF_ENCRYPT_R3) {
|
|
ret += HPDF_Dict_AddNumber (dict, "V", 2);
|
|
ret += HPDF_Dict_AddNumber (dict, "R", 3);
|
|
ret += HPDF_Dict_AddNumber (dict, "Length", attr->key_len * 8);
|
|
}
|
|
|
|
ret += HPDF_Dict_AddNumber (dict, "P", attr->permission);
|
|
|
|
if (ret != HPDF_OK)
|
|
return HPDF_Error_GetCode (dict->error);
|
|
|
|
return HPDF_OK;
|
|
}
|
|
|
|
|
|
void
|
|
HPDF_EncryptDict_OnFree (HPDF_Dict obj)
|
|
{
|
|
HPDF_Encrypt attr = (HPDF_Encrypt)obj->attr;
|
|
|
|
HPDF_PTRACE((" HPDF_EncryptDict_OnFree\n"));
|
|
|
|
if (attr)
|
|
HPDF_FreeMem (obj->mmgr, attr);
|
|
}
|
|
|
|
|
|
HPDF_STATUS
|
|
HPDF_EncryptDict_SetPassword (HPDF_EncryptDict dict,
|
|
const char *owner_passwd,
|
|
const char *user_passwd)
|
|
{
|
|
HPDF_Encrypt attr = (HPDF_Encrypt)dict->attr;
|
|
|
|
HPDF_PTRACE((" HPDF_EncryptDict_SetPassword\n"));
|
|
|
|
if (HPDF_StrLen(owner_passwd, 2) == 0)
|
|
return HPDF_SetError(dict->error, HPDF_ENCRYPT_INVALID_PASSWORD, 0);
|
|
|
|
if (owner_passwd && user_passwd &&
|
|
HPDF_StrCmp (owner_passwd, user_passwd) == 0)
|
|
return HPDF_SetError(dict->error, HPDF_ENCRYPT_INVALID_PASSWORD, 0);
|
|
|
|
HPDF_PadOrTrancatePasswd (owner_passwd, attr->owner_passwd);
|
|
HPDF_PadOrTrancatePasswd (user_passwd, attr->user_passwd);
|
|
|
|
return HPDF_OK;
|
|
}
|
|
|
|
|
|
HPDF_BOOL
|
|
HPDF_EncryptDict_Validate (HPDF_EncryptDict dict)
|
|
{
|
|
HPDF_Obj_Header *header = (HPDF_Obj_Header *)dict;
|
|
|
|
HPDF_PTRACE((" HPDF_EncryptDict_Validate\n"));
|
|
|
|
if (!dict || !dict->attr)
|
|
return HPDF_FALSE;
|
|
|
|
if (header->obj_class != (HPDF_OCLASS_DICT | HPDF_OSUBCLASS_ENCRYPT))
|
|
return HPDF_FALSE;
|
|
|
|
return HPDF_TRUE;
|
|
}
|
|
|
|
|
|
HPDF_Encrypt
|
|
HPDF_EncryptDict_GetAttr (HPDF_EncryptDict dict)
|
|
{
|
|
HPDF_Obj_Header *header = (HPDF_Obj_Header *)dict;
|
|
|
|
HPDF_PTRACE((" HPDF_EncryptDict_GetAttr\n"));
|
|
|
|
if (dict && dict->attr &&
|
|
(header->obj_class == (HPDF_OCLASS_DICT | HPDF_OSUBCLASS_ENCRYPT)))
|
|
return (HPDF_Encrypt)dict->attr;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|