| 99 | | static void test_dsa_signature_clearsign_file(const char *filename, |
|---|
| 100 | | const ops_secret_key_t *skey) |
|---|
| 101 | | { |
|---|
| 102 | | char cmd[MAXBUF+1]; |
|---|
| 103 | | char myfile[MAXBUF+1]; |
|---|
| 104 | | char signed_file[MAXBUF+1]; |
|---|
| | 99 | static void check_sig_with_ops_core(ops_parse_info_t *pinfo, |
|---|
| | 100 | ops_boolean_t use_armour, |
|---|
| | 101 | validate_data_cb_arg_t *validate_arg) |
|---|
| | 102 | { |
|---|
| | 103 | ops_validate_result_t* result=ops_mallocz(sizeof (ops_validate_result_t)); |
|---|
| 106 | | ops_boolean_t overwrite; |
|---|
| 107 | | |
|---|
| 108 | | // setup filenames |
|---|
| 109 | | snprintf(myfile, sizeof myfile, "%s/%s", dir, filename); |
|---|
| 110 | | snprintf(signed_file, sizeof signed_file, "%s.asc", myfile); |
|---|
| 111 | | |
|---|
| 112 | | // sign file |
|---|
| 113 | | overwrite=ops_true; |
|---|
| 114 | | ops_sign_file_as_cleartext(myfile, NULL, skey, overwrite); |
|---|
| 115 | | |
|---|
| 116 | | /* |
|---|
| 117 | | * Validate output |
|---|
| 118 | | */ |
|---|
| 119 | | |
|---|
| 120 | | // Check with OPS |
|---|
| 121 | | |
|---|
| 122 | | { |
|---|
| | 105 | |
|---|
| | 106 | memset(validate_arg, '\0', sizeof *validate_arg); |
|---|
| | 107 | validate_arg->result=result; |
|---|
| | 108 | validate_arg->keyring=&pub_keyring; |
|---|
| | 109 | validate_arg->rarg=ops_reader_get_arg_from_pinfo(pinfo); |
|---|
| | 110 | |
|---|
| | 111 | ops_parse_options(pinfo, OPS_PTAG_SS_ALL, OPS_PARSE_PARSED); |
|---|
| | 112 | pinfo->rinfo.accumulate=ops_true; |
|---|
| | 113 | |
|---|
| | 114 | // Set up armour/passphrase options |
|---|
| | 115 | |
|---|
| | 116 | if (use_armour) |
|---|
| | 117 | ops_reader_push_dearmour(pinfo); |
|---|
| | 118 | |
|---|
| | 119 | // Do the verification |
|---|
| | 120 | |
|---|
| | 121 | rtn=ops_parse_and_print_errors(pinfo); |
|---|
| | 122 | CU_ASSERT(rtn==1); |
|---|
| | 123 | |
|---|
| | 124 | // Tidy up |
|---|
| | 125 | if (use_armour) |
|---|
| | 126 | ops_reader_pop_dearmour(pinfo); |
|---|
| | 127 | |
|---|
| | 128 | ops_parse_info_delete(pinfo); |
|---|
| | 129 | ops_validate_result_free(result); |
|---|
| | 130 | } |
|---|
| | 131 | |
|---|
| | 132 | static void check_sig_with_ops(const char *signed_file) |
|---|
| | 133 | { |
|---|
| | 134 | validate_data_cb_arg_t validate_arg; |
|---|
| 151 | | ops_reader_set_fd(pinfo, fd); |
|---|
| 152 | | pinfo->rinfo.accumulate=ops_true; |
|---|
| 153 | | |
|---|
| 154 | | // Must de-armour because it's clearsigned |
|---|
| 155 | | |
|---|
| 156 | | ops_reader_push_dearmour(pinfo); |
|---|
| 157 | | |
|---|
| 158 | | // Do the verification |
|---|
| 159 | | |
|---|
| 160 | | rtn=ops_parse(pinfo); |
|---|
| 161 | | ops_print_errors(ops_parse_info_get_errors(pinfo)); |
|---|
| 162 | | CU_ASSERT(rtn==1); |
|---|
| 163 | | |
|---|
| 164 | | // Tidy up |
|---|
| 165 | | // if (has_armour) |
|---|
| 166 | | ops_reader_pop_dearmour(pinfo); |
|---|
| 167 | | |
|---|
| 168 | | ops_parse_info_delete(pinfo); |
|---|
| 169 | | |
|---|
| | 153 | |
|---|
| | 154 | check_sig_with_ops_core(pinfo, ops_false, &validate_arg); |
|---|
| | 155 | |
|---|
| | 168 | |
|---|
| | 169 | static void check_sig(const char *signed_file) |
|---|
| | 170 | { |
|---|
| | 171 | check_sig_with_ops(signed_file); |
|---|
| | 172 | check_sig_with_gpg(signed_file); |
|---|
| | 173 | } |
|---|
| | 174 | |
|---|
| | 175 | // make sure myfile and signed_file are big enough |
|---|
| | 176 | static void set_up_file_names(char myfile[MAXBUF], char signed_file[MAXBUF], |
|---|
| | 177 | const char *filename, const char *ext) |
|---|
| | 178 | { |
|---|
| | 179 | snprintf(myfile, MAXBUF, "%s/%s", dir, filename); |
|---|
| | 180 | snprintf(signed_file, MAXBUF, "%s.%s", myfile, ext); |
|---|
| | 181 | } |
|---|
| | 182 | |
|---|
| | 183 | static void test_dsa_signature_clearsign_file(const char *filename, |
|---|
| | 184 | const ops_secret_key_t *skey) |
|---|
| | 185 | { |
|---|
| | 186 | char myfile[MAXBUF]; |
|---|
| | 187 | char signed_file[MAXBUF]; |
|---|
| | 188 | ops_boolean_t overwrite; |
|---|
| | 189 | |
|---|
| | 190 | set_up_file_names(myfile, signed_file, filename, "asc"); |
|---|
| | 191 | |
|---|
| | 192 | // sign file |
|---|
| | 193 | overwrite=ops_true; |
|---|
| | 194 | ops_sign_file_as_cleartext(myfile, NULL, skey, overwrite); |
|---|
| | 195 | |
|---|
| | 196 | // validate output |
|---|
| | 197 | check_sig(signed_file); |
|---|
| 215 | | /* |
|---|
| 216 | | * Validate output |
|---|
| 217 | | */ |
|---|
| 218 | | |
|---|
| 219 | | // Check with OPS |
|---|
| 220 | | |
|---|
| 221 | | { |
|---|
| 222 | | int fd=0; |
|---|
| 223 | | ops_parse_info_t *pinfo=NULL; |
|---|
| 224 | | validate_data_cb_arg_t validate_arg; |
|---|
| 225 | | ops_validate_result_t* result=ops_mallocz(sizeof (ops_validate_result_t)); |
|---|
| 226 | | |
|---|
| 227 | | int rtn=0; |
|---|
| 228 | | |
|---|
| 229 | | if (debug) |
|---|
| 230 | | { |
|---|
| 231 | | fprintf(stderr,"\n***\n*** Starting to parse for validation\n***\n"); |
|---|
| 232 | | } |
|---|
| 233 | | |
|---|
| 234 | | // open signed file |
|---|
| 235 | | fd=open(signed_file,O_RDONLY | O_BINARY); |
|---|
| 236 | | if(fd < 0) |
|---|
| 237 | | { |
|---|
| 238 | | perror(signed_file); |
|---|
| 239 | | exit(2); |
|---|
| 240 | | } |
|---|
| 241 | | |
|---|
| 242 | | // Set verification reader and handling options |
|---|
| 243 | | |
|---|
| 244 | | pinfo=ops_parse_info_new(); |
|---|
| 245 | | |
|---|
| 246 | | memset(&validate_arg, '\0', sizeof validate_arg); |
|---|
| 247 | | validate_arg.result=result; |
|---|
| 248 | | validate_arg.keyring=&pub_keyring; |
|---|
| 249 | | validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo); |
|---|
| 250 | | |
|---|
| 251 | | ops_parse_options(pinfo, OPS_PTAG_SS_ALL, OPS_PARSE_PARSED); |
|---|
| 252 | | ops_parse_cb_set(pinfo, callback_verify, &validate_arg); |
|---|
| 253 | | ops_reader_set_fd(pinfo, fd); |
|---|
| 254 | | pinfo->rinfo.accumulate=ops_true; |
|---|
| 255 | | |
|---|
| 256 | | // Must de-armour because it's clearsigned |
|---|
| 257 | | |
|---|
| 258 | | ops_reader_push_dearmour(pinfo); |
|---|
| 259 | | |
|---|
| 260 | | // Do the verification |
|---|
| 261 | | |
|---|
| 262 | | rtn=ops_parse(pinfo); |
|---|
| 263 | | ops_print_errors(ops_parse_info_get_errors(pinfo)); |
|---|
| 264 | | CU_ASSERT(rtn==1); |
|---|
| 265 | | |
|---|
| 266 | | // Tidy up |
|---|
| 267 | | // if (has_armour) |
|---|
| 268 | | ops_reader_pop_dearmour(pinfo); |
|---|
| 269 | | |
|---|
| 270 | | ops_parse_info_delete(pinfo); |
|---|
| 271 | | |
|---|
| 272 | | close(fd); |
|---|
| 273 | | ops_validate_result_free(result); |
|---|
| 274 | | } |
|---|
| 275 | | |
|---|
| 276 | | // Check signature with GPG |
|---|
| 277 | | { |
|---|
| 278 | | snprintf(cmd, sizeof cmd, "%s --verify %s", gpgcmd, signed_file); |
|---|
| 279 | | rtn=run(cmd); |
|---|
| 280 | | CU_ASSERT(rtn == 0); |
|---|
| 281 | | } |
|---|
| | 227 | // validate output |
|---|
| | 228 | check_sig(signed_file); |
|---|
| 299 | | //ops_sign_file(myfile, NULL, skey, use_armour, overwrite); |
|---|
| 300 | | |
|---|
| 301 | | /* |
|---|
| 302 | | * Validate output |
|---|
| 303 | | */ |
|---|
| 304 | | |
|---|
| 305 | | // Check with OPS |
|---|
| 306 | | |
|---|
| 307 | | { |
|---|
| 308 | | int fd=0; |
|---|
| 309 | | ops_parse_info_t *pinfo=NULL; |
|---|
| 310 | | validate_data_cb_arg_t validate_arg; |
|---|
| 311 | | ops_validate_result_t* result=ops_mallocz(sizeof (ops_validate_result_t));; |
|---|
| 312 | | int rtn=0; |
|---|
| 313 | | |
|---|
| 314 | | if (debug) |
|---|
| 315 | | fprintf(stderr, "\n***\n*** Starting to parse for validation\n***\n"); |
|---|
| 316 | | |
|---|
| 317 | | // open signed file |
|---|
| 318 | | fd=open(signed_file, O_RDONLY | O_BINARY); |
|---|
| 319 | | if(fd < 0) |
|---|
| 320 | | { |
|---|
| 321 | | perror(signed_file); |
|---|
| 322 | | exit(2); |
|---|
| 323 | | } |
|---|
| 324 | | |
|---|
| 325 | | // Set verification reader and handling options |
|---|
| 326 | | |
|---|
| 327 | | pinfo=ops_parse_info_new(); |
|---|
| 328 | | |
|---|
| 329 | | memset(&validate_arg, '\0', sizeof validate_arg); |
|---|
| 330 | | validate_arg.result=result; |
|---|
| 331 | | validate_arg.keyring=&pub_keyring; |
|---|
| 332 | | validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo); |
|---|
| 333 | | |
|---|
| 334 | | ops_parse_options(pinfo, OPS_PTAG_SS_ALL, OPS_PARSE_PARSED); |
|---|
| 335 | | ops_parse_cb_set(pinfo, callback_verify, &validate_arg); |
|---|
| 336 | | ops_reader_set_fd(pinfo, fd); |
|---|
| 337 | | pinfo->rinfo.accumulate=ops_true; |
|---|
| 338 | | |
|---|
| 339 | | // Set up armour/passphrase options |
|---|
| 340 | | |
|---|
| 341 | | if (use_armour) |
|---|
| 342 | | ops_reader_push_dearmour(pinfo); |
|---|
| 343 | | |
|---|
| 344 | | // Do the verification |
|---|
| 345 | | |
|---|
| 346 | | rtn=ops_parse_and_print_errors(pinfo); |
|---|
| 347 | | CU_ASSERT(rtn==1); |
|---|
| 348 | | |
|---|
| 349 | | // Tidy up |
|---|
| 350 | | if (use_armour) |
|---|
| 351 | | ops_reader_pop_dearmour(pinfo); |
|---|
| 352 | | |
|---|
| 353 | | ops_parse_info_delete(pinfo); |
|---|
| 354 | | |
|---|
| 355 | | close(fd); |
|---|
| 356 | | ops_validate_result_free(result); |
|---|
| 357 | | } |
|---|
| 358 | | |
|---|
| 359 | | // Check signature with GPG |
|---|
| 360 | | { |
|---|
| 361 | | snprintf(cmd, sizeof cmd, "%s --verify %s", gpgcmd, signed_file); |
|---|
| 362 | | rtn=run(cmd); |
|---|
| 363 | | CU_ASSERT(rtn == 0); |
|---|
| 364 | | } |
|---|
| | 242 | |
|---|
| | 243 | // validate output |
|---|
| | 244 | check_sig(signed_file); |
|---|
| 398 | | memset(&validate_arg, '\0', sizeof validate_arg); |
|---|
| 399 | | validate_arg.result=result; |
|---|
| 400 | | validate_arg.keyring=&pub_keyring; |
|---|
| 401 | | validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo); |
|---|
| 402 | | |
|---|
| 403 | | ops_parse_options(pinfo, OPS_PTAG_SS_ALL, OPS_PARSE_PARSED); |
|---|
| 404 | | pinfo->rinfo.accumulate=ops_true; |
|---|
| 405 | | |
|---|
| 406 | | // Set up armour/passphrase options |
|---|
| 407 | | |
|---|
| 408 | | if (use_armour) |
|---|
| 409 | | ops_reader_push_dearmour(pinfo); |
|---|
| 410 | | |
|---|
| 411 | | // Do the verification |
|---|
| 412 | | |
|---|
| 413 | | rtn=ops_parse_and_print_errors(pinfo); |
|---|
| 414 | | CU_ASSERT(rtn==1); |
|---|
| 415 | | |
|---|
| 416 | | // Tidy up |
|---|
| 417 | | if (use_armour) |
|---|
| 418 | | ops_reader_pop_dearmour(pinfo); |
|---|
| 419 | | |
|---|
| 420 | | ops_parse_info_delete(pinfo); |
|---|
| | 268 | check_sig_with_ops_core(pinfo, use_armour, &validate_arg); |
|---|
| | 269 | |
|---|