|
| 1 | +# Summary |
| 2 | + |
| 3 | +This RFC proposes the addition of OS keychain APIs to the libobs platform utilities to faciliate secure storage of credentials. |
| 4 | + |
| 5 | +# Motivation |
| 6 | + |
| 7 | +While the credentials stored by OBS in profiles are not of severe sensitivity due to limited scope, as a modern desktop application we should still do our best to store them securely. |
| 8 | + |
| 9 | +# Detailed Changes |
| 10 | + |
| 11 | +This RFC proposes the addition of the following libobs API methods: |
| 12 | + |
| 13 | +- `bool os_keychain_available(void)` |
| 14 | +- `bool os_keychain_save(const char *namespace, const char *key, const char *data)` |
| 15 | +- `bool os_keychain_load(const char *namespace, const char *key, char **data)` |
| 16 | +- `bool os_keychain_delete(const char *namespace, const char *key)` |
| 17 | + |
| 18 | +As the API requires OS-specific implementations it shall become part of the `util/platform.h` header. |
| 19 | + |
| 20 | +**Implementation notes:** |
| 21 | + |
| 22 | +Operating-system backends: |
| 23 | +- Windows: `wincred.h` / `Cred*` Win32 API functions |
| 24 | +- macOS: Keychain Services API |
| 25 | +- Linux: `libsecret` |
| 26 | + |
| 27 | +The `namespace` is a user-visible component that may be displayed in keychain management applications as the label or name of an entry. It must be specified, ASCII only, and must be human-readable. |
| 28 | +In most cases it should identify the component and contents, e.g. for OAuth credentials stored by the OBS Studio UI this could be "OBS Studio OAuth Credentials". |
| 29 | +An entry can only be loaded or deleted if the namespace and key match the ones specified when saving. |
| 30 | + |
| 31 | +`os_keychain_available()` will always return `true` on Windows and macOS, on Linux it will return `true` if libobs was compiled with libsecret support, but does not indicate whether a keychain backend is available. |
| 32 | + |
| 33 | +**Usage examples:** |
| 34 | +Saving: |
| 35 | +```c |
| 36 | +const char *namespace = "OBS Studio Stream Keys"; |
| 37 | +const char *key = "StreamKey_abcef"; |
| 38 | +const char *value = "mystreamkey"; |
| 39 | +bool success = os_keychain_save(namespace, key, value); |
| 40 | +``` |
| 41 | + |
| 42 | +Loading: |
| 43 | +```c |
| 44 | +const char *namespace = "OBS Studio Stream Keys"; |
| 45 | +const char *key = "StreamKey_abcef"; |
| 46 | +char *value = NULL; |
| 47 | +bool success = os_keychain_load(namespace, key, &value); |
| 48 | + |
| 49 | +... do stuff ... |
| 50 | + |
| 51 | +if (value) |
| 52 | + bfree(value); |
| 53 | +``` |
| 54 | +
|
| 55 | +Deletion: |
| 56 | +```c |
| 57 | +const char *namespace = "OBS Studio Stream Keys"; |
| 58 | +const char *key = "StreamKey_abcef"; |
| 59 | +bool success = os_keychain_delete(namespace, key); |
| 60 | +``` |
| 61 | + |
| 62 | +# Drawbacks |
| 63 | + |
| 64 | +Accessing keychain information can reduce portability of profiles by not storing information in config files. OBS Studio may opt out of using a keychain if it is running in portable mode. |
| 65 | + |
| 66 | +In some cases accessing the keychain may require user confirmation, the API may block in such cases, which has to be accounted for by API users. |
| 67 | + |
| 68 | +If no keychain is available API users will have to fall back to storing data otherwise (e.g. obs data or config files). |
| 69 | + |
| 70 | +If keychain operations fail API users may have to also fall back to an insecure storage method or warn the user of faiure. |
| 71 | + |
| 72 | +# Additional Information |
| 73 | + |
| 74 | +- Windows credential store documentation: https://learn.microsoft.com/en-us/windows/win32/api/wincred/ |
| 75 | +- macOS keychain documentation: https://developer.apple.com/documentation/security/keychain_services?language=objc |
| 76 | +- Linux/GNOME libsecret documentation: https://gnome.pages.gitlab.gnome.org/libsecret/ |
| 77 | +- Flatpak "Secret" Portal: https://docs.flatpak.org/en/latest/portal-api-reference.html#gdbus-org.freedesktop.portal.Secret |
| 78 | +- Pull request: https://github.com/obsproject/obs-studio/pull/9122 |
0 commit comments