| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <sal/config.h> |
| 21 |
|
| 22 |
#include <memory> |
| 23 |
|
| 24 |
#include <rtl/uuid.h> |
| 25 |
#include <rtl/ustring.hxx> |
| 26 |
#include <com/sun/star/security/ExtAltNameType.hpp> |
| 27 |
#include <com/sun/star/security/CertAltNameEntry.hpp> |
| 28 |
#include <com/sun/star/beans/NamedValue.hpp> |
| 29 |
#include <comphelper/sequence.hxx> |
| 30 |
#include <o3tl/char16_t2wchar_t.hxx> |
| 31 |
|
| 32 |
#include "sanextension_mscryptimpl.hxx" |
| 33 |
|
| 34 |
using namespace ::com::sun::star; |
| 35 |
using namespace ::com::sun::star::uno ; |
| 36 |
using namespace ::com::sun::star::security ; |
| 37 |
|
| 38 |
using ::com::sun::star::security::XCertificateExtension ; |
| 39 |
|
| 40 |
|
| 41 |
SanExtensionImpl::SanExtensionImpl() : |
| 42 |
m_critical( false ) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
SanExtensionImpl::~SanExtensionImpl() { |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
//Methods from XCertificateExtension |
| 51 |
sal_Bool SAL_CALL SanExtensionImpl::isCritical() { |
| 52 |
return m_critical ; |
| 53 |
} |
| 54 |
|
| 55 |
css::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl::getExtensionId() { |
| 56 |
return m_xExtnId ; |
| 57 |
} |
| 58 |
|
| 59 |
css::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl::getExtensionValue() { |
| 60 |
return m_xExtnValue ; |
| 61 |
} |
| 62 |
|
| 63 |
//Methods from XSanExtension |
| 64 |
css::uno::Sequence< css::security::CertAltNameEntry > SAL_CALL SanExtensionImpl::getAlternativeNames(){ |
| 65 |
|
| 66 |
if (!m_Entries.hasElements()) |
| 67 |
{ |
| 68 |
CERT_ALT_NAME_INFO *subjectName; |
| 69 |
DWORD size; |
| 70 |
CryptDecodeObjectEx(X509_ASN_ENCODING, X509_ALTERNATE_NAME, reinterpret_cast<unsigned char*>(m_xExtnValue.getArray()), m_xExtnValue.getLength(), CRYPT_DECODE_ALLOC_FLAG | CRYPT_DECODE_NOCOPY_FLAG, nullptr,&subjectName, &size); |
| 71 |
|
| 72 |
auto arrCertAltNameEntry = std::make_unique<CertAltNameEntry[]>(subjectName->cAltEntry); |
| 73 |
|
| 74 |
for (unsigned int i = 0; i < static_cast<unsigned int>(subjectName->cAltEntry); i++){ |
| 75 |
PCERT_ALT_NAME_ENTRY pEntry = &subjectName->rgAltEntry[i]; |
| 76 |
|
| 77 |
switch(pEntry->dwAltNameChoice) { |
| 78 |
case CERT_ALT_NAME_OTHER_NAME : |
| 79 |
{ |
| 80 |
arrCertAltNameEntry[i].Type = ExtAltNameType_OTHER_NAME; |
| 81 |
PCERT_OTHER_NAME pOtherName = pEntry->pOtherName; |
| 82 |
|
| 83 |
css::beans::NamedValue otherNameProp; |
| 84 |
otherNameProp.Name = OUString::createFromAscii(pOtherName->pszObjId); |
| 85 |
|
| 86 |
Sequence< sal_Int8 > otherName( comphelper::arrayToSequence<sal_Int8>( |
| 87 |
pOtherName->Value.pbData, pOtherName->Value.cbData) ); |
| 88 |
otherNameProp.Value <<= otherName; |
| 89 |
|
| 90 |
arrCertAltNameEntry[i].Value <<= otherNameProp; |
| 91 |
break; |
| 92 |
} |
| 93 |
case CERT_ALT_NAME_RFC822_NAME : |
| 94 |
arrCertAltNameEntry[i].Type = ExtAltNameType_RFC822_NAME; |
| 95 |
arrCertAltNameEntry[i].Value <<= OUString(o3tl::toU(pEntry->pwszRfc822Name)); |
| 96 |
break; |
| 97 |
case CERT_ALT_NAME_DNS_NAME : |
| 98 |
arrCertAltNameEntry[i].Type = ExtAltNameType_DNS_NAME; |
| 99 |
arrCertAltNameEntry[i].Value <<= OUString(o3tl::toU(pEntry->pwszDNSName)); |
| 100 |
break; |
| 101 |
case CERT_ALT_NAME_DIRECTORY_NAME : |
| 102 |
{ |
| 103 |
arrCertAltNameEntry[i].Type = ExtAltNameType_DIRECTORY_NAME; |
| 104 |
break; |
| 105 |
} |
| 106 |
case CERT_ALT_NAME_URL : |
| 107 |
arrCertAltNameEntry[i].Type = ExtAltNameType_URL; |
| 108 |
arrCertAltNameEntry[i].Value <<= OUString(o3tl::toU(pEntry->pwszURL)); |
| 109 |
break; |
| 110 |
case CERT_ALT_NAME_IP_ADDRESS : |
| 111 |
{ |
| 112 |
arrCertAltNameEntry[i].Type = ExtAltNameType_IP_ADDRESS; |
| 113 |
|
| 114 |
Sequence< sal_Int8 > ipAddress( comphelper::arrayToSequence<sal_Int8>( |
| 115 |
pEntry->IPAddress.pbData, pEntry->IPAddress.cbData) ); |
| 116 |
arrCertAltNameEntry[i].Value <<= ipAddress; |
| 117 |
break; |
| 118 |
} |
| 119 |
case CERT_ALT_NAME_REGISTERED_ID : |
| 120 |
arrCertAltNameEntry[i].Type = ExtAltNameType_REGISTERED_ID; |
| 121 |
arrCertAltNameEntry[i].Value <<= OUString::createFromAscii(pEntry->pszRegisteredID); |
| 122 |
break; |
| 123 |
} |
| 124 |
} |
| 125 |
m_Entries = ::comphelper::arrayToSequence< css::security::CertAltNameEntry >(arrCertAltNameEntry.get(), subjectName->cAltEntry); |
| 126 |
} |
| 127 |
|
| 128 |
return m_Entries; |
| 129 |
} |
| 130 |
|
| 131 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |