1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: securityenvironment_nssimpl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
37 #include "../diagnose.hxx"
39 using namespace xmlsecurity
;
43 const char * errString
;
48 const ErrDesc allDesc
[] = {
50 #include "certerrors.h"
56 /* Returns a UTF-8 encoded constant error string for "errNum".
57 * Returns NULL of errNum is unknown.
60 getCertError(PRErrorCode errNum
)
62 static char sEmpty
[] = "";
63 const int numDesc
= sizeof(allDesc
) / sizeof(ErrDesc
);
64 for (int i
= 0; i
< numDesc
; i
++)
66 if (allDesc
[i
].errNum
== errNum
)
67 return allDesc
[i
].errString
;
74 printChainFailure(CERTVerifyLog
*log
)
76 unsigned long errorFlags
= 0;
77 unsigned int depth
= (unsigned int)-1;
78 const char * specificError
= NULL
;
79 const char * issuer
= NULL
;
80 CERTVerifyLogNode
*node
= NULL
;
84 xmlsec_trace("Bad certifcation path:");
85 for (node
= log
->head
; node
; node
= node
->next
)
87 if (depth
!= node
->depth
)
90 xmlsec_trace("Certificate: %d. %s %s:", depth
,
91 node
->cert
->subjectName
,
92 depth
? "[Certificate Authority]": "");
94 xmlsec_trace(" ERROR %ld: %s", node
->error
,
95 getCertError(node
->error
));
100 case SEC_ERROR_INADEQUATE_KEY_USAGE
:
101 errorFlags
= (unsigned long)node
->arg
;
104 case KU_DIGITAL_SIGNATURE
:
105 specificError
= "Certificate cannot sign.";
107 case KU_KEY_ENCIPHERMENT
:
108 specificError
= "Certificate cannot encrypt.";
110 case KU_KEY_CERT_SIGN
:
111 specificError
= "Certificate cannot sign other certs.";
114 specificError
= "[unknown usage].";
117 case SEC_ERROR_INADEQUATE_CERT_TYPE
:
118 errorFlags
= (unsigned long)node
->arg
;
121 case NS_CERT_TYPE_SSL_CLIENT
:
122 case NS_CERT_TYPE_SSL_SERVER
:
123 specificError
= "Certificate cannot be used for SSL.";
125 case NS_CERT_TYPE_SSL_CA
:
126 specificError
= "Certificate cannot be used as an SSL CA.";
128 case NS_CERT_TYPE_EMAIL
:
129 specificError
= "Certificate cannot be used for SMIME.";
131 case NS_CERT_TYPE_EMAIL_CA
:
132 specificError
= "Certificate cannot be used as an SMIME CA.";
134 case NS_CERT_TYPE_OBJECT_SIGNING
:
135 specificError
= "Certificate cannot be used for object signing.";
137 case NS_CERT_TYPE_OBJECT_SIGNING_CA
:
138 specificError
= "Certificate cannot be used as an object signing CA.";
141 specificError
= "[unknown usage].";
144 case SEC_ERROR_UNKNOWN_ISSUER
:
145 specificError
= "Unknown issuer:";
146 issuer
= node
->cert
->issuerName
;
148 case SEC_ERROR_UNTRUSTED_ISSUER
:
149 specificError
= "Untrusted issuer:";
150 issuer
= node
->cert
->issuerName
;
152 case SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE
:
153 specificError
= "Expired issuer certificate:";
154 issuer
= node
->cert
->issuerName
;
160 xmlsec_trace("%s", specificError
);
162 xmlsec_trace("%s", issuer
);