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