Tag Archives: fedora

Integrating Linux with Okta Device Trust

Post Syndicated from original https://mjg59.dreamwidth.org/64311.html

I’ve written about bearer tokens and how much pain they cause me before, but sadly wishing for a better world doesn’t make it happen so I’m making do with what’s available. Okta has a feature called Device Trust which allows to you configure access control policies that prevent people obtaining tokens unless they’re using a trusted device. This doesn’t actually bind the tokens to the hardware in any way, so if a device is compromised or if a user is untrustworthy this doesn’t prevent the token ending up on an unmonitored system with no security policies. But it’s an incremental improvement, other than the fact that for desktop it’s only supported on Windows and MacOS, which really doesn’t line up well with my interests.

Obviously there’s nothing fundamentally magic about these platforms, so it seemed fairly likely that it would be possible to make this work elsewhere. I spent a while staring at the implementation using Charles Proxy and the Chrome developer tools network tab and had worked out a lot, and then Okta published a paper describing a lot of what I’d just laboriously figured out. But it did also help clear up some points of confusion and clarified some design choices. I’m not going to give a full description of the details (with luck there’ll be code shared for that before too long), but here’s an outline of how all of this works. Also, to be clear, I’m only going to talk about the desktop support here – mobile is a bunch of related but distinct things that I haven’t looked at in detail yet.

Okta’s Device Trust (as officially supported) relies on Okta Verify, a local agent. When initially installed, Verify authenticates as the user, obtains a token with a scope that allows it to manage devices, and then registers the user’s computer as an additional MFA factor. This involves it generating a JWT that embeds a number of custom claims about the device and its state, including things like the serial number. This JWT is signed with a locally generated (and hardware-backed, using a TPM or Secure Enclave) key, which allows Okta to determine that any future updates from a device claiming the same identity are genuinely from the same device (you could construct an update with a spoofed serial number, but you can’t copy the key out of a TPM so you can’t sign it appropriately). This is sufficient to get a device registered with Okta, at which point it can be used with Fastpass, Okta’s hardware-backed MFA mechanism.

As outlined in the aforementioned deep dive paper, Fastpass is implemented via multiple mechanisms. I’m going to focus on the loopback one, since it’s the one that has the strongest security properties. In this mode, Verify listens on one of a list of 10 or so ports on localhost. When you hit the Okta signin widget, choosing Fastpass triggers the widget into hitting each of these ports in turn until it finds one that speaks Fastpass and then submits a challenge to it (along with the URL that’s making the request). Verify then constructs a response that includes the challenge and signs it with the hardware-backed key, along with information about whether this was done automatically or whether it included forcing the user to prove their presence. Verify then submits this back to Okta, and if that checks out Okta completes the authentication.

Doing this via loopback from the browser has a bunch of nice properties, primarily around the browser providing information about which site triggered the request. This means the Verify agent can make a decision about whether to submit something there (ie, if a fake login widget requests your creds, the agent will ignore it), and also allows the issued token to be cross-checked against the site that requested it (eg, if g1thub.com requests a token that’s valid for github.com, that’s a red flag). It’s not quite at the same level as a hardware WebAuthn token, but it has many of the anti-phishing properties.

But none of this actually validates the device identity! The entire registration process is up to the client, and clients are in a position to lie. Someone could simply reimplement Verify to lie about, say, a device serial number when registering, and there’d be no proof to the contrary. Thankfully there’s another level to this to provide stronger assurances. Okta allows you to provide a CA root[1]. When Okta issues a Fastpass challenge to a device the challenge includes a list of the trusted CAs. If a client has a certificate that chains back to that, it can embed an additional JWT in the auth JWT, this one containing the certificate and signed with the certificate’s private key. This binds the CA-issued identity to the Fastpass validation, and causes the device to start appearing as “Managed” in the Okta device management UI. At that point you can configure policy to restrict various apps to managed devices, ensuring that users are only able to get tokens if they’re using a device you’ve previously issued a certificate to.

I’ve managed to get Linux tooling working with this, though there’s still a few drawbacks. The main issue is that the API only allows you to register devices that declare themselves as Windows or MacOS, followed by the login system sniffing browser user agent and only offering Fastpass if you’re on one of the officially supported platforms. This can be worked around with an extension that spoofs user agent specifically on the login page, but that’s still going to result in devices being logged as a non-Linux OS which makes interpreting the logs more difficult. There’s also no ability to choose which bits of device state you log: there’s a couple of existing integrations, and otherwise a fixed set of parameters that are reported. It’d be lovely to be able to log arbitrary material and make policy decisions based on that.

This also doesn’t help with ChromeOS. There’s no real way to automatically launch something that’s bound to localhost (you could probably make this work using Crostini but there’s no way to launch a Crostini app at login), and access to hardware-backed keys is kind of a complicated topic in ChromeOS for privacy reasons. I haven’t tried this yet, but I think using an enterprise force-installed extension and the chrome.enterprise.platformKeys API to obtain a device identity cert and then intercepting requests to the appropriate port range on localhost ought to be enough to do that? But I’ve literally never written any Javascript so I don’t know. Okta supports falling back from the loopback protocol to calling a custom URI scheme, but once you allow that you’re also losing a bunch of the phishing protection, so I’d prefer not to take that approach.

Like I said, none of this prevents exfiltration of bearer tokens once they’ve been issued, and there’s still a lot of ecosystem work to do there. But ensuring that tokens can’t be issued to unmanaged machines in the first place is still a step forwards, and with luck we’ll be able to make use of this on Linux systems without relying on proprietary client-side tooling.

(Time taken to code this implementation: about two days, and under 1000 lines of new code. Time taken to figure out what the fuck to write: rather a lot longer)

[1] There’s also support for having Okta issue certificates, but then you’re kind of back to the “How do I know this is my device” situation

comment count unavailable comments

Asking ChatGPT to write my security-sensitive code for me

Post Syndicated from original https://mjg59.dreamwidth.org/64090.html

I have a patchset that makes it safe to use hibernation under Linux even in a secure boot world but it relies on preventing userland from using one of the TPM PCRs[1] that would otherwise be available to it. TPM 2 devices support emulating PCRs in NVRAM, which would obviously be beneficial in not taking away a scare resource, but the docs suggest there’s no way to tie a key generation to an NVRAM value which makes this more complicated.

So, why not ask a computer to do this for me? I asked ChatGPT to write me some code that would bind a TPM key to an NVRAM value. After a couple of false starts it told me:To bind an encryption key to the value of a TPM NV index, you can use the TPM2_NV_DefineSpace command to define an NV index with the TPMA_NV_BIND attribute. Woo! That sounds perfect. Only one problem – I can’t actually find the TPMA_NV_BIND attribute defined anywhere in the spec. Well, ask the AI again.

Here is the definition of TPMA_NV_BIND from the TPM 2.0 specification:
TPMA_NV_BIND (BIT 17) If SET, the contents of the NV Index are bound to the platform hierarchy.

Ok, that sounds convincing. Where is it in the spec?

The definition of TPMA_NV_BIND is on page 126 of the TPM 2.0 specification, in section 9.7.1 “TPMA_NV”.

Huh. Nope. Page 126 says nothing about this. Section 9.7.1 says nothing about this. The TPMA_NV bits are actually described on page 168 of volume 2 of the spec, in section 13.4. Bit 17 is TPMA_NV_OWNERREAD. TPMA_NV_BIND does not appear in the spec anywhere. I told the AI that.

I apologize for the error in my previous response. You are correct that the TPMA_NV_BIND attribute does not appear in the TPM 2.0 specification.

To bind an encryption key to the value of a TPM NV index, you can use the TPM2_NV_DefineSpace command with the TPMA_NV_BIND attribute.

I’m not afraid of being unemployed in the near future.

[1] “Platform Configuration Registers” – a modern TPM has 24 of these. When something security sensitive happens, you generate a hash of that event and pass it to the TPM. The TPM appends that to an existing PCR value and then hashes that concatenated value and sets the PCR to that. This means the PCR value depends not only on the values provided, but also the order they’re provided in. Various TPM operations can be made conditional on the PCR values meeting specific criteria.

comment count unavailable comments

Changing firmware config that doesn’t want to be changed

Post Syndicated from original https://mjg59.dreamwidth.org/63787.html

Today I had to deal with a system that had an irritating restriction – a firmware configuration option I really wanted to be able to change appeared as a greyed out entry in the configuration menu. Some emails revealed that this was a deliberate choice on the part of the system vendor, so that seemed to be that. Thankfully in this case there was a way around that.

One of the things UEFI introduced was a mechanism to generically describe firmware configuration options, called Visual Forms Representation (or VFR). At the most straightforward level, this lets you define a set of forms containing questions, with each question associated with a value in a variable. Questions can be made dependent upon the answers to other questions, so you can have options that appear or disappear based on how other questions were answered. An example in this language might be something like:
CheckBox Prompt: "Console Redirection", Help: "Console Redirection Enable or Disable.", QuestionFlags: 0x10, QuestionId: 53, VarStoreId: 1, VarStoreOffset: 0x39, Flags: 0x0
In which question 53 asks whether console redirection should be enabled or disabled. Other questions can then rely on the answer to question 53 to influence whether or not they’re relevant (eg, if console redirection is disabled, there’s no point in asking which port it should be redirected to). As a checkbox, if it’s set then the value will be set to 1, and 0 otherwise. But where’s that stored? Earlier we have another declaration:
VarStore GUID: EC87D643-EBA4-4BB5-A1E5-3F3E36B20DA9, VarStoreId: 1, Size: 0xF4, Name: "Setup"
A UEFI variable called “Setup” and with GUID EC87D643-EBA4-4BB5-A1E5-3F3E36B20DA9 is declared as VarStoreId 1 (matching the declaration in the question) and is 0xf4 bytes long. The question indicates that the offset for that variable is 0x39. Rewriting Setup-EC87D643-EBA4-4BB5-A1E5-3F3E36B20DA9 with a modified value in offset 0x39 will allow direct manipulation of the config option.

But how do we get this data in the first place? VFR isn’t built into the firmware directly – instead it’s turned into something called Intermediate Forms Representation, or IFR. UEFI firmware images are typically in a standardised format, and you can use UEFITool to extract individual components from that firmware. If you use UEFITool to search for “Setup” there’s a good chance you’ll be able to find the component that implements the setup UI. Running IFRExtractor-RS against it will then pull out any IFR data it finds, and decompile that into something resembling the original VFR. And now you have the list of variables and offsets and the configuration associated with them, even if your firmware has chosen to hide those options from you.

Given that a bunch of these config values may be security relevant, this seems a little concerning – what stops an attacker who has access to the OS from simply modifying these variables directly? UEFI avoids this by having two separate stages of boot, one where the full firmware (“Boot Services”) is available, and one where only a subset (“Runtime Services”) is available. The transition is triggered by the OS calling ExitBootServices, indicating the handoff from the firmware owning the hardware to the OS owning the hardware. This is also considered a security boundary – before ExitBootServices everything running has been subject to any secure boot restrictions, and afterwards applications can do whatever they want. UEFI variables can be flagged as being visible in both Boot and Runtime Services, or can be flagged as Boot Services only. As long as all the security critical variables are Boot Services only, an attacker should never be able to run untrusted code that could alter them.

In my case, the firmware option I wanted to alter had been enclosed in “GrayOutIf True” blocks. But the questions were still defined and the code that acted on those options was still present, so simply modifying the variables while still inside Boot Services gave me what I wanted. Note that this isn’t a given! The presence of configuration options in the IFR data doesn’t mean that anything will later actually read and make use of that variable – a vendor may have flagged options as unavailable and then removed the code, but never actually removed the config data. And also please do note that the reason stuff was removed may have been that it doesn’t actually work, and altering any of these variables risks bricking your hardware in a way that’s extremely difficult to recover. And there’s also no requirement that vendors use IFR to describe their configuration, so you may not get any help here anyway.

In summary: if you do this you may break your computer. If you don’t break your computer, it might not work anyway. I’m not going to help you try to break your computer. And I didn’t come up with any of this, I just didn’t find it all written down in one place while I was researching it.

comment count unavailable comments

Trying to remove the need to trust cloud providers

Post Syndicated from original https://mjg59.dreamwidth.org/63261.html

First up: what I’m covering here is probably not relevant for most people. That’s ok! Different situations have different threat models, and if what I’m talking about here doesn’t feel like you have to worry about it, that’s great! Your life is easier as a result. But I have worked in situations where we had to care about some of the scenarios I’m going to describe here, and the technologies I’m going to talk about here solve a bunch of these problems.

So. You run a typical VM in the cloud. Who has access to that VM? Well, firstly, anyone who has the ability to log into the host machine with administrative capabilities. With enough effort, perhaps also anyone who has physical access to the host machine. But the hypervisor also has the ability to inspect what’s running inside a VM, so anyone with the ability to install a backdoor into the hypervisor could theoretically target you. And who’s to say the cloud platform launched the correct image in the first place? The control plane could have introduced a backdoor into your image and run that instead. Or the javascript running in the web UI that you used to configure the instance could have selected a different image without telling you. Anyone with the ability to get a (cleverly obfuscated) backdoor introduced into quite a lot of code could achieve that. Obviously you’d hope that everyone working for a cloud provider is honest, and you’d also hope that their security policies are good and that all code is well reviewed before being committed. But when you have several thousand people working on various components of a cloud platform, there’s always the potential for something to slip up.

Let’s imagine a large enterprise with a whole bunch of laptops used by developers. If someone has the ability to push a new package to one of those laptops, they’re in a good position to obtain credentials belonging to the user of that laptop. That means anyone with that ability effectively has the ability to obtain arbitrary other privileges – they just need to target someone with the privilege they want. You can largely mitigate this by ensuring that the group of people able to do this is as small as possible, and put technical barriers in place to prevent them from pushing new packages unilaterally.

Now imagine this in the cloud scenario. Anyone able to interfere with the control plane (either directly or by getting code accepted that alters its behaviour) is in a position to obtain credentials belonging to anyone running in that cloud. That’s probably a much larger set of people than have the ability to push stuff to laptops, but they have much the same level of power. You’ll obviously have a whole bunch of processes and policies and oversights to make it difficult for a compromised user to do such a thing, but if you’re a high enough profile target it’s a plausible scenario.

How can we avoid this? The easiest way is to take the people able to interfere with the control plane out of the loop. The hypervisor knows what it booted, and if there’s a mechanism for the VM to pass that information to a user in a trusted way, you’ll be able to detect the control plane handing over the wrong image. This can be achieved using trusted boot. The hypervisor-provided firmware performs a “measurement” (basically a cryptographic hash of some data) of what it’s booting, storing that information in a virtualised TPM. This TPM can later provide a signed copy of the measurements on demand. A remote system can look at these measurements and determine whether the system is trustworthy – if a modified image had been provided, the measurements would be different. As long as the hypervisor is trustworthy, it doesn’t matter whether or not the control plane is – you can detect whether you were given the correct OS image, and you can build your trust on top of that.

(Of course, this depends on you being able to verify the key used to sign those measurements. On real hardware the TPM has a certificate that chains back to the manufacturer and uniquely identifies the TPM. On cloud platforms you typically have to retrieve the public key via the metadata channel, which means you’re trusting the control plane to give you information about the hypervisor in order to verify what the control plane gave to the hypervisor. This is suboptimal, even though realistically the number of moving parts in that part of the control plane is much smaller than the number involved in provisioning the instance in the first place, so an attacker managing to compromise both is less realistic. Still, AWS doesn’t even give you that, which does make it all rather more complicated)

Ok, so we can (largely) decouple our trust in the VM from having to trust the control plane. But we’re still relying on the hypervisor to provide those attestations. What if the hypervisor isn’t trustworthy? This sounds somewhat ridiculous (if you can’t run a trusted app on top of an untrusted OS, how can you run a trusted OS on top of an untrusted hypervisor?), but AMD actually have a solution for that. SEV (“Secure Encrypted Virtualisation”) is a technology where (handwavily) an encryption key is generated when a new VM is created, and the memory belonging to that VM is encrypted with that key. The hypervisor has no access to that encryption key, and any access to memory initiated by the hypervisor will only see the encrypted content. This means that nobody with the ability to tamper with the hypervisor can see what’s going on inside the OS (and also means that nobody with physical access can either, so that’s another threat dealt with).

But how do we know that the hypervisor set this up, and how do we know that the correct image was booted? SEV has support for a “Launch attestation”, a CPU generated signed statement that it booted the current VM with SEV enabled. But it goes further than that! The attestation includes a measurement of what was booted, which means we don’t need to trust the hypervisor at all – the CPU itself will tell us what image we were given. Perfect.

Except, well. There’s a few problems. AWS just doesn’t have any VMs that implement SEV yet (there are bare metal instances that do, but obviously you’re building your own infrastructure to make that work). Google only seem to provide the launch measurement via the logging service – and they only include the parsed out data, not the original measurement. So, we still have to trust (a subset of) the control plane. Azure provides it via a separate attestation service, but again it doesn’t seem to provide the raw attestation and so you’re still trusting the attestation service. For the newest generation of SEV, SEV-SNP, this is less of a big deal because the guest can provide its own attestation. But Google doesn’t offer SEV-SNP hardware yet, and the driver you need for this only shipped in Linux 5.19 and Azure’s SEV Ubuntu images only offer up to 5.15 at the moment, so making use of that means you’re putting your own image together at the moment.

And there’s one other kind of major problem. A normal VM image provides a bootloader and a kernel and a filesystem. That bootloader needs to run on something. That “something” is typically hypervisor-provided “firmware” – for instance, OVMF. This probably has some level of cloud vendor patching, and they probably don’t ship the source for it. You’re just having to trust that the firmware is trustworthy, and we’re talking about trying to avoid placing trust in the cloud provider. Azure has a private beta allowing users to upload images that include their own firmware, meaning that all the code you trust (outside the CPU itself) can be provided by the user, and once that’s GA it ought to be possible to boot Azure VMs without having to trust any Microsoft-provided code.

Well, mostly. As AMD admit, SEV isn’t guaranteed to be resistant to certain microarchitectural attacks. This is still much more restrictive than the status quo where the hypervisor could just read arbitrary content out of the VM whenever it wanted to, but it’s still not ideal. Which, to be fair, is where we are with CPUs in general.

(Thanks to Leonard Cohnen who gave me a bunch of excellent pointers on this stuff while I was digging through it yesterday)

comment count unavailable comments

On-device WebAuthn and what makes it hard to do well

Post Syndicated from original https://mjg59.dreamwidth.org/62746.html

WebAuthn improves login security a lot by making it significantly harder for a user’s credentials to be misused – a WebAuthn token will only respond to a challenge if it’s issued by the site a secret was issued to, and in general will only do so if the user provides proof of physical presence[1]. But giving people tokens is tedious and also I have a new laptop which only has USB-C but does have a working fingerprint reader and I hate the aesthetics of the Yubikey 5C Nano, so I’ve been thinking about what WebAuthn looks like done without extra hardware.

Let’s talk about the broad set of problems first. For this to work you want to be able to generate a key in hardware (so it can’t just be copied elsewhere if the machine is compromised), prove to a remote site that it’s generated in hardware (so the remote site isn’t confused about what security assertions you’re making), and tie use of that key to the user being physically present (which may range from “I touched this object” to “I presented biometric evidence of identity”). What’s important here is that a compromised OS shouldn’t be able to just fake a response. For that to be possible, the chain between proof of physical presence to the secret needs to be outside the control of the OS.

For a physical security token like a Yubikey, this is pretty easy. The communication protocol involves the OS passing a challenge and the source of the challenge to the token. The token then waits for a physical touch, verifies that the source of the challenge corresponds to the secret it’s being asked to respond to the challenge with, and provides a response. At the point where keys are being enrolled, the token can generate a signed attestation that it generated the key, and a remote site can then conclude that this key is legitimately sequestered away from the OS. This all takes place outside the control of the OS, meeting all the goals described above.

How about Macs? The easiest approach here is to make use of the secure enclave and TouchID. The secure enclave is a separate piece of hardware built into either a support chip (for x86-based Macs) or directly on the SoC (for ARM-based Macs). It’s capable of generating keys and also capable of producing attestations that said key was generated on an Apple secure enclave (“Apple Anonymous Attestation”, which has the interesting property of attesting that it was generated on Apple hardware, but not which Apple hardware, avoiding a lot of privacy concerns). These keys can have an associated policy that says they’re only usable if the user provides a legitimate touch on the fingerprint sensor, which means it can not only assert physical presence of a user, it can assert physical presence of an authorised user. Communication between the fingerprint sensor and the secure enclave is a private channel that the OS can’t meaningfully interfere with, which means even a compromised OS can’t fake physical presence responses (eg, the OS can’t record a legitimate fingerprint press and then send that to the secure enclave again in order to mimic the user being present – the secure enclave requires that each response from the fingerprint sensor be unique). This achieves our goals.

The PC space is more complicated. In the Mac case, communication between the biometric sensors (be that TouchID or FaceID) occurs in a controlled communication channel where all the hardware involved knows how to talk to the other hardware. In the PC case, the typical location where we’d store secrets is in the TPM, but TPMs conform to a standardised spec that has no understanding of this sort of communication, and biometric components on PCs have no way to communicate with the TPM other than via the OS. We can generate keys in the TPM, and the TPM can attest to those keys being TPM-generated, which means an attacker can’t exfiltrate those secrets and mimic the user’s token on another machine. But in the absence of any explicit binding between the TPM and the physical presence indicator, the association needs to be up to code running on the CPU. If that’s in the OS, an attacker who compromises the OS can simply ask the TPM to respond to an challenge it wants, skipping the biometric validation entirely.

Windows solves this problem in an interesting way. The Windows Hello Enhanced Signin doesn’t add new hardware, but relies on the use of virtualisation. The agent that handles WebAuthn responses isn’t running in the OS, it’s running in another VM that’s entirely isolated from the OS. Hardware that supports this model has a mechanism for proving its identity to the local code (eg, fingerprint readers that support this can sign their responses with a key that has a certificate that chains back to Microsoft). Additionally, the secrets that are associated with the TPM can be held in this VM rather than in the OS, meaning that the OS can’t use them directly. This means we have a flow where a browser asks for a WebAuthn response, that’s passed to the VM, the VM asks the biometric device for proof of user presence (including some sort of random value to prevent the OS just replaying that), receives it, and then asks the TPM to generate a response to the challenge. Compromising the OS doesn’t give you the ability to forge the responses between the biometric device and the VM, and doesn’t give you access to the secrets in the TPM, so again we meet all our goals.

