BetaOSM ist in der Beta-Phase. Lesen Sie die bekannten Grenzen (auf Englisch).
OSM

Unser Code

Sechs Stücke von OSMs echtem Code, unverändert, so wie er auf Ihrem Server läuft. So ist ganz OSM geschrieben.

Ein Update braucht genug Unterschriften

Ihr Server installiert ein Update nur, wenn genug Schlüssel von OSM es unterschrieben haben, jeder Schlüssel einmal gezählt.

def verify(raw, keys, threshold, namespace, ssh_keygen='ssh-keygen'):
    """A signed envelope -> its payload bytes, when at least `threshold` distinct keys of `keys` signed them."""
    payload, sigs = envelope(raw)
    keys = key_set(keys)
    if not isinstance(threshold, int) or isinstance(threshold, bool) or threshold < 1:
        raise ChannelError('The signature threshold is not valid.')
    good = set()
    for fp, sig in sigs:
        if fp in keys and fp not in good and ssh_verify(keys[fp], namespace, payload, sig, ssh_keygen):
            good.add(fp)
    if len(good) < threshold:
        raise ChannelError(f'A signed file has {len(good)} valid signature{"" if len(good) == 1 else "s"} of the '
                           f'{threshold} needed ({namespace}).')
    return payload
src/osm/channel.py, Zeile 162: verify

Nie älter, nie abgelaufen

Eine Update-Liste, die älter ist als die letzte oder abgelaufen, wird abgelehnt: Niemand kann Ihren Server auf einer alten Version festhalten.

def _fresh(d, what, now, longest):
    issued, expires = _int(d, 'issued', what), _int(d, 'expires', what)
    if issued > now + DAY:
        raise ChannelError(f'{what} was made in the future: is this server\'s clock right?')
    if expires <= now:
        raise ChannelError(f'{what} ran out on {time.strftime("%Y-%m-%d", time.gmtime(expires))}.')
    if expires - issued > longest:
        raise ChannelError(f'{what} is valid for too long.')


def _not_older(d, payload, stored, field, what):
    if stored is None:
        return
    old = _object(stored, d['type'])
    if d[field] < old[field]:
        raise ChannelError(f'{what} is older than the one this server has seen ({field} {d[field]} < {old[field]}).')
    if d[field] == old[field] and payload != stored:
        raise ChannelError(f'{what} has the {field} of the one this server has, but other contents.')
src/osm/channel.py, Zeile 203: _fresh, _not_older

Ein zweiter Schritt, der nicht lesbar ist, ist nicht „aus“

Kann die Datei der Zwei-Schritt-Anmeldung eines Kontos nicht gelesen werden, lehnt OSM die Anmeldung ab. Das Passwort allein kommt nie aus Versehen hinein.

def read_two_step(user, path=None):
    """(Auth.totp_get; without the agent at hand: the Security check) An account's two-step sign-in, read from its file
    -> its record; None when it has none, or the file is another account's (other_account).  A file that is there but
    cannot be read, or is not one OSM wrote: OpError 503, never "none"."""
    try:
        with open(path or os.path.join(paths.TOTP_DIR, user + '.json'), encoding='utf-8') as f:
            d = json.load(f)
    except FileNotFoundError:
        return None
    except (OSError, ValueError) as e:                  # (ValueError: bad JSON, or bytes that are not UTF-8)
        _log_unreadable(user, getattr(e, 'strerror', None) or 'not valid JSON')
        raise OpError(_TOTP_UNREADABLE.format(user=user), 503)
    if not isinstance(d, dict) or not isinstance(d.get('enabled', False), bool) \
            or (d.get('enabled') and not (isinstance(d.get('secret'), str) and d['secret'])):
        _log_unreadable(user, 'not a two-step sign-in OSM wrote')
        raise OpError(_TOTP_UNREADABLE.format(user=user), 503)
    return None if other_account(d, user) else d
src/osm/agent/auth.py, Zeile 190: read_two_step

Aus dem Internet reicht ein Passwort nie

Über OSM Connect braucht jedes Konto seinen zweiten Faktor.

def may_sign_in(user, second_factor):
    """(auth, once the password or the passkey was right) Connect's rules for the account: one it lets in (who: the
    Administrators, plus the chosen groups, or every account), with a second factor.  OpError(403) otherwise."""
    from . import passkeys
    if not _who_allows(user, load()['rules']):
        raise OpError('This account may not sign in through OSM Connect. An Administrator can allow it on the server\'s '
                      'own network (Settings > Remote access).', 403)
    if not second_factor:
        rp = connect_rp()
        if any(k.get('rp_id') == rp for k in passkeys.keys_of(user)):
            raise OpError('Through OSM Connect a password alone is not enough: sign in with your passkey.', 403)
        raise OpError('Through OSM Connect an account needs two-step sign-in. Set it up on the server\'s own network '
                      '(My Account > Security), then sign in here with its code.', 403)
src/osm/agent/ops_connect.py, Zeile 2022: may_sign_in

Ein Dateiname wird in einem Schritt belegt

Das Verschieben einer Datei ersetzt nie eine, die jemand anderes einen Moment zuvor dort gespeichert hat.

def rename_noreplace(src, dst):
    """os.rename that never replaces what is at dst: FileExistsError then.  A check before a rename let a file made
    meanwhile (over SMB, by an app) be replaced without a word (the review of 10 Nov 2026).  Linux's renameat2 with
    RENAME_NOREPLACE; where the file system refuses that flag, a file is linked to dst and its old name removed (a link
    never replaces), and a folder is renamed onto an empty folder made for it (a rename never replaces one that is not
    empty); on one without links either, the check and the rename together, as before."""
    f = _libc_renameat2()
    if f:
        import ctypes
        if f(_AT_FDCWD, os.fsencode(src), _AT_FDCWD, os.fsencode(dst), RENAME_NOREPLACE) == 0:
            return
        e = ctypes.get_errno()
        if e not in (errno.EINVAL, errno.ENOSYS):
            raise OSError(e, os.strerror(e), src, None, dst)
    if os.path.isdir(src) and not os.path.islink(src):
        os.mkdir(dst, 0o700)                         # (FileExistsError when something is there)
        try:
            os.rename(src, dst)
        except OSError:
            try:
                os.rmdir(dst)
            except OSError:
                pass
            raise
        return
    try:
        os.link(src, dst, follow_symlinks=False)     # (FileExistsError when something is there)
    except FileExistsError:
        raise
    except OSError as e:
        if e.errno not in (errno.EPERM, errno.EOPNOTSUPP, errno.ENOTSUP, errno.EMLINK, errno.ENOSYS):
            raise
        if os.path.lexists(dst):                     # (no links on this file system: FAT, exFAT)
            raise FileExistsError(errno.EEXIST, os.strerror(errno.EEXIST), dst)
        os.rename(src, dst)
        return
    try:
        os.unlink(src)
    except OSError:
        os.unlink(dst)                               # (its old name could not go: as it was)
        raise
src/osm/helpers/fileops.py, Zeile 1686: rename_noreplace

Aus einem Fehler wird ein Test

Wenn wir einen Fehler beheben, stellt ein Test genau den Moment nach, in dem er geschah, und bleibt.

def test_a_file_made_meanwhile_is_never_replaced(self):
    """The other client's file is made at the very moment between op_transfer's look at the name and the move."""
    for op, real in (('move', fo._move), ('copy', fo._copy)):
        with self.subTest(op=op):
            src = self.put('in/report.docx', 'mine')

            def theirs_first(p, d, job=None, real=real):
                self.put('to/report.docx', 'theirs')
                return real(p, d, job)
            with mock.patch.object(fo, '_' + op, side_effect=theirs_first):
                said = self.transfer(op, src)
            self.assertEqual(said, f'There is something called report.docx in the target already. '
                                   f'Nothing was {"moved" if op == "move" else "copied"}.')
            self.assertEqual((self.read('to/report.docx'), self.read('in/report.docx')), ('theirs', 'mine'))
            self.assertEqual(self.hidden('to'), [])
            os.unlink(self.dst)
tests/test_sec_review2.py, Zeile 80: test_a_file_made_meanwhile_is_never_replaced

Jede Änderung, geprüft

  • Mehr als 5.000 automatische Tests laufen bei jeder Änderung, auf Debian 13, wie auf Ihrem Server.
  • Neun Arten von Prüfungen müssen bestehen, bevor eine Änderung gebaut werden kann: die Tests, zwei Code-Prüfer, die Regeln des kompilierten Builds, die API-Referenz, die Skripte des Desktops mit ihrem Deutsch und Französisch, die Links der Dokumentation, die Übergabe an diese Website und der App-Katalog.
  • Unser Bedrohungsmodell nennt jeden Teil von OSM, der einem Netzwerk zugewandt ist, und was dort gilt. Wir prüfen es immer wieder, und jedes Problem, das eine Prüfung findet, wird mit dem Test behoben, der es gefunden hätte.

Die Stücke stammen aus OSM 0.3.0 (49ab072720fe). Etwas gefunden? Schreiben Sie an security@osm-os.com.