-
Notifications
You must be signed in to change notification settings - Fork 135
Draft: #690: encrypt message #691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
0bcc42e
453193c
e5e5536
ad58d74
51a4d4b
6e3b0b5
7a9f8c4
b98e306
ff37f0b
1d62473
e1a1f09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| std::pair<std::string, std::string> generate_rsa_keypair(int bits); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #include "Encrypt.h" | ||
| #include "iptux-utils/output.h" | ||
| #include <gnutls/abstract.h> | ||
| #include <gnutls/gnutls.h> | ||
| #include <gnutls/x509.h> | ||
|
|
||
| using namespace std; | ||
|
|
||
| std::pair<std::string, std::string> generate_rsa_keypair(int bits) { | ||
| pair<string, string> keypair; | ||
| int ret; | ||
|
|
||
| gnutls_global_init(); | ||
|
|
||
| gnutls_privkey_t privkey; | ||
| ret = gnutls_privkey_init(&privkey); | ||
| if (ret < 0) { | ||
| LOG_WARN("gnutls_privkey_init failed: %s", gnutls_strerror(ret)); | ||
sourcery-ai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return keypair; | ||
| } | ||
|
|
||
| ret = gnutls_privkey_generate(privkey, GNUTLS_PK_RSA, bits, 0); | ||
|
||
| if (ret < 0) { | ||
| LOG_WARN("gnutls_privkey_generate failed: %s", gnutls_strerror(ret)); | ||
| gnutls_privkey_deinit(privkey); | ||
| return keypair; | ||
| } | ||
|
|
||
| return keypair; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚨 suggestion (security): Persisting the private key in plain text config may be a security concern
Persisting the private key in the general config store means any user/process with access to that file can read it. Depending on your threat model, consider a more secure storage mechanism (OS keyring/keystore, separate restricted file, or encrypting the key with a passphrase) rather than plain text in the config. At minimum, ensure the config file location is tightly permissioned if you keep this approach.
Suggested implementation:
To fully address the concern, you should:
private_key(e.g. OS keyring/keystore integration, or a separate file created with restrictive permissions such as 0600).ProgramData::initPrivateKey()to load the private key from that secure storage, and ensure it never falls back to reading it from the general config.private_keyviaconfigand migrate them to the secure storage path instead.