Kaydet (Commit) 9c8dc01d authored tarafından Gökçen Eraslan's avatar Gökçen Eraslan

Merge branch 'feature/pdf-signing'

...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#define HID_FILTER_PDF_USER_INTERFACE "HID_FILTER_PDF_USER_INTERFACE" #define HID_FILTER_PDF_USER_INTERFACE "HID_FILTER_PDF_USER_INTERFACE"
#define HID_FILTER_PDF_SECURITY "HID_FILTER_PDF_SECURITY" #define HID_FILTER_PDF_SECURITY "HID_FILTER_PDF_SECURITY"
#define HID_FILTER_PDF_LINKS "HID_FILTER_PDF_LINKS" #define HID_FILTER_PDF_LINKS "HID_FILTER_PDF_LINKS"
#define HID_FILTER_PDF_SIGNING "HID_FILTER_PDF_SIGNING"
#endif #endif
This diff is collapsed.
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#define RID_PDF_TAB_OPNFTR (RID_PDF_DIALOG_START + 3) #define RID_PDF_TAB_OPNFTR (RID_PDF_DIALOG_START + 3)
#define RID_PDF_TAB_SECURITY (RID_PDF_DIALOG_START + 4) #define RID_PDF_TAB_SECURITY (RID_PDF_DIALOG_START + 4)
#define RID_PDF_TAB_LINKS (RID_PDF_DIALOG_START + 12) #define RID_PDF_TAB_LINKS (RID_PDF_DIALOG_START + 12)
#define RID_PDF_TAB_SIGNING (RID_PDF_DIALOG_START + 13)
#define RID_PDF_WARNPDFAPASSWORD (RID_PDF_DIALOG_START + 6) #define RID_PDF_WARNPDFAPASSWORD (RID_PDF_DIALOG_START + 6)
//strings //strings
...@@ -177,3 +178,15 @@ ...@@ -177,3 +178,15 @@
#define FL_INITVIEW_VERTICAL 158 #define FL_INITVIEW_VERTICAL 158
#define FL_VPREFER_VERTICAL 158 #define FL_VPREFER_VERTICAL 158
#define FL_SECURITY_VERTICAL 160 #define FL_SECURITY_VERTICAL 160
//controls for digital signatures tab page
#define CB_SIGN_PDF 170
#define FT_SIGN_PASSWORD 171
#define ED_SIGN_PASSWORD 172
#define FT_SIGN_LOCATION 173
#define ED_SIGN_LOCATION 174
#define FT_SIGN_CONTACT 175
#define ED_SIGN_CONTACT 176
#define FT_SIGN_REASON 177
#define ED_SIGN_REASON 178
#define BTN_SIGN_SELECT_CERT 179
...@@ -148,6 +148,14 @@ protected: ...@@ -148,6 +148,14 @@ protected:
sal_Int32 mnViewPDFMode; sal_Int32 mnViewPDFMode;
sal_Bool mbConvertOOoTargets; sal_Bool mbConvertOOoTargets;
sal_Bool mbExportBmkToPDFDestination; sal_Bool mbExportBmkToPDFDestination;
sal_Bool mbSignPDF;
::rtl::OUString msSignPassword;
::rtl::OUString msSignLocation;
::rtl::OUString msSignContact;
::rtl::OUString msSignReason;
com::sun::star::uno::Reference< com::sun::star::security::XCertificate > maSignCertificate;
::rtl::OUString maWatermarkText; ::rtl::OUString maWatermarkText;
public: public:
...@@ -157,6 +165,7 @@ public: ...@@ -157,6 +165,7 @@ public:
friend class ImpPDFTabOpnFtrPage; friend class ImpPDFTabOpnFtrPage;
friend class ImpPDFTabSecurityPage; friend class ImpPDFTabSecurityPage;
friend class ImpPDFTabLinksPage; friend class ImpPDFTabLinksPage;
friend class ImpPDFTabSigningPage;
ImpPDFTabDialog( Window* pParent, ImpPDFTabDialog( Window* pParent,
Sequence< PropertyValue >& rFilterData, Sequence< PropertyValue >& rFilterData,
...@@ -429,6 +438,36 @@ public: ...@@ -429,6 +438,36 @@ public:
void ImplPDFALinkControl( sal_Bool bEnableLaunch ); void ImplPDFALinkControl( sal_Bool bEnableLaunch );
}; };
//class to implement the digital signing
class ImpPDFTabSigningPage : public SfxTabPage
{
CheckBox maCbSignPDF;
FixedText maFtSignPassword;
Edit maEdSignPassword;
FixedText maFtSignLocation;
Edit maEdSignLocation;
FixedText maFtSignContactInfo;
Edit maEdSignContactInfo;
FixedText maFtSignReason;
Edit maEdSignReason;
PushButton maPbSignSelectCert;
com::sun::star::uno::Reference< com::sun::star::security::XCertificate > maSignCertificate;
DECL_LINK( ToggleSignPDFHdl, void* );
DECL_LINK( ClickmaPbSignSelectCert, void* );
public:
ImpPDFTabSigningPage( Window* pParent,
const SfxItemSet& rSet );
~ImpPDFTabSigningPage();
static SfxTabPage* Create( Window* pParent,
const SfxItemSet& rAttrSet );
void GetFilterConfigItem( ImpPDFTabDialog* paParent);
void SetFilterConfigItem( const ImpPDFTabDialog* paParent );
};
#endif // IMPDIALOG_HXX #endif // IMPDIALOG_HXX
......
...@@ -816,6 +816,91 @@ TabPage RID_PDF_TAB_SECURITY ...@@ -816,6 +816,91 @@ TabPage RID_PDF_TAB_SECURITY
}; };
}; };
//----------------------------------------------------------
//tab page for PDF Export, digital signatures
TabPage RID_PDF_TAB_SIGNING
{
HelpId = HID_FILTER_PDF_SIGNING ;
Text [ en-US ] = "Digital Signatures";
TAB_PDF_SIZE;
Hide = TRUE;
CheckBox CB_SIGN_PDF
{
Pos = MAP_APPFONT ( 6 , 3 ) ;
Size = MAP_APPFONT ( 164 , 16 ) ;
TabStop = TRUE ;
WordBreak = TRUE ;
Text[ en-US ] = "Sign PDF file" ;
};
PushButton BTN_SIGN_SELECT_CERT
{
TabStop = TRUE ;
Disable = TRUE ;
Pos = MAP_APPFONT ( 12, 17 ) ;
Size = MAP_APPFONT ( 120 , 13 ) ;
Text[ en-US ] = "Select c~ertificate...";
};
FixedText FT_SIGN_PASSWORD
{
Pos = MAP_APPFONT( 12, 35 );
Size = MAP_APPFONT( 109, 10 );
Text[ en-US ] = "Certificate Password";
};
Edit ED_SIGN_PASSWORD
{
Border = TRUE ;
Pos = MAP_APPFONT ( 102, 35 ) ;
Size = MAP_APPFONT ( 68 , 12 ) ;
};
FixedText FT_SIGN_LOCATION
{
Pos = MAP_APPFONT( 12, 48 );
Size = MAP_APPFONT( 109, 10 );
Text[ en-US ] = "Location";
};
Edit ED_SIGN_LOCATION
{
Border = TRUE ;
Pos = MAP_APPFONT ( 102, 48 ) ;
Size = MAP_APPFONT ( 68 , 12 ) ;
};
FixedText FT_SIGN_CONTACT
{
Pos = MAP_APPFONT( 12, 61 );
Size = MAP_APPFONT( 109, 10 );
Text[ en-US ] = "Contact Information";
};
Edit ED_SIGN_CONTACT
{
Border = TRUE ;
Pos = MAP_APPFONT ( 102, 61 ) ;
Size = MAP_APPFONT ( 68 , 12 ) ;
};
FixedText FT_SIGN_REASON
{
Pos = MAP_APPFONT( 12, 74 );
Size = MAP_APPFONT( 109, 10 );
Text[ en-US ] = "Reason";
};
Edit ED_SIGN_REASON
{
Border = TRUE ;
Pos = MAP_APPFONT ( 102, 74 ) ;
Size = MAP_APPFONT ( 68 , 12 ) ;
};
};
//---------------------------------------------------------- //----------------------------------------------------------
//tab page for PDF Export, links management //tab page for PDF Export, links management
TabPage RID_PDF_TAB_LINKS TabPage RID_PDF_TAB_LINKS
...@@ -930,6 +1015,11 @@ TabDialog RID_PDF_EXPORT_DLG ...@@ -930,6 +1015,11 @@ TabDialog RID_PDF_EXPORT_DLG
Identifier = RID_PDF_TAB_SECURITY; Identifier = RID_PDF_TAB_SECURITY;
Text [ en-US ] = "Security"; Text [ en-US ] = "Security";
}; };
PageItem
{
Identifier = RID_PDF_TAB_SIGNING;
Text [ en-US ] = "Digital Signatures";
};
}; };
}; };
}; };
......
...@@ -554,6 +554,18 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue ...@@ -554,6 +554,18 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
rFilterData[ nData ].Value >>= mbExportHiddenSlides; rFilterData[ nData ].Value >>= mbExportHiddenSlides;
else if ( rFilterData[ nData ].Name == "OpenBookmarkLevels" ) else if ( rFilterData[ nData ].Name == "OpenBookmarkLevels" )
rFilterData[ nData ].Value >>= mnOpenBookmarkLevels; rFilterData[ nData ].Value >>= mnOpenBookmarkLevels;
else if ( rFilterData[ nData ].Name == "SignPDF" )
rFilterData[ nData ].Value >>= mbSignPDF;
else if ( rFilterData[ nData ].Name == "SignatureLocation" )
rFilterData[ nData ].Value >>= msSignLocation;
else if ( rFilterData[ nData ].Name == "SignatureReason" )
rFilterData[ nData ].Value >>= msSignReason;
else if ( rFilterData[ nData ].Name == "SignatureContactInfo" )
rFilterData[ nData ].Value >>= msSignContact;
else if ( rFilterData[ nData ].Name == "SignaturePassword" )
rFilterData[ nData ].Value >>= msSignPassword;
else if ( rFilterData[ nData ].Name == "SignatureCertificate" )
rFilterData[ nData ].Value >>= maSignCertificate;
} }
aContext.URL = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI); aContext.URL = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
...@@ -781,6 +793,14 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue ...@@ -781,6 +793,14 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
aContext.ForcePDFAction = sal_False; aContext.ForcePDFAction = sal_False;
} }
} }
aContext.SignPDF = mbSignPDF;
aContext.SignLocation = msSignLocation;
aContext.SignContact = msSignContact;
aContext.SignReason = msSignReason;
aContext.SignPassword = msSignPassword;
aContext.SignCertificate = maSignCertificate;
// all context data set, time to create the printing device // all context data set, time to create the printing device
PDFWriter* pPDFWriter = new PDFWriter( aContext, xEnc ); PDFWriter* pPDFWriter = new PDFWriter( aContext, xEnc );
OutputDevice* pOut = pPDFWriter->GetReferenceDevice(); OutputDevice* pOut = pPDFWriter->GetReferenceDevice();
......
...@@ -111,6 +111,14 @@ private: ...@@ -111,6 +111,14 @@ private:
sal_Bool mbExportBmkToDest; sal_Bool mbExportBmkToDest;
sal_Bool ImplExportPage( ::vcl::PDFWriter& rWriter, ::vcl::PDFExtOutDevData& rPDFExtOutDevData, sal_Bool ImplExportPage( ::vcl::PDFWriter& rWriter, ::vcl::PDFExtOutDevData& rPDFExtOutDevData,
const GDIMetaFile& rMtf ); const GDIMetaFile& rMtf );
sal_Bool mbSignPDF;
OUString msSignLocation;
OUString msSignContact;
OUString msSignReason;
OUString msSignPassword;
Reference< security::XCertificate > maSignCertificate;
void ImplWriteWatermark( ::vcl::PDFWriter& rWriter, const Size& rPageSize ); void ImplWriteWatermark( ::vcl::PDFWriter& rWriter, const Size& rPageSize );
public: public:
......
...@@ -143,7 +143,9 @@ interface XDocumentDigitalSignatures : com::sun::star::uno::XInterface ...@@ -143,7 +143,9 @@ interface XDocumentDigitalSignatures : com::sun::star::uno::XInterface
void addAuthorToTrustedSources( [in] com::sun::star::security::XCertificate Author ); void addAuthorToTrustedSources( [in] com::sun::star::security::XCertificate Author );
void addLocationToTrustedSources( [in] string Location ); void addLocationToTrustedSources( [in] string Location );
/** This method shows CertificateChooser dialog, used by document and PDF signing
*/
com::sun::star::security::XCertificate chooseCertificate();
} ; } ;
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "com/sun/star/io/XOutputStream.hpp" #include "com/sun/star/io/XOutputStream.hpp"
#include "com/sun/star/beans/XMaterialHolder.hpp" #include "com/sun/star/beans/XMaterialHolder.hpp"
#include "com/sun/star/security/XCertificate.hpp"
#include "com/sun/star/lang/Locale.hpp" #include "com/sun/star/lang/Locale.hpp"
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
...@@ -197,7 +198,8 @@ public: ...@@ -197,7 +198,8 @@ public:
enum WidgetType enum WidgetType
{ {
PushButton, RadioButton, CheckBox, Edit, ListBox, ComboBox, Hierarchy PushButton, RadioButton, CheckBox, Edit, ListBox, ComboBox, Hierarchy,
Signature
}; };
enum WidgetState enum WidgetState
...@@ -449,6 +451,28 @@ public: ...@@ -449,6 +451,28 @@ public:
} }
}; };
struct SignatureWidget: public AnyWidget
{
// Use Sig prefix for members to avoid conflict with
// the Location member of the AnyWidget which spcifies the coordinates
// of the signature
rtl::OUString SigLocation;
rtl::OUString SigReason;
rtl::OUString SigContactInfo;
bool SigHidden;
SignatureWidget()
: AnyWidget( vcl::PDFWriter::Signature ),
SigHidden( true )
{}
virtual AnyWidget* Clone() const
{
return new SignatureWidget( *this );
}
};
enum ExportDataFormat { HTML, XML, FDF, PDF }; enum ExportDataFormat { HTML, XML, FDF, PDF };
// see 3.6.1 of PDF 1.4 ref for details, used for 8.1 PDF v 1.4 ref also // see 3.6.1 of PDF 1.4 ref for details, used for 8.1 PDF v 1.4 ref also
// These emuns are treated as integer while reading/writing to configuration // These emuns are treated as integer while reading/writing to configuration
...@@ -606,6 +630,13 @@ The following structure describes the permissions used in PDF security ...@@ -606,6 +630,13 @@ The following structure describes the permissions used in PDF security
PDFWriter::PDFEncryptionProperties Encryption; PDFWriter::PDFEncryptionProperties Encryption;
PDFWriter::PDFDocInfo DocumentInfo; PDFWriter::PDFDocInfo DocumentInfo;
bool SignPDF;
rtl::OUString SignLocation;
rtl::OUString SignPassword;
rtl::OUString SignReason;
rtl::OUString SignContact;
com::sun::star::uno::Reference< com::sun::star::security::XCertificate> SignCertificate;
com::sun::star::lang::Locale DocumentLocale; // defines the document default language com::sun::star::lang::Locale DocumentLocale; // defines the document default language
sal_uInt32 DPIx, DPIy; // how to handle MapMode( MAP_PIXEL ) sal_uInt32 DPIx, DPIy; // how to handle MapMode( MAP_PIXEL )
// 0 here specifies a default handling // 0 here specifies a default handling
...@@ -637,9 +668,11 @@ The following structure describes the permissions used in PDF security ...@@ -637,9 +668,11 @@ The following structure describes the permissions used in PDF security
InitialPage( 1 ), InitialPage( 1 ),
OpenBookmarkLevels( -1 ), OpenBookmarkLevels( -1 ),
Encryption(), Encryption(),
SignPDF( false ),
DPIx( 0 ), DPIx( 0 ),
DPIy( 0 ), DPIy( 0 ),
ColorMode( PDFWriter::DrawColor ) ColorMode( PDFWriter::DrawColor ),
SignCertificate( 0 )
{} {}
}; };
......
...@@ -678,6 +678,10 @@ private: ...@@ -678,6 +678,10 @@ private:
sal_Int32 m_nCurrentPage; sal_Int32 m_nCurrentPage;
sal_Int32 m_nCatalogObject; sal_Int32 m_nCatalogObject;
// object number of the main signature dictionary
sal_Int32 m_nSignatureObject;
sal_Int64 m_nSignatureContentOffset;
sal_Int64 m_nSignatureLastByteRangeNoOffset;
sal_Int32 m_nResourceDict; sal_Int32 m_nResourceDict;
ResourceDict m_aGlobalResourceDict; ResourceDict m_aGlobalResourceDict;
sal_Int32 m_nFontDictObject; sal_Int32 m_nFontDictObject;
...@@ -950,6 +954,11 @@ i12626 ...@@ -950,6 +954,11 @@ i12626
sal_Int32 emitStructParentTree( sal_Int32 nTreeObject ); sal_Int32 emitStructParentTree( sal_Int32 nTreeObject );
// writes page tree and catalog // writes page tree and catalog
bool emitCatalog(); bool emitCatalog();
// writes signature dictionary object
bool emitSignature();
// creates a PKCS7 object using the ByteRange and overwrite /Contents
// of the signature dictionary
bool finalizeSignature();
// writes xref and trailer // writes xref and trailer
bool emitTrailer(); bool emitTrailer();
// emit additional streams collected; also create there object numbers // emit additional streams collected; also create there object numbers
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <documentdigitalsignatures.hxx> #include <documentdigitalsignatures.hxx>
#include <xmlsecurity/digitalsignaturesdialog.hxx> #include <xmlsecurity/digitalsignaturesdialog.hxx>
#include <xmlsecurity/certificatechooser.hxx>
#include <xmlsecurity/certificateviewer.hxx> #include <xmlsecurity/certificateviewer.hxx>
#include <xmlsecurity/macrosecurity.hxx> #include <xmlsecurity/macrosecurity.hxx>
#include <xmlsecurity/biginteger.hxx> #include <xmlsecurity/biginteger.hxx>
...@@ -424,6 +425,28 @@ void DocumentDigitalSignatures::showCertificate( ...@@ -424,6 +425,28 @@ void DocumentDigitalSignatures::showCertificate(
return bFound; return bFound;
} }
Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertificate() throw (RuntimeException)
{
Reference< dcss::xml::crypto::XSecurityEnvironment > xSecEnv;
XMLSignatureHelper aSignatureHelper( mxCtx );
if ( aSignatureHelper.Init() )
xSecEnv = aSignatureHelper.GetSecurityEnvironment();
CertificateChooser aChooser( NULL, mxCtx, xSecEnv, aSignatureHelper.GetSignatureInformations());
if (aChooser.Execute() != RET_OK)
return Reference< css::security::XCertificate >(0);
Reference< css::security::XCertificate > xCert = aChooser.GetSelectedCertificate();
if ( !xCert.is() )
return Reference< css::security::XCertificate >(0);
return xCert;
}
::sal_Bool DocumentDigitalSignatures::isLocationTrusted( const ::rtl::OUString& Location ) throw (RuntimeException) ::sal_Bool DocumentDigitalSignatures::isLocationTrusted( const ::rtl::OUString& Location ) throw (RuntimeException)
{ {
sal_Bool bFound = sal_False; sal_Bool bFound = sal_False;
......
...@@ -85,6 +85,7 @@ public: ...@@ -85,6 +85,7 @@ public:
void SAL_CALL addAuthorToTrustedSources( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& Author ) throw (::com::sun::star::uno::RuntimeException); void SAL_CALL addAuthorToTrustedSources( const ::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate >& Author ) throw (::com::sun::star::uno::RuntimeException);
void SAL_CALL addLocationToTrustedSources( const ::rtl::OUString& Location ) throw (::com::sun::star::uno::RuntimeException); void SAL_CALL addLocationToTrustedSources( const ::rtl::OUString& Location ) throw (::com::sun::star::uno::RuntimeException);
::com::sun::star::uno::Reference< ::com::sun::star::security::XCertificate > SAL_CALL chooseCertificate( ) throw (::com::sun::star::uno::RuntimeException);
}; };
com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL DocumentDigitalSignatures_CreateInstance( com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL DocumentDigitalSignatures_CreateInstance(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment