LCOV - code coverage report
Current view: top level - libreoffice/xmlsecurity/source/xmlsec/nss - sanextension_nssimpl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 89 0.0 %
Date: 2012-12-27 Functions: 0 10 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             : using ::rtl::OUString ;
      40             : 
      41             : using ::com::sun::star::security::XCertificateExtension ;
      42             : 
      43             : 
      44           0 : SanExtensionImpl :: SanExtensionImpl() :
      45           0 : m_critical( sal_False )
      46             : {
      47           0 : }
      48             : 
      49           0 : SanExtensionImpl :: ~SanExtensionImpl() {
      50           0 : }
      51             : 
      52             : 
      53             : //Methods from XCertificateExtension
      54           0 : sal_Bool SAL_CALL SanExtensionImpl :: isCritical() throw( ::com::sun::star::uno::RuntimeException ) {
      55           0 :     return m_critical ;
      56             : }
      57             : 
      58           0 : ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl :: getExtensionId() throw( ::com::sun::star::uno::RuntimeException ) {
      59           0 :     return m_xExtnId ;
      60             : }
      61             : 
      62           0 : ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL SanExtensionImpl :: getExtensionValue() throw( ::com::sun::star::uno::RuntimeException ) {
      63           0 :     return m_xExtnValue ;
      64             : }
      65             : 
      66             : namespace {
      67             :     // Helper functions from nss/lib/certdb/genname.c
      68           0 :     static int GetNamesLength(CERTGeneralName *names)
      69             :     {
      70           0 :         int              length = 0;
      71             :         CERTGeneralName  *first;
      72             : 
      73           0 :         first = names;
      74           0 :         if (names != NULL) {
      75           0 :             do {
      76           0 :                 length++;
      77           0 :                 names = CERT_GetNextGeneralName(names);
      78             :             } while (names != first);
      79             :         }
      80           0 :         return length;
      81             :     }
      82             : 
      83             : }
      84             : 
      85             : //Methods from XSanExtension
      86           0 : ::com::sun::star::uno::Sequence< com::sun::star::security::CertAltNameEntry > SAL_CALL SanExtensionImpl :: getAlternativeNames() throw( ::com::sun::star::uno::RuntimeException ){
      87             : 
      88           0 :     if (!m_Entries.hasElements())
      89             :     {
      90             :         SECItem item;
      91             : 
      92           0 :         item.type = siDERCertBuffer;
      93           0 :         item.data = (unsigned char*) m_xExtnValue.getArray();
      94           0 :         item.len = m_xExtnValue.getLength();
      95             : 
      96             :         PRArenaPool *arena;
      97             :         CERTGeneralName *nameList;
      98           0 :         arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
      99             : 
     100           0 :         if (!arena)
     101           0 :             return m_Entries;
     102             : 
     103           0 :         nameList = CERT_DecodeAltNameExtension(arena, &item);
     104             : 
     105           0 :         CERTGeneralName* current = nameList;
     106             : 
     107           0 :         int size = GetNamesLength(nameList);
     108           0 :         CertAltNameEntry* arrCertAltNameEntry = new CertAltNameEntry[size];
     109           0 :         for(int i = 0; i < size ; i++){
     110           0 :             switch (current->type) {
     111             :                 case certOtherName: {
     112           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_OTHER_NAME;
     113           0 :                     ::com::sun::star::beans::PropertyValue otherNameProp;
     114           0 :                     otherNameProp.Name = ::rtl::OUString::createFromAscii(CERT_GetOidString(&current->name.OthName.oid));
     115             : 
     116           0 :                     Sequence< sal_Int8 > otherName( current->name.OthName.name.len ) ;
     117           0 :                     for( unsigned int r = 0; r < current->name.OthName.name.len ; r ++ )
     118           0 :                         otherName[r] = *( current->name.OthName.name.data + r ) ;
     119             : 
     120           0 :                     otherNameProp.Value <<= otherName;
     121             : 
     122           0 :                     arrCertAltNameEntry[i].Value <<= otherNameProp;
     123           0 :                     break;
     124             :                                     }
     125             :                 case certRFC822Name:
     126           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_RFC822_NAME;
     127           0 :                     arrCertAltNameEntry[i].Value <<= ::rtl::OUString((const sal_Char*)current->name.other.data, current->name.other.len, RTL_TEXTENCODING_ASCII_US);
     128             :                     break;
     129             :                 case certDNSName:
     130           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_DNS_NAME;
     131           0 :                     arrCertAltNameEntry[i].Value <<= ::rtl::OUString((const sal_Char*)current->name.other.data, current->name.other.len, RTL_TEXTENCODING_ASCII_US);
     132             :                     break;
     133             :                 case certX400Address: {
     134             :                     // unsupported
     135           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_X400_ADDRESS;
     136             :                     break;
     137             :                                       }
     138             :                 case certDirectoryName: {
     139             :                     // unsupported
     140           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_DIRECTORY_NAME;
     141             :                     break;
     142             :                                         }
     143             :                 case certEDIPartyName:  {
     144             :                     // unsupported
     145           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_EDI_PARTY_NAME;
     146             :                     break;
     147             :                                         }
     148             :                 case certURI:
     149           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_URL;
     150           0 :                     arrCertAltNameEntry[i].Value <<= ::rtl::OUString((const sal_Char*)current->name.other.data, current->name.other.len, RTL_TEXTENCODING_ASCII_US);
     151             :                     break;
     152             :                 case certIPAddress: {
     153           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_IP_ADDRESS;
     154             : 
     155           0 :                     Sequence< sal_Int8 > ipAddress( current->name.other.len ) ;
     156           0 :                     for( unsigned int r = 0; r < current->name.other.len ; r ++ )
     157           0 :                         ipAddress[r] = *( current->name.other.data + r ) ;
     158             : 
     159           0 :                     arrCertAltNameEntry[i].Value <<= ipAddress;
     160           0 :                     break;
     161             :                                     }
     162             :                 case certRegisterID:
     163           0 :                     arrCertAltNameEntry[i].Type = ExtAltNameType_REGISTERED_ID;
     164             : 
     165             : 
     166           0 :                     rtl::OString nssOid = ::rtl::OString(CERT_GetOidString(&current->name.other));
     167           0 :                     rtl::OString unoOid = removeOIDFromString(nssOid);
     168           0 :                     arrCertAltNameEntry[i].Value <<= rtl::OStringToOUString( unoOid, RTL_TEXTENCODING_ASCII_US );
     169           0 :                     break;
     170             :             }
     171           0 :             current = CERT_GetNextGeneralName(current);
     172             :         }
     173             : 
     174           0 :         m_Entries = ::comphelper::arrayToSequence< com::sun::star::security::CertAltNameEntry >(arrCertAltNameEntry, size);
     175             : 
     176           0 :         delete [] arrCertAltNameEntry;
     177             : 
     178           0 :         PORT_FreeArena(arena, PR_FALSE);
     179             : 
     180             : 
     181             :     }
     182             : 
     183           0 :     return m_Entries;
     184             : }
     185             : 
     186           0 : ::rtl::OString SanExtensionImpl :: removeOIDFromString( const ::rtl::OString &oidString)
     187             : {
     188           0 :     ::rtl::OString objID;
     189           0 :     ::rtl::OString oid("OID.");
     190           0 :     if (oidString.match(oid))
     191           0 :         objID = oidString.copy(oid.getLength());
     192             :     else
     193           0 :         objID = oidString;
     194           0 :     return objID;
     195             : 
     196             : }
     197             : 
     198             : //Helper method
     199           0 : void SanExtensionImpl :: setCertExtn( unsigned char* value, unsigned int vlen, unsigned char* id, unsigned int idlen, sal_Bool critical ) {
     200             :     unsigned int i ;
     201           0 :     if( value != NULL && vlen != 0 ) {
     202           0 :         Sequence< sal_Int8 > extnv( vlen ) ;
     203           0 :         for( i = 0; i < vlen ; i ++ )
     204           0 :             extnv[i] = *( value + i ) ;
     205             : 
     206           0 :         m_xExtnValue = extnv ;
     207             :     } else {
     208           0 :         m_xExtnValue = Sequence<sal_Int8>();
     209             :     }
     210             : 
     211           0 :     if( id != NULL && idlen != 0 ) {
     212           0 :         Sequence< sal_Int8 > extnId( idlen ) ;
     213           0 :         for( i = 0; i < idlen ; i ++ )
     214           0 :             extnId[i] = *( id + i ) ;
     215             : 
     216           0 :         m_xExtnId = extnId ;
     217             :     } else {
     218           0 :         m_xExtnId =  Sequence<sal_Int8>();
     219             :     }
     220             : 
     221           0 :     m_critical = critical ;
     222           0 : }
     223             : 
     224             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10