On Linux (and other free OSes), things are less good. Projects like tpm-fido generate keys on the TPM, but there’s no secure channel between that code and whatever’s providing proof of physical presence. An attacker who compromises the OS may not be able to copy the keys to their own system, but while they’re on the compromised system they can respond to as many challenges as they like. That’s not the same security assertion we have in the other cases.

Overall, Apple’s approach is the simplest – having binding between the various hardware components involved means you can just ignore the OS entirely. Windows doesn’t have the luxury of having as much control over what the hardware landscape looks like, so has to rely on virtualisation to provide a security barrier against a compromised OS. And in Linux land, we’re fucked. Who do I have to pay to write a lightweight hypervisor that runs on commodity hardware and provides an environment where we can run this sort of code?

[1] As I discussed recently there are scenarios where these assertions are less strong, but even so

comment count unavailable comments

End-to-end encrypted messages need more than libsignal

Post Syndicated from original https://mjg59.dreamwidth.org/62598.html

(Disclaimer: I’m not a cryptographer, and I do not claim to be an expert in Signal. I’ve had this read over by a couple of people who are so with luck there’s no egregious errors, but any mistakes here are mine)

There are indications that Twitter is working on end-to-end encrypted DMs, likely building on work that was done back in 2018. This made use of libsignal, the reference implementation of the protocol used by the Signal encrypted messaging app. There seems to be a fairly widespread perception that, since libsignal is widely deployed (it’s also the basis for WhatsApp‘s e2e encryption) and open source and has been worked on by a whole bunch of cryptography experts, choosing to use libsignal means that 90% of the work has already been done. And in some ways this is true – the security of the protocol is probably just fine. But there’s rather more to producing a secure and usable client than just sprinkling on some libsignal.

(Aside: To be clear, I have no reason to believe that the people who were working on this feature in 2018 were unaware of this. This thread kind of implies that the practical problems are why it didn’t ship at the time. Given the reduction in Twitter’s engineering headcount, and given the new leadership’s espousal of political and social perspectives that don’t line up terribly well with the bulk of the cryptography community, I have doubts that any implementation deployed in the near future will get all of these details right)

I was musing about this last night and someone pointed out some prior art. Bridgefy is a messaging app that uses Bluetooth as its transport layer, allowing messaging even in the absence of data services. The initial implementation involved a bunch of custom cryptography, enabling a range of attacks ranging from denial of service to extracting plaintext from encrypted messages. In response to criticism Bridgefy replaced their custom cryptographic protocol with libsignal, but that didn’t fix everything. One issue is the potential for MITMing – keys are shared on first communication, but the client provided no mechanism to verify those keys, so a hostile actor could pretend to be a user, receive messages intended for that user, and then reencrypt them with the user’s actual key. This isn’t a weakness in libsignal, in the same way that the ability to add a custom certificate authority to a browser’s trust store isn’t a weakness in TLS. In Signal the app key distribution is all handled via Signal’s servers, so if you’re just using libsignal you need to implement the equivalent yourself.

The other issue was more subtle. libsignal has no awareness at all of the Bluetooth transport layer. Deciding where to send a message is up to the client, and these routing messages were spoofable. Any phone in the mesh could say “Send messages for Bob here”, and other phones would do so. This should have been a denial of service at worst, since the messages for Bob would still be encrypted with Bob’s key, so the attacker would be able to prevent Bob from receiving the messages but wouldn’t be able to decrypt them. However, the code to decide where to send the message and the code to decide which key to encrypt the message with were separate, and the routing decision was made before the encryption key decision. An attacker could send a message saying “Route messages for Bob to me”, and then another saying “Actually lol no I’m Mallory”. If a message was sent between those two messages, the message intended for Bob would be delivered to Mallory’s phone and encrypted with Mallory’s key.

Again, this isn’t a libsignal issue. libsignal encrypted the message using the key bundle it was told to encrypt it with, but the client code gave it a key bundle corresponding to the wrong user. A race condition in the client logic allowed messages intended for one person to be delivered to and readable by another.

This isn’t the only case where client code has used libsignal poorly. The Bond Touch is a Bluetooth-connected bracelet that you wear. Tapping it or drawing gestures sends a signal to your phone, which culminates in a message being sent to someone else’s phone which sends a signal to their bracelet, which then vibrates and glows in order to indicate a specific sentiment. The idea is that you can send brief indications of your feelings to someone you care about by simply tapping on your wrist, and they can know what you’re thinking without having to interrupt whatever they’re doing at the time. It’s kind of sweet in a way that I’m not, but it also advertised “Private Spaces”, a supposedly secure way to send chat messages and pictures, and that seemed more interesting. I grabbed the app and disassembled it, and found it was using libsignal. So I bought one and played with it, including dumping the traffic from the app. One important thing to realise is that libsignal is just the protocol library – it doesn’t implement a server, and so you still need some way to get information between clients. And one of the bits of information you have to get between clients is the public key material.

Back when I played with this earlier this year, key distribution was implemented by uploading the public key to a database. The other end would download the public key, and everything works out fine. And this doesn’t sound like a problem, given that the entire point of a public key is to be, well, public. Except that there was no access control on this database, and the filenames were simply phone numbers, so you could overwrite anyone’s public key with one of your choosing. This didn’t let you cause messages intended for them to be delivered to you, so exploiting this for anything other than a DoS would require another vulnerability somewhere, but there are contrived situations where this would potentially allow the privacy expectations to be broken.

Another issue with this app was its handling of one-time prekeys. When you send someone new a message via Signal, it’s encrypted with a key derived from not only the recipient’s identity key, but also from what’s referred to as a “one-time prekey”. Users generate a bunch of keypairs and upload the public half to the server. When you want to send a message to someone, you ask the server for one of their one-time prekeys and use that. Decrypting this message requires using the private half of the one-time prekey, and the recipient deletes it afterwards. This means that an attacker who intercepts a bunch of encrypted messages over the network and then later somehow obtains the long-term keys still won’t be able to decrypt the messages, since they depended on keys that no longer exist. Since these one-time prekeys are only supposed to be used once (it’s in the name!) there’s a risk that they can all be consumed before they’re replenished. The spec regarding pre-keys says that servers should consider rate-limiting this, but the protocol also supports falling back to just not using one-time prekeys if they’re exhausted (you lose the forward secrecy benefits, but it’s still end-to-end encrypted). This implementation not only implemented no rate-limiting, making it easy to exhaust the one-time prekeys, it then also failed to fall back to running without them. Another easy way to force DoS.

(And, remember, a successful DoS on an encrypted communications channel potentially results in the users falling back to an unencrypted communications channel instead. DoS may not break the encrypted protocol, but it may be sufficient to obtain plaintext anyway)

And finally, there’s ClearSignal. I looked at this earlier this year – it’s avoided many of these pitfalls by literally just being a modified version of the official Signal client and using the existing Signal servers (it’s even interoperable with Actual Signal), but it’s then got a bunch of other weirdness. The Signal database (I /think/ including the keys, but I haven’t completely verified that) gets backed up to an AWS S3 bucket, identified using something derived from a key using KERI, and I’ve seen no external review of that whatsoever. So, who knows. It also has crash reporting enabled, and it’s unclear how much internal state it sends on crashes, and it’s also based on an extremely old version of Signal with the “You need to upgrade Signal” functionality disabled.

Three clients all using libsignal in one form or another, and three clients that do things wrong in ways that potentially have a privacy impact. Again, none of these issues are down to issues with libsignal, they’re all in the code that surrounds it. And remember that Twitter probably has to worry about other issues as well! If I lose my phone I’m probably not going to worry too much about whether the messages sent through my weird bracelet app being gone forever, but losing all my Twitter DMs would be a significant change in behaviour from the status quo. But that’s not an easy thing to do when you’re not supposed to have access to any keys! Group chats? That’s another significant problem to deal with. And making the messages readable through the web UI as well as on mobile means dealing with another set of key distribution issues. Get any of this wrong in one way and the user experience doesn’t line up with expectations, get it wrong in another way and the worst case involves some of your users in countries with poor human rights records being executed.

Simply building something on top of libsignal doesn’t mean it’s secure. If you want meaningful functionality you need to build a lot of infrastructure around libsignal, and doing that well involves not just competent development and UX design, but also a strong understanding of security and cryptography. Given Twitter’s lost most of their engineering and is led by someone who’s alienated all the cryptographers I know, I wouldn’t be optimistic.

comment count unavailable comments

Making an Orbic Speed RC400L autoboot when USB power is attached

Post Syndicated from original https://mjg59.dreamwidth.org/62419.html

As I mentioned a couple of weeks ago, I’ve been trying to hack an Orbic Speed RC400L mobile hotspot so it’ll automatically boot when power is attached. When plugged in it would flash a “Welcome” screen and then switch to a display showing the battery charging – it wouldn’t show up on USB, and didn’t turn on any networking. So, my initial assumption was that the bootloader was making a policy decision not to boot Linux. After getting root (as described in the previous post), I was able to cat /proc/mtd and see that partition 7 was titled “aboot”. Aboot is a commonly used Android bootloader, based on Little Kernel – LK provides the hardware interface, aboot is simply an app that runs on top of it. I was able to find the source code for Quectel’s aboot, which is intended to run on the same SoC that’s in this hotspot, so it was relatively easy to line up a bunch of the Ghidra decompilation with actual source (top tip: find interesting strings in your decompilation and paste them into github search, and see whether you get a repo back).

Unfortunately looking through this showed various cases where bootloader policy decisions were made, but all of them seemed to result in Linux booting. Patching them and flashing the patched loader back to the hotspot didn’t change the behaviour. So now I was confused: it seemed like Linux was loading, but there wasn’t an obvious point in the boot scripts where it then decided not to do stuff. No boot logs were retained between boots, which made things even more annoying. But then I realised that, well, I have root – I can just do my own logging. I hacked in an additional init script to dump dmesg to /var, powered it down, and then plugged in a USB cable. It booted to the charging screen. I hit the power button and it booted fully, appearing on USB. I adb shelled in, checked the logs, and saw that it had booted twice. So, we were definitely entering Linux before showing the charging screen. But what was the difference?

Diffing the dmesg showed that there was a major distinction on the kernel command line. The kernel command line is data populated by the bootloader and then passed to the kernel – it’s how you provide arguments that alter kernel behaviour without having to recompile it, but it’s also exposed to userland by the running kernel so it also serves as a way for the bootloader to pass information to the running userland. The boot that resulted in the charging screen had a androidboot.poweronreason=USB argument, the one that booted fully had androidboot.poweronreason=PWRKEY. Searching the filesystem for androidboot.poweronreason showed that the script that configures USB did not enable USB if poweronreason was USB, and the same string also showed up in a bunch of other applications. The bootloader was always booting Linux, but it was telling Linux why it had booted, and if that reason was “USB” then Linux was choosing not to enable USB and not starting the networking stack.

