Skip to content

Commit

Permalink
Sandbox: Add basic iOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Jan 29, 2024
1 parent e1fae28 commit 812873a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/util/sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
#include <QFileInfo>
#include <QObject>
#include <QtDebug>
#include <QtGlobal>

#include "util/mac.h"

#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#endif

#ifdef Q_OS_MACOS
#include <Security/SecCode.h>
#include <Security/SecRequirement.h>
#endif
Expand All @@ -27,7 +31,10 @@ QHash<QString, SecurityTokenWeakPointer> Sandbox::s_activeTokens;

// static
void Sandbox::checkSandboxed() {
#ifdef __APPLE__
#ifdef Q_OS_IOS
// iOS apps are always sandboxed
s_bInSandbox = true;
#elif defined(Q_OS_MACOS)
SecCodeRef secCodeSelf;
if (SecCodeCopySelf(kSecCSDefaultFlags, &secCodeSelf) == errSecSuccess) {
SecRequirementRef sandboxReq;
Expand Down Expand Up @@ -187,9 +194,14 @@ bool Sandbox::createSecurityToken(const QString& canonicalPath,
kCFURLPOSIXPathStyle, isDirectory);
if (url) {
CFErrorRef error = NULL;
#ifdef Q_OS_IOS
// https://bugreports.qt.io/browse/QTBUG-67522
CFURLBookmarkCreationOptions options = kCFURLBookmarkCreationSuitableForBookmarkFile;
#else
CFURLBookmarkCreationOptions options = kCFURLBookmarkCreationWithSecurityScope;
#endif
CFDataRef bookmark = CFURLCreateBookmarkData(
kCFAllocatorDefault, url,
kCFURLBookmarkCreationWithSecurityScope, nil, nil, &error);
kCFAllocatorDefault, url, options, nil, nil, &error);
CFRelease(url);
if (bookmark) {
QByteArray bookmarkBA = QByteArray(
Expand Down Expand Up @@ -357,7 +369,7 @@ SecurityTokenPointer Sandbox::openSecurityTokenForDir(const QDir& dir, bool crea

SecurityTokenPointer Sandbox::openTokenFromBookmark(const QString& canonicalPath,
const QString& bookmarkBase64) {
#ifdef __APPLE__
#ifdef Q_OS_MACOS
QByteArray bookmarkBA = QByteArray::fromBase64(bookmarkBase64.toLatin1());
if (!bookmarkBA.isEmpty()) {
CFDataRef bookmarkData = CFDataCreate(
Expand Down Expand Up @@ -402,7 +414,7 @@ SecurityTokenPointer Sandbox::openTokenFromBookmark(const QString& canonicalPath
return nullptr;
}

#ifdef __APPLE__
#ifdef Q_OS_MACOS
QString Sandbox::migrateOldSettings() {
// QStandardPaths::DataLocation returns a different location depending on whether the build
// is signed (and therefore sandboxed with the hardened runtime), so use the absolute path
Expand Down

0 comments on commit 812873a

Please sign in to comment.