| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/gcm_driver/crypto/gcm_encryption_provider.h" | 5 #include "components/gcm_driver/crypto/gcm_encryption_provider.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 const char kEncryptionProperty[] = "encryption"; | 23 const char kEncryptionProperty[] = "encryption"; |
| 24 const char kCryptoKeyProperty[] = "crypto_key"; | 24 const char kCryptoKeyProperty[] = "crypto_key"; |
| 25 | 25 |
| 26 // Directory in the GCM Store in which the encryption database will be stored. | 26 // Directory in the GCM Store in which the encryption database will be stored. |
| 27 const base::FilePath::CharType kEncryptionDirectoryName[] = | 27 const base::FilePath::CharType kEncryptionDirectoryName[] = |
| 28 FILE_PATH_LITERAL("Encryption"); | 28 FILE_PATH_LITERAL("Encryption"); |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 std::string GCMEncryptionProvider::ToDecryptionFailureDetailsString( |
| 33 DecryptionFailure reason) { |
| 34 switch(reason) { |
| 35 case DECRYPTION_FAILURE_UNKNOWN: |
| 36 return "Unknown failure"; |
| 37 case DECRYPTION_FAILURE_INVALID_ENCRYPTION_HEADER: |
| 38 return "Invalid format for the Encryption header"; |
| 39 case DECRYPTION_FAILURE_INVALID_CRYPTO_KEY_HEADER: |
| 40 return "Invalid format for the Crypto-Key header"; |
| 41 case DECRYPTION_FAILURE_NO_KEYS: |
| 42 return "There are no associated keys with the subscription"; |
| 43 case DECRYPTION_FAILURE_INVALID_PUBLIC_KEY: |
| 44 return "The public key in the Crypto-Key header is invalid"; |
| 45 case DECRYPTION_FAILURE_INVALID_PAYLOAD: |
| 46 return "AES-GCM decryption failed"; |
| 47 } |
| 48 |
| 49 NOTREACHED(); |
| 50 return "(invalid reason)"; |
| 51 } |
| 52 |
| 32 GCMEncryptionProvider::GCMEncryptionProvider() | 53 GCMEncryptionProvider::GCMEncryptionProvider() |
| 33 : weak_ptr_factory_(this) { | 54 : weak_ptr_factory_(this) { |
| 34 } | 55 } |
| 35 | 56 |
| 36 GCMEncryptionProvider::~GCMEncryptionProvider() { | 57 GCMEncryptionProvider::~GCMEncryptionProvider() { |
| 37 } | 58 } |
| 38 | 59 |
| 39 void GCMEncryptionProvider::Init( | 60 void GCMEncryptionProvider::Init( |
| 40 const base::FilePath& store_path, | 61 const base::FilePath& store_path, |
| 41 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) { | 62 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 decrypted_message.decrypted = true; | 220 decrypted_message.decrypted = true; |
| 200 | 221 |
| 201 // There must be no data associated with the decrypted message at this point, | 222 // There must be no data associated with the decrypted message at this point, |
| 202 // to make sure that we don't end up in an infinite decryption loop. | 223 // to make sure that we don't end up in an infinite decryption loop. |
| 203 DCHECK_EQ(0u, decrypted_message.data.size()); | 224 DCHECK_EQ(0u, decrypted_message.data.size()); |
| 204 | 225 |
| 205 success_callback.Run(decrypted_message); | 226 success_callback.Run(decrypted_message); |
| 206 } | 227 } |
| 207 | 228 |
| 208 } // namespace gcm | 229 } // namespace gcm |
| OLD | NEW |