libstorage-ng
Encryption.h
1 /*
2  * Copyright (c) [2016-2022] SUSE LLC
3  *
4  * All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as published
8  * by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, contact Novell, Inc.
17  *
18  * To contact Novell about this file by physical or electronic mail, you may
19  * find current contact information at www.novell.com.
20  */
21 
22 
23 #ifndef STORAGE_ENCRYPTION_H
24 #define STORAGE_ENCRYPTION_H
25 
26 
27 #include "storage/Devices/BlkDevice.h"
28 
29 
30 namespace storage
31 {
32 
33  enum class EncryptionType {
34  NONE, TWOFISH, TWOFISH_OLD, TWOFISH256_OLD, LUKS, LUKS1 = LUKS, UNKNOWN, LUKS2, PLAIN,
35  BITLOCKER
36  };
37 
38 
44  std::string get_encryption_type_name(EncryptionType encryption_type);
45 
46 
47  // TODO depending on the encryption types supported the Encryption class
48  // can be dropped or be abstract
49 
50 
54  class Encryption : public BlkDevice
55  {
56  public:
57 
64  static Encryption* create(Devicegraph* devicegraph, const std::string& name);
65 
66  static Encryption* load(Devicegraph* devicegraph, const xmlNode* node);
67 
71  EncryptionType get_type() const;
72 
78  void set_type(EncryptionType type);
79 
83  const std::string& get_password() const;
84 
88  void set_password(const std::string& password);
89 
93  const std::string& get_key_file() const;
94 
100  void set_key_file(const std::string& key_file);
101 
107  const std::string& get_cipher() const;
108 
115  void set_cipher(const std::string& cipher);
116 
122  unsigned int get_key_size() const;
123 
130  void set_key_size(unsigned int key_size);
131 
137  const std::string& get_pbkdf() const;
138 
145  void set_pbkdf(const std::string& pbkdf);
146 
152  const std::string& get_integrity() const;
153 
164  void set_integrity(const std::string& integrity);
165 
170  MountByType get_mount_by() const;
171 
176  void set_mount_by(MountByType mount_by);
177 
184  void set_default_mount_by();
185 
189  const std::vector<std::string>& get_crypt_options() const;
190 
194  void set_crypt_options(const std::vector<std::string>& crypt_options);
195 
200  bool is_in_etc_crypttab() const;
201 
205  void set_in_etc_crypttab(bool in_etc_crypttab);
206 
213 
217  const BlkDevice* get_blk_device() const;
218 
222  const std::string& get_open_options() const;
223 
228  void set_open_options(const std::string& open_options);
229 
233  static std::vector<Encryption*> get_all(Devicegraph* devicegraph);
234 
238  static std::vector<const Encryption*> get_all(const Devicegraph* devicegraph);
239 
240  public:
241 
242  class Impl;
243 
244  Impl& get_impl();
245  const Impl& get_impl() const;
246 
247  virtual Encryption* clone() const override;
248 
249  protected:
250 
251  Encryption(Impl* impl);
252 
253  };
254 
255 
261  bool is_encryption(const Device* device);
262 
269  Encryption* to_encryption(Device* device);
270 
274  const Encryption* to_encryption(const Device* device);
275 
276 }
277 
278 #endif
void set_cipher(const std::string &cipher)
Set the cipher.
std::string get_encryption_type_name(EncryptionType encryption_type)
Convert the EncryptionType encryption_type to a string.
void set_open_options(const std::string &open_options)
Set extra options for open calls.
const std::vector< std::string > & get_crypt_options() const
Get options (fourth field) in /etc/crypttab.
bool is_in_etc_crypttab() const
Query whether the LUKS device is present (probed devicegraph) or will be present (staging devicegraph...
Encryption * to_encryption(Device *device)
Converts pointer to Device to pointer to Encryption.
void set_default_mount_by()
Set the mount-by method to the global default, see Storage::get_default_mount_by().
const std::string & get_key_file() const
Get the key file.
const std::string & get_open_options() const
Get extra options for open calls.
void set_password(const std::string &password)
Set the encryption password.
void set_in_etc_crypttab(bool in_etc_crypttab)
Set whether the LUKS device will be present in /etc/crypttab.
const std::string & get_pbkdf() const
Get the PBKDF (of the first used keyslot).
void set_crypt_options(const std::vector< std::string > &crypt_options)
Set options (fourth field) in /etc/crypttab.
const std::string & get_integrity() const
Get the integrity.
void set_mount_by(MountByType mount_by)
Set the mount-by method.
unsigned int get_key_size() const
Get the key size in bytes.
static Encryption * create(Devicegraph *devicegraph, const std::string &name)
Create a device of type Encryption.
An encryption layer on a blk device.
Definition: Encryption.h:54
const std::string & get_password() const
Get the encryption password.
The main container of the libstorage-ng.
Definition: Devicegraph.h:169
void set_integrity(const std::string &integrity)
Set the integrity.
const std::string & get_cipher() const
Get the cipher.
An abstract Block Device.
Definition: BlkDevice.h:48
void set_key_file(const std::string &key_file)
Set the key file.
An abstract base class for storage devices.
Definition: Device.h:81
MountByType get_mount_by() const
Get the mount-by method.
void set_pbkdf(const std::string &pbkdf)
Set the PBKDF.
static std::vector< Encryption * > get_all(Devicegraph *devicegraph)
Get all Encryption objects of the devicegraph.
BlkDevice * get_blk_device()
Return underlying blk device.
void set_type(EncryptionType type)
Set the encryption type.
The storage namespace.
Definition: Actiongraph.h:38
void set_key_size(unsigned int key_size)
Set the key size in bytes.
bool is_encryption(const Device *device)
Checks whether device points to an Encryption.
EncryptionType get_type() const
Get the encryption type.
MountByType
The key by which the mount program identifies a mountable.
Definition: Mountable.h:60