Changeset 527
- Timestamp:
- 12/12/07 11:24:01
- Files:
-
- openpgpsdk/trunk/examples/packet-dump.c (modified) (2 diffs)
- openpgpsdk/trunk/include/openpgpsdk/errors.h (modified) (1 diff)
- openpgpsdk/trunk/src/advanced/adv_errors.c (modified) (2 diffs)
- openpgpsdk/trunk/src/advanced/adv_packet-parse.c (modified) (2 diffs)
- openpgpsdk/trunk/src/advanced/adv_signature.c (modified) (6 diffs)
- openpgpsdk/trunk/src/advanced/adv_validate.c (modified) (5 diffs)
- openpgpsdk/trunk/tests/test_rsa_verify.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/examples/packet-dump.c
r511 r527 15 15 #include <string.h> 16 16 #include <fcntl.h> 17 18 // \todo change this once we know it works 19 #include "../src/advanced/parse_local.h" 17 20 18 21 #include <openpgpsdk/final.h> … … 1100 1103 ops_reader_set_fd(pinfo,fd); 1101 1104 1105 pinfo->rinfo.accumulate=ops_true; 1106 1102 1107 if(armour) 1103 1108 ops_reader_push_dearmour(pinfo,ops_true,ops_true,ops_true); openpgpsdk/trunk/include/openpgpsdk/errors.h
r521 r527 49 49 OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG =OPS_E_ALG+1, 50 50 OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG =OPS_E_ALG+2, 51 OPS_E_ALG_UNSUPPORTED_SIGNATURE_ KEY_ALG =OPS_E_ALG+3,51 OPS_E_ALG_UNSUPPORTED_SIGNATURE_ALG =OPS_E_ALG+3, 52 52 OPS_E_ALG_UNSUPPORTED_HASH_ALG =OPS_E_ALG+4, 53 53 openpgpsdk/trunk/src/advanced/adv_errors.c
r517 r527 29 29 { OPS_E_R_READ_FAILED, "OPS_E_R_READ_FAILED" }, 30 30 { OPS_E_R_EARLY_EOF, "OPS_E_R_EARLY_EOF" }, 31 { OPS_E_R_BAD_FORMAT, "OPS_E_R_BAD_FORMAT" }, 32 { OPS_E_R_UNCONSUMED_DATA, "OPS_E_R_UNCONSUMED_DATA" }, 31 33 32 34 { OPS_E_W, "OPS_E_W" }, … … 40 42 ERR(OPS_E_P_MPI_FORMAT_ERROR), 41 43 42 { OPS_E_PROTO, "OPS_E_PROTO" }, 43 { OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT, "OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT" }, 44 { OPS_E_C, "OPS_E_C" }, 44 45 45 { OPS_E_C, "OPS_E_C" }, 46 ERR(OPS_E_V), 47 ERR(OPS_E_V_BAD_SIGNATURE), 48 ERR(OPS_E_V_UNKNOWN_SIGNER), 49 50 ERR(OPS_E_ALG), 51 ERR(OPS_E_ALG_UNSUPPORTED_SYMMETRIC_ALG), 52 ERR(OPS_E_ALG_UNSUPPORTED_PUBLIC_KEY_ALG), 53 ERR(OPS_E_ALG_UNSUPPORTED_SIGNATURE_ALG), 54 ERR(OPS_E_ALG_UNSUPPORTED_HASH_ALG), 55 56 ERR(OPS_E_PROTO), 57 ERR(OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT), 58 ERR(OPS_E_PROTO_UNKNOWN_SS), 59 ERR(OPS_E_PROTO_CRITICAL_SS_IGNORED), 60 ERR(OPS_E_PROTO_BAD_PUBLIC_KEY_VRSN), 61 ERR(OPS_E_PROTO_BAD_SIGNATURE_VRSN), 62 ERR(OPS_E_PROTO_BAD_ONE_PASS_SIG_VRSN), 63 ERR(OPS_E_PROTO_BAD_PKSK_VRSN), 64 ERR(OPS_E_PROTO_DECRYPTED_MSG_WRONG_LEN), 65 ERR(OPS_E_PROTO_BAD_SK_CHECKSUM), 66 46 67 47 68 { (int) NULL, (char *)NULL }, /* this is the end-of-array marker */ openpgpsdk/trunk/src/advanced/adv_packet-parse.c
r521 r527 1271 1271 1272 1272 default: 1273 OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_ KEY_ALG,1273 OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_ALG, 1274 1274 "Unsupported signature key algorithm (%s)", 1275 1275 ops_show_pka(C.signature.key_algorithm)); … … 1730 1730 1731 1731 default: 1732 OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_ KEY_ALG,1732 OPS_ERROR_1(&pinfo->errors,OPS_E_ALG_UNSUPPORTED_SIGNATURE_ALG, 1733 1733 "Bad v4 signature key algorithm (%s)", 1734 1734 ops_show_pka(C.signature.key_algorithm)); openpgpsdk/trunk/src/advanced/adv_signature.c
r521 r527 179 179 { 180 180 unsigned char sigbuf[8192]; 181 unsigned char hashbuf [8192];181 unsigned char hashbuf_from_sig[8192]; 182 182 unsigned n; 183 183 unsigned keysize; … … 187 187 keysize=BN_num_bytes(rsa->n); 188 188 /* RSA key can't be bigger than 65535 bits, so... */ 189 assert(keysize <= sizeof hashbuf );189 assert(keysize <= sizeof hashbuf_from_sig); 190 190 assert((unsigned)BN_num_bits(sig->sig) <= 8*sizeof sigbuf); 191 191 BN_bn2bin(sig->sig,sigbuf); 192 192 193 n=ops_rsa_public_decrypt(hashbuf,sigbuf,(BN_num_bits(sig->sig)+7)/8,rsa); 193 n=ops_rsa_public_decrypt(hashbuf_from_sig,sigbuf,(BN_num_bits(sig->sig)+7)/8,rsa); 194 int debug_len_decrypted=n; 194 195 195 196 if(n != keysize) // obviously, this includes error returns 196 197 return ops_false; 197 198 198 /*199 printf(" decrypt=%d ",n);200 hexdump(hashbuf,n);201 */202 203 199 // XXX: why is there a leading 0? The first byte should be 1... 204 200 // XXX: because the decrypt should use keysize and not sigsize? 205 if(hashbuf [0] != 0 || hashbuf[1] != 1)201 if(hashbuf_from_sig[0] != 0 || hashbuf_from_sig[1] != 1) 206 202 return ops_false; 207 203 … … 217 213 218 214 for(n=2 ; n < keysize-plen-hash_length-1 ; ++n) 219 if(hashbuf [n] != 0xff)215 if(hashbuf_from_sig[n] != 0xff) 220 216 return ops_false; 221 217 222 if(hashbuf [n++] != 0)218 if(hashbuf_from_sig[n++] != 0) 223 219 return ops_false; 224 220 … … 228 224 229 225 printf("\n"); 230 printf("hashbuf \n");231 for (zz=0; zz< plen; zz++)232 { printf("%02x ", hashbuf [n+zz]); }226 printf("hashbuf_from_sig\n"); 227 for (zz=0; zz<debug_len_decrypted; zz++) 228 { printf("%02x ", hashbuf_from_sig[n+zz]); } 233 229 printf("\n"); 234 230 printf("prefix\n"); … … 238 234 239 235 printf("\n"); 240 printf("hash buf2\n");236 printf("hash from sig\n"); 241 237 unsigned uu; 242 238 for (uu=0; uu<hash_length; uu++) 243 { printf("%02x ", hashbuf [n+plen+uu]); }239 { printf("%02x ", hashbuf_from_sig[n+plen+uu]); } 244 240 printf("\n"); 245 printf("hash \n");241 printf("hash passed in (should match hash from sig)\n"); 246 242 for (uu=0; uu<hash_length; uu++) 247 243 { printf("%02x ", hash[uu]); } 248 244 printf("\n"); 249 245 } 250 if(memcmp(&hashbuf [n],prefix,plen)251 || memcmp(&hashbuf [n+plen],hash,hash_length))246 if(memcmp(&hashbuf_from_sig[n],prefix,plen) 247 || memcmp(&hashbuf_from_sig[n+plen],hash,hash_length)) 252 248 return ops_false; 253 249 … … 641 637 sig->hash.add(&sig->hash,ops_memory_get_data(sig->mem), 642 638 sig->unhashed_count_offset); 643 /* what is this??? should delete? RW 639 640 // add final trailer 644 641 ops_hash_add_int(&sig->hash,sig->sig.version,1); 645 642 ops_hash_add_int(&sig->hash,0xff,1); 646 643 // +6 for version, type, pk alg, hash alg, hashed subpacket length 647 644 ops_hash_add_int(&sig->hash,sig->hashed_data_length+6,4); 648 */649 645 650 646 if (debug) openpgpsdk/trunk/src/advanced/adv_validate.c
r521 r527 24 24 ops_hash_t hash; 25 25 unsigned char hashout[OPS_MAX_HASH_SIZE]; 26 unsigned char trailer[6]; 27 unsigned int hashedlen; 26 28 27 29 //common_init_signature(&hash,sig); … … 30 32 hash.add(&hash,data,len); 31 33 hash.add(&hash,sig->v4_hashed_data,sig->v4_hashed_data_length); 34 35 trailer[0]=0x04; // version 36 trailer[1]=0xFF; 37 hashedlen=sig->v4_hashed_data_length; 38 trailer[2]=hashedlen >> 24; 39 trailer[3]=hashedlen >> 16; 40 trailer[4]=hashedlen >> 8; 41 trailer[5]=hashedlen; 42 hash.add(&hash,&trailer[0],6); 43 32 44 n=hash.finish(&hash,hashout); 33 45 … … 277 289 { 278 290 case OPS_SIG_BINARY: 291 case OPS_SIG_TEXT: 279 292 switch(arg->use) 280 293 { … … 292 305 293 306 default: 294 assert (0); 307 OPS_ERROR_1(errors,OPS_E_UNIMPLEMENTED,"Unimplemented Sig Use %d", arg->use); 308 printf(" Unimplemented Sig Use %d\n", arg->use); 309 break; 295 310 } 296 311 … … 308 323 OPS_ERROR_1(errors, OPS_E_UNIMPLEMENTED, 309 324 "Unexpected signature type 0x%02x\n", content->signature.type); 310 exit(1);325 // exit(1); 311 326 } 312 327 ops_memory_free(mem); openpgpsdk/trunk/tests/test_rsa_verify.c
r525 r527 82 82 // and sign them 83 83 84 snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign -- local-user %s --armor %s/%s",84 snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign --textmode --local-user %s --armor %s/%s", 85 85 gpgcmd, alpha_name, dir, filename_rsa_clearsign_nopassphrase); 86 86 if (system(cmd)) 87 87 { return 1; } 88 88 89 snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign -- local-user %s --passphrase %s --armor %s/%s",89 snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign --textmode --local-user %s --passphrase %s --armor %s/%s", 90 90 gpgcmd, bravo_name, bravo_passphrase, dir, filename_rsa_clearsign_passphrase); 91 91 if (system(cmd))
