Changeset b2546f0 in mod_gnutls


Ignore:
Timestamp:
Jan 9, 2020, 5:44:38 PM (9 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
master, proxy-ticket
Children:
20a3915
Parents:
221ffe5
Message:

mgstest.softhsm: Include type when searching object URLs

The p11tool documentation notes that some tokens require the same
label to be used for a certificate and its private key. That isn't the
case for SoftHSM, but I still want to support the case where a key
pair shares a label.

Location:
test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • test/doctest-mgstest.py

    r221ffe5 rb2546f0  
    1010        'mgstest.http',
    1111        'mgstest.services',
     12        'mgstest.softhsm',
    1213        'mgstest.tests'
    1314    ]
  • test/mgstest/softhsm.py

    r221ffe5 rb2546f0  
    2020import subprocess
    2121import tempfile
     22from enum import Enum, auto
    2223from pathlib import Path
    2324
     
    3536tokendir_re = re.compile(r'^directories\.tokendir\s*=\s*(.*)$')
    3637
    37 test_key_label = 'privkey'
    38 test_cert_label = 'certificate'
     38test_label = 'test_server'
     39
     40class ObjectType(Enum):
     41    """Types that may occur in PKCS#11 URIs (type=...).
     42
     43    See: https://tools.ietf.org/html/rfc7512#section-2.3
     44
     45    """
     46    CERT = 'cert'
     47    DATA = 'data'
     48    PRIVATE = 'private'
     49    PUBLIC = 'public'
     50    SECRET_KEY = 'secret-key'
     51
     52    def __init__(self, uri_type):
     53        self.uri_type = uri_type
     54
     55    def __str__(self):
     56        """
     57        >>> str(ObjectType.CERT)
     58        'type=cert'
     59        """
     60        return f'type={self.uri_type}'
     61
     62    def __repr__(self):
     63        """
     64        >>> repr(ObjectType.PRIVATE)
     65        'ObjectType.PRIVATE'
     66        """
     67        return f'{self.__class__.__name__!s}.{self.name}'
    3968
    4069class Token:
     
    116145        self._object_listing = None
    117146
    118     def get_object_url(self, label):
     147    def get_object_url(self, label, type):
    119148        """Get the PKCS#11 URL for an object in this token, selected by
    120149        label."""
     
    128157        for line in self._object_listing:
    129158            m = object_re.fullmatch(line)
    130             if m:
     159            if m and str(type) in m.group(1):
    131160                return m.group(1)
    132161
     
    139168            'SOFTHSM_LIB': str(Path(self.softhsm_lib).resolve()),
    140169            'P11_PIN': self.pin,
    141             'P11_CERT_URL': self.get_object_url(test_cert_label),
    142             'P11_KEY_URL': self.get_object_url(test_key_label)
     170            'P11_CERT_URL': self.get_object_url(test_label, ObjectType.CERT),
     171            'P11_KEY_URL': self.get_object_url(test_label, ObjectType.PRIVATE)
    143172        }
    144173
  • test/softhsm-init.py

    r221ffe5 rb2546f0  
    4646        token.reset_db()
    4747        token.init_token()
    48         token.store_key(args.privkey, mgstest.softhsm.test_key_label)
     48        token.store_key(args.privkey, mgstest.softhsm.test_label)
    4949        if args.certificate:
    50             token.store_cert(args.certificate, mgstest.softhsm.test_cert_label)
     50            token.store_cert(args.certificate, mgstest.softhsm.test_label)
    5151    except:
    5252        # Don't leave a half-done token around, the next make call
Note: See TracChangeset for help on using the changeset viewer.