Re: [jose] JWK Generator Service

Richard Barnes <rlb@ipv.sx> Tue, 04 November 2014 15:19 UTC

Return-Path: <rlb@ipv.sx>
X-Original-To: jose@ietfa.amsl.com
Delivered-To: jose@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id D48D91A89E7 for <jose@ietfa.amsl.com>; Tue, 4 Nov 2014 07:19:26 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.977
X-Spam-Level:
X-Spam-Status: No, score=-1.977 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, FM_FORGED_GMAIL=0.622, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=ham
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xCbDIFbSXMcv for <jose@ietfa.amsl.com>; Tue, 4 Nov 2014 07:19:19 -0800 (PST)
Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 3A40B1A8983 for <jose@ietf.org>; Tue, 4 Nov 2014 07:19:19 -0800 (PST)
Received: by mail-vc0-f169.google.com with SMTP id hy4so6767000vcb.14 for <jose@ietf.org>; Tue, 04 Nov 2014 07:19:18 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=swnuMwnXDg9+oBiLmJsTFP0TN0D+XshQXec7OaWC3zc=; b=btsJqeILefpy1e54JJTP5phDGsQ+pYMUbLJPKBXItc2ESv7owL6rAbCmBxBMyidzp4 xRrXhVkMKpudHkboxEyT81h3YowgdI9LNRvObtFROAySNhDB1iz6DKqkrExL8Ix97ZD0 79AsUshVKLZzih/eDnnwa3sTZduoioeMV6pMz+o+LbvcvGRGaZlzJRUcIdTEt+ewo4aQ +CKKIOMTvxCcHNM2ADoYEx9alp2GinCV8E2tPLt5PVxJHLewe7gvdE+zfVkQhG9zLiwl 72Pr8x49eO8AF3FnuRKhzWa9jelEPR5IuVQOnkspsGyBaUbcJNZtwGeaTuJOU1ZmQ7r8 x4vg==
X-Gm-Message-State: ALoCoQk34iiEi6tKNZIvb+/B5b2YujnM68L9TQ9I3RNxaS2xBMONltyZV3GEn8CPvz8hIBb5B19u
MIME-Version: 1.0
X-Received: by 10.220.195.132 with SMTP id ec4mr20978947vcb.16.1415114358259; Tue, 04 Nov 2014 07:19:18 -0800 (PST)
Received: by 10.31.149.205 with HTTP; Tue, 4 Nov 2014 07:19:18 -0800 (PST)
In-Reply-To: <5458E955.3090700@mit.edu>
References: <5458E645.9020904@mit.edu> <CAL02cgTVHkGmB2+L90EaqpBT26+FqsNsvkvsV0Tig45tDJLjaw@mail.gmail.com> <5458E955.3090700@mit.edu>
Date: Tue, 04 Nov 2014 10:19:18 -0500
Message-ID: <CAL02cgSf_MeLys1D+bJcSsfPz9e5TLt5wT4G9szhD-=2OVFAnA@mail.gmail.com>
From: Richard Barnes <rlb@ipv.sx>
To: Justin Richer <jricher@mit.edu>
Content-Type: multipart/alternative; boundary="001a11c1ba98a41781050709fcea"
Archived-At: http://mailarchive.ietf.org/arch/msg/jose/gdjUicinuWplFe-4YhoCp0MVqew
Cc: "jose@ietf.org" <jose@ietf.org>
Subject: Re: [jose] JWK Generator Service
X-BeenThere: jose@ietf.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: Javascript Object Signing and Encryption <jose.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/jose>, <mailto:jose-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/jose/>
List-Post: <mailto:jose@ietf.org>
List-Help: <mailto:jose-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/jose>, <mailto:jose-request@ietf.org?subject=subscribe>
X-List-Received-Date: Tue, 04 Nov 2014 15:19:27 -0000

Oops, here's the real version:

-----BEGIN-----
var alg = {
      name: "RSASSA-PKCS1-v1_5",
      hash: "SHA-256",
      modulusLength: 1024,
      publicExponent: new Uint8Array([0x01, 0x00, 0x01])
    };
crypto.subtle.generateKey(alg, true, ["sign", "verify"])
  .then(
    function(keyPair) {
      crypto.subtle.exportKey("jwk", keyPair.privateKey).then(function(x) {
console.log(x) });
      crypto.subtle.exportKey("jwk", keyPair.publicKey).then(function(x) {
console.log(x) });
    }
  );
-----END-----

That should work in recent versions of Firefox if you turn on
dom.webcrypto.enabled, and in Safari with s/subtle/webkitSubtle/.

It shouldn't be much more complicated in node.js (require("node-forge")) or
python.  The only marginally non-trivial part is the base64 encoding.

--Richard





On Tue, Nov 4, 2014 at 9:57 AM, Justin Richer <jricher@mit.edu> wrote:

>  That will be great to have a Javascript version widely available as
> well, when it's ready. I also know someone working on a Python app to
> handle the same task on the commandline, and I look forward to people
> having their pick of tools to do this job. If key generation isn't easy,
> people will get lazy and re-use keys, fail to rotate them when needed, or
> other, worse things.
>
>  -- Justin
>
>
> On 11/4/2014 9:54 AM, Richard Barnes wrote:
>
>  Note that with WebCrypto, the crypto parts of this become one-liners.
>
>  crypto.subtle.generateKey({name: "RSA-OAEP", hash: "SHA-1"}, true,
> ["encrypt", "decrypt"])
>    .then( function(keyPair) {
>
>   })
>
> On Tue, Nov 4, 2014 at 9:44 AM, Justin Richer <jricher@mit.edu> wrote:
>
>> A while ago, I was fed up with creating self-signed X.509 certificates
>> just to manage the bare keys used in JOSE processing. There's a lot of
>> extraneous effort that goes into making fake certificate chains that are
>> then dutifully ignored by the application, especially when the JWK format
>> can hold both public and private keys natively already. So we switched our
>> apps over to reading the JWK format instead of X.509, but we still needed
>> something to securely generate the keys themselves. So I created a
>> commandline Java application to generate keys in JWK format (based on the
>> NimbusDS JOSE library):
>>
>>   https://github.com/mitreid-connect/json-web-key-generator
>>
>> It's slightly unwieldy to compile and run but it gets the job done. Last
>> night, I wrapped that commandline application with a webapp and made it
>> publicly available:
>>
>>   https://mkjwk.org/
>>
>> This simple service will generate a JWK in RSA, EC, or Oct (shared
>> secret) format for you, using Java's cryptographic engine. You can add in
>> the use, kid, and alg parameters, and the results are formatted into
>> easily-copyable JSON. It will even wrap the key in a keyset and pull out
>> the public key separately for you, in case you need those.
>>
>> We don't log any of the keys being generated by the service, but to be
>> extra safe I would still recommend using a local generation mechanism (like
>> the commandline app above) for production systems.
>>
>> Finally, I put the code to the site online in the name of transparency:
>>
>>   https://github.com/mitreid-connect/mkjwk.org
>>
>> I hope that people can find this useful, and we can start moving off of
>> X.509 for bare key storage in applications. Much thanks to MIT KIT for
>> providing hosting and support.
>>
>>  -- Justin
>>
>> _______________________________________________
>> jose mailing list
>> jose@ietf.org
>> https://www.ietf.org/mailman/listinfo/jose
>>
>
>
>