1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmlsecurity.hxx" 26 27 /* 28 * Implementation of the I/O interfaces based on stream and URI binding 29 */ 30 #include "errorcallback.hxx" 31 32 #include <sal/types.h> 33 //For reasons that escape me, this is what xmlsec does when size_t is not 4 34 #if SAL_TYPES_SIZEOFPOINTER != 4 35 # define XMLSEC_NO_SIZE_T 36 #endif 37 #include "xmlsec/xmlsec.h" 38 #include "xmlsec/errors.h" 39 40 using namespace ::com::sun::star::xml::crypto; 41 42 // ::com::sun::star::uno::Reference< XXMLSecurityTemplate > g_xErrorRecorder; 43 // bool g_bErrorRecorded; 44 45 // SecurityOperationStatus getOperationStatus(int reason) 46 // { 47 // switch (reason) 48 // { 49 // case XMLSEC_ERRORS_R_XMLSEC_FAILED: 50 // return SecurityOperationStatus_ENGINE_FAILED; 51 // case XMLSEC_ERRORS_R_MALLOC_FAILED: 52 // return SecurityOperationStatus_MALLOC_FAILED; 53 // case XMLSEC_ERRORS_R_STRDUP_FAILED: 54 // return SecurityOperationStatus_STRDUP_FAILED; 55 // case XMLSEC_ERRORS_R_CRYPTO_FAILED: 56 // return SecurityOperationStatus_CRYPTO_FAILED; 57 // case XMLSEC_ERRORS_R_XML_FAILED: 58 // return SecurityOperationStatus_XML_FAILED; 59 // case XMLSEC_ERRORS_R_XSLT_FAILED: 60 // return SecurityOperationStatus_XSLT_FAILED; 61 // case XMLSEC_ERRORS_R_IO_FAILED: 62 // return SecurityOperationStatus_IO_FAILED; 63 // case XMLSEC_ERRORS_R_DISABLED: 64 // return SecurityOperationStatus_DISABLED; 65 // case XMLSEC_ERRORS_R_NOT_IMPLEMENTED: 66 // return SecurityOperationStatus_NOT_IMPLEMENTED; 67 // case XMLSEC_ERRORS_R_INVALID_SIZE: 68 // return SecurityOperationStatus_INVALID_SIZE; 69 // case XMLSEC_ERRORS_R_INVALID_DATA: 70 // return SecurityOperationStatus_INVALID_DATA; 71 // case XMLSEC_ERRORS_R_INVALID_RESULT: 72 // return SecurityOperationStatus_INVALID_RESULT; 73 // case XMLSEC_ERRORS_R_INVALID_TYPE: 74 // return SecurityOperationStatus_INVALID_TYPE; 75 // case XMLSEC_ERRORS_R_INVALID_OPERATION: 76 // return SecurityOperationStatus_INVALID_OPERATION; 77 // case XMLSEC_ERRORS_R_INVALID_STATUS: 78 // return SecurityOperationStatus_INVALID_STATUS; 79 // case XMLSEC_ERRORS_R_INVALID_FORMAT: 80 // return SecurityOperationStatus_INVALID_FORMAT; 81 // case XMLSEC_ERRORS_R_DATA_NOT_MATCH: 82 // return SecurityOperationStatus_DATA_NOT_MATCH; 83 // case XMLSEC_ERRORS_R_INVALID_NODE: 84 // return SecurityOperationStatus_INVALID_NODE; 85 // case XMLSEC_ERRORS_R_INVALID_NODE_CONTENT: 86 // return SecurityOperationStatus_INVALID_NODE_CONTENT; 87 // case XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE: 88 // return SecurityOperationStatus_INVALID_NODE_ATTRIBUTE; 89 // case XMLSEC_ERRORS_R_MISSING_NODE_ATTRIBUTE: 90 // return SecurityOperationStatus_MISSING_NODE_ATTRIBUTE; 91 // case XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT: 92 // return SecurityOperationStatus_NODE_ALREADY_PRESENT; 93 // case XMLSEC_ERRORS_R_UNEXPECTED_NODE: 94 // return SecurityOperationStatus_UNEXPECTED_NODE; 95 // case XMLSEC_ERRORS_R_NODE_NOT_FOUND: 96 // return SecurityOperationStatus_NODE_NOT_FOUND; 97 // case XMLSEC_ERRORS_R_INVALID_TRANSFORM: 98 // return SecurityOperationStatus_INVALID_TRANSFORM; 99 // case XMLSEC_ERRORS_R_INVALID_TRANSFORM_KEY: 100 // return SecurityOperationStatus_INVALID_TRANSFORM_KEY; 101 // case XMLSEC_ERRORS_R_INVALID_URI_TYPE: 102 // return SecurityOperationStatus_INVALID_URI_TYPE; 103 // case XMLSEC_ERRORS_R_TRANSFORM_SAME_DOCUMENT_REQUIRED: 104 // return SecurityOperationStatus_TRANSFORM_SAME_DOCUMENT_REQUIRED; 105 // case XMLSEC_ERRORS_R_TRANSFORM_DISABLED: 106 // return SecurityOperationStatus_TRANSFORM_DISABLED; 107 // case XMLSEC_ERRORS_R_INVALID_KEY_DATA: 108 // return SecurityOperationStatus_INVALID_KEY_DATA; 109 // case XMLSEC_ERRORS_R_KEY_DATA_NOT_FOUND: 110 // return SecurityOperationStatus_KEY_DATA_NOT_FOUND; 111 // case XMLSEC_ERRORS_R_KEY_DATA_ALREADY_EXIST: 112 // return SecurityOperationStatus_KEY_DATA_ALREADY_EXIST; 113 // case XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE: 114 // return SecurityOperationStatus_INVALID_KEY_DATA_SIZE; 115 // case XMLSEC_ERRORS_R_KEY_NOT_FOUND: 116 // return SecurityOperationStatus_KEY_NOT_FOUND; 117 // case XMLSEC_ERRORS_R_KEYDATA_DISABLED: 118 // return SecurityOperationStatus_KEYDATA_DISABLED; 119 // case XMLSEC_ERRORS_R_MAX_RETRIEVALS_LEVEL: 120 // return SecurityOperationStatus_MAX_RETRIEVALS_LEVEL; 121 // case XMLSEC_ERRORS_R_MAX_RETRIEVAL_TYPE_MISMATCH: 122 // return SecurityOperationStatus_MAX_RETRIEVAL_TYPE_MISMATCH; 123 // case XMLSEC_ERRORS_R_MAX_ENCKEY_LEVEL: 124 // return SecurityOperationStatus_MAX_ENCKEY_LEVEL; 125 // case XMLSEC_ERRORS_R_CERT_VERIFY_FAILED: 126 // return SecurityOperationStatus_CERT_VERIFY_FAILED; 127 // case XMLSEC_ERRORS_R_CERT_NOT_FOUND: 128 // return SecurityOperationStatus_CERT_NOT_FOUND; 129 // case XMLSEC_ERRORS_R_CERT_REVOKED: 130 // return SecurityOperationStatus_CERT_REVOKED; 131 // case XMLSEC_ERRORS_R_CERT_ISSUER_FAILED: 132 // return SecurityOperationStatus_CERT_ISSUER_FAILED; 133 // case XMLSEC_ERRORS_R_CERT_NOT_YET_VALID: 134 // return SecurityOperationStatus_CERT_NOT_YET_VALID; 135 // case XMLSEC_ERRORS_R_CERT_HAS_EXPIRED: 136 // return SecurityOperationStatus_CERT_HAS_EXPIRED; 137 // case XMLSEC_ERRORS_R_DSIG_NO_REFERENCES: 138 // return SecurityOperationStatus_DSIG_NO_REFERENCES; 139 // case XMLSEC_ERRORS_R_DSIG_INVALID_REFERENCE: 140 // return SecurityOperationStatus_DSIG_INVALID_REFERENCE; 141 // case XMLSEC_ERRORS_R_ASSERTION: 142 // return SecurityOperationStatus_ASSERTION; 143 // default: 144 // return SecurityOperationStatus_RUNTIMEERROR_FAILED; 145 // } 146 // } 147 148 149 extern "C" 150 void errorCallback(const char * /*file*/, 151 int /*line*/, 152 const char * /*func*/, 153 const char * /*errorObject*/, 154 const char * /*errorSubject*/, 155 int /*reason*/, 156 const char * /*msg*/) 157 { 158 #if OSL_DEBUG_LEVEL > 1 159 // const char * afunc = func ? func : ""; 160 // const char * errObj = errorObject ? errorObject : ""; 161 // const char * errSub = errorSubject ? errorSubject : ""; 162 // const char * amsg = msg ? msg : ""; 163 // fprintf(stdout, "xmlsec error: %s, %s, %s, %i %s \n", afunc, errObj, errSub, reason, amsg); 164 #endif 165 //ToDo write log message 166 // if (g_xErrorRecorder.is() && !g_bErrorRecorded) 167 // { 168 // g_xErrorRecorder->setStatus(getOperationStatus(reason)); 169 170 // if ( reason != XMLSEC_ERRORS_R_ASSERTION && reason!=XMLSEC_ERRORS_R_XMLSEC_FAILED) 171 // { 172 // g_bErrorRecorded = true; 173 // } 174 // } 175 } 176 177 // void setErrorRecorder(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSecurityTemplate >& xTemplate) 178 // { 179 // g_xErrorRecorder = xTemplate; 180 // g_xErrorRecorder->setStatus(SecurityOperationStatus_OPERATION_SUCCEEDED); 181 // g_bErrorRecorded = false; 182 // xmlSecErrorsSetCallback(errorCallback); 183 // } 184 185 //void setErrorRecorder(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSignatureTemplate >& xTemplate) 186 187 void setErrorRecorder() 188 { 189 // ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSecurityTemplate > 190 // xSecurityTemplate(xTemplate, ::com::sun::star::uno::UNO_QUERY); 191 // setErrorRecorder( xSecurityTemplate ); 192 xmlSecErrorsSetCallback(errorCallback); 193 } 194 195 // void setErrorRecorder(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLEncryptionTemplate >& xTemplate) 196 // { 197 // ::com::sun::star::uno::Reference< ::com::sun::star::xml::crypto::XXMLSecurityTemplate > 198 // xSecurityTemplate(xTemplate, ::com::sun::star::uno::UNO_QUERY); 199 // setErrorRecorder( xSecurityTemplate ); 200 // } 201 202 void clearErrorRecorder() 203 { 204 xmlSecErrorsSetCallback(NULL); 205 // g_xErrorRecorder = NULL; 206 } 207 208