Kaydet (Commit) da7d7a24 authored tarafından Vladimir Glazounov's avatar Vladimir Glazounov

INTEGRATION: CWS xmlsec08 (1.3.10); FILE MERGED

2005/01/20 03:34:28 mmi 1.3.10.1: smartcard support
Issue number:  38448
Submitted by:
Reviewed by:
üst 54564a8e
......@@ -2,9 +2,9 @@
*
* $RCSfile: xmlencryption_nssimpl.cxx,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change: $Author: rt $ $Date: 2004-11-26 14:59:01 $
* last change: $Author: vg $ $Date: 2005-03-10 18:13:35 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
......@@ -79,8 +79,8 @@
#include "xmlelementwrapper_xmlsecimpl.hxx"
#endif
#ifndef _XMLSECURITYCONTEXT_NSSIMPL_HXX_
#include "xmlsecuritycontext_nssimpl.hxx"
#ifndef _SECURITYENVIRONMENT_NSSIMPL_HXX_
#include "securityenvironment_nssimpl.hxx"
#endif
#ifndef _ERRORCALLBACK_XMLSECIMPL_HXX_
......@@ -108,6 +108,7 @@ using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
using ::com::sun::star::xml::crypto::XXMLEncryption ;
using ::com::sun::star::xml::crypto::XXMLEncryptionTemplate ;
using ::com::sun::star::xml::crypto::XXMLSecurityContext ;
using ::com::sun::star::xml::crypto::XSecurityEnvironment ;
using ::com::sun::star::xml::crypto::XMLEncryptionException ;
XMLEncryption_NssImpl :: XMLEncryption_NssImpl( const Reference< XMultiServiceFactory >& aFactory ) : m_xServiceManager( aFactory ) {
......@@ -120,7 +121,7 @@ XMLEncryption_NssImpl :: ~XMLEncryption_NssImpl() {
Reference< XXMLEncryptionTemplate >
SAL_CALL XMLEncryption_NssImpl :: encrypt(
const Reference< XXMLEncryptionTemplate >& aTemplate ,
const Reference< XXMLSecurityContext >& aSecurityCtx
const Reference< XSecurityEnvironment >& aEnvironment
) throw( com::sun::star::xml::crypto::XMLEncryptionException,
com::sun::star::uno::SecurityException )
{
......@@ -133,18 +134,24 @@ SAL_CALL XMLEncryption_NssImpl :: encrypt(
if( !aTemplate.is() )
throw RuntimeException() ;
if( !aSecurityCtx.is() )
if( !aEnvironment.is() )
throw RuntimeException() ;
//Get Keys Manager
Reference< XUnoTunnel > xSecTunnel( aSecurityCtx , UNO_QUERY ) ;
Reference< XUnoTunnel > xSecTunnel( aEnvironment , UNO_QUERY ) ;
if( !xSecTunnel.is() ) {
throw RuntimeException() ;
}
#if 0
XMLSecurityContext_NssImpl* pSecCtxt = ( XMLSecurityContext_NssImpl* )xSecTunnel->getSomething( XMLSecurityContext_NssImpl::getUnoTunnelId() ) ;
if( pSecCtxt == NULL )
throw RuntimeException() ;
#endif
SecurityEnvironment_NssImpl* pSecEnv = ( SecurityEnvironment_NssImpl* )xSecTunnel->getSomething( SecurityEnvironment_NssImpl::getUnoTunnelId() ) ;
if( pSecEnv == NULL )
throw RuntimeException() ;
//Get the encryption template
Reference< XXMLElementWrapper > xTemplate = aTemplate->getTemplate() ;
......@@ -205,14 +212,18 @@ SAL_CALL XMLEncryption_NssImpl :: encrypt(
isParentRef = sal_False;
}
pMngr = pSecCtxt->keysManager() ;
setErrorRecorder( aTemplate );
pMngr = pSecEnv->createKeysManager() ; //i39448
if( !pMngr ) {
throw RuntimeException() ;
}
//Create Encryption context
pEncCtx = xmlSecEncCtxCreate( pMngr ) ;
if( pEncCtx == NULL )
{
pSecEnv->destroyKeysManager( pMngr ) ; //i39448
//throw XMLEncryptionException() ;
clearErrorRecorder();
return aTemplate;
......@@ -252,6 +263,7 @@ SAL_CALL XMLEncryption_NssImpl :: encrypt(
if( xmlSecEncCtxXmlEncrypt( pEncCtx , pEncryptedData , pContent ) < 0 )
{
xmlSecEncCtxDestroy( pEncCtx ) ;
pSecEnv->destroyKeysManager( pMngr ) ; //i39448
//throw XMLEncryptionException() ;
clearErrorRecorder();
......@@ -259,6 +271,7 @@ SAL_CALL XMLEncryption_NssImpl :: encrypt(
}
xmlSecEncCtxDestroy( pEncCtx ) ;
pSecEnv->destroyKeysManager( pMngr ) ; //i39448
//get the new EncryptedData element
if (isParentRef)
......@@ -291,16 +304,6 @@ SAL_CALL XMLEncryption_NssImpl :: decrypt(
if( !aSecurityCtx.is() )
throw RuntimeException() ;
//Get Keys Manager
Reference< XUnoTunnel > xSecTunnel( aSecurityCtx , UNO_QUERY ) ;
if( !xSecTunnel.is() ) {
throw RuntimeException() ;
}
XMLSecurityContext_NssImpl* pSecCtxt = ( XMLSecurityContext_NssImpl* )xSecTunnel->getSomething( XMLSecurityContext_NssImpl::getUnoTunnelId() ) ;
if( pSecCtxt == NULL )
throw RuntimeException() ;
//Get the encryption template
Reference< XXMLElementWrapper > xTemplate = aTemplate->getTemplate() ;
if( !xTemplate.is() ) {
......@@ -334,51 +337,48 @@ SAL_CALL XMLEncryption_NssImpl :: decrypt(
isParentRef = sal_False;
}
pMngr = pSecCtxt->keysManager() ;
setErrorRecorder( aTemplate );
sal_Int32 nSecurityEnvironment = aSecurityCtx->getSecurityEnvironmentNumber();
sal_Int32 i;
for (i=0; i<nSecurityEnvironment; ++i)
{
Reference< XSecurityEnvironment > aEnvironment = aSecurityCtx->getSecurityEnvironmentByIndex(i);
//Get Keys Manager
Reference< XUnoTunnel > xSecTunnel( aEnvironment , UNO_QUERY ) ;
if( !aEnvironment.is() ) {
throw RuntimeException() ;
}
SecurityEnvironment_NssImpl* pSecEnv = ( SecurityEnvironment_NssImpl* )xSecTunnel->getSomething( SecurityEnvironment_NssImpl::getUnoTunnelId() ) ;
if( pSecEnv == NULL )
throw RuntimeException() ;
pMngr = pSecEnv->createKeysManager() ; //i39448
if( !pMngr ) {
throw RuntimeException() ;
}
//Create Encryption context
pEncCtx = xmlSecEncCtxCreate( pMngr ) ;
if( pEncCtx == NULL )
{
pSecEnv->destroyKeysManager( pMngr ) ; //i39448
//throw XMLEncryptionException() ;
clearErrorRecorder();
return aTemplate;
}
//Decrypt the template
if( xmlSecEncCtxDecrypt( pEncCtx , pEncryptedData ) < 0 || pEncCtx->result == NULL ) {
xmlSecEncCtxDestroy( pEncCtx ) ;
//throw XMLEncryptionException() ;
clearErrorRecorder();
return aTemplate;
}
/*----------------------------------------
if( pEncCtx->resultReplaced != 0 ) {
pContent = pEncryptedData ;
Reference< XUnoTunnel > xTunnel( ret , UNO_QUERY ) ;
if( !xTunnel.is() ) {
xmlSecEncCtxDestroy( pEncCtx ) ;
throw RuntimeException() ;
}
XMLElementWrapper_XmlSecImpl* pNode = ( XMLElementWrapper_XmlSecImpl* )xTunnel->getSomething( XMLElementWrapper_XmlSecImpl::getUnoTunnelImplementationId() ) ;
if( pNode == NULL ) {
xmlSecEncCtxDestroy( pEncCtx ) ;
throw RuntimeException() ;
}
pNode->setNativeElement( pContent ) ;
} else {
xmlSecEncCtxDestroy( pEncCtx ) ;
throw XMLEncryptionException() ;
}
----------------------------------------*/
if(!( xmlSecEncCtxDecrypt( pEncCtx , pEncryptedData ) < 0 || pEncCtx->result == NULL ))
{
//The decryption succeeds
//Destroy the encryption context
xmlSecEncCtxDestroy( pEncCtx ) ;
pSecEnv->destroyKeysManager( pMngr ) ; //i39448
//get the decrypted element
XMLElementWrapper_XmlSecImpl * ret = new XMLElementWrapper_XmlSecImpl(isParentRef?
......@@ -386,6 +386,15 @@ SAL_CALL XMLEncryption_NssImpl :: decrypt(
//return ret;
aTemplate->setTemplate(ret);
break;
}
else
{
//The decryption fails, continue with the next security environment
xmlSecEncCtxDestroy( pEncCtx ) ;
pSecEnv->destroyKeysManager( pMngr ) ; //i39448
}
}
clearErrorRecorder();
return aTemplate;
......
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