# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = @{bin}/browserpass
profile browserpass @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/nameservice-strict>

  network netlink raw,

  @{exec_path} mr,

  @{bin}/gpg{2,} rCx -> gpg,

  owner @{HOME}/.password-store/{,**} r,
  owner @{HOME}/.mozilla/firefox/@{rand8}.*/.parentlock rw,
  owner @{HOME}/.mozilla/firefox/@{rand8}.*/extensions/* r,
  owner @{user_cache_dirs}/mozilla/firefox/@{rand8}.*/startupCache/scriptCache-*.bin r,
  owner @{user_cache_dirs}/mozilla/firefox/@{rand8}.*/startupCache/startupCache.*.little r,
  owner @{user_cache_dirs}/mozilla/firefox/@{rand8}.*/safebrowsing-updating/google[0-9]/goog-phish-proto-@{int}.vlpset rw,
  owner @{tmp}/mozilla-temp-@{int} r,

  @{sys}/kernel/mm/transparent_hugepage/hpage_pmd_size r,

  owner @{PROC}/@{pid}/mountinfo r,

  # Inherit Silencer
  deny network inet6,
  deny network inet,
  deny owner @{HOME}/.mozilla/firefox/@{rand8}.*/features/*/*.xpi r,
  deny owner @{HOME}/.mozilla/firefox/@{rand8}.*/storage/default/{,**} rw,
  deny owner @{user_download_dirs}/{,**} rw,
  deny owner @{run}/user/@{uid}/gnome-shell-disable-extensions w,
  deny owner @{user_share_dirs}/gvfs-metadata/{,**} r,
  deny /dev/dri/* rw,

  profile gpg flags=(complain) {
    include <abstractions/base>
    include <abstractions/nameservice-strict>

    capability dac_read_search,

    @{bin}/gpg{,2}    mr,

    owner @{HOME}/@{XDG_GPG_DIR}/ rw,
    owner @{HOME}/@{XDG_GPG_DIR}/** rwkl -> @{HOME}/@{XDG_GPG_DIR}/**,

    owner @{user_password_store_dirs}/   rw,
    owner @{user_password_store_dirs}/** rwkl -> @{HOME}/.password-store/**,
    owner @{user_projects_dirs}/**/*-store/   rw,
    owner @{user_projects_dirs}/**/*-store/** rwkl -> @{user_projects_dirs}/**/*-store/**,
    owner @{user_config_dirs}/*-store/   rw,
    owner @{user_config_dirs}/*-store/** rwkl -> @{user_config_dirs}/*-store/**,

    include if exists <local/browserpass_gpg>
  }

  include if exists <local/browserpass>
}
