1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <rtl/ustring.hxx>
23 #include <com/sun/star/security/ExtAltNameType.hpp>
24 #include <com/sun/star/security/CertAltNameEntry.hpp>
25 #include <com/sun/star/beans/NamedValue.hpp>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <comphelper/sequence.hxx>
29 #include "sanextension_mscryptimpl.hxx"
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::security
;
35 using ::com::sun::star::security::XCertificateExtension
;
38 SanExtensionImpl :: SanExtensionImpl() :
39 m_critical( sal_False
)
43 SanExtensionImpl :: ~SanExtensionImpl() {
47 //Methods from XCertificateExtension
48 sal_Bool SAL_CALL
SanExtensionImpl :: isCritical() throw( ::com::sun::star::uno::RuntimeException
) {
52 ::com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
SanExtensionImpl :: getExtensionId() throw( ::com::sun::star::uno::RuntimeException
) {
56 ::com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
SanExtensionImpl :: getExtensionValue() throw( ::com::sun::star::uno::RuntimeException
) {
60 //Methods from XSanExtension
61 ::com::sun::star::uno::Sequence
< com::sun::star::security::CertAltNameEntry
> SAL_CALL
SanExtensionImpl :: getAlternativeNames() throw( ::com::sun::star::uno::RuntimeException
){
63 if (!m_Entries
.hasElements())
65 CERT_ALT_NAME_INFO
*subjectName
;
67 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
);
69 CertAltNameEntry
* arrCertAltNameEntry
= new CertAltNameEntry
[subjectName
->cAltEntry
];
71 for (unsigned int i
= 0; i
< (unsigned int)subjectName
->cAltEntry
; i
++){
72 PCERT_ALT_NAME_ENTRY pEntry
= &subjectName
->rgAltEntry
[i
];
74 switch(pEntry
->dwAltNameChoice
) {
75 case CERT_ALT_NAME_OTHER_NAME
:
77 arrCertAltNameEntry
[i
].Type
= ExtAltNameType_OTHER_NAME
;
78 PCERT_OTHER_NAME pOtherName
= pEntry
->pOtherName
;
80 ::com::sun::star::beans::NamedValue otherNameProp
;
81 otherNameProp
.Name
= OUString::createFromAscii(pOtherName
->pszObjId
);
83 Sequence
< sal_Int8
> otherName( pOtherName
->Value
.cbData
) ;
84 for( unsigned int n
= 0; n
< (unsigned int) pOtherName
->Value
.cbData
; n
++ )
85 otherName
[n
] = *( pOtherName
->Value
.pbData
+ n
) ;
87 otherNameProp
.Value
<<= otherName
;
89 arrCertAltNameEntry
[i
].Value
<<= otherNameProp
;
92 case CERT_ALT_NAME_RFC822_NAME
:
93 arrCertAltNameEntry
[i
].Type
= ExtAltNameType_RFC822_NAME
;
94 arrCertAltNameEntry
[i
].Value
<<= OUString((const sal_Unicode
*)pEntry
->pwszRfc822Name
);
96 case CERT_ALT_NAME_DNS_NAME
:
97 arrCertAltNameEntry
[i
].Type
= ExtAltNameType_DNS_NAME
;
98 arrCertAltNameEntry
[i
].Value
<<= OUString((const sal_Unicode
*)pEntry
->pwszDNSName
);
100 case CERT_ALT_NAME_DIRECTORY_NAME
:
102 arrCertAltNameEntry
[i
].Type
= ExtAltNameType_DIRECTORY_NAME
;
105 case CERT_ALT_NAME_URL
:
106 arrCertAltNameEntry
[i
].Type
= ExtAltNameType_URL
;
107 arrCertAltNameEntry
[i
].Value
<<= OUString((const sal_Unicode
*)pEntry
->pwszURL
);
109 case CERT_ALT_NAME_IP_ADDRESS
:
111 arrCertAltNameEntry
[i
].Type
= ExtAltNameType_IP_ADDRESS
;
113 Sequence
< sal_Int8
> ipAddress( pEntry
->IPAddress
.cbData
) ;
114 for( unsigned int n
= 0; n
< pEntry
->IPAddress
.cbData
; n
++ )
115 ipAddress
[n
] = *( pEntry
->IPAddress
.pbData
+ n
) ;
117 arrCertAltNameEntry
[i
].Value
<<= ipAddress
;
120 case CERT_ALT_NAME_REGISTERED_ID
:
121 arrCertAltNameEntry
[i
].Type
= ExtAltNameType_REGISTERED_ID
;
122 arrCertAltNameEntry
[i
].Value
<<= OUString::createFromAscii(pEntry
->pszRegisteredID
);
126 m_Entries
= ::comphelper::arrayToSequence
< com::sun::star::security::CertAltNameEntry
>(arrCertAltNameEntry
, subjectName
->cAltEntry
);
128 delete [] arrCertAltNameEntry
;
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */