Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,3 @@
path = third_party/protobuf
url = https://github.com/protocolbuffers/protobuf
branch = master
[submodule "third_party/absl"]
path = third_party/absl
url = https://github.com/abseil/abseil-cpp
branch = master
15 changes: 3 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.0.2)
cmake_minimum_required(VERSION 3.1)

# Do not install gtest since we are embedding googletest.
option(INSTALL_GTEST "Do not install gtest since we are embedding googletest" OFF)

project(ukey2)

set(CMAKE_CXX_STANDARD 11)

option(ukey2_USE_LOCAL_PROTOBUF
"Use local copy of protobuf library and compiler" OFF)

option(ukey2_USE_LOCAL_ABSL
"Use local copy of abseil-cpp library" OFF)

option(BYPASS_TESTING
"Do not build or run tests" OFF)

Expand All @@ -35,14 +34,6 @@ if (ukey2_USE_LOCAL_PROTOBUF)
include(cmake/local_build_protobuf.cmake)
endif()

if (ukey2_USE_LOCAL_ABSL)
if (NOT TARGET absl::base)
add_subdirectory(third_party/absl)
endif()
else()
find_package(absl REQUIRED)
endif()

find_package(Protobuf REQUIRED)

enable_testing()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ git submodule update --init --recursive
```
cd <source root>
mkdir build; cd build
cmake -Dukey2_USE_LOCAL_PROTOBUF=ON -Dukey2_USE_LOCAL_ABSL=ON -DCMAKE_INSTALL_PREFIX=/tmp/ukey2_install ..
cmake -Dukey2_USE_LOCAL_PROTOBUF=ON -DCMAKE_INSTALL_PREFIX=/tmp/ukey2_install ..
make
make install
```
Expand Down
4 changes: 0 additions & 4 deletions src/main/cpp/src/securegcm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,4 @@ target_link_libraries(ukey2_shell
PUBLIC
securemessage
ukey2
absl::base
absl::fixed_array
absl::flags
absl::flags_parse
)
68 changes: 51 additions & 17 deletions src/main/cpp/src/securegcm/ukey2_shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,13 @@
#include <iostream>
#include <memory>

#include <getopt.h>

#include "securegcm/ukey2_handshake.h"
#include "absl/container/fixed_array.h"
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"

#define LOG(ERROR) std::cerr
#define CHECK_EQ(a, b) do { if ((a) != (b)) abort(); } while(0)

ABSL_FLAG(
int, verification_string_length, 32,
"The length in bytes of the verification string. Must be a value between 1"
"and 32.");
ABSL_FLAG(string, mode, "initiator",
"The mode to run as: one of [initiator, responder]");

namespace securegcm {

namespace {
Expand Down Expand Up @@ -86,10 +78,10 @@ string ReadFrame() {
length |= static_cast<uint32_t>(length_data[3]) << (0 * 8);

// Read |length| bytes from the stream.
absl::FixedArray<char> buffer(length);
CHECK_EQ(length, fread(buffer.data(), 1, length, stdin));
std::unique_ptr<char[]> buffer(new char[length]);
CHECK_EQ(length, fread(buffer.get(), 1, length, stdin));

return string(buffer.data(), length);
return string(buffer.get(), length);
}

} // namespace
Expand Down Expand Up @@ -271,11 +263,54 @@ bool UKey2Shell::RunAsResponder() {

} // namespace securegcm

static void printUsage(char* name) {
std::string exec_name(name);
std::string usage(

"ICACHE is a command-line based wrapper, exercising the\n"
"UKey2Handshake class. Its main use is to be run in a Java test, testing the\n"
"compatibility of the Java and C++ implementations.\n"
"\n"
"This program can be run in two modes, initiator or responder (default is\n"
"initiator):\n"
" ukey2_shell --mode=initiator --verification_string_length=32\n"
" ukey2_shell --mode=responder --verification_string_length=32\n"
);
const std::string from("ICACHE");
for (size_t pos = usage.find(from); pos != std::string::npos; pos = usage.find(from, pos)) {
usage.replace(pos, from.length(), exec_name);
}
printf("%s", usage.c_str());
}

int main(int argc, char** argv) {
absl::ParseCommandLine(argc, argv);
static constexpr const char* OPTSTR = "ha:";
static const struct option OPTIONS[] = {
{ "help", no_argument, 0, 'h' },
{ "mode", required_argument, 0, 'm' },
{ "verification_string_length", required_argument, 0, 'l' },
{ 0, 0, 0, 0 } // termination of the option list
};
int opt;
int option_index = 0;
int verification_string_length = 32;
string mode = "initiator";

while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) {
switch (opt) {
default:
case 'h':
printUsage(argv[0]);
return 0;
case 'l':
verification_string_length = atoi(optarg);
break;
case 'm':
mode = optarg;
break;
}
}

const int verification_string_length =
absl::GetFlag(FLAGS_verification_string_length);
if (verification_string_length < 1 || verification_string_length > 32) {
LOG(ERROR) << "Invalid flag value, verification_string_length: "
<< verification_string_length;
Expand All @@ -284,7 +319,6 @@ int main(int argc, char** argv) {

securegcm::UKey2Shell shell(verification_string_length);
int exit_code = 0;
const string mode = absl::GetFlag(FLAGS_mode);
if (mode == "initiator") {
exit_code = !shell.RunAsInitiator();
} else if (mode == "responder") {
Expand Down
1 change: 0 additions & 1 deletion third_party/absl
Submodule absl deleted from 278e0a