21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

et = RSA_verify(NID_sha1, hash, 20, sig, siglen, r);<br />

RSA_blinding_off(r);<br />

BN_CTX_free(c);<br />

return ret;<br />

}<br />

See Also<br />

Recipes 7.4, 7.12<br />

7.14 Securely Signing and Encrypting with RSA<br />

<strong>Problem</strong><br />

You need to both sign and encrypt data using RSA.<br />

Solution<br />

Sign the concatenation of the public key of the message recipient and the data you<br />

actually wish to sign. Then concatenate the signature to the plaintext, and encrypt<br />

everything, in multiple messages if necessary.<br />

Discussion<br />

Naïve implementations where a message is both signed and encrypted with public<br />

key cryptography tend to be insecure. Simply signing data with a private key and then<br />

encrypting the data with a public key isn’t secure, even if the signature is part of the<br />

data you encrypt. Such a scheme is susceptible to an attack called surreptitious forwarding.<br />

For example, suppose that there are two servers, S1 and S2. The client C<br />

signs a message and encrypts it with S1’s public key. Once S1 decrypts the message, it<br />

can reencrypt it with S2’s public key and make it look as if the message came from C.<br />

In a connection-oriented protocol, it could allow a compromised S1 to replay a key<br />

transport between C and S1 to a second server S2. That is, if an attacker compromises<br />

S1, he may be able to imitate C to S2. In a document-based environment such<br />

as an electronic mail system, if Alice sends email to Bob, Bob can forward it to Charlie,<br />

making it look as if it came from Alice instead of Bob. For example, if Alice sends<br />

important corporate secrets to Bob, who also works for the company, Bob can send<br />

the secrets to the competition and make it look as if it came from Alice. When the<br />

CEO finds out, it will appear that Alice, not Bob, is responsible.<br />

There are several strategies for fixing this problem. However, encrypting and then<br />

signing does not fix the problem. In fact, it makes the system far less secure. A secure<br />

Securely Signing and Encrypting with RSA | 343<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!