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