Changeset 617
- Timestamp:
- 09/05/08 16:40:36
- Files:
-
- openpgpsdk/trunk/include/openpgpsdk/create.h (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/errors.h (modified) (1 diff)
- openpgpsdk/trunk/include/openpgpsdk/signature.h (modified) (1 diff)
- openpgpsdk/trunk/src/app/openpgp.c (modified) (14 diffs)
- openpgpsdk/trunk/src/lib/create.c (modified) (4 diffs)
- openpgpsdk/trunk/src/lib/packet-parse.c (modified) (1 diff)
- openpgpsdk/trunk/src/lib/reader_encrypted_seip.c (modified) (2 diffs)
- openpgpsdk/trunk/src/lib/signature.c (modified) (3 diffs)
- openpgpsdk/trunk/tests/test_rsa_signature.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/include/openpgpsdk/create.h
r574 r617 47 47 void ops_create_info_delete(ops_create_info_t *info); 48 48 49 ops_memory_t* ops_write_buf_from_file(const char *filename );49 ops_memory_t* ops_write_buf_from_file(const char *filename, int* errnum); 50 50 int ops_write_file_from_buf(const char *filename, const char* buf, const size_t len, const ops_boolean_t overwrite); 51 51 openpgpsdk/trunk/include/openpgpsdk/errors.h
r610 r617 69 69 OPS_E_V_NO_SIGNATURE =OPS_E_V+2, 70 70 OPS_E_V_UNKNOWN_SIGNER =OPS_E_V+3, 71 OPS_E_V_BAD_HASH =OPS_E_V+4, 71 72 72 73 /* Algorithm support errors */ openpgpsdk/trunk/include/openpgpsdk/signature.h
r573 r617 90 90 ops_boolean_t ops_sign_file_as_cleartext(const char* filename, const ops_secret_key_t *skey, const ops_boolean_t overwrite); 91 91 ops_boolean_t ops_sign_buf_as_cleartext(const char* input, const size_t len, ops_memory_t** output, const ops_secret_key_t *skey); 92 voidops_sign_file(const char* input_filename, const char* output_filename, const ops_secret_key_t *skey, const ops_boolean_t use_armour, const ops_boolean_t overwrite);92 ops_boolean_t ops_sign_file(const char* input_filename, const char* output_filename, const ops_secret_key_t *skey, const ops_boolean_t use_armour, const ops_boolean_t overwrite); 93 93 ops_memory_t * ops_sign_mem(const void* input, const int input_len, const ops_sig_type_t sig_type, const ops_secret_key_t *skey, const ops_boolean_t use_armour); 94 94 openpgpsdk/trunk/src/app/openpgp.c
r616 r617 41 41 #define DEFAULT_NUMBITS 1024 42 42 43 #define MAXBUF 1024 44 43 45 static const char* usage="%s --list-keys | --encrypt | --decrypt | --sign | --clearsign | --verify [--keyring=<keyring>] [--userid=<userid>] [--filename=<filename>] [--armour] [--homedir=<homedir>]\n"; 44 46 static const char* usage_list_keys="%s --list-keys [--keyring=<keyring>]\n"; … … 126 128 127 129 pname=argv[0]; 128 const int maxbuf=1024; 129 char opt_keyring[maxbuf+1]; 130 char opt_userid[maxbuf+1]; 131 char opt_passphrase[maxbuf+1]; 132 char opt_filename[maxbuf+1]; 133 char opt_homedir[maxbuf+1]; 134 // char opt_numbits[maxbuf+1]; 130 char opt_keyring[MAXBUF+1]=""; 131 char opt_userid[MAXBUF+1]=""; 132 char opt_passphrase[MAXBUF+1]=""; 133 char opt_filename[MAXBUF+1]=""; 134 char opt_homedir[MAXBUF+1]=""; 135 135 136 int got_homedir=0; 136 137 int got_keyring=0; … … 140 141 int got_numbits=0; 141 142 int numbits=DEFAULT_NUMBITS; 142 char outputfilename[ maxbuf+1];143 char outputfilename[MAXBUF+1]=""; 143 144 ops_keyring_t* myring=NULL; 144 char myring_name[ maxbuf+1];145 char myring_name[MAXBUF+1]=""; 145 146 ops_keyring_t* pubring=NULL; 146 char pubring_name[ maxbuf+1];147 char pubring_name[MAXBUF+1]=""; 147 148 ops_keyring_t* secring=NULL; 148 char secring_name[ maxbuf+1];149 char secring_name[MAXBUF+1]=""; 149 150 const ops_keydata_t* keydata=NULL; 150 151 char *suffix=NULL; 151 152 char *dir=NULL; 152 char default_homedir[maxbuf+1]; 153 // char full_keyringname[maxbuf+1]; 153 char default_homedir[MAXBUF+1]=""; 154 154 ops_boolean_t overwrite=ops_true; 155 155 ops_keydata_t* mykeydata=NULL; … … 158 158 ops_validate_result_t *validate_result=NULL; 159 159 ops_user_id_t uid; 160 //char line[maxbuf+1];161 //int i=0;162 160 ops_secret_key_t* skey=NULL; 163 161 164 165 memset(opt_keyring,'\0',sizeof(opt_keyring));166 memset(opt_userid,'\0',sizeof(opt_userid));167 memset(opt_passphrase,'\0',sizeof(opt_passphrase));168 memset(opt_filename,'\0',sizeof(opt_filename));169 memset(opt_homedir,'\0',sizeof(opt_homedir));170 171 memset(outputfilename,'\0',sizeof(outputfilename));172 162 173 163 if (argc<2) … … 243 233 case KEYRING: 244 234 assert(optarg); 245 snprintf(opt_keyring, maxbuf,"%s",optarg);235 snprintf(opt_keyring,MAXBUF,"%s",optarg); 246 236 got_keyring=1; 247 237 break; … … 249 239 case USERID: 250 240 assert(optarg); 251 snprintf(opt_userid, maxbuf,"%s",optarg);241 snprintf(opt_userid,MAXBUF,"%s",optarg); 252 242 got_userid=1; 253 243 break; … … 255 245 case PASSPHRASE: 256 246 assert(optarg); 257 snprintf(opt_passphrase, maxbuf,"%s",optarg);247 snprintf(opt_passphrase,MAXBUF,"%s",optarg); 258 248 got_passphrase=1; 259 249 break; … … 261 251 case FILENAME: 262 252 assert(optarg); 263 snprintf(opt_filename, maxbuf,"%s",optarg);253 snprintf(opt_filename,MAXBUF,"%s",optarg); 264 254 got_filename=1; 265 255 break; … … 271 261 case HOMEDIR: 272 262 assert(optarg); 273 snprintf(opt_homedir, maxbuf, "%s", optarg);263 snprintf(opt_homedir, MAXBUF, "%s", optarg); 274 264 got_homedir=1; 275 265 break; … … 278 268 case NUMBITS: 279 269 assert(optarg); 280 sscanf(optarg, "%d", &numbits);270 numbits=atoi(optarg); 281 271 got_numbits=1; 282 272 break; … … 301 291 else 302 292 { 303 snprintf(default_homedir, maxbuf,"%s/.gnupg",getenv("HOME"));293 snprintf(default_homedir,MAXBUF,"%s/.gnupg",getenv("HOME")); 304 294 printf("dir: %s\n", default_homedir); 305 295 dir=default_homedir; 306 296 } 307 297 308 snprintf(pubring_name, maxbuf, "%s/pubring.gpg", dir);298 snprintf(pubring_name, MAXBUF, "%s/pubring.gpg", dir); 309 299 pubring=ops_mallocz(sizeof *pubring); 310 300 if (!ops_keyring_read_from_file(pubring,ops_false,pubring_name)) … … 313 303 exit(-1); 314 304 } 315 snprintf(secring_name, maxbuf, "%s/secring.gpg", dir);305 snprintf(secring_name, MAXBUF, "%s/secring.gpg", dir); 316 306 secring=ops_mallocz(sizeof *secring); 317 307 if (!ops_keyring_read_from_file(secring,ops_false,secring_name)) … … 323 313 if (got_keyring) 324 314 { 325 snprintf(myring_name, maxbuf, "%s/%s", opt_homedir, opt_keyring);315 snprintf(myring_name, MAXBUF, "%s/%s", opt_homedir, opt_keyring); 326 316 myring=ops_mallocz(sizeof *myring); 327 317 if (!ops_keyring_read_from_file(myring,ops_false,myring_name)) … … 485 475 486 476 // outputfilename 487 snprintf(outputfilename, maxbuf,"%s%s", opt_filename,suffix);477 snprintf(outputfilename,MAXBUF,"%s%s", opt_filename,suffix); 488 478 489 479 overwrite=ops_true; openpgpsdk/trunk/src/lib/create.c
r616 r617 1047 1047 } 1048 1048 1049 ops_memory_t* ops_write_buf_from_file(const char *filename) 1049 /** 1050 \ingroup HighLevelAPI 1051 1052 \return allocated memory. If there was an error opening the file or reading from it, errnum is set to the cause 1053 */ 1054 1055 ops_memory_t* ops_write_buf_from_file(const char *filename, int* errnum) 1050 1056 { 1051 1057 size_t initial_size=1024; … … 1053 1059 unsigned char buf[1024]; 1054 1060 ops_memory_t* mem=NULL; 1061 1062 *errnum=0; 1055 1063 1056 1064 #ifdef WIN32 … … 1060 1068 #endif 1061 1069 if (fd < 0) 1070 { 1071 *errnum=errno; 1062 1072 return ops_false; 1073 } 1063 1074 1064 1075 mem=ops_memory_new(); … … 1068 1079 ssize_t n=0; 1069 1080 n=read(fd,buf,1024); 1081 if (n<0) 1082 { 1083 *errnum=errno; 1084 break; 1085 } 1070 1086 if (!n) 1071 1087 break; openpgpsdk/trunk/src/lib/packet-parse.c
r616 r617 2482 2482 if(decrypt) 2483 2483 { 2484 unsigned char buf[OPS_MAX_BLOCK_SIZE+2] ;2484 unsigned char buf[OPS_MAX_BLOCK_SIZE+2]=""; 2485 2485 size_t b=decrypt->blocksize; 2486 2486 // ops_parser_content_t content; openpgpsdk/trunk/src/lib/reader_encrypted_seip.c
r616 r617 149 149 buf[b-2],buf[b-1],buf[b],buf[b+1]); 150 150 OPS_ERROR(errors, OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT,"Bad symmetric decrypt when parsing SE IP packet"); 151 free(buf); 151 152 return -1; 152 153 } … … 185 186 if (memcmp(mdc_hash,hashed,OPS_SHA1_HASH_SIZE)) 186 187 { 187 fprintf(stderr,"Hash is bad\n");188 // ERRP(pinfo,"Bad hash in MDC");188 OPS_ERROR(errors, OPS_E_V_BAD_HASH, "Bad hash in MDC packet"); 189 free(buf); 189 190 return 0; 190 191 } openpgpsdk/trunk/src/lib/signature.c
r616 r617 921 921 } 922 922 923 voidops_sign_file(const char* input_filename, const char* output_filename, const ops_secret_key_t *skey, const ops_boolean_t use_armour, const ops_boolean_t overwrite)923 ops_boolean_t ops_sign_file(const char* input_filename, const char* output_filename, const ops_secret_key_t *skey, const ops_boolean_t use_armour, const ops_boolean_t overwrite) 924 924 { 925 925 // \todo allow choice of hash algorithams … … 941 941 // read input file into buf 942 942 943 mem_buf=ops_write_buf_from_file(input_filename); 943 int errnum; 944 mem_buf=ops_write_buf_from_file(input_filename,&errnum); 945 if (errnum) 946 return ops_false; 944 947 945 948 // setup output filename … … 1007 1010 ops_create_signature_delete(sig); 1008 1011 ops_memory_free(mem_buf); 1012 1013 return ops_true; 1009 1014 } 1010 1015 openpgpsdk/trunk/tests/test_rsa_signature.c
r574 r617 185 185 ops_memory_t *output=NULL; 186 186 ops_boolean_t overwrite; 187 int errnum=0; 187 188 188 189 // setup filenames … … 194 195 195 196 // read file contents 196 input=ops_write_buf_from_file(myfile); 197 input=ops_write_buf_from_file(myfile,&errnum); 198 CU_ASSERT(errnum==0); 197 199 198 200 // sign file
