10391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// Copyright 2015 The Android Open Source Project 20391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// 30391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// Licensed under the Apache License, Version 2.0 (the "License"); 40391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// you may not use this file except in compliance with the License. 50391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// You may obtain a copy of the License at 60391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// 70391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// http://www.apache.org/licenses/LICENSE-2.0 80391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// 90391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// Unless required by applicable law or agreed to in writing, software 100391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// distributed under the License is distributed on an "AS IS" BASIS, 110391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 120391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// See the License for the specific language governing permissions and 130391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko// limitations under the License. 140391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 150391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko#include "webservd/keystore_encryptor.h" 160391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 170391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko#include <memory> 180391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 190391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko#include <keystore/keystore_client_impl.h> 200391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 210391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenkonamespace { 220391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 230391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenkoconst char kWebserverKeyName[] = "webservd_https_a40cd1b4"; 240391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 250391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko} // namespace 260391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 270391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenkonamespace webservd { 280391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 290391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenkostd::unique_ptr<Encryptor> Encryptor::CreateDefaultEncryptor() { 300391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko return std::unique_ptr<Encryptor>( 310391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko new KeystoreEncryptor(std::unique_ptr<keystore::KeystoreClient>( 320391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko new keystore::KeystoreClientImpl))); 330391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko} 340391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 350391a1eb2964a6f7e47ad418185b697ff8e41f45Alex VakulenkoKeystoreEncryptor::KeystoreEncryptor( 360391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko std::unique_ptr<keystore::KeystoreClient> keystore) 370391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko : keystore_(std::move(keystore)) {} 380391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 390391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenkobool KeystoreEncryptor::EncryptWithAuthentication(const std::string& plaintext, 400391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko std::string* ciphertext) { 410391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko return keystore_->encryptWithAuthentication(kWebserverKeyName, plaintext, 420391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko ciphertext); 430391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko} 440391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 450391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenkobool KeystoreEncryptor::DecryptWithAuthentication(const std::string& ciphertext, 460391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko std::string* plaintext) { 470391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko return keystore_->decryptWithAuthentication(kWebserverKeyName, ciphertext, 480391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko plaintext); 490391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko} 500391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko 510391a1eb2964a6f7e47ad418185b697ff8e41f45Alex Vakulenko} // namespace webservd 52