File indexing completed on 2023-09-24 04:05:18
0001 /* This file is part of the KDE project 0002 * 0003 * Copyright (C) 2000 George Staikos <staikos@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #if KSSL_HAVE_SSL 0022 #ifndef _kde_ksslcallback_c 0023 #define _kde_ksslcallback_c 0024 0025 X509 *KSSL_X509CallBack_ca; 0026 bool KSSL_X509CallBack_ca_found; 0027 0028 extern "C" { 0029 static int X509Callback(int ok, X509_STORE_CTX *ctx) 0030 { 0031 0032 //qDebug() << "X509Callback: ok = " << ok << " error = " << ctx->error << " depth = " << ctx->error_depth; 0033 // Here is how this works. We put "ok = 1;" in any case that we 0034 // don't consider to be an error. In that case, it will return OK 0035 // for the certificate check as long as there are no other critical 0036 // errors. Don't forget that there can be multiple errors. 0037 // 0038 // Of course we can also put other code in here but any data returned 0039 // back will not be threadsafe ofcourse. 0040 0041 if (KSSL_X509CallBack_ca) { 0042 if (KOSSL::self()->X509_cmp(KOSSL::self()->X509_STORE_CTX_get_current_cert(ctx), KSSL_X509CallBack_ca) != 0) { 0043 return 1; // Ignore errors for this certificate 0044 } 0045 0046 KSSL_X509CallBack_ca_found = true; 0047 } 0048 0049 if (!ok) { 0050 switch (KOSSL::self()->X509_STORE_CTX_get_error(ctx)) { 0051 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: 0052 case X509_V_ERR_UNABLE_TO_GET_CRL: 0053 case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: 0054 case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: 0055 case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: 0056 case X509_V_ERR_CERT_SIGNATURE_FAILURE: 0057 case X509_V_ERR_CRL_SIGNATURE_FAILURE: 0058 case X509_V_ERR_CERT_NOT_YET_VALID: 0059 case X509_V_ERR_CERT_HAS_EXPIRED: 0060 case X509_V_ERR_CRL_NOT_YET_VALID: 0061 case X509_V_ERR_CRL_HAS_EXPIRED: 0062 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: 0063 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: 0064 case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: 0065 case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: 0066 case X509_V_ERR_OUT_OF_MEM: 0067 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: 0068 case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: 0069 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: 0070 case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: 0071 case X509_V_ERR_CERT_CHAIN_TOO_LONG: 0072 case X509_V_ERR_CERT_REVOKED: 0073 case X509_V_ERR_INVALID_CA: 0074 case X509_V_ERR_PATH_LENGTH_EXCEEDED: 0075 case X509_V_ERR_INVALID_PURPOSE: 0076 case X509_V_ERR_CERT_UNTRUSTED: 0077 case X509_V_ERR_CERT_REJECTED: 0078 case X509_V_ERR_APPLICATION_VERIFICATION: 0079 default: 0080 break; 0081 } 0082 } 0083 0084 return (ok); 0085 } 0086 } 0087 0088 #endif 0089 #endif 0090