Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Unified Diff: base/security/challenger.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/security/challenger.h ('k') | base/security/hash-internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/security/challenger.cc
diff --git a/base/security/challenger.cc b/base/security/challenger.cc
deleted file mode 100644
index ab3ee95e93bb08647d702faad4b09323678994c4..0000000000000000000000000000000000000000
--- a/base/security/challenger.cc
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2007-2009 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-// ========================================================================
-
-#include "challenger.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "rsa.h"
-#include "md5.h"
-#include "aes.h"
-#include "b64.h"
-
-// Windows compilers do not have C99 support yet.
-#if defined(WIN32) || defined(_WIN32)
-#ifndef snprintf
-#define snprintf _snprintf
-#endif
-#endif
-
-Challenger::Challenger(RSA::PublicKey pkey,
- const unsigned char* seed, int seed_size)
- : rsa_(pkey) {
- memset(count_, 0, sizeof(count_));
- // Use seed as key for AES. Compress seed first.
- MD5(seed, seed_size, seed_);
-}
-
-const char* Challenger::challenge() {
- uint8_t ctr[AES_BLOCK_SIZE];
-
- // Compute current challenge.
- AES_encrypt_block(seed_, count_, ctr);
-
- // Increment count for future fresh challenges.
- for (size_t i = 0; i < sizeof(count_) && !++count_[i]; ++i);
-
- // Prepend our version number.
- char* p = challenge_;
- p += snprintf(challenge_, sizeof(challenge_), "%d:", rsa_.version());
-
- // Append our current challenge.
- B64_encode(ctr, sizeof(ctr), p, sizeof(challenge_) - (p - challenge_));
-
- return challenge_;
-}
-
-bool Challenger::verify(const char* hash, const char* signature) const {
- char message[128];
- uint8_t sigbuf[128];
-
- // Expect exactly 128 bytes of decoded signature data.
- if (B64_decode(signature, sigbuf, sizeof(sigbuf)) != sizeof(sigbuf))
- return false;
-
- // Verify signature with baked-in public key and recover embedded message.
- int result = rsa_.verify(sigbuf, sizeof(sigbuf),
- message, sizeof(message) - 1);
-
- if (result < 0 || result >= static_cast<int>(sizeof(message) - 1))
- return false;
-
- // Since we're expecting a textual message, 0-terminate it.
- message[result] = '\0';
-
- // Construct and compare expected against received signed message.
- char expected[128];
- snprintf(expected, sizeof(expected), "%s:%s", challenge_, hash);
-
- return !strcmp(expected, message);
-}
« no previous file with comments | « base/security/challenger.h ('k') | base/security/hash-internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698