| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "crypto/encryptor.h" | 5 #include "crypto/encryptor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 | 86 |
| 87 std::string decrypted; | 87 std::string decrypted; |
| 88 | 88 |
| 89 // This wrong key causes the last padding byte to be 5, which is a valid | 89 // This wrong key causes the last padding byte to be 5, which is a valid |
| 90 // padding length, and the second to last padding byte to be 137, which is | 90 // padding length, and the second to last padding byte to be 137, which is |
| 91 // invalid. If an implementation simply uses the last padding byte to | 91 // invalid. If an implementation simply uses the last padding byte to |
| 92 // determine the padding length without checking every padding byte, | 92 // determine the padding length without checking every padding byte, |
| 93 // Encryptor::Decrypt() will still return true. This is the case for NSS | 93 // Encryptor::Decrypt() will still return true. This is the case for NSS |
| 94 // (crbug.com/124434). | 94 // (crbug.com/124434). |
| 95 #if !defined(USE_NSS) && !defined(OS_WIN) && !defined(OS_MACOSX) | 95 #if !defined(USE_NSS_CERTS) && !defined(OS_WIN) && !defined(OS_MACOSX) |
| 96 crypto::Encryptor decryptor; | 96 crypto::Encryptor decryptor; |
| 97 EXPECT_TRUE(decryptor.Init(wrong_key.get(), crypto::Encryptor::CBC, iv)); | 97 EXPECT_TRUE(decryptor.Init(wrong_key.get(), crypto::Encryptor::CBC, iv)); |
| 98 EXPECT_FALSE(decryptor.Decrypt(ciphertext, &decrypted)); | 98 EXPECT_FALSE(decryptor.Decrypt(ciphertext, &decrypted)); |
| 99 #endif | 99 #endif |
| 100 | 100 |
| 101 // This demonstrates that not all wrong keys can be detected by padding | 101 // This demonstrates that not all wrong keys can be detected by padding |
| 102 // error. This wrong key causes the last padding byte to be 1, which is | 102 // error. This wrong key causes the last padding byte to be 1, which is |
| 103 // a valid padding block of length 1. | 103 // a valid padding block of length 1. |
| 104 crypto::Encryptor decryptor2; | 104 crypto::Encryptor decryptor2; |
| 105 EXPECT_TRUE(decryptor2.Init(wrong_key2.get(), crypto::Encryptor::CBC, iv)); | 105 EXPECT_TRUE(decryptor2.Init(wrong_key2.get(), crypto::Encryptor::CBC, iv)); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // | 522 // |
| 523 // Otherwise when using std::string as the other tests do, accesses several | 523 // Otherwise when using std::string as the other tests do, accesses several |
| 524 // bytes off the end of the buffer may fall inside the reservation of | 524 // bytes off the end of the buffer may fall inside the reservation of |
| 525 // the string and not be detected. | 525 // the string and not be detected. |
| 526 scoped_ptr<char[]> ciphertext(new char[1]); | 526 scoped_ptr<char[]> ciphertext(new char[1]); |
| 527 | 527 |
| 528 std::string plaintext; | 528 std::string plaintext; |
| 529 EXPECT_FALSE( | 529 EXPECT_FALSE( |
| 530 encryptor.Decrypt(base::StringPiece(ciphertext.get(), 1), &plaintext)); | 530 encryptor.Decrypt(base::StringPiece(ciphertext.get(), 1), &plaintext)); |
| 531 } | 531 } |
| OLD | NEW |