def on_hsm_connected(self, hsm):
"""Called when the hsm interface becomes connected. This means the
plugin has connected to the principal Barbican charm.
In order for the Barbican charm to use this plugin (softhsm2) the
plugin needs to provide a PKCS#11 libary for barbican to access, a
password to access the token and a slot_id for the token.
This sets the plugin_data on the hsm relation for the Barbican charm to
pick up.
:param hsm: a BarbicanProvides instance for the relation.
:raises RuntimeError: if the token_store can't be setup - which is
FATAL.
"""
hookenv.log("Setting plugin name to softhsm2", level=hookenv.DEBUG)
hsm.set_name('softhsm2')
pin, so_pin = read_pins_from_store()
if pin is None:
self.setup_token_store()
pin, so_pin = read_pins_from_store()
if pin is None:
hookenv.status_set('error', "Couldn't set up the token store?")
raise RuntimeError(
"BarbicanSoftHSMCharm.setup_token_store() failed?")
slot_id = read_slot_id(BARBICAN_TOKEN_LABEL)
if slot_id is None:
raise RuntimeError("No {} slot in token store?"
.format(BARBICAN_TOKEN_LABEL))
plugin_data = {
"library_path": SOFTHSM2_LIB_PATH,
"login": pin,
"slot_id": slot_id
}
hsm.set_plugin_data(plugin_data)
评论列表
文章目录