One approach would be to modify every application that parsed this data and make it work even if the power on reason was “USB”. That would have been tedious. It seemed easier to modify the bootloader. Looking for that string in Ghidra showed that it was reading a register from the power management controller and then interpreting that to determine the reason it had booted. In effect, it was doing something like:

boot_reason = read_pmic_boot_reason();
switch(boot_reason) {
case 0x10:
  bootparam = strdup("androidboot.poweronreason=PWRKEY");
  break;
case 0x20:
  bootparam = strdup("androidboot.poweronreason=USB");
  break;
default:
  bootparam = strdup("androidboot.poweronreason=Hard_Reset");
}

Changing the 0x20 to 0xff meant that the USB case would never be detected, and it would fall through to the default. All the userland code was happy to accept “Hard_Reset” as a legitimate reason to boot, and now plugging in USB results in the modem booting to a functional state. Woo.

If you want to do this yourself, dump the aboot partition from your device, and search for the hex sequence “03 02 00 0a 20″”. Change the final 0x20 to 0xff, copy it back to the device, and write it to mtdblock7. If it doesn’t work, feel free to curse me, but I’m almost certainly going to be no use to you whatsoever. Also, please, do not just attempt to mechanically apply this to other hotspots. It’s not going to end well.

comment count unavailable comments

Making unphishable 2FA phishable

Post Syndicated from original https://mjg59.dreamwidth.org/62175.html

One of the huge benefits of WebAuthn is that it makes traditional phishing attacks impossible. An attacker sends you a link to a site that looks legitimate but isn’t, and you type in your credentials. With SMS or TOTP-based 2FA, you type in your second factor as well, and the attacker now has both your credentials and a legitimate (if time-limited) second factor token to log in with. WebAuthn prevents this by verifying that the site it’s sending the secret to is the one that issued it in the first place – visit an attacker-controlled site and said attacker may get your username and password, but they won’t be able to obtain a valid WebAuthn response.

But what if there was a mechanism for an attacker to direct a user to a legitimate login page, resulting in a happy WebAuthn flow, and obtain valid credentials for that user anyway? This seems like the lead-in to someone saying “The Aristocrats”, but unfortunately it’s (a) real, (b) RFC-defined, and (c) implemented in a whole bunch of places that handle sensitive credentials. The villain of this piece is RFC 8628, and while it exists for good reasons it can be used in a whole bunch of ways that have unfortunate security consequences.

What is the RFC 8628-defined Device Authorization Grant, and why does it exist? Imagine a device that you don’t want to type a password into – either it has no input devices at all (eg, some IoT thing) or it’s awkward to type a complicated password (eg, a TV with an on-screen keyboard). You want that device to be able to access resources on behalf of a user, so you want to ensure that that user authenticates the device. RFC 8628 describes an approach where the device requests the credentials, and then presents a code to the user (either on screen or over Bluetooth or something), and starts polling an endpoint for a result. The user visits a URL and types in that code (or is given a URL that has the code pre-populated) and is then guided through a standard auth process. The key distinction is that if the user authenticates correctly, the issued credentials are passed back to the device rather than the user – on successful auth, the endpoint the device is polling will return an oauth token.

But what happens if it’s not a device that requests the credentials, but an attacker? What if said attacker obfuscates the URL in some way and tricks a user into clicking it? The user will be presented with their legitimate ID provider login screen, and if they’re using a WebAuthn token for second factor it’ll work correctly (because it’s genuinely talking to the real ID provider!). The user will then typically be prompted to approve the request, but in every example I’ve seen the language used here is very generic and doesn’t describe what’s going on or ask the user. AWS simply says “An application or device requested authorization using your AWS sign-in” and has a big “Allow” button, giving the user no indication at all that hitting “Allow” may give a third party their credentials.

This isn’t novel! Christoph Tafani-Dereeper has an excellent writeup on this topic from last year, which builds on Nestori Syynimaa’s earlier work. But whenever I’ve talked about this, people seem surprised at the consequences. WebAuthn is supposed to protect against phishing attacks, but this approach subverts that protection by presenting the user with a legitimate login page and then handing their credentials to someone else.

RFC 8628 actually recognises this vector and presents a set of mitigations. Unfortunately nobody actually seems to implement these, and most of the mitigations are based around the idea that this flow will only be used for physical devices. Sadly, AWS uses this for initial authentication for the aws-cli tool, so there’s no device in that scenario. Another mitigation is that there’s a relatively short window where the code is valid, and so sending a link via email is likely to result in it expiring before the user clicks it. An attacker could avoid this by directing the user to a domain under their control that triggers the flow and then redirects the user to the login page, ensuring that the code is only generated after the user has clicked the link.

Can this be avoided? The best way to do so is to ensure that you don’t support this token issuance flow anywhere, or if you do then ensure that any tokens issued that way are extremely narrowly scoped. Unfortunately if you’re an AWS user, that’s probably not viable – this flow is required for the cli tool to perform SSO login, and users are going to end up with broadly scoped tokens as a result. The logs are also not terribly useful.

The infuriating thing is that this isn’t necessary for CLI tooling. The reason this approach is taken is that you need a way to get the token to a local process even if the user is doing authentication in a browser. This can be avoided by having the process listen on localhost, and then have the login flow redirect to localhost (including the token) on successful completion. In this scenario the attacker can’t get access to the token without having access to the user’s machine, and if they have that they probably have access to the token anyway.

There’s no real moral here other than “Security is hard”. Sorry.

comment count unavailable comments

Poking a mobile hotspot

Post Syndicated from original https://mjg59.dreamwidth.org/61725.html

I’ve been playing with an Orbic Speed, a relatively outdated device that only speaks LTE Cat 4, but the towers I can see from here are, uh, not well provisioned so throughput really isn’t a concern (and refurbs are $18, so). As usual I’m pretty terrible at just buying devices and using them for their intended purpose, and in this case it has the irritating behaviour that if there’s a power cut and the battery runs out it doesn’t boot again when power returns, so here’s what I’ve learned so far.

First, it’s clearly running Linux (nmap indicates that, as do the headers from the built-in webserver). The login page for the web interface has some text reading “Open Source Notice” that highlights when you move the mouse over it, but that’s it – there’s code to make the text light up, but it’s not actually a link. There’s no exposed license notices at all, although there is a copy on the filesystem that doesn’t seem to be reachable from anywhere. The notice tells you to email them to receive source code, but doesn’t actually provide an email address.

Still! Let’s see what else we can figure out. There’s no open ports other than the web server, but there is an update utility that includes some interesting components. First, there’s a copy of adb, the Android Debug Bridge. That doesn’t mean the device is running Android, it’s common for embedded devices from various vendors to use a bunch of Android infrastructure (including the bootloader) while having a non-Android userland on top. But this is still slightly surprising, because the device isn’t exposing an adb interface over USB. There’s also drivers for various Qualcomm endpoints that are, again, not exposed. Running the utility under Windows while the modem is connected results in the modem rebooting and Windows talking about new hardware being detected, and watching the device manager shows a bunch of COM ports being detected and bound by Qualcomm drivers. So, what’s it doing?

Sticking the utility into Ghidra and looking for strings that correspond to the output that the tool conveniently leaves in the logs subdirectory shows that after finding a device it calls vendor_device_send_cmd(). This is implemented in a copy of libusb-win32 that, again, has no offer for source code. But it’s also easy to drop that into Ghidra and discover thatn vendor_device_send_cmd() is just a wrapper for usb_control_msg(dev,0xc0,0xa0,0,0,NULL,0,1000);. Sending that from Linux results in the device rebooting and suddenly exposing some more USB endpoints, including a functional adb interface. Although, annoyingly, the rndis interface that enables USB tethering via the modem is now missing.

Unfortunately the adb user is unprivileged, but most files on the system are world-readable. data/logs/atfwd.log is especially interesting. This modem has an application processor built into the modem chipset itself, and while the modem implements the Hayes Command Set there’s also a mechanism for userland to register that certain AT commands should be pushed up to userland. These are handled by the atfwd_daemon that runs as root, and conveniently logs everything it’s up to. This includes having logged all the communications executed when the update tool was run earlier, so let’s dig into that.

The system sends a bunch of AT+SYSCMD= commands, each of which is in the form of echo (stuff) >>/usrdata/sec/chipid. Once that’s all done, it sends AT+CHIPID, receives a response of CHIPID:PASS, and then AT+SER=3,1, at which point the modem reboots back into the normal mode – adb is gone, but rndis is back. But the logs also reveal that between the CHIPID request and the response is a security check that involves RSA. The logs on the client side show that the text being written to the chipid file is a single block of base64 encoded data. Decoding it just gives apparently random binary. Heading back to Ghidra shows that atfwd_daemon is reading the chipid file and then decrypting it with an RSA key. The key is obtained by calling a series of functions, each of which returns a long base64-encoded string. Decoding each of these gives 1028 bytes of high entropy data, which is then passed to another function that decrypts it using AES CBC using a key of 000102030405060708090a0b0c0d0e0f and an initialization vector of all 0s. This is somewhat weird, since there’s 1028 bytes of data and 128 bit AES works on blocks of 16 bytes. The behaviour of OpenSSL is apparently to just pad the data out to a multiple of 16 bytes, but that implies that we’re going to end up with a block of garbage at the end. It turns out not to matter – despite the fact that we decrypt 1028 bytes of input only the first 200 bytes mean anything, with the rest just being garbage. Concatenating all of that together gives us a PKCS#8 private key blob in PEM format. Which means we have not only the private key, but also the public key.

So, what’s in the encrypted data, and where did it come from in the first place? It turns out to be a JSON blob that contains the IMEI and the serial number of the modem. This is information that can be read from the modem in the first place, so it’s not secret. The modem decrypts it, compares the values in the blob to its own values, and if they match sets a flag indicating that validation has succeeeded. But what encrypted it in the first place? It turns out that the json blob is just POSTed to http://pro.w.ifelman.com/api/encrypt and an encrypted blob returned. Of course, the fact that it’s being encrypted on the server with the public key and sent to the modem that decrypted with the private key means that having access to the modem gives us the public key as well, which means we can just encrypt our own blobs.

What does that buy us? Digging through the code shows the only case that it seems to matter is when parsing the AT+SER command. The first argument to this is the serial mode to transition to, and the second is whether this should be a temporary transition or a permanent one. Once parsed, these arguments are passed to /sbin/usb/compositions/switch_usb which just writes the mode out to /usrdata/mode.cfg (if permanent) or /usrdata/mode_tmp.cfg (if temporary). On boot, /data/usb/boot_hsusb_composition reads the number from this file and chooses which USB profile to apply. This requires no special permissions, except if the number is 3 – if so, the RSA verification has to be performed first. This is somewhat strange, since mode 9 gives the same rndis functionality as mode 3, but also still leaves the debug and diagnostic interfaces enabled.

So what’s the point of all of this? I’m honestly not sure! It doesn’t seem like any sort of effective enforcement mechanism (even ignoring the fact that you can just create your own blobs, if you change the IMEI on the device somehow, you can just POST the new values to the server and get back a new blob), so the best I’ve been able to come up with is to ensure that there’s some mapping between IMEI and serial number before the device can be transitioned into production mode during manufacturing.

But, uh, we can just ignore all of this anyway. Remember that AT+SYSCMD= stuff that was writing the data to /usrdata/sec/chipid in the first place? Anything that’s passed to AT+SYSCMD is just executed as root. Which means we can just write a new value (including 3) to /usrdata/mode.cfg in the first place, without needing to jump through any of these hoops. Which also means we can just adb push a shell onto there and then use the AT interface to make it suid root, which avoids needing to figure out how to exploit any of the bugs that are just sitting there given it’s running a 3.18.48 kernel.

Anyway, I’ve now got a modem that’s got working USB tethering and also exposes a working adb interface, and I’ve got root on it. Which let me dump the bootloader and discover that it implements fastboot and has an oem off-mode-charge command which solves the problem I wanted to solve of having the device boot when it gets power again. Unfortunately I still need to get into fastboot mode. I haven’t found a way to do it through software (adb reboot bootloader doesn’t do anything), but this post suggests it’s just a matter of grounding a test pad, at which point I should just be able to run fastboot oem off-mode-charge and it’ll be all set. But that’s a job for tomorrow.

comment count unavailable comments

Cloud desktops aren’t as good as you’d think

Post Syndicated from original https://mjg59.dreamwidth.org/61535.html

Fast laptops are expensive, cheap laptops are slow. But even a fast laptop is slower than a decent workstation, and if your developers want a local build environment they’re probably going to want a decent workstation. They’ll want a fast (and expensive) laptop as well, though, because they’re not going to carry their workstation home with them and obviously you expect them to be able to work from home. And in two or three years they’ll probably want a new laptop and a new workstation, and that’s even more money. Not to mention the risks associated with them doing development work on their laptop and then drunkenly leaving it in a bar or having it stolen or the contents being copied off it while they’re passing through immigration at an airport. Surely there’s a better way?

This is the thinking that leads to “Let’s give developers a Chromebook and a VM running in the cloud”. And it’s an appealing option! You spend far less on the laptop, and the VM is probably cheaper than the workstation – you can shut it down when it’s idle, you can upgrade it to have more CPUs and RAM as necessary, and you get to impose all sorts of additional neat security policies because you have full control over the network. You can run a full desktop environment on the VM, stream it to a cheap laptop, and get the fast workstation experience on something that weighs about a kilogram. Your developers get the benefit of a fast machine wherever they are, and everyone’s happy.

But having worked at more than one company that’s tried this approach, my experience is that very few people end up happy. I’m going to give a few reasons here, but I can’t guarantee that they cover everything – and, to be clear, many (possibly most) of the reasons I’m going to describe aren’t impossible to fix, they’re simply not priorities. I’m also going to restrict this discussion to the case of “We run a full graphical environment on the VM, and stream that to the laptop” – an approach that only offers SSH access is much more manageable, but also significantly more restricted in certain ways. With those details mentioned, let’s begin.

The first thing to note is that the overall experience is heavily tied to the protocol you use for the remote display. Chrome Remote Desktop is extremely appealing from a simplicity perspective, but is also lacking some extremely key features (eg, letting you use multiple displays on the local system), so from a developer perspective it’s suboptimal. If you read the rest of this post and want to try this anyway, spend some time working with your users to find out what their requirements are and figure out which technology best suits them.

Second, let’s talk about GPUs. Trying to run a modern desktop environment without any GPU acceleration is going to be a miserable experience. Sure, throwing enough CPU at the problem will get you past the worst of this, but you’re still going to end up with users who need to do 3D visualisation, or who are doing VR development, or who expect WebGL to work without burning up every single one of the CPU cores you so graciously allocated to their VM. Cloud providers will happily give you GPU instances, but that’s going to cost more and you’re going to need to re-run your numbers to verify that this is still a financial win. “But most of my users don’t need that!” you might say, and we’ll get to that later on.

Next! Video quality! This seems like a trivial point, but if you’re giving your users a VM as their primary interface, then they’re going to do things like try to use Youtube inside it because there’s a conference presentation that’s relevant to their interests. The obvious solution here is “Do your video streaming in a browser on the local system, not on the VM” but from personal experience that’s a super awkward pain point! If I click on a link inside the VM it’s going to open a browser there, and now I have a browser in the VM and a local browser and which of them contains the tab I’m looking for WHO CAN SAY. So your users are going to watch stuff inside their VM, and re-compressing decompressed video is going to look like shit unless you’re throwing a huge amount of bandwidth at the problem. And this is ignoring the additional irritation of your browser being unreadable while you’re rapidly scrolling through pages, or terminal output from build processes being a muddy blur of artifacts, or the corner case of “I work for Youtube and I need to be able to examine 4K streams to determine whether changes have resulted in a degraded experience” which is a very real job and one that becomes impossible when you pass their lovingly crafted optimisations through whatever codec your remote desktop protocol has decided to pick based on some random guesses about the local network, and look everyone is going to have a bad time.

The browser experience. As mentioned before, you’ll have local browsers and remote browsers. Do they have the same security policy? Who knows! Are all the third party services you depend on going to be ok with the same user being logged in from two different IPs simultaneously because they lost track of which browser they had an open session in? Who knows! Are your users going to become frustrated? Who knows oh wait no I know the answer to this one, it’s “yes”.

Accessibility! More of your users than you expect rely on various accessibility interfaces, be those mechanisms for increasing contrast, screen magnifiers, text-to-speech, speech-to-text, alternative input mechanisms and so on. And you probably don’t know this, but most of these mechanisms involve having accessibility software be able to introspect the UI of applications in order to provide appropriate input or expose available options and the like. So, I’m running a local text-to-speech agent. How does it know what’s happening in the remote VM? It doesn’t because it’s just getting an a/v stream, so you need to run another accessibility stack inside the remote VM and the two of them are unaware of each others existence and this works just as badly as you’d think. Alternative input mechanism? Good fucking luck with that, you’re at best going to fall back to “Send synthesized keyboard inputs” and that is nowhere near as good as “Set the contents of this text box to this unicode string” and yeah I used to work on accessibility software maybe you can tell. And how is the VM going to send data to a braille output device? Anyway, good luck with the lawsuits over arbitrarily making life harder for a bunch of members of a protected class.

One of the benefits here is supposed to be a security improvement, so let’s talk about WebAuthn. I’m a big fan of WebAuthn, given that it’s a multi-factor authentication mechanism that actually does a good job of protecting against phishing, but if my users are running stuff inside a VM, how do I use it? If you work at Google there’s a solution, but that does mean limiting yourself to Chrome Remote Desktop (there are extremely good reasons why this isn’t generally available). Microsoft have apparently just specced a mechanism for doing this over RDP, but otherwise you’re left doing stuff like forwarding USB over IP, and that means that your USB WebAuthn no longer works locally. It also doesn’t work for any other type of WebAuthn token, such as a bluetooth device, or an Apple TouchID sensor, or any of the Windows Hellow support. If you’re planning on moving to WebAuthn and also planning on moving to remote VM desktops, you’re going to have a bad time.

That’s the stuff that comes to mind immediately. And sure, maybe each of these issues is irrelevant to most of your users. But the actual question you need to ask is what percentage of your users will hit one or more of these, because if that’s more than an insignificant percentage you’ll still be staffing all the teams that dealt with hardware, handling local OS installs, worrying about lost or stolen devices, and the glorious future of just being able to stop worrying about this is going to be gone and the financial benefits you promised would appear are probably not going to work out in the same way.

A lot of this falls back to the usual story of corporate IT – understand the needs of your users and whether what you’re proposing actually meets them. Almost everything I’ve described here is a corner case, but if your company is larger than about 20 people there’s a high probability that at least one person is going to fall into at least one of these corner cases. You’re going to need to spend a lot of time understanding your user population to have a real understanding of what the actual costs are here, and I haven’t seen anyone do that work before trying to launch this and (inevitably) going back to just giving people actual computers.

There are alternatives! Modern IDEs tend to support SSHing out to remote hosts to perform builds there, so as long as you’re ok with source code being visible on laptops you can at least shift the “I need a workstation with a bunch of CPU” problem out to the cloud. The laptops are going to need to be more expensive because they’re also going to need to run more software locally, but it wouldn’t surprise me if this ends up being cheaper than the full-on cloud desktop experience in most cases.

Overall, the most important thing to take into account here is that your users almost certainly have more use cases than you expect, and this sort of change is going to have direct impact on the workflow of every single one of your users. Make sure you know how much that’s going to be, and take that into consideration when suggesting it’ll save you money.

comment count unavailable comments

Handling WebAuthn over remote SSH connections

Post Syndicated from original https://mjg59.dreamwidth.org/61232.html

Being able to SSH into remote machines and do work there is great. Using hardware security tokens for 2FA is also great. But trying to use them both at the same time doesn’t work super well, because if you hit a WebAuthn request on the remote machine it doesn’t matter how much you mash your token – it’s not going to work.

But could it?

The SSH agent protocol abstracts key management out of SSH itself and into a separate process. When you run “ssh-add .ssh/id_rsa”, that key is being loaded into the SSH agent. When SSH wants to use that key to authenticate to a remote system, it asks the SSH agent to perform the cryptographic signatures on its behalf. SSH also supports forwarding the SSH agent protocol over SSH itself, so if you SSH into a remote system then remote clients can also access your keys – this allows you to bounce through one remote system into another without having to copy your keys to those remote systems.

More recently, SSH gained the ability to store SSH keys on hardware tokens such as Yubikeys. If configured appropriately, this means that even if you forward your agent to a remote site, that site can’t do anything with your keys unless you physically touch the token. But out of the box, this is only useful for SSH keys – you can’t do anything else with this support.

Well, that’s what I thought, at least. And then I looked at the code and realised that SSH is communicating with the security tokens using the same library that a browser would, except it ensures that any signature request starts with the string “ssh:” (which a genuine WebAuthn request never will). This constraint can actually be disabled by passing -O no-restrict-websafe to ssh-agent, except that was broken until this weekend. But let’s assume there’s a glorious future where that patch gets backported everywhere, and see what we can do with it.

First we need to load the key into the security token. For this I ended up hacking up the Go SSH agent support. Annoyingly it doesn’t seem to be possible to make calls to the agent without going via one of the exported methods here, so I don’t think this logic can be implemented without modifying the agent module itself. But this is basically as simple as adding another key message type that looks something like:

type ecdsaSkKeyMsg struct {
       Type        string `sshtype:"17|25"`
       Curve       string
       PubKeyBytes []byte
       RpId        string
       Flags       uint8
       KeyHandle   []byte
       Reserved    []byte
       Comments    string
       Constraints []byte `ssh:"rest"`
}

Where Type is ssh.KeyAlgoSKECDSA256, Curve is “nistp256”, RpId is the identity of the relying party (eg, “webauthn.io”), Flags is 0x1 if you want the user to have to touch the key, KeyHandle is the hardware token’s representation of the key (basically an opaque blob that’s sufficient for the token to regenerate the keypair – this is generally stored by the remote site and handed back to you when it wants you to authenticate). The other fields can be ignored, other than PubKeyBytes, which is supposed to be the public half of the keypair.

This causes an obvious problem. We have an opaque blob that represents a keypair. We don’t have the public key. And OpenSSH verifies that PubKeyByes is a legitimate ecdsa public key before it’ll load the key. Fortunately it only verifies that it’s a legitimate ecdsa public key, and does nothing to verify that it’s related to the private key in any way. So, just generate a new ECDSA key (ecdsa.GenerateKey(elliptic.P256(), rand.Reader)) and marshal it ( elliptic.Marshal(ecKey.Curve, ecKey.X, ecKey.Y)) and we’re good. Pass that struct to ssh.Marshal() and then make an agent call.

Now you can use the standard agent interfaces to trigger a signature event. You want to pass the raw challenge (not the hash of the challenge!) – the SSH code will do the hashing itself. If you’re using agent forwarding this will be forwarded from the remote system to your local one, and your security token should start blinking – touch it and you’ll get back an ssh.Signature blob. ssh.Unmarshal() the Blob member to a struct like

type ecSig struct {
        R *big.Int
        S *big.Int
}

and then ssh.Unmarshal the Rest member to

type authData struct {
        Flags    uint8
        SigCount uint32
}

The signature needs to be converted back to a DER-encoded ASN.1 structure (eg,

var b cryptobyte.Builder
b.AddASN1(asn1.SEQUENCE, func(b *cryptobyte.Builder) {
        b.AddASN1BigInt(ecSig.R)
        b.AddASN1BigInt(ecSig.S)
})
signatureDER, _ := b.Bytes()

, and then you need to construct the Authenticator Data structure. For this, take the RpId used earlier and generate the sha256. Append the one byte Flags variable, and then convert SigCount to big endian and append those 4 bytes. You should now have a 37 byte structure. This needs to be CBOR encoded (I used github.com/fxamacker/cbor and just called cbor.Marshal(data, cbor.EncOptions{})).

Now base64 encode the sha256 of the challenge data, the DER-encoded signature and the CBOR-encoded authenticator data and you’ve got everything you need to provide to the remote site to satisfy the challenge.

There are alternative approaches – you can use USB/IP to forward the hardware token directly to the remote system. But that means you can’t use it locally, so it’s less than ideal. Or you could implement a proxy that communicates with the key locally and have that tunneled through to the remote host, but at that point you’re just reinventing ssh-agent.

And you should bear in mind that the default behaviour of blocking this sort of request is for a good reason! If someone is able to compromise a remote system that you’re SSHed into, they can potentially trick you into hitting the key to sign a request they’ve made on behalf of an arbitrary site. Obviously they could do the same without any of this if they’ve compromised your local system, but there is some additional risk to this. It would be nice to have sensible MAC policies that default-denied access to the SSH agent socket and only allowed trustworthy binaries to do so, or maybe have some sort of reasonable flatpak-style portal to gate access. For my threat model I think it’s a worthwhile security tradeoff, but you should evaluate that carefully yourself.

Anyway. Now to figure out whether there’s a reasonable way to get browsers to work with this.

comment count unavailable comments

Bring Your Own Disaster

Post Syndicated from original https://mjg59.dreamwidth.org/61089.html

After my last post, someone suggested that having employers be able to restrict keys to machines they control is a bad thing. So here’s why I think Bring Your Own Device (BYOD) scenarios are bad not only for employers, but also for users.

There’s obvious mutual appeal to having developers use their own hardware rather than rely on employer-provided hardware. The user gets to use hardware they’re familiar with, and which matches their ergonomic desires. The employer gets to save on the money required to buy new hardware for the employee. From this perspective, there’s a clear win-win outcome.

But once you start thinking about security, it gets more complicated. If I, as an employer, want to ensure that any systems that can access my resources meet a certain security baseline (eg, I don’t want my developers using unpatched Windows ME), I need some of my own software installed on there. And that software doesn’t magically go away when the user is doing their own thing. If a user lends their machine to their partner, is the partner fully informed about what level of access I have? Are they going to feel that their privacy has been violated if they find out afterwards?

But it’s not just about monitoring. If an employee’s machine is compromised and the compromise is detected, what happens next? If the employer owns the system then it’s easy – you pick up the device for forensic analysis and give the employee a new machine to use while that’s going on. If the employee owns the system, they’re probably not going to be super enthusiastic about handing over a machine that also contains a bunch of their personal data. In much of the world the law is probably on their side, and even if it isn’t then telling the employee that they have a choice between handing over their laptop or getting fired probably isn’t going to end well.

But obviously this is all predicated on the idea that an employer needs visibility into what’s happening on systems that have access to their systems, or which are used to develop code that they’ll be deploying. And I think it’s fair to say that not everyone needs that! But if you hold any sort of personal data (including passwords) for any external users, I really do think you need to protect against compromised employee machines, and that does mean having some degree of insight into what’s happening on those machines. If you don’t want to deal with the complicated consequences of allowing employees to use their own hardware, it’s rational to ensure that only employer-owned hardware can be used.

But what about the employers that don’t currently need that? If there’s no plausible future where you’ll host user data, or where you’ll sell products to others who’ll host user data, then sure! But if that might happen in future (even if it doesn’t right now), what’s your transition plan? How are you going to deal with employees who are happily using their personal systems right now? At what point are you going to buy new laptops for everyone? BYOD might work for you now, but will it always?

And if your employer insists on employees using their own hardware, those employees should ask what happens in the event of a security breach. Whose responsibility is it to ensure that hardware is kept up to date? Is there an expectation that security can insist on the hardware being handed over for investigation? What information about the employee’s use of their own hardware is going to be logged, who has access to those logs, and how long are those logs going to be kept for? If those questions can’t be answered in a reasonable way, it’s a huge red flag. You shouldn’t have to give up your privacy and (potentially) your hardware for a job.

Using technical mechanisms to ensure that employees only use employer-provided hardware is understandably icky, but it’s something that allows employers to impose appropriate security policies without violating employee privacy.

comment count unavailable comments

git signatures with SSH certificates

Post Syndicated from original https://mjg59.dreamwidth.org/60916.html

Last night I complained that git’s SSH signature format didn’t support using SSH certificates rather than raw keys, and was swiftly corrected, once again highlighting that the best way to make something happen is to complain about it on the internet in order to trigger the universe to retcon it into existence to make you look like a fool. But anyway. Let’s talk about making this work!

git’s SSH signing support is actually just it shelling out to ssh-keygen with a specific set of options, so let’s go through an example of this with ssh-keygen. First, here’s my certificate:

$ ssh-keygen -L -f id_aurora-cert.pub
id_aurora-cert.pub:
Type: [email protected] user certificate
Public key: ECDSA-CERT SHA256:(elided)
Signing CA: RSA SHA256:(elided)
Key ID: "[email protected]"
Serial: 10505979558050566331
Valid: from 2022-09-13T17:23:53 to 2022-09-14T13:24:23
Principals:
[email protected]
Critical Options: (none)
Extensions:
permit-agent-forwarding
permit-port-forwarding
permit-pty

Ok! Now let’s sign something:

$ ssh-keygen -Y sign -f ~/.ssh/id_aurora-cert.pub -n git /tmp/testfile
Signing file /tmp/testfile
Write signature to /tmp/testfile.sig

To verify this we need an allowed signatures file, which should look something like:

*@aurora.tech cert-authority ssh-rsa AAA(elided)

Perfect. Let’s verify it:

$ cat /tmp/testfile | ssh-keygen -Y verify -f /tmp/allowed_signers -I [email protected] -n git -s /tmp/testfile.sig
Good "git" signature for [email protected] with ECDSA-CERT key SHA256:(elided)

Woo! So, how do we make use of this in git? Generating the signatures is as simple as

$ git config --global commit.gpgsign true
$ git config --global gpg.format ssh
$ git config --global user.signingkey /home/mjg59/.ssh/id_aurora-cert.pub

and then getting on with life. Any commits will now be signed with the provided certificate. Unfortunately, git itself won’t handle verification of these – it calls ssh-keygen -Y find-principals which doesn’t deal with wildcards in the allowed signers file correctly, and then falls back to verifying the signature without making any assertions about identity. Which means you’re going to have to implement this in your own CI by extracting the commit and the signature, extracting the identity from the commit metadata and calling ssh-keygen on your own. But it can be made to work!

But why would you want to? The current approach of managing keys for git isn’t ideal – you can kind of piggy-back off github/gitlab SSH key infrastructure, but if you’re an enterprise using SSH certificates for access then your users don’t necessarily have enrolled keys to start with. And using certificates gives you extra benefits, such as having your CA verify that keys are hardware-backed before issuing a cert. Want to ensure that whoever made a commit was actually on an authorised laptop? Now you can!

I’ll probably spend a little while looking into whether it’s plausible to make the git verification code work with certificates or whether the right thing is to fix up ssh-keygen -Y find-principals to work with wildcard identities, but either way it’s probably not much effort to get this working out of the box.

comment count unavailable comments

UEFI rootkits and UEFI secure boot

Post Syndicated from original https://mjg59.dreamwidth.org/60654.html

Kaspersky describes a UEFI-implant used to attack Windows systems. Based on it appearing to require patching of the system firmware image, they hypothesise that it’s propagated by manually dumping the contents of the system flash, modifying it, and then reflashing it back to the board. This probably requires physical access to the board, so it’s not especially terrifying – if you’re in a situation where someone’s sufficiently enthusiastic about targeting you that they’re reflashing your computer by hand, it’s likely that you’re going to have a bad time regardless.

But let’s think about why this is in the firmware at all. Sophos previously discussed an implant that’s sufficiently similar in some technical details that Kaspersky suggest they may be related to some degree. One notable difference is that the MyKings implant described by Sophos installs itself into the boot block of legacy MBR partitioned disks. This code will only be executed on old-style BIOS systems (or UEFI systems booting in BIOS compatibility mode), and they have no support for code signatures, so there’s no need to be especially clever. Run malicious code in the boot block, patch the next stage loader, follow that chain all the way up to the kernel. Simple.

One notable distinction here is that the MBR boot block approach won’t be persistent – if you reinstall the OS, the MBR will be rewritten[1] and the infection is gone. UEFI doesn’t really change much here – if you reinstall Windows a new copy of the bootloader will be written out and the UEFI boot variables (that tell the firmware which bootloader to execute) will be updated to point at that. The implant may still be on disk somewhere, but it won’t be run.

But there’s a way to avoid this. UEFI supports loading firmware-level drivers from disk. If, rather than providing a backdoored bootloader, the implant takes the form of a UEFI driver, the attacker can set a different set of variables that tell the firmware to load that driver at boot time, before running the bootloader. OS reinstalls won’t modify these variables, which means the implant will survive and can reinfect the new OS install. The only way to get rid of the implant is to either reformat the drive entirely (which most OS installers won’t do by default) or replace the drive before installation.

This is much easier than patching the system firmware, and achieves similar outcomes – the number of infected users who are going to wipe their drives to reinstall is fairly low, and the kernel could be patched to hide the presence of the implant on the filesystem[2]. It’s possible that the goal was to make identification as hard as possible, but there’s a simpler argument here – if the firmware has UEFI Secure Boot enabled, the firmware will refuse to load such a driver, and the implant won’t work. You could certainly just patch the firmware to disable secure boot and lie about it, but if you’re at the point of patching the firmware anyway you may as well just do the extra work of installing your implant there.

I think there’s a reasonable argument that the existence of firmware-level rootkits suggests that UEFI Secure Boot is doing its job and is pushing attackers into lower levels of the stack in order to obtain the same outcomes. Technologies like Intel’s Boot Guard may (in their current form) tend to block user choice, but in theory should be effective in blocking attacks of this form and making things even harder for attackers. It should already be impossible to perform attacks like the one Kaspersky describes on more modern hardware (the system should identify that the firmware has been tampered with and fail to boot), which pushes things even further – attackers will have to take advantage of vulnerabilities in the specific firmware they’re targeting. This obviously means there’s an incentive to find more firmware vulnerabilities, which means the ability to apply security updates for system firmware as easily as security updates for OS components is vital (hint hint if your system firmware updates aren’t available via LVFS you’re probably doing it wrong).

We’ve known that UEFI rootkits have existed for a while (Hacking Team had one in 2015), but it’s interesting to see a fairly widespread one out in the wild. Protecting against this kind of attack involves securing the entire boot chain, including the firmware itself. The industry has clearly been making progress in this respect, and it’ll be interesting to see whether such attacks become more common (because Secure Boot works but firmware security is bad) or not.

[1] As we all remember from Windows installs overwriting Linux bootloaders
[2] Although this does run the risk of an infected user booting another OS instead, and being able to see the implant

comment count unavailable comments

Responsible stewardship of the UEFI secure boot ecosystem

Post Syndicated from original https://mjg59.dreamwidth.org/60248.html

After I mentioned that Lenovo are now shipping laptops that only boot Windows by default, a few people pointed to a Lenovo document that:
Starting in 2022 for Secured-core PCs it is a Microsoft requirement for the 3rd Party Certificate to be disabled by default.
“Secured-core” is a term used to describe machines that meet a certain set of Microsoft requirements around firmware security, and by and large it’s a good thing – devices that meet these requirements are resilient against a whole bunch of potential attacks in the early boot process. But unfortunately the 2022 requirements don’t seem to be publicly available, so it’s difficult to know what’s being asked for and why. But first, some background.

Most x86 UEFI systems that support Secure Boot trust at least two certificate authorities:

1) The Microsoft Windows Production PCA – this is used to sign the bootloader in production Windows builds. Trusting this is sufficient to boot Windows.
2) The Microsoft Corporation UEFI CA – this is used by Microsoft to sign non-Windows UEFI binaries, including built-in drivers for hardware that needs to work in the UEFI environment (such as GPUs and network cards) and bootloaders for non-Windows.

