LCOV - code coverage report
Current view: top level - xmlsecurity/source/xmlsec/nss - secerror.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 58 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 2 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             : 
      21             : #include "secerr.h"
      22             : #include "secerror.hxx"
      23             : #include "sslerr.h"
      24             : #include "nspr.h"
      25             : #include "nss.h"
      26             : #include "certt.h"
      27             : #include <sal/log.hxx>
      28             : #include <sal/macros.h>
      29             : #include <sal/types.h>
      30             : 
      31             : struct ErrDesc {
      32             :     PRErrorCode  errNum;
      33             :     const char * errString;
      34             : };
      35             : 
      36             : 
      37             : 
      38             : const ErrDesc allDesc[] = {
      39             : 
      40             : #include "certerrors.h"
      41             : 
      42             : };
      43             : 
      44             : 
      45             : 
      46             : /* Returns a UTF-8 encoded constant error string for "errNum".
      47             :  * Returns NULL of errNum is unknown.
      48             :  */
      49             : const char *
      50           0 : getCertError(PRErrorCode errNum)
      51             : {
      52             :     static const char sEmpty[] = "";
      53           0 :     const int numDesc = SAL_N_ELEMENTS(allDesc);
      54           0 :     for (int i = 0; i < numDesc; i++)
      55             :     {
      56           0 :         if (allDesc[i].errNum == errNum)
      57           0 :             return  allDesc[i].errString;
      58             :     }
      59             : 
      60           0 :     return sEmpty;
      61             : }
      62             : 
      63             : void
      64           0 : printChainFailure(CERTVerifyLog *log)
      65             : {
      66           0 :     unsigned int       depth  = (unsigned int)-1;
      67           0 :     CERTVerifyLogNode *node   = NULL;
      68             : 
      69           0 :     if (log->count > 0)
      70             :     {
      71             :         SAL_INFO("xmlsecurity.xmlsec", "Bad certifcation path:");
      72           0 :         unsigned long errorFlags  = 0;
      73           0 :         for (node = log->head; node; node = node->next)
      74             :         {
      75           0 :             if (depth != node->depth)
      76             :             {
      77           0 :                 depth = node->depth;
      78             :                 SAL_INFO("xmlsecurity.xmlsec", "Certificate:  " << depth <<
      79             :                          node->cert->subjectName << ": " <<
      80             :                          (depth ? "[Certificate Authority]": ""));
      81             :             }
      82             :             SAL_INFO("xmlsecurity.xmlsec", "  ERROR " << node->error << ": " <<
      83             :                      getCertError(node->error));
      84           0 :             const char * specificError = NULL;
      85           0 :             const char * issuer = NULL;
      86           0 :             switch (node->error)
      87             :             {
      88             :             case SEC_ERROR_INADEQUATE_KEY_USAGE:
      89           0 :                 errorFlags = reinterpret_cast<unsigned long>(node->arg);
      90           0 :                 switch (errorFlags)
      91             :                 {
      92             :                 case KU_DIGITAL_SIGNATURE:
      93           0 :                     specificError = "Certificate cannot sign.";
      94           0 :                     break;
      95             :                 case KU_KEY_ENCIPHERMENT:
      96           0 :                     specificError = "Certificate cannot encrypt.";
      97           0 :                     break;
      98             :                 case KU_KEY_CERT_SIGN:
      99           0 :                     specificError = "Certificate cannot sign other certs.";
     100           0 :                     break;
     101             :                 default:
     102           0 :                     specificError = "[unknown usage].";
     103           0 :                     break;
     104             :                 }
     105           0 :                 break;
     106             :             case SEC_ERROR_INADEQUATE_CERT_TYPE:
     107           0 :                 errorFlags = reinterpret_cast<unsigned long>(node->arg);
     108           0 :                 switch (errorFlags)
     109             :                 {
     110             :                 case NS_CERT_TYPE_SSL_CLIENT:
     111             :                 case NS_CERT_TYPE_SSL_SERVER:
     112           0 :                     specificError = "Certificate cannot be used for SSL.";
     113           0 :                     break;
     114             :                 case NS_CERT_TYPE_SSL_CA:
     115           0 :                     specificError = "Certificate cannot be used as an SSL CA.";
     116           0 :                     break;
     117             :                 case NS_CERT_TYPE_EMAIL:
     118           0 :                     specificError = "Certificate cannot be used for SMIME.";
     119           0 :                     break;
     120             :                 case NS_CERT_TYPE_EMAIL_CA:
     121           0 :                     specificError = "Certificate cannot be used as an SMIME CA.";
     122           0 :                     break;
     123             :                 case NS_CERT_TYPE_OBJECT_SIGNING:
     124           0 :                     specificError = "Certificate cannot be used for object signing.";
     125           0 :                     break;
     126             :                 case NS_CERT_TYPE_OBJECT_SIGNING_CA:
     127           0 :                     specificError = "Certificate cannot be used as an object signing CA.";
     128           0 :                     break;
     129             :                 default:
     130           0 :                     specificError = "[unknown usage].";
     131           0 :                     break;
     132             :                 }
     133           0 :                 break;
     134             :             case SEC_ERROR_UNKNOWN_ISSUER:
     135           0 :                 specificError = "Unknown issuer:";
     136           0 :                 issuer = node->cert->issuerName;
     137           0 :                 break;
     138             :             case SEC_ERROR_UNTRUSTED_ISSUER:
     139           0 :                 specificError = "Untrusted issuer:";
     140           0 :                 issuer = node->cert->issuerName;
     141           0 :                 break;
     142             :             case SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE:
     143           0 :                 specificError = "Expired issuer certificate:";
     144           0 :                 issuer = node->cert->issuerName;
     145           0 :                 break;
     146             :             default:
     147           0 :                 break;
     148             :             }
     149           0 :             if (specificError)
     150             :                 SAL_INFO("xmlsecurity.xmlsec", specificError);
     151           0 :             if (issuer)
     152             :                 SAL_INFO("xmlsecurity.xmlsec", issuer);
     153             :         }
     154             :     }
     155           0 : }
     156             : 
     157             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11