LCOV - code coverage report
Current view: top level - xmlsecurity/source/xmlsec/nss - sanextension_nssimpl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 80 0.0 %
Date: 2014-11-03 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #include <rtl/uuid.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/PropertyValue.hpp>
      26             : #include <com/sun/star/uno/Reference.hxx>
      27             : #include <comphelper/sequence.hxx>
      28             : #include <seccomon.h>
      29             : #include <cert.h>
      30             : #include <certt.h>
      31             : #include <secitem.h>
      32             : #include <secport.h>
      33             : 
      34             : #include "sanextension_nssimpl.hxx"
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::uno ;
      38             : using namespace ::com::sun::star::security ;
      39             : 
      40             : using ::com::sun::star::security::XCertificateExtension ;
      41             : 
      42             : 
      43           0 : SanExtensionImpl :: SanExtensionImpl() :
      44           0 : m_critical( false )
      45             : {
      46           0 : }
      47             : 
      48           0 : SanExtensionImpl :: ~SanExtensionImpl() {
      49           0 : }
      50             : 
      51             : 
      52             : //Methods from XCertificateExtension
      53           0 : sal_Bool SAL_CALL SanExtensionImpl :: isCritical() throw( ::com::sun::star::uno::RuntimeException, std::exception ) {
      54           0 :     return m_critical ;
      55             : }
      56             : 
      57           0 : ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl :: getExtensionId() throw( ::com::sun::star::uno::RuntimeException, std::exception ) {
      58           0 :     return m_xExtnId ;
      59             : }
      60             : 
      61           0 : ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl :: getExtensionValue() throw( ::com::sun::star::uno::RuntimeException, std::exception ) {
      62           0 :     return m_xExtnValue ;
      63             : }
      64             : 
      65             : namespace {
      66             :     // Helper functions from nss/lib/certdb/genname.c
      67           0 :     static int GetNamesLength(CERTGeneralName *names)
      68             :     {
      69           0 :         int              length = 0;
      70             :         CERTGeneralName  *first;
      71             : 
      72           0 :         first = names;
      73           0 :         if (names != NULL) {
      74           0 :             do {
      75           0 :                 length++;
      76           0 :                 names = CERT_GetNextGeneralName(names);
      77             :             } while (names != first);
      78             :         }
      79           0 :         return length;
      80             :     }
      81             : 
      82             : }
      83             : 
      84             : //Methods from XSanExtension
      85           0 : ::com::sun::star::uno::Sequence< com::sun::star::security::CertAltNameEntry > SAL_CALL SanExtensionImpl :: getAlternativeNames() throw( ::com::sun::star::uno::RuntimeException, std::exception ){
      86             : 
      87           0 :     if (!m_Entries.hasElements())
      88             :     {
      89             :         SECItem item;
      90             : 
      91           0 :         item.type = siDERCertBuffer;
      92           0 :         item.data = (unsigned char*) m_xExtnValue.getArray();
      93           0 :         item.len = m_xExtnValue.getLength();
      94             : 
      95             :         PRArenaPool *arena;
      96             :         CERTGeneralName *nameList;
      97           0 :         arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
      98             : 
      99           0 :         if (!arena)
     100           0 :             return m_Entries;
     101             : 
     102           0 :         nameList = CERT_DecodeAltNameExtension(arena, &item);
     103             : 
     104           0 :         CERTGeneralName* current = nameList;
     105             : 
     106           0 :         int size = GetNamesLength(nameList);
     107           0 :         CertAltNameEntry* arrCertAltNameEntry = new CertAltNameEntry[size];
     108           0 :         for(int i = 0; i < size ; i++){
     109           0 :             switch (current->type) {
     110             :                 case certOtherName: {
     111           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_OTHER_NAME;
     112           0 :                     ::com::sun::star::beans::PropertyValue otherNameProp;
     113           0 :                     otherNameProp.Name = OUString::createFromAscii(CERT_GetOidString(&current->name.OthName.oid));
     114             : 
     115           0 :                     Sequence< sal_Int8 > otherName( current->name.OthName.name.len ) ;
     116           0 :                     for( unsigned int r = 0; r < current->name.OthName.name.len ; r ++ )
     117           0 :                         otherName[r] = *( current->name.OthName.name.data + r ) ;
     118             : 
     119           0 :                     otherNameProp.Value <<= otherName;
     120             : 
     121           0 :                     arrCertAltNameEntry[i].Value <<= otherNameProp;
     122           0 :                     break;
     123             :                                     }
     124             :                 case certRFC822Name:
     125           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_RFC822_NAME;
     126           0 :                     arrCertAltNameEntry[i].Value <<= OUString((const sal_Char*)current->name.other.data, current->name.other.len, RTL_TEXTENCODING_ASCII_US);
     127           0 :                     break;
     128             :                 case certDNSName:
     129           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_DNS_NAME;
     130           0 :                     arrCertAltNameEntry[i].Value <<= OUString((const sal_Char*)current->name.other.data, current->name.other.len, RTL_TEXTENCODING_ASCII_US);
     131           0 :                     break;
     132             :                 case certX400Address: {
     133             :                     // unsupported
     134           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_X400_ADDRESS;
     135           0 :                     break;
     136             :                                       }
     137             :                 case certDirectoryName: {
     138             :                     // unsupported
     139           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_DIRECTORY_NAME;
     140           0 :                     break;
     141             :                                         }
     142             :                 case certEDIPartyName:  {
     143             :                     // unsupported
     144           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_EDI_PARTY_NAME;
     145           0 :                     break;
     146             :                                         }
     147             :                 case certURI:
     148           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_URL;
     149           0 :                     arrCertAltNameEntry[i].Value <<= OUString((const sal_Char*)current->name.other.data, current->name.other.len, RTL_TEXTENCODING_ASCII_US);
     150           0 :                     break;
     151             :                 case certIPAddress: {
     152           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_IP_ADDRESS;
     153             : 
     154           0 :                     Sequence< sal_Int8 > ipAddress( current->name.other.len ) ;
     155           0 :                     for( unsigned int r = 0; r < current->name.other.len ; r ++ )
     156           0 :                         ipAddress[r] = *( current->name.other.data + r ) ;
     157             : 
     158           0 :                     arrCertAltNameEntry[i].Value <<= ipAddress;
     159           0 :                     break;
     160             :                                     }
     161             :                 case certRegisterID:
     162           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_REGISTERED_ID;
     163             : 
     164             : 
     165           0 :                     OString nssOid = OString(CERT_GetOidString(&current->name.other));
     166           0 :                     OString unoOid = removeOIDFromString(nssOid);
     167           0 :                     arrCertAltNameEntry[i].Value <<= OStringToOUString( unoOid, RTL_TEXTENCODING_ASCII_US );
     168           0 :                     break;
     169             :             }
     170           0 :             current = CERT_GetNextGeneralName(current);
     171             :         }
     172             : 
     173           0 :         m_Entries = ::comphelper::arrayToSequence< com::sun::star::security::CertAltNameEntry >(arrCertAltNameEntry, size);
     174             : 
     175           0 :         delete [] arrCertAltNameEntry;
     176             : 
     177           0 :         PORT_FreeArena(arena, PR_FALSE);
     178             : 
     179             : 
     180             :     }
     181             : 
     182           0 :     return m_Entries;
     183             : }
     184             : 
     185           0 : OString SanExtensionImpl :: removeOIDFromString( const OString &oidString)
     186             : {
     187           0 :     OString objID;
     188           0 :     OString oid("OID.");
     189           0 :     if (oidString.match(oid))
     190           0 :         objID = oidString.copy(oid.getLength());
     191             :     else
     192           0 :         objID = oidString;
     193           0 :     return objID;
     194             : 
     195             : }
     196             : 
     197             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10