5 Ways How Code Signing Works

When you think of code signing, you might imagine the process as a magical unicorn that sprinkles fairy dust on your code to make it magically secure. The truth is much less magical but no less extraordinary. Code signing is a process in which apps are authenticated and validated so users can have confidence they are from a trustworthy source and haven’t been tampered with.
It’s an important security measure for apps because, without it, anyone could put malicious software in the App Store and trick users into downloading and installing it. Signing your app takes some upfront setup time, but once you are set up with your certificate and private key, you can sign each new app version with just one command. In this blog post, we’ll cover five ways how code signing works. So, keep reading!

What is Code Signing?

Code signing is a way for developers to verify that the app someone has downloaded isn’t tampered with or malicious software. It’s a crucial step in ensuring the App Store distributes dedicated, safe apps to users. Code signing is all about making sure the app you’re downloading and installing is the app the developer intended you to get.

If it’s not, you won’t know until you’ve already downloaded it and it’s too late. That’s why code signing is an integral part of app development.
Code signing uses digital certificates to authenticate the app developer and ensure there is no tampering with the app. Apple, Microsoft, and other trusted certificate authorities issue the certificates, so the user knows the app came from a verified source.

So, let’s look at how code signing works:

Enrollment process

First, the developer will generate a certificate request. This requests certificate authorities like Apple or Microsoft to issue a certificate. You can also do this using an online tool. This request will include a public key so the certificate authority can verify your identity and a request to issue the certificate for a specific app.

Once the certificate authority receives your request, it will decide whether to issue the certificate. If it does, the certificate authority will sign the certificate with its private key. The certificate authority then returns the public key so the developer can authenticate the certificate and the certificate authority’s signature.

Once the developer has the certificate, they add it to their code signing identity. This is a list of all the certificates the developer has. They can sign their code using the certificates from their code signing identity.

Public key encryption

A developer must create a private key to generate a certificate request. This is a secret key that only the developer has access to. It’s like having a pair of unique, secret handcuffs attached to your computer.

Once the certificate is issued, the private key is used to encrypt the public key so it can be added to the certificate. The public key is what’s used to sign apps. But because it is encrypted with the private key, it can only be decrypted with the key. The private key is then used to sign the certificate. So, when the certificate authority verifies the certificate, it will use the public key in the certificate and attempt to decrypt it with the private key.

Hash function

A hash function takes a string of text, like the name of your app or a file name, and produces a number. This is a mathematical function, but it is often used to create a data fingerprint. A hash function is used during the code signing process to generate a fingerprint of your app. It will use the app’s name and every line of code to create “fingerprints” of each file and store them in a database.

If there is ever a change to the app, the hash value will change too. If the hash values of the two apps are different, they are different versions of the app. You will receive a warning alert of malicious software if the hash function values don’t pair. But, if the values are the same, you’ll be allowed to proceed with the download.

Code signing certificates

A code signing certificate is what you sign your app with. When someone downloads your app, their device will check the signature to ensure it is valid. When an app is signed with a certificate, it will also include the hash values of the files.
The hash values will change if the software is corrupted. Your device will detect this change in hash values and issue a warning message that the app has been interrupted. Users can either delete the app or proceed with the installation at their own risk.

Root certificates

Although code signing certificates may assure authority and authenticity, it’s crucial to know that malware developers can create a developer’s public key and generate fake certificates.
So, how do you know a certificate is authentic? This is where root certificates come in handy. Root certificates trace the signing certificates back to the certificate authorizers to determine their authenticity.

If the signing certificate cannot verify the authenticity of the root certificate, you will be issued a warning to abort the download of the software.

Conclusion

Code signing is a crucial part of building and distributing apps. It allows you to prove that you created the app and protect it from tampering or modification. It’s imperative when distributing apps through the App Store because it makes it much harder for malicious software to slip in. You’ll need to enroll with code signing providers to code sign your app and send certificate requests to a trusted CA. They will issue a certificate, which you will use to sign your code. When users download your app, they can verify that it is not malicious software and is the app you intended them to get.