Google App Engine Security Module API and JWT support

In late March 2011, Google rolled out a new Google App Engine API that can be used to support 'application identity'. Most of you are already familiar with user identity, authenticating a user usually involves a user name and password, or an oauth token bind to that particular user. We are going to apply the same authentication concept to applications, give applications a cloud identifier that could be used to interoperate with other cloud applications.

The new API is currently referred to as the Cloud Security Module API and at the most basic level it allows you to create a digital signature.  The digital key used to create the signature is secured by Google App Engine, and thus the developer's code does not need to worry about protecting the key.  This is functionally similar to a Hardware Security Module though the Cloud Security Module API does not implement the full PKCS#11 interface.  The API includes two interfaces:
  • app_identity.getPublicCertificatesForApp(): This function will enable your application to get the public key in a self-signed X.509 PEM certificate format.  Note that the Google App Engine automatically rotates the public key every few hours.  We suggest having a well defined URL on your site that calls this function and returns the current certificate.  An example of a returned x509 certificate can be found in the "Certificate Format" section below.
  • app_identity.signForApp(string_blob): The blob you pass to this function will be used to generate an RSA signature using the X.509 private key that Google App Engine manages for your application.  The system that needs to verify this signature will need to lookup the current certificate that Google App Engine used to created the signature.
Live Demo
Here is one basic use case that leverages this API to do application authentication:
  • Client App generates a signed blob by calling app_identity.signForApp(string_blob)
  • Client App exposes its public certificates on a public endpoint, for example  In the demos below we use a trivial Json format to expose certificates, something like: {"cert1":"x509 cert pem", "cert2":"x509 cert pem 2"...}.
  • Client App sends a request to API App along with the signed blob and the URL that contains Client App's public certificates.
  • API App fetches Client App's public certificates from that URL
  • API App verifies the signature of the signed blob.  The API App might perform other business logic like checking if the Client App (as identified by the URL of its public certificates) is on an access control list.
  • Both apps should agree on the same 'signed blob' format.  In our demo we use JWT as the signed token format. The detailed spec can be found at
Google has built two sample Apps which demonstrate this use case and which both run on Google App Engine, one is Python, one is Java.
  • The Java app can act as both as a Client App and API App: 
    • This is a REST API endpoint which acts in the API App role. It accepts two URL parameters, jwt and certurl.  It verifies the JWT signature by fetching certificates from the public certificate provided by the certurl parameter.
    • This is the user facing part of the app which acts in the Client App role.  By default it makes a call the the API endpoint above running on the same application.  However you can modify the URL of the endpoint it calls, for example by pointing it at your own verification endpoint which accepts the same parameters as the sample API endpoint.
    • This is the second part of the Client App functionality which exposes public certificates for this app. NOTICE: In real cases, public certificates URL must be a HTTPS URL to ensure transmit integrity.
  • The Python app ( can only act as a Client App.  It generates a JWT by calling the GAE app_identity.signForApp function, then calls the Java app's API endpoint, and shows the response it receives.  This python app also exposes its certs at the URL
Sample Code
We are making the source code of these apps available to help with industry discussions about standards and interop.  The API App is written in Java.  One calling app is written in Python and the other in Java.  You can checkout the source code at

The API App that verifies the signatures has very little code that is unique to Google App Engine.  So if you want to perform some basic interop testing, you can run an instance of that code on your own server.  If you visit the two calling apps, you can then override the URL of the API endpoint that they try to call and point them at your app.  Alternatively, you can run your own instance of a calling app, including publishing its cert on an Internet accessible URL.  If you access the UI of that app, it can make an API call to the API App and confirm that the signature was verified.

Google has also started to test the ability to use OAuth2 assertions when making calls to Google APIs.

Using the Google App Engine Identity API
If you want to write your own Google App Engine app that uses the new identity API feature, you might find it easiest to start with the sample code described above.  However if you want to write your own AppEngine app from scratch, we have provided some instructions below on how to get started.

You need to import two files into your projects:

You need to import one additional Jar to your project:
There also exists a Java version JWT library, which is compatible with JWT spec by Mike Jones, you can find the library at, a Jar version could be found at  The library is based on the Draft 1.0 JWT spec, but the later drafts did not make big changes to the functionality.

There're some packages which JWT library depends on, I also include those packages at :

Common for both JAVA and PYTHON:
  • Currently App needs to call getPublicCertificatesForApp, and write code to expose certs, in nearly future, we are planning to provide a standard Google API to expose those certificates in a standard format.
  • In order to construct a valid JWT, you need to provide an 'issuer' field, in the above example, it doesn't matter what 'issuer' be used, but in some more sophisticated use cases, 'issuer' can be important. 

Certificate format in Google App Engine Identity API
The App Engine function app_identity.getPublicCertificatesForApp() is used to get the list of public certificates which should be used to verify the signature created by the app_identity.signForApp(string_blob) function.  Because App Engine will rotate the signing key periodically, there could be multiple valid certificates at the same time.   The certificate itself will be an self-signed X.509 formatted certificate with an embedded public key in PEM format. There's also an identifier string called 'keyName' associated with each x509 certificate.  Below is an example of a returned x509 certificate:
Here is the decoded version:

        Version: 3 (0x2)
        Serial Number:
        Signature Algorithm: sha1WithRSAEncryption
            Not Before: Jan 27 23:00:23 2011 GMT
            Not After : Jan 29 00:00:23 2011 GMT
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (2048 bit)
                Modulus (2048 bit):
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Basic Constraints: critical
            X509v3 Key Usage: critical
                Digital Signature
            X509v3 Extended Key Usage: critical
                TLS Web Client Authentication
    Signature Algorithm: sha1WithRSAEncryption