I'm trying to code the following from RFC 7906 using pyasn1:
aa-keyAlgorithm ATTRIBUTE ::= {
TYPE KeyAlgorithm
IDENTIFIED BY id-kma-keyAlgorithm }
KeyAlgorithm ::= SEQUENCE {
keyAlg OBJECT IDENTIFIER,
checkWordAlg [1] OBJECT IDENTIFIER OPTIONAL,
crcAlg [2] OBJECT IDENTIFIER OPTIONAL }
The relevant section of code I have presently is:
id_kma_keyAlgorithm = ObjectIdentifier('2.16.840.1.101.2.1.13.1')
aes256_gcm_oid = ObjectIdentifier('2.16.840.1.101.2.1.13.1')
id_keyAlg_ckword64 = ObjectIdentifier('1.2.826.0.1145.0.5.0')
id_keyalg_crc32 = ObjectIdentifier('1.2.826.0.1145.0.5.1')
class aa_keyAlgorithm(Sequence):
componentType = NamedTypes(
NamedType('attrType', ObjectIdentifer()),
NamedType('attrValues', KeyAlgorithm())
)
class KeyAlgorithm(Sequence):
componentType = NamedTypes(
NamedType('keyAlg', ObjectIdentifier()),
OptionalNamedType('checkWordAlg', ObjectIdentifier().subtype(
implicitTag=Tag(tagClassContext, tagFormatSimple, 1))),
OptionalNamedType('crcAlg', ObjectIdentifier().subtype(
implicitTag=Tag(tagClassContext, tagFormatSimple, 2)))
key_algorithm = aa_keyAlgorithm()
key_alg_attrs = KeyAlgorithm()
key_algorithm.setComponentByName('attrType', id_kma_keyAlgorithm)
key_algorithm.setComponentByName('attrValues', key_alg_attrs)
key_alg_attrs.setComponentByName('keyAlg', aes256_gcm_oid)
key_alg_attrs.setComponentByName('checkWordAlg',id_keyAlg_ckword64, matchTags = True)
key_alg_attrs.setComponentByName('crcAlg', id_keyalg_crc32, matchTags = True)
I am getting the following error:
Component-value is tag-incompatible: <ObjectIdentifier value object, tagSet <Tagset object, tags 0:0:6>, payload [1.2.826.0.1145.0.5.0]> vs <NamedTypes object, types <NamedType object, type KeyAlgorithm=<ObjectIdentifier schema object, tagSet <TagSet object, tags 0:0:6>>>, <OptionalNamedType object, type checkWordAlg=<ObjectIdentifier schema object, tagSet <TagSet object, tags 128:0:1>>>, <OptionalNamedType object, type crcAlg=<ObjectIdentifier schema object, tagSet <TagSet object, tags 128:0:2>>>>
The code runs fine without trying to add the context tags. I've tried various combinations of matchTags = True/False throughout the code. What is I need to change to make the tags compatible?