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

Add password edit and pass XCertificate to PDFWriter code in VCL.

Now, we have the password of private key and the certificate to
sign. Ready to use NSS and create necessary PKCS7 object using
these.

Change-Id: Id69487e92283059fcd558d33cf6a6128df0f50d9
üst bb1ba4f3
......@@ -249,9 +249,6 @@ ImpPDFTabDialog::ImpPDFTabDialog( Window* pParent,
//prepare values for digital signatures
mbSignPDF = maConfigItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "SignPDF" ) ), sal_False );
//msSignLocation = maConfigItem.ReadString( OUString( RTL_CONSTASCII_USTRINGPARAM( "SignatureLocation" ) ), "" );
//msSignContact = maConfigItem.ReadString( OUString( RTL_CONSTASCII_USTRINGPARAM( "SignatureContactInfo" ) ), "" );
//msSignReason = maConfigItem.ReadString( OUString( RTL_CONSTASCII_USTRINGPARAM( "SignatureReason" ) ), "" );
//queue the tab pages for later creation (created when first shown)
AddTabPage( RID_PDF_TAB_SIGNING, ImpPDFTabSigningPage::Create, 0 );
......@@ -416,7 +413,7 @@ Sequence< PropertyValue > ImpPDFTabDialog::GetFilterData()
Sequence< PropertyValue > aRet( maConfigItem.GetFilterData() );
int nElementAdded = 9;
int nElementAdded = 11;
aRet.realloc( aRet.getLength() + nElementAdded );
......@@ -472,6 +469,14 @@ Sequence< PropertyValue > ImpPDFTabDialog::GetFilterData()
aRet[ nLength - nElementAdded ].Value <<= msSignContact;
nElementAdded--;
aRet[ nLength - nElementAdded ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "SignaturePassword" ) );
aRet[ nLength - nElementAdded ].Value <<= msSignPassword;
nElementAdded--;
aRet[ nLength - nElementAdded ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "SignatureCertificate" ) );
aRet[ nLength - nElementAdded ].Value <<= maSignCertificate;
nElementAdded--;
return aRet;
}
......@@ -1678,13 +1683,16 @@ ImpPDFTabSigningPage::ImpPDFTabSigningPage( Window* pParent,
SfxTabPage( pParent, PDFFilterResId( RID_PDF_TAB_SIGNING ), rCoreSet ),
maCbSignPDF( this, PDFFilterResId( CB_SIGN_PDF ) ),
maFtSignPassword( this, PDFFilterResId( FT_SIGN_PASSWORD ) ),
maEdSignPassword( this, PDFFilterResId( ED_SIGN_PASSWORD ) ),
maFtSignLocation( this, PDFFilterResId( FT_SIGN_LOCATION ) ),
maEdSignLocation( this, PDFFilterResId( ED_SIGN_LOCATION ) ),
maFtSignContactInfo( this, PDFFilterResId( FT_SIGN_CONTACT ) ),
maEdSignContactInfo( this, PDFFilterResId( ED_SIGN_CONTACT ) ),
maFtSignReason( this, PDFFilterResId( FT_SIGN_REASON ) ),
maEdSignReason( this, PDFFilterResId( ED_SIGN_REASON ) ),
maPbSignSelectCert( this, PDFFilterResId( BTN_SIGN_SELECT_CERT ) )
maPbSignSelectCert( this, PDFFilterResId( BTN_SIGN_SELECT_CERT ) ),
maSignCertificate()
{
FreeResource();
......@@ -1711,7 +1719,7 @@ IMPL_LINK_NOARG( ImpPDFTabSigningPage, ClickmaPbSignSelectCert )
if ( !xSigner.is() )
return 0;
Reference< security::XCertificate > xCert = xSigner->chooseCertificate();
maSignCertificate = xSigner->chooseCertificate();
return 0;
}
......@@ -1728,8 +1736,10 @@ void ImpPDFTabSigningPage::GetFilterConfigItem( ImpPDFTabDialog* paParent )
{
paParent->mbSignPDF = maCbSignPDF.IsChecked();
paParent->msSignLocation = maEdSignLocation.GetText();
paParent->msSignPassword = maEdSignPassword.GetText();
paParent->msSignContact = maEdSignContactInfo.GetText();
paParent->msSignReason = maEdSignReason.GetText();
paParent->maSignCertificate = maSignCertificate;
}
......@@ -1739,6 +1749,7 @@ void ImpPDFTabSigningPage::SetFilterConfigItem( const ImpPDFTabDialog* paParent
maCbSignPDF.SetToggleHdl( LINK( this, ImpPDFTabSigningPage, ToggleSignPDFHdl ) );
maEdSignLocation.Enable( false );
maEdSignPassword.Enable( false );
maEdSignContactInfo.Enable( false );
maEdSignReason.Enable( false );
maPbSignSelectCert.Enable( false );
......@@ -1746,15 +1757,18 @@ void ImpPDFTabSigningPage::SetFilterConfigItem( const ImpPDFTabDialog* paParent
if (paParent->mbSignPDF)
{
maCbSignPDF.Check();
maEdSignPassword.SetText(paParent->msSignPassword);
maEdSignLocation.SetText(paParent->msSignLocation);
maEdSignContactInfo.SetText(paParent->msSignContact);
maEdSignReason.SetText(paParent->msSignReason);
maSignCertificate = paParent->maSignCertificate;
}
}
// -----------------------------------------------------------------------------
IMPL_LINK_NOARG(ImpPDFTabSigningPage, ToggleSignPDFHdl)
{
maEdSignPassword.Enable( maCbSignPDF.IsChecked() );
maEdSignLocation.Enable( maCbSignPDF.IsChecked() );
maEdSignContactInfo.Enable( maCbSignPDF.IsChecked() );
maEdSignReason.Enable( maCbSignPDF.IsChecked() );
......
......@@ -202,10 +202,12 @@
//controls for digital signatures tab page
#define CB_SIGN_PDF 170
#define FT_SIGN_LOCATION 171
#define ED_SIGN_LOCATION 172
#define FT_SIGN_CONTACT 173
#define ED_SIGN_CONTACT 174
#define FT_SIGN_REASON 175
#define ED_SIGN_REASON 176
#define BTN_SIGN_SELECT_CERT 177
#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
......@@ -151,9 +151,11 @@ protected:
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;
......@@ -441,6 +443,8 @@ public:
class ImpPDFTabSigningPage : public SfxTabPage
{
CheckBox maCbSignPDF;
FixedText maFtSignPassword;
Edit maEdSignPassword;
FixedText maFtSignLocation;
Edit maEdSignLocation;
FixedText maFtSignContactInfo;
......@@ -448,6 +452,7 @@ class ImpPDFTabSigningPage : public SfxTabPage
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* );
......
......@@ -843,23 +843,37 @@ TabPage RID_PDF_TAB_SIGNING
Text[ en-US ] = "Select c~ertificate...";
};
FixedText FT_SIGN_LOCATION
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 ( 122, 35 ) ;
Size = MAP_APPFONT ( 48 , 12 ) ;
Pos = MAP_APPFONT ( 102, 48 ) ;
Size = MAP_APPFONT ( 68 , 12 ) ;
};
FixedText FT_SIGN_CONTACT
{
Pos = MAP_APPFONT( 12, 48 );
Pos = MAP_APPFONT( 12, 61 );
Size = MAP_APPFONT( 109, 10 );
Text[ en-US ] = "Contact Information";
};
......@@ -867,13 +881,13 @@ TabPage RID_PDF_TAB_SIGNING
Edit ED_SIGN_CONTACT
{
Border = TRUE ;
Pos = MAP_APPFONT ( 122, 48 ) ;
Size = MAP_APPFONT ( 48 , 12 ) ;
Pos = MAP_APPFONT ( 102, 61 ) ;
Size = MAP_APPFONT ( 68 , 12 ) ;
};
FixedText FT_SIGN_REASON
{
Pos = MAP_APPFONT( 12, 61 );
Pos = MAP_APPFONT( 12, 74 );
Size = MAP_APPFONT( 109, 10 );
Text[ en-US ] = "Reason";
};
......@@ -881,8 +895,8 @@ TabPage RID_PDF_TAB_SIGNING
Edit ED_SIGN_REASON
{
Border = TRUE ;
Pos = MAP_APPFONT ( 122, 61 ) ;
Size = MAP_APPFONT ( 48 , 12 ) ;
Pos = MAP_APPFONT ( 102, 74 ) ;
Size = MAP_APPFONT ( 68 , 12 ) ;
};
};
......
......@@ -562,6 +562,10 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
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);
......@@ -794,6 +798,8 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
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
PDFWriter* pPDFWriter = new PDFWriter( aContext, xEnc );
......
......@@ -122,6 +122,8 @@ private:
OUString msSignLocation;
OUString msSignContact;
OUString msSignReason;
OUString msSignPassword;
Reference< security::XCertificate > maSignCertificate;
void ImplWriteWatermark( ::vcl::PDFWriter& rWriter, const Size& rPageSize );
public:
......
......@@ -41,6 +41,7 @@
#include "com/sun/star/io/XOutputStream.hpp"
#include "com/sun/star/beans/XMaterialHolder.hpp"
#include "com/sun/star/security/XCertificate.hpp"
#include "com/sun/star/lang/Locale.hpp"
#include <boost/scoped_ptr.hpp>
......@@ -631,8 +632,10 @@ The following structure describes the permissions used in PDF security
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
sal_uInt32 DPIx, DPIy; // how to handle MapMode( MAP_PIXEL )
......@@ -668,7 +671,8 @@ The following structure describes the permissions used in PDF security
SignPDF( false ),
DPIx( 0 ),
DPIy( 0 ),
ColorMode( PDFWriter::DrawColor )
ColorMode( PDFWriter::DrawColor ),
SignCertificate( 0 )
{}
};
......
......@@ -6175,6 +6175,8 @@ bool PDFWriterImpl::finalizeSignature()
}
// 3- create the PKCS#7 object using NSS
// use m_aContext.SignCertificate and m_aContext.SignPassword as certificate and private key password
// SignCertificate->getEncoded is DER encoded certificate
// 4- overwrite the PKCS7 content to the m_nSignatureContentOffset
CHECK_RETURN( (osl_File_E_None == osl_setFilePos( m_aFile, osl_Pos_Absolut, m_nSignatureContentOffset ) ) );
......
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