[Mud] Using an HSM to sign MUD files?

Eliot Lear <lear@cisco.com> Sun, 09 February 2020 12:59 UTC

Return-Path: <lear@cisco.com>
X-Original-To: mud@ietfa.amsl.com
Delivered-To: mud@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id AC3861200FE for <mud@ietfa.amsl.com>; Sun, 9 Feb 2020 04:59:32 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -14.501
X-Spam-Level:
X-Spam-Status: No, score=-14.501 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_HI=-5, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=cisco.com
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 0YnlHtqiB3wu for <mud@ietfa.amsl.com>; Sun, 9 Feb 2020 04:59:30 -0800 (PST)
Received: from aer-iport-4.cisco.com (aer-iport-4.cisco.com [173.38.203.54]) (using TLSv1.2 with cipher DHE-RSA-SEED-SHA (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id AFDF21200F5 for <mud@ietf.org>; Sun, 9 Feb 2020 04:59:29 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=21097; q=dns/txt; s=iport; t=1581253169; x=1582462769; h=from:mime-version:subject:message-id:date:cc:to; bh=kYdoqsa26KIMcUS9vWS40szd1xtN/A4QSYFor7PPm98=; b=DeHKZfa0Gv6dLoMPZ2dULCKNCq7pgnnGFgpIE6jVFSAGOqXzBkgUuI8u cNDyn3Zuk8zGoHpnUJotmfIgT3rcZE7tUifRecs6zNQ5wl2t2FiGt0j0v w7uhPUM7mYfAfeKEM15WOPKvOFIxYFTBdPT1HGxuI5uASWz/iqyIUAgnj o=;
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: A0CaGQC2AUBe/xbLJq1mHAECKAEHAQIFAQQEAYFgAoEjAYFvVSASKoQViQOHfpllgXsJAQEBDAEBGxQBAYRATgmCEjYHDgIDDQEBBAEBAQIBBQRthTcMhhBOCFMKAoQYAYJ7rDB1gTKFSoUQgTgBjDyCAIERJwwUgh6IRzKCCiIEjVAooXqCRASCSoR+gV6Daok4G4JIeYs5jBWmWoMvAgQGBQIVgVkBMYFYMxoIGxU7KgGCQQk1EhgNmQGDY0ADMI5oAQE
X-IronPort-AV: E=Sophos; i="5.70,421,1574121600"; d="scan'208,217"; a="23066773"
Received: from aer-iport-nat.cisco.com (HELO aer-core-3.cisco.com) ([173.38.203.22]) by aer-iport-4.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 09 Feb 2020 12:59:25 +0000
Received: from [10.61.243.10] ([10.61.243.10]) by aer-core-3.cisco.com (8.15.2/8.15.2) with ESMTPS id 019CxOrR028996 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 9 Feb 2020 12:59:25 GMT
From: Eliot Lear <lear@cisco.com>
Content-Type: multipart/alternative; boundary="Apple-Mail=_88501008-4AFA-497D-A66F-207CBA06E85F"
Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\))
Message-Id: <48EB1BF2-1163-42D2-9E24-8B1DC437203C@cisco.com>
Date: Sun, 09 Feb 2020 13:59:24 +0100
Cc: Rich Salz <rsalz@akamai.com>
To: mud@ietf.org
X-Mailer: Apple Mail (2.3608.60.0.2.5)
X-Outbound-SMTP-Client: 10.61.243.10, [10.61.243.10]
X-Outbound-Node: aer-core-3.cisco.com
Archived-At: <https://mailarchive.ietf.org/arch/msg/mud/znAKbCu1HLpTv9WYYc0xN0W_h3I>
Subject: [Mud] Using an HSM to sign MUD files?
X-BeenThere: mud@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Discussion of Manufacturer Ussage Descriptions <mud.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/mud>, <mailto:mud-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/mud/>
List-Post: <mailto:mud@ietf.org>
List-Help: <mailto:mud-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/mud>, <mailto:mud-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sun, 09 Feb 2020 12:59:33 -0000

I was asked by a partner how to modify the normal MUD signing instructions when an HSM is in play.  Each HSM is a little different, but the general concepts are the same.  OpenSSL does come equipped with a means to invoke HSMs.  What has to happen, roughly speaking is the following:

Configure the HSM engine in the openssl.cnf file.
Make sure you know the PKCS#11 URI
Invoke the engine using cms.

I’m using SoftHSM2 only as an example in this message.  If you need to install a certificate and a key into the HSM, follow its instructions to do so.  For SoftHSM2 that means doing the following:

Initialize a token:
softhsm2-util --init-token --slot 1 --label mud
Find the Slot # associated with that label
softhsm-util —show-slots
Load the appropriate private key:
pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so  --slot 1810141384 --pin secret --write-object clientcert.key --type privkey
Load the appropriate certificate:
pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --slot 1810141384 -pin secret --write-object clientcert.pem --type cert


One must next inform OpenSSL that the engine is to be used.  This is done in the openssl.cnf file.  I will not go through the details of this file’s construction, as it was written by good people who happen to have sadistic tendencies.

At the very top of the file, we add the following line:

openssl_conf = openssl_init

Then at the very bottom of the file we will add the following lines:

[openssl_init]

engines=engine_section

[engine_section]
pkcs11=pkcs11_section

[pkcs11_section]
engine_id = pkcs11
dynamic_path = /usr/lib/x86_64-linux-gnu/engines-1.1/libpkcs11.so
MODULE_PATH= /usr/lib/softhsm/libsofthsm2.so
default_algorithms = ALL
init = 1

The top part informs openssl that it should check the [openssl_init] section on initialization.  The openssl_init section indicates where to find the engine section, and then we get to the pkcs11 engine.

You will need to replace the softhsm line with an appropriate line for you, given to you by the HSM manufacturer, and they may also give you some arguments.

Now… you will note the use of libpkcs11 above.  To install that:

sudo apt-get install -y libpkcs11 libengine-pkcs11-openssl1.1

The next thing you will need is the appropriate PKCS#11 URI.  To get that, I have found that p11tool does the job best, as follows:

sudo apt-get install -y gnutls-bin
p11tool --list-tokens


You should get output along the lines of:

Token 2:
	URL: pkcs11:model=SoftHSM%20v2;manufacturer=SoftHSM%20project;serial=88807c3febe490c8;token=mud
	Label: mud
	Type: Generic token
	Manufacturer: SoftHSM project
	Model: SoftHSM v2
	Serial: 88807c3febe490c8
	Module: /usr/lib/softhsm/libsofthsm2.so

All of this information will likely vary for you.  The only thing you care about is the URI.  Copy what you see in the response.  If you don’t see anything with p11tool, stop.  Some debugging is in order at that point.

Now to sign the file using cms, we use a line similar to how one normally signs a mud file.  This time, however, we will invoke the PKCS#11 engine.  This has to be done in three ways: by specifying the -engine option, by indicating the keyform, and by modifying -inkey.

% openssl cms -in mudfile.json -outform der -engine pkcs11 -keyform engine -sign -signer clientcert.pem -binary -certfile intermediate.pem -out mudfile.p7s  -inkey 'pkcs11:model=SoftHSM%20v2;manufacturer=SoftHSM%20project;serial=88807c3febe490c8;token=mud;pin-value=123456’


Note the addition of the pin at the end.

For this operation to work, we presume that you have the normal signing certificate available as a file.

Different drivers work a little differently.  Some are in a position to prompt you for the PIN, and this is of course preferred.

Eliot