Warning, /pim/kleopatra/tests/test.data.signed-opaque.p7s is written in an unsupported language. File is not indexed.
0001 0 *H 010 + 0 *H $ /* -*- mode: c++; c-basic-offset:4 -*- 0002 tests/test_uiserver.cpp 0003 0004 This file is part of Kleopatra, the KDE keymanager 0005 Copyright (c) 2007 Klarälvdalens Datakonsult AB 0006 0007 Kleopatra is free software; you can redistribute it and/or modify 0008 it under the terms of the GNU General Public License as published by 0009 the Free Software Foundation; either version 2 of the License, or 0010 (at your option) any later version. 0011 0012 Kleopatra is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 General Public License for more details. 0016 0017 You should have received a copy of the GNU General Public License 0018 along with this program; if not, write to the Free Software 0019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0020 0021 In addition, as a special exception, the copyright holders give 0022 permission to link the code of this program with any edition of 0023 the Qt library by Trolltech AS, Norway (or with modified versions 0024 of Qt that use the same license as Qt), and distribute linked 0025 combinations including the two. You must obey the GNU General 0026 Public License in all respects for all of the code used other than 0027 Qt. If you modify this file, you may extend this exception to 0028 your version of the file, but you are not obligated to do so. If 0029 you do not wish to do so, delete this exception statement from 0030 your version. 0031 */ 0032 0033 // 0034 // Usage: test_uiserver <socket> --verify-detached <signed data> <signature> 0035 // 0036 #ifndef _ASSUAN_ONLY_GPG_ERRORS 0037 #define _ASSUAN_ONLY_GPG_ERRORS 0038 #endif 0039 #include "../uiserver/kleo-assuan.h" 0040 #include <gpg-error.h> 0041 0042 #include <QtCore> 0043 0044 #include <unistd.h> 0045 #include <sys/types.h> 0046 #include <sys/stat.h> 0047 #include <fcntl.h> 0048 #include <errno.h> 0049 #include <assert.h> 0050 0051 #include <iostream> 0052 #include <map> 0053 #include <string> 0054 #include <vector> 0055 0056 using namespace Kleo; 0057 0058 static std::vector<int> inFDs, outFDs, msgFDs; 0059 static std::vector<std::string> inFiles, outFiles, msgFiles; 0060 static std::map<std::string,std::string> inquireData; 0061 0062 static std::string hexencode( const std::string & in ) { 0063 std::string result; 0064 result.reserve( 3 * in.size() ); 0065 0066 static const char hex[] = "0123456789ABCDEF"; 0067 0068 for ( std::string::const_iterator it = in.begin(), end = in.end() ; it != end ; ++it ) 0069 switch ( const unsigned char ch = *it ) { 0070 default: 0071 if ( ch >= '!' && ch <= '~' || ch > 0xA0 ) { 0072 result += ch; 0073 break; 0074 } 0075 // else fall through 0076 case ' ': 0077 result += '+'; 0078 break; 0079 case '"': 0080 case '#': 0081 case '$': 0082 case '%': 0083 case '\'': 0084 case '+': 0085 case '=': 0086 result += '%'; 0087 result += hex[ (ch & 0xF0) >> 4 ]; 0088 result += hex[ (ch & 0x0F) ]; 0089 break; 0090 } 0091 0092 return result; 0093 } 0094 0095 static void usage( const std::string & msg=std::string() ) { 0096 std::cerr << msg << std::endl << 0097 "\n" 0098 "Usage: test_uiserver <socket> [<io>] [<options>] [<inquire>] command [<args>]\n" 0099 "where:\n" 0100 " <io>: [--input[-fd] <file>] [--output[-fd] <file>] [--message[-fd] <file>]\n" 0101 " <options>: *[--option name=value]\n" 0102 " <inquire>: [--inquire keyword=<file>]\n"; 0103 exit( 1 ); 0104 } 0105 0106 static int data( void * void_ctx, const void * buffer, size_t len ) { 0107 (void)void_ctx; (void)buffer; (void)len; 0108 return 0; // ### implement me 0109 } 0110 0111 static int status( void * void_ctx, const char * line ) { 0112 (void)void_ctx; (void)line; 0113 return 0; 0114 } 0115 0116 static int inquire( void * void_ctx, const char * keyword ) { 0117 assuan_context_t ctx = (assuan_context_t)void_ctx; 0118 assert( ctx ); 0119 const std::map<std::string,std::string>::const_iterator it = inquireData.find( keyword ); 0120 if ( it == inquireData.end() ) 0121 return gpg_error( GPG_ERR_UNKNOWN_COMMAND ); 0122 0123 if ( !it->second.empty() && it->second[0] == '@' ) 0124 return gpg_error( GPG_E RR_NOT_IMPLEMENTED ); 0125 0126 if ( const gpg_error_t err = assuan_send_data( ctx, it->second.c_str(), it->second.size() ) ) { 0127 qDebug( "assuan_write_data: %s", gpg_strerror( err ) ); 0128 return err; 0129 } 0130 0131 return 0; 0132 } 0133 0134 int main( int argc, char * argv[] ) { 0135 0136 assuan_set_assuan_err_source( GPG_ERR_SOURCE_DEFAULT ); 0137 0138 if ( argc < 3 ) 0139 usage(); // need socket and command, at least 0140 0141 const char * socket = argv[1]; 0142 0143 std::vector<const char*> options; 0144 0145 std::string command; 0146 for ( int optind = 2 ; optind < argc ; ++optind ) { 0147 const char * const arg = argv[optind]; 0148 if ( qstrcmp( arg, "--input-fd" ) == 0 ) { 0149 int inFD; 0150 if ( (inFD = open( argv[++optind], O_RDONLY )) == -1 ) { 0151 perror( "--input-fd open()" ); 0152 return 1; 0153 } 0154 inFDs.push_back( inFD ); 0155 } else if ( qstrcmp( arg, "--output-fd" ) == 0 ) { 0156 int outFD; 0157 if ( (outFD = open( argv[++optind], O_WRONLY|O_CREAT )) == -1 ) { 0158 perror( "--output-fd open()" ); 0159 return 1; 0160 } 0161 outFDs.push_back( outFD ); 0162 } else if ( qstrcmp( arg, "--message-fd" ) == 0 ) { 0163 int msgFD; 0164 if ( (msgFD = open( argv[++optind], O_RDONLY )) == -1 ) { 0165 perror( "--message-fd open()" ); 0166 return 1; 0167 } 0168 msgFDs.push_back( msgFD ); 0169 } else if ( qstrcmp( arg, "--input" ) == 0 ) { 0170 const std::string file = argv[++optind]; 0171 inFiles.push_back( file ); 0172 } else if ( qstrcmp( arg, "--output" ) == 0 ) { 0173 const std::string file = argv[++optind]; 0174 outFiles.push_back( file ); 0175 } else if ( qstrcmp( arg, "--message" ) == 0 ) { 0176 const std::string file = argv[++optind]; 0177 msgFiles.push_back( file ); 0178 } else if ( qstrcmp( arg, "--option" ) == 0 ) { 0179 options.push_back( argv[++optind] ); 0180 } else if ( qstrcmp( arg, "--inquire" ) == 0 ) { 0181 const std::string inqval = argv[++optind]; 0182 const size_t pos = inqval.find( '=' ); 0183 // ### implement indirection with "@file"... 0184 inquireData[inqval.substr( 0, pos )] = inqval.substr( pos+1 ); 0185 } else { 0186 while ( optind < argc ) { 0187 if ( !command.empty() ) 0188 command += ' '; 0189 command += argv[optind++]; 0190 } 0191 } 0192 } 0193 if ( command.empty() ) 0194 usage( "Command expected, but only options found" ); 0195 0196 assuan_context_t ctx = 0; 0197 0198 if ( const gpg_error_t err = assuan_socket_connect_ext( &ctx, socket, -1, 1 ) ) { 0199 qDebug( "%s", assuan_exception( err, "assuan_socket_connect_ext" ).what() ); 0200 return 1; 0201 } 0202 0203 assuan_set_log_stream( ctx, stderr ); 0204 0205 for ( std::vector<int>::const_iterator it = inFDs.begin(), end = inFDs.end() ; it != end ; ++it ) { 0206 if ( const gpg_error_t err = assuan_sendfd( ctx, *it ) ) { 0207 qDebug( "%s", assuan_exception( err, "assuan_sendfd( inFD )" ).what() ); 0208 return 1; 0209 } 0210 0211 if ( const gpg_error_t err = assuan_transact( ctx, "INPUT FD", 0, 0, 0, 0, 0, 0 ) ) { 0212 qDebug( "%s", assuan_exception( err, "INPUT FD" ).what() ); 0213 return 1; 0214 } 0215 } 0216 0217 0218 for ( std::vector<std::string>::const_iterator it = inFiles.begin(), end = inFiles.end() ; it != end ; ++it ) { 0219 char buffer[1024]; 0220 sprintf( buffer, "INPUT FILE=%s", hexencode( *it ).c_str() ); 0221 0222 if ( const gpg_error_t err = assuan_transact( ctx, buffer, 0, 0, 0, 0, 0, 0 ) ) { 0223 qDebug( "%s", assuan_exception( err, buffer ).what() ); 0224 return 1; 0225 } 0226 } 0227 0228 0229 for ( std::vector<int>::const_iterator it = msgFDs.begin(), end = msgFDs.end() ; it != end ; ++it ) { 0230 if ( const gpg_error_t err = assuan_sendfd( ctx, *it ) ) { 0231 qDebug( "%s", assuan_exception( err, "assuan_sendfd( msgFD )" ).what() ); 0232 return 1; 0233 } 0234 0235 if ( const gpg_error_t err $= assuan_transact( ctx, "MESSAGE FD", 0, 0, 0, 0, 0, 0 ) ) { 0236 qDebug( "%s", assuan_exception( err, "MESSAGE FD" ).what() ); 0237 return 1; 0238 } 0239 } 0240 0241 0242 for ( std::vector<std::string>::const_iterator it = msgFiles.begin(), end = msgFiles.end() ; it != end ; ++it ) { 0243 char buffer[1024]; 0244 sprintf( buffer, "MESSAGE FILE=%s", hexencode( *it ).c_str() ); 0245 0246 if ( const gpg_error_t err = assuan_transact( ctx, buffer, 0, 0, 0, 0, 0, 0 ) ) { 0247 qDebug( "%s", assuan_exception( err, buffer ).what() ); 0248 return 1; 0249 } 0250 } 0251 0252 0253 for ( std::vector<int>::const_iterator it = outFDs.begin(), end = outFDs.end() ; it != end ; ++it ) { 0254 if ( const gpg_error_t err = assuan_sendfd( ctx, *it ) ) { 0255 qDebug( "%s", assuan_exception( err, "assuan_sendfd( outFD )" ).what() ); 0256 return 1; 0257 } 0258 0259 if ( const gpg_error_t err = assuan_transact( ctx, "OUTPUT FD", 0, 0, 0, 0, 0, 0 ) ) { 0260 qDebug( "%s", assuan_exception( err, "OUTPUT FD" ).what() ); 0261 return 1; 0262 } 0263 } 0264 0265 0266 for ( std::vector<std::string>::const_iterator it = outFiles.begin(), end = outFiles.end() ; it != end ; ++it ) { 0267 char buffer[1024]; 0268 sprintf( buffer, "OUTPUT FILE=%s", hexencode( *it ).c_str() ); 0269 0270 if ( const gpg_error_t err = assuan_transact( ctx, buffer, 0, 0, 0, 0, 0, 0 ) ) { 0271 qDebug( "%s", assuan_exception( err, buffer ).what() ); 0272 return 1; 0273 } 0274 } 0275 0276 0277 0278 Q_FOREACH( const char * opt, options ) { 0279 std::string line = "OPTION "; 0280 line += opt; 0281 if ( const gpg_error_t err = assuan_transact( ctx, line.c_str(), 0, 0, 0, 0, 0, 0 ) ) { 0282 qDebug( "%s", assuan_exception( err, line ).what() ); 0283 return 1; 0284 } 0285 } 0286 0287 if ( const gpg_error_t err = assuan_transact( ctx, command.c_str(), data, ctx, inquire, ctx, status, ctx ) ) { 0288 qDebug( "%s", assuan_exception( err, command ).what() ); 0289 return 1; 0290 } 0291 0292 assuan_disconnect( ctx ); 0293 0294 return 0; 0295 } 0296 00qN0 *H 0;10 UDE10U 0297 Intevation GmbH10U Test-ZS 50 071011134945Z 081204134945Z0L10 UDE10 0298 U 0299 KDE10U Kleopatra10UKleopatra Test Key0"0 *H 0 0300 K2Ul}pknxRXB"8LmOCB +kqz@DeTQ (A(Q3~QY)*eL^32?H U=#<֟*yIăgї͉Q"J&_-'ϐۜ:)töjoA}]RX][x@~{UU ]DZ 0301 M 00U0 0U0iUb0`0^\ZXldap://ca.intevation.org/cn=Test-ZS 5, o=Intevation GmbH, c=DE?certificateRevocationList0O `HB B@E-Mail Certificates for Intevation and friends (non-production).0U)q~r(o0eU#^0\C6'S9A?0=10 UDE10U 0302 Intevation GmbH10UWurzel ZS 30U0cms@kleo.example.org0 *H "g{ڿKyUSx;_{o1E`L2qnX #i:N!=|x!),_~;x2"}vN`=>Z%ZG2o<d100@0;10 UDE10U 0303 Intevation GmbH10U Test-ZS 5N0+0 *H 1 *H 0 *H 1 071220000001Z0# *H 1\J/{F!(q.W)N0, *H 100 `He 0*H 0 *H N?>H3MԜW^V<\-|xhN9#/9f CeTe'aDWԛZ.S3y-w/Z IJ|Ҭt>xY@K3*BY1H#SFÚj6>^au5?4=e;ty6b|D.Ǽ'\Vqj ^f?%:Y_YaJ$cz߆~~_Q6,rG 1X,