src/pgp_netpgp.c
changeset 182 2b286e499c94
parent 180 6008e35e7735
child 183 e83ac06e2d6d
     1.1 --- a/src/pgp_netpgp.c	Sat Apr 04 16:40:33 2015 +0200
     1.2 +++ b/src/pgp_netpgp.c	Wed Apr 08 17:34:25 2015 +0200
     1.3 @@ -112,7 +112,9 @@
     1.4      *psize = 0;
     1.5      *keylist = NULL;
     1.6  
     1.7 -    mem = pgp_decrypt_buf(netpgp->io, ctext, csize,
     1.8 +	memset(&vresult, 0x0, sizeof(vresult));
     1.9 +
    1.10 +    mem = pgp_decrypt_and_validate_buf(netpgp->io, &vresult, ctext, csize,
    1.11                  netpgp->secring, netpgp->pubring,
    1.12                  1 /* armoured */,
    1.13                  0 /* sshkeys */,
    1.14 @@ -122,40 +124,26 @@
    1.15      }
    1.16  
    1.17  	_psize = pgp_mem_len(mem);
    1.18 -	if ((_ptext = calloc(1, _psize)) == NULL) {
    1.19 -        return PEP_OUT_OF_MEMORY;
    1.20 -	}
    1.21 -	memcpy(_ptext, pgp_mem_data(mem), _psize);
    1.22 -
    1.23 -    result = PEP_DECRYPTED;
    1.24 -
    1.25 -    cat = pgp_memory_new();
    1.26 +    if (_psize){
    1.27 +        if ((_ptext = calloc(1, _psize)) == NULL) {
    1.28 +            return PEP_OUT_OF_MEMORY;
    1.29 +        }
    1.30 +        result = PEP_DECRYPTED;
    1.31 +    }else{
    1.32 +        return PEP_DECRYPT_NO_KEY;
    1.33 +    }
    1.34  
    1.35 -    /* if recognized */
    1.36 -    /* decrypt */
    1.37 -    /* if OK, verify */
    1.38 -    /*
    1.39 -    result = PEP_DECRYPTED_AND_VERIFIED;
    1.40 -    result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
    1.41 -    result = PEP_DECRYPTED;
    1.42 -    result = PEP_DECRYPT_WRONG_FORMAT;
    1.43 -    result = PEP_DECRYPT_NO_KEY;
    1.44 -    return PEP_OUT_OF_MEMORY;
    1.45 -    */
    1.46 -	(void) memset(&vresult, 0x0, sizeof(vresult));
    1.47 -	ret = pgp_validate_mem(io, &vresult, mem,
    1.48 -				&cat, 1, netpgp->pubring);
    1.49 +	memcpy(_ptext, pgp_mem_data(mem), _psize);
    1.50 +	pgp_memory_free(mem);
    1.51  
    1.52 -	// pgp_memory_free(mem) done by pgp_validate_mem
    1.53 -
    1.54 -	if (ret) {
    1.55 +    if (vresult.validc && !vresult.invalidc && !vresult.unknownc ) {
    1.56  		// resultp(io, "<stdin>", &vresult, netpgp->pubring);
    1.57  	    // signedmem is freed from pgp_validate_mem
    1.58          result = PEP_DECRYPTED_AND_VERIFIED;
    1.59  	}else{
    1.60          if (vresult.validc + vresult.invalidc + vresult.unknownc == 0) {
    1.61              // No signatures found - is this memory signed?
    1.62 -            result = PEP_DECRYPT_NO_KEY;
    1.63 +            result = PEP_VERIFY_NO_KEY; 
    1.64          } else if (vresult.invalidc == 0 && vresult.unknownc == 0) {
    1.65              // memory verification failure: invalid signature time
    1.66              result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
    1.67 @@ -166,6 +154,14 @@
    1.68              result = PEP_DECRYPT_WRONG_FORMAT;
    1.69          }
    1.70      }
    1.71 +    /*
    1.72 +    result = PEP_DECRYPTED_AND_VERIFIED;
    1.73 +    result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
    1.74 +    result = PEP_DECRYPTED;
    1.75 +    result = PEP_DECRYPT_WRONG_FORMAT;
    1.76 +    result = PEP_DECRYPT_NO_KEY;
    1.77 +    return PEP_OUT_OF_MEMORY;
    1.78 +    */
    1.79      //result = PEP_UNKNOWN_ERROR;
    1.80      //            stringlist_t *k;
    1.81      //            _keylist = new_stringlist(NULL);
    1.82 @@ -179,8 +175,6 @@
    1.83      //                    k = stringlist_add(k, "SIGNATURE FPR"/*TODO*/);
    1.84      //            } while (0 /* TODO sign next*/);
    1.85  
    1.86 -    pgp_memory_free(cat);
    1.87 -
    1.88      if (result == PEP_DECRYPTED_AND_VERIFIED
    1.89          || result == PEP_DECRYPTED) {
    1.90          *ptext = _ptext;