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 .
26 #include <sal/macros.h>
28 #include "../diagnose.hxx"
30 using namespace xmlsecurity
;
34 const char * errString
;
39 const ErrDesc allDesc
[] = {
41 #include "certerrors.h"
47 /* Returns a UTF-8 encoded constant error string for "errNum".
48 * Returns NULL of errNum is unknown.
51 getCertError(PRErrorCode errNum
)
53 static char sEmpty
[] = "";
54 const int numDesc
= SAL_N_ELEMENTS(allDesc
);
55 for (int i
= 0; i
< numDesc
; i
++)
57 if (allDesc
[i
].errNum
== errNum
)
58 return allDesc
[i
].errString
;
65 printChainFailure(CERTVerifyLog
*log
)
67 unsigned int depth
= (unsigned int)-1;
68 const char * specificError
= NULL
;
69 const char * issuer
= NULL
;
70 CERTVerifyLogNode
*node
= NULL
;
74 xmlsec_trace("Bad certifcation path:");
75 unsigned long errorFlags
= 0;
76 for (node
= log
->head
; node
; node
= node
->next
)
78 if (depth
!= node
->depth
)
81 xmlsec_trace("Certificate: %d. %s %s:", depth
,
82 node
->cert
->subjectName
,
83 depth
? "[Certificate Authority]": "");
85 xmlsec_trace(" ERROR %ld: %s", node
->error
,
86 getCertError(node
->error
));
91 case SEC_ERROR_INADEQUATE_KEY_USAGE
:
92 errorFlags
= (unsigned long)node
->arg
;
95 case KU_DIGITAL_SIGNATURE
:
96 specificError
= "Certificate cannot sign.";
98 case KU_KEY_ENCIPHERMENT
:
99 specificError
= "Certificate cannot encrypt.";
101 case KU_KEY_CERT_SIGN
:
102 specificError
= "Certificate cannot sign other certs.";
105 specificError
= "[unknown usage].";
109 case SEC_ERROR_INADEQUATE_CERT_TYPE
:
110 errorFlags
= (unsigned long)node
->arg
;
113 case NS_CERT_TYPE_SSL_CLIENT
:
114 case NS_CERT_TYPE_SSL_SERVER
:
115 specificError
= "Certificate cannot be used for SSL.";
117 case NS_CERT_TYPE_SSL_CA
:
118 specificError
= "Certificate cannot be used as an SSL CA.";
120 case NS_CERT_TYPE_EMAIL
:
121 specificError
= "Certificate cannot be used for SMIME.";
123 case NS_CERT_TYPE_EMAIL_CA
:
124 specificError
= "Certificate cannot be used as an SMIME CA.";
126 case NS_CERT_TYPE_OBJECT_SIGNING
:
127 specificError
= "Certificate cannot be used for object signing.";
129 case NS_CERT_TYPE_OBJECT_SIGNING_CA
:
130 specificError
= "Certificate cannot be used as an object signing CA.";
133 specificError
= "[unknown usage].";
137 case SEC_ERROR_UNKNOWN_ISSUER
:
138 specificError
= "Unknown issuer:";
139 issuer
= node
->cert
->issuerName
;
141 case SEC_ERROR_UNTRUSTED_ISSUER
:
142 specificError
= "Untrusted issuer:";
143 issuer
= node
->cert
->issuerName
;
145 case SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE
:
146 specificError
= "Expired issuer certificate:";
147 issuer
= node
->cert
->issuerName
;
153 xmlsec_trace("%s", specificError
);
155 xmlsec_trace("%s", issuer
);
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */