1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except 6 * in compliance with the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <gtest/gtest.h> 18 19 #include <adb/crypto/rsa_2048_key.h> 20 #include <adb/crypto/x509_generator.h> 21 #include <android-base/logging.h> 22 #include <android-base/strings.h> 23 24 namespace adb { 25 namespace crypto { 26 27 TEST(X509Generator, Smoke) { 28 auto rsa_2048 = CreateRSA2048Key(); 29 30 std::string pub_key_plus_name; 31 auto* rsa = EVP_PKEY_get0_RSA(rsa_2048->GetEvpPkey()); 32 ASSERT_TRUE(CalculatePublicKey(&pub_key_plus_name, rsa)); 33 std::vector<std::string> split = android::base::Split(std::string(pub_key_plus_name), " \t"); 34 EXPECT_EQ(split.size(), 2); 35 36 LOG(INFO) << "pub_key=[" << pub_key_plus_name << "]"; 37 auto x509_cert = GenerateX509Certificate(rsa_2048->GetEvpPkey()); 38 ASSERT_NE(x509_cert.get(), nullptr); 39 40 std::string x509_str = X509ToPEMString(x509_cert.get()); 41 ASSERT_FALSE(x509_str.empty()); 42 } 43 44 } // namespace crypto 45 } // namespace adb 46