1*c82f2877SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*c82f2877SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c82f2877SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c82f2877SAndrew Rist * distributed with this work for additional information 6*c82f2877SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c82f2877SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c82f2877SAndrew Rist * "License"); you may not use this file except in compliance 9*c82f2877SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*c82f2877SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*c82f2877SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c82f2877SAndrew Rist * software distributed under the License is distributed on an 15*c82f2877SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c82f2877SAndrew Rist * KIND, either express or implied. See the License for the 17*c82f2877SAndrew Rist * specific language governing permissions and limitations 18*c82f2877SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*c82f2877SAndrew Rist *************************************************************/ 21*c82f2877SAndrew Rist 22*c82f2877SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx" 26cdf0e10cSrcweir #include <sal/config.h> 27cdf0e10cSrcweir #include <rtl/uuid.h> 28cdf0e10cSrcweir #include <rtl/ustring.hxx> 29cdf0e10cSrcweir #include <com/sun/star/security/ExtAltNameType.hpp> 30cdf0e10cSrcweir #include <com/sun/star/security/CertAltNameEntry.hpp> 31cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 32cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 33cdf0e10cSrcweir #include <comphelper/sequence.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweir #ifndef _SANEXTENSION_MSCRYPTIMPL_HXX_ 37cdf0e10cSrcweir #include "sanextension_mscryptimpl.hxx" 38cdf0e10cSrcweir #endif 39cdf0e10cSrcweir 40cdf0e10cSrcweir using namespace ::com::sun::star; 41cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 42cdf0e10cSrcweir using namespace ::com::sun::star::security ; 43cdf0e10cSrcweir using ::rtl::OUString ; 44cdf0e10cSrcweir 45cdf0e10cSrcweir using ::com::sun::star::security::XCertificateExtension ; 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir SanExtensionImpl :: SanExtensionImpl() : 49cdf0e10cSrcweir m_critical( sal_False ) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir SanExtensionImpl :: ~SanExtensionImpl() { 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir 57cdf0e10cSrcweir //Methods from XCertificateExtension 58cdf0e10cSrcweir sal_Bool SAL_CALL SanExtensionImpl :: isCritical() throw( ::com::sun::star::uno::RuntimeException ) { 59cdf0e10cSrcweir return m_critical ; 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl :: getExtensionId() throw( ::com::sun::star::uno::RuntimeException ) { 63cdf0e10cSrcweir return m_xExtnId ; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl :: getExtensionValue() throw( ::com::sun::star::uno::RuntimeException ) { 67cdf0e10cSrcweir return m_xExtnValue ; 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir //Methods from XSanExtension 71cdf0e10cSrcweir ::com::sun::star::uno::Sequence< com::sun::star::security::CertAltNameEntry > SAL_CALL SanExtensionImpl :: getAlternativeNames() throw( ::com::sun::star::uno::RuntimeException ){ 72cdf0e10cSrcweir 73cdf0e10cSrcweir if (!m_Entries.hasElements()) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir CERT_ALT_NAME_INFO *subjectName; 76cdf0e10cSrcweir DWORD size; 77cdf0e10cSrcweir CryptDecodeObjectEx(X509_ASN_ENCODING, X509_ALTERNATE_NAME, (unsigned char*) m_xExtnValue.getArray(), m_xExtnValue.getLength(), CRYPT_DECODE_ALLOC_FLAG | CRYPT_DECODE_NOCOPY_FLAG, NULL,&subjectName, &size); 78cdf0e10cSrcweir 79cdf0e10cSrcweir CertAltNameEntry* arrCertAltNameEntry = new CertAltNameEntry[subjectName->cAltEntry]; 80cdf0e10cSrcweir 81cdf0e10cSrcweir for (unsigned int i = 0; i < (unsigned int)subjectName->cAltEntry; i++){ 82cdf0e10cSrcweir PCERT_ALT_NAME_ENTRY pEntry = &subjectName->rgAltEntry[i]; 83cdf0e10cSrcweir 84cdf0e10cSrcweir switch(pEntry->dwAltNameChoice) { 85cdf0e10cSrcweir case CERT_ALT_NAME_OTHER_NAME : 86cdf0e10cSrcweir { 87cdf0e10cSrcweir arrCertAltNameEntry[i].Type = ExtAltNameType_OTHER_NAME; 88cdf0e10cSrcweir PCERT_OTHER_NAME pOtherName = pEntry->pOtherName; 89cdf0e10cSrcweir 90cdf0e10cSrcweir ::com::sun::star::beans::NamedValue otherNameProp; 91cdf0e10cSrcweir otherNameProp.Name = ::rtl::OUString::createFromAscii(pOtherName->pszObjId); 92cdf0e10cSrcweir 93cdf0e10cSrcweir Sequence< sal_Int8 > otherName( pOtherName->Value.cbData ) ; 94cdf0e10cSrcweir for( unsigned int n = 0; n < (unsigned int) pOtherName->Value.cbData ; n ++ ) 95cdf0e10cSrcweir otherName[n] = *( pOtherName->Value.pbData + n ) ; 96cdf0e10cSrcweir 97cdf0e10cSrcweir otherNameProp.Value <<= otherName; 98cdf0e10cSrcweir 99cdf0e10cSrcweir arrCertAltNameEntry[i].Value <<= otherNameProp; 100cdf0e10cSrcweir break; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir case CERT_ALT_NAME_RFC822_NAME : 103cdf0e10cSrcweir arrCertAltNameEntry[i].Type = ExtAltNameType_RFC822_NAME; 104cdf0e10cSrcweir arrCertAltNameEntry[i].Value <<= ::rtl::OUString((const sal_Unicode*)pEntry->pwszRfc822Name); 105cdf0e10cSrcweir break; 106cdf0e10cSrcweir case CERT_ALT_NAME_DNS_NAME : 107cdf0e10cSrcweir arrCertAltNameEntry[i].Type = ExtAltNameType_DNS_NAME; 108cdf0e10cSrcweir arrCertAltNameEntry[i].Value <<= ::rtl::OUString((const sal_Unicode*)pEntry->pwszDNSName); 109cdf0e10cSrcweir break; 110cdf0e10cSrcweir case CERT_ALT_NAME_DIRECTORY_NAME : 111cdf0e10cSrcweir { 112cdf0e10cSrcweir arrCertAltNameEntry[i].Type = ExtAltNameType_DIRECTORY_NAME; 113cdf0e10cSrcweir break; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir case CERT_ALT_NAME_URL : 116cdf0e10cSrcweir arrCertAltNameEntry[i].Type = ExtAltNameType_URL; 117cdf0e10cSrcweir arrCertAltNameEntry[i].Value <<= ::rtl::OUString((const sal_Unicode*)pEntry->pwszURL); 118cdf0e10cSrcweir break; 119cdf0e10cSrcweir case CERT_ALT_NAME_IP_ADDRESS : 120cdf0e10cSrcweir { 121cdf0e10cSrcweir arrCertAltNameEntry[i].Type = ExtAltNameType_IP_ADDRESS; 122cdf0e10cSrcweir 123cdf0e10cSrcweir Sequence< sal_Int8 > ipAddress( pEntry->IPAddress.cbData ) ; 124cdf0e10cSrcweir for( unsigned int n = 0; n < pEntry->IPAddress.cbData ; n ++ ) 125cdf0e10cSrcweir ipAddress[n] = *( pEntry->IPAddress.pbData + n ) ; 126cdf0e10cSrcweir 127cdf0e10cSrcweir arrCertAltNameEntry[i].Value <<= ipAddress; 128cdf0e10cSrcweir break; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir case CERT_ALT_NAME_REGISTERED_ID : 131cdf0e10cSrcweir arrCertAltNameEntry[i].Type = ExtAltNameType_REGISTERED_ID; 132cdf0e10cSrcweir arrCertAltNameEntry[i].Value <<= ::rtl::OUString::createFromAscii(pEntry->pszRegisteredID); 133cdf0e10cSrcweir break; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir m_Entries = ::comphelper::arrayToSequence< com::sun::star::security::CertAltNameEntry >(arrCertAltNameEntry, subjectName->cAltEntry); 137cdf0e10cSrcweir 138cdf0e10cSrcweir delete [] arrCertAltNameEntry; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir return m_Entries; 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir //Helper method 145cdf0e10cSrcweir void SanExtensionImpl :: setCertExtn( ::com::sun::star::uno::Sequence< sal_Int8 > extnId, ::com::sun::star::uno::Sequence< sal_Int8 > extnValue, sal_Bool critical ) { 146cdf0e10cSrcweir m_critical = critical ; 147cdf0e10cSrcweir m_xExtnId = extnId ; 148cdf0e10cSrcweir m_xExtnValue = extnValue ; 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir void SanExtensionImpl :: setCertExtn( unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, sal_Bool critical ) { 152cdf0e10cSrcweir unsigned int i ; 153cdf0e10cSrcweir if( value != NULL && vlen != 0 ) { 154cdf0e10cSrcweir Sequence< sal_Int8 > extnv( vlen ) ; 155cdf0e10cSrcweir for( i = 0; i < vlen ; i ++ ) 156cdf0e10cSrcweir extnv[i] = *( value + i ) ; 157cdf0e10cSrcweir 158cdf0e10cSrcweir m_xExtnValue = extnv ; 159cdf0e10cSrcweir } else { 160cdf0e10cSrcweir m_xExtnValue = Sequence<sal_Int8>(); 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir if( id != NULL && idlen != 0 ) { 164cdf0e10cSrcweir Sequence< sal_Int8 > extnId( idlen ) ; 165cdf0e10cSrcweir for( i = 0; i < idlen ; i ++ ) 166cdf0e10cSrcweir extnId[i] = *( id + i ) ; 167cdf0e10cSrcweir 168cdf0e10cSrcweir m_xExtnId = extnId ; 169cdf0e10cSrcweir } else { 170cdf0e10cSrcweir m_xExtnId = Sequence<sal_Int8>(); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir m_critical = critical ; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir void SanExtensionImpl :: extractCertExt () { 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179