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