The apparent secured-core requirement for 2022 is that the second of these CAs should not be trusted by default. As a result, drivers or bootloaders signed with this certificate will not run on these systems. This means that, out of the box, these systems will not boot anything other than Windows[1].

Given the association with the secured-core requirements, this is presumably a security decision of some kind. Unfortunately, we have no real idea what this security decision is intended to protect against. The most likely scenario is concerns about the (in)security of binaries signed with the third-party signing key – there are some legitimate concerns here, but I’m going to cover why I don’t think they’re terribly realistic.

The first point is that, from a boot security perspective, a signed bootloader that will happily boot unsigned code kind of defeats the point. Kaspersky did it anyway. The second is that even a signed bootloader that is intended to only boot signed code may run into issues in the event of security vulnerabilities – the Boothole vulnerabilities are an example of this, covering multiple issues in GRUB that could allow for arbitrary code execution and potential loading of untrusted code.

So we know that signed bootloaders that will (either through accident or design) execute unsigned code exist. The signatures for all the known vulnerable bootloaders have been revoked, but that doesn’t mean there won’t be other vulnerabilities discovered in future. Configuring systems so that they don’t trust the third-party CA means that those signed bootloaders won’t be trusted, which means any future vulnerabilities will be irrelevant. This seems like a simple choice?

There’s actually a couple of reasons why I don’t think it’s anywhere near that simple. The first is that whenever a signed object is booted by the firmware, the trusted certificate used to verify that object is measured into PCR 7 in the TPM. If a system previously booted with something signed with the Windows Production CA, and is now suddenly booting with something signed with the third-party UEFI CA, the values in PCR 7 will be different. TPMs support “sealing” a secret – encrypting it with a policy that the TPM will only decrypt it if certain conditions are met. Microsoft make use of this for their default Bitlocker disk encryption mechanism. The disk encryption key is encrypted by the TPM, and associated with a specific PCR 7 value. If the value of PCR 7 doesn’t match, the TPM will refuse to decrypt the key, and the machine won’t boot. This means that attempting to attack a Windows system that has Bitlocker enabled using a non-Windows bootloader will fail – the system will be unable to obtain the disk unlock key, which is a strong indication to the owner that they’re being attacked.

The second is that this is predicated on the idea that removing the third-party bootloaders and drivers removes all the vulnerabilities. In fact, there’s been rather a lot of vulnerabilities in the Windows bootloader. A broad enough vulnerability in the Windows bootloader is arguably a lot worse than a vulnerability in a third-party loader, since it won’t change the PCR 7 measurements and the system will boot happily. Removing trust in the third-party CA does nothing to protect against this.

The third reason doesn’t apply to all systems, but it does to many. System vendors frequently want to ship diagnostic or management utilities that run in the boot environment, but would prefer not to have to go to the trouble of getting them all signed by Microsoft. The simple solution to this is to ship their own certificate and sign all their tooling directly – the secured-core Lenovo I’m looking at currently is an example of this, with a Lenovo signing certificate. While everything signed with the third-party signing certificate goes through some degree of security review, there’s no requirement for any vendor tooling to be reviewed at all. Removing the third-party CA does nothing to protect the user against the code that’s most likely to contain vulnerabilities.

Obviously I may be missing something here – Microsoft may well have a strong technical justification. But they haven’t shared it, and so right now we’re left making guesses. And right now, I just don’t see a good security argument.

But let’s move on from the technical side of things and discuss the broader issue. The reason UEFI Secure Boot is present on most x86 systems is that Microsoft mandated it back in 2012. Microsoft chose to be the only trusted signing authority. Microsoft made the decision to assert that third-party code could be signed and trusted.

We’ve certainly learned some things since then, and a bunch of things have changed. Third-party bootloaders based on the Shim infrastructure are now reviewed via a community-managed process. We’ve had a productive coordinated response to the Boothole incident, which also taught us that the existing revocation strategy wasn’t going to scale. In response, the community worked with Microsoft to develop a specification for making it easier to handle similar events in future. And it’s also worth noting that after the initial Boothole disclosure was made to the GRUB maintainers, they proactively sought out other vulnerabilities in their codebase rather than simply patching what had been reported. The free software community has gone to great lengths to ensure third-party bootloaders are compatible with the security goals of UEFI Secure Boot.

So, to have Microsoft, the self-appointed steward of the UEFI Secure Boot ecosystem, turn round and say that a bunch of binaries that have been reviewed through processes developed in negotiation with Microsoft, implementing technologies designed to make management of revocation easier for Microsoft, and incorporating fixes for vulnerabilities discovered by the developers of those binaries who notified Microsoft of these issues despite having no obligation to do so, and which have then been signed by Microsoft are now considered by Microsoft to be insecure is, uh, kind of impolite? Especially when unreviewed vendor-signed binaries are still considered trustworthy, despite no external review being carried out at all.

If Microsoft had a set of criteria used to determine whether something is considered sufficiently trustworthy, we could determine which of these we fell short on and do something about that. From a technical perspective, Microsoft could set criteria that would allow a subset of third-party binaries that met additional review be trusted without having to trust all third-party binaries[2]. But, instead, this has been a decision made by the steward of this ecosystem without consulting major stakeholders.

If there are legitimate security concerns, let’s talk about them and come up with solutions that fix them without doing a significant amount of collateral damage. Don’t complain about a vendor blocking your apps and then do the same thing yourself.

[1] They’ll also refuse to run any drivers that are stored in flash on Thunderbolt devices, which means eGPU setups may be more complicated, as will netbooting off Thunderbolt-attached NICs
[2] Use a different leaf cert to sign the new trust tier, add the old leaf cert to dbx unless a config option is set, leave the existing intermediate in db

comment count unavailable comments

Lenovo shipping new laptops that only boot Windows by default

Post Syndicated from original https://mjg59.dreamwidth.org/59931.html

I finally managed to get hold of a Thinkpad Z13 to examine a functional implementation of Microsoft’s Pluton security co-processor. Trying to boot Linux from a USB stick failed out of the box for no obvious reason, but after further examination the cause became clear – the firmware defaults to not trusting bootloaders or drivers signed with the Microsoft 3rd Party UEFI CA key. This means that given the default firmware configuration, nothing other than Windows will boot. It also means that you won’t be able to boot from any third-party external peripherals that are plugged in via Thunderbolt.

There’s no security benefit to this. If you want security here you’re paying attention to the values measured into the TPM, and thanks to Microsoft’s own specification for measurements made into PCR 7, switching from booting Windows to booting something signed with the 3rd party signing key will change the measurements and invalidate any sealed secrets. It’s trivial to detect this. Distrusting the 3rd party CA by default doesn’t improve security, it just makes it harder for users to boot alternative operating systems.

Lenovo, this isn’t OK. The entire architecture of UEFI secure boot is that it allows for security without compromising user choice of OS. Restricting boot to Windows by default provides no security benefit but makes it harder for people to run the OS they want to. Please fix it.

comment count unavailable comments

Can we fix bearer tokens?

Post Syndicated from original https://mjg59.dreamwidth.org/59704.html

Last month I wrote about how bearer tokens are just awful, and a week later Github announced that someone had managed to exfiltrate bearer tokens from Heroku that gave them access to, well, a lot of Github repositories. This has inevitably resulted in a whole bunch of discussion about a number of things, but people seem to be largely ignoring the fundamental issue that maybe we just shouldn’t have magical blobs that grant you access to basically everything even if you’ve copied them from a legitimate holder to Honest John’s Totally Legitimate API Consumer.

To make it clearer what the problem is here, let’s use an analogy. You have a safety deposit box. To gain access to it, you simply need to be able to open it with a key you were given. Anyone who turns up with the key can open the box and do whatever they want with the contents. Unfortunately, the key is extremely easy to copy – anyone who is able to get hold of your keyring for a moment is in a position to duplicate it, and then they have access to the box. Wouldn’t it be better if something could be done to ensure that whoever showed up with a working key was someone who was actually authorised to have that key?

To achieve that we need some way to verify the identity of the person holding the key. In the physical world we have a range of ways to achieve this, from simply checking whether someone has a piece of ID that associates them with the safety deposit box all the way up to invasive biometric measurements that supposedly verify that they’re definitely the same person. But computers don’t have passports or fingerprints, so we need another way to identify them.

When you open a browser and try to connect to your bank, the bank’s website provides a TLS certificate that lets your browser know that you’re talking to your bank instead of someone pretending to be your bank. The spec allows this to be a bi-directional transaction – you can also prove your identity to the remote website. This is referred to as “mutual TLS”, or mTLS, and a successful mTLS transaction ends up with both ends knowing who they’re talking to, as long as they have a reason to trust the certificate they were presented with.

That’s actually a pretty big constraint! We have a reasonable model for the server – it’s something that’s issued by a trusted third party and it’s tied to the DNS name for the server in question. Clients don’t tend to have stable DNS identity, and that makes the entire thing sort of awkward. But, thankfully, maybe we don’t need to? We don’t need the client to be able to prove its identity to arbitrary third party sites here – we just need the client to be able to prove it’s a legitimate holder of whichever bearer token it’s presenting to that site. And that’s a much easier problem.

