| OLD | NEW |
| (Empty) |
| 1 // Copyright 2007-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #ifndef OMAHA_COMMON_SECURITY_CHALLENGER_H__ | |
| 17 #define OMAHA_COMMON_SECURITY_CHALLENGER_H__ | |
| 18 | |
| 19 #include <inttypes.h> | |
| 20 | |
| 21 #include "md5.h" | |
| 22 #include "aes.h" | |
| 23 #include "rsa.h" | |
| 24 | |
| 25 class Challenger { | |
| 26 public: | |
| 27 // Instantiate internal PRNG with seed. Use a proper method on your | |
| 28 // target platform to collect some entropy. For windows for instance, | |
| 29 // use CryptoAPI; on unix, read some from /dev/urandom. | |
| 30 // 128 bits of entropy is plenty. | |
| 31 explicit Challenger(RSA::PublicKey public_key, | |
| 32 const uint8_t* seed, int seed_size); | |
| 33 | |
| 34 // Not a const method! Every call updates internal state and never | |
| 35 // are identical challenges returned. | |
| 36 // Returns WebSafe base64 encoded string. | |
| 37 const char* challenge(); | |
| 38 | |
| 39 // Verifies whether signature contains current challenge and hash. | |
| 40 // Arguments are expected to be WebSafe base64 encoded strings. | |
| 41 bool verify(const char* hash, const char* signature) const; | |
| 42 | |
| 43 private: | |
| 44 char challenge_[64]; | |
| 45 uint8_t count_[AES_BLOCK_SIZE]; | |
| 46 uint8_t seed_[MD5_DIGEST_SIZE]; | |
| 47 RSA rsa_; | |
| 48 }; | |
| 49 | |
| 50 #endif // OMAHA_COMMON_SECURITY_CHALLENGER_H__ | |
| OLD | NEW |