summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2017-09-26 11:28:57 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2017-09-30 11:23:41 +0200
commit362a21d3a129b90149f6ef645c127f5e86e0ba61 (patch)
tree8583cb29b33de56e4489cb8950d2714a1fb2957e /xmlsecurity
parent81ce629c9e8a4fc26ded9d49157e3f3263991e03 (diff)
Use explicit function names for fooA/fooW WinAPI; prefer fooW
We should only use generic foo function name when it takes params that are also dependent on UNICODE define, like LoadCursor( nullptr, IDC_ARROW ) where IDC_ARROW is defined in MSVC headers synchronised with LoadCursor definition. We should always use Unicode API for any file paths operations, because otherwise we will get "?" for any character in path that is not in current non-unicode codepage, which will result in failed file operations. Change-Id: I3a7f453ca0f893002d8a9764318919709fd8b633 Reviewed-on: https://gerrit.libreoffice.org/42935 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx26
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.cxx5
-rw-r--r--xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx41
3 files changed, 30 insertions, 42 deletions
diff --git a/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx
index 8df7520a9897..44b430fe939a 100644
--- a/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx
+++ b/xmlsecurity/source/xmlsec/mscrypt/securityenvironment_mscryptimpl.cxx
@@ -372,7 +372,7 @@ Sequence< Reference < XCertificate > > SecurityEnvironment_MSCryptImpl::getPerso
CertEnumSystemStore(CERT_SYSTEM_STORE_CURRENT_USER, nullptr, nullptr, cert_enum_system_store_callback);
#endif
- hSystemKeyStore = CertOpenSystemStore( 0, "MY" ) ;
+ hSystemKeyStore = CertOpenSystemStoreW( 0, L"MY" ) ;
if( hSystemKeyStore != nullptr ) {
pCertContext = CertEnumCertificatesInStore( hSystemKeyStore, pCertContext );
while (pCertContext)
@@ -420,7 +420,6 @@ Sequence< Reference < XCertificate > > SecurityEnvironment_MSCryptImpl::getPerso
Reference< XCertificate > SecurityEnvironment_MSCryptImpl::getCertificate( const OUString& issuerName, const Sequence< sal_Int8 >& serialNumber ) {
unsigned int i ;
- LPCSTR pszName ;
X509Certificate_MSCryptImpl *xcert = nullptr ;
PCCERT_CONTEXT pCertContext = nullptr ;
HCERTSTORE hCertStore = nullptr ;
@@ -434,10 +433,9 @@ Reference< XCertificate > SecurityEnvironment_MSCryptImpl::getCertificate( const
encoding = osl_getTextEncodingFromLocale( pLocale ) ;
//Create cert info from issue and serial
- OString oissuer = OUStringToOString( issuerName , encoding ) ;
- pszName = oissuer.getStr() ;
+ LPCWSTR pszName = SAL_W( issuerName.getStr() );
- if( ! ( CertStrToName(
+ if( ! ( CertStrToNameW(
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
pszName ,
CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG | CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG,
@@ -452,7 +450,7 @@ Reference< XCertificate > SecurityEnvironment_MSCryptImpl::getCertificate( const
if(!certInfo.Issuer.pbData)
throw RuntimeException() ;
- if( ! ( CertStrToName(
+ if( ! ( CertStrToNameW(
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
pszName ,
CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG | CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG,
@@ -492,19 +490,19 @@ Reference< XCertificate > SecurityEnvironment_MSCryptImpl::getCertificate( const
hCertStore = m_hCertStore ;
break;
case 2:
- hCertStore = CertOpenSystemStore( 0, "MY" ) ;
+ hCertStore = CertOpenSystemStoreW( 0, L"MY" ) ;
if(hCertStore == nullptr || !m_bEnableDefault) continue ;
break;
case 3:
- hCertStore = CertOpenSystemStore( 0, "Root" ) ;
+ hCertStore = CertOpenSystemStoreW( 0, L"Root" ) ;
if(hCertStore == nullptr || !m_bEnableDefault) continue ;
break;
case 4:
- hCertStore = CertOpenSystemStore( 0, "Trust" ) ;
+ hCertStore = CertOpenSystemStoreW( 0, L"Trust" ) ;
if(hCertStore == nullptr || !m_bEnableDefault) continue ;
break;
case 5:
- hCertStore = CertOpenSystemStore( 0, "CA" ) ;
+ hCertStore = CertOpenSystemStoreW( 0, L"CA" ) ;
if(hCertStore == nullptr || !m_bEnableDefault) continue ;
break;
default:
@@ -1055,7 +1053,7 @@ xmlSecKeysMngrPtr SecurityEnvironment_MSCryptImpl::createKeysManager() {
*/
if( defaultEnabled() ) {
//Add system key store into the keys manager.
- m_hMySystemStore = CertOpenSystemStore( 0, "MY" ) ;
+ m_hMySystemStore = CertOpenSystemStoreW( 0, L"MY" ) ;
if( m_hMySystemStore != nullptr ) {
if( xmlSecMSCryptoAppliedKeysMngrAdoptKeyStore( pKeysMngr, m_hMySystemStore ) < 0 ) {
CertCloseStore( m_hMySystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
@@ -1065,7 +1063,7 @@ xmlSecKeysMngrPtr SecurityEnvironment_MSCryptImpl::createKeysManager() {
}
//Add system root store into the keys manager.
- m_hRootSystemStore = CertOpenSystemStore( 0, "Root" ) ;
+ m_hRootSystemStore = CertOpenSystemStoreW( 0, L"Root" ) ;
if( m_hRootSystemStore != nullptr ) {
if( xmlSecMSCryptoAppliedKeysMngrAdoptTrustedStore( pKeysMngr, m_hRootSystemStore ) < 0 ) {
CertCloseStore( m_hRootSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
@@ -1075,7 +1073,7 @@ xmlSecKeysMngrPtr SecurityEnvironment_MSCryptImpl::createKeysManager() {
}
//Add system trusted store into the keys manager.
- m_hTrustSystemStore = CertOpenSystemStore( 0, "Trust" ) ;
+ m_hTrustSystemStore = CertOpenSystemStoreW( 0, L"Trust" ) ;
if( m_hTrustSystemStore != nullptr ) {
if( xmlSecMSCryptoAppliedKeysMngrAdoptUntrustedStore( pKeysMngr, m_hTrustSystemStore ) < 0 ) {
CertCloseStore( m_hTrustSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
@@ -1085,7 +1083,7 @@ xmlSecKeysMngrPtr SecurityEnvironment_MSCryptImpl::createKeysManager() {
}
//Add system CA store into the keys manager.
- m_hCaSystemStore = CertOpenSystemStore( 0, "CA" ) ;
+ m_hCaSystemStore = CertOpenSystemStoreW( 0, L"CA" ) ;
if( m_hCaSystemStore != nullptr ) {
if( xmlSecMSCryptoAppliedKeysMngrAdoptUntrustedStore( pKeysMngr, m_hCaSystemStore ) < 0 ) {
CertCloseStore( m_hCaSystemStore, CERT_CLOSE_STORE_CHECK_FLAG ) ;
diff --git a/xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.cxx
index 72b50e292079..6fd3bdc85c24 100644
--- a/xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.cxx
+++ b/xmlsecurity/source/xmlsec/mscrypt/seinitializer_mscryptimpl.cxx
@@ -50,13 +50,14 @@ cssu::Reference< cssxc::XXMLSecurityContext > SAL_CALL
{
const char* n_pCertStore ;
HCERTSTORE n_hStoreHandle ;
+ OString sCertDir;
//Initialize the crypto engine
if( sCertDB.getLength() > 0 )
{
- OString sCertDir(sCertDB.getStr(), sCertDB.getLength(), RTL_TEXTENCODING_ASCII_US);
+ sCertDir = OString(sCertDB.getStr(), sCertDB.getLength(), RTL_TEXTENCODING_ASCII_US);
n_pCertStore = sCertDir.getStr();
- n_hStoreHandle = CertOpenSystemStore( NULL, n_pCertStore ) ;
+ n_hStoreHandle = CertOpenSystemStoreW( NULL, SAL_W(sCertDB.getStr())) ;
if( n_hStoreHandle == nullptr )
{
return nullptr;
diff --git a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx
index 7fcc699b8a25..c45b541cf3d7 100644
--- a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx
+++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx
@@ -205,9 +205,7 @@ css::uno::Sequence< sal_Int8 > SAL_CALL X509Certificate_MSCryptImpl::getSerialNu
OUString SAL_CALL X509Certificate_MSCryptImpl::getIssuerName() {
if( m_pCertContext != nullptr && m_pCertContext->pCertInfo != nullptr ) {
- DWORD cbIssuer ;
-
- cbIssuer = CertNameToStr(
+ DWORD cchIssuer = CertNameToStrW(
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
&( m_pCertContext->pCertInfo->Issuer ),
CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG ,
@@ -215,28 +213,22 @@ OUString SAL_CALL X509Certificate_MSCryptImpl::getIssuerName() {
) ;
// Here the cbIssuer count the last 0x00 , take care.
- if( cbIssuer != 0 ) {
- auto issuer = std::unique_ptr<char[]>(new char[ cbIssuer ]);
+ if( cchIssuer != 0 ) {
+ auto issuer = std::unique_ptr<wchar_t[]>(new wchar_t[ cchIssuer ]);
- cbIssuer = CertNameToStr(
+ cchIssuer = CertNameToStrW(
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
&( m_pCertContext->pCertInfo->Issuer ),
CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG ,
- issuer.get(), cbIssuer
+ issuer.get(), cchIssuer
) ;
- if( cbIssuer <= 0 ) {
+ if( cchIssuer <= 0 ) {
throw RuntimeException() ;
}
- // for correct encoding
- sal_uInt16 encoding ;
- rtl_Locale *pLocale = nullptr ;
- osl_getProcessLocale( &pLocale ) ;
- encoding = osl_getTextEncodingFromLocale( pLocale ) ;
-
- if(issuer.get()[cbIssuer-1] == 0) cbIssuer--; //delimit the last 0x00;
- OUString xIssuer(issuer.get() , cbIssuer ,encoding ) ;
+ if(issuer.get()[cchIssuer -1] == 0) cchIssuer--; //delimit the last 0x00;
+ OUString xIssuer(SAL_U(issuer.get()), cchIssuer) ;
return replaceTagSWithTagST(xIssuer);
} else {
@@ -251,32 +243,29 @@ OUString SAL_CALL X509Certificate_MSCryptImpl::getSubjectName()
{
if( m_pCertContext != nullptr && m_pCertContext->pCertInfo != nullptr )
{
- DWORD cbSubject ;
-
- cbSubject = CertNameToStrW(
+ DWORD cchSubject = CertNameToStrW(
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
&( m_pCertContext->pCertInfo->Subject ),
CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG ,
nullptr, 0
) ;
- if( cbSubject != 0 )
+ if( cchSubject != 0 )
{
- auto subject = std::unique_ptr<wchar_t[]>(new wchar_t[ cbSubject ]);
+ auto subject = std::unique_ptr<wchar_t[]>(new wchar_t[ cchSubject ]);
- cbSubject = CertNameToStrW(
+ cchSubject = CertNameToStrW(
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ,
&( m_pCertContext->pCertInfo->Subject ),
CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG ,
- subject.get(), cbSubject
+ subject.get(), cchSubject
) ;
- if( cbSubject <= 0 ) {
+ if( cchSubject <= 0 ) {
throw RuntimeException() ;
}
- OUString xSubject(
- reinterpret_cast<const sal_Unicode*>(subject.get()));
+ OUString xSubject(SAL_U(subject.get()));
return replaceTagSWithTagST(xSubject);
} else