Here’s the simple solution – clients generate a TLS cert. This can be self-signed, because all we want to do here is be able to verify whether the machine talking to us is the same one that had a token issued to it. The client contacts a service that’s going to give it a bearer token. The service requests mTLS auth without being picky about the certificate that’s presented. The service embeds a hash of that certificate in the token before handing it back to the client. Whenever the client presents that token to any other service, the service ensures that the mTLS cert the client presented matches the hash in the bearer token. Copy the token without copying the mTLS certificate and the token gets rejected. Hurrah hurrah hats for everyone.

Well except for the obvious problem that if you’re in a position to exfiltrate the bearer tokens you can probably just steal the client certificates and keys as well, and now you can pretend to be the original client and this is not adding much additional security. Fortunately pretty much everything we care about has the ability to store the private half of an asymmetric key in hardware (TPMs on Linux and Windows systems, the Secure Enclave on Macs and iPhones, either a piece of magical hardware or Trustzone on Android) in a way that avoids anyone being able to just steal the key.

How do we know that the key is actually in hardware? Here’s the fun bit – it doesn’t matter. If you’re issuing a bearer token to a system then you’re already asserting that the system is trusted. If the system is lying to you about whether or not the key it’s presenting is hardware-backed then you’ve already lost. If it lied and the system is later compromised then sure all your apes get stolen, but maybe don’t run systems that lie and avoid that situation as a result?

Anyway. This is covered in RFC 8705 so why aren’t we all doing this already? From the client side, the largest generic issue is that TPMs are astonishingly slow in comparison to doing a TLS handshake on the CPU. RSA signing operations on TPMs can take around half a second, which doesn’t sound too bad, except your browser is probably establishing multiple TLS connections to subdomains on the site it’s connecting to and performance is going to tank. Fixing this involves doing whatever’s necessary to convince the browser to pipe everything over a single TLS connection, and that’s just not really where the web is right at the moment. Using EC keys instead helps a lot (~0.1 seconds per signature on modern TPMs), but it’s still going to be a bottleneck.

The other problem, of course, is that ecosystem support for hardware-backed certificates is just awful. Windows lets you stick them into the standard platform certificate store, but the docs for this are hidden in a random PDF in a Github repo. Macs require you to do some weird bridging between the Secure Enclave API and the keychain API. Linux? Well, the standard answer is to do PKCS#11, and I have literally never met anybody who likes PKCS#11 and I have spent a bunch of time in standards meetings with the sort of people you might expect to like PKCS#11 and even they don’t like it. It turns out that loading a bunch of random C bullshit that has strong feelings about function pointers into your security critical process is not necessarily something that is going to improve your quality of life, so instead you should use something like this and just have enough C to bridge to a language that isn’t secretly plotting to kill your pets the moment you turn your back.

And, uh, obviously none of this matters at all unless people actually support it. Github has no support at all for validating the identity of whoever holds a bearer token. Most issuers of bearer tokens have no support for embedding holder identity into the token. This is not good! As of last week, all three of the big cloud providers support virtualised TPMs in their VMs – we should be running CI on systems that can do that, and tying any issued tokens to the VMs that are supposed to be making use of them.

So sure this isn’t trivial. But it’s also not impossible, and making this stuff work would improve the security of, well, everything. We literally have the technology to prevent attacks like Github suffered. What do we have to do to get people to actually start working on implementing that?

comment count unavailable comments

The Freedom Phone is not great at privacy

Post Syndicated from original https://mjg59.dreamwidth.org/59479.html

The Freedom Phone advertises itself as a “Free speech and privacy first focused phone”. As documented on the features page, it runs ClearOS, an Android-based OS produced by Clear United (or maybe one of the bewildering array of associated companies, we’ll come back to that later). It’s advertised as including Signal, but what’s shipped is not the version available from the Signal website or any official app store – instead it’s this fork called “ClearSignal”.

The first thing to note about ClearSignal is that the privacy policy link from that page 404s, which is not a great start. The second thing is that it has a version number of 5.8.14, which is strange because upstream went from 5.8.10 to 5.9.0. The third is that, despite Signal being GPL 3, there’s no source code available. So, I grabbed jadx and started looking for differences between ClearSignal and the upstream 5.8.10 release. The results were, uh, surprising.

First up is that they seem to have integrated ACRA, a crash reporting framework. This feels a little odd – in the absence of a privacy policy, it’s unclear what information this gathers or how it’ll be stored. Having a piece of privacy software automatically uploading information about what you were doing in the event of a crash with no notification other than a toast that appears saying “Crash Report” feels a little dubious.

Next is that Signal (for fairly obvious reasons) warns you if your version is out of date and eventually refuses to work unless you upgrade. ClearSignal has dealt with this problem by, uh, simply removing that code. The MacOS version of the desktop app they provide for download seems to be derived from a release from last September, which for an Electron-based app feels like a pretty terrible idea. Weirdly, for Windows they link to an official binary release from February 2021, and for Linux they tell you how to use the upstream repo properly. I have no idea what’s going on here.

They’ve also added support for network backups of your Signal data. This involves the backups being pushed to an S3 bucket using credentials that are statically available in the app. It’s ok, though, each upload has some sort of nominally unique identifier associated with it, so it’s not trivial to just download other people’s backups. But, uh, where does this identifier come from? It turns out that Clear Center, another of the Clear family of companies, employs a bunch of people to work on a ClearID[1], some sort of decentralised something or other that seems to be based on KERI. There’s an overview slide deck here which didn’t really answer any of my questions and as far as I can tell this is entirely lacking any sort of peer review, but hey it’s only the one thing that stops anyone on the internet being able to grab your Signal backups so how important can it be.

The final thing, though? They’ve extended Signal’s invitation support to encourage users to get others to sign up for Clear United. There’s an exposed API endpoint called “get_user_email_by_mobile_number” which does exactly what you’d expect – if you give it a registered phone number, it gives you back the associated email address. This requires no authentication. But it gets better! The API to generate a referral link to send to others sends the name and phone number of everyone in your phone’s contact list. There does not appear to be any indication that this is going to happen.

So, from a privacy perspective, going to go with things being some distance from ideal. But what’s going on with all these Clear companies anyway? They all seem to be related to Michael Proper, who founded the Clear Foundation in 2009. They are, perhaps unsurprisingly, heavily invested in blockchain stuff, while Clear United also appears to be some sort of multi-level marketing scheme which has a membership agreement that includes the somewhat astonishing claim that:

Specifically, the initial focus of the Association will provide members with supplements and technologies for:

9a. Frequency Evaluation, Scans, Reports;

9b. Remote Frequency Health Tuning through Quantum Entanglement;

9c. General and Customized Frequency Optimizations;

– there’s more discussion of this and other weirdness here. Clear Center, meanwhile, has a Chief Physics Officer? I have a lot of questions.

Anyway. We have a company that seems to be combining blockchain and MLM, has some opinions about Quantum Entanglement, bases the security of its platform on a set of novel cryptographic primitives that seem to have had no external review, has implemented an API that just hands out personal information without any authentication and an app that appears more than happy to upload all your contact details without telling you first, has failed to update this app to keep up with upstream security updates, and is violating the upstream license. If this is their idea of “privacy first”, I really hate to think what their code looks like when privacy comes further down the list.

[1] Pointed out to me here

comment count unavailable comments

Bearer tokens are just awful

Post Syndicated from original https://mjg59.dreamwidth.org/59353.html

As I mentioned last time, bearer tokens are not super compatible with a model in which every access is verified to ensure it’s coming from a trusted device. Let’s talk about that in a bit more detail.

First off, what is a bearer token? In its simplest form, it’s simply an opaque blob that you give to a user after an authentication or authorisation challenge, and then they show it to you to prove that they should be allowed access to a resource. In theory you could just hand someone a randomly generated blob, but then you’d need to keep track of which blobs you’ve issued and when they should be expired and who they correspond to, so frequently this is actually done using JWTs which contain some base64 encoded JSON that describes the user and group membership and so on and then have a signature associated with them so whenever the user presents one you can just validate the signature and then assume that the contents of the JSON are trustworthy.

One thing to note here is that the crypto is purely between whoever issued the token and whoever validates the token – as far as the server is concerned, any client who can just show it the token is just fine as long as the signature is verified. There’s no way to verify the client’s state, so one of the core ideas of Zero Trust (that we verify that the client is in a trustworthy state on every access) is already violated.

Can we make things not terrible? Sure! We may not be able to validate the client state on every access, but we can validate the client state when we issue the token in the first place. When the user hits a login page, we do state validation according to whatever policy we want to enforce, and if the client violates that policy we refuse to issue a token to it. If the token has a sufficiently short lifetime then an attacker is only going to have a short period of time to use that token before it expires and then (with luck) they won’t be able to get a new one because the state validation will fail.

Except! This is fine for cases where we control the issuance flow. What if we have a scenario where a third party authenticates the client (by verifying that they have a valid token issued by their ID provider) and then uses that to issue their own token that’s much longer lived? Well, now the client has a long-lived token sitting on it. And if anyone copies that token to another device, they can now pretend to be that client.

This is, sadly, depressingly common. A lot of services will verify the user, and then issue an oauth token that’ll expire some time around the heat death of the universe. If a client system is compromised and an attacker just copies that token to another system, they can continue to pretend to be the legitimate user until someone notices (which, depending on whether or not the service in question has any sort of audit logs, and whether you’re paying any attention to them, may be once screenshots of your data show up on Twitter).

This is a problem! There’s no way to fit a hosted service that behaves this way into a Zero Trust model – the best you can say is that a token was issued to a device that was, around that time, apparently trustworthy, and now it’s some time later and you have literally no idea whether the device is still trustworthy or if the token is still even on that device.

But wait, there’s more! Even if you’re nowhere near doing any sort of Zero Trust stuff, imagine the case of a user having a bunch of tokens from multiple services on their laptop, and then they leave their laptop unlocked in a cafe while they head to the toilet and whoops it’s not there any more, better assume that someone has access to all the data on there. How many services has our opportunistic new laptop owner gained access to as a result? How do we revoke all of the tokens that are sitting there on the local disk? Do you even have a policy for dealing with that?

There isn’t a simple answer to all of these problems. Replacing bearer tokens with some sort of asymmetric cryptographic challenge to the client would at least let us tie the tokens to a TPM or other secure enclave, and then we wouldn’t have to worry about them being copied elsewhere. But that wouldn’t help us if the client is compromised and the attacker simply keeps using the compromised client. The entire model of simply proving knowledge of a secret being sufficient to gain access to a resource is inherently incompatible with a desire for fine-grained trust verification on every access, but I don’t see anything changing until we have a standard for third party services to be able to perform that trust verification against a customer’s policy.

Still, at least this means I can just run weird Android IoT apps through mitmproxy, pull the bearer token out of the request headers and then start poking the remote API with curl. It may all be broken, but it’s also got me a bunch of bug bounty credit, so, it;s impossible to say if its bad or not,

(Addendum: this suggestion that we solve the hardware binding problem by simply passing all the network traffic through some sort of local enclave that could see tokens being set and would then sequester them and reinject them into later requests is OBVIOUSLY HORRIFYING and is also probably going to be at least three startup pitches by the end of next week)

comment count unavailable comments