def envelope(challenge, cert, signature): user_certificate = decoder.decode(cert) version_section = univ.Integer(1) digest_section = univ.Set() digest_section[0] = univ.Sequence() digest_section[0][0] = univ.ObjectIdentifier('1.3.14.3.2.26') digest_section[0][1] = univ.Null() challenge_section = univ.Sequence() challenge_section[0] = univ.ObjectIdentifier('1.2.840.113549.1.7.1') challenge_section[1] = univ.OctetString(value=base64.b64decode(challenge), tagSet=tag.TagSet( (), tag.Tag(0, 0, 4), tag.Tag(128, 32, 0))) cert_section = univ.Sequence( tagSet=tag.TagSet((), tag.Tag(0, 32, 16), tag.Tag(128, 32, 0))) cert_section[0] = user_certificate[0][0] cert_section[1] = user_certificate[0][1] cert_section[2] = user_certificate[0][2] response_section = univ.Set() response_section[0] = univ.Sequence() response_section[0][0] = univ.Integer(1) response_section[0][1] = univ.Sequence() response_section[0][1][0] = user_certificate[0][0][3] response_section[0][1][1] = user_certificate[0][0][1] response_section[0][2] = univ.Sequence() response_section[0][2][0] = univ.ObjectIdentifier('1.3.14.3.2.26') response_section[0][2][1] = univ.Null() response_section[0][3] = univ.Sequence() response_section[0][3][0] = univ.ObjectIdentifier('1.2.840.113549.1.1.1') response_section[0][3][1] = univ.Null() response_section[0][4] = univ.OctetString(signature) outer = univ.Sequence() outer[0] = univ.ObjectIdentifier('1.2.840.113549.1.7.2') outer[1] = univ.Sequence( tagSet=tag.TagSet((), tag.Tag(0, 32, 16), tag.Tag(128, 32, 0))) outer[1][0] = version_section outer[1][1] = digest_section outer[1][2] = challenge_section outer[1][3] = cert_section outer[1][4] = response_section encoded = encoder.encode(outer) b64 = base64.b64encode(encoded).decode('utf-8') return encoded
def setUp(self): self.s1 = univ.Set(componentType=namedtype.NamedTypes( namedtype.NamedType('name', univ.OctetString('')), namedtype.OptionalNamedType('null', univ.Null('')), namedtype.DefaultedNamedType('age', univ.Integer(34)) )) self.s2 = self.s1.clone()
def setUp(self): BaseTestCase.setUp(self) self.s = univ.Set(componentType=namedtype.NamedTypes( namedtype.NamedType('place-holder', univ.Null('')), namedtype.OptionalNamedType('first-name', univ.OctetString()), namedtype.DefaultedNamedType('age', univ.Integer(33)) ))
def setUp(self): BaseTestCase.setUp(self) c = univ.Choice(componentType=namedtype.NamedTypes( namedtype.NamedType('actual', univ.Boolean(0)))) self.s = univ.Set(componentType=namedtype.NamedTypes( namedtype.NamedType('place-holder', univ.Null('')), namedtype.NamedType('status', c)))
def setUp(self): c = univ.Choice(componentType=namedtype.NamedTypes( namedtype.NamedType('name', univ.OctetString('')), namedtype.NamedType('amount', univ.Integer(0)))) self.s = univ.Set(componentType=namedtype.NamedTypes( namedtype.NamedType('place-holder', univ.Null('')), namedtype.NamedType('status', c)))
class CertMetaData(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('MetaDataType', univ.ObjectIdentifier()), namedtype.NamedType( 'MetaDataValue', univ.Set(componentType=namedtype.NamedTypes( namedtype.NamedType('RealContent', univ.OctetString())))))
def attr_signing_certificate(self): issuerSerial = classes.IssuerSerial() issuerSerial['issuer'] = self.cert_issuer_name() issuerSerial['serialNumber'] = self.certificate.serial_number essCertId = classes.ESSCertID() essCertId['certHash'] = self.certificate.public_bytes( serialization.Encoding.DER) essCertId['issuerSerial'] = issuerSerial essCertsIds = univ.Sequence() essCertsIds.setComponentByPosition(0, essCertId) signing_certificate = classes.SigningCertificate() signing_certificate['certs'] = essCertsIds attribute = rfc3852.Attribute() attribute['attrType'] = constants.id_signing_certificate values = univ.Set() values.setComponentByPosition(0, signing_certificate) attribute['attrValues'] = values return attribute
def setUp(self): c = univ.Choice(componentType=namedtype.NamedTypes( namedtype.NamedType('name', univ.OctetString()), namedtype.NamedType('amount', univ.Boolean()))) self.s = univ.Set(componentType=namedtype.NamedTypes( namedtype.NamedType('value', univ.Integer(5)), namedtype.NamedType('status', c)))
def setUp(self): self.s = univ.Set(componentType=namedtype.NamedTypes( namedtype.NamedType('place-holder', univ.Null(null)), namedtype.NamedType('first-name', univ.OctetString(null)), namedtype.NamedType('age', univ.Integer(33)))) self.s.setComponentByPosition(0, univ.Null(null)) self.s.setComponentByPosition(1, univ.OctetString('quick brown')) self.s.setComponentByPosition(2, univ.Integer(1))
def attr_content_type(self): attribute = rfc3852.Attribute() attribute['attrType'] = constants.id_content_type values = univ.Set() values.setComponentByPosition(0, constants.id_ct_TSTInfo) attribute['attrValues'] = values return attribute
class SetDecoder(SequenceDecoder): protoComponent = univ.Set() def _getComponentTagMap(self, r, idx): return r.getComponentTagMap() def _getComponentPositionByType(self, r, t, idx): nextIdx = r.getComponentPositionByType(t) if nextIdx is None: return idx else: return nextIdx
def attr_message_digest(self, content): attribute = rfc3852.Attribute() attribute['attrType'] = constants.id_message_digest contentDigest = hashlib.sha256(content).digest() values = univ.Set() values.setComponentByPosition(0, univ.OctetString(contentDigest)) attribute['attrValues'] = values return attribute
class SetDecoder(SetOrSetOfDecoder): protoComponent = univ.Set() def _getComponentTagMap(self, asn1Object, idx): return asn1Object.componentType.tagMapUnique def _getComponentPositionByType(self, asn1Object, tagSet, idx): if asn1Object.componentType: return asn1Object.componentType.getPositionByType(tagSet) else: return idx
class SetDecoder(SequenceAndSetDecoderBase): protoComponent = univ.Set() orderedComponents = False def _getComponentTagMap(self, asn1Object, idx): return asn1Object.componentType.tagMapUnique def _getComponentPositionByType(self, asn1Object, tagSet, idx): if asn1Object.componentType: return asn1Object.componentType.getPositionByType(tagSet) else: return idx
class SetDecoder(SequenceDecoder): protoComponent = univ.Set() def _getComponentTagMap(self, asn1Object, idx): return asn1Object.getComponentTagMap() def _getComponentPositionByType(self, asn1Object, tagSet, idx): nextIdx = asn1Object.getComponentPositionByType(tagSet) if nextIdx is None: return idx else: return nextIdx
def testWithUntaggedChoice(self): c = univ.Choice(componentType=namedtype.NamedTypes( namedtype.NamedType('premium', univ.Boolean()))) s = univ.Set(componentType=namedtype.NamedTypes( namedtype.NamedType('name', univ.OctetString()), namedtype.NamedType('customer', c))) s.setComponentByName('name', 'A') s.getComponentByName('customer').setComponentByName('premium', True) assert encoder.encode(s) == ints2octs((49, 6, 1, 1, 255, 4, 1, 65))
class SetDecoder(SequenceAndSetDecoderBase): protoComponent = univ.Set() orderedComponents = False def _getComponentTagMap(self, asn1Object, idx): return asn1Object.componentTagMap def _getComponentPositionByType(self, asn1Object, tagSet, idx): nextIdx = asn1Object.getComponentPositionByType(tagSet) if nextIdx is None: return idx else: return nextIdx
class SetDecoder(SequenceDecoder): protoComponent = univ.Set() def _getAsn1SpecByPosition(self, t, idx): if t.getComponentType() is not None: if hasattr(t, 'getComponentTypeMap'): return t.getComponentTypeMap() # Set/SetOf # or no asn1Specs def _getPositionByType(self, t, c, idx): if t.getComponentType() is not None: if hasattr(t,'getComponentPositionByType') and t.getComponentType(): effectiveTagSet = getattr( c, 'getEffectiveTagSet', c.getTagSet )() return t.getComponentPositionByType(effectiveTagSet) # Set return idx # SetOf or w/o asn1Specs
def testWithTaggedChoice(self): c = univ.Choice(componentType=namedtype.NamedTypes( namedtype.NamedType('premium', univ.Boolean()))).subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 7)) s = univ.Set(componentType=namedtype.NamedTypes( namedtype.NamedType('name', univ.OctetString()), namedtype.NamedType('customer', c))) s.setComponentByName('name', 'A') s.getComponentByName('customer').setComponentByName('premium', True) assert encoder.encode(s) == ints2octs( (49, 128, 4, 1, 65, 167, 128, 1, 1, 255, 0, 0, 0, 0))
def testGetTagMap(self): assert self.s1.tagMap.presentTypes == {univ.Set.tagSet: univ.Set()}
def setUp(self): BaseTestCase.setUp(self) self.s = univ.Set() self.s.setComponentByPosition(0, univ.Null('')) self.s.setComponentByPosition(1, univ.OctetString('quick brown')) self.s.setComponentByPosition(2, univ.Integer(1))
class _Attribute(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('type', univ.ObjectIdentifier()), namedtype.NamedType('values', univ.Set()), )
def testGetTagMap(self): assert self.s1.getTagMap().getPosMap() == {univ.Set.tagSet: univ.Set()}
class SetOrSetOfDecoder(UniversalConstructedTypeDecoder): protoRecordComponent = univ.Set() protoSequenceComponent = univ.SetOf()
class SetDecoder(SetOrSetOfDecoder): protoComponent = univ